@worm-print-platform/echarts 1.5.2 → 1.6.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/dist/ui.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @worm-print-platform/echarts v1.5.2
2
+ * @worm-print-platform/echarts v1.6.0
3
3
  * Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
4
4
  * SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
5
5
  * SPDX-License-Identifier: MIT
@@ -7,32 +7,1099 @@
7
7
 
8
8
  // src/ui.ts
9
9
  import { defineElementUI, registerElementUI } from "@worm-print-platform/plugin-kit";
10
+ import { render } from "@worm-print-platform/plugin-kit/dom";
11
+ import { colorPicker } from "@worm-print-platform/plugin-kit/controls";
12
+
13
+ // src/plugin.ts
10
14
  import {
11
- asObject,
12
- CHART_KINDS,
13
- cloneChartOption,
14
- createDefaultChartOption,
15
- FUNNEL_PADDING_DEFAULTS,
16
- getChartKindDefinition,
17
- getChartPalettes,
18
- normalizeChartOption,
19
- previewChartOption,
20
- RADAR_RADIUS_DEFAULT,
21
- readFunnelPadding,
22
- readPaletteKey,
23
- readRadarRadius,
24
- renderChartToSvg,
25
- resolveChartPanelFields,
26
- syncSeriesCount,
27
- writeFunnelPadding,
28
- writeRadarRadius
29
- } from "@worm-print-platform/echarts/kit";
15
+ defineElementPlugin,
16
+ getElementPluginById,
17
+ registerElementPlugin
18
+ } from "@worm-print-platform/core/designer";
19
+
20
+ // src/kinds.ts
21
+ var BASE_REQUIRED = ["left", "top", "width", "height", "chartOption"];
22
+ var DATA_FIELDS = ["dataSource", "categoryField", "valueFields", "seriesField"];
23
+ var STYLE_FIELDS = ["title", "legend", "palette"];
24
+ var CHART_KIND_DEFINITIONS = [
25
+ {
26
+ type: "barChart",
27
+ label: "\u67F1\u72B6\u56FE",
28
+ icon: "ChartColumn",
29
+ seriesType: "bar",
30
+ orientation: "vertical",
31
+ fields: [...DATA_FIELDS, ...STYLE_FIELDS, "stack", "label"],
32
+ requiredOptionKeys: BASE_REQUIRED,
33
+ defaultWidth: 100,
34
+ defaultHeight: 60,
35
+ notes: "\u67F1\u72B6\u56FE\uFF1A\u7C7B\u76EE + \u591A\u4E2A\u6570\u503C\u5B57\u6BB5\uFF0C\u6BCF\u5B57\u6BB5\u4E00\u4E2A series\uFF1Bseries[].data \u5199 $data \u5360\u4F4D\uFF1B\u56FA\u5B9A\u9AD8\uFF0C\u7981\u6B62 autoHeight"
36
+ },
37
+ {
38
+ type: "barHChart",
39
+ label: "\u6761\u5F62\u56FE",
40
+ icon: "ChartBar",
41
+ seriesType: "bar",
42
+ orientation: "horizontal",
43
+ fields: [...DATA_FIELDS, ...STYLE_FIELDS, "stack", "label"],
44
+ requiredOptionKeys: BASE_REQUIRED,
45
+ defaultWidth: 100,
46
+ defaultHeight: 60,
47
+ notes: "\u6A2A\u5411\u6761\u5F62\u56FE\uFF1AxAxis \u4E3A\u6570\u503C\u3001yAxis \u4E3A\u7C7B\u76EE\uFF1B\u7C7B\u76EE\u5199 yAxis.data \u7684 $data \u5360\u4F4D"
48
+ },
49
+ {
50
+ type: "lineChart",
51
+ label: "\u6298\u7EBF\u56FE",
52
+ icon: "ChartLine",
53
+ seriesType: "line",
54
+ fields: [...DATA_FIELDS, ...STYLE_FIELDS, "stack", "label"],
55
+ requiredOptionKeys: BASE_REQUIRED,
56
+ defaultWidth: 100,
57
+ defaultHeight: 60,
58
+ notes: "\u6298\u7EBF\u56FE\uFF1A\u7C7B\u76EE + \u591A\u4E2A\u6570\u503C\u5B57\u6BB5\uFF1B\u4E0D\u5199 areaStyle"
59
+ },
60
+ {
61
+ type: "areaChart",
62
+ label: "\u9762\u79EF\u56FE",
63
+ icon: "ChartArea",
64
+ seriesType: "line",
65
+ fields: [...DATA_FIELDS, ...STYLE_FIELDS, "stack", "label"],
66
+ requiredOptionKeys: BASE_REQUIRED,
67
+ defaultWidth: 100,
68
+ defaultHeight: 60,
69
+ notes: "\u9762\u79EF\u56FE\uFF1A\u6298\u7EBF + series[].areaStyle\uFF1B\u5176\u4F59\u540C\u6298\u7EBF\u56FE"
70
+ },
71
+ {
72
+ type: "pieChart",
73
+ label: "\u997C\u56FE",
74
+ icon: "ChartPie",
75
+ seriesType: "pie",
76
+ fields: ["dataSource", "categoryField", "valueFields", ...STYLE_FIELDS, "label"],
77
+ requiredOptionKeys: BASE_REQUIRED,
78
+ defaultWidth: 60,
79
+ defaultHeight: 60,
80
+ notes: "\u997C\u56FE\uFF1A\u7C7B\u76EE + \u9996\u4E2A\u6570\u503C\u5B57\u6BB5\u751F\u6210 { name, value }\uFF1B\u53EA\u9700\u4E00\u4E2A\u6570\u503C\u5B57\u6BB5"
81
+ },
82
+ {
83
+ type: "doughnutChart",
84
+ label: "\u73AF\u5F62\u56FE",
85
+ icon: "Donut",
86
+ seriesType: "pie",
87
+ fields: ["dataSource", "categoryField", "valueFields", ...STYLE_FIELDS, "innerRadius", "label"],
88
+ requiredOptionKeys: BASE_REQUIRED,
89
+ defaultWidth: 60,
90
+ defaultHeight: 60,
91
+ notes: "\u73AF\u5F62\u56FE\uFF1A\u997C\u56FE + radius:[\u5185\u5F84,\u5916\u5F84]\uFF1B\u5185\u5F84\u7531\u9762\u677F\u914D\u7F6E"
92
+ },
93
+ {
94
+ type: "scatterChart",
95
+ label: "\u6563\u70B9\u56FE",
96
+ icon: "ChartScatter",
97
+ seriesType: "scatter",
98
+ fields: ["dataSource", "categoryField", "valueFields", ...STYLE_FIELDS, "bubble", "label"],
99
+ requiredOptionKeys: BASE_REQUIRED,
100
+ defaultWidth: 80,
101
+ defaultHeight: 60,
102
+ notes: "\u6563\u70B9\u56FE\uFF1A\u7C7B\u76EE\u5B57\u6BB5\u4F5C x\u3001\u9996\u4E2A\u6570\u503C\u5B57\u6BB5\u4F5C y\uFF1BchartBubble \u5F00\u542F\u65F6\u7528\u7B2C\u4E8C\u4E2A\u6570\u503C\u5B57\u6BB5\u4F5C\u70B9\u5927\u5C0F"
103
+ },
104
+ {
105
+ type: "radarChart",
106
+ label: "\u96F7\u8FBE\u56FE",
107
+ icon: "Radar",
108
+ seriesType: "radar",
109
+ fields: ["dataSource", "categoryField", "valueFields", ...STYLE_FIELDS, "radius", "label"],
110
+ requiredOptionKeys: BASE_REQUIRED,
111
+ defaultWidth: 70,
112
+ defaultHeight: 60,
113
+ notes: "\u96F7\u8FBE\u56FE\uFF1A\u6BCF\u4E2A\u6570\u503C\u5B57\u6BB5\u662F\u4E00\u4E2A\u7EF4\u5EA6\uFF08radar.indicator\uFF09\uFF0C\u6BCF\u884C\u6570\u636E\u662F\u4E00\u4E2A\u7CFB\u5217\uFF08\u7C7B\u76EE\u5B57\u6BB5\u4F5C\u7CFB\u5217\u540D\uFF09\uFF1B\u534A\u5F84\u7531\u9762\u677F\u5199 radar.radius\uFF08%\uFF0C\u9ED8\u8BA4 75\uFF09"
114
+ },
115
+ {
116
+ type: "funnelChart",
117
+ label: "\u6F0F\u6597\u56FE",
118
+ icon: "Funnel",
119
+ seriesType: "funnel",
120
+ fields: ["dataSource", "categoryField", "valueFields", ...STYLE_FIELDS, "padding", "label"],
121
+ requiredOptionKeys: BASE_REQUIRED,
122
+ defaultWidth: 60,
123
+ defaultHeight: 60,
124
+ notes: "\u6F0F\u6597\u56FE\uFF1A\u7C7B\u76EE + \u9996\u4E2A\u6570\u503C\u5B57\u6BB5\uFF0C\u6309\u6570\u503C\u964D\u5E8F\uFF1B\u56DB\u8FB9\u5185\u8FB9\u8DDD\u7531\u9762\u677F\u5199 series.left/right/top/bottom\uFF08%\uFF0C\u53F3\u4FA7\u9700\u7559\u5916\u7F6E\u6807\u7B7E\u7A7A\u95F4\uFF09"
125
+ },
126
+ {
127
+ type: "gaugeChart",
128
+ label: "\u4EEA\u8868\u76D8",
129
+ icon: "Gauge",
130
+ seriesType: "gauge",
131
+ fields: ["dataSource", "valueFields", ...STYLE_FIELDS, "gaugeRange", "label"],
132
+ requiredOptionKeys: BASE_REQUIRED,
133
+ defaultWidth: 60,
134
+ defaultHeight: 60,
135
+ notes: "\u4EEA\u8868\u76D8\uFF1A\u53D6\u9996\u884C\u6570\u636E\u7684\u9996\u4E2A\u6570\u503C\u5B57\u6BB5\u4F5C\u6307\u9488\u503C\uFF1Bmin/max \u7531\u9762\u677F\u5199\u5165 series[0].min/max"
136
+ }
137
+ ];
138
+ var CHART_KINDS = CHART_KIND_DEFINITIONS.map((def) => def.type);
139
+ function getChartKindDefinition(type) {
140
+ return CHART_KIND_DEFINITIONS.find((def) => def.type === type);
141
+ }
142
+ function resolveChartPanelFields(type) {
143
+ return getChartKindDefinition(type)?.fields ?? [];
144
+ }
145
+
146
+ // src/bind.ts
147
+ import { evaluateTemplate } from "@worm-print-platform/core";
148
+ function chartNumber(value) {
149
+ const n = typeof value === "number" ? value : Number(value);
150
+ return Number.isFinite(n) ? n : 0;
151
+ }
152
+ function evaluateChartOption(node, data, keepStrings = false) {
153
+ if (typeof node === "string") {
154
+ if (node.startsWith("$data")) return node;
155
+ if (keepStrings) return node;
156
+ return node.includes("{") ? evaluateTemplate(node, data) : node;
157
+ }
158
+ if (Array.isArray(node)) return node.map((item) => evaluateChartOption(item, data, keepStrings));
159
+ if (node && typeof node === "object") {
160
+ const out = {};
161
+ for (const [key, value] of Object.entries(node)) {
162
+ const childKeep = keepStrings || key === "label" || key === "detail";
163
+ out[key] = evaluateChartOption(value, data, childKeep);
164
+ }
165
+ return out;
166
+ }
167
+ return node;
168
+ }
169
+ function hasDataPlaceholder(series) {
170
+ return Array.isArray(series.data) && series.data.includes("$data");
171
+ }
172
+ function resolveListSource(options, data) {
173
+ const explicit = options.dataSource;
174
+ if (typeof explicit === "string" && Array.isArray(data[explicit])) return data[explicit];
175
+ for (const value of Object.values(data)) {
176
+ if (Array.isArray(value)) return value;
177
+ }
178
+ return [];
179
+ }
180
+ function asString(value) {
181
+ return typeof value === "string" && value.length > 0 ? value : void 0;
182
+ }
183
+ function asFieldList(value) {
184
+ return Array.isArray(value) ? value.filter((item) => typeof item === "string" && item.length > 0) : [];
185
+ }
186
+ function seriesOf(option) {
187
+ return Array.isArray(option.series) ? option.series : [];
188
+ }
189
+ function rowValue(row, field2) {
190
+ return field2 ? chartNumber(row[field2]) : 0;
191
+ }
192
+ function writeCategories(option, categories) {
193
+ for (const key of ["xAxis", "yAxis"]) {
194
+ const raw = option[key];
195
+ const axes = Array.isArray(raw) ? raw : raw ? [raw] : [];
196
+ for (const axis of axes) {
197
+ if (axis && typeof axis === "object" && Array.isArray(axis.data) && axis.data.includes("$data")) {
198
+ axis.data = [...categories];
199
+ }
200
+ }
201
+ }
202
+ }
203
+ function applyCartesian(option, rows, categoryField, valueFields, seriesField) {
204
+ const rawSeries = seriesOf(option);
205
+ if (!rawSeries.some(hasDataPlaceholder)) return;
206
+ const categories = rows.map((row, index) => categoryField ? row[categoryField] : index + 1);
207
+ const fieldAt = (index) => valueFields[Math.min(index, valueFields.length - 1)];
208
+ if (seriesField) {
209
+ const template2 = rawSeries[0];
210
+ const groups = /* @__PURE__ */ new Map();
211
+ for (const row of rows) {
212
+ const name = String(row[seriesField] ?? "");
213
+ const bucket = groups.get(name) ?? /* @__PURE__ */ new Map();
214
+ const category = String(row[categoryField ?? ""]);
215
+ bucket.set(category, (bucket.get(category) ?? 0) + rowValue(row, fieldAt(0)));
216
+ groups.set(name, bucket);
217
+ }
218
+ const distinctCategories = [...new Set(categories)];
219
+ option.series = [...groups.entries()].map(([name, bucket]) => ({
220
+ ...template2,
221
+ name,
222
+ data: distinctCategories.map((category) => bucket.get(String(category)) ?? null)
223
+ }));
224
+ writeCategories(option, distinctCategories);
225
+ return;
226
+ }
227
+ const template = rawSeries[rawSeries.length - 1];
228
+ while (rawSeries.length < valueFields.length) rawSeries.push({ ...template, data: ["$data"] });
229
+ option.series = rawSeries.map((series, index) => {
230
+ if (!hasDataPlaceholder(series)) return series;
231
+ return { ...series, data: rows.map((row) => rowValue(row, fieldAt(index))) };
232
+ });
233
+ writeCategories(option, categories);
234
+ }
235
+ function applyPieLike(option, rows, categoryField, valueField, sortDescending) {
236
+ const series = seriesOf(option);
237
+ if (!series.some(hasDataPlaceholder)) return;
238
+ const data = rows.map((row) => ({
239
+ name: categoryField ? String(row[categoryField] ?? "") : "",
240
+ value: rowValue(row, valueField)
241
+ }));
242
+ if (sortDescending) data.sort((a, b) => b.value - a.value);
243
+ option.series = series.map((item) => ({ ...item, data }));
244
+ }
245
+ function applyScatter(option, rows, xField, valueFields, bubble) {
246
+ const series = seriesOf(option);
247
+ if (!series.some(hasDataPlaceholder)) return;
248
+ const yField = valueFields[0];
249
+ const sizeField = bubble ? valueFields[1] : void 0;
250
+ const sizes = sizeField ? rows.map((row) => rowValue(row, sizeField)) : [];
251
+ const min = sizes.length > 0 ? Math.min(...sizes) : 0;
252
+ const max = sizes.length > 0 ? Math.max(...sizes) : 0;
253
+ const sizeOf = (value) => max === min ? 12 : Math.round(6 + (value - min) / (max - min) * 18);
254
+ option.series = series.map((item) => ({
255
+ ...item,
256
+ data: rows.map((row) => {
257
+ const value = [rowValue(row, xField), rowValue(row, yField)];
258
+ if (!sizeField) return value;
259
+ return { value, symbolSize: sizeOf(rowValue(row, sizeField)) };
260
+ })
261
+ }));
262
+ }
263
+ function niceMax(value) {
264
+ if (value <= 0) return 10;
265
+ const magnitude = 10 ** Math.floor(Math.log10(value));
266
+ const step = magnitude >= 10 ? magnitude : 10;
267
+ return Math.ceil(value / step) * step;
268
+ }
269
+ function applyRadar(option, rows, categoryField, valueFields) {
270
+ const series = seriesOf(option);
271
+ if (!series.some(hasDataPlaceholder)) return;
272
+ const columnMax = valueFields.map((field2) => Math.max(0, ...rows.map((row) => rowValue(row, field2))));
273
+ option.radar = {
274
+ ...option.radar ?? {},
275
+ // 维度 = 数值字段;max 取该列最大值上浮取整
276
+ indicator: valueFields.map((field2, index) => ({ name: field2, max: niceMax(columnMax[index]) }))
277
+ };
278
+ option.series = series.map((item) => ({
279
+ ...item,
280
+ data: rows.map((row) => ({
281
+ name: categoryField ? String(row[categoryField] ?? "") : "",
282
+ value: valueFields.map((field2) => rowValue(row, field2))
283
+ }))
284
+ }));
285
+ }
286
+ function applyGauge(option, rows, valueField) {
287
+ const series = seriesOf(option);
288
+ if (!series.some(hasDataPlaceholder)) return;
289
+ const first = rows[0] ?? {};
290
+ option.series = series.map((item) => ({ ...item, data: [{ value: rowValue(first, valueField), name: valueField }] }));
291
+ }
292
+ function bindChartData(type, options, data) {
293
+ const raw = options.chartOption;
294
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
295
+ const option = evaluateChartOption(raw, data);
296
+ const valueFields = asFieldList(options.chartValueFields);
297
+ if (valueFields.length === 0) return { _chartOption: option };
298
+ const list = resolveListSource({ ...options, dataSource: options.chartDataSource ?? options.dataSource }, data);
299
+ if (list.length === 0) return { _chartOption: option };
300
+ const categoryField = asString(options.chartCategoryField);
301
+ const def = getChartKindDefinition(type);
302
+ switch (def?.seriesType) {
303
+ case "radar":
304
+ applyRadar(option, list, categoryField, valueFields);
305
+ break;
306
+ case "gauge":
307
+ applyGauge(option, list, valueFields[0]);
308
+ break;
309
+ case "funnel":
310
+ applyPieLike(option, list, categoryField, valueFields[0], true);
311
+ break;
312
+ case "pie":
313
+ applyPieLike(option, list, categoryField, valueFields[0], false);
314
+ break;
315
+ case "scatter":
316
+ applyScatter(option, list, categoryField, valueFields, options.chartBubble === true);
317
+ break;
318
+ default:
319
+ applyCartesian(option, list, categoryField, valueFields, asString(options.chartSeriesField));
320
+ break;
321
+ }
322
+ return { _chartOption: option };
323
+ }
324
+
325
+ // src/config.ts
326
+ import { configurePlugin, getPluginConfig } from "@worm-print-platform/core/designer";
327
+
328
+ // src/constants.ts
329
+ var CHART_PLUGIN_ID = "@worm-print-platform/echarts";
330
+ var CHART_PALETTES = [
331
+ { key: "default", label: "\u9ED8\u8BA4\u84DD", colors: ["#5470c6", "#91cc75", "#fac858", "#ee6666", "#73c0de"] },
332
+ { key: "fresh", label: "\u6E05\u65B0\u7EFF", colors: ["#2f9e6e", "#5cc9a7", "#9ad6c1", "#f2c94c", "#4a90e2"] },
333
+ { key: "warm", label: "\u6696\u6A59\u7EA2", colors: ["#f2704e", "#f7a35c", "#f7d56d", "#c54e3f", "#8f5a4a"] },
334
+ { key: "purple", label: "\u7D2B\u7070", colors: ["#7b61ff", "#9b8cff", "#c3baff", "#596275", "#8d99ae"] }
335
+ ];
336
+ var FALLBACK_SAMPLE_CATEGORIES = ["\u793A\u4F8B\u4E00", "\u793A\u4F8B\u4E8C", "\u793A\u4F8B\u4E09"];
337
+ var FUNNEL_PADDING_DEFAULTS = { top: 6, right: 25, bottom: 6, left: 5 };
338
+ var RADAR_RADIUS_DEFAULT = 75;
339
+ var ECHARTS_RADAR_RADIUS_DEFAULT = 50;
340
+ var ECHARTS_FUNNEL_PADDING_PX = { top: 60, right: 80, bottom: 65, left: 80 };
341
+
342
+ // src/defaults.ts
343
+ var GRID = { left: "8%", right: "8%", bottom: "12%", top: "18%", containLabel: true };
344
+ function percentInsets(padding) {
345
+ return {
346
+ top: `${padding.top}%`,
347
+ right: `${padding.right}%`,
348
+ bottom: `${padding.bottom}%`,
349
+ left: `${padding.left}%`
350
+ };
351
+ }
352
+ function createDefaultChartOption(type) {
353
+ const def = getChartKindDefinition(type);
354
+ const title = { text: "" };
355
+ switch (def?.seriesType) {
356
+ case "pie":
357
+ return {
358
+ title,
359
+ tooltip: { trigger: "item" },
360
+ series: [{
361
+ type: "pie",
362
+ name: "\u6570\u91CF",
363
+ data: ["$data"],
364
+ radius: type === "doughnutChart" ? ["40%", "70%"] : "62%"
365
+ }]
366
+ };
367
+ case "scatter":
368
+ return {
369
+ title,
370
+ grid: GRID,
371
+ tooltip: { trigger: "axis" },
372
+ xAxis: { type: "value" },
373
+ yAxis: { type: "value" },
374
+ series: [{ type: "scatter", name: "\u6570\u91CF", data: ["$data"], symbolSize: 8 }]
375
+ };
376
+ case "radar":
377
+ return {
378
+ title,
379
+ tooltip: { trigger: "item" },
380
+ // indicator 由绑定阶段按 chartValueFields 生成;设计态预览见 previewChartOption
381
+ radar: { indicator: [], radius: `${RADAR_RADIUS_DEFAULT}%` },
382
+ series: [{ type: "radar", name: "\u6570\u91CF", data: ["$data"] }]
383
+ };
384
+ case "funnel":
385
+ return {
386
+ title,
387
+ tooltip: { trigger: "item" },
388
+ legend: { show: false },
389
+ // 不写内边距会吃 ECharts 的 px 默认(左右 80/上下 60~65),小框里图形只占一半不到
390
+ series: [{ type: "funnel", name: "\u6570\u91CF", data: ["$data"], sort: "descending", ...percentInsets(FUNNEL_PADDING_DEFAULTS) }]
391
+ };
392
+ case "gauge":
393
+ return {
394
+ title,
395
+ tooltip: { trigger: "item" },
396
+ series: [{ type: "gauge", name: "\u6570\u91CF", min: 0, max: 100, data: [{ value: 0, name: "\u6570\u91CF" }] }]
397
+ };
398
+ default: {
399
+ const horizontal = def?.orientation === "horizontal";
400
+ const isArea = def?.seriesType === "line" && type === "areaChart";
401
+ const seriesType = def?.seriesType === "line" ? "line" : "bar";
402
+ return {
403
+ title,
404
+ grid: GRID,
405
+ tooltip: { trigger: "axis" },
406
+ xAxis: horizontal ? { type: "value" } : { type: "category", data: ["$data"] },
407
+ yAxis: horizontal ? { type: "category", data: ["$data"] } : { type: "value" },
408
+ series: [{ type: seriesType, name: "\u6570\u91CF", data: ["$data"], ...isArea ? { areaStyle: {} } : {} }]
409
+ };
410
+ }
411
+ }
412
+ }
413
+
414
+ // src/config.ts
415
+ function getChartPluginConfig() {
416
+ return getPluginConfig(CHART_PLUGIN_ID);
417
+ }
418
+ function getChartPalettes() {
419
+ const overrides = getChartPluginConfig().palettes ?? {};
420
+ const builtin = CHART_PALETTES.map((palette) => {
421
+ const custom = overrides[palette.key];
422
+ return custom ? { key: palette.key, label: custom.label ?? palette.label, colors: custom.colors } : { key: palette.key, label: palette.label, colors: palette.colors };
423
+ });
424
+ const extra = Object.entries(overrides).filter(([key]) => !CHART_PALETTES.some((palette) => palette.key === key)).map(([key, value]) => ({ key, label: value.label ?? key, colors: value.colors }));
425
+ return [...builtin, ...extra];
426
+ }
427
+ function getSampleCategories() {
428
+ const custom = getChartPluginConfig().sampleCategories;
429
+ return Array.isArray(custom) && custom.length > 0 ? custom : FALLBACK_SAMPLE_CATEGORIES;
430
+ }
431
+ function chartFactoryDefaults(type, partial) {
432
+ const config = getChartPluginConfig();
433
+ const def = getChartKindDefinition(type);
434
+ return {
435
+ width: typeof config.defaultWidth === "number" ? config.defaultWidth : def?.defaultWidth ?? 100,
436
+ height: typeof config.defaultHeight === "number" ? config.defaultHeight : def?.defaultHeight ?? 60,
437
+ title: def?.label ?? "\u56FE\u8868",
438
+ chartOption: createDefaultChartOption(type),
439
+ chartDataSource: "",
440
+ chartCategoryField: "name",
441
+ chartValueFields: ["value"],
442
+ chartSeriesField: "",
443
+ ...partial
444
+ };
445
+ }
446
+
447
+ // src/echarts.ts
448
+ import { BarChart, LineChart, PieChart, ScatterChart, RadarChart, FunnelChart, GaugeChart } from "echarts/charts";
449
+ import {
450
+ DatasetComponent,
451
+ GridComponent,
452
+ LegendComponent,
453
+ TitleComponent,
454
+ TooltipComponent
455
+ } from "echarts/components";
456
+ import * as echarts from "echarts/core";
457
+ import { SVGRenderer } from "echarts/renderers";
458
+ echarts.use([
459
+ BarChart,
460
+ LineChart,
461
+ PieChart,
462
+ ScatterChart,
463
+ RadarChart,
464
+ FunnelChart,
465
+ GaugeChart,
466
+ GridComponent,
467
+ TooltipComponent,
468
+ LegendComponent,
469
+ TitleComponent,
470
+ DatasetComponent,
471
+ SVGRenderer
472
+ ]);
473
+ var appliedComponents = /* @__PURE__ */ new Set();
474
+ function applyExtraComponents() {
475
+ const extra = getChartPluginConfig().components ?? [];
476
+ const fresh = extra.filter((item) => item != null && !appliedComponents.has(item));
477
+ if (fresh.length === 0) return;
478
+ echarts.use(fresh);
479
+ for (const item of fresh) appliedComponents.add(item);
480
+ }
481
+
482
+ // src/units.ts
483
+ var PX_PER_MM = 96 / 25.4;
484
+ function mmToChartPx(mm) {
485
+ const value = Number.isFinite(mm) ? mm : 0;
486
+ return Math.max(1, Math.round(value * PX_PER_MM));
487
+ }
488
+
489
+ // src/option-utils.ts
490
+ var SAMPLE_VALUES = [12, 20, 15];
491
+ function cloneChartOption(value) {
492
+ try {
493
+ return JSON.parse(JSON.stringify(value));
494
+ } catch {
495
+ return value;
496
+ }
497
+ }
498
+ function previewChartOption(type, option) {
499
+ if (!option || typeof option !== "object" || Array.isArray(option)) return {};
500
+ const next = cloneChartOption(option);
501
+ const def = getChartKindDefinition(type);
502
+ const categories = [...getSampleCategories()];
503
+ const values = [...SAMPLE_VALUES];
504
+ const series = Array.isArray(next.series) ? next.series : [];
505
+ const replaceSeriesData = (mapper) => {
506
+ for (const item of series) {
507
+ if (Array.isArray(item.data) && item.data.includes("$data")) item.data = mapper(item);
508
+ }
509
+ };
510
+ const replaceAxisData = () => {
511
+ for (const key of ["xAxis", "yAxis"]) {
512
+ const axes = Array.isArray(next[key]) ? next[key] : next[key] ? [next[key]] : [];
513
+ for (const axis of axes) {
514
+ if (axis && Array.isArray(axis.data) && axis.data.includes("$data")) axis.data = [...categories];
515
+ }
516
+ }
517
+ };
518
+ switch (def?.seriesType) {
519
+ case "pie":
520
+ replaceSeriesData(() => categories.map((name, index) => ({ name, value: values[index] ?? 10 })));
521
+ break;
522
+ case "funnel":
523
+ replaceSeriesData(() => categories.map((name, index) => ({ name, value: values[index] ?? 10 })));
524
+ break;
525
+ case "scatter":
526
+ replaceSeriesData(() => values.map((value) => [value, value + 6]));
527
+ break;
528
+ case "radar":
529
+ next.radar = {
530
+ ...next.radar ?? {},
531
+ indicator: categories.map((name) => ({ name, max: 30 }))
532
+ };
533
+ replaceSeriesData(() => [{ name: "\u793A\u4F8B", value: values }]);
534
+ break;
535
+ case "gauge":
536
+ replaceSeriesData(() => [{ value: values[0] ?? 40, name: "\u6570\u91CF" }]);
537
+ break;
538
+ default:
539
+ replaceSeriesData(() => [...values]);
540
+ replaceAxisData();
541
+ break;
542
+ }
543
+ return next;
544
+ }
545
+ function readPaletteKey(option, palettes) {
546
+ const color = Array.isArray(option?.color) ? (option?.color).map(String) : [];
547
+ const hit = palettes.find((palette) => palette.colors.every((c, i) => c === color[i]) && color.length === palette.colors.length);
548
+ return hit?.key ?? "default";
549
+ }
550
+ function asObject(node) {
551
+ if (Array.isArray(node)) return node[0] && typeof node[0] === "object" ? { ...node[0] } : {};
552
+ return node && typeof node === "object" ? { ...node } : {};
553
+ }
554
+ function syncSeriesCount(option, count, type) {
555
+ const next = cloneChartOption(option);
556
+ const rawSeries = Array.isArray(next.series) ? next.series : [];
557
+ const def = getChartKindDefinition(type);
558
+ const template = rawSeries[0] ?? { type: def?.seriesType === "line" ? "line" : "bar", data: ["$data"] };
559
+ next.series = Array.from({ length: Math.max(count, 1) }, (_, index) => ({
560
+ ...template,
561
+ ...rawSeries[index] ?? {},
562
+ data: ["$data"]
563
+ }));
564
+ return next;
565
+ }
566
+ var round1 = (value) => Math.round(value * 10) / 10;
567
+ function pxToPercent(px, totalPx) {
568
+ return totalPx > 0 ? round1(px / totalPx * 100) : 0;
569
+ }
570
+ function readInsetPercent(value, totalPx, echartsPx) {
571
+ if (typeof value === "string" && value.trim().endsWith("%")) {
572
+ const parsed = Number.parseFloat(value);
573
+ if (Number.isFinite(parsed)) return round1(parsed);
574
+ }
575
+ if (typeof value === "number" && Number.isFinite(value)) return pxToPercent(value, totalPx);
576
+ return pxToPercent(echartsPx, totalPx);
577
+ }
578
+ function clamp(value, min, max) {
579
+ return Math.min(max, Math.max(min, value));
580
+ }
581
+ function percentString(value) {
582
+ return `${clamp(round1(value), 0, 100)}%`;
583
+ }
584
+ function firstSeries(option) {
585
+ const series = Array.isArray(option.series) ? option.series : [];
586
+ const first = series[0];
587
+ return first && typeof first === "object" ? first : {};
588
+ }
589
+ function readFunnelPadding(option, widthMm, heightMm) {
590
+ const source = option && typeof option === "object" ? option : {};
591
+ const series = firstSeries(source);
592
+ const widthPx = mmToChartPx(widthMm);
593
+ const heightPx = mmToChartPx(heightMm);
594
+ return {
595
+ top: readInsetPercent(series.top, heightPx, ECHARTS_FUNNEL_PADDING_PX.top),
596
+ right: readInsetPercent(series.right, widthPx, ECHARTS_FUNNEL_PADDING_PX.right),
597
+ bottom: readInsetPercent(series.bottom, heightPx, ECHARTS_FUNNEL_PADDING_PX.bottom),
598
+ left: readInsetPercent(series.left, widthPx, ECHARTS_FUNNEL_PADDING_PX.left)
599
+ };
600
+ }
601
+ function writeFunnelPadding(option, padding) {
602
+ const next = cloneChartOption(option);
603
+ const series = Array.isArray(next.series) ? next.series : [];
604
+ if (series.length === 0) series.push({ type: "funnel", data: ["$data"] });
605
+ const first = series[0];
606
+ first.top = percentString(padding.top);
607
+ first.right = percentString(padding.right);
608
+ first.bottom = percentString(padding.bottom);
609
+ first.left = percentString(padding.left);
610
+ next.series = series;
611
+ return next;
612
+ }
613
+ function readRadarRadius(option, widthMm, heightMm) {
614
+ const source = option && typeof option === "object" ? option : {};
615
+ const raw = asObject(source.radar).radius;
616
+ const value = Array.isArray(raw) ? raw[raw.length - 1] : raw;
617
+ const widthPx = mmToChartPx(widthMm);
618
+ const heightPx = mmToChartPx(heightMm);
619
+ const viewSize = Math.min(widthPx, heightPx) / 2;
620
+ if (typeof value === "string" && value.trim().endsWith("%")) {
621
+ const parsed = Number.parseFloat(value);
622
+ if (Number.isFinite(parsed)) return round1(parsed);
623
+ }
624
+ if (typeof value === "number" && Number.isFinite(value)) return pxToPercent(value, viewSize);
625
+ return ECHARTS_RADAR_RADIUS_DEFAULT;
626
+ }
627
+ function writeRadarRadius(option, percent) {
628
+ const next = cloneChartOption(option);
629
+ next.radar = { ...asObject(next.radar), radius: percentString(clamp(percent, 20, 100)) };
630
+ return next;
631
+ }
632
+
633
+ // src/label.ts
634
+ var LABEL_PRESETS = [
635
+ { key: "value", label: "\u6570\u503C", formatter: "{c}" },
636
+ { key: "name-value", label: "\u540D\u79F0: \u6570\u503C", formatter: "{b}: {c}" },
637
+ { key: "name", label: "\u540D\u79F0", formatter: "{b}" },
638
+ { key: "percent", label: "\u767E\u5206\u6BD4", formatter: "{d}%" }
639
+ ];
640
+ var LABEL_POSITIONS = {
641
+ bar: [
642
+ { value: "top", label: "\u9876\u90E8" },
643
+ { value: "inside", label: "\u5185\u90E8" },
644
+ { value: "insideTop", label: "\u5185\u90E8\u9876\u7AEF" },
645
+ { value: "bottom", label: "\u5E95\u90E8" },
646
+ { value: "insideBottom", label: "\u5185\u90E8\u5E95\u7AEF" },
647
+ { value: "right", label: "\u53F3\u4FA7" },
648
+ { value: "left", label: "\u5DE6\u4FA7" },
649
+ { value: "middle", label: "\u5C45\u4E2D" }
650
+ ],
651
+ line: [
652
+ { value: "top", label: "\u9876\u90E8" },
653
+ { value: "bottom", label: "\u5E95\u90E8" },
654
+ { value: "inside", label: "\u5185\u90E8" },
655
+ { value: "left", label: "\u5DE6\u4FA7" },
656
+ { value: "right", label: "\u53F3\u4FA7" }
657
+ ],
658
+ pie: [
659
+ { value: "outside", label: "\u5916\u4FA7" },
660
+ { value: "inside", label: "\u5185\u90E8" },
661
+ { value: "center", label: "\u4E2D\u5FC3" }
662
+ ],
663
+ scatter: [
664
+ { value: "top", label: "\u9876\u90E8" },
665
+ { value: "bottom", label: "\u5E95\u90E8" },
666
+ { value: "left", label: "\u5DE6\u4FA7" },
667
+ { value: "right", label: "\u53F3\u4FA7" },
668
+ { value: "inside", label: "\u5185\u90E8" }
669
+ ],
670
+ radar: [
671
+ { value: "top", label: "\u9876\u90E8" },
672
+ { value: "bottom", label: "\u5E95\u90E8" },
673
+ { value: "left", label: "\u5DE6\u4FA7" },
674
+ { value: "right", label: "\u53F3\u4FA7" },
675
+ { value: "inside", label: "\u5185\u90E8" }
676
+ ],
677
+ funnel: [
678
+ { value: "outer", label: "\u5916\u4FA7" },
679
+ { value: "inner", label: "\u5185\u90E8" },
680
+ { value: "left", label: "\u5DE6\u4FA7" },
681
+ { value: "right", label: "\u53F3\u4FA7" },
682
+ { value: "top", label: "\u9876\u90E8" },
683
+ { value: "bottom", label: "\u5E95\u90E8" }
684
+ ],
685
+ gauge: []
686
+ };
687
+ var NATIVE_SHOW = {
688
+ bar: false,
689
+ line: false,
690
+ pie: true,
691
+ scatter: false,
692
+ radar: false,
693
+ funnel: true,
694
+ gauge: true
695
+ };
696
+ var ENABLE_DEFAULTS = {
697
+ bar: { position: "top", fontSize: 12 },
698
+ line: { position: "top", fontSize: 12 },
699
+ pie: { position: "outside", overflow: "none", fontSize: 11 },
700
+ scatter: { position: "top", fontSize: 11 },
701
+ radar: { position: "top", fontSize: 10 },
702
+ funnel: { position: "outer", fontSize: 11 },
703
+ gauge: { fontSize: 14 }
704
+ };
705
+ var TYPE_DEFAULTS = {
706
+ barHChart: { position: "right", fontSize: 12 }
707
+ };
708
+ var FIELDS_BY_SERIES = {
709
+ bar: [
710
+ "formatter",
711
+ "overflow",
712
+ "position",
713
+ "rotate",
714
+ "offset",
715
+ "fontSize",
716
+ "fontWeight",
717
+ "color",
718
+ "backgroundColor",
719
+ "borderColor",
720
+ "borderWidth",
721
+ "borderRadius",
722
+ "padding"
723
+ ],
724
+ line: [
725
+ "formatter",
726
+ "overflow",
727
+ "position",
728
+ "rotate",
729
+ "offset",
730
+ "fontSize",
731
+ "fontWeight",
732
+ "color",
733
+ "backgroundColor",
734
+ "borderColor",
735
+ "borderWidth",
736
+ "borderRadius",
737
+ "padding"
738
+ ],
739
+ pie: [
740
+ "formatter",
741
+ "overflow",
742
+ "position",
743
+ "distance",
744
+ "offset",
745
+ "fontSize",
746
+ "fontWeight",
747
+ "color",
748
+ "backgroundColor",
749
+ "borderColor",
750
+ "borderWidth",
751
+ "borderRadius",
752
+ "padding",
753
+ "labelLine.show",
754
+ "labelLine.length",
755
+ "labelLine.length2",
756
+ "labelLine.smooth"
757
+ ],
758
+ scatter: [
759
+ "formatter",
760
+ "overflow",
761
+ "position",
762
+ "distance",
763
+ "rotate",
764
+ "offset",
765
+ "fontSize",
766
+ "fontWeight",
767
+ "color",
768
+ "backgroundColor",
769
+ "borderColor",
770
+ "borderWidth",
771
+ "borderRadius",
772
+ "padding"
773
+ ],
774
+ radar: ["formatter", "fontSize", "fontWeight", "color"],
775
+ funnel: [
776
+ "formatter",
777
+ "overflow",
778
+ "position",
779
+ "distance",
780
+ "fontSize",
781
+ "fontWeight",
782
+ "color",
783
+ "labelLine.show",
784
+ "labelLine.length",
785
+ "labelLine.smooth"
786
+ ],
787
+ gauge: ["formatter", "fontSize", "fontWeight", "color", "offset"]
788
+ };
789
+ var VALUE_KEYS = [
790
+ "formatter",
791
+ "overflow",
792
+ "position",
793
+ "distance",
794
+ "rotate",
795
+ "offset",
796
+ "fontSize",
797
+ "fontWeight",
798
+ "color",
799
+ "backgroundColor",
800
+ "borderColor",
801
+ "borderWidth",
802
+ "borderRadius",
803
+ "padding"
804
+ ];
805
+ function seriesOf2(option) {
806
+ const series = option?.series;
807
+ return Array.isArray(series) ? series : [];
808
+ }
809
+ function asRecord(node) {
810
+ return node && typeof node === "object" && !Array.isArray(node) ? { ...node } : {};
811
+ }
812
+ function normalizeLabelOffsetInPlace(target) {
813
+ if (typeof target.offsetX !== "number" && typeof target.offsetY !== "number") return;
814
+ if (!Array.isArray(target.offset)) {
815
+ target.offset = [
816
+ typeof target.offsetX === "number" ? target.offsetX : 0,
817
+ typeof target.offsetY === "number" ? target.offsetY : 0
818
+ ];
819
+ }
820
+ delete target.offsetX;
821
+ delete target.offsetY;
822
+ }
823
+ function labelTargetOf(type) {
824
+ return getChartKindDefinition(type)?.seriesType === "gauge" ? "detail" : "label";
825
+ }
826
+ function labelFieldsOf(type) {
827
+ const def = getChartKindDefinition(type);
828
+ return def ? FIELDS_BY_SERIES[def.seriesType] : [];
829
+ }
830
+ function readChartLabel(option, type) {
831
+ const def = getChartKindDefinition(type);
832
+ const series = seriesOf2(option);
833
+ const target = asRecord(series[0]?.[labelTargetOf(type)]);
834
+ normalizeLabelOffsetInPlace(target);
835
+ const state = {
836
+ show: typeof target.show === "boolean" ? target.show : def ? NATIVE_SHOW[def.seriesType] : false,
837
+ // labelLine 在 ECharts 里是 series 顶层键(与 label 平级),不是 label 的子键
838
+ labelLine: asRecord(series[0]?.labelLine)
839
+ };
840
+ for (const key of VALUE_KEYS) {
841
+ const value = target[key];
842
+ if (key === "offset") continue;
843
+ if (typeof value === "string" || typeof value === "number") state[key] = value;
844
+ }
845
+ const offset = target.offset;
846
+ if (Array.isArray(offset) && typeof offset[0] === "number" && typeof offset[1] === "number") {
847
+ state.offset = [offset[0], offset[1]];
848
+ }
849
+ return state;
850
+ }
851
+ function defaultSetOf(type) {
852
+ const def = getChartKindDefinition(type);
853
+ if (!def) return {};
854
+ return { ...ENABLE_DEFAULTS[def.seriesType], ...TYPE_DEFAULTS[type] };
855
+ }
856
+ function isEmpty(value) {
857
+ return value === null || value === void 0 || value === "";
858
+ }
859
+ function updateChartLabel(option, type, patch) {
860
+ const next = cloneChartOption(option ?? {});
861
+ const series = Array.isArray(next.series) ? next.series : [];
862
+ const def = getChartKindDefinition(type);
863
+ if (!def || series.length === 0) return next;
864
+ const targetKey = labelTargetOf(type);
865
+ const { enabled, labelLine, ...values } = patch;
866
+ for (const item of series) {
867
+ if (!item || typeof item !== "object") continue;
868
+ const current = asRecord(item[targetKey]);
869
+ normalizeLabelOffsetInPlace(current);
870
+ if (enabled === true) {
871
+ Object.assign(current, { ...defaultSetOf(type), ...current, show: true });
872
+ } else if (enabled === false) {
873
+ current.show = false;
874
+ }
875
+ for (const [key, value] of Object.entries(values)) {
876
+ if (isEmpty(value)) delete current[key];
877
+ else current[key] = value;
878
+ }
879
+ if (labelLine) {
880
+ const line = asRecord(item.labelLine);
881
+ for (const [key, value] of Object.entries(labelLine)) {
882
+ if (isEmpty(value)) delete line[key];
883
+ else line[key] = value;
884
+ }
885
+ item.labelLine = line;
886
+ }
887
+ item[targetKey] = current;
888
+ }
889
+ return next;
890
+ }
891
+
892
+ // src/normalize.ts
893
+ function asArray(value) {
894
+ if (Array.isArray(value)) return value.map((item) => ({ ...item }));
895
+ return [];
896
+ }
897
+ function normalizeCategoryAxis(axis, horizontal) {
898
+ const next = { ...axis, type: horizontal ? "value" : "category" };
899
+ if (horizontal) delete next.data;
900
+ else if (!Array.isArray(next.data)) next.data = ["$data"];
901
+ return next;
902
+ }
903
+ function normalizeValueAxis(axis, horizontal) {
904
+ const next = { ...axis, type: horizontal ? "category" : "value" };
905
+ if (horizontal && !Array.isArray(next.data)) next.data = ["$data"];
906
+ if (!horizontal) delete next.data;
907
+ return next;
908
+ }
909
+ function mapAxes(value, fn) {
910
+ if (Array.isArray(value)) return value.map((item) => fn({ ...item }));
911
+ if (value && typeof value === "object") return fn({ ...value });
912
+ return fn({});
913
+ }
914
+ function normalizeChartOption(type, option) {
915
+ const def = getChartKindDefinition(type);
916
+ if (!def) return option;
917
+ const next = structuredClone(option);
918
+ const series = asArray(next.series);
919
+ if (series.length === 0) return next;
920
+ const labelKey = labelTargetOf(type);
921
+ for (const item of series) {
922
+ const label = item[labelKey];
923
+ if (label && typeof label === "object" && !Array.isArray(label)) {
924
+ const nextLabel = { ...label };
925
+ normalizeLabelOffsetInPlace(nextLabel);
926
+ item[labelKey] = nextLabel;
927
+ }
928
+ }
929
+ if (def.seriesType === "pie") {
930
+ next.series = series.map((item) => ({
931
+ ...item,
932
+ type: "pie",
933
+ ...type === "doughnutChart" ? { radius: item.radius ?? ["40%", "70%"] } : {}
934
+ }));
935
+ delete next.xAxis;
936
+ delete next.yAxis;
937
+ return next;
938
+ }
939
+ if (def.seriesType === "scatter") {
940
+ next.series = series.map((item) => ({ ...item, type: "scatter" }));
941
+ next.xAxis = mapAxes(next.xAxis, (axis) => ({ ...axis, type: "value", data: void 0 }));
942
+ next.yAxis = mapAxes(next.yAxis, (axis) => ({ ...axis, type: "value", data: void 0 }));
943
+ return next;
944
+ }
945
+ if (def.seriesType === "radar") {
946
+ next.series = series.map((item) => ({ ...item, type: "radar" }));
947
+ return next;
948
+ }
949
+ if (def.seriesType === "funnel") {
950
+ next.series = series.map((item) => ({ ...item, type: "funnel", sort: "descending" }));
951
+ return next;
952
+ }
953
+ if (def.seriesType === "gauge") {
954
+ next.series = series.map((item) => ({ ...item, type: "gauge" }));
955
+ return next;
956
+ }
957
+ const horizontal = def.orientation === "horizontal";
958
+ const seriesType = def.seriesType === "line" ? "line" : "bar";
959
+ next.xAxis = mapAxes(next.xAxis, (axis) => normalizeCategoryAxis(axis, horizontal));
960
+ next.yAxis = mapAxes(next.yAxis, (axis) => normalizeValueAxis(axis, horizontal));
961
+ next.series = series.map((item) => {
962
+ const shape = { ...item, type: seriesType };
963
+ if (type === "areaChart") shape.areaStyle = item.areaStyle ?? {};
964
+ else delete shape.areaStyle;
965
+ return shape;
966
+ });
967
+ return next;
968
+ }
969
+
970
+ // src/renderer.ts
971
+ function fitSvgRoot(svg, widthPx, heightPx) {
972
+ const match = /<svg\b[^>]*>/i.exec(svg);
973
+ if (!match) return svg;
974
+ const rootTag = match[0];
975
+ const rawAttrs = rootTag.slice("<svg".length, -1);
976
+ const styleMatch = /\sstyle\s*=\s*"([^"]*)"/i.exec(rawAttrs);
977
+ const keptStyle = (styleMatch?.[1] ?? "").split(";").map((decl) => decl.trim()).filter((decl) => decl && !/^(width|height|display)\s*:/i.test(decl)).join(";");
978
+ const attrs = rawAttrs.replace(/\s(width|height|style|viewBox)\s*=\s*"[^"]*"/gi, "").trimEnd();
979
+ const style = ["display:block", "width:100%", "height:100%", keptStyle].filter(Boolean).join(";");
980
+ const nextTag = `<svg${attrs} width="100%" height="100%" viewBox="0 0 ${widthPx} ${heightPx}" style="${style}">`;
981
+ return svg.slice(0, match.index) + nextTag + svg.slice(match.index + rootTag.length);
982
+ }
983
+ function renderChartToSvg(spec) {
984
+ applyExtraComponents();
985
+ const option = normalizeChartOption(spec.type, spec.option);
986
+ if (!option || typeof option !== "object" || Array.isArray(option)) {
987
+ throw new Error("\u56FE\u8868 option \u975E\u6CD5\uFF1A\u9700\u8981\u5BF9\u8C61");
988
+ }
989
+ const width = mmToChartPx(spec.widthMm);
990
+ const height = mmToChartPx(spec.heightMm);
991
+ const chart = echarts.init(null, null, { renderer: "svg", ssr: true, width, height });
992
+ try {
993
+ const userTextStyle = option.textStyle && typeof option.textStyle === "object" && !Array.isArray(option.textStyle) ? option.textStyle : void 0;
994
+ const textStyle = {
995
+ ...spec.fontFamily ? { fontFamily: spec.fontFamily } : {},
996
+ ...userTextStyle ?? {}
997
+ };
998
+ chart.setOption({
999
+ animation: false,
1000
+ ...option,
1001
+ ...Object.keys(textStyle).length > 0 ? { textStyle } : {}
1002
+ });
1003
+ return fitSvgRoot(chart.renderToSVGString(), width, height);
1004
+ } finally {
1005
+ chart.dispose();
1006
+ }
1007
+ }
1008
+ function escapeHtml(value) {
1009
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
1010
+ }
1011
+ function renderChartElement(spec) {
1012
+ const option = spec._chartOption ?? spec.chartOption;
1013
+ const placeholder = `<span>${escapeHtml(String(spec.title ?? "\u56FE\u8868"))}</span>`;
1014
+ if (!option || typeof option !== "object" || Array.isArray(option)) return placeholder;
1015
+ try {
1016
+ return renderChartToSvg({
1017
+ key: String(spec.key ?? ""),
1018
+ type: String(spec.type ?? ""),
1019
+ option,
1020
+ widthMm: Number(spec.widthMm ?? 0),
1021
+ heightMm: Number(spec.heightMm ?? 0),
1022
+ fontFamily: typeof spec.fontFamily === "string" ? spec.fontFamily : void 0
1023
+ });
1024
+ } catch {
1025
+ return placeholder;
1026
+ }
1027
+ }
1028
+
1029
+ // src/version.ts
1030
+ var CHART_EXECUTOR_VERSION = "2";
1031
+
1032
+ // src/plugin.ts
1033
+ var CHART_OPTION_META = {
1034
+ chartOption: { kind: "object", label: "\u56FE\u8868 option" },
1035
+ chartDataSource: { kind: "text", label: "\u6570\u636E\u6E90" },
1036
+ chartCategoryField: { kind: "text", label: "\u7C7B\u76EE\u5B57\u6BB5" },
1037
+ chartValueFields: { kind: "object", label: "\u6570\u503C\u5B57\u6BB5" },
1038
+ chartSeriesField: { kind: "text", label: "\u7CFB\u5217\u62C6\u5206\u5B57\u6BB5" }
1039
+ };
1040
+ var SCATTER_OPTION_META = {
1041
+ ...CHART_OPTION_META,
1042
+ chartBubble: { kind: "bool", label: "\u6C14\u6CE1\u5927\u5C0F" }
1043
+ };
1044
+ var CHART_PLUGIN = defineElementPlugin({
1045
+ id: CHART_PLUGIN_ID,
1046
+ version: CHART_EXECUTOR_VERSION,
1047
+ kinds: CHART_KIND_DEFINITIONS.map((def) => ({
1048
+ type: def.type,
1049
+ label: def.label,
1050
+ icon: def.icon,
1051
+ fixedHeight: true,
1052
+ requiredOptionKeys: def.requiredOptionKeys,
1053
+ notes: def.notes,
1054
+ optionMeta: def.type === "scatterChart" ? SCATTER_OPTION_META : CHART_OPTION_META,
1055
+ defaultOptions: (partial) => chartFactoryDefaults(def.type, partial),
1056
+ binding: { bind: (options, data) => bindChartData(def.type, options, data) }
1057
+ })),
1058
+ render: {
1059
+ html: renderChartElement,
1060
+ createRenderer: () => ({ render: renderChartElement })
1061
+ }
1062
+ });
1063
+ var disposeHandle;
1064
+ function registerChartPlugin(designer, extraRender) {
1065
+ const current = getElementPluginById(CHART_PLUGIN_ID);
1066
+ if (!designer && !extraRender) {
1067
+ const dispose2 = registerElementPlugin(CHART_PLUGIN);
1068
+ disposeHandle = dispose2;
1069
+ return dispose2;
1070
+ }
1071
+ const merged = {
1072
+ ...CHART_PLUGIN,
1073
+ designer: designer ?? current?.designer ?? CHART_PLUGIN.designer,
1074
+ render: { ...CHART_PLUGIN.render, ...current?.render, ...extraRender }
1075
+ };
1076
+ const dispose = registerElementPlugin(merged);
1077
+ disposeHandle = dispose;
1078
+ return dispose;
1079
+ }
1080
+ registerChartPlugin();
1081
+
1082
+ // src/ui.ts
30
1083
  var CANVAS_STYLE = "width:100%;height:100%;min-width:0;min-height:0;pointer-events:none";
31
1084
  var STYLES = [
32
1085
  ".echarts-canvas-element{overflow:hidden}",
33
1086
  ".echarts-field-row{display:flex;gap:6px;align-items:center}",
34
1087
  ".echarts-field-row>.pd-input{flex:1;min-width:0}",
35
- ".echarts-field-row>.pd-button{flex:none}"
1088
+ ".echarts-field-row>.pd-button{flex:none}",
1089
+ ".echarts-dropdown-trigger{display:flex;align-items:center;justify-content:space-between;gap:6px;width:100%;height:26px;min-height:26px;padding:3px 6px;border:1px solid var(--pd-border,#d9dde6);border-radius:6px;background:var(--pd-input-bg,#fff);color:inherit;font:inherit;box-sizing:border-box;cursor:pointer;text-align:left}",
1090
+ ".echarts-dropdown-trigger:hover{border-color:var(--pd-text-faint,#b4b9c4)}",
1091
+ '.echarts-dropdown-trigger[aria-expanded="true"]{border-color:var(--pd-accent,#165dff);box-shadow:0 0 0 2px rgb(22 93 255 / 12%)}',
1092
+ ".echarts-dropdown-value{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
1093
+ ".echarts-dropdown-arrow{flex:none;color:var(--pd-text-muted,#909399);font-size:10px;transition:transform .14s}",
1094
+ '.echarts-dropdown-trigger[aria-expanded="true"] .echarts-dropdown-arrow{transform:rotate(180deg)}',
1095
+ ".echarts-dropdown-panel{position:fixed;z-index:1200;max-height:240px;overflow:auto;padding:3px;border:1px solid var(--pd-border,#d9dde6);border-radius:6px;background:var(--pd-input-bg,#fff);box-shadow:0 6px 18px rgb(0 0 0 / 14%);box-sizing:border-box}",
1096
+ ".echarts-dropdown-option{padding:5px 8px;border-radius:4px;cursor:pointer;font-size:12px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}",
1097
+ ".echarts-dropdown-option:hover{background:var(--pd-accent-soft,rgb(22 93 255 / 9%))}",
1098
+ ".echarts-dropdown-option.is-active{background:var(--pd-accent-soft,rgb(22 93 255 / 9%));color:var(--pd-accent,#165dff)}",
1099
+ ".echarts-label-group{margin-top:8px;border-top:1px solid var(--pd-border,#e5e7eb);padding-top:8px}",
1100
+ ".echarts-label-group>summary{display:flex;align-items:center;cursor:pointer;list-style:none;font-size:12px;font-weight:600}",
1101
+ ".echarts-label-summary>.pd-field{flex:1;margin:0;font-weight:400}",
1102
+ ".echarts-label-sub{font-size:11px;color:var(--pd-text-secondary,#6b7280);margin:8px 0 4px}"
36
1103
  ].join("");
37
1104
  var CHART_OPTION_KEYS = [
38
1105
  "chartOption",
@@ -60,11 +1127,13 @@ var SEARCH_KEYWORDS = [
60
1127
  "\u6563\u70B9",
61
1128
  "\u96F7\u8FBE",
62
1129
  "\u6F0F\u6597",
63
- "\u4EEA\u8868"
1130
+ "\u4EEA\u8868",
1131
+ "\u6570\u636E\u6807\u7B7E",
1132
+ "\u6570\u503C\u6807\u7B7E",
1133
+ "label"
64
1134
  ];
65
1135
  var PANEL_HINT = "\u6570\u636E\u7531\u6A21\u677F\u7ED1\u5B9A\u9636\u6BB5\u6CE8\u5165\uFF1Aseries/xAxis \u7684 data \u4FDD\u7559 `$data` \u5360\u4F4D\u5373\u53EF\uFF1B\u590D\u6742\u6837\u5F0F\u53EF\u5728\u6A21\u677F JSON \u4E2D\u624B\u5199 chartOption\u3002";
66
- var datalistSeq = 0;
67
- function escapeHtml(value) {
1136
+ function escapeHtml2(value) {
68
1137
  return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
69
1138
  }
70
1139
  function elementType(element) {
@@ -112,10 +1181,37 @@ function dataSourceCandidates(data) {
112
1181
  if (!first) return [];
113
1182
  return Object.keys(first).filter((key) => Array.isArray(first[key]));
114
1183
  }
1184
+ function dataRowFields(data, dataSource) {
1185
+ const first = data?.[0];
1186
+ if (!first) return [];
1187
+ const key = dataSource && Array.isArray(first[dataSource]) ? dataSource : Object.keys(first).find((k) => Array.isArray(first[k]));
1188
+ if (!key) return [];
1189
+ const rows = first[key];
1190
+ return rows.length > 0 && typeof rows[0] === "object" && rows[0] !== null ? Object.keys(rows[0]) : [];
1191
+ }
1192
+ function fieldLabelMap(fields) {
1193
+ const map = /* @__PURE__ */ new Map();
1194
+ for (const field2 of fields ?? []) {
1195
+ if (field2.fieldKey && field2.fieldLabel) map.set(field2.fieldKey, field2.fieldLabel);
1196
+ }
1197
+ return map;
1198
+ }
1199
+ function optionLabel(value, labels, fallbackSuffix) {
1200
+ if (!value) return fallbackSuffix ?? "\uFF08\u9ED8\u8BA4\uFF09";
1201
+ const name = labels.get(value);
1202
+ const base = name ? `${name}\uFF08${value}\uFF09` : value;
1203
+ return fallbackSuffix ? `${base}${fallbackSuffix}` : base;
1204
+ }
1205
+ function dropdownOptions(candidates, current, labels = /* @__PURE__ */ new Map()) {
1206
+ const opts = candidates.map((value) => ({ value, label: optionLabel(value, labels) }));
1207
+ if (current && !candidates.includes(current)) opts.unshift({ value: current, label: optionLabel(current, labels, "\uFF08\u5F53\u524D\uFF09") });
1208
+ if (!current) opts.unshift({ value: "", label: "\uFF08\u9ED8\u8BA4\uFF1A\u9876\u5C42\u7B2C\u4E00\u4E2A\u6570\u7EC4\uFF09" });
1209
+ return opts;
1210
+ }
115
1211
  function seriesList(option) {
116
1212
  return Array.isArray(option.series) ? option.series : [];
117
1213
  }
118
- function clamp(value, min, max) {
1214
+ function clamp2(value, min, max) {
119
1215
  return Math.min(max, Math.max(min, value));
120
1216
  }
121
1217
  function syncValueFields(ctx, type, nextFields) {
@@ -142,7 +1238,7 @@ function renderCanvas(ctx) {
142
1238
  return `<div class="echarts-canvas-element" style="${CANVAS_STYLE}">${svg}</div>`;
143
1239
  } catch {
144
1240
  const title = typeof options.title === "string" && options.title.trim() ? options.title : getChartKindDefinition(type)?.label ?? "\u56FE\u8868";
145
- return `<div class="echarts-canvas-element" style="${CANVAS_STYLE}">${escapeHtml(title)}</div>`;
1241
+ return `<div class="echarts-canvas-element" style="${CANVAS_STYLE}">${escapeHtml2(title)}</div>`;
146
1242
  }
147
1243
  }
148
1244
  function el(tag, className, text) {
@@ -178,6 +1274,270 @@ function checkboxField(labelText, checked, onCommit) {
178
1274
  wrap.appendChild(input);
179
1275
  return wrap;
180
1276
  }
1277
+ function selectInput(options, value, onCommit) {
1278
+ const select = el("select", "pd-select");
1279
+ for (const item of options) {
1280
+ const optionEl = el("option");
1281
+ optionEl.value = item.value;
1282
+ optionEl.textContent = item.label;
1283
+ select.appendChild(optionEl);
1284
+ }
1285
+ select.value = value;
1286
+ select.addEventListener("change", () => onCommit(select.value));
1287
+ return select;
1288
+ }
1289
+ var activeDropdown = null;
1290
+ function composedPathOf(ev) {
1291
+ const composed = typeof ev.composedPath === "function" ? ev.composedPath() : [];
1292
+ return composed.length ? composed : [ev.target];
1293
+ }
1294
+ function dropdownSelect(options, value, onCommit) {
1295
+ const current = options.find((item) => item.value === value) ?? { value, label: value || "\uFF08\u9ED8\u8BA4\uFF09" };
1296
+ const trigger = el("button", "echarts-dropdown-trigger");
1297
+ trigger.type = "button";
1298
+ trigger.setAttribute("aria-haspopup", "listbox");
1299
+ trigger.setAttribute("aria-expanded", "false");
1300
+ const valueEl = el("span", "echarts-dropdown-value", current.label);
1301
+ const arrow = el("span", "echarts-dropdown-arrow", "\u25BE");
1302
+ trigger.appendChild(valueEl);
1303
+ trigger.appendChild(arrow);
1304
+ let panel = null;
1305
+ let off = [];
1306
+ const close = () => {
1307
+ off.forEach((fn) => fn());
1308
+ off = [];
1309
+ panel?.remove();
1310
+ panel = null;
1311
+ trigger.setAttribute("aria-expanded", "false");
1312
+ if (activeDropdown?.close === close) activeDropdown = null;
1313
+ };
1314
+ const open = () => {
1315
+ activeDropdown?.close();
1316
+ const root = trigger.getRootNode();
1317
+ const mount = root instanceof ShadowRoot ? root : document.body;
1318
+ panel = el("div", "echarts-dropdown-panel");
1319
+ panel.setAttribute("role", "listbox");
1320
+ for (const item of options) {
1321
+ const optionEl = el("div", `echarts-dropdown-option${item.value === value ? " is-active" : ""}`, item.label);
1322
+ optionEl.setAttribute("role", "option");
1323
+ optionEl.setAttribute("aria-selected", item.value === value ? "true" : "false");
1324
+ optionEl.addEventListener("click", (ev) => {
1325
+ ev.stopPropagation();
1326
+ close();
1327
+ onCommit(item.value);
1328
+ });
1329
+ panel.appendChild(optionEl);
1330
+ }
1331
+ mount.appendChild(panel);
1332
+ const rect = trigger.getBoundingClientRect();
1333
+ panel.style.left = `${rect.left}px`;
1334
+ panel.style.top = `${rect.bottom + 4}px`;
1335
+ panel.style.minWidth = `${rect.width}px`;
1336
+ trigger.setAttribute("aria-expanded", "true");
1337
+ activeDropdown = { close };
1338
+ const onPointerDown = (ev) => {
1339
+ const path = composedPathOf(ev);
1340
+ if (path.includes(trigger) || path.includes(panel)) return;
1341
+ close();
1342
+ };
1343
+ const onKeydown = (ev) => {
1344
+ if (ev.key === "Escape") close();
1345
+ };
1346
+ const onScroll = () => close();
1347
+ document.addEventListener("pointerdown", onPointerDown, true);
1348
+ document.addEventListener("keydown", onKeydown);
1349
+ window.addEventListener("scroll", onScroll, true);
1350
+ window.addEventListener("resize", onScroll);
1351
+ root.addEventListener("scroll", onScroll, true);
1352
+ off.push(
1353
+ () => document.removeEventListener("pointerdown", onPointerDown, true),
1354
+ () => document.removeEventListener("keydown", onKeydown),
1355
+ () => window.removeEventListener("scroll", onScroll, true),
1356
+ () => window.removeEventListener("resize", onScroll),
1357
+ () => root.removeEventListener("scroll", onScroll, true)
1358
+ );
1359
+ };
1360
+ trigger.addEventListener("click", (ev) => {
1361
+ ev.stopPropagation();
1362
+ if (panel) close();
1363
+ else open();
1364
+ });
1365
+ return trigger;
1366
+ }
1367
+ var OVERFLOW_OPTIONS = [
1368
+ { value: "", label: "\u9ED8\u8BA4" },
1369
+ { value: "none", label: "\u4E0D\u5904\u7406\uFF08\u663E\u793A\u5B8C\u6574\uFF09" },
1370
+ { value: "truncate", label: "\u622A\u65AD" },
1371
+ { value: "break", label: "\u6362\u884C" }
1372
+ ];
1373
+ var FONT_WEIGHT_OPTIONS = [
1374
+ { value: "", label: "\u9ED8\u8BA4" },
1375
+ { value: "normal", label: "\u5E38\u89C4" },
1376
+ { value: "bold", label: "\u52A0\u7C97" }
1377
+ ];
1378
+ var STYLE_FIELD_LABELS = {
1379
+ distance: "\u8DDD\u79BB",
1380
+ rotate: "\u65CB\u8F6C\uFF08\u5EA6\uFF09",
1381
+ fontSize: "\u5B57\u53F7",
1382
+ fontWeight: "\u5B57\u91CD",
1383
+ color: "\u6587\u5B57\u989C\u8272",
1384
+ backgroundColor: "\u80CC\u666F\u8272",
1385
+ borderColor: "\u8FB9\u6846\u8272",
1386
+ borderWidth: "\u8FB9\u6846\u5BBD\u5EA6",
1387
+ borderRadius: "\u5706\u89D2",
1388
+ padding: "\u5185\u8FB9\u8DDD"
1389
+ };
1390
+ function renderLabelGroup(ctx, type) {
1391
+ const element = ctx.element;
1392
+ const def = getChartKindDefinition(type);
1393
+ const fields = labelFieldsOf(type);
1394
+ const has = (key) => fields.includes(key);
1395
+ const state = readChartLabel(panelOption(element), type);
1396
+ const commit = (patch) => {
1397
+ commitOption(ctx, type, updateChartLabel(panelOption(element), type, patch));
1398
+ };
1399
+ const commitNumber = (key, raw) => {
1400
+ if (raw.trim() === "") return commit({ [key]: null });
1401
+ const value = Number(raw);
1402
+ if (!Number.isFinite(value)) return;
1403
+ commit({ [key]: value });
1404
+ };
1405
+ const commitLineNumber = (key, raw) => {
1406
+ if (raw.trim() === "") return commit({ labelLine: { [key]: null } });
1407
+ const value = Number(raw);
1408
+ if (!Number.isFinite(value)) return;
1409
+ commit({ labelLine: { [key]: value } });
1410
+ };
1411
+ const numberField = (key, value) => {
1412
+ const wrap = field(STYLE_FIELD_LABELS[key] ?? key);
1413
+ wrap.appendChild(
1414
+ textInput({ value: value === void 0 ? "" : String(value), type: "number" }, (raw) => commitNumber(key, raw))
1415
+ );
1416
+ return wrap;
1417
+ };
1418
+ const colorField = (key, value) => {
1419
+ const wrap = field(STYLE_FIELD_LABELS[key] ?? key);
1420
+ const holder = el("span");
1421
+ render(colorPicker({
1422
+ value: value ?? "",
1423
+ title: STYLE_FIELD_LABELS[key] ?? key,
1424
+ onChange: (next) => commit({ [key]: next ?? "" })
1425
+ }), holder);
1426
+ wrap.appendChild(holder);
1427
+ return wrap;
1428
+ };
1429
+ const group = el("details", "echarts-label-group");
1430
+ group.open = state.show;
1431
+ const summary = el("summary", "echarts-label-summary");
1432
+ const toggle = checkboxField("\u663E\u793A\u6570\u636E\u6807\u7B7E", state.show, (checked) => commit({ enabled: checked }));
1433
+ toggle.querySelector("input")?.addEventListener("click", (event) => event.stopPropagation());
1434
+ summary.appendChild(toggle);
1435
+ group.appendChild(summary);
1436
+ if (has("formatter") || has("overflow")) {
1437
+ group.appendChild(el("div", "echarts-label-sub", "\u5185\u5BB9"));
1438
+ if (has("formatter")) {
1439
+ const wrap = field("\u6570\u636E\u6807\u7B7E\u5185\u5BB9");
1440
+ wrap.appendChild(
1441
+ selectInput(
1442
+ [{ value: "", label: "\u81EA\u5B9A\u4E49 / \u9ED8\u8BA4" }, ...LABEL_PRESETS.map((preset) => ({ value: preset.formatter, label: preset.label }))],
1443
+ state.formatter ?? "",
1444
+ (value) => commit({ formatter: value })
1445
+ )
1446
+ );
1447
+ wrap.appendChild(
1448
+ textInput({ value: state.formatter ?? "", placeholder: "\u5982 {b}: {c}" }, (value) => commit({ formatter: value }))
1449
+ );
1450
+ group.appendChild(wrap);
1451
+ }
1452
+ if (has("overflow")) {
1453
+ const wrap = field("\u6EA2\u51FA\u5904\u7406");
1454
+ wrap.appendChild(selectInput(OVERFLOW_OPTIONS, state.overflow ?? "", (value) => commit({ overflow: value })));
1455
+ group.appendChild(wrap);
1456
+ }
1457
+ }
1458
+ if (has("position") || has("distance") || has("rotate") || has("offset")) {
1459
+ group.appendChild(el("div", "echarts-label-sub", "\u4F4D\u7F6E"));
1460
+ if (has("position")) {
1461
+ const wrap = field("\u6807\u7B7E\u4F4D\u7F6E");
1462
+ const positions = def ? LABEL_POSITIONS[def.seriesType] ?? [] : [];
1463
+ wrap.appendChild(
1464
+ selectInput([{ value: "", label: "\u9ED8\u8BA4" }, ...positions], state.position ?? "", (value) => commit({ position: value }))
1465
+ );
1466
+ group.appendChild(wrap);
1467
+ }
1468
+ if (has("distance")) group.appendChild(numberField("distance", state.distance));
1469
+ if (has("rotate")) group.appendChild(numberField("rotate", state.rotate));
1470
+ if (has("offset")) {
1471
+ let commitOffset2 = function() {
1472
+ const parse = (input, fallback) => {
1473
+ const text = input.value.trim();
1474
+ if (text === "") return 0;
1475
+ const value = Number(text);
1476
+ return Number.isFinite(value) ? value : fallback;
1477
+ };
1478
+ commit({ offset: [parse(inputX, current[0] ?? 0), parse(inputY, current[1] ?? 0)] });
1479
+ };
1480
+ var commitOffset = commitOffset2;
1481
+ const wrap = field("\u504F\u79FB X / Y");
1482
+ const row = el("div", "echarts-field-row");
1483
+ const current = state.offset ?? [0, 0];
1484
+ const inputX = textInput({ value: String(current[0] ?? 0), type: "number" }, () => commitOffset2());
1485
+ const inputY = textInput({ value: String(current[1] ?? 0), type: "number" }, () => commitOffset2());
1486
+ row.appendChild(inputX);
1487
+ row.appendChild(inputY);
1488
+ wrap.appendChild(row);
1489
+ group.appendChild(wrap);
1490
+ }
1491
+ }
1492
+ const styleKeys = ["fontSize", "fontWeight", "color", "backgroundColor", "borderColor", "borderWidth", "borderRadius", "padding"];
1493
+ if (styleKeys.some(has)) {
1494
+ group.appendChild(el("div", "echarts-label-sub", "\u6837\u5F0F"));
1495
+ if (has("fontSize")) group.appendChild(numberField("fontSize", state.fontSize));
1496
+ if (has("fontWeight")) {
1497
+ const wrap = field("\u5B57\u91CD");
1498
+ wrap.appendChild(selectInput(FONT_WEIGHT_OPTIONS, state.fontWeight ?? "", (value) => commit({ fontWeight: value })));
1499
+ group.appendChild(wrap);
1500
+ }
1501
+ for (const key of ["color", "backgroundColor", "borderColor"]) {
1502
+ if (has(key)) group.appendChild(colorField(key, state[key]));
1503
+ }
1504
+ for (const key of ["borderWidth", "borderRadius", "padding"]) {
1505
+ if (has(key)) group.appendChild(numberField(key, state[key]));
1506
+ }
1507
+ }
1508
+ if (has("labelLine.show")) {
1509
+ group.appendChild(el("div", "echarts-label-sub", "\u5F15\u5BFC\u7EBF"));
1510
+ group.appendChild(
1511
+ checkboxField("\u663E\u793A\u5F15\u5BFC\u7EBF", state.labelLine.show === true, (checked) => commit({ labelLine: { show: checked } }))
1512
+ );
1513
+ if (has("labelLine.length")) {
1514
+ const wrap = field("\u5F15\u5BFC\u7EBF\u957F\u5EA6");
1515
+ wrap.appendChild(
1516
+ textInput(
1517
+ { value: state.labelLine.length === void 0 ? "" : String(state.labelLine.length), type: "number" },
1518
+ (raw) => commitLineNumber("length", raw)
1519
+ )
1520
+ );
1521
+ group.appendChild(wrap);
1522
+ }
1523
+ if (has("labelLine.length2")) {
1524
+ const wrap = field("\u7B2C\u4E8C\u6BB5\u957F\u5EA6");
1525
+ wrap.appendChild(
1526
+ textInput(
1527
+ { value: state.labelLine.length2 === void 0 ? "" : String(state.labelLine.length2), type: "number" },
1528
+ (raw) => commitLineNumber("length2", raw)
1529
+ )
1530
+ );
1531
+ group.appendChild(wrap);
1532
+ }
1533
+ if (has("labelLine.smooth")) {
1534
+ group.appendChild(
1535
+ checkboxField("\u5E73\u6ED1\u5F15\u5BFC\u7EBF", state.labelLine.smooth === true, (checked) => commit({ labelLine: { smooth: checked } }))
1536
+ );
1537
+ }
1538
+ }
1539
+ return group;
1540
+ }
181
1541
  function renderProperty(ctx) {
182
1542
  const element = ctx.element;
183
1543
  const type = elementType(element);
@@ -189,41 +1549,30 @@ function renderProperty(ctx) {
189
1549
  const heightMm = Number(options.height) || 0;
190
1550
  const limit = maxValueFields(def);
191
1551
  const palettes = getChartPalettes();
1552
+ const fieldLabels = fieldLabelMap(ctx.fields);
192
1553
  const root = el("div", "echarts-property");
193
1554
  const form = el("form", "pd-form");
194
1555
  form.addEventListener("submit", (event) => event.preventDefault());
195
1556
  root.appendChild(form);
196
1557
  if (has("dataSource")) {
197
1558
  const wrap = field("\u6570\u636E\u6E90");
198
- const candidates = dataSourceCandidates(ctx.data);
199
- let datalist;
200
- if (candidates.length > 0) {
201
- datalist = el("datalist");
202
- datalist.id = `echarts-ds-${++datalistSeq}`;
203
- for (const key of candidates) {
204
- const optionEl = el("option");
205
- optionEl.value = key;
206
- datalist.appendChild(optionEl);
207
- }
208
- }
1559
+ const current = String(options.chartDataSource ?? "");
209
1560
  wrap.appendChild(
210
- textInput(
211
- {
212
- value: String(options.chartDataSource ?? ""),
213
- placeholder: "\u6570\u636E\u96C6\u8DEF\u5F84\uFF08\u7559\u7A7A\u53D6\u9876\u5C42\u7B2C\u4E00\u4E2A\u6570\u7EC4\uFF09",
214
- list: datalist?.id
215
- },
1561
+ dropdownSelect(
1562
+ dropdownOptions(dataSourceCandidates(ctx.data), current, fieldLabels),
1563
+ current,
216
1564
  (value) => commitOption(ctx, type, panelOption(element), { chartDataSource: value })
217
1565
  )
218
1566
  );
219
- if (datalist) wrap.appendChild(datalist);
220
1567
  form.appendChild(wrap);
221
1568
  }
222
1569
  if (has("categoryField")) {
223
1570
  const wrap = field("\u7C7B\u76EE\u5B57\u6BB5");
1571
+ const current = String(options.chartCategoryField ?? "");
224
1572
  wrap.appendChild(
225
- textInput(
226
- { value: String(options.chartCategoryField ?? ""), placeholder: "\u5982 name" },
1573
+ dropdownSelect(
1574
+ dropdownOptions(dataRowFields(ctx.data, String(options.chartDataSource ?? "")), current, fieldLabels),
1575
+ current,
227
1576
  (value) => commitOption(ctx, type, panelOption(element), { chartCategoryField: value })
228
1577
  )
229
1578
  );
@@ -235,8 +1584,9 @@ function renderProperty(ctx) {
235
1584
  fieldsNow.forEach((value, index) => {
236
1585
  const row = el("div", "echarts-field-row");
237
1586
  row.appendChild(
238
- textInput(
239
- { value, placeholder: "\u5982 value" },
1587
+ dropdownSelect(
1588
+ dropdownOptions(dataRowFields(ctx.data, String(options.chartDataSource ?? "")), value, fieldLabels),
1589
+ value,
240
1590
  (next) => {
241
1591
  const list = readValueFields(element);
242
1592
  list[index] = next;
@@ -321,6 +1671,9 @@ function renderProperty(ctx) {
321
1671
  wrap.appendChild(select);
322
1672
  form.appendChild(wrap);
323
1673
  }
1674
+ if (has("label")) {
1675
+ form.appendChild(renderLabelGroup(ctx, type));
1676
+ }
324
1677
  if (has("stack")) {
325
1678
  const series = seriesList(panelOption(element));
326
1679
  const stacked = series.some((item) => item.stack !== void 0 && item.stack !== null && item.stack !== "");
@@ -343,7 +1696,7 @@ function renderProperty(ctx) {
343
1696
  textInput({ value: String(inner), type: "number", min: 0, max: 90 }, (value) => {
344
1697
  const next = panelOption(element);
345
1698
  const series = seriesList(next);
346
- if (series[0]) series[0].radius = [`${clamp(Number(value) || 0, 0, 90)}%`, "70%"];
1699
+ if (series[0]) series[0].radius = [`${clamp2(Number(value) || 0, 0, 90)}%`, "70%"];
347
1700
  commitOption(ctx, type, next);
348
1701
  })
349
1702
  );
@@ -363,7 +1716,7 @@ function renderProperty(ctx) {
363
1716
  row.appendChild(
364
1717
  textInput({ value: String(padding[side]), type: "number", min: 0, max: 60, title }, (value) => {
365
1718
  const raw = Number(value);
366
- const next = Number.isFinite(raw) ? clamp(raw, 0, 60) : FUNNEL_PADDING_DEFAULTS[side];
1719
+ const next = Number.isFinite(raw) ? clamp2(raw, 0, 60) : FUNNEL_PADDING_DEFAULTS[side];
367
1720
  const option = panelOption(element);
368
1721
  const current = readFunnelPadding(option, widthMm, heightMm);
369
1722
  commitOption(ctx, type, writeFunnelPadding(option, { ...current, [side]: next }));
@@ -380,7 +1733,7 @@ function renderProperty(ctx) {
380
1733
  { value: String(readRadarRadius(panelOption(element), widthMm, heightMm)), type: "number", min: 20, max: 100 },
381
1734
  (value) => {
382
1735
  const raw = Number(value);
383
- const next = Number.isFinite(raw) ? clamp(raw, 20, 100) : RADAR_RADIUS_DEFAULT;
1736
+ const next = Number.isFinite(raw) ? clamp2(raw, 20, 100) : RADAR_RADIUS_DEFAULT;
384
1737
  commitOption(ctx, type, writeRadarRadius(panelOption(element), next));
385
1738
  }
386
1739
  )
@@ -422,15 +1775,15 @@ var CHART_ELEMENT_UI = defineElementUI({
422
1775
  searchKeywords: SEARCH_KEYWORDS,
423
1776
  styles: STYLES
424
1777
  });
425
- var disposeHandle;
1778
+ var disposeHandle2;
426
1779
  function installChartCommonUI() {
427
- disposeHandle?.();
428
- disposeHandle = registerElementUI(CHART_ELEMENT_UI);
429
- return disposeHandle;
1780
+ disposeHandle2?.();
1781
+ disposeHandle2 = registerElementUI(CHART_ELEMENT_UI);
1782
+ return disposeHandle2;
430
1783
  }
431
1784
  function uninstallChartCommonUI() {
432
- disposeHandle?.();
433
- disposeHandle = void 0;
1785
+ disposeHandle2?.();
1786
+ disposeHandle2 = void 0;
434
1787
  }
435
1788
  installChartCommonUI();
436
1789
  export {