Le Sparte
Le Sparte

Reputation: 163

D3.js (v5 or v6) : get initial zoom position and scale to fit force layout

In d3 v5 (or 6!) what’s the code needed to

  1. get my force layout to be automatically centered in my SVG (on start at least)?
  2. get the zoom level defined dynamically to keep all nodes inside the visible SVG (on start at least)?

I’m considering to check the position of each node at each frame and react accordingly, but it looks way too ressource consuming.

Many thanks for your help!

Upvotes: 1

Views: 2626

Answers (0)

Related Questions