Skip to content

Commit

Permalink
feat(bar): Add getColor to props provided to custom layers (#2651)
Browse files Browse the repository at this point in the history
* Add colors and colorBy to common props to enable access to colors in a custom layer

* Pass getColor instead

* Fix type
  • Loading branch information
lemps authored Oct 24, 2024
1 parent 1ce58a5 commit 7ed3ae0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/bar/src/Bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ const InnerBar = <RawDatum extends BarDatum>({
toggleSerie,
legendsWithData,
barTotals,
getColor,
} = useBar<RawDatum>({
indexBy,
label,
Expand Down Expand Up @@ -409,6 +410,7 @@ const InnerBar = <RawDatum extends BarDatum>({
onClick,
onMouseEnter,
onMouseLeave,
getColor,
}),
[
commonProps,
Expand All @@ -427,6 +429,7 @@ const InnerBar = <RawDatum extends BarDatum>({
onClick,
onMouseEnter,
onMouseLeave,
getColor,
]
)

Expand Down
3 changes: 3 additions & 0 deletions packages/bar/src/BarCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ const InnerBarCanvas = <RawDatum extends BarDatum>({
shouldRenderBarLabel,
legendsWithData,
barTotals,
getColor,
} = useBar<RawDatum>({
indexBy,
label,
Expand Down Expand Up @@ -292,6 +293,7 @@ const InnerBarCanvas = <RawDatum extends BarDatum>({
onClick,
onMouseEnter,
onMouseLeave,
getColor,
}),
[
borderRadius,
Expand All @@ -314,6 +316,7 @@ const InnerBarCanvas = <RawDatum extends BarDatum>({
onClick,
onMouseEnter,
onMouseLeave,
getColor,
]
)

Expand Down
3 changes: 2 additions & 1 deletion packages/bar/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
Theme,
ValueFormat,
} from '@nivo/core'
import { InheritedColorConfig, OrdinalColorScaleConfig } from '@nivo/colors'
import { InheritedColorConfig, OrdinalColorScale, OrdinalColorScaleConfig } from '@nivo/colors'
import { LegendProps } from '@nivo/legends'
import { AnyScale, ScaleSpec, ScaleBandSpec } from '@nivo/scales'
import { SpringValues } from '@react-spring/web'
Expand Down Expand Up @@ -124,6 +124,7 @@ interface BarCustomLayerBaseProps<RawDatum>

xScale: AnyScale
yScale: AnyScale
getColor: OrdinalColorScale<ComputedDatum<RawDatum>>
}

export interface BarCustomLayerProps<RawDatum>
Expand Down

0 comments on commit 7ed3ae0

Please sign in to comment.