UNPKG

3.58 kBTypeScriptView Raw
1/**
2 * @fileOverview Cartesian Axis
3 */
4import React, { ReactElement, ReactNode, Component, SVGProps } from 'react';
5import { CartesianViewBox, PresentationAttributesAdaptChildEvent, CartesianTickItem, AxisInterval } from '../util/types';
6/** The orientation of the axis in correspondence to the chart */
7export type Orientation = 'top' | 'bottom' | 'left' | 'right';
8/** A unit to be appended to a value */
9export type Unit = string | number;
10/** The formatter function of tick */
11export type TickFormatter = (value: any, index: number) => string;
12export interface CartesianAxisProps {
13 className?: string;
14 x?: number;
15 y?: number;
16 width?: number;
17 height?: number;
18 unit?: Unit;
19 orientation?: Orientation;
20 viewBox?: CartesianViewBox;
21 tick?: SVGProps<SVGTextElement> | ReactElement<SVGElement> | ((props: any) => ReactElement<SVGElement>) | boolean;
22 axisLine?: boolean | SVGProps<SVGLineElement>;
23 tickLine?: boolean | SVGProps<SVGLineElement>;
24 mirror?: boolean;
25 tickMargin?: number;
26 hide?: boolean;
27 label?: any;
28 minTickGap?: number;
29 ticks?: CartesianTickItem[];
30 tickSize?: number;
31 tickFormatter?: TickFormatter;
32 ticksGenerator?: (props?: CartesianAxisProps) => CartesianTickItem[];
33 interval?: AxisInterval;
34 /** Angle in which ticks will be rendered. */
35 angle?: number;
36}
37interface IState {
38 fontSize: string;
39 letterSpacing: string;
40}
41export type Props = Omit<PresentationAttributesAdaptChildEvent<any, SVGElement>, 'viewBox'> & CartesianAxisProps;
42export declare class CartesianAxis extends Component<Props, IState> {
43 static displayName: string;
44 static defaultProps: {
45 x: number;
46 y: number;
47 width: number;
48 height: number;
49 viewBox: {
50 x: number;
51 y: number;
52 width: number;
53 height: number;
54 };
55 orientation: string;
56 ticks: CartesianTickItem[];
57 stroke: string;
58 tickLine: boolean;
59 axisLine: boolean;
60 tick: boolean;
61 mirror: boolean;
62 minTickGap: number;
63 tickSize: number;
64 tickMargin: number;
65 interval: string;
66 };
67 private layerReference;
68 constructor(props: Props);
69 shouldComponentUpdate({ viewBox, ...restProps }: Props, nextState: IState): boolean;
70 componentDidMount(): void;
71 /**
72 * Calculate the coordinates of endpoints in ticks
73 * @param {Object} data The data of a simple tick
74 * @return {Object} (x1, y1): The coordinate of endpoint close to tick text
75 * (x2, y2): The coordinate of endpoint close to axis
76 */
77 getTickLineCoord(data: CartesianTickItem): {
78 line: {
79 x1: number;
80 y1: number;
81 x2: number;
82 y2: number;
83 };
84 tick: {
85 x: number;
86 y: number;
87 };
88 };
89 getTickTextAnchor(): string;
90 getTickVerticalAnchor(): string;
91 renderAxisLine(): React.JSX.Element;
92 static renderTickItem(option: Props['tick'], props: any, value: ReactNode): React.JSX.Element;
93 /**
94 * render the ticks
95 * @param {Array} ticks The ticks to actually render (overrides what was passed in props)
96 * @param {string} fontSize Fontsize to consider for tick spacing
97 * @param {string} letterSpacing Letterspacing to consider for tick spacing
98 * @return {ReactComponent} renderedTicks
99 */
100 renderTicks(ticks: CartesianTickItem[], fontSize: string, letterSpacing: string): React.JSX.Element;
101 render(): React.JSX.Element;
102}
103export {};