Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

120
Visualizações
Cytoscape rendering of saved nodes and edges not rendering in proper position

I'm trying to render a graph to its original state from a saved JSON object that stores the nodes and edges arrays and all of their respective data including the x,y positions. I have an onLoad function that gets triggered when the page loads:

const onLoad = (_core) => {
  core.current = _core;
  if (savedView.nodes && savedView.node != undefined) {
       let curElements = JSON.stringify({
            nodes: savedView.nodes;
            edges: savedView.edges;
       });
       let layout = core.current._cy.layout({ name: 'preset' });
       layout.run();
       core.current._cy.add(JSON.parse(curElements));

In the above code snippet, _core is the core cytoscape graph object that's being passed into the function and the 'savedView' var is an object that contains the nodes and edges arrays that I want to pull out to use when re-rendering the graph. A sample of a couple of the elements contained in the nodes array:

{
    classes: 'draft-entity'
    data: {
        id: 'rkb1'
        type: 'person'
        displayName: 'Bob'
        elementType: 'node'
    {
    grabbable: true
    group: "nodes"
    locked: false
    pannable: false
    position: {x: 334.85120850976364, y: 20}
    removed: false
    selectable: true
    selected: false
}
{
    classes: 'draft-entity'
    data: {
        id: 'rkb2'
        type: 'person'
        displayName: 'Jane'
        elementType: 'node'
    {
    grabbable: true
    group: "nodes"
    locked: false
    pannable: false
    position: {x: 237, y: 149}
    removed: false
    selectable: true
    selected: false
}

When the nodes and edges are added to the graph, they are not rendered in the position in which they were when the graph was saved. I'm not sure what I'm doing wrong here. I've checked a couple of threads that mentioned using the 'preset' layout, but the way I'm implementing it doesn't seem to be working.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda