diff --git a/editor/js/editor.js b/editor/js/editor.js index cdd8d53d46ecac85feedd0d19d4327c9f681f062..c9fd936be1a2e48fac2600bff31a0e599abe6331 100644 --- a/editor/js/editor.js +++ b/editor/js/editor.js @@ -26,11 +26,7 @@ window.onload = function () { graph = new Graph.Graph(graphConfig); load(); - // Deactivate physics after a short delay - setTimeout(() => { - graph.stopPhysics(); - graph.storeCurrentData("Physics stopped"); - }, graph.physicsDelay); + graph.restartSimulation(); }); }; @@ -71,4 +67,6 @@ function load() { graphObj.cooldownTicks(0); graphObj.graphData(data); }); + + graph.setRenderer(graphObj); } diff --git a/editor/js/graph.js b/editor/js/graph.js index d3a6c276b411d3b5a6b39b70a2dc9868eafada37..d1949d2217b9cad4f0519d3256ab20531e1e9226 100644 --- a/editor/js/graph.js +++ b/editor/js/graph.js @@ -46,10 +46,36 @@ export class Graph extends ManagedData { this.calculateLinkTypes(); this.onChangeCallbacks = []; this.physicsDelay = STOP_PHYSICS_DELAY; + this.physicsStopTimeoutId = undefined; + this.graphRenderer = undefined; + } + + setRenderer(graphRenderer) { + this.graphRenderer = graphRenderer; } restartSimulation() { + if (this.physicsStopTimeoutId !== undefined) { + clearTimeout(this.physicsStopTimeoutId); + } + + if (this.graphRenderer !== undefined) { + this.data[GRAPH_NODES].forEach((n) => { + n.x /= 10; + n.y /= 10; + n.fx = undefined; + n.fy = undefined; + }); + + this.graphRenderer.d3ReheatSimulation(); + } + // Deactivate physics after a short delay + this.physicsStopTimeoutId = setTimeout(() => { + this.stopPhysics(); + this.storeCurrentData("Physics stopped"); + this.physicsStopTimeoutId = undefined; + }, this.physicsDelay); } triggerOnChange() {