Fix horizontal node positions while scaling vertical

11 views Asked by At

I have a force layout applied to a Sigma graph. The horizontal elements are in fixed column positions, while the vertical varies.

I would like to preserve the horizontal positions when the graph gets short and wide, but Sigma will always scale the entire graph to a 1:1 aspect ratio.

How can I make the graph use the full container width without manually adjusting all of the x coordinates by some magic factor?

full size scaled smaller

1

There are 1 answers

0
technomage On

In order to solve this, I've removed all internal scaling and applied an aspect ratio to the Y component of all elements, and let the camera fit the graph to the view.

So whenever I'm setting the y attribute of a node, I divide by the aspectRatio of the sigma container (width / height), which effectively stretches or squashes the Y axis without affecting node shape.

Obviously, the node positions must be updated on any container resize.