From 284b54741789e8a30200db8e16386b317fb2f41b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lembit=20L=C3=B5pp?= Date: Tue, 24 Sep 2024 10:36:15 +0300 Subject: [PATCH 1/3] Add colors and colorBy to common props to enable access to colors in a custom layer --- packages/bar/src/Bar.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/bar/src/Bar.tsx b/packages/bar/src/Bar.tsx index 797b559e4..60fdef6be 100644 --- a/packages/bar/src/Bar.tsx +++ b/packages/bar/src/Bar.tsx @@ -250,6 +250,8 @@ const InnerBar = ({ () => ({ borderRadius, borderWidth, + colorBy, + colors, enableLabel, isInteractive, labelSkipWidth, @@ -269,6 +271,8 @@ const InnerBar = ({ [ borderRadius, borderWidth, + colorBy, + colors, enableLabel, getTooltipLabel, isInteractive, From 9a8ecb7cad650dcc116e715ae797c35c365c380b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lembit=20L=C3=B5pp?= Date: Tue, 24 Sep 2024 11:27:07 +0300 Subject: [PATCH 2/3] Pass getColor instead --- packages/bar/src/Bar.tsx | 7 +++---- packages/bar/src/BarCanvas.tsx | 3 +++ packages/bar/src/types.ts | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/bar/src/Bar.tsx b/packages/bar/src/Bar.tsx index 60fdef6be..0513bd8bc 100644 --- a/packages/bar/src/Bar.tsx +++ b/packages/bar/src/Bar.tsx @@ -133,6 +133,7 @@ const InnerBar = ({ toggleSerie, legendsWithData, barTotals, + getColor, } = useBar({ indexBy, label, @@ -250,8 +251,6 @@ const InnerBar = ({ () => ({ borderRadius, borderWidth, - colorBy, - colors, enableLabel, isInteractive, labelSkipWidth, @@ -271,8 +270,6 @@ const InnerBar = ({ [ borderRadius, borderWidth, - colorBy, - colors, enableLabel, getTooltipLabel, isInteractive, @@ -413,6 +410,7 @@ const InnerBar = ({ onClick, onMouseEnter, onMouseLeave, + getColor, }), [ commonProps, @@ -431,6 +429,7 @@ const InnerBar = ({ onClick, onMouseEnter, onMouseLeave, + getColor, ] ) diff --git a/packages/bar/src/BarCanvas.tsx b/packages/bar/src/BarCanvas.tsx index 27459641e..38e93a664 100644 --- a/packages/bar/src/BarCanvas.tsx +++ b/packages/bar/src/BarCanvas.tsx @@ -218,6 +218,7 @@ const InnerBarCanvas = ({ shouldRenderBarLabel, legendsWithData, barTotals, + getColor, } = useBar({ indexBy, label, @@ -292,6 +293,7 @@ const InnerBarCanvas = ({ onClick, onMouseEnter, onMouseLeave, + getColor, }), [ borderRadius, @@ -314,6 +316,7 @@ const InnerBarCanvas = ({ onClick, onMouseEnter, onMouseLeave, + getColor, ] ) diff --git a/packages/bar/src/types.ts b/packages/bar/src/types.ts index 22a4ab575..2b63651a2 100644 --- a/packages/bar/src/types.ts +++ b/packages/bar/src/types.ts @@ -124,6 +124,7 @@ interface BarCustomLayerBaseProps xScale: AnyScale yScale: AnyScale + getColor: OrdinalColorScaleConfig> } export interface BarCustomLayerProps From 6d4de7b4554a3b8b1639ba73a6482142f51d6b76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lembit=20L=C3=B5pp?= Date: Thu, 3 Oct 2024 13:47:32 +0300 Subject: [PATCH 3/3] Fix type --- packages/bar/src/types.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/bar/src/types.ts b/packages/bar/src/types.ts index 2b63651a2..c5bfcefc4 100644 --- a/packages/bar/src/types.ts +++ b/packages/bar/src/types.ts @@ -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' @@ -124,7 +124,7 @@ interface BarCustomLayerBaseProps xScale: AnyScale yScale: AnyScale - getColor: OrdinalColorScaleConfig> + getColor: OrdinalColorScale> } export interface BarCustomLayerProps