Skip to content
Snippets Groups Projects
Commit a84232f9 authored by Maximilian Giller's avatar Maximilian Giller
Browse files

Added simulation handling to Graph

parent a12d2826
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
......@@ -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() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment