ignacioola / insights

A JavaScript library to visualize and navigate graphs
200 stars 42 forks source link

Default zoom level to fit inside element #7

Open khanh703 opened 9 years ago

khanh703 commented 9 years ago

Is there a way to set the default zoom on.rendered so that graph fits inside element?

khanh703 commented 9 years ago

So I'm able to get the desired zoom value that will allow for the entire graph to fit inside my container. While the default zoom works to scale the graph to fit, the graph remains off centered, running graph.center(0) to center on the root node does not always work as there are always a few nodes that expands past the majority of the clusters. I can play around with the translation values, but I have no idea how these values (-1018.40185546875,-295.5054626464844) translates to graph being placed in the center of my container. How are the translate values defined?

default_zoom = (element.node().getBBox().height > element.node().getBBox().width) ? element.attr("height") / ( element.node().getBBox().height) :  element.attr("width")  / ( element.node().getBBox().width);
graph.zoom(default_zoom);