javascriptobservablehq

access node data and fill accordingly on observablehq forcegraph


I am accessing the following sample page on observablehq. Force directed graph

At the moment the page colors node based on group.

I am struggling to do the following:

Any help?

Thanks


Solution

  • The group accessor allows you to access each node, in the example it is accessing the group property of the node: nodeGroup: d => d.group.

    The example also uses a ordinal scale, if you want to use continuous values from your nodes you could fork the example (or copy the whole function) and change the d3.scaleOrdinal to something like d3.scaleLinear