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