Skip to content

Commit 5cb243f

Browse files
committed
Make ELK -> ReactFlow conversion recursive
1 parent 7398731 commit 5cb243f

File tree

1 file changed

+18
-12
lines changed
  • rust/cubesql/cubesql/egraph-debug-template/src

1 file changed

+18
-12
lines changed

rust/cubesql/cubesql/egraph-debug-template/src/index.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,25 +111,31 @@ function layout(
111111
edges: elkEdges,
112112
};
113113

114+
function elk2flow(node, flattenChildren, withStyle) {
115+
node.position = { x: node.x, y: node.y };
116+
if (withStyle) {
117+
node.style = {
118+
...node.style,
119+
width: node.width,
120+
height: node.height,
121+
};
122+
}
123+
flattenChildren.push(node);
124+
(node.children ?? []).forEach((child) => {
125+
// only depth 0 get styles
126+
elk2flow(child, flattenChildren, false);
127+
});
128+
delete node.children;
129+
}
130+
114131
const elk = new ELK();
115132
return elk.layout(graph).then(({ children }) => {
116133
// By mutating the children in-place we saves ourselves from creating a
117134
// needless copy of the nodes array.
118135
const flattenChildren = [];
119136

120137
children.forEach((node) => {
121-
node.position = { x: node.x, y: node.y };
122-
node.style = {
123-
...node.style,
124-
width: node.width,
125-
height: node.height,
126-
};
127-
flattenChildren.push(node);
128-
node.children.forEach((child) => {
129-
child.position = { x: child.x, y: child.y };
130-
flattenChildren.push(child);
131-
});
132-
delete node.children;
138+
elk2flow(node, flattenChildren, true);
133139
});
134140

135141
setNodes(flattenChildren);

0 commit comments

Comments
 (0)