d3-force-cluster-3d

A clustering force type for the d3-force-3d simulation engine.

Usage no npm install needed!

<script type="module">
  import d3ForceCluster3d from 'https://cdn.skypack.dev/d3-force-cluster-3d';
</script>

README

d3-force-cluster-3d

NPM package Build Size Dependencies

This is a 3D port of d3-force-cluster, a force type that attracts nodes toward a set of cluster centers.

This force plugin is compatible with d3-force-3d and can function in a one, two or three dimensional space.

Quick start

import d3ForceCluster from 'd3-force-cluster-3d';

or

d3.forceCluster = require('d3-force-cluster-3d');

or even

<script src="//unpkg.com/d3-force-cluster-3d"></script>

then

d3.forceSimulation()
    .nodes(<myNodes>)
    .force('cluster', d3.forceCluster()
        .centers(node => clusters[node.cluster])
    );

API reference

Method Description Default
centers([fn]) Getter/setter for the accessor function (fn(node)) to define each node's cluster center. All cluster centers should be defined as a radius and set of coordinates { radius, x, y, z }, according to the number of spatial dimensions in the simulation. node => ({ x: 0, y: 0, z: 0 })
strength([num]) Getter/setter for the force strength. The value must be within the [0,1] range. This parameter determines the attraction strength of each node to the specified cluster center. 0.1
centerInertia([num]) Getter/setter for the inertia of cluster center nodes. The value must be within the [0,1] range. Lower values (close to 0) result in cluster center nodes with lower inertia: they are easily pulled around by other nodes in the cluster. Higher values (close to 1) result in cluster center nodes that are moved very little by other nodes in the cluster. 0