Skip to content

Commit 3a9d866

Browse files
fix(colors): Multiple charts using ContinuousColorsLegendSvg share the same legend color scale (#2695)
Co-authored-by: Hugh Williams <[email protected]>
1 parent af22689 commit 3a9d866

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/legends/src/svg/ContinuousColorsLegendSvg.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ export const ContinuousColorsLegendSvg = ({
5252

5353
const theme = useTheme()
5454

55+
// remove commas, parentheses and spaces from stop color, this will then create a unique id depending on which color scheme you use.
56+
// so if you have two or more heatmaps on a single page with differing color schemes the legend will be correct for each.
5557
const id = `ContinuousColorsLegendSvgGradient.${direction}.${colorStops
56-
.map(stop => stop.offset)
58+
.map(stop => `${stop.stopColor.replace(/[(),\s]/g, '')}.${stop.offset}`)
5759
.join('_')}`
5860

5961
return (

storybook/stories/heatmap/HeatMap.stories.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ export const CustomTooltip: Story = {
100100
),
101101
}
102102

103+
export const MultipleHeatMaps: Story = {
104+
render: () => (
105+
<>
106+
<HeatMapWithColor colorConfig={'sequential (full domain)'} />
107+
<HeatMapWithColor colorConfig={'diverging at 0.5'} />
108+
</>
109+
),
110+
}
111+
103112
const customColorConfigs = {
104113
'sequential (full domain)': {
105114
type: 'sequential',

0 commit comments

Comments
 (0)