Skip to content

Commit

Permalink
fix(Topology): Fix ColaGroupLayout crash on add
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-phillips-18 committed Apr 5, 2023
1 parent 2418be1 commit 730aa16
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/module/src/layouts/BaseLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class BaseLayout implements Layout {
this.options = {
...LAYOUT_DEFAULTS,
onSimulationEnd: this.onSimulationEnd,
listenForChanges: true,
...options
};

Expand Down Expand Up @@ -174,7 +175,7 @@ export class BaseLayout implements Layout {

private startListening(): void {
const controller = this.graph.getController();
if (controller) {
if (controller && this.options.listenForChanges) {
controller.addEventListener(ADD_CHILD_EVENT, this.handleChildAdded);
controller.addEventListener(REMOVE_CHILD_EVENT, this.handleChildRemoved);
controller.addEventListener(ELEMENT_VISIBILITY_CHANGE_EVENT, this.handleElementVisibilityChange);
Expand Down
7 changes: 6 additions & 1 deletion packages/module/src/layouts/ColaGroupsLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ class ColaGroupsLayout extends ColaLayout implements Layout {
});
}

protected stopSimulation(): void {
super.stopSimulation();
this.childLayouts.forEach(layout => layout.stop());
}

protected createLayoutNode(node: Node, nodeDistance: number, index: number) {
return new ColaGroupsNode(node, nodeDistance, index);
}
Expand Down Expand Up @@ -119,7 +124,7 @@ class ColaGroupsLayout extends ColaLayout implements Layout {
edges: LayoutLink[],
groups: LayoutGroup[]
): BaseLayout {
const layout = new ColaGroupsLayout(graph, this.options);
const layout = new ColaGroupsLayout(graph, { ...this.options, listenForChanges: false });
layout.setupLayout(graph, nodes, edges, groups);
return layout;
}
Expand Down
1 change: 1 addition & 0 deletions packages/module/src/layouts/LayoutOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export interface LayoutOptions {
allowDrag: boolean;
layoutOnDrag: boolean;
onSimulationEnd?: () => void;
listenForChanges?: boolean;
}

0 comments on commit 730aa16

Please sign in to comment.