@particle-academy/fancy-echarts 1.2.0 → 2.0.0
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 +217 -213
- package/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/docs/EChart.md +207 -207
- package/docs/EChart3D.md +178 -178
- package/docs/EChartGraphic.md +149 -149
- package/docs/registration.md +152 -152
- package/docs/themes.md +152 -152
- package/docs/useECharts.md +129 -129
- package/package.json +71 -66
package/README.md
CHANGED
|
@@ -1,213 +1,217 @@
|
|
|
1
|
-
# @particle-academy/fancy-echarts
|
|
2
|
-
|
|
3
|
-
React component library wrapping [Apache ECharts](https://echarts.apache.org/) with typed components for every chart type — 2D, 3D, and graphic layers.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
# npm
|
|
9
|
-
npm install @particle-academy/fancy-echarts echarts
|
|
10
|
-
|
|
11
|
-
# pnpm
|
|
12
|
-
pnpm add @particle-academy/fancy-echarts echarts
|
|
13
|
-
|
|
14
|
-
# yarn
|
|
15
|
-
yarn add @particle-academy/fancy-echarts echarts
|
|
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
|
-
option
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
|
81
|
-
|
|
82
|
-
| [
|
|
83
|
-
| [
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
|
107
|
-
|
|
108
|
-
| `
|
|
109
|
-
| `
|
|
110
|
-
| `
|
|
111
|
-
| `
|
|
112
|
-
| `
|
|
113
|
-
| `
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
**
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
1
|
+
# @particle-academy/fancy-echarts
|
|
2
|
+
|
|
3
|
+
React component library wrapping [Apache ECharts](https://echarts.apache.org/) with typed components for every chart type — 2D, 3D, and graphic layers.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# npm
|
|
9
|
+
npm install @particle-academy/fancy-echarts echarts
|
|
10
|
+
|
|
11
|
+
# pnpm
|
|
12
|
+
pnpm add @particle-academy/fancy-echarts echarts
|
|
13
|
+
|
|
14
|
+
# yarn
|
|
15
|
+
yarn add @particle-academy/fancy-echarts echarts
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`echarts` is a peer dependency — install it alongside fancy-echarts so you control the version and avoid bundling two copies if other parts of your app already use echarts.
|
|
19
|
+
|
|
20
|
+
For 3D charts (globe, surface, scatter3D, bar3D), also install `echarts-gl`:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install echarts-gl
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Peer dependencies:** `react >= 18`, `react-dom >= 18`, `echarts >= 5.5`, `echarts-gl >= 2.0` (optional, only needed for 3D)
|
|
27
|
+
|
|
28
|
+
> **Breaking change in 2.0** — `echarts` and `echarts-gl` moved from regular dependencies to peer dependencies. Upgrading from 1.x? Run `npm install echarts` (and `echarts-gl` if you use 3D charts) once.
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
import { EChart, registerAll } from "@particle-academy/fancy-echarts";
|
|
34
|
+
|
|
35
|
+
// Register all chart types (convenience for quick start)
|
|
36
|
+
registerAll();
|
|
37
|
+
|
|
38
|
+
function App() {
|
|
39
|
+
return (
|
|
40
|
+
<EChart
|
|
41
|
+
option={{
|
|
42
|
+
xAxis: { type: "category", data: ["Mon", "Tue", "Wed", "Thu", "Fri"] },
|
|
43
|
+
yAxis: { type: "value" },
|
|
44
|
+
series: [{ type: "bar", data: [120, 200, 150, 80, 70] }],
|
|
45
|
+
}}
|
|
46
|
+
/>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Security: untrusted formatter strings
|
|
52
|
+
|
|
53
|
+
ECharts permits HTML strings in many `option` text fields — `tooltip.formatter`, `title.subtext`, `legend.formatter`, axis label `formatter`, etc. The wrapper forwards your `option` to ECharts as-is. If a formatter string interpolates user-generated data, sanitize it first or use a function formatter and assemble safe DOM:
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
// ❌ Unsafe — user-controlled name renders as HTML
|
|
57
|
+
option={{
|
|
58
|
+
tooltip: { formatter: `<b>${userName}</b>: ${value}` },
|
|
59
|
+
}}
|
|
60
|
+
|
|
61
|
+
// ✅ Function formatter, escape user input
|
|
62
|
+
option={{
|
|
63
|
+
tooltip: {
|
|
64
|
+
formatter: (params) => {
|
|
65
|
+
const safe = params.name.replace(/[&<>"']/g, (c) => ({
|
|
66
|
+
"&": "&", "<": "<", ">": ">", '"': """, "'": "'",
|
|
67
|
+
}[c]!));
|
|
68
|
+
return `<b>${safe}</b>: ${params.value}`;
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
}}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
This is consumer responsibility — the wrapper does not introspect `option` to identify HTML-bearing fields.
|
|
75
|
+
|
|
76
|
+
## Documentation
|
|
77
|
+
|
|
78
|
+
Full component documentation is available in the [docs/](docs/) folder:
|
|
79
|
+
|
|
80
|
+
| Topic | Description |
|
|
81
|
+
|-------|-------------|
|
|
82
|
+
| [EChart](docs/EChart.md) | Base chart component + all 20 series sub-components |
|
|
83
|
+
| [EChart3D](docs/EChart3D.md) | 3D charts (Bar, Scatter, Line, Surface, Globe) |
|
|
84
|
+
| [EChartGraphic](docs/EChartGraphic.md) | Custom drawing with the graphic API |
|
|
85
|
+
| [useECharts](docs/useECharts.md) | Core hook for custom integrations |
|
|
86
|
+
| [Registration](docs/registration.md) | Tree shaking and selective chart registration |
|
|
87
|
+
| [Themes](docs/themes.md) | Built-in themes and custom theme creation |
|
|
88
|
+
|
|
89
|
+
## Components
|
|
90
|
+
|
|
91
|
+
### `<EChart>` — Base Component
|
|
92
|
+
|
|
93
|
+
Accepts any ECharts option object. Full power of ECharts with React lifecycle management.
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
<EChart
|
|
97
|
+
option={echartsOption}
|
|
98
|
+
theme="dark"
|
|
99
|
+
renderer="canvas"
|
|
100
|
+
autoResize={true}
|
|
101
|
+
onEvents={{ click: (params) => console.log(params) }}
|
|
102
|
+
style={{ height: 500 }}
|
|
103
|
+
/>
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
| Prop | Type | Default | Description |
|
|
107
|
+
|------|------|---------|-------------|
|
|
108
|
+
| `option` | `EChartsOption` | — | ECharts option object |
|
|
109
|
+
| `theme` | `string \| object` | auto | Theme name or object. Auto-detects dark mode if omitted |
|
|
110
|
+
| `renderer` | `"canvas" \| "svg"` | `"canvas"` | Rendering engine |
|
|
111
|
+
| `notMerge` | `boolean` | `false` | Replace option instead of merging |
|
|
112
|
+
| `lazyUpdate` | `boolean` | `false` | Delay chart update |
|
|
113
|
+
| `showLoading` | `boolean` | `false` | Show loading animation |
|
|
114
|
+
| `loadingOption` | `object` | — | Loading animation config |
|
|
115
|
+
| `onEvents` | `Record<string, Function>` | — | Event handlers (`click`, `mouseover`, etc.) |
|
|
116
|
+
| `autoResize` | `boolean` | `true` | Auto-resize on container change |
|
|
117
|
+
| `style` | `CSSProperties` | `{ width: "100%", height: 400 }` | Container style |
|
|
118
|
+
|
|
119
|
+
### `<EChart3D>` — 3D Charts
|
|
120
|
+
|
|
121
|
+
Separate component that automatically loads `echarts-gl` before rendering. Shows a loading placeholder until the 3D engine is ready.
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
import { EChart3D } from "@particle-academy/fancy-echarts";
|
|
125
|
+
|
|
126
|
+
<EChart3D
|
|
127
|
+
option={{
|
|
128
|
+
globe: {
|
|
129
|
+
baseColor: "#1a3b5c",
|
|
130
|
+
shading: "color",
|
|
131
|
+
atmosphere: { show: true },
|
|
132
|
+
viewControl: { autoRotate: true },
|
|
133
|
+
},
|
|
134
|
+
}}
|
|
135
|
+
style={{ height: 500 }}
|
|
136
|
+
/>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### `<EChartGraphic>` — Graphic Layer
|
|
140
|
+
|
|
141
|
+
For custom drawing with the ECharts graphic API.
|
|
142
|
+
|
|
143
|
+
```tsx
|
|
144
|
+
import { EChartGraphic } from "@particle-academy/fancy-echarts";
|
|
145
|
+
|
|
146
|
+
<EChartGraphic
|
|
147
|
+
elements={[
|
|
148
|
+
{ type: "circle", shape: { cx: 100, cy: 100, r: 50 }, style: { fill: "#5470c6" } },
|
|
149
|
+
{ type: "text", style: { text: "Hello", x: 100, y: 100, fill: "#fff" } },
|
|
150
|
+
]}
|
|
151
|
+
/>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Hooks
|
|
155
|
+
|
|
156
|
+
### `useECharts`
|
|
157
|
+
|
|
158
|
+
Core hook for custom integrations:
|
|
159
|
+
|
|
160
|
+
```tsx
|
|
161
|
+
import { useECharts } from "@particle-academy/fancy-echarts";
|
|
162
|
+
|
|
163
|
+
function CustomChart() {
|
|
164
|
+
const { chartRef, instance } = useECharts({
|
|
165
|
+
option: { /* ... */ },
|
|
166
|
+
autoResize: true,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
return <div ref={chartRef} style={{ width: "100%", height: 400 }} />;
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Dark Mode
|
|
174
|
+
|
|
175
|
+
Dark mode is automatic. When no `theme` prop is provided, the component detects `prefers-color-scheme: dark` and applies ECharts' built-in dark theme with a transparent background (so charts blend with your page's dark background). The theme updates reactively when the user toggles their system preference.
|
|
176
|
+
|
|
177
|
+
To override, pass a specific `theme` prop:
|
|
178
|
+
|
|
179
|
+
```tsx
|
|
180
|
+
<EChart option={option} theme="dark" /> {/* Always dark */}
|
|
181
|
+
<EChart option={option} theme="vintage" /> {/* Always vintage */}
|
|
182
|
+
<EChart option={option} /> {/* Auto dark/light */}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Tree Shaking
|
|
186
|
+
|
|
187
|
+
For production bundle optimization, use `registerCharts` to register only the chart types you need instead of `registerAll`:
|
|
188
|
+
|
|
189
|
+
```tsx
|
|
190
|
+
import { registerCharts, BarChart, LineChart, GridComponent, TooltipComponent, CanvasRenderer } from "@particle-academy/fancy-echarts";
|
|
191
|
+
|
|
192
|
+
registerCharts([BarChart, LineChart, GridComponent, TooltipComponent, CanvasRenderer]);
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Themes
|
|
196
|
+
|
|
197
|
+
Built-in theme presets:
|
|
198
|
+
|
|
199
|
+
```tsx
|
|
200
|
+
import { registerBuiltinThemes } from "@particle-academy/fancy-echarts";
|
|
201
|
+
|
|
202
|
+
registerBuiltinThemes(); // Registers "dark-preset", "vintage", "pastel"
|
|
203
|
+
|
|
204
|
+
<EChart option={option} theme="vintage" />
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Supported Chart Types
|
|
208
|
+
|
|
209
|
+
**2D Charts:** Line, Bar, Pie, Scatter, Radar, Heatmap, Candlestick, Boxplot, Treemap, Sunburst, Funnel, Gauge, Sankey, Graph, Parallel, ThemeRiver, Calendar, PictorialBar, Map, Custom, EffectScatter
|
|
210
|
+
|
|
211
|
+
**3D Charts:** Bar3D, Scatter3D, Line3D, Surface, Globe
|
|
212
|
+
|
|
213
|
+
**Graphic:** Rect, Circle, Ring, Arc, Polygon, Polyline, Path, Image, Text, Group — with keyframe animation support
|
|
214
|
+
|
|
215
|
+
## License
|
|
216
|
+
|
|
217
|
+
MIT
|