2

I am having d3.forceSimulation and I have set link distance and forceCenter and so on. But can I somehow know how wide and height the chart will be? Like if the link distance is 150 and centered, maximum w/h would be 150? I don't know how nodes will be connected in advance.

 var simulation = d3.forceSimulation()
                .force("link", d3.forceLink().id(function (d) {
                    return d.id;
                }).distance(150).strength(2))
                .force("charge", d3.forceManyBody())
                .force("center", d3.forceCenter(width / 2, height / 2));
13Akaren
  • 225
  • 3
  • 16
  • 1
    The force layout is independent of any rendering: it occupies the space needed to satisfy the forces as best as possible. You can apply a [bounding force/constraint](https://stackoverflow.com/q/9573178/7106086), or [auto zoom](https://stackoverflow.com/q/16236600/7106086). Otherwise, if you have nontrivial and dynamic data you won't know the extent of the nodes until you run the force. – Andrew Reid Jul 27 '21 at 00:20

0 Answers0