This post describes how to build a very basic
circular packing with d3.js. In
this example, 8 nodes are represented by 8 circles of same size. You
can see many other examples in the
circular packing section of the
gallery. This example works with d3.js v4
and
v6
data
is pretty simple, each node
just have a name.
enter()
and append()
approach. All
circles are initialized with the same position: the center
of the svg
area.
d3.forceSimulation()
allows to
define the forces we want to apply to circles
forceCenter
), are slightly attracted one each
other (forceManyBody
), and overlapping is
avoided (forceCollide
).
tick
), node position is
updated