Skip to content

Commit e749a34

Browse files
committed
release: v4.0.0-rc.0
1 parent 9770a40 commit e749a34

File tree

5 files changed

+56
-46
lines changed

5 files changed

+56
-46
lines changed

README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import {
4444
```js
4545

4646
/**
47-
* A string of all className you want applied to the base component.
47+
* A string of all className you want applied to the base component.
4848
*/
4949
className?: string
5050
/**
@@ -56,7 +56,7 @@ customTooltips?: boolean
5656
/**
5757
* The data object that is passed into the Chart.js chart (more info).
5858
*/
59-
data: Chart.ChartData | ((canvas: HTMLCanvasElement) => Chart.ChartData)
59+
data: ChartData | ((canvas: HTMLCanvasElement) => ChartData)
6060
/**
6161
* A fallback for when the canvas cannot be rendered. Can be used for accessible chart descriptions.
6262
*
@@ -66,15 +66,24 @@ fallbackContent?: React.ReactNode
6666
/**
6767
* Proxy for Chart.js getDatasetAtEvent. Calls with dataset and triggering event.
6868
*/
69-
getDatasetAtEvent?: (dataset: Array<{}>, event: React.MouseEvent<HTMLCanvasElement>) => void
69+
getDatasetAtEvent?: (
70+
dataset: InteractionItem[],
71+
event: React.MouseEvent<HTMLCanvasElement>,
72+
) => void
7073
/**
7174
* Proxy for Chart.js getElementAtEvent. Calls with single element array and triggering event.
7275
*/
73-
getElementAtEvent?: (element: [{}], event: React.MouseEvent<HTMLCanvasElement>) => void
76+
getElementAtEvent?: (
77+
element: InteractionItem[],
78+
event: React.MouseEvent<HTMLCanvasElement>,
79+
) => void
7480
/**
7581
* Proxy for Chart.js getElementsAtEvent. Calls with element array and triggering event.
7682
*/
77-
getElementsAtEvent?: (elements: Array<{}>, event: React.MouseEvent<HTMLCanvasElement>) => void
83+
getElementsAtEvent?: (
84+
elements: InteractionItem[],
85+
event: React.MouseEvent<HTMLCanvasElement>,
86+
) => void
7887
/**
7988
* Height attribute applied to the rendered canvas.
8089
*
@@ -90,13 +99,13 @@ id?: string
9099
*
91100
* {@link https://www.chartjs.org/docs/latest/general/options.html More Info}
92101
*/
93-
options?: Chart.ChartOptions
102+
options?: ChartOptions
94103
/**
95104
* The plugins array that is passed into the Chart.js chart (more info)
96105
*
97106
* {@link https://www.chartjs.org/docs/latest/developers/plugins.html More Info}
98107
*/
99-
plugins?: Chart.PluginServiceRegistrationOptions[]
108+
plugins?: Plugin[]
100109
/**
101110
* If true, will tear down and redraw chart on all updates.
102111
*
@@ -106,9 +115,9 @@ redraw?: boolean
106115
/**
107116
* Chart.js chart type.
108117
*
109-
* @type {'line' | 'bar' | 'horizontalBar' | 'radar' | 'doughnut' | 'polarArea' | 'bubble' | 'pie' | 'scatter'}
118+
* @type {'line' | 'bar' | 'radar' | 'doughnut' | 'polarArea' | 'bubble' | 'pie' | 'scatter'}
110119
*/
111-
type: Chart.ChartType
120+
type: ChartType
112121
/**
113122
* Width attribute applied to the rendered canvas.
114123
*

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coreui/react-chartjs",
3-
"version": "2.0.0-beta.0",
3+
"version": "2.0.0-rc.0",
44
"description": "CoreUI React component wrapper for chart.js",
55
"license": "MIT",
66
"homepage": "https://coreui.io",

src/CChart.tsx

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import React, {
99
useRef,
1010
} from 'react'
1111

12-
import Chart from 'chart.js/auto'
12+
import Chart, { ChartData, ChartOptions, ChartType, InteractionItem, Plugin } from 'chart.js/auto'
1313
import * as chartjs from 'chart.js'
1414
import { customTooltips as cuiCustomTooltips } from '@coreui/chartjs'
1515

@@ -31,7 +31,7 @@ export interface CChartProps extends HTMLAttributes<HTMLCanvasElement | HTMLDivE
3131
/**
3232
* The data object that is passed into the Chart.js chart (more info).
3333
*/
34-
data: Chart.ChartData | ((canvas: HTMLCanvasElement) => Chart.ChartData)
34+
data: ChartData | ((canvas: HTMLCanvasElement) => ChartData)
3535
/**
3636
* A fallback for when the canvas cannot be rendered. Can be used for accessible chart descriptions.
3737
*
@@ -41,15 +41,24 @@ export interface CChartProps extends HTMLAttributes<HTMLCanvasElement | HTMLDivE
4141
/**
4242
* Proxy for Chart.js getDatasetAtEvent. Calls with dataset and triggering event.
4343
*/
44-
getDatasetAtEvent?: (dataset: Array<{}>, event: React.MouseEvent<HTMLCanvasElement>) => void
44+
getDatasetAtEvent?: (
45+
dataset: InteractionItem[],
46+
event: React.MouseEvent<HTMLCanvasElement>,
47+
) => void
4548
/**
4649
* Proxy for Chart.js getElementAtEvent. Calls with single element array and triggering event.
4750
*/
48-
getElementAtEvent?: (element: [{}], event: React.MouseEvent<HTMLCanvasElement>) => void
51+
getElementAtEvent?: (
52+
element: InteractionItem[],
53+
event: React.MouseEvent<HTMLCanvasElement>,
54+
) => void
4955
/**
5056
* Proxy for Chart.js getElementsAtEvent. Calls with element array and triggering event.
5157
*/
52-
getElementsAtEvent?: (elements: Array<{}>, event: React.MouseEvent<HTMLCanvasElement>) => void
58+
getElementsAtEvent?: (
59+
elements: InteractionItem[],
60+
event: React.MouseEvent<HTMLCanvasElement>,
61+
) => void
5362
/**
5463
* Height attribute applied to the rendered canvas.
5564
*
@@ -65,13 +74,13 @@ export interface CChartProps extends HTMLAttributes<HTMLCanvasElement | HTMLDivE
6574
*
6675
* {@link https://www.chartjs.org/docs/latest/general/options.html More Info}
6776
*/
68-
options?: Chart.ChartOptions
77+
options?: ChartOptions
6978
/**
7079
* The plugins array that is passed into the Chart.js chart (more info)
7180
*
7281
* {@link https://www.chartjs.org/docs/latest/developers/plugins.html More Info}
7382
*/
74-
plugins?: Chart.PluginServiceRegistrationOptions[]
83+
plugins?: Plugin[]
7584
/**
7685
* If true, will tear down and redraw chart on all updates.
7786
*
@@ -81,9 +90,9 @@ export interface CChartProps extends HTMLAttributes<HTMLCanvasElement | HTMLDivE
8190
/**
8291
* Chart.js chart type.
8392
*
84-
* @type {'line' | 'bar' | 'horizontalBar' | 'radar' | 'doughnut' | 'polarArea' | 'bubble' | 'pie' | 'scatter'}
93+
* @type {'line' | 'bar' | 'radar' | 'doughnut' | 'polarArea' | 'bubble' | 'pie' | 'scatter'}
8594
*/
86-
type: Chart.ChartType
95+
type: ChartType
8796
/**
8897
* Width attribute applied to the rendered canvas.
8998
*
@@ -120,9 +129,9 @@ export const CChart = forwardRef<Chart | undefined, CChartProps>((props, ref) =>
120129

121130
const canvasRef = useRef<HTMLCanvasElement>(null)
122131

123-
const computedData = useMemo<Chart.ChartData>(() => {
132+
const computedData = useMemo(() => {
124133
if (typeof data === 'function') {
125-
return canvasRef.current ? data(canvasRef.current) : {}
134+
return canvasRef.current ? data(canvasRef.current) : { datasets: [] }
126135
} else return merge({}, data)
127136
}, [data, canvasRef.current])
128137

@@ -150,7 +159,7 @@ export const CChart = forwardRef<Chart | undefined, CChartProps>((props, ref) =>
150159
)
151160
}
152161

153-
const onClick = (e: React.MouseEvent<HTMLCanvasElement>) => {
162+
const handleOnClick = (e: any) => {
154163
if (!chart) return
155164

156165
getDatasetAtEvent &&
@@ -243,7 +252,9 @@ export const CChart = forwardRef<Chart | undefined, CChartProps>((props, ref) =>
243252
width={width}
244253
ref={ref}
245254
id={id}
246-
onClick={onClick}
255+
onClick={(e: React.MouseEvent<HTMLCanvasElement>) => {
256+
handleOnClick(e)
257+
}}
247258
data-testid="canvas"
248259
role="img"
249260
>
@@ -264,27 +275,26 @@ export const CChart = forwardRef<Chart | undefined, CChartProps>((props, ref) =>
264275
CChart.propTypes = {
265276
className: PropTypes.string,
266277
customTooltips: PropTypes.bool,
267-
data: PropTypes.oneOfType([PropTypes.object, PropTypes.func]), // TODO: check
278+
data: PropTypes.any.isRequired, // TODO: check
268279
fallbackContent: PropTypes.node,
269-
getDatasetAtEvent: PropTypes.func, // TODO: check
270-
getElementAtEvent: PropTypes.func, // TODO: check
271-
getElementsAtEvent: PropTypes.func, // TODO: check
280+
getDatasetAtEvent: PropTypes.func,
281+
getElementAtEvent: PropTypes.func,
282+
getElementsAtEvent: PropTypes.func,
272283
height: PropTypes.number,
273284
id: PropTypes.string,
274-
options: PropTypes.object, // TODO: check
275-
plugins: PropTypes.array, // TODO: check
285+
options: PropTypes.object,
286+
plugins: PropTypes.array,
276287
redraw: PropTypes.bool,
277-
type: PropTypes.oneOf([
278-
'line',
288+
type: PropTypes.oneOf<ChartType>([
279289
'bar',
280-
'horizontalBar',
281-
'radar',
282-
'doughnut',
283-
'polarArea',
290+
'line',
291+
'scatter',
284292
'bubble',
285293
'pie',
286-
'scatter',
287-
]),
294+
'doughnut',
295+
'polarArea',
296+
'radar',
297+
]).isRequired,
288298
width: PropTypes.number,
289299
wrapper: PropTypes.bool,
290300
}

src/CCharts.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { forwardRef } from 'react'
22
import { CChart, CChartProps } from './CChart'
33
import Chart from 'chart.js/auto'
4-
// import * as chartjs from 'chart.js';
54

65
export const CChartBar = forwardRef<Chart | undefined, CChartProps>((props, ref) => (
76
<CChart {...props} type="bar" ref={ref} />
@@ -21,12 +20,6 @@ export const CChartDoughnut = forwardRef<Chart | undefined, CChartProps>((props,
2120

2221
CChartDoughnut.displayName = 'CChartDoughnut'
2322

24-
export const CChartHorizontalBar = forwardRef<Chart | undefined, CChartProps>((props, ref) => (
25-
<CChart {...props} type="horizontalBar" ref={ref} />
26-
))
27-
28-
CChartHorizontalBar.displayName = 'CChartHorizontalBar'
29-
3023
export const CChartLine = forwardRef<Chart | undefined, CChartProps>((props, ref) => (
3124
<CChart {...props} type="line" ref={ref} />
3225
))

src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
CChartBar,
44
CChartBubble,
55
CChartDoughnut,
6-
CChartHorizontalBar,
76
CChartLine,
87
CChartPie,
98
CChartPolarArea,
@@ -16,7 +15,6 @@ export {
1615
CChartBar,
1716
CChartBubble,
1817
CChartDoughnut,
19-
CChartHorizontalBar,
2018
CChartLine,
2119
CChartPie,
2220
CChartPolarArea,

0 commit comments

Comments
 (0)