diff --git a/editor/js/editor.js b/editor/js/editor.js index 493f70be80c9d3a5dc825ac441f54f4498009ed5..cc24322161303aded4172cccdaf0f864da3928b7 100644 --- a/editor/js/editor.js +++ b/editor/js/editor.js @@ -15,6 +15,7 @@ window.onload = function () { // Deactivate physics after a short delay setTimeout(() => { graph.stopPhysics(); + graph.storeCurrentData("Physics stopped"); }, STOP_PHYSICS_DELAY); }); }; @@ -64,6 +65,7 @@ function load() { .onLinkClick((link) => state.onLinkClick(link)); graph.onChangeCallbacks.push((data) => { + graphObj.cooldownTicks(0); graphObj.graphData(data); }); } diff --git a/editor/js/graph.js b/editor/js/graph.js index 1eab6fa76ec5edb79bb82483a87c6bc2d4337e01..cefc9a4b0b6c956a97ce3bdd7ffb90ec14408c66 100644 --- a/editor/js/graph.js +++ b/editor/js/graph.js @@ -17,6 +17,8 @@ const IMAGE_SRC = PLUGIN_PATH + "datasets/images/"; const LINK_PARAMS = [LINK_TYPE]; const NODE_PARAMS = [NODE_ID, NODE_LABEL, NODE_IMAGE, NODE_DESCRIPTION]; +const LINK_SIM_PARAMS = ["index"]; +const NODE_SIM_PARAMS = ["index", "x", "y", "vx", "vy", "fx", "fy"]; // Based on https://github.com/d3/d3-force#simulation_nodes const JSON_CONFIG = PLUGIN_PATH + "datasets/aud1.json"; @@ -41,7 +43,7 @@ class Graph extends ManagedData { this.triggerOnChange(); } - formatData(data) { + storableData(data) { return this.getCleanData(data, true); } @@ -151,7 +153,7 @@ class Graph extends ManagedData { ); } - getCleanData(data = undefined, positions = false) { + getCleanData(data = undefined, simulationParameters = false) { if (data === undefined) { data = this.data; } @@ -161,33 +163,33 @@ class Graph extends ManagedData { cleanData[GRAPH_NODES] = []; data[GRAPH_LINKS].forEach((link) => - cleanData[GRAPH_LINKS].push(this.getCleanLink(link)) + cleanData[GRAPH_LINKS].push(this.getCleanLink(link, simulationParameters)) ); data[GRAPH_NODES].forEach((node) => - cleanData[GRAPH_NODES].push(this.getCleanNode(node, positions)) + cleanData[GRAPH_NODES].push(this.getCleanNode(node, simulationParameters)) ); - console.log(cleanData); return cleanData; } - getCleanNode(node, positions) { + getCleanNode(node, simulationParameters) { var cleanNode = {}; NODE_PARAMS.forEach((param) => { cleanNode[param] = node[param]; }); - if (positions) { - cleanNode.fx = node.fx; - cleanNode.fy = node.fy; + if (simulationParameters) { + NODE_SIM_PARAMS.forEach((param) => { + cleanNode[param] = node[param]; + }); } return cleanNode; } - getCleanLink(link) { + getCleanLink(link, simulationParameters) { var cleanLink = {}; // Source and target nodes @@ -200,6 +202,12 @@ class Graph extends ManagedData { cleanLink[param] = link[param]; }); + if (simulationParameters) { + LINK_SIM_PARAMS.forEach((param) => { + cleanLink[param] = link[param]; + }); + } + return cleanLink; } diff --git a/editor/js/manageddata.js b/editor/js/manageddata.js index c83ddd735033027b7cb29219c427c28b50e2e373..d97d0d23889104c49ea805ff2997fcf0524be40f 100644 --- a/editor/js/manageddata.js +++ b/editor/js/manageddata.js @@ -36,12 +36,12 @@ class ManagedData { return true; } - formatData(data) { + storableData(data) { return data; } storeCurrentData(description) { - var formattedData = this.formatData(this.data); + var formattedData = this.storableData(this.data); this.history.unshift({ description: description, @@ -51,5 +51,6 @@ class ManagedData { // Forget about the currently stored potential future this.history.splice(0, this.historyPosition); this.historyPosition = 0; + console.log(this.history[0]); } }