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