Skip to content

Commit 7ed3ae0

Browse files
authored
feat(bar): Add getColor to props provided to custom layers (#2651)
* Add colors and colorBy to common props to enable access to colors in a custom layer * Pass getColor instead * Fix type
1 parent 1ce58a5 commit 7ed3ae0

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

packages/bar/src/Bar.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ const InnerBar = <RawDatum extends BarDatum>({
133133
toggleSerie,
134134
legendsWithData,
135135
barTotals,
136+
getColor,
136137
} = useBar<RawDatum>({
137138
indexBy,
138139
label,
@@ -409,6 +410,7 @@ const InnerBar = <RawDatum extends BarDatum>({
409410
onClick,
410411
onMouseEnter,
411412
onMouseLeave,
413+
getColor,
412414
}),
413415
[
414416
commonProps,
@@ -427,6 +429,7 @@ const InnerBar = <RawDatum extends BarDatum>({
427429
onClick,
428430
onMouseEnter,
429431
onMouseLeave,
432+
getColor,
430433
]
431434
)
432435

packages/bar/src/BarCanvas.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ const InnerBarCanvas = <RawDatum extends BarDatum>({
218218
shouldRenderBarLabel,
219219
legendsWithData,
220220
barTotals,
221+
getColor,
221222
} = useBar<RawDatum>({
222223
indexBy,
223224
label,
@@ -292,6 +293,7 @@ const InnerBarCanvas = <RawDatum extends BarDatum>({
292293
onClick,
293294
onMouseEnter,
294295
onMouseLeave,
296+
getColor,
295297
}),
296298
[
297299
borderRadius,
@@ -314,6 +316,7 @@ const InnerBarCanvas = <RawDatum extends BarDatum>({
314316
onClick,
315317
onMouseEnter,
316318
onMouseLeave,
319+
getColor,
317320
]
318321
)
319322

packages/bar/src/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
Theme,
1313
ValueFormat,
1414
} from '@nivo/core'
15-
import { InheritedColorConfig, OrdinalColorScaleConfig } from '@nivo/colors'
15+
import { InheritedColorConfig, OrdinalColorScale, OrdinalColorScaleConfig } from '@nivo/colors'
1616
import { LegendProps } from '@nivo/legends'
1717
import { AnyScale, ScaleSpec, ScaleBandSpec } from '@nivo/scales'
1818
import { SpringValues } from '@react-spring/web'
@@ -124,6 +124,7 @@ interface BarCustomLayerBaseProps<RawDatum>
124124

125125
xScale: AnyScale
126126
yScale: AnyScale
127+
getColor: OrdinalColorScale<ComputedDatum<RawDatum>>
127128
}
128129

129130
export interface BarCustomLayerProps<RawDatum>

0 commit comments

Comments
 (0)