1

I'm using the D3 plug-in to make a Sankey diagram, and would like to add labels above each column of nodes. Something like this:enter image description here

Is there a function in the sankey object that can return the location of the nodes?

var sankey = d3.sankey()
    .nodeWidth(15)
    .nodePadding(10)
    .size([width, height]);

I'm following the pattern here: http://bost.ocks.org/mike/sankey/

mike
  • 22,931
  • 31
  • 77
  • 100
  • If you look at the source code of the example, you'll see that `energy.nodes` provides the data for the coloured rectangles, with the positions determined by the `x` and `y` attributes of the elements. You can use this same information to place the labels. – Lars Kotthoff Dec 05 '14 at 19:52
  • Thanks -- I was hoping there was a sharp way to get the position of all "columns" that wasn't looping through the data, but that's certainly a plausible option. – mike Dec 05 '14 at 20:00
  • You could filter this data to get only distinct `x` values, but there's no way to get just the different "levels" with the current implementation. – Lars Kotthoff Dec 05 '14 at 20:05

0 Answers0