anvaka / VivaGraphJS

Graph drawing library for JavaScript
Other
3.75k stars 425 forks source link

Selecting where to place graph svg #97

Closed fpayer closed 9 years ago

fpayer commented 10 years ago

First off - This is a great graphing library. I've been searching for a while to find something that had physics and created consistent graphs. All the other force-driven graphing I have seen use math.random to place nodes.

I was wondering if there is a way to choose where to place the svg element when it gets added to the DOM. It looks the SVG will always get place inside the body tag. Is there a way for me to place it in a div?

fpayer commented 10 years ago

Also, is there a way to set the size of the svg during creation? If I try to do so after it is created, the elements inside the svg do not fit to the new dimensions.

Tatermen commented 10 years ago

To place the graph in a div, assuming the div is named 'diagram':

var renderer = Viva.Graph.View.renderer(graph, {
    graphics: graphics,
    layout: layout,
    container: document.getElementById('diagram'),
});
renderer.run();
anvaka commented 9 years ago

@fpayer the answer given by @Tatermen is correct. Vivagraph should also adjust its view based on window size. You can style parent container before attaching vivagraph to it. Or alternatively call reset() method of the renderer.