UNPKG

4.85 kBTypeScriptView Raw
1/**
2 * @fileOverview Render a group of bar
3 */
4import React, { Key, PureComponent, ReactElement } from 'react';
5import { Props as RectangleProps } from '../shape/Rectangle';
6import { Props as XAxisProps } from './XAxis';
7import { Props as YAxisProps } from './YAxis';
8import { D3Scale, TooltipType, LegendType, AnimationTiming, ChartOffset, DataKey, TickItem, PresentationAttributesAdaptChildEvent, AnimationDuration, ActiveShape } from '../util/types';
9import { ImplicitLabelType } from '../component/Label';
10import { MinPointSize } from '../util/BarUtils';
11export interface BarRectangleItem extends RectangleProps {
12 value?: number | [number, number];
13 /** the coordinate of background rectangle */
14 background?: {
15 x?: number;
16 y?: number;
17 width?: number;
18 height?: number;
19 };
20}
21interface InternalBarProps {
22 xAxis?: Omit<XAxisProps, 'scale'> & {
23 scale: D3Scale<string | number>;
24 x?: number;
25 width?: number;
26 };
27 yAxis?: Omit<YAxisProps, 'scale'> & {
28 scale: D3Scale<string | number>;
29 y?: number;
30 height?: number;
31 };
32 data?: BarRectangleItem[];
33 top?: number;
34 left?: number;
35 width?: number;
36 height?: number;
37}
38export interface BarProps extends InternalBarProps {
39 className?: string;
40 index?: Key;
41 activeIndex?: number;
42 layout?: 'horizontal' | 'vertical';
43 xAxisId?: string | number;
44 yAxisId?: string | number;
45 stackId?: string | number;
46 barSize?: string | number;
47 unit?: string | number;
48 name?: string | number;
49 dataKey: DataKey<any>;
50 tooltipType?: TooltipType;
51 legendType?: LegendType;
52 minPointSize?: MinPointSize;
53 maxBarSize?: number;
54 hide?: boolean;
55 shape?: ActiveShape<BarProps, SVGPathElement>;
56 activeBar?: ActiveShape<BarProps, SVGPathElement>;
57 background?: ActiveShape<BarProps, SVGPathElement>;
58 radius?: number | [number, number, number, number];
59 onAnimationStart?: () => void;
60 onAnimationEnd?: () => void;
61 isAnimationActive?: boolean;
62 animationBegin?: number;
63 animationDuration?: AnimationDuration;
64 animationEasing?: AnimationTiming;
65 animationId?: number;
66 id?: string;
67 label?: ImplicitLabelType;
68}
69export type Props = Omit<PresentationAttributesAdaptChildEvent<any, SVGPathElement>, 'radius' | 'name'> & BarProps;
70interface State {
71 readonly isAnimationFinished?: boolean;
72 readonly prevData?: BarRectangleItem[];
73 readonly curData?: BarRectangleItem[];
74 readonly prevAnimationId?: number;
75}
76export declare class Bar extends PureComponent<Props, State> {
77 static displayName: string;
78 static defaultProps: {
79 xAxisId: number;
80 yAxisId: number;
81 legendType: string;
82 minPointSize: number;
83 hide: boolean;
84 data: BarRectangleItem[];
85 layout: string;
86 activeBar: boolean;
87 isAnimationActive: boolean;
88 animationBegin: number;
89 animationDuration: number;
90 animationEasing: string;
91 };
92 /**
93 * Compose the data of each group
94 * @param {Object} props Props for the component
95 * @param {Object} item An instance of Bar
96 * @param {Array} barPosition The offset and size of each bar
97 * @param {Object} xAxis The configuration of x-axis
98 * @param {Object} yAxis The configuration of y-axis
99 * @param {Array} stackedData The stacked data of a bar item
100 * @return{Array} Composed data
101 */
102 static getComposedData: ({ props, item, barPosition, bandSize, xAxis, yAxis, xAxisTicks, yAxisTicks, stackedData, dataStartIndex, displayedData, offset, }: {
103 props: Props;
104 item: ReactElement;
105 barPosition: any;
106 bandSize: number;
107 xAxis: InternalBarProps['xAxis'];
108 yAxis: InternalBarProps['yAxis'];
109 xAxisTicks: TickItem[];
110 yAxisTicks: TickItem[];
111 stackedData: Array<[number, number]>;
112 dataStartIndex: number;
113 offset: ChartOffset;
114 displayedData: any[];
115 }) => {
116 top?: number;
117 bottom?: number;
118 left?: number;
119 right?: number;
120 width?: number;
121 height?: number;
122 brushBottom?: number;
123 data: any[];
124 layout: "horizontal" | "vertical";
125 };
126 state: State;
127 static getDerivedStateFromProps(nextProps: Props, prevState: State): State;
128 id: string;
129 handleAnimationEnd: () => void;
130 handleAnimationStart: () => void;
131 renderRectanglesStatically(data: BarRectangleItem[]): React.JSX.Element[];
132 renderRectanglesWithAnimation(): React.JSX.Element;
133 renderRectangles(): React.JSX.Element | React.JSX.Element[];
134 renderBackground(): React.JSX.Element[];
135 renderErrorBar(needClip: boolean, clipPathId: string): React.JSX.Element;
136 render(): React.JSX.Element;
137}
138export {};