Skip to content

Commit

Permalink
Fix interactive layout
Browse files Browse the repository at this point in the history
may still be having an issue with eclipse-elk/elk#1083
  • Loading branch information
saulshanabrook committed Oct 23, 2024
1 parent c3d1bb5 commit c21f03d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "egraph-visualizer",
"version": "2.0.5",
"version": "2.0.6",
"repository": {
"type": "git",
"url": "git+https://github.com/egraphs-good/egraph-visualizer.git"
Expand Down
25 changes: 22 additions & 3 deletions src/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const interactiveOptions = {
"elk.layered.layering.strategy": "INTERACTIVE",
"elk.layered.nodePlacement.strategy": "INTERACTIVE",
// Had to disable or leads to weird edges
// "elk.layered.crossingMinimization.semiInteractive": "true",
// "elk.layered.crossingMinimization.strategy": "INTERACTIVE",
};

Expand Down Expand Up @@ -364,18 +365,36 @@ function toELKNode(
// and preserve the positions of the nodes that were already layed out
elkRoot.layoutOptions = { ...elkRoot.layoutOptions, ...interactiveOptions };
for (const elkClass of elkRoot.children) {
const previousClass = layout.children.find(({ data }) => data.id === elkClass.id);
const previousClass = layout.children.find(({ id }) => id === elkClass.id);
if (!previousClass) {
continue;
}
Object.assign(elkClass.layoutOptions!, interactiveOptions);
elkClass.layoutOptions = { ...elkClass.layoutOptions, ...interactiveOptions };
elkClass.x = previousClass.x;
elkClass.y = previousClass.y;
for (const elkCLassPort of elkClass.ports || []) {
const previousPort = (previousClass.ports || []).find(({ id }) => id === elkCLassPort.id);
if (!previousPort) {
continue;
}
elkCLassPort.x = previousPort.x;
elkCLassPort.y = previousPort.y;
}

for (const elkNode of elkClass.children) {
const previousNode = previousClass.children.find(({ data }) => data.id === elkNode.id);
const previousNode = previousClass.children.find(({ id }) => id === elkNode.id);
if (!previousNode) {
continue;
}
for (const elkNodePort of elkNode.ports || []) {
const previousPort = (previousNode.ports || []).find(({ id }) => id === elkNodePort.id);
if (!previousPort) {
continue;
}
elkNodePort.x = previousPort.x;
elkNodePort.y = previousPort.y;
}

elkNode.x = previousNode.x;
elkNode.y = previousNode.y;
}
Expand Down

0 comments on commit c21f03d

Please sign in to comment.