提交 4964437a 编写于 作者: J Jason Park

fix _setNodePositions (#193)

上级 c80a94bd
...@@ -14,8 +14,6 @@ class DirectedGraphTracer extends Tracer { ...@@ -14,8 +14,6 @@ class DirectedGraphTracer extends Tracer {
constructor(name) { constructor(name) {
super(name); super(name);
this.nodePositions = [];
if (this.isNew) initView(this); if (this.isNew) initView(this);
} }
...@@ -45,11 +43,12 @@ class DirectedGraphTracer extends Tracer { ...@@ -45,11 +43,12 @@ class DirectedGraphTracer extends Tracer {
return this; return this;
} }
_setNodePositions(obj){ _setNodePositions(positions) {
for(var i = 0; i < obj.length; i++){ this.manager.pushStep(this.capsule, {
this.nodePositions.push(obj[i]); type: 'setNodePositions',
} positions: positions
super.dirtyData(); });
return this;
} }
processStep(step, options) { processStep(step, options) {
...@@ -57,6 +56,14 @@ class DirectedGraphTracer extends Tracer { ...@@ -57,6 +56,14 @@ class DirectedGraphTracer extends Tracer {
case 'setTreeData': case 'setTreeData':
this.setTreeData.apply(this, step.arguments); this.setTreeData.apply(this, step.arguments);
break; 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 'visit':
case 'leave': case 'leave':
var visit = step.type == 'visit'; var visit = step.type == 'visit';
...@@ -135,8 +142,8 @@ class DirectedGraphTracer extends Tracer { ...@@ -135,8 +142,8 @@ class DirectedGraphTracer extends Tracer {
nodes.push({ nodes.push({
id: this.n(i), id: this.n(i),
label: '' + i, label: '' + i,
x: (this.nodePositions[i]) ? this.nodePositions[i].x : .5 + Math.sin(currentAngle) / 2, x: .5 + Math.sin(currentAngle) / 2,
y: (this.nodePositions[i]) ? this.nodePositions[i].y : .5 + Math.cos(currentAngle) / 2, y: .5 + Math.cos(currentAngle) / 2,
size: 1, size: 1,
color: this.color.default, color: this.color.default,
weight: 0 weight: 0
......
...@@ -77,21 +77,12 @@ class Tracer { ...@@ -77,21 +77,12 @@ class Tracer {
$name.text(name || this.defaultName); $name.text(name || this.defaultName);
} }
dirtyData(){
this.isNew = true;
}
cleanData(){
this.isNew = false;
}
setData() { setData() {
const data = toJSON(arguments); const data = toJSON(arguments);
if (!this.isNew && this.lastData === data) { if (!this.isNew && this.lastData === data) {
return true; return true;
} }
this.lastData = this.capsule.lastData = data; this.lastData = this.capsule.lastData = data;
this.cleanData();
return false; return false;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册