Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for incorrect chart props #2745

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/large-cherries-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"victory-bar": patch
"victory-canvas": patch
"victory-core": patch
---

Fix incorrect typescript props
2 changes: 1 addition & 1 deletion packages/victory-bar/src/bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 17 additions & 8 deletions packages/victory-bar/src/path-helper-methods.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as d3Shape from "victory-vendor/d3-shape";
import { BarProps } from "./bar";

import { circle, point } from "./geometry-helper-methods";

Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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);
Expand All @@ -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 => {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
};
1 change: 1 addition & 0 deletions packages/victory-bar/src/victory-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface VictoryBarProps
number | string | number[] | string[]
>[];
eventKey?: StringOrNumberOrCallback;
getPath?: (props: VictoryBarProps) => string;
horizontal?: boolean;
style?: VictoryStyleInterface;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/victory-canvas/src/canvas-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions packages/victory-core/src/victory-util/common-props.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export interface VictoryCommonThemeProps {
animate?: boolean | AnimatePropTypeInterface;
colorScale?: ColorScalePropType;
containerComponent?: React.ReactElement;
disableInlineStyles?: boolean;
domainPadding?: DomainPaddingPropType;
externalEventMutations?: EventCallbackInterface<
string | string[],
Expand Down
Loading