提交 50b87f6d 编写于 作者: K Kevin Nadro

Allowing for custom node positions on graphs

Can add custom (x,y) positions for all the nodes in a graph!  This code
doesn’t not work or effect the graphs that are “trees” i.e using
setTreeData.
上级 85d88070
......@@ -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
......
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册