question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dagre auto-layout not working properly after editing the layout ( delete node, and insert new node in-between nodes )

See original GitHub issue

Describe the Bug

I’m building a binary tree structure node visualisation web-app I want to be able to re-render all nodes with the new position after deleting a node

Current behaviour On adding a new node after deleting a node, the new node jumps to a new position as the deleted node is still present

code sample

const CustomNodeFlow = () => {
  const dispatch = useAppDispatch();
  const { elements } = useAppSelector((state) => state.flowgraphSlice);

  const layeredElements = useMemo(
    () => getLayoutedElements(elements, 'LR'),
    [elements]
  );

  const onElementClick = (
    event: React.MouseEvent<Element, MouseEvent>,
    element: Node | Edge
  ) => {
    if (element.type === NodeTypesEnum.DecisionNode) return;
    dispatch(setSelectedNode(element as Node));
  };

  return (
    <ReactFlow
      elements={layeredElements}
      nodeTypes={nodeTypes}
      onElementClick={onElementClick}
      defaultZoom={0.75}
    >
      <Background variant={BackgroundVariant.Dots} gap={24} size={0.5} />
      <Controls />
    </ReactFlow>
  );
};

Your Example Website or App

No response

Steps to Reproduce the Bug or Issue

On adding a new node after deleting a node, the new node jumps to a new position as the deleted node is still present

Expected behavior

The graph should re-render nodes with newly calculated position

Screenshots or Videos

https://www.loom.com/share/e918c73a3e534e1f8c7fb72b159fff16

Platform

  • OS: macOS
  • Browser: Chrome, Safari, Firefox
  • Version: 10

Additional context

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jayanthbondicommented, Jul 28, 2022

Hi @dexkode4 , I’m facing the similar issue, could you please share the codesandbox link if you have it.

1reaction
raartscommented, Mar 23, 2022

Seen this happen in my setup too, but it wasn’t an issue for me. My guess: you will have to study dagre internals if you want to sort this out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

error when autolayout · Issue #205 · dagrejs/dagre - GitHub
The case is : we use graphlib to create a graph g g.setNode("boss1", { label: "boss1", ... when we create edge which from...
Read more >
Dagre Tree Example - React Flow
This example shows how you can integrate dagre.js with React Flow to create simple tree layouts. Good alternatives to dagre are d3-hierarchy or...
Read more >
Adding and Removing Nodes in D3js Force Graph
Now let's make that function that will add a node to the layout once the graph has been initialized! newNodeData is an object...
Read more >
GEPHI – Introduction to Network Analysis and Visualization ...
The size of a node depends on the value of its “degree centrality” ... Let's add some more information to our graph by...
Read more >
Aspire V9.0 User Manual - Vectric
When you create or open a two-sided project, Aspire will display two new icons ... Node Editing to fine tune the vectors of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found