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

Migrate victory-pie to TypeScript #2740

Merged
merged 4 commits into from
Jan 25, 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
5 changes: 5 additions & 0 deletions .changeset/kind-rivers-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"victory-pie": patch
---

Migrate victory-pie to TypeScript
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const getSlices = (props, data) => {
.startAngle(Helpers.degreesToRadians(props.startAngle))
.endAngle(Helpers.degreesToRadians(props.endAngle))
.padAngle(Helpers.degreesToRadians(padAngle))
.value((datum) => {
.value((datum: any) => {
return datum._y;
});
return layoutFunction(data);
Expand All @@ -62,7 +62,7 @@ const getSlices = (props, data) => {
const getCalculatedValues = (props) => {
const { colorScale } = props;
const styleObject = Helpers.getDefaultStyles(props, "pie");
const style = Helpers.getStyles(props.style, styleObject, "auto", "100%");
const style = Helpers.getStyles(props.style, styleObject);
const colors = Array.isArray(colorScale)
? colorScale
: Style.getColorScale(colorScale);
Expand Down
86 changes: 0 additions & 86 deletions packages/victory-pie/src/index.d.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/victory-pie/src/index.js

This file was deleted.

2 changes: 2 additions & 0 deletions packages/victory-pie/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./victory-pie";
export * from "./slice";
Original file line number Diff line number Diff line change
@@ -1,9 +1,51 @@
import React from "react";
import PropTypes from "prop-types";
import { Helpers, CommonProps, Path } from "victory-core";
import {
Helpers,
CommonProps,
Path,
NumberOrCallback,
SliceNumberOrCallback,
StringOrCallback,
VictoryCommonProps,
VictoryStyleInterface,
} from "victory-core";
import { defaults, isFunction, assign } from "lodash";
import * as d3Shape from "victory-vendor/d3-shape";

export type VictorySliceLabelPositionType =
| "startAngle"
| "centroid"
| "endAngle";
export type VictorySliceLabelPlacementType =
| "vertical"
| "parallel"
| "perpendicular";
export type VictorySliceTTargetType = "data" | "labels" | "parent";

export interface SliceProps extends VictoryCommonProps {
ariaLabel?: StringOrCallback;
cornerRadius?: SliceNumberOrCallback<SliceProps, "cornerRadius">;
datum?: any;
innerRadius?: NumberOrCallback;
padAngle?: SliceNumberOrCallback<SliceProps, "padAngle">;
pathComponent?: React.ReactElement;
pathFunction?: (props: SliceProps) => string;
radius?: SliceNumberOrCallback<SliceProps, "radius">;
slice?: {
startAngle?: number;
endAngle?: number;
padAngle?: number;
data?: any[];
};
sliceEndAngle?: SliceNumberOrCallback<SliceProps, "sliceEndAngle">;
sliceStartAngle?: SliceNumberOrCallback<SliceProps, "sliceStartAngle">;
style?: VictoryStyleInterface;
tabIndex?: NumberOrCallback;
role?: string;
shapeRendering?: string;
}

const getPath = (props) => {
const { slice, radius, innerRadius, cornerRadius } = props;
if (isFunction(props.pathFunction)) {
Expand Down Expand Up @@ -68,13 +110,13 @@ const evaluateProps = (props) => {
});
};

const defaultProps = {
const defaultProps: SliceProps = {
pathComponent: <Path />,
role: "presentation",
shapeRendering: "auto",
};

const Slice = (initialProps) => {
export const Slice = (initialProps: SliceProps) => {
const props = evaluateProps({ ...defaultProps, ...initialProps });
const defaultTransform = props.origin
? `translate(${props.origin.x}, ${props.origin.y})`
Expand Down Expand Up @@ -107,5 +149,3 @@ Slice.propTypes = {
sliceEndAngle: PropTypes.oneOfType([PropTypes.number, PropTypes.func]),
sliceStartAngle: PropTypes.oneOfType([PropTypes.number, PropTypes.func]),
};

export default Slice;
Loading
Loading