Skip to content

Commit

Permalink
Migrate victory-pie to TypeScript (#2740)
Browse files Browse the repository at this point in the history
  • Loading branch information
KenanYusuf authored Jan 25, 2024
1 parent 0c9b7f1 commit 492675f
Show file tree
Hide file tree
Showing 9 changed files with 338 additions and 450 deletions.
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

1 comment on commit 492675f

@vercel
Copy link

@vercel vercel bot commented on 492675f Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.