UNPKG

5.41 kBTypeScriptView Raw
1/**
2 * @fileOverview Render sectors of a pie
3 */
4import React, { PureComponent, ReactElement, ReactNode, SVGProps } from 'react';
5import { Props as SectorProps } from '../shape/Sector';
6import { LegendType, TooltipType, AnimationTiming, Coordinate, ChartOffset, DataKey, PresentationAttributesAdaptChildEvent, AnimationDuration, ActiveShape } from '../util/types';
7interface PieDef {
8 /** The abscissa of pole in polar coordinate */
9 cx?: number | string;
10 /** The ordinate of pole in polar coordinate */
11 cy?: number | string;
12 /** The start angle of first sector */
13 startAngle?: number;
14 /** The end angle of last sector */
15 endAngle?: number;
16 paddingAngle?: number;
17 /** The inner radius of sectors */
18 innerRadius?: number | string;
19 /** The outer radius of sectors */
20 outerRadius?: number | string;
21 cornerRadius?: number | string;
22}
23type PieLabelLine = ReactElement<SVGElement> | ((props: any) => ReactElement<SVGElement>) | SVGProps<SVGPathElement> | boolean;
24export type PieLabel<P = any> = ReactElement<SVGElement> | ((props: P) => ReactNode | ReactElement<SVGElement>) | (SVGProps<SVGTextElement> & {
25 offsetRadius?: number;
26}) | boolean;
27export type PieSectorDataItem = SectorProps & {
28 percent?: number;
29 name?: string | number;
30 midAngle?: number;
31 middleRadius?: number;
32 tooltipPosition?: Coordinate;
33 value?: number;
34 paddingAngle?: number;
35 dataKey?: string;
36 payload?: any;
37};
38interface PieProps extends PieDef {
39 className?: string;
40 animationId?: number;
41 dataKey: DataKey<any>;
42 nameKey?: DataKey<any>;
43 valueKey?: DataKey<any>;
44 /** Match each sector's stroke color to it's fill color */
45 blendStroke?: boolean;
46 /** The minimum angle for no-zero element */
47 minAngle?: number;
48 legendType?: LegendType;
49 tooltipType?: TooltipType;
50 /** the max radius of pie */
51 maxRadius?: number;
52 hide?: boolean;
53 /** the input data */
54 data?: any[];
55 sectors?: PieSectorDataItem[];
56 activeShape?: ActiveShape<PieSectorDataItem>;
57 inactiveShape?: ActiveShape<PieSectorDataItem>;
58 labelLine?: PieLabelLine;
59 label?: PieLabel;
60 activeIndex?: number | number[];
61 animationEasing?: AnimationTiming;
62 isAnimationActive?: boolean;
63 animationBegin?: number;
64 animationDuration?: AnimationDuration;
65 onAnimationEnd?: () => void;
66 onAnimationStart?: () => void;
67 id?: string;
68 onMouseEnter?: (data: any, index: number, e: React.MouseEvent) => void;
69 onMouseLeave?: (data: any, index: number, e: React.MouseEvent) => void;
70 onClick?: (data: any, index: number, e: React.MouseEvent) => void;
71 rootTabIndex?: number;
72}
73export interface PieLabelRenderProps extends PieDef {
74 name: string;
75 percent?: number;
76 stroke: string;
77 index?: number;
78 textAnchor: string;
79 x: number;
80 y: number;
81 [key: string]: any;
82}
83interface State {
84 isAnimationFinished?: boolean;
85 prevIsAnimationActive?: boolean;
86 prevSectors?: PieSectorDataItem[];
87 curSectors?: PieSectorDataItem[];
88 prevAnimationId?: number;
89 sectorToFocus?: number;
90}
91export type Props = PresentationAttributesAdaptChildEvent<any, SVGElement> & PieProps;
92export declare class Pie extends PureComponent<Props, State> {
93 pieRef: SVGGElement;
94 sectorRefs: SVGGElement[];
95 static displayName: string;
96 static defaultProps: {
97 stroke: string;
98 fill: string;
99 legendType: string;
100 cx: string;
101 cy: string;
102 startAngle: number;
103 endAngle: number;
104 innerRadius: number;
105 outerRadius: string;
106 paddingAngle: number;
107 labelLine: boolean;
108 hide: boolean;
109 minAngle: number;
110 isAnimationActive: boolean;
111 animationBegin: number;
112 animationDuration: number;
113 animationEasing: string;
114 nameKey: string;
115 blendStroke: boolean;
116 rootTabIndex: number;
117 };
118 static parseDeltaAngle: (startAngle: number, endAngle: number) => number;
119 static getRealPieData: (itemProps: Props) => any[];
120 static parseCoordinateOfPie: (itemProps: Props, offset: ChartOffset) => {
121 cx: number;
122 cy: number;
123 innerRadius: number;
124 outerRadius: number;
125 maxRadius: number;
126 };
127 static getComposedData: ({ item, offset, }: {
128 item: React.ReactElement<Props>;
129 offset: ChartOffset;
130 }) => Omit<Props, 'dataKey'>;
131 constructor(props: Props);
132 state: State;
133 static getDerivedStateFromProps(nextProps: Props, prevState: State): State;
134 static getTextAnchor(x: number, cx: number): "start" | "middle" | "end";
135 id: string;
136 isActiveIndex(i: number): boolean;
137 hasActiveIndex(): number | boolean;
138 handleAnimationEnd: () => void;
139 handleAnimationStart: () => void;
140 static renderLabelLineItem(option: PieLabelLine, props: any, key: string): React.JSX.Element;
141 static renderLabelItem(option: PieLabel, props: any, value: any): React.JSX.Element;
142 renderLabels(sectors: PieSectorDataItem[]): React.JSX.Element;
143 renderSectorsStatically(sectors: PieSectorDataItem[]): React.JSX.Element[];
144 renderSectorsWithAnimation(): React.JSX.Element;
145 attachKeyboardHandlers(pieRef: SVGGElement): void;
146 renderSectors(): React.JSX.Element | React.JSX.Element[];
147 componentDidMount(): void;
148 render(): React.JSX.Element;
149}
150export {};