vasturiano / d3-force-3d

Force-directed graph layout in 1D, 2D or 3D using velocity Verlet integration.
https://observablehq.com/@vasturiano/multi-dimensional-d3-force-simulation
MIT License
373 stars 54 forks source link

Clustering with forceRadial #10

Closed MaksZhukov closed 4 years ago

MaksZhukov commented 4 years ago

Can I set up clustering behavior for some nodes with help forceRadial for different positions? I see I can set x,y,z as value, not a callback for each node. If I can't, could you give me the best solutions to see some group of nodes around a group of x,y,zpositions?

vasturiano commented 4 years ago

@MaksZhukov the x, y and z methods do not support node accessor functions, only constant values. This is done to maintain consistency with d3-force.

What I would do is have multiple forceRadial forces in your system, one for each cluster with preset x,y,z focal points. To make sure each force only applies to nodes in that cluster, you can set 0 strength conditionally, like:

clusterNForce = forceRadial(10, ...clusterCoords)
  .strength(node => isInCluster(node) ? 0.1 : 0)
MaksZhukov commented 4 years ago

@vasturiano Thank you!