d3-sankey
d3-sankey copied to clipboard
Support multiple orientations?
Seems out of scope for the library. You can center the container vertically.
Can you provide any more details? Or a working example where you'd like centering?
Thank you for your answer.
The value attribute of link array's item is set to 1.
The result like this image. https://pan.baidu.com/s/1XDIRTNsB0I7CfbLzLruqEA
Can the nodes be centered in the y direction?
@curran I think @limzgiser is asking for a option to display an vertical sankey diagram (But I'm not sure since his image won't load)... I'm building one for a project by simply swapping x
and y
values, but it's a bit tedious and makes the code hard to read / understand.
Also d3-sankey
does not implement a sankeyLinkVertical
, which I built myself using
function sankeyLinkVertical () {
return d3.linkVertical()
.source(function(d) { return [d.y0, d.source.x1]; })
.target(function(d) { return [d.y1, d.target.x0]; });
}
(Again: swapping x
and y
)
Yep, you can swap x and y to change the orientation of the Sankey diagram. That said it might be nice for the Sankey diagram to support orientations similar to https://github.com/d3/d3-hierarchy/issues/63, so I’ll re-interpret this issue as that.
If you want the nodes to be centered vertically within their columns, that’s not currently supported, but I expect you could just move the nodes into the middle manually by computing the total column size and then the desired node positions.
@mbostock @curran do you have any thoughts on the vertical orientation approach offered in #71 ?
Reviewed the PR at a high level. Generally looks good!
Thanks @curran !
Related https://github.com/d3/d3-hierarchy/issues/63.
I think I’d follow the approach there (and in d3-axis) and have aliases for the different orientations d3.sankeyUp, d3.sankeyDown, d3.sankeyLeft, d3.sankeyRight with the default d3.sankey = d3.sankeyRight.
But, I’m a little busy right now with other stuff so I don’t know when I’ll get a chance to review this.
@mbostock Great, that makes sense. I've implemented only two orientations (d3.sankeyHorizontal
and d3.sankeyVertical
) so far but the bottom-to-top and right-to-left use cases do make sense too. I'll add support for those (and update the orientation names) in the PR at some point soon.
@mbostock @curran Rendering for each of the four cardinal directions is now available in ~~#71~~ #110; these are provisionally exported as orientLeft, orientRight
by the library since there is currently a naming conflict with existing exports for sankeyLeft, sankeyRight, ...
(these relate to node alignment within the graph, rather than the rendering orientation of the overall diagram).
It's not the most elegant implementation and relies on some conditional behaviour -- for bottom-to-top rendering in particular -- and I'd welcome any suggestions for improvements.
@jayaddison Nice work. Wondering when this will be merged.