@ai-gui/plugin-chart 0.1.0 → 0.3.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
@@ -8,6 +8,12 @@ Chart plugin for [AIGUI](../../README.md), powered by [ECharts](https://echarts.
8
8
  pnpm add @ai-gui/plugin-chart
9
9
  ```
10
10
 
11
+ Install `echarts-gl` only when using `chart({ gl: true })`:
12
+
13
+ ```sh
14
+ pnpm add echarts-gl
15
+ ```
16
+
11
17
  ## Usage
12
18
 
13
19
  ```tsx
@@ -24,7 +30,7 @@ The model emits, e.g.:
24
30
  ## Options
25
31
 
26
32
  - `interactive?: boolean` — when true, complete options render a **live** ECharts instance (tooltip / dataZoom / click) via a `mount` output. When false/omitted, they render a static SSR SVG.
27
- - `gl?: boolean` — when true, render 3D charts via `echarts-gl` (WebGL, live-only; implies interactive). Enables 3D series like `bar3D`, `scatter3D`, `surface`, `line3D`, `globe`, `map3D`.
33
+ - `gl?: boolean` — when true, render 3D charts via the optional `echarts-gl` peer dependency (WebGL, live-only; implies interactive). Enables 3D series like `bar3D`, `scatter3D`, `surface`, `line3D`, `globe`, `map3D`.
28
34
  - `width?: number` / `height?: number` — chart dimensions (default 600 × 400).
29
35
 
30
36
  ## Exports
package/dist/index.cjs CHANGED
@@ -22,10 +22,65 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
22
  }) : target, mod));
23
23
 
24
24
  //#endregion
25
- const echarts = __toESM(require("echarts"));
25
+ const echarts_charts = __toESM(require("echarts/charts"));
26
+ const echarts_components = __toESM(require("echarts/components"));
27
+ const echarts_core = __toESM(require("echarts/core"));
28
+ const echarts_features = __toESM(require("echarts/features"));
29
+ const echarts_renderers = __toESM(require("echarts/renderers"));
26
30
  const __ai_gui_core = __toESM(require("@ai-gui/core"));
27
31
 
28
32
  //#region src/index.ts
33
+ (0, echarts_core.use)([
34
+ echarts_charts.BarChart,
35
+ echarts_charts.BoxplotChart,
36
+ echarts_charts.CandlestickChart,
37
+ echarts_charts.CustomChart,
38
+ echarts_charts.EffectScatterChart,
39
+ echarts_charts.FunnelChart,
40
+ echarts_charts.GaugeChart,
41
+ echarts_charts.GraphChart,
42
+ echarts_charts.HeatmapChart,
43
+ echarts_charts.LineChart,
44
+ echarts_charts.LinesChart,
45
+ echarts_charts.MapChart,
46
+ echarts_charts.ParallelChart,
47
+ echarts_charts.PictorialBarChart,
48
+ echarts_charts.PieChart,
49
+ echarts_charts.RadarChart,
50
+ echarts_charts.SankeyChart,
51
+ echarts_charts.ScatterChart,
52
+ echarts_charts.SunburstChart,
53
+ echarts_charts.ThemeRiverChart,
54
+ echarts_charts.TreeChart,
55
+ echarts_charts.TreemapChart,
56
+ echarts_components.AriaComponent,
57
+ echarts_components.AxisPointerComponent,
58
+ echarts_components.BrushComponent,
59
+ echarts_components.CalendarComponent,
60
+ echarts_components.DataZoomComponent,
61
+ echarts_components.DatasetComponent,
62
+ echarts_components.GeoComponent,
63
+ echarts_components.GraphicComponent,
64
+ echarts_components.GridComponent,
65
+ echarts_components.LegendComponent,
66
+ echarts_components.MarkAreaComponent,
67
+ echarts_components.MarkLineComponent,
68
+ echarts_components.MarkPointComponent,
69
+ echarts_components.ParallelComponent,
70
+ echarts_components.PolarComponent,
71
+ echarts_components.RadarComponent,
72
+ echarts_components.SingleAxisComponent,
73
+ echarts_components.TimelineComponent,
74
+ echarts_components.TitleComponent,
75
+ echarts_components.ToolboxComponent,
76
+ echarts_components.TooltipComponent,
77
+ echarts_components.TransformComponent,
78
+ echarts_components.VisualMapComponent,
79
+ echarts_features.LabelLayout,
80
+ echarts_features.UniversalTransition,
81
+ echarts_renderers.CanvasRenderer,
82
+ echarts_renderers.SVGRenderer
83
+ ]);
29
84
  /** Memoized `echarts-gl` side-effect import, shared across all mounts. */
30
85
  let glReady = null;
31
86
  const loadGl = () => glReady ??= import("echarts-gl");
@@ -57,19 +112,22 @@ function chart(opts = {}) {
57
112
  return {
58
113
  kind: "mount",
59
114
  mount: (el) => {
60
- let inst;
115
+ let inst$1;
61
116
  let disposed = false;
62
117
  loadGl().then(() => {
63
118
  if (disposed) return;
64
- inst = echarts.init(el, void 0, {
119
+ inst$1 = (0, echarts_core.init)(el, void 0, {
65
120
  width,
66
121
  height
67
122
  });
68
- inst.setOption(opt);
69
- }).catch(() => {});
123
+ inst$1.setOption(opt);
124
+ }).catch(() => {
125
+ inst$1?.dispose();
126
+ inst$1 = void 0;
127
+ });
70
128
  return () => {
71
129
  disposed = true;
72
- inst?.dispose();
130
+ inst$1?.dispose();
73
131
  };
74
132
  }
75
133
  };
@@ -79,18 +137,24 @@ function chart(opts = {}) {
79
137
  return {
80
138
  kind: "mount",
81
139
  mount: (el) => {
82
- const inst = echarts.init(el, void 0, {
140
+ const inst$1 = (0, echarts_core.init)(el, void 0, {
83
141
  renderer: "svg",
84
142
  width,
85
143
  height
86
144
  });
87
- inst.setOption(opt);
88
- return () => inst.dispose();
145
+ try {
146
+ inst$1.setOption(opt);
147
+ } catch {
148
+ inst$1.dispose();
149
+ return;
150
+ }
151
+ return () => inst$1.dispose();
89
152
  }
90
153
  };
91
154
  }
155
+ let inst;
92
156
  try {
93
- const inst = echarts.init(null, null, {
157
+ inst = (0, echarts_core.init)(null, null, {
94
158
  renderer: "svg",
95
159
  ssr: true,
96
160
  width,
@@ -98,7 +162,6 @@ function chart(opts = {}) {
98
162
  });
99
163
  inst.setOption(option);
100
164
  const svg = inst.renderToSVGString();
101
- inst.dispose();
102
165
  return {
103
166
  kind: "html",
104
167
  html: svg
@@ -108,6 +171,8 @@ function chart(opts = {}) {
108
171
  kind: "html",
109
172
  html: `<pre data-aigui-chart-error>${String(e?.message ?? e)}</pre>`
110
173
  };
174
+ } finally {
175
+ inst?.dispose();
111
176
  }
112
177
  };
113
178
  return {
package/dist/index.js CHANGED
@@ -1,7 +1,62 @@
1
- import * as echarts from "echarts";
1
+ import { BarChart, BoxplotChart, CandlestickChart, CustomChart, EffectScatterChart, FunnelChart, GaugeChart, GraphChart, HeatmapChart, LineChart, LinesChart, MapChart, ParallelChart, PictorialBarChart, PieChart, RadarChart, SankeyChart, ScatterChart, SunburstChart, ThemeRiverChart, TreeChart, TreemapChart } from "echarts/charts";
2
+ import { AriaComponent, AxisPointerComponent, BrushComponent, CalendarComponent, DataZoomComponent, DatasetComponent, GeoComponent, GraphicComponent, GridComponent, LegendComponent, MarkAreaComponent, MarkLineComponent, MarkPointComponent, ParallelComponent, PolarComponent, RadarComponent, SingleAxisComponent, TimelineComponent, TitleComponent, ToolboxComponent, TooltipComponent, TransformComponent, VisualMapComponent } from "echarts/components";
3
+ import { init, use } from "echarts/core";
4
+ import { LabelLayout, UniversalTransition } from "echarts/features";
5
+ import { CanvasRenderer, SVGRenderer } from "echarts/renderers";
2
6
  import { parsePartialJSON } from "@ai-gui/core";
3
7
 
4
8
  //#region src/index.ts
9
+ use([
10
+ BarChart,
11
+ BoxplotChart,
12
+ CandlestickChart,
13
+ CustomChart,
14
+ EffectScatterChart,
15
+ FunnelChart,
16
+ GaugeChart,
17
+ GraphChart,
18
+ HeatmapChart,
19
+ LineChart,
20
+ LinesChart,
21
+ MapChart,
22
+ ParallelChart,
23
+ PictorialBarChart,
24
+ PieChart,
25
+ RadarChart,
26
+ SankeyChart,
27
+ ScatterChart,
28
+ SunburstChart,
29
+ ThemeRiverChart,
30
+ TreeChart,
31
+ TreemapChart,
32
+ AriaComponent,
33
+ AxisPointerComponent,
34
+ BrushComponent,
35
+ CalendarComponent,
36
+ DataZoomComponent,
37
+ DatasetComponent,
38
+ GeoComponent,
39
+ GraphicComponent,
40
+ GridComponent,
41
+ LegendComponent,
42
+ MarkAreaComponent,
43
+ MarkLineComponent,
44
+ MarkPointComponent,
45
+ ParallelComponent,
46
+ PolarComponent,
47
+ RadarComponent,
48
+ SingleAxisComponent,
49
+ TimelineComponent,
50
+ TitleComponent,
51
+ ToolboxComponent,
52
+ TooltipComponent,
53
+ TransformComponent,
54
+ VisualMapComponent,
55
+ LabelLayout,
56
+ UniversalTransition,
57
+ CanvasRenderer,
58
+ SVGRenderer
59
+ ]);
5
60
  /** Memoized `echarts-gl` side-effect import, shared across all mounts. */
6
61
  let glReady = null;
7
62
  const loadGl = () => glReady ??= import("echarts-gl");
@@ -33,19 +88,22 @@ function chart(opts = {}) {
33
88
  return {
34
89
  kind: "mount",
35
90
  mount: (el) => {
36
- let inst;
91
+ let inst$1;
37
92
  let disposed = false;
38
93
  loadGl().then(() => {
39
94
  if (disposed) return;
40
- inst = echarts.init(el, void 0, {
95
+ inst$1 = init(el, void 0, {
41
96
  width,
42
97
  height
43
98
  });
44
- inst.setOption(opt);
45
- }).catch(() => {});
99
+ inst$1.setOption(opt);
100
+ }).catch(() => {
101
+ inst$1?.dispose();
102
+ inst$1 = void 0;
103
+ });
46
104
  return () => {
47
105
  disposed = true;
48
- inst?.dispose();
106
+ inst$1?.dispose();
49
107
  };
50
108
  }
51
109
  };
@@ -55,18 +113,24 @@ function chart(opts = {}) {
55
113
  return {
56
114
  kind: "mount",
57
115
  mount: (el) => {
58
- const inst = echarts.init(el, void 0, {
116
+ const inst$1 = init(el, void 0, {
59
117
  renderer: "svg",
60
118
  width,
61
119
  height
62
120
  });
63
- inst.setOption(opt);
64
- return () => inst.dispose();
121
+ try {
122
+ inst$1.setOption(opt);
123
+ } catch {
124
+ inst$1.dispose();
125
+ return;
126
+ }
127
+ return () => inst$1.dispose();
65
128
  }
66
129
  };
67
130
  }
131
+ let inst;
68
132
  try {
69
- const inst = echarts.init(null, null, {
133
+ inst = init(null, null, {
70
134
  renderer: "svg",
71
135
  ssr: true,
72
136
  width,
@@ -74,7 +138,6 @@ function chart(opts = {}) {
74
138
  });
75
139
  inst.setOption(option);
76
140
  const svg = inst.renderToSVGString();
77
- inst.dispose();
78
141
  return {
79
142
  kind: "html",
80
143
  html: svg
@@ -84,6 +147,8 @@ function chart(opts = {}) {
84
147
  kind: "html",
85
148
  html: `<pre data-aigui-chart-error>${String(e?.message ?? e)}</pre>`
86
149
  };
150
+ } finally {
151
+ inst?.dispose();
87
152
  }
88
153
  };
89
154
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-gui/plugin-chart",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "ECharts chart plugin for AIGUI — static SVG, interactive, and 3D (echarts-gl).",
5
5
  "keywords": [
6
6
  "llm",
@@ -24,14 +24,23 @@
24
24
  "homepage": "https://github.com/liliang-cn/aigui#readme",
25
25
  "bugs": "https://github.com/liliang-cn/aigui/issues",
26
26
  "type": "module",
27
+ "sideEffects": false,
28
+ "engines": {
29
+ "node": ">=18"
30
+ },
27
31
  "main": "./dist/index.cjs",
28
32
  "module": "./dist/index.js",
29
33
  "types": "./dist/index.d.ts",
30
34
  "exports": {
31
35
  ".": {
32
- "types": "./dist/index.d.ts",
33
- "import": "./dist/index.js",
34
- "require": "./dist/index.cjs"
36
+ "import": {
37
+ "types": "./dist/index.d.ts",
38
+ "default": "./dist/index.js"
39
+ },
40
+ "require": {
41
+ "types": "./dist/index.d.cts",
42
+ "default": "./dist/index.cjs"
43
+ }
35
44
  }
36
45
  },
37
46
  "files": [
@@ -44,11 +53,22 @@
44
53
  },
45
54
  "dependencies": {
46
55
  "echarts": "^5.5.1",
47
- "echarts-gl": "^2.0.9",
48
- "@ai-gui/core": "0.1.0"
56
+ "@ai-gui/core": "0.3.0"
57
+ },
58
+ "peerDependencies": {
59
+ "echarts-gl": "^2.0.9"
60
+ },
61
+ "peerDependenciesMeta": {
62
+ "echarts-gl": {
63
+ "optional": true
64
+ }
65
+ },
66
+ "devDependencies": {
67
+ "echarts-gl": "^2.0.9"
49
68
  },
50
69
  "scripts": {
51
70
  "build": "tsdown",
71
+ "test": "pnpm --dir ../.. exec vitest run --project plugin-chart",
52
72
  "typecheck": "tsc --noEmit"
53
73
  }
54
74
  }