plotly.js icon indicating copy to clipboard operation
plotly.js copied to clipboard

[sankey] color links with gradients

Open OliBravo opened this issue 6 years ago • 7 comments

Hi, I was looking for adding gradient to sankey links. I would like to reproduce a diagram like this: image

I'm highly interested in such an option for R, because I'm a developer of Shiny apps. At the moment, it would be sufficient for me to know a workaround solution, for example custom JS code I could use to add gradients after a sankey diagram is already rendered.

OliBravo avatar Nov 19 '18 09:11 OliBravo

This feature should be rolled in at the same time as we close https://github.com/plotly/plotly.js/issues/3318 .

screenshot_2019-01-23_12-04-53

antoinerg avatar Jan 23 '19 17:01 antoinerg

It looks like in your example @OliBravo the gradient specifically fades between the two node colors (plus some opacity). That's a nice effect - not as the default, but perhaps we can have that as an explicit option somewhere, rather than forcing you to explicitly specify both end colors for each link - although explicit colors everywhere should also be supported.

alexcjohnson avatar Jan 23 '19 19:01 alexcjohnson

Hi! Has this feature been added yet? I'd also like to include a gradient feature in my sankey

aesharpe avatar Jul 26 '19 20:07 aesharpe

I'm also interested in this feature.

mattsiler avatar Nov 11 '19 21:11 mattsiler

Was this ever implemented?

Jedevold avatar May 06 '21 17:05 Jedevold

I've found multiple examples of color links with gradients implementation using d3Sankey: https://stackoverflow.com/a/21208382 https://bl.ocks.org/micahstubbs/3c0cb0c0de021e0d9653032784c035e9 https://observablehq.com/@d3/sankey

Could someone give me some general insights on how to implement such functionality on a working plotly.js sankey diagram? Or is it easier to simply go directly to d3Sankey and avoid the hassle?

migupry avatar Jul 05 '22 03:07 migupry

@migupry note that plotly.js uses a fork of d3-sankey: https://github.com/plotly/d3-sankey - mainly this was done to switch how we draw links: d3-sankey draws a path from source to target, using stroke-width and stroke-color to set its size and color. Our fork draws the full link outline and uses fill-color. This allows us to avoid overlaps when several links travel in parallel, and lets us outline the links. But as a result we would need to re-implement gradient link colors. There would be two steps to getting this into plotly.js: (1) add the capability to https://github.com/plotly/d3-sankey - probably following the general pattern of how this was done in the original, but applying it to fill instead of stroke; if the only gradient allowed by the original is 'source-target', that seems like the main thing people are interested in but if we can do something more general and allow each link to specify its own gradient that would be even better. (2) expose this capability inside plotly.js

alexcjohnson avatar Jul 06 '22 12:07 alexcjohnson

@alexcjohnson I appreciate the explanation, I'd also like to take up the mantle on trying to fix this issue since this is something that I've had an issue with as well.

@antoinerg If there's any way you could look way back in time and tell me some of the roadblocks you ran into?

gregorywaynepower avatar Jul 06 '23 21:07 gregorywaynepower