From 4964437a06e4e9ee8ac66633da0ab92716a73c60 Mon Sep 17 00:00:00 2001 From: Jason Park Date: Thu, 23 Jun 2016 23:56:07 +0900 Subject: [PATCH] fix _setNodePositions (#193) --- js/module/tracer/directed_graph.js | 25 ++++++++++++++++--------- js/module/tracer/tracer.js | 9 --------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/js/module/tracer/directed_graph.js b/js/module/tracer/directed_graph.js index 434f60b..6e0553c 100644 --- a/js/module/tracer/directed_graph.js +++ b/js/module/tracer/directed_graph.js @@ -14,8 +14,6 @@ class DirectedGraphTracer extends Tracer { constructor(name) { super(name); - this.nodePositions = []; - if (this.isNew) initView(this); } @@ -45,11 +43,12 @@ class DirectedGraphTracer extends Tracer { return this; } - _setNodePositions(obj){ - for(var i = 0; i < obj.length; i++){ - this.nodePositions.push(obj[i]); - } - super.dirtyData(); + _setNodePositions(positions) { + this.manager.pushStep(this.capsule, { + type: 'setNodePositions', + positions: positions + }); + return this; } processStep(step, options) { @@ -57,6 +56,14 @@ class DirectedGraphTracer extends Tracer { case 'setTreeData': this.setTreeData.apply(this, step.arguments); break; + case 'setNodePositions': + $.each(this.graph.nodes(), (i, node) => { + if (i >= step.positions.length) return false; + const position = step.positions[i]; + node.x = position.x; + node.y = position.y; + }); + break; case 'visit': case 'leave': var visit = step.type == 'visit'; @@ -135,8 +142,8 @@ class DirectedGraphTracer extends Tracer { nodes.push({ id: this.n(i), label: '' + i, - x: (this.nodePositions[i]) ? this.nodePositions[i].x : .5 + Math.sin(currentAngle) / 2, - y: (this.nodePositions[i]) ? this.nodePositions[i].y : .5 + Math.cos(currentAngle) / 2, + x: .5 + Math.sin(currentAngle) / 2, + y: .5 + Math.cos(currentAngle) / 2, size: 1, color: this.color.default, weight: 0 diff --git a/js/module/tracer/tracer.js b/js/module/tracer/tracer.js index 7040f40..642c714 100644 --- a/js/module/tracer/tracer.js +++ b/js/module/tracer/tracer.js @@ -77,21 +77,12 @@ class Tracer { $name.text(name || this.defaultName); } - dirtyData(){ - this.isNew = true; - } - - cleanData(){ - this.isNew = false; - } - setData() { const data = toJSON(arguments); if (!this.isNew && this.lastData === data) { return true; } this.lastData = this.capsule.lastData = data; - this.cleanData(); return false; } -- GitLab