react-use-echarts 0.0.4 → 0.0.6
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 +6 -3
- package/dist/index.d.ts +10 -30
- package/dist/index.es.js +62 -74
- package/dist/index.umd.js +1 -1
- package/package.json +17 -11
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 { useEcharts } from 'react-use-echarts';
|
|
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']
|
|
@@ -64,7 +67,7 @@ The main hook for using ECharts in React components.
|
|
|
64
67
|
|
|
65
68
|
```tsx
|
|
66
69
|
const { chartRef, setOption, getInstance } = useEcharts({
|
|
67
|
-
option:
|
|
70
|
+
option: UseEchartsOptions['option']; // ECharts options configuration (required)
|
|
68
71
|
theme?: string | object; // ECharts theme name or configuration
|
|
69
72
|
notMerge?: boolean; // Whether to not merge with previous options
|
|
70
73
|
lazyUpdate?: boolean; // Whether to update chart lazily
|
package/dist/index.d.ts
CHANGED
|
@@ -55,36 +55,16 @@ 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
69
|
export declare const useEcharts: ({ option, theme, notMerge, lazyUpdate, showLoading, loadingOption, onEvents, }: UseEchartsOptions) => UseEchartsReturn;
|
|
90
70
|
|
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.6",
|
|
5
5
|
"description": "A powerful React hooks library for Apache ECharts",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"react",
|
|
@@ -41,22 +41,26 @@
|
|
|
41
41
|
"dist"
|
|
42
42
|
],
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@eslint/js": "^9.
|
|
45
|
-
"@
|
|
44
|
+
"@eslint/js": "^9.16.0",
|
|
45
|
+
"@testing-library/react": "^16.0.1",
|
|
46
|
+
"@types/node": "^22.10.1",
|
|
46
47
|
"@types/react": "^18.3.12",
|
|
47
48
|
"@types/react-dom": "^18.3.1",
|
|
48
|
-
"@vitejs/plugin-react-swc": "^3.7.
|
|
49
|
+
"@vitejs/plugin-react-swc": "^3.7.2",
|
|
50
|
+
"@vitest/coverage-v8": "2.1.8",
|
|
49
51
|
"echarts": "^5.5.1",
|
|
50
|
-
"eslint": "^9.
|
|
52
|
+
"eslint": "^9.16.0",
|
|
51
53
|
"eslint-plugin-react-hooks": "^5.0.0",
|
|
52
|
-
"eslint-plugin-react-refresh": "^0.4.
|
|
53
|
-
"globals": "^15.
|
|
54
|
+
"eslint-plugin-react-refresh": "^0.4.16",
|
|
55
|
+
"globals": "^15.13.0",
|
|
56
|
+
"jsdom": "^25.0.1",
|
|
54
57
|
"react": "^18.3.1",
|
|
55
58
|
"react-dom": "^18.3.1",
|
|
56
|
-
"typescript": "~5.
|
|
57
|
-
"typescript-eslint": "^8.
|
|
58
|
-
"vite": "^
|
|
59
|
-
"vite-plugin-dts": "^4.3.0"
|
|
59
|
+
"typescript": "~5.7.2",
|
|
60
|
+
"typescript-eslint": "^8.17.0",
|
|
61
|
+
"vite": "^6.0.2",
|
|
62
|
+
"vite-plugin-dts": "^4.3.0",
|
|
63
|
+
"vitest": "^2.1.8"
|
|
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
|
}
|