d3-sankey icon indicating copy to clipboard operation
d3-sankey copied to clipboard

Support multiple orientations?

Open limzgiser opened this issue 6 years ago • 11 comments

limzgiser avatar Apr 24 '18 01:04 limzgiser

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?

curran avatar Apr 24 '18 09:04 curran

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?

limzgiser avatar Apr 26 '18 04:04 limzgiser

@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)

leonardfischer avatar May 23 '18 09:05 leonardfischer

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 avatar Sep 01 '19 23:09 mbostock

@mbostock @curran do you have any thoughts on the vertical orientation approach offered in #71 ?

jayaddison avatar Jan 15 '20 10:01 jayaddison

Reviewed the PR at a high level. Generally looks good!

curran avatar Jan 15 '20 12:01 curran

Thanks @curran !

jayaddison avatar Jan 15 '20 12:01 jayaddison

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 avatar Jan 15 '20 17:01 mbostock

@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.

jayaddison avatar Jan 15 '20 20:01 jayaddison

@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 avatar Sep 10 '20 20:09 jayaddison

@jayaddison Nice work. Wondering when this will be merged.

Spenhouet avatar Jun 10 '22 21:06 Spenhouet