From 21b5edd7bb7c4fd59abb496a311d7f3e77c3c377 Mon Sep 17 00:00:00 2001 From: Charlie Brown Date: Fri, 26 Jan 2024 08:23:48 -0600 Subject: [PATCH 1/3] Fix the type signature of `getPath` in charts --- packages/victory-bar/src/bar.tsx | 2 +- .../victory-bar/src/path-helper-methods.ts | 25 +++++++++++++------ packages/victory-bar/src/victory-bar.tsx | 1 + packages/victory-canvas/src/canvas-bar.tsx | 2 +- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/packages/victory-bar/src/bar.tsx b/packages/victory-bar/src/bar.tsx index fcdc68c3e..26d083b10 100644 --- a/packages/victory-bar/src/bar.tsx +++ b/packages/victory-bar/src/bar.tsx @@ -21,7 +21,7 @@ export interface BarProps extends VictoryCommonPrimitiveProps { barWidth?: NumberOrCallback; cornerRadius?: NumberOrCallback | VictoryBarCornerRadiusObject; datum?: any; - getPath?: (x: number, y: number, props: any) => string; + getPath?: (props: BarProps) => string; horizontal?: boolean; pathComponent?: React.ReactElement; width?: number; diff --git a/packages/victory-bar/src/path-helper-methods.ts b/packages/victory-bar/src/path-helper-methods.ts index e20629a9e..44209e1c1 100644 --- a/packages/victory-bar/src/path-helper-methods.ts +++ b/packages/victory-bar/src/path-helper-methods.ts @@ -1,4 +1,5 @@ import * as d3Shape from "victory-vendor/d3-shape"; +import { BarProps } from "./bar"; import { circle, point } from "./geometry-helper-methods"; @@ -42,10 +43,18 @@ const transformAngle = (angle: number) => { return -1 * angle + Math.PI / 2; }; -export const getCustomBarPath = (props, width) => { +export const getCustomBarPath = ( + props: BarProps, + width: number, +): string | undefined => { const { getPath } = props; - const propsWithCalculatedValues = { ...props, ...getPosition(props, width) }; - return getPath(propsWithCalculatedValues); + if (typeof getPath === "function") { + const propsWithCalculatedValues = { + ...props, + ...getPosition(props, width), + }; + return getPath(propsWithCalculatedValues); + } }; const getStartAngle = (props, index: number) => { @@ -251,7 +260,7 @@ export const getHorizontalBarPath = (props, width, cornerRadius) => { return mapPointsToPath(points, cr, direction); }; -export const getVerticalPolarBarPath = (props, cornerRadius) => { +export const getVerticalPolarBarPath = (props: BarProps, cornerRadius) => { const { datum, scale, index, alignment, style } = props; const r1 = scale.y(datum._y0 || 0); const r2 = scale.y(datum._y1 !== undefined ? datum._y1 : datum._y); @@ -264,8 +273,8 @@ export const getVerticalPolarBarPath = (props, cornerRadius) => { start = alignment === "start" ? currentAngle : currentAngle - size; end = alignment === "end" ? currentAngle : currentAngle + size; } else { - start = getStartAngle(props, index); - end = getEndAngle(props, index); + start = getStartAngle(props, Number(index)); + end = getEndAngle(props, Number(index)); } const getPath = (edge): string => { @@ -409,7 +418,7 @@ export const getVerticalPolarBarPath = (props, cornerRadius) => { return `${path} z`; }; -export const getBarPath = (props, width, cornerRadius) => { +export const getBarPath = (props: BarProps, width: number, cornerRadius) => { if (props.getPath) { return getCustomBarPath(props, width); } @@ -419,7 +428,7 @@ export const getBarPath = (props, width, cornerRadius) => { : getVerticalBarPath(props, width, cornerRadius); }; -export const getPolarBarPath = (props, cornerRadius) => { +export const getPolarBarPath = (props: BarProps, cornerRadius) => { // TODO Radial bars return getVerticalPolarBarPath(props, cornerRadius); }; diff --git a/packages/victory-bar/src/victory-bar.tsx b/packages/victory-bar/src/victory-bar.tsx index f2638bba0..e7d66a529 100644 --- a/packages/victory-bar/src/victory-bar.tsx +++ b/packages/victory-bar/src/victory-bar.tsx @@ -49,6 +49,7 @@ export interface VictoryBarProps number | string | number[] | string[] >[]; eventKey?: StringOrNumberOrCallback; + getPath?: (props: VictoryBarProps) => string; horizontal?: boolean; style?: VictoryStyleInterface; } diff --git a/packages/victory-canvas/src/canvas-bar.tsx b/packages/victory-canvas/src/canvas-bar.tsx index cdb24ec18..4ccdc4290 100644 --- a/packages/victory-canvas/src/canvas-bar.tsx +++ b/packages/victory-canvas/src/canvas-bar.tsx @@ -20,7 +20,7 @@ export interface CanvasBarProps extends VictoryCommonPrimitiveProps { barWidth?: NumberOrCallback; cornerRadius?: NumberOrCallback | VictoryBarCornerRadiusObject; datum?: any; - getPath?: (x: number, y: number, size: number) => string; + getPath?: (props: CanvasBarProps) => string; horizontal?: boolean; width?: number; x?: number; From e89601aeaee1557db294aa10409aa2d2f13418bb Mon Sep 17 00:00:00 2001 From: Charlie Brown Date: Fri, 26 Jan 2024 08:24:09 -0600 Subject: [PATCH 2/3] Add the missing `disableInlineStyles` prop in common components --- packages/victory-core/src/victory-util/common-props.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/victory-core/src/victory-util/common-props.tsx b/packages/victory-core/src/victory-util/common-props.tsx index 971a1cc2c..1b0153234 100644 --- a/packages/victory-core/src/victory-util/common-props.tsx +++ b/packages/victory-core/src/victory-util/common-props.tsx @@ -95,6 +95,7 @@ export interface VictoryCommonThemeProps { animate?: boolean | AnimatePropTypeInterface; colorScale?: ColorScalePropType; containerComponent?: React.ReactElement; + disableInlineStyles?: boolean; domainPadding?: DomainPaddingPropType; externalEventMutations?: EventCallbackInterface< string | string[], From e6b385709abba58ae7e376756092721a786da6a2 Mon Sep 17 00:00:00 2001 From: Charlie Brown Date: Fri, 26 Jan 2024 08:24:55 -0600 Subject: [PATCH 3/3] Changeset --- .changeset/large-cherries-rhyme.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/large-cherries-rhyme.md diff --git a/.changeset/large-cherries-rhyme.md b/.changeset/large-cherries-rhyme.md new file mode 100644 index 000000000..93e28e7db --- /dev/null +++ b/.changeset/large-cherries-rhyme.md @@ -0,0 +1,7 @@ +--- +"victory-bar": patch +"victory-canvas": patch +"victory-core": patch +--- + +Fix incorrect typescript props