Skip to content

Commit c21f03d

Browse files
Fix interactive layout
may still be having an issue with eclipse-elk/elk#1083
1 parent c3d1bb5 commit c21f03d

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "egraph-visualizer",
3-
"version": "2.0.5",
3+
"version": "2.0.6",
44
"repository": {
55
"type": "git",
66
"url": "git+https://github.com/egraphs-good/egraph-visualizer.git"

src/layout.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const interactiveOptions = {
4545
"elk.layered.layering.strategy": "INTERACTIVE",
4646
"elk.layered.nodePlacement.strategy": "INTERACTIVE",
4747
// Had to disable or leads to weird edges
48+
// "elk.layered.crossingMinimization.semiInteractive": "true",
4849
// "elk.layered.crossingMinimization.strategy": "INTERACTIVE",
4950
};
5051

@@ -364,18 +365,36 @@ function toELKNode(
364365
// and preserve the positions of the nodes that were already layed out
365366
elkRoot.layoutOptions = { ...elkRoot.layoutOptions, ...interactiveOptions };
366367
for (const elkClass of elkRoot.children) {
367-
const previousClass = layout.children.find(({ data }) => data.id === elkClass.id);
368+
const previousClass = layout.children.find(({ id }) => id === elkClass.id);
368369
if (!previousClass) {
369370
continue;
370371
}
371-
Object.assign(elkClass.layoutOptions!, interactiveOptions);
372+
elkClass.layoutOptions = { ...elkClass.layoutOptions, ...interactiveOptions };
372373
elkClass.x = previousClass.x;
373374
elkClass.y = previousClass.y;
375+
for (const elkCLassPort of elkClass.ports || []) {
376+
const previousPort = (previousClass.ports || []).find(({ id }) => id === elkCLassPort.id);
377+
if (!previousPort) {
378+
continue;
379+
}
380+
elkCLassPort.x = previousPort.x;
381+
elkCLassPort.y = previousPort.y;
382+
}
383+
374384
for (const elkNode of elkClass.children) {
375-
const previousNode = previousClass.children.find(({ data }) => data.id === elkNode.id);
385+
const previousNode = previousClass.children.find(({ id }) => id === elkNode.id);
376386
if (!previousNode) {
377387
continue;
378388
}
389+
for (const elkNodePort of elkNode.ports || []) {
390+
const previousPort = (previousNode.ports || []).find(({ id }) => id === elkNodePort.id);
391+
if (!previousPort) {
392+
continue;
393+
}
394+
elkNodePort.x = previousPort.x;
395+
elkNodePort.y = previousPort.y;
396+
}
397+
379398
elkNode.x = previousNode.x;
380399
elkNode.y = previousNode.y;
381400
}

0 commit comments

Comments
 (0)