@particle-academy/fancy-echarts 1.2.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 ADDED
@@ -0,0 +1,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
+ 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