Skip to content

Commit

Permalink
Fix react flow custom nodes positioning (#795)
Browse files Browse the repository at this point in the history
  • Loading branch information
3keyroman authored Sep 4, 2024
1 parent da5a01b commit 0f1fec4
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/components/FlowChart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,21 @@ const getLayoutedElements = (nodes: CustomNode[], edges: Edge[], direction = 'TB

dagre.layout(dagreGraph);

nodes.forEach((node: CustomNode) => {
const updatedNodes = nodes.map((node: CustomNode) => {
const nodeWithPosition = dagreGraph.node(node.id);
node.targetPosition = isHorizontal ? Position.Left : Position.Top;
node.sourcePosition = isHorizontal ? Position.Right : Position.Bottom;
const currentNodeHeight = node.data?.description ? nodeHeight + 35 : nodeHeight;
node.position = {
x: nodeWithPosition.x - nodeWidth / 2,
y: nodeWithPosition.y - currentNodeHeight / 2,
return {
...node,
targetPosition: isHorizontal ? Position.Left : Position.Top,
sourcePosition: isHorizontal ? Position.Right : Position.Bottom,
position: {
x: nodeWithPosition.x - nodeWidth / 2,
y: nodeWithPosition.y - currentNodeHeight / 2,
},
};

return node;
});

return { nodes, edges };
return { nodes: updatedNodes, edges };
}
};
const FlowChartContent = ({
Expand Down

0 comments on commit 0f1fec4

Please sign in to comment.