uber / react-vis

Data Visualization Components
https://uber.github.io/react-vis
MIT License
8.72k stars 834 forks source link

Can't change links color at Sankey chart #1275

Open morozovkirill opened 4 years ago

morozovkirill commented 4 years ago

I'm trying to change default blue links at Sankey chart with style option. But nothing happens. Could anybody help me?

        <Sankey
            nodePadding={0}
            margin={0}
            nodes={data.nodes}
            links={data.links}
            width={1720}
            height={860}
            style={{
                labels: {
                    fontSize: "18px",
                    fill: "rgba(255, 255, 255, .85)",
                },
                links: { stroke: "rgba(255, 255, 255, .5)" },
                rects: {
                    fill: "rgba(255, 255, 255, .5)",
                },
            }}
        />
procek69 commented 4 years ago

You need to update links structure, i.e.:

const links = [
    { source: 0, target: 4, value: 10, color: 'rgba(20,20,30,.3)' },
    { source: 1, target: 4, value: 20, color: 'rgba(90,90,90,.3)' },
    { source: 2, target: 4, value: 20, color: 'rgba(200,45,40,.3)' },
    { source: 3, target: 5, value: 4, color: 'rgb(45,70,40)' },
];
commesan commented 4 years ago

Documentation still suggests that you can use links in the style object, but this does not seem to be supported. That would seem a very basic feature to have.

In the most common case it doesn't seem te make sense to add styling on each datum of your data.

To keep data and style separate:

<Sankey nodes={data.nodes} links={data.links.map((d, i) => ({ ...d, color:'#df8305', opacity: 0.1 }))} />