strathausen / dracula

JavaScript layout and representation of connected graphs.
https://www.graphdracula.net
MIT License
836 stars 132 forks source link

Dynamically add nodes or edges #22

Open alexfrancavilla opened 11 years ago

alexfrancavilla commented 11 years ago

Hi, I need to dynamically add stuff to the canvas but all aproaches I try fail.

$('#asd').click(function() {
    ggg.addEdge("A3-1","S1", {  });
});

Also tried to clear the existing canvas and redraw it entirely (failed also)

$('#asd').click(function() {
    $('#canvas').html('');
    ggg.addEdge("A3-1","S1", {  });
    var layouter = new Graph.Layout.Spring(ggg);
    var renderer = new Graph.Renderer.Raphael('canvas', ggg, width, height);
});

The nodes are correct and adding the edge on initialization works fine, is this a bug in dracula?

monomon commented 11 years ago

Seems correct to me... is there a specific reason why you are passing the empty object as third argument? No time to try this right now, but try removing it.

Also, if I remember correctly I had to manually redraw the edges right after adding them:

for (var i = 0; i < g.graph.edges.length; i++) {
    g.drawEdge(g.graph.edges[i]);
}

Let me know if this works.