Skip to content

Commit

Permalink
[layout] reduce quality metric impact
Browse files Browse the repository at this point in the history
review event which triggers layout metric calculation
the updateNode event scope was too large so we created a nodesDragged one
  • Loading branch information
paulgirard committed Oct 7, 2024
1 parent f73ced0 commit 53e6924
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/core/layouts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,26 @@ const gridEnabledAtom = derivedAtom(layoutStateAtom, (value) => pick(value.quali
gridEnabledAtom.bindEffect((connectedClosenessSettings) => {
if (!connectedClosenessSettings.enabled) return;

// Compute the layout quality metric when node's position changed
//Compute the layout quality metric when node's position changed
const { computeLayoutQualityMetric } = layoutActions;
const fn = debounce(computeLayoutQualityMetric, 300, { leading: true, maxWait: 300 });

computeLayoutQualityMetric();
const sigmaGraph = sigmaGraphAtom.get();
// this event is triggered when sigma data are updated by the derived atom mechanism through a graph import
// this event is triggered when a sync layout has been applied
// this is a custom event
(sigmaGraph as EventEmitter).on("graphImported", fn);

// this event is triggered by user manually changing node positions by dragging node
sigmaGraph.on("nodeAttributesUpdated", fn);
// this is a custom event
(sigmaGraph as EventEmitter).on("nodesDragged", fn);

// this event is triggered by async layout
sigmaGraph.on("eachNodeAttributesUpdated", fn);

return () => {
(sigmaGraph as EventEmitter).off("graphImported", fn);
(sigmaGraph as EventEmitter).off("nodesDragged", fn);
sigmaGraph.off("eachNodeAttributesUpdated", fn);
sigmaGraph.off("nodeAttributesUpdated", fn);
};
});

0 comments on commit 53e6924

Please sign in to comment.