Skip to content

Commit

Permalink
[Layout Quality] Debounce layout quality metric
Browse files Browse the repository at this point in the history
  • Loading branch information
sim51 committed Jun 13, 2024
1 parent 6fda4be commit fcde127
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/core/layouts/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import connectedCloseness from "graphology-metrics/layout-quality/connected-closeness";
import { connectedCloseness } from "graphology-metrics/layout-quality";
import { debounce } from "lodash";

import { graphDatasetActions, graphDatasetAtom, sigmaGraphAtom } from "../graph";
import { dataGraphToFullGraph } from "../graph/utils";
Expand Down Expand Up @@ -107,13 +108,14 @@ layoutStateAtom.bind((layoutState, prevState) => {
const { computeLayoutQualityMetric } = layoutActions;

if (updatedQualityKeys.has("enabled")) {
const fn = debounce(computeLayoutQualityMetric, 500, { leading: true, maxWait: 500 });
if (layoutState.quality.enabled) {
computeLayoutQualityMetric();
sigmaGraphAtom.get().on("nodeAttributesUpdated", computeLayoutQualityMetric);
sigmaGraphAtom.get().on("eachNodeAttributesUpdated", computeLayoutQualityMetric);
sigmaGraphAtom.get().on("nodeAttributesUpdated", fn);
sigmaGraphAtom.get().on("eachNodeAttributesUpdated", fn);
} else {
sigmaGraphAtom.get().off("eachNodeAttributesUpdated", computeLayoutQualityMetric);
sigmaGraphAtom.get().off("nodeAttributesUpdated", computeLayoutQualityMetric);
sigmaGraphAtom.get().off("eachNodeAttributesUpdated", fn);
sigmaGraphAtom.get().off("nodeAttributesUpdated", fn);
}
}
});

0 comments on commit fcde127

Please sign in to comment.