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