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
Changes from 1 commit
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
Next Next commit
Fix the type signature of getPath in charts
carbonrobot committed Jan 26, 2024
commit 21b5edd7bb7c4fd59abb496a311d7f3e77c3c377
2 changes: 1 addition & 1 deletion packages/victory-bar/src/bar.tsx
Original file line number Diff line number Diff line change
@@ -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;
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";

@@ -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);
};
1 change: 1 addition & 0 deletions packages/victory-bar/src/victory-bar.tsx
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ export interface VictoryBarProps
number | string | number[] | string[]
>[];
eventKey?: StringOrNumberOrCallback;
getPath?: (props: VictoryBarProps) => string;
horizontal?: boolean;
style?: VictoryStyleInterface;
}
2 changes: 1 addition & 1 deletion packages/victory-canvas/src/canvas-bar.tsx
Original file line number Diff line number Diff line change
@@ -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;