react-use-echarts 0.0.3 โ 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -12
- package/dist/index.d.ts +17 -37
- package/dist/index.es.js +62 -74
- package/dist/index.umd.js +1 -1
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/react-use-echarts)
|
|
4
4
|
[](https://www.npmjs.com/package/react-use-echarts)
|
|
5
|
+
[](https://github.com/chensid/react-use-echarts/actions/workflows/npm-publish.yml)
|
|
6
|
+
[](https://github.com/chensid/react-use-echarts/issues)
|
|
7
|
+
[](https://github.com/chensid/react-use-echarts/pulls)
|
|
5
8
|
[](https://github.com/chensid/react-use-echarts/blob/main/LICENSE.txt)
|
|
6
9
|
|
|
7
10
|
A powerful React hooks library for Apache ECharts, making it easy to use ECharts in your React applications with minimal boilerplate.
|
|
@@ -31,10 +34,10 @@ pnpm add react-use-echarts echarts
|
|
|
31
34
|
## ๐จ Usage
|
|
32
35
|
|
|
33
36
|
```tsx
|
|
34
|
-
import {
|
|
37
|
+
import { useEcharts, UseEchartsOptions } from 'react-use-echarts';
|
|
35
38
|
|
|
36
39
|
function MyChart() {
|
|
37
|
-
const options = {
|
|
40
|
+
const options: UseEchartsOptions['option'] = {
|
|
38
41
|
xAxis: {
|
|
39
42
|
type: 'category',
|
|
40
43
|
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
|
@@ -48,7 +51,9 @@ function MyChart() {
|
|
|
48
51
|
}]
|
|
49
52
|
};
|
|
50
53
|
|
|
51
|
-
const { chartRef } =
|
|
54
|
+
const { chartRef } = useEcharts({
|
|
55
|
+
option: options
|
|
56
|
+
});
|
|
52
57
|
|
|
53
58
|
return <div ref={chartRef} style={{ width: '100%', height: '400px' }} />;
|
|
54
59
|
}
|
|
@@ -56,25 +61,33 @@ function MyChart() {
|
|
|
56
61
|
|
|
57
62
|
## ๐ API
|
|
58
63
|
|
|
59
|
-
###
|
|
64
|
+
### useEcharts
|
|
60
65
|
|
|
61
66
|
The main hook for using ECharts in React components.
|
|
62
67
|
|
|
63
68
|
```tsx
|
|
64
|
-
const { chartRef,
|
|
69
|
+
const { chartRef, setOption, getInstance } = useEcharts({
|
|
70
|
+
option: UseEchartsOptions['option']; // ECharts options configuration (required)
|
|
71
|
+
theme?: string | object; // ECharts theme name or configuration
|
|
72
|
+
notMerge?: boolean; // Whether to not merge with previous options
|
|
73
|
+
lazyUpdate?: boolean; // Whether to update chart lazily
|
|
74
|
+
showLoading?: boolean; // Whether to display loading animation
|
|
75
|
+
loadingOption?: object; // Loading animation configuration
|
|
76
|
+
onEvents?: { // Event handlers
|
|
77
|
+
[eventName: string]: {
|
|
78
|
+
handler: (params: any) => void;
|
|
79
|
+
query?: string | object;
|
|
80
|
+
context?: object;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
65
84
|
```
|
|
66
85
|
|
|
67
|
-
#### Parameters
|
|
68
|
-
|
|
69
|
-
- `options` (required): ECharts options configuration
|
|
70
|
-
- `theme` (optional): ECharts theme name or configuration
|
|
71
|
-
- `opts` (optional): ECharts initialization options
|
|
72
|
-
|
|
73
86
|
#### Returns
|
|
74
87
|
|
|
75
88
|
- `chartRef`: Ref object to attach to the chart container
|
|
76
|
-
- `instance`: ECharts instance (available after component mounts)
|
|
77
89
|
- `setOption`: Function to update chart options
|
|
90
|
+
- `getInstance`: Function to get the ECharts instance (available after component mounts)
|
|
78
91
|
|
|
79
92
|
## ๐ค Contributing
|
|
80
93
|
|
package/dist/index.d.ts
CHANGED
|
@@ -55,44 +55,24 @@ export declare interface EChartsEvents {
|
|
|
55
55
|
export declare type Theme = string | object | null;
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* @param options
|
|
62
|
-
* @param options.
|
|
63
|
-
* @param options.
|
|
64
|
-
* @param options.
|
|
65
|
-
* @param options.
|
|
66
|
-
* @param options.
|
|
67
|
-
* @
|
|
68
|
-
* @param options.onEvents - Event handlers for the chart
|
|
69
|
-
* @returns Object containing chart reference and control functions
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```typescript
|
|
73
|
-
* const { chartRef, setOption, getInstance } = useECharts({
|
|
74
|
-
* option: {
|
|
75
|
-
* xAxis: { type: 'category', data: ['A', 'B', 'C'] },
|
|
76
|
-
* yAxis: { type: 'value' },
|
|
77
|
-
* series: [{ data: [120, 200, 150], type: 'line' }]
|
|
78
|
-
* },
|
|
79
|
-
* onEvents: {
|
|
80
|
-
* 'click': {
|
|
81
|
-
* handler: (params) => console.log('clicked', params)
|
|
82
|
-
* }
|
|
83
|
-
* }
|
|
84
|
-
* });
|
|
85
|
-
*
|
|
86
|
-
* return <div ref={chartRef} style={{ width: '100%', height: '400px' }} />;
|
|
87
|
-
* ```
|
|
58
|
+
* React hook for Apache ECharts integration
|
|
59
|
+
* @param options Configuration object
|
|
60
|
+
* @param options.option Chart configuration
|
|
61
|
+
* @param options.theme Chart theme name
|
|
62
|
+
* @param options.notMerge Skip merging with previous options
|
|
63
|
+
* @param options.lazyUpdate Enable lazy update mode
|
|
64
|
+
* @param options.showLoading Display loading animation
|
|
65
|
+
* @param options.loadingOption Loading animation config
|
|
66
|
+
* @param options.onEvents Event handlers map
|
|
67
|
+
* @returns Chart control methods and ref
|
|
88
68
|
*/
|
|
89
|
-
export declare const
|
|
69
|
+
export declare const useEcharts: ({ option, theme, notMerge, lazyUpdate, showLoading, loadingOption, onEvents, }: UseEchartsOptions) => UseEchartsReturn;
|
|
90
70
|
|
|
91
71
|
/**
|
|
92
|
-
* Configuration options for
|
|
93
|
-
*
|
|
72
|
+
* Configuration options for useEcharts hook
|
|
73
|
+
* useEcharts hook ็้
็ฝฎ้้กน
|
|
94
74
|
*/
|
|
95
|
-
export declare interface
|
|
75
|
+
export declare interface UseEchartsOptions {
|
|
96
76
|
/**
|
|
97
77
|
* ECharts configuration options
|
|
98
78
|
* ECharts ็้
็ฝฎ้กน
|
|
@@ -134,10 +114,10 @@ export declare interface UseEChartsOptions {
|
|
|
134
114
|
}
|
|
135
115
|
|
|
136
116
|
/**
|
|
137
|
-
* Return type for
|
|
138
|
-
*
|
|
117
|
+
* Return type for useEcharts hook
|
|
118
|
+
* useEcharts hook ็่ฟๅ็ฑปๅ
|
|
139
119
|
*/
|
|
140
|
-
export declare interface
|
|
120
|
+
export declare interface UseEchartsReturn {
|
|
141
121
|
/**
|
|
142
122
|
* Reference to the chart container element
|
|
143
123
|
* ๅพ่กจๅฎนๅจๅ
็ด ็ๅผ็จ
|
package/dist/index.es.js
CHANGED
|
@@ -1,84 +1,72 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
import * as
|
|
3
|
-
const
|
|
4
|
-
/**
|
|
5
|
-
* Chart configuration options
|
|
6
|
-
* ๅพ่กจ้
็ฝฎ้้กน
|
|
7
|
-
*/
|
|
1
|
+
import { useRef as p, useCallback as z, useEffect as w } from "react";
|
|
2
|
+
import * as C from "echarts";
|
|
3
|
+
const R = ({
|
|
4
|
+
/** Chart configuration */
|
|
8
5
|
option: f,
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Whether to merge options or not
|
|
16
|
-
* ๆฏๅฆๅๅนถ้้กน
|
|
17
|
-
* @default false
|
|
18
|
-
*/
|
|
19
|
-
notMerge: a = !1,
|
|
20
|
-
/**
|
|
21
|
-
* Whether to update chart lazily or not
|
|
22
|
-
* ๆฏๅฆๆๆดๆฐๅพ่กจ
|
|
23
|
-
* @default false
|
|
24
|
-
*/
|
|
6
|
+
/** Theme name */
|
|
7
|
+
theme: a,
|
|
8
|
+
/** Skip merging with previous options */
|
|
9
|
+
notMerge: m = !1,
|
|
10
|
+
/** Enable lazy update mode */
|
|
25
11
|
lazyUpdate: l = !1,
|
|
26
|
-
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Loading animation configuration options
|
|
34
|
-
* ๅ ่ฝฝๅจ็ป้
็ฝฎ้้กน
|
|
35
|
-
*/
|
|
36
|
-
loadingOption: h,
|
|
37
|
-
/**
|
|
38
|
-
* Event handlers for the chart
|
|
39
|
-
* ๅพ่กจไบไปถๅค็ๅฝๆฐ
|
|
40
|
-
*/
|
|
41
|
-
onEvents: c
|
|
12
|
+
/** Display loading animation */
|
|
13
|
+
showLoading: h = !1,
|
|
14
|
+
/** Loading animation config */
|
|
15
|
+
loadingOption: d,
|
|
16
|
+
/** Event handlers map */
|
|
17
|
+
onEvents: s
|
|
42
18
|
}) => {
|
|
43
|
-
const
|
|
44
|
-
(
|
|
45
|
-
|
|
46
|
-
|
|
19
|
+
const c = p(null), t = p(), O = () => t.current, u = z(() => {
|
|
20
|
+
if (c.current && !t.current) {
|
|
21
|
+
const e = C.init(c.current, a);
|
|
22
|
+
return t.current = e, s && Object.entries(s).forEach(
|
|
23
|
+
([r, { handler: n, query: i, context: o }]) => {
|
|
24
|
+
i ? e.on(r, i, n, o) : e.on(r, n, o);
|
|
25
|
+
}
|
|
26
|
+
), h ? e.showLoading(d) : e.hideLoading(), e.setOption(f, { notMerge: m, lazyUpdate: l }), e;
|
|
27
|
+
}
|
|
28
|
+
return t.current;
|
|
29
|
+
}, [
|
|
30
|
+
f,
|
|
31
|
+
a,
|
|
32
|
+
m,
|
|
33
|
+
l,
|
|
34
|
+
h,
|
|
35
|
+
d,
|
|
36
|
+
s
|
|
37
|
+
]), b = z(
|
|
38
|
+
(e, r) => {
|
|
39
|
+
requestAnimationFrame(() => {
|
|
40
|
+
const n = t.current || u();
|
|
41
|
+
n && n.setOption(e, r);
|
|
42
|
+
});
|
|
47
43
|
},
|
|
48
|
-
[]
|
|
44
|
+
[u]
|
|
49
45
|
);
|
|
50
|
-
return
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
};
|
|
63
|
-
}, [o, c]), i(() => {
|
|
64
|
-
r.current && (d ? r.current.showLoading(h) : r.current.hideLoading(), r.current.setOption(f, {
|
|
65
|
-
notMerge: a,
|
|
66
|
-
lazyUpdate: l
|
|
67
|
-
}));
|
|
68
|
-
}, [f, a, l, d, h]), i(() => {
|
|
69
|
-
const e = () => {
|
|
70
|
-
var t;
|
|
71
|
-
(t = r.current) == null || t.resize();
|
|
46
|
+
return w(() => {
|
|
47
|
+
const e = t.current;
|
|
48
|
+
if (!e) return;
|
|
49
|
+
const r = () => {
|
|
50
|
+
const i = setTimeout(() => {
|
|
51
|
+
e == null || e.resize();
|
|
52
|
+
}, 250);
|
|
53
|
+
return () => clearTimeout(i);
|
|
54
|
+
}, n = r();
|
|
55
|
+
return window.addEventListener("resize", r), () => {
|
|
56
|
+
s && Object.entries(s).forEach(([i, { handler: o }]) => {
|
|
57
|
+
e.off(i, o);
|
|
58
|
+
}), window.removeEventListener("resize", r), e.dispose(), t.current = void 0, n();
|
|
72
59
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
60
|
+
}, [s]), w(() => {
|
|
61
|
+
c.current && requestAnimationFrame(() => {
|
|
62
|
+
u();
|
|
63
|
+
});
|
|
64
|
+
}, [c, u]), {
|
|
65
|
+
chartRef: c,
|
|
66
|
+
setOption: b,
|
|
67
|
+
getInstance: O
|
|
80
68
|
};
|
|
81
69
|
};
|
|
82
70
|
export {
|
|
83
|
-
|
|
71
|
+
R as useEcharts
|
|
84
72
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(r,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("react"),require("echarts")):typeof define=="function"&&define.amd?define(["exports","react","echarts"],t):(r=typeof globalThis<"u"?globalThis:r||self,t(r["react-use-echarts"]={},r.React,r.echarts))})(this,function(r,t,O){"use strict";function j(n){const f=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const i in n)if(i!=="default"){const d=Object.getOwnPropertyDescriptor(n,i);Object.defineProperty(f,i,d.get?d:{enumerable:!0,get:()=>n[i]})}}return f.default=n,Object.freeze(f)}const T=j(O),z=({option:n,theme:f,notMerge:i=!1,lazyUpdate:d=!1,showLoading:m=!1,loadingOption:b,onEvents:o})=>{const l=t.useRef(null),c=t.useRef(),g=()=>c.current,h=t.useCallback(()=>{if(l.current&&!c.current){const e=T.init(l.current,f);return c.current=e,o&&Object.entries(o).forEach(([s,{handler:u,query:a,context:p}])=>{a?e.on(s,a,u,p):e.on(s,u,p)}),m?e.showLoading(b):e.hideLoading(),e.setOption(n,{notMerge:i,lazyUpdate:d}),e}return c.current},[n,f,i,d,m,b,o]),w=t.useCallback((e,s)=>{requestAnimationFrame(()=>{const u=c.current||h();u&&u.setOption(e,s)})},[h]);return t.useEffect(()=>{const e=c.current;if(!e)return;const s=()=>{const a=setTimeout(()=>{e==null||e.resize()},250);return()=>clearTimeout(a)},u=s();return window.addEventListener("resize",s),()=>{o&&Object.entries(o).forEach(([a,{handler:p}])=>{e.off(a,p)}),window.removeEventListener("resize",s),e.dispose(),c.current=void 0,u()}},[o]),t.useEffect(()=>{l.current&&requestAnimationFrame(()=>{h()})},[l,h]),{chartRef:l,setOption:w,getInstance:g}};r.useEcharts=z,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-use-echarts",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.5",
|
|
5
5
|
"description": "A powerful React hooks library for Apache ECharts",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"react",
|
|
@@ -42,21 +42,25 @@
|
|
|
42
42
|
],
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@eslint/js": "^9.15.0",
|
|
45
|
-
"@
|
|
45
|
+
"@testing-library/react": "^16.0.1",
|
|
46
|
+
"@types/node": "^22.9.1",
|
|
46
47
|
"@types/react": "^18.3.12",
|
|
47
48
|
"@types/react-dom": "^18.3.1",
|
|
48
49
|
"@vitejs/plugin-react-swc": "^3.7.1",
|
|
50
|
+
"@vitest/coverage-v8": "2.1.5",
|
|
49
51
|
"echarts": "^5.5.1",
|
|
50
52
|
"eslint": "^9.15.0",
|
|
51
53
|
"eslint-plugin-react-hooks": "^5.0.0",
|
|
52
54
|
"eslint-plugin-react-refresh": "^0.4.14",
|
|
53
55
|
"globals": "^15.12.0",
|
|
56
|
+
"jsdom": "^25.0.1",
|
|
54
57
|
"react": "^18.3.1",
|
|
55
58
|
"react-dom": "^18.3.1",
|
|
56
59
|
"typescript": "~5.6.3",
|
|
57
60
|
"typescript-eslint": "^8.15.0",
|
|
58
61
|
"vite": "^5.4.11",
|
|
59
|
-
"vite-plugin-dts": "^4.3.0"
|
|
62
|
+
"vite-plugin-dts": "^4.3.0",
|
|
63
|
+
"vitest": "^2.1.5"
|
|
60
64
|
},
|
|
61
65
|
"peerDependencies": {
|
|
62
66
|
"echarts": "^5.5.1",
|
|
@@ -66,6 +70,8 @@
|
|
|
66
70
|
"scripts": {
|
|
67
71
|
"dev": "vite",
|
|
68
72
|
"build": "tsc -b && vite build",
|
|
73
|
+
"test": "vitest",
|
|
74
|
+
"coverage": "vitest run --coverage",
|
|
69
75
|
"lint": "eslint .",
|
|
70
76
|
"typecheck": "tsc -b"
|
|
71
77
|
}
|