Skip to content

Commit

Permalink
🐛 Use correct color for gradient in node color derivation
Browse files Browse the repository at this point in the history
  • Loading branch information
joao-m-santos committed Aug 31, 2023
1 parent b3111ae commit 0a4348e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const MultipleLevelsWithColorDerivationFromIncomingLinks: Story = {
}),
args: {
...DATASETS.MultipleLevelsWithColorDerivationFromIncomingLinks,
options: { gradient: true },
title: 'Color derivation from incoming links',
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,20 @@ const gradients = computed(() => {
if (!options.value.gradient || !graph.value) return;
return graph.value.links.reduce((acc, link) => {
const { source, target } = link;
const sourceColor = source.color || source.fallbackColor;
// If `deriveColorFromIncomingLinks`, use the source's color for the gradient
const targetColor = target.deriveColorFromIncomingLinks
? sourceColor
: target.color || target.fallbackColor;
acc[link.id] = {
source: link.source.color || link.source.fallbackColor,
target: link.target.color || link.target.fallbackColor,
x1: link.source.x1,
x2: link.target.x0,
source: sourceColor,
target: targetColor,
x1: source.x1,
x2: target.x0,
};
return acc;
}, {}) as Record<
Expand Down Expand Up @@ -327,7 +336,7 @@ const nodesDerivingColorFromIncomingLinks = computed(() => {
return subNodeDetails;
});
function getLinkStroke(link: SankeyLink<SankeyNodeProps, SankeyLinkProps>) {
function getLinkStroke(link: SankeyLink) {
return options.value.gradient && `url('#${chartID}_${link.id}')`;
}
Expand Down
1 change: 1 addition & 0 deletions packages/lib/src/docs/storybook-data/alluvial-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ const DATASETS = {
{
label: 'E',
value: 'E',
color: 'royalblue',
targets: [
{ node: 'G', value: 10 },
{ node: 'H', value: 5, color: 'darkteal' },
Expand Down

0 comments on commit 0a4348e

Please sign in to comment.