-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathtypedCharts.tsx
59 lines (48 loc) · 1.41 KB
/
typedCharts.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React, { forwardRef } from 'react';
import {
Chart as ChartJS,
LineController,
BarController,
RadarController,
DoughnutController,
PolarAreaController,
BubbleController,
PieController,
ScatterController,
} from 'chart.js';
import type { ChartType, ChartComponentLike } from 'chart.js';
import type {
ChartProps,
ChartJSOrUndefined,
TypedChartComponent,
} from './types.js';
import { Chart } from './chart.js';
function createTypedChart<T extends ChartType>(
type: T,
registerables: ChartComponentLike
) {
ChartJS.register(registerables);
return forwardRef<ChartJSOrUndefined<T>, Omit<ChartProps<T>, 'type'>>(
(props, ref) => <Chart {...props} ref={ref} type={type} />
) as TypedChartComponent<T>;
}
export const Line = /* #__PURE__ */ createTypedChart('line', LineController);
export const Bar = /* #__PURE__ */ createTypedChart('bar', BarController);
export const Radar = /* #__PURE__ */ createTypedChart('radar', RadarController);
export const Doughnut = /* #__PURE__ */ createTypedChart(
'doughnut',
DoughnutController
);
export const PolarArea = /* #__PURE__ */ createTypedChart(
'polarArea',
PolarAreaController
);
export const Bubble = /* #__PURE__ */ createTypedChart(
'bubble',
BubbleController
);
export const Pie = /* #__PURE__ */ createTypedChart('pie', PieController);
export const Scatter = /* #__PURE__ */ createTypedChart(
'scatter',
ScatterController
);