patrickfuller / jgraph

An embeddable webGL graph visualization library.
http://patrickfuller.github.io/jgraph
MIT License
133 stars 31 forks source link

Render multiple jgraph views on single page #10

Open fredhohman opened 7 years ago

fredhohman commented 7 years ago

Is it possible to render multiple jgraph views on one page? For example:

jgraph.create('.graph-left');
$.getJSON('graphs/lesmis.json', function (graph) {
    jgraph.draw(graph);
});

jgraph.create('.graph-right');
$.getJSON('graphs/lesmis.json', function (graph) {
    jgraph.draw(graph);
});

When I run this, the .graph-right div shows a jgraph, but .graph-left does not.

Thanks!

patrickfuller commented 7 years ago

You can deep copy the jgraph object to run independent canvases. Something like this should work:

var left, right;
left = $.extend({}, jgraph);
right = $.extend({}, jgraph);

left.create('.graph-left');
$.getJSON('graphs/lesmis.json', function (graph) {
    left.draw(graph);
});
right.create('.graph-right');
$.getJSON('graphs/lesmis.json', function (graph) {
    right.draw(graph);
});

Longer term, jgraph should be reorganized to make this easier.

fredhohman commented 7 years ago

Great, thanks!