scottysseus
scottysseus

Reputation: 2020

Cytoscape.js: calculate graph dimensions at current zoom level?

I would like to resize both a) the container DOM element and b) the zoom level based on the height of my graph.

Suppose I add nodes and edges dynamically to the graph. Given a maximum zoom level (zMax) and a maximum container height (cMax), I'd like to fit according to the following rules:

The problem is, I am not sure of any built-in functionality for calculating the height of the graph in pixels at the current zoom level. I suppose I could iterate over the nodes and find the lowest and highest y-values, but I am hoping there is a more efficient option.

Upvotes: 1

Views: 1433

Answers (1)

maxkfranz
maxkfranz

Reputation: 12250

You should use functions that return values in rendered (on-screen) co-ordinates.

See http://js.cytoscape.org/#notation/position

See also http://js.cytoscape.org/#eles.renderedBoundingBox

E.g. cy.elements().renderedBoundingBox().h is the rendered height of the entire graph.

Upvotes: 1

Related Questions