samizdatco/arbor

Single-node graph

ZoltanLajosKis opened this issue · 10 comments

If I start off with a graph consisting of a single node, then the node will start running around like I was doing a Brownian motion simulation. Furthermore, if I later add nodes and edges to this graph, the initial node will stabilize in the center, but the new nodes and edges will not appear. Also, after this, firefox dies pretty soon because of low resources.

I'm using the basic example codes, with the following settings:
sys = arbor.ParticleSystem(1000, 600, 0.5);
sys.parameters({gravity:true});

To reproduce, in $(document). ... do:
sys.addNode('a')
window.setTimeout(add,3000);

and in add(), add additional elements:

function add() {
sys.addNode('b');
sys.addEdge('b', 'a');
}

I'm having this problem too. Very frustrating

Will offer a £25 bounty to anyone who can fix this to the satisfaction of the author, samizdatco

In the meantime I checked out d3.js. There the solution for the "jerking" problem seems to be that every node has an invisible edge connected to the center of the canvas. This makes sure that the graph tends to the center, while not losing on overall shape.

As for the rest of my problem, I wonder if it is caused by the jerking, or is completely independent.

Thanks Zoltan. Checking out d3.js now...

2011/10/7 Zoltán Lajos Kis
reply@reply.github.com:

In the meantime I checked out d3.js. There the solution for the "jerking" problem seems to be that every node has an invisible edge connected to the center of the canvas. This makes sure that the graph tends to the center, while not losing on overall shape.

As for the rest of my problem, I wonder if it is caused by the jerking, or is completely independent.

Reply to this email directly or view it on GitHub:
#12 (comment)

I am also experiencing this problem.

I've come up with a workaround that 'solves' the problem. This issue occurs when you are adding nodes dynamically, and not loading anything initially.

The resolution is as follows (I realize its hacky, but it 'works'):

var temp= {};
temp["initialNode"] = { 'color': 'red', 'shape': 'dot', 'label': '' };

var data = {
    nodes: temp,
    edges: {}
};
sys.graft(data);
setTimeout(function () {
    sys.pruneNode("initialNode");
}, 2000);

For whatever reason, it solved the problem for me

hay commented

Here's another solution taken from this stackoverflow post.

// We assume 'system' is your ParticleSystem

// First we need this function
function countNodes() {
    var count = 0;

    system.eachNode(function() {
        count++;
    });

    return count;
}

// Then, in the redraw() method of your renderer try this:
var friction = countNodes() === 1 ? 1.0 : 0.5;
system.parameters({ friction : friction });

Thanks very much for your sharing.
Now I have an extra problem in arborjs.
I add a text besides every edge,the text will be jittered if I dragged any node serval times and now the page will be crashed if I refresh it.
Have you met similar situations?Or some suggestions?
Thanks in advance!

Jianbin Wang

It's 2017 and I'm also having the single spastic node problem.. Is this project still alive (I realize the last commit is in 2012)?

i try to add a virtual node(color is white and label is '') when the node has only one, and obviously it works