UNPKG

10.8 kBTypeScriptView Raw
1// Type definitions for ReactNativeChartKit 2.6
2// Project: https://github.com/indiespirit/react-native-chart-kit
3// TypeScript Version: 3.0
4
5import * as React from "react";
6import { ViewStyle } from "react-native";
7import { TextProps, CircleProps, TextStyle } from "react-native-svg";
8
9export interface Dataset {
10 /** The data corresponding to the x-axis label. */
11 data: number[];
12 /** A function returning the color of the stroke given an input opacity value. */
13 color?: (opacity: number) => string;
14 /** The width of the stroke. Defaults to 2. */
15 strokeWidth?: number;
16
17 /** A boolean indicating whether to render dots for this line */
18 withDots?: boolean;
19}
20
21export interface ChartData {
22 /** The x-axis labels */
23 labels: string[];
24 datasets: Dataset[];
25}
26
27export interface LineChartData extends ChartData {
28 legend?: string[];
29}
30
31// LineChart
32export interface LineChartProps {
33 /**
34 * Data for the chart.
35 *
36 * Example from [docs](https://github.com/indiespirit/react-native-chart-kit#line-chart):
37 *
38 * ```javascript
39 * const data = {
40 * labels: ['January', 'February', 'March', 'April', 'May', 'June'],
41 * datasets: [{
42 * data: [ 20, 45, 28, 80, 99, 43 ],
43 * color: (opacity = 1) => `rgba(134, 65, 244, ${opacity})`, // optional
44 * strokeWidth: 2 // optional
45 * }],
46 * legend: ["Rainy Days", "Sunny Days", "Snowy Days"] // optional
47 * }
48 * ```
49 */
50 data: LineChartData;
51 /**
52 * Width of the chart, use 'Dimensions' library to get the width of your screen for responsive.
53 */
54 width: number;
55 /**
56 * Height of the chart.
57 */
58 height: number;
59 /**
60 * Show dots on the line - default: True.
61 */
62 withDots?: boolean;
63 /**
64 * Show shadow for line - default: True.
65 */
66 withShadow?: boolean;
67 /**
68 * Show inner dashed lines - default: True.
69 */
70
71 withScrollableDot?: boolean;
72 withInnerLines?: boolean;
73 /**
74 * Show outer dashed lines - default: True.
75 */
76 withOuterLines?: boolean;
77 /**
78 * Show vertical labels - default: True.
79 */
80 withVerticalLabels?: boolean;
81 /**
82 * Show horizontal labels - default: True.
83 */
84 withHorizontalLabels?: boolean;
85 /**
86 * Render charts from 0 not from the minimum value. - default: False.
87 */
88 fromZero?: boolean;
89 /**
90 * Prepend text to horizontal labels -- default: ''.
91 */
92 yAxisLabel?: string;
93 /**
94 * Append text to horizontal labels -- default: ''.
95 */
96 yAxisSuffix?: string;
97 /**
98 * Prepend text to vertical labels -- default: ''.
99 */
100 xAxisLabel?: string;
101 /**
102 * Configuration object for the chart, see example:
103 *
104 * ```javascript
105 * const chartConfig = {
106 * backgroundGradientFrom: "#1E2923",
107 * backgroundGradientFromOpacity: 0,
108 * backgroundGradientTo: "#08130D",
109 * backgroundGradientToOpacity: 0.5,
110 * color: (opacity = 1) => `rgba(26, 255, 146, ${opacity})`,
111 * labelColor: (opacity = 1) => `rgba(26, 255, 146, ${opacity})`,
112 * strokeWidth: 2, // optional, default 3
113 * barPercentage: 0.5
114 * };
115 * ```
116 */
117 chartConfig: ChartConfig;
118
119 /**
120 * Divide axis quantity by the input number -- default: 1.
121 */
122 yAxisInterval?: number;
123
124 /**
125 * Defines if chart is transparent
126 */
127 transparent?: boolean;
128 /**
129 * This function takes a [whole bunch](https://github.com/indiespirit/react-native-chart-kit/blob/master/src/line-chart.js#L266)
130 * of stuff and can render extra elements,
131 * such as data point info or additional markup.
132 */
133 decorator?: Function;
134 /**
135 * Callback that is called when a data point is clicked.
136 */
137 onDataPointClick?: (data: {
138 index: number;
139 value: number;
140 dataset: Dataset;
141 x: number;
142 y: number;
143 getColor: (opacity: number) => string;
144 }) => void;
145 /**
146 * Style of the container view of the chart.
147 */
148 style?: ViewStyle;
149 /**
150 * Add this prop to make the line chart smooth and curvy.
151 *
152 * [Example](https://github.com/indiespirit/react-native-chart-kit#bezier-line-chart)
153 */
154 bezier?: boolean;
155 /**
156 * Defines the dot color function that is used to calculate colors of dots in a line chart.
157 * Takes `(dataPoint, dataPointIndex)` as arguments.
158 */
159 getDotColor?: (dataPoint: any, index: number) => string;
160 /**
161 * Renders additional content for dots in a line chart.
162 * Takes `({x, y, index})` as arguments.
163 */
164 renderDotContent?: (params: {
165 x: number;
166 y: number;
167 index: number;
168 }) => React.ReactNode;
169 /**
170 * Rotation angle of the horizontal labels - default 0 (degrees).
171 */
172 horizontalLabelRotation?: number;
173 /**
174 * Rotation angle of the vertical labels - default 0 (degrees).
175 */
176 verticalLabelRotation?: number;
177 /**
178 * Offset for Y axis labels.
179 */
180 yLabelsOffset?: number;
181 /**
182 * Offset for X axis labels.
183 */
184 xLabelsOffset?: number;
185 /**
186 * Array of indices of the data points you don't want to display.
187 */
188 hidePointsAtIndex?: number[];
189 /**
190 * This function change the format of the display value of the Y label.
191 * Takes the y value as argument and should return the desirable string.
192 */
193 formatYLabel?: (yValue: string) => string;
194 /**
195 * This function change the format of the display value of the X label.
196 * Takes the X value as argument and should return the desirable string.
197 */
198 formatXLabel?: (xValue: string) => string;
199 /**
200 * Provide props for a data point dot.
201 */
202 getDotProps?: (dataPoint: any, index: number) => object;
203 /**
204 * The number of horizontal lines
205 */
206 segments?: number;
207}
208
209export class LineChart extends React.Component<LineChartProps> {}
210
211// ProgressChart
212
213export type ProgressChartData =
214 | Array<number>
215 | { labels?: Array<string>; data: Array<number> };
216export interface ProgressChartProps {
217 data: ProgressChartData;
218 width: number;
219 height: number;
220 chartConfig?: ChartConfig;
221 hideLegend?: boolean;
222 strokeWidth?: number;
223 radius?:number;
224}
225
226export class ProgressChart extends React.Component<ProgressChartProps> {}
227
228// BarChart
229export interface BarChartProps {
230 data: ChartData;
231 width: number;
232 height: number;
233 fromZero?: boolean;
234 withInnerLines?: boolean;
235 yAxisLabel: string;
236 yAxisSuffix: string;
237 chartConfig: ChartConfig;
238 style?: ViewStyle;
239 horizontalLabelRotation?: number;
240 verticalLabelRotation?: number;
241 /**
242 * The number of horizontal lines
243 */
244 segments?: number;
245 showBarTops?: boolean;
246}
247
248export class BarChart extends React.Component<BarChartProps> {}
249
250// StackedBarChart
251export interface StackedBarChartData {
252 labels: string[];
253 legend: string[];
254 data: number[][];
255 barColors: string[];
256}
257
258export interface Size {
259 width: number;
260 height: number;
261}
262
263export interface StackedBarChartProps {
264 /**
265 * E.g.
266 * ```javascript
267 * const data = {
268 * labels: ["Test1", "Test2"],
269 * legend: ["L1", "L2", "L3"],
270 * data: [[60, 60, 60], [30, 30, 60]],
271 * barColors: ["#dfe4ea", "#ced6e0", "#a4b0be"]
272 * };
273 * ```
274 */
275 data: StackedBarChartData;
276 width: number;
277 height: number;
278 chartConfig: ChartConfig;
279 style?: ViewStyle;
280 barPercentage?: number;
281 hideLegend: boolean;
282 /**
283 * The number of horizontal lines
284 */
285 segments?: number;
286}
287
288export class StackedBarChart extends React.Component<StackedBarChartProps> {}
289
290// PieChart
291export interface PieChartProps {
292 data: Array<any>;
293 width: number;
294 height: number;
295 chartConfig: ChartConfig;
296 accessor: string;
297 backgroundColor: string;
298 paddingLeft: string;
299 center?: Array<number>;
300 absolute?: boolean;
301 hasLegend?: boolean;
302}
303
304export class PieChart extends React.Component<PieChartProps> {}
305
306// ContributionGraph
307export interface ContributionGraphProps {
308 values: Array<any>;
309 endDate: Date;
310 numDays: number;
311 width: number;
312 height: number;
313 gutterSize?: number;
314 squareSize?: number;
315 horizontal?: boolean;
316 showMonthLabels?: boolean;
317 showOutOfRangeDays?: boolean;
318 chartConfig: ChartConfig;
319 accessor?: string;
320 getMonthLabel?: (monthIndex: number) => string;
321 onDayPress?: ({ count: number, date: Date }) => void;
322}
323
324export class ContributionGraph extends React.Component<
325 ContributionGraphProps
326> {}
327
328// AbstractChart
329export class AbstractChart extends React.Component {}
330
331// ChartConfig
332export interface ChartConfig {
333 backgroundColor?: string;
334 /**
335 * Defines the first color in the linear gradient of a chart's background
336 */
337 backgroundGradientFrom?: string;
338 /**
339 * Defines the first color opacity in the linear gradient of a chart's background
340 */
341 backgroundGradientFromOpacity?: number;
342 /**
343 * Defines the second color in the linear gradient of a chart's background
344 */
345 backgroundGradientTo?: string;
346 /**
347 * Defines the second color opacity in the linear gradient of a chart's background
348 */
349 backgroundGradientToOpacity?: number;
350 fillShadowGradient?: string;
351 fillShadowGradientOpacity?: number;
352 /**
353 * Defines the option to use color from dataset to each chart data
354 */
355 useShadowColorFromDataset?: boolean;
356 /**
357 * Defines the base color function that is used to calculate colors of labels and sectors used in a chart
358 */
359 color?: (opacity: number, index?: number) => string;
360 /**
361 * Defines the function that is used to calculate the color of the labels used in a chart.
362 */
363 labelColor?: (opacity: number) => string;
364 /**
365 * Defines the base stroke width in a chart
366 */
367 strokeWidth?: number;
368 /**
369 * Defines the percent (0-1) of the available width each bar width in a chart
370 */
371 barPercentage?: number;
372 barRadius?: number;
373 /**
374 * Override styles of the background lines, refer to react-native-svg's Line documentation
375 */
376 propsForBackgroundLines?: object;
377 /**
378 * Override styles of the labels, refer to react-native-svg's Text documentation
379 */
380 propsForLabels?: TextProps;
381 /**
382 * Override styles of the dots, refer to react-native-svg's Text documentation
383 */
384 propsForDots?: CircleProps;
385 decimalPlaces?: number;
386 style?: ViewStyle;
387
388 /**
389 * Define stroke line join type
390 */
391 linejoinType?: "round" | "butt" | "square";
392
393 /**
394 * Define fill color for scrollable dot
395 */
396 scrollableDotFill?: string;
397
398 /**
399 * Define stroke color for scrollable dot
400 */
401 scrollableDotStrokeColor?: string;
402
403 /**
404 * Define stroke width for scrollable dot
405 */
406 scrollableDotStrokeWidth?: number;
407
408 /**
409 * Define radius for scrollable dot
410 */
411 scrollableDotRadius?: number;
412
413 /**
414 * Override style for additional info view upper scrollable dot
415 */
416 scrollableInfoViewStyle?: ViewStyle;
417
418 /**
419 * Override text style for additional info view upper scrollable dot
420 */
421 scrollableInfoTextStyle?: TextStyle;
422
423 /**
424 * Set Info View offset
425 */
426 scrollableInfoOffset?: number;
427
428 /**
429 * Set Info View size
430 */
431 scrollableInfoSize?: Size;
432}