diff --git a/js/module/tracer/directed_graph.js b/js/module/tracer/directed_graph.js index 702dce257431d67384a2e0b1dbf799db54b87300..434f60b309806ecff6e8f1541dc6a6244b53f89a 100644 --- a/js/module/tracer/directed_graph.js +++ b/js/module/tracer/directed_graph.js @@ -14,6 +14,8 @@ class DirectedGraphTracer extends Tracer { constructor(name) { super(name); + this.nodePositions = []; + if (this.isNew) initView(this); } @@ -43,6 +45,13 @@ class DirectedGraphTracer extends Tracer { return this; } + _setNodePositions(obj){ + for(var i = 0; i < obj.length; i++){ + this.nodePositions.push(obj[i]); + } + super.dirtyData(); + } + processStep(step, options) { switch (step.type) { case 'setTreeData': @@ -116,7 +125,6 @@ class DirectedGraphTracer extends Tracer { setData(G, undirected) { if (super.setData.apply(this, arguments)) return true; - this.graph.clear(); const nodes = []; const edges = []; @@ -127,8 +135,8 @@ class DirectedGraphTracer extends Tracer { nodes.push({ id: this.n(i), label: '' + i, - x: .5 + Math.sin(currentAngle) / 2, - y: .5 + Math.cos(currentAngle) / 2, + 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, size: 1, color: this.color.default, weight: 0 diff --git a/js/module/tracer/tracer.js b/js/module/tracer/tracer.js index 642c714164a5307175514f1f4f6f64aa544d6c97..7040f4030a603201de5cdc27ebb232175bca77c2 100644 --- a/js/module/tracer/tracer.js +++ b/js/module/tracer/tracer.js @@ -77,12 +77,21 @@ 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; }