From 8b6e3321e7e60f681e63d149d652a4a0e4cc39cf Mon Sep 17 00:00:00 2001 From: ZhangGe6 Date: Sun, 24 Apr 2022 20:20:42 +0800 Subject: [PATCH] delete and refresh graph done --- static/view-sidebar.js | 9 +++++++++ static/view.js | 28 ++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/static/view-sidebar.js b/static/view-sidebar.js index bc7a28d..70650a4 100644 --- a/static/view-sidebar.js +++ b/static/view-sidebar.js @@ -206,6 +206,7 @@ sidebar.NodeSidebar = class { this._addButton('Delete'); this._addButton('Recover'); this._addButton('Download'); + this._addButton('RefreshGraph'); // console.log(this._host._view._graph._nodes) // console.log(node) @@ -331,6 +332,14 @@ sidebar.NodeSidebar = class { }); } + if (title === 'RefreshGraph') { + // console.log('pressed') + buttonElement.addEventListener('click', () => { + this._host._view._updateGraph(); + }); + } + + } diff --git a/static/view.js b/static/view.js index 105add2..04a3ba0 100644 --- a/static/view.js +++ b/static/view.js @@ -468,13 +468,25 @@ view.View = class { } _updateGraph(model, graphs) { + console.log('view._updateGraph() is called') // console.log(model); // console.log(graphs); const lastModel = this._model; const lastGraphs = this._graphs; - this._model = model; - this._graphs = graphs; + // console.log(lastNodeState) + // update graph if and only if `model` and `graphs` are provided + if (model && graphs) { + this._model = model; + this._graphs = graphs; + } const graph = this.activeGraph; + + this.lastViewGraph = this._graph; + // if (lastViewGraph) { + // console.log(this._graph) + // this.lastModelNodeName2State = lastViewGraph._modelNodeName2State; + // } + // console.log("_updateGraph is called"); return this._timeout(100).then(() => { if (graph && graph != lastGraphs[0]) { @@ -569,7 +581,14 @@ view.View = class { const viewGraph = new view.Graph(this, model, groups, options); // console.log(viewGraph) + if (this.lastViewGraph) { + console.log(this.lastViewGraph._modelNodeName2ViewNode) + console.log('node state of lastViewGraph is loaded') + viewGraph._modelNodeName2State = this.lastViewGraph._modelNodeName2State; + } + console.log(viewGraph._modelNodeName2State) viewGraph.add(graph); + // console.log(viewGraph._arguments) // Workaround for Safari background drag/zoom issue: @@ -917,6 +936,11 @@ view.Graph = class extends grapher.Graph { for (const node of graph.nodes) { // console.log(node) + // My code + if (this._modelNodeName2State.get(node.name) == 'Deleted') { + console.log(this._modelNodeName2State.get(node.name)) + continue; + } const viewNode = this.createNode(node);