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

fix _setNodePositions (#193)

上级 c80a94bd
......@@ -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
......
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册