@worm-print-platform/echarts 1.5.0 → 1.5.3

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.
@@ -0,0 +1,1064 @@
1
+ /*!
2
+ * @worm-print-platform/echarts v1.5.3
3
+ * Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
4
+ * SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
5
+ * SPDX-License-Identifier: MIT
6
+ */
7
+
8
+ // src/plugin.ts
9
+ import {
10
+ defineElementPlugin,
11
+ getElementPluginById,
12
+ registerElementPlugin
13
+ } from "@worm-print-platform/core/designer";
14
+
15
+ // src/kinds.ts
16
+ var BASE_REQUIRED = ["left", "top", "width", "height", "chartOption"];
17
+ var DATA_FIELDS = ["dataSource", "categoryField", "valueFields", "seriesField"];
18
+ var STYLE_FIELDS = ["title", "legend", "palette"];
19
+ var CHART_KIND_DEFINITIONS = [
20
+ {
21
+ type: "barChart",
22
+ label: "\u67F1\u72B6\u56FE",
23
+ icon: "ChartColumn",
24
+ seriesType: "bar",
25
+ orientation: "vertical",
26
+ fields: [...DATA_FIELDS, ...STYLE_FIELDS, "stack"],
27
+ requiredOptionKeys: BASE_REQUIRED,
28
+ defaultWidth: 100,
29
+ defaultHeight: 60,
30
+ 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"
31
+ },
32
+ {
33
+ type: "barHChart",
34
+ label: "\u6761\u5F62\u56FE",
35
+ icon: "ChartBar",
36
+ seriesType: "bar",
37
+ orientation: "horizontal",
38
+ fields: [...DATA_FIELDS, ...STYLE_FIELDS, "stack"],
39
+ requiredOptionKeys: BASE_REQUIRED,
40
+ defaultWidth: 100,
41
+ defaultHeight: 60,
42
+ notes: "\u6A2A\u5411\u6761\u5F62\u56FE\uFF1AxAxis \u4E3A\u6570\u503C\u3001yAxis \u4E3A\u7C7B\u76EE\uFF1B\u7C7B\u76EE\u5199 yAxis.data \u7684 $data \u5360\u4F4D"
43
+ },
44
+ {
45
+ type: "lineChart",
46
+ label: "\u6298\u7EBF\u56FE",
47
+ icon: "ChartLine",
48
+ seriesType: "line",
49
+ fields: [...DATA_FIELDS, ...STYLE_FIELDS, "stack"],
50
+ requiredOptionKeys: BASE_REQUIRED,
51
+ defaultWidth: 100,
52
+ defaultHeight: 60,
53
+ notes: "\u6298\u7EBF\u56FE\uFF1A\u7C7B\u76EE + \u591A\u4E2A\u6570\u503C\u5B57\u6BB5\uFF1B\u4E0D\u5199 areaStyle"
54
+ },
55
+ {
56
+ type: "areaChart",
57
+ label: "\u9762\u79EF\u56FE",
58
+ icon: "ChartArea",
59
+ seriesType: "line",
60
+ fields: [...DATA_FIELDS, ...STYLE_FIELDS, "stack"],
61
+ requiredOptionKeys: BASE_REQUIRED,
62
+ defaultWidth: 100,
63
+ defaultHeight: 60,
64
+ notes: "\u9762\u79EF\u56FE\uFF1A\u6298\u7EBF + series[].areaStyle\uFF1B\u5176\u4F59\u540C\u6298\u7EBF\u56FE"
65
+ },
66
+ {
67
+ type: "pieChart",
68
+ label: "\u997C\u56FE",
69
+ icon: "ChartPie",
70
+ seriesType: "pie",
71
+ fields: ["dataSource", "categoryField", "valueFields", ...STYLE_FIELDS],
72
+ requiredOptionKeys: BASE_REQUIRED,
73
+ defaultWidth: 60,
74
+ defaultHeight: 60,
75
+ 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"
76
+ },
77
+ {
78
+ type: "doughnutChart",
79
+ label: "\u73AF\u5F62\u56FE",
80
+ icon: "Donut",
81
+ seriesType: "pie",
82
+ fields: ["dataSource", "categoryField", "valueFields", ...STYLE_FIELDS, "innerRadius"],
83
+ requiredOptionKeys: BASE_REQUIRED,
84
+ defaultWidth: 60,
85
+ defaultHeight: 60,
86
+ notes: "\u73AF\u5F62\u56FE\uFF1A\u997C\u56FE + radius:[\u5185\u5F84,\u5916\u5F84]\uFF1B\u5185\u5F84\u7531\u9762\u677F\u914D\u7F6E"
87
+ },
88
+ {
89
+ type: "scatterChart",
90
+ label: "\u6563\u70B9\u56FE",
91
+ icon: "ChartScatter",
92
+ seriesType: "scatter",
93
+ fields: ["dataSource", "categoryField", "valueFields", ...STYLE_FIELDS, "bubble"],
94
+ requiredOptionKeys: BASE_REQUIRED,
95
+ defaultWidth: 80,
96
+ defaultHeight: 60,
97
+ 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"
98
+ },
99
+ {
100
+ type: "radarChart",
101
+ label: "\u96F7\u8FBE\u56FE",
102
+ icon: "Radar",
103
+ seriesType: "radar",
104
+ fields: ["dataSource", "categoryField", "valueFields", ...STYLE_FIELDS, "radius"],
105
+ requiredOptionKeys: BASE_REQUIRED,
106
+ defaultWidth: 70,
107
+ defaultHeight: 60,
108
+ 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"
109
+ },
110
+ {
111
+ type: "funnelChart",
112
+ label: "\u6F0F\u6597\u56FE",
113
+ icon: "Funnel",
114
+ seriesType: "funnel",
115
+ fields: ["dataSource", "categoryField", "valueFields", ...STYLE_FIELDS, "padding"],
116
+ requiredOptionKeys: BASE_REQUIRED,
117
+ defaultWidth: 60,
118
+ defaultHeight: 60,
119
+ 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"
120
+ },
121
+ {
122
+ type: "gaugeChart",
123
+ label: "\u4EEA\u8868\u76D8",
124
+ icon: "Gauge",
125
+ seriesType: "gauge",
126
+ fields: ["dataSource", "valueFields", ...STYLE_FIELDS, "gaugeRange"],
127
+ requiredOptionKeys: BASE_REQUIRED,
128
+ defaultWidth: 60,
129
+ defaultHeight: 60,
130
+ 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"
131
+ }
132
+ ];
133
+ var CHART_KINDS = CHART_KIND_DEFINITIONS.map((def) => def.type);
134
+ function getChartKindDefinition(type) {
135
+ return CHART_KIND_DEFINITIONS.find((def) => def.type === type);
136
+ }
137
+
138
+ // src/bind.ts
139
+ import { evaluateTemplate } from "@worm-print-platform/core";
140
+ function chartNumber(value) {
141
+ const n = typeof value === "number" ? value : Number(value);
142
+ return Number.isFinite(n) ? n : 0;
143
+ }
144
+ function evaluateChartOption(node, data) {
145
+ if (typeof node === "string") {
146
+ if (node.startsWith("$data")) return node;
147
+ return node.includes("{") ? evaluateTemplate(node, data) : node;
148
+ }
149
+ if (Array.isArray(node)) return node.map((item) => evaluateChartOption(item, data));
150
+ if (node && typeof node === "object") {
151
+ const out = {};
152
+ for (const [key, value] of Object.entries(node)) {
153
+ out[key] = evaluateChartOption(value, data);
154
+ }
155
+ return out;
156
+ }
157
+ return node;
158
+ }
159
+ function hasDataPlaceholder(series) {
160
+ return Array.isArray(series.data) && series.data.includes("$data");
161
+ }
162
+ function resolveListSource(options, data) {
163
+ const explicit = options.dataSource;
164
+ if (typeof explicit === "string" && Array.isArray(data[explicit])) return data[explicit];
165
+ for (const value of Object.values(data)) {
166
+ if (Array.isArray(value)) return value;
167
+ }
168
+ return [];
169
+ }
170
+ function asString(value) {
171
+ return typeof value === "string" && value.length > 0 ? value : void 0;
172
+ }
173
+ function asFieldList(value) {
174
+ return Array.isArray(value) ? value.filter((item) => typeof item === "string" && item.length > 0) : [];
175
+ }
176
+ function seriesOf(option) {
177
+ return Array.isArray(option.series) ? option.series : [];
178
+ }
179
+ function rowValue(row, field2) {
180
+ return field2 ? chartNumber(row[field2]) : 0;
181
+ }
182
+ function writeCategories(option, categories) {
183
+ for (const key of ["xAxis", "yAxis"]) {
184
+ const raw = option[key];
185
+ const axes = Array.isArray(raw) ? raw : raw ? [raw] : [];
186
+ for (const axis of axes) {
187
+ if (axis && typeof axis === "object" && Array.isArray(axis.data) && axis.data.includes("$data")) {
188
+ axis.data = [...categories];
189
+ }
190
+ }
191
+ }
192
+ }
193
+ function applyCartesian(option, rows, categoryField, valueFields, seriesField) {
194
+ const rawSeries = seriesOf(option);
195
+ if (!rawSeries.some(hasDataPlaceholder)) return;
196
+ const categories = rows.map((row, index) => categoryField ? row[categoryField] : index + 1);
197
+ const fieldAt = (index) => valueFields[Math.min(index, valueFields.length - 1)];
198
+ if (seriesField) {
199
+ const template2 = rawSeries[0];
200
+ const groups = /* @__PURE__ */ new Map();
201
+ for (const row of rows) {
202
+ const name = String(row[seriesField] ?? "");
203
+ const bucket = groups.get(name) ?? /* @__PURE__ */ new Map();
204
+ const category = String(row[categoryField ?? ""]);
205
+ bucket.set(category, (bucket.get(category) ?? 0) + rowValue(row, fieldAt(0)));
206
+ groups.set(name, bucket);
207
+ }
208
+ const distinctCategories = [...new Set(categories)];
209
+ option.series = [...groups.entries()].map(([name, bucket]) => ({
210
+ ...template2,
211
+ name,
212
+ data: distinctCategories.map((category) => bucket.get(String(category)) ?? null)
213
+ }));
214
+ writeCategories(option, distinctCategories);
215
+ return;
216
+ }
217
+ const template = rawSeries[rawSeries.length - 1];
218
+ while (rawSeries.length < valueFields.length) rawSeries.push({ ...template, data: ["$data"] });
219
+ option.series = rawSeries.map((series, index) => {
220
+ if (!hasDataPlaceholder(series)) return series;
221
+ return { ...series, data: rows.map((row) => rowValue(row, fieldAt(index))) };
222
+ });
223
+ writeCategories(option, categories);
224
+ }
225
+ function applyPieLike(option, rows, categoryField, valueField, sortDescending) {
226
+ const series = seriesOf(option);
227
+ if (!series.some(hasDataPlaceholder)) return;
228
+ const data = rows.map((row) => ({
229
+ name: categoryField ? String(row[categoryField] ?? "") : "",
230
+ value: rowValue(row, valueField)
231
+ }));
232
+ if (sortDescending) data.sort((a, b) => b.value - a.value);
233
+ option.series = series.map((item) => ({ ...item, data }));
234
+ }
235
+ function applyScatter(option, rows, xField, valueFields, bubble) {
236
+ const series = seriesOf(option);
237
+ if (!series.some(hasDataPlaceholder)) return;
238
+ const yField = valueFields[0];
239
+ const sizeField = bubble ? valueFields[1] : void 0;
240
+ const sizes = sizeField ? rows.map((row) => rowValue(row, sizeField)) : [];
241
+ const min = sizes.length > 0 ? Math.min(...sizes) : 0;
242
+ const max = sizes.length > 0 ? Math.max(...sizes) : 0;
243
+ const sizeOf = (value) => max === min ? 12 : Math.round(6 + (value - min) / (max - min) * 18);
244
+ option.series = series.map((item) => ({
245
+ ...item,
246
+ data: rows.map((row) => {
247
+ const value = [rowValue(row, xField), rowValue(row, yField)];
248
+ if (!sizeField) return value;
249
+ return { value, symbolSize: sizeOf(rowValue(row, sizeField)) };
250
+ })
251
+ }));
252
+ }
253
+ function niceMax(value) {
254
+ if (value <= 0) return 10;
255
+ const magnitude = 10 ** Math.floor(Math.log10(value));
256
+ const step = magnitude >= 10 ? magnitude : 10;
257
+ return Math.ceil(value / step) * step;
258
+ }
259
+ function applyRadar(option, rows, categoryField, valueFields) {
260
+ const series = seriesOf(option);
261
+ if (!series.some(hasDataPlaceholder)) return;
262
+ const columnMax = valueFields.map((field2) => Math.max(0, ...rows.map((row) => rowValue(row, field2))));
263
+ option.radar = {
264
+ ...option.radar ?? {},
265
+ // 维度 = 数值字段;max 取该列最大值上浮取整
266
+ indicator: valueFields.map((field2, index) => ({ name: field2, max: niceMax(columnMax[index]) }))
267
+ };
268
+ option.series = series.map((item) => ({
269
+ ...item,
270
+ data: rows.map((row) => ({
271
+ name: categoryField ? String(row[categoryField] ?? "") : "",
272
+ value: valueFields.map((field2) => rowValue(row, field2))
273
+ }))
274
+ }));
275
+ }
276
+ function applyGauge(option, rows, valueField) {
277
+ const series = seriesOf(option);
278
+ if (!series.some(hasDataPlaceholder)) return;
279
+ const first = rows[0] ?? {};
280
+ option.series = series.map((item) => ({ ...item, data: [{ value: rowValue(first, valueField), name: valueField }] }));
281
+ }
282
+ function bindChartData(type, options, data) {
283
+ const raw = options.chartOption;
284
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
285
+ const option = evaluateChartOption(raw, data);
286
+ const valueFields = asFieldList(options.chartValueFields);
287
+ if (valueFields.length === 0) return { _chartOption: option };
288
+ const list = resolveListSource({ ...options, dataSource: options.chartDataSource ?? options.dataSource }, data);
289
+ if (list.length === 0) return { _chartOption: option };
290
+ const categoryField = asString(options.chartCategoryField);
291
+ const def = getChartKindDefinition(type);
292
+ switch (def?.seriesType) {
293
+ case "radar":
294
+ applyRadar(option, list, categoryField, valueFields);
295
+ break;
296
+ case "gauge":
297
+ applyGauge(option, list, valueFields[0]);
298
+ break;
299
+ case "funnel":
300
+ applyPieLike(option, list, categoryField, valueFields[0], true);
301
+ break;
302
+ case "pie":
303
+ applyPieLike(option, list, categoryField, valueFields[0], false);
304
+ break;
305
+ case "scatter":
306
+ applyScatter(option, list, categoryField, valueFields, options.chartBubble === true);
307
+ break;
308
+ default:
309
+ applyCartesian(option, list, categoryField, valueFields, asString(options.chartSeriesField));
310
+ break;
311
+ }
312
+ return { _chartOption: option };
313
+ }
314
+
315
+ // src/config.ts
316
+ import { configurePlugin, getPluginConfig } from "@worm-print-platform/core/designer";
317
+
318
+ // src/constants.ts
319
+ var CHART_PLUGIN_ID = "@worm-print-platform/echarts";
320
+ var FUNNEL_PADDING_DEFAULTS = { top: 6, right: 25, bottom: 6, left: 5 };
321
+ var RADAR_RADIUS_DEFAULT = 75;
322
+
323
+ // src/defaults.ts
324
+ var GRID = { left: "8%", right: "8%", bottom: "12%", top: "18%", containLabel: true };
325
+ function percentInsets(padding) {
326
+ return {
327
+ top: `${padding.top}%`,
328
+ right: `${padding.right}%`,
329
+ bottom: `${padding.bottom}%`,
330
+ left: `${padding.left}%`
331
+ };
332
+ }
333
+ function createDefaultChartOption(type) {
334
+ const def = getChartKindDefinition(type);
335
+ const title = { text: "" };
336
+ switch (def?.seriesType) {
337
+ case "pie":
338
+ return {
339
+ title,
340
+ tooltip: { trigger: "item" },
341
+ series: [{
342
+ type: "pie",
343
+ name: "\u6570\u91CF",
344
+ data: ["$data"],
345
+ radius: type === "doughnutChart" ? ["40%", "70%"] : "62%"
346
+ }]
347
+ };
348
+ case "scatter":
349
+ return {
350
+ title,
351
+ grid: GRID,
352
+ tooltip: { trigger: "axis" },
353
+ xAxis: { type: "value" },
354
+ yAxis: { type: "value" },
355
+ series: [{ type: "scatter", name: "\u6570\u91CF", data: ["$data"], symbolSize: 8 }]
356
+ };
357
+ case "radar":
358
+ return {
359
+ title,
360
+ tooltip: { trigger: "item" },
361
+ // indicator 由绑定阶段按 chartValueFields 生成;设计态预览见 previewChartOption
362
+ radar: { indicator: [], radius: `${RADAR_RADIUS_DEFAULT}%` },
363
+ series: [{ type: "radar", name: "\u6570\u91CF", data: ["$data"] }]
364
+ };
365
+ case "funnel":
366
+ return {
367
+ title,
368
+ tooltip: { trigger: "item" },
369
+ legend: { show: false },
370
+ // 不写内边距会吃 ECharts 的 px 默认(左右 80/上下 60~65),小框里图形只占一半不到
371
+ series: [{ type: "funnel", name: "\u6570\u91CF", data: ["$data"], sort: "descending", ...percentInsets(FUNNEL_PADDING_DEFAULTS) }]
372
+ };
373
+ case "gauge":
374
+ return {
375
+ title,
376
+ tooltip: { trigger: "item" },
377
+ series: [{ type: "gauge", name: "\u6570\u91CF", min: 0, max: 100, data: [{ value: 0, name: "\u6570\u91CF" }] }]
378
+ };
379
+ default: {
380
+ const horizontal = def?.orientation === "horizontal";
381
+ const isArea = def?.seriesType === "line" && type === "areaChart";
382
+ const seriesType = def?.seriesType === "line" ? "line" : "bar";
383
+ return {
384
+ title,
385
+ grid: GRID,
386
+ tooltip: { trigger: "axis" },
387
+ xAxis: horizontal ? { type: "value" } : { type: "category", data: ["$data"] },
388
+ yAxis: horizontal ? { type: "category", data: ["$data"] } : { type: "value" },
389
+ series: [{ type: seriesType, name: "\u6570\u91CF", data: ["$data"], ...isArea ? { areaStyle: {} } : {} }]
390
+ };
391
+ }
392
+ }
393
+ }
394
+
395
+ // src/config.ts
396
+ function getChartPluginConfig() {
397
+ return getPluginConfig(CHART_PLUGIN_ID);
398
+ }
399
+ function chartFactoryDefaults(type, partial) {
400
+ const config = getChartPluginConfig();
401
+ const def = getChartKindDefinition(type);
402
+ return {
403
+ width: typeof config.defaultWidth === "number" ? config.defaultWidth : def?.defaultWidth ?? 100,
404
+ height: typeof config.defaultHeight === "number" ? config.defaultHeight : def?.defaultHeight ?? 60,
405
+ title: def?.label ?? "\u56FE\u8868",
406
+ chartOption: createDefaultChartOption(type),
407
+ chartDataSource: "",
408
+ chartCategoryField: "name",
409
+ chartValueFields: ["value"],
410
+ chartSeriesField: "",
411
+ ...partial
412
+ };
413
+ }
414
+
415
+ // src/echarts.ts
416
+ import { BarChart, LineChart, PieChart, ScatterChart, RadarChart, FunnelChart, GaugeChart } from "echarts/charts";
417
+ import {
418
+ DatasetComponent,
419
+ GridComponent,
420
+ LegendComponent,
421
+ TitleComponent,
422
+ TooltipComponent
423
+ } from "echarts/components";
424
+ import * as echarts from "echarts/core";
425
+ import { SVGRenderer } from "echarts/renderers";
426
+ echarts.use([
427
+ BarChart,
428
+ LineChart,
429
+ PieChart,
430
+ ScatterChart,
431
+ RadarChart,
432
+ FunnelChart,
433
+ GaugeChart,
434
+ GridComponent,
435
+ TooltipComponent,
436
+ LegendComponent,
437
+ TitleComponent,
438
+ DatasetComponent,
439
+ SVGRenderer
440
+ ]);
441
+ var appliedComponents = /* @__PURE__ */ new Set();
442
+ function applyExtraComponents() {
443
+ const extra = getChartPluginConfig().components ?? [];
444
+ const fresh = extra.filter((item) => item != null && !appliedComponents.has(item));
445
+ if (fresh.length === 0) return;
446
+ echarts.use(fresh);
447
+ for (const item of fresh) appliedComponents.add(item);
448
+ }
449
+
450
+ // src/normalize.ts
451
+ function asArray(value) {
452
+ if (Array.isArray(value)) return value.map((item) => ({ ...item }));
453
+ return [];
454
+ }
455
+ function normalizeCategoryAxis(axis, horizontal) {
456
+ const next = { ...axis, type: horizontal ? "value" : "category" };
457
+ if (horizontal) delete next.data;
458
+ else if (!Array.isArray(next.data)) next.data = ["$data"];
459
+ return next;
460
+ }
461
+ function normalizeValueAxis(axis, horizontal) {
462
+ const next = { ...axis, type: horizontal ? "category" : "value" };
463
+ if (horizontal && !Array.isArray(next.data)) next.data = ["$data"];
464
+ if (!horizontal) delete next.data;
465
+ return next;
466
+ }
467
+ function mapAxes(value, fn) {
468
+ if (Array.isArray(value)) return value.map((item) => fn({ ...item }));
469
+ if (value && typeof value === "object") return fn({ ...value });
470
+ return fn({});
471
+ }
472
+ function normalizeChartOption(type, option) {
473
+ const def = getChartKindDefinition(type);
474
+ if (!def) return option;
475
+ const next = structuredClone(option);
476
+ const series = asArray(next.series);
477
+ if (series.length === 0) return next;
478
+ if (def.seriesType === "pie") {
479
+ next.series = series.map((item) => ({
480
+ ...item,
481
+ type: "pie",
482
+ ...type === "doughnutChart" ? { radius: item.radius ?? ["40%", "70%"] } : {}
483
+ }));
484
+ delete next.xAxis;
485
+ delete next.yAxis;
486
+ return next;
487
+ }
488
+ if (def.seriesType === "scatter") {
489
+ next.series = series.map((item) => ({ ...item, type: "scatter" }));
490
+ next.xAxis = mapAxes(next.xAxis, (axis) => ({ ...axis, type: "value", data: void 0 }));
491
+ next.yAxis = mapAxes(next.yAxis, (axis) => ({ ...axis, type: "value", data: void 0 }));
492
+ return next;
493
+ }
494
+ if (def.seriesType === "radar") {
495
+ next.series = series.map((item) => ({ ...item, type: "radar" }));
496
+ return next;
497
+ }
498
+ if (def.seriesType === "funnel") {
499
+ next.series = series.map((item) => ({ ...item, type: "funnel", sort: "descending" }));
500
+ return next;
501
+ }
502
+ if (def.seriesType === "gauge") {
503
+ next.series = series.map((item) => ({ ...item, type: "gauge" }));
504
+ return next;
505
+ }
506
+ const horizontal = def.orientation === "horizontal";
507
+ const seriesType = def.seriesType === "line" ? "line" : "bar";
508
+ next.xAxis = mapAxes(next.xAxis, (axis) => normalizeCategoryAxis(axis, horizontal));
509
+ next.yAxis = mapAxes(next.yAxis, (axis) => normalizeValueAxis(axis, horizontal));
510
+ next.series = series.map((item) => {
511
+ const shape = { ...item, type: seriesType };
512
+ if (type === "areaChart") shape.areaStyle = item.areaStyle ?? {};
513
+ else delete shape.areaStyle;
514
+ return shape;
515
+ });
516
+ return next;
517
+ }
518
+
519
+ // src/units.ts
520
+ var PX_PER_MM = 96 / 25.4;
521
+ function mmToChartPx(mm) {
522
+ const value = Number.isFinite(mm) ? mm : 0;
523
+ return Math.max(1, Math.round(value * PX_PER_MM));
524
+ }
525
+
526
+ // src/renderer.ts
527
+ function fitSvgRoot(svg, widthPx, heightPx) {
528
+ const match = /<svg\b[^>]*>/i.exec(svg);
529
+ if (!match) return svg;
530
+ const rootTag = match[0];
531
+ const rawAttrs = rootTag.slice("<svg".length, -1);
532
+ const styleMatch = /\sstyle\s*=\s*"([^"]*)"/i.exec(rawAttrs);
533
+ const keptStyle = (styleMatch?.[1] ?? "").split(";").map((decl) => decl.trim()).filter((decl) => decl && !/^(width|height|display)\s*:/i.test(decl)).join(";");
534
+ const attrs = rawAttrs.replace(/\s(width|height|style|viewBox)\s*=\s*"[^"]*"/gi, "").trimEnd();
535
+ const style = ["display:block", "width:100%", "height:100%", keptStyle].filter(Boolean).join(";");
536
+ const nextTag = `<svg${attrs} width="100%" height="100%" viewBox="0 0 ${widthPx} ${heightPx}" style="${style}">`;
537
+ return svg.slice(0, match.index) + nextTag + svg.slice(match.index + rootTag.length);
538
+ }
539
+ function renderChartToSvg(spec) {
540
+ applyExtraComponents();
541
+ const option = normalizeChartOption(spec.type, spec.option);
542
+ if (!option || typeof option !== "object" || Array.isArray(option)) {
543
+ throw new Error("\u56FE\u8868 option \u975E\u6CD5\uFF1A\u9700\u8981\u5BF9\u8C61");
544
+ }
545
+ const width = mmToChartPx(spec.widthMm);
546
+ const height = mmToChartPx(spec.heightMm);
547
+ const chart = echarts.init(null, null, { renderer: "svg", ssr: true, width, height });
548
+ try {
549
+ const userTextStyle = option.textStyle && typeof option.textStyle === "object" && !Array.isArray(option.textStyle) ? option.textStyle : void 0;
550
+ const textStyle = {
551
+ ...spec.fontFamily ? { fontFamily: spec.fontFamily } : {},
552
+ ...userTextStyle ?? {}
553
+ };
554
+ chart.setOption({
555
+ animation: false,
556
+ ...option,
557
+ ...Object.keys(textStyle).length > 0 ? { textStyle } : {}
558
+ });
559
+ return fitSvgRoot(chart.renderToSVGString(), width, height);
560
+ } finally {
561
+ chart.dispose();
562
+ }
563
+ }
564
+ function escapeHtml(value) {
565
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
566
+ }
567
+ function renderChartElement(spec) {
568
+ const option = spec._chartOption ?? spec.chartOption;
569
+ const placeholder = `<span>${escapeHtml(String(spec.title ?? "\u56FE\u8868"))}</span>`;
570
+ if (!option || typeof option !== "object" || Array.isArray(option)) return placeholder;
571
+ try {
572
+ return renderChartToSvg({
573
+ key: String(spec.key ?? ""),
574
+ type: String(spec.type ?? ""),
575
+ option,
576
+ widthMm: Number(spec.widthMm ?? 0),
577
+ heightMm: Number(spec.heightMm ?? 0),
578
+ fontFamily: typeof spec.fontFamily === "string" ? spec.fontFamily : void 0
579
+ });
580
+ } catch {
581
+ return placeholder;
582
+ }
583
+ }
584
+
585
+ // src/version.ts
586
+ var CHART_EXECUTOR_VERSION = "2";
587
+
588
+ // src/plugin.ts
589
+ var CHART_OPTION_META = {
590
+ chartOption: { kind: "object", label: "\u56FE\u8868 option" },
591
+ chartDataSource: { kind: "text", label: "\u6570\u636E\u6E90" },
592
+ chartCategoryField: { kind: "text", label: "\u7C7B\u76EE\u5B57\u6BB5" },
593
+ chartValueFields: { kind: "object", label: "\u6570\u503C\u5B57\u6BB5" },
594
+ chartSeriesField: { kind: "text", label: "\u7CFB\u5217\u62C6\u5206\u5B57\u6BB5" }
595
+ };
596
+ var SCATTER_OPTION_META = {
597
+ ...CHART_OPTION_META,
598
+ chartBubble: { kind: "bool", label: "\u6C14\u6CE1\u5927\u5C0F" }
599
+ };
600
+ var CHART_PLUGIN = defineElementPlugin({
601
+ id: CHART_PLUGIN_ID,
602
+ version: CHART_EXECUTOR_VERSION,
603
+ kinds: CHART_KIND_DEFINITIONS.map((def) => ({
604
+ type: def.type,
605
+ label: def.label,
606
+ icon: def.icon,
607
+ fixedHeight: true,
608
+ requiredOptionKeys: def.requiredOptionKeys,
609
+ notes: def.notes,
610
+ optionMeta: def.type === "scatterChart" ? SCATTER_OPTION_META : CHART_OPTION_META,
611
+ defaultOptions: (partial) => chartFactoryDefaults(def.type, partial),
612
+ binding: { bind: (options, data) => bindChartData(def.type, options, data) }
613
+ })),
614
+ render: {
615
+ html: renderChartElement,
616
+ createRenderer: () => ({ render: renderChartElement })
617
+ }
618
+ });
619
+ var disposeHandle;
620
+ function registerChartPlugin(designer, extraRender) {
621
+ const current = getElementPluginById(CHART_PLUGIN_ID);
622
+ if (!designer && !extraRender) {
623
+ const dispose2 = registerElementPlugin(CHART_PLUGIN);
624
+ disposeHandle = dispose2;
625
+ return dispose2;
626
+ }
627
+ const merged = {
628
+ ...CHART_PLUGIN,
629
+ designer: designer ?? current?.designer ?? CHART_PLUGIN.designer,
630
+ render: { ...CHART_PLUGIN.render, ...current?.render, ...extraRender }
631
+ };
632
+ const dispose = registerElementPlugin(merged);
633
+ disposeHandle = dispose;
634
+ return dispose;
635
+ }
636
+ registerChartPlugin();
637
+
638
+ // src/index.ts
639
+ registerChartPlugin();
640
+
641
+ // src/ui.ts
642
+ import { defineElementUI, registerElementUI } from "@worm-print-platform/plugin-kit";
643
+ import {
644
+ asObject,
645
+ CHART_KINDS as CHART_KINDS2,
646
+ cloneChartOption,
647
+ createDefaultChartOption as createDefaultChartOption2,
648
+ FUNNEL_PADDING_DEFAULTS as FUNNEL_PADDING_DEFAULTS2,
649
+ getChartKindDefinition as getChartKindDefinition2,
650
+ getChartPalettes as getChartPalettes2,
651
+ normalizeChartOption as normalizeChartOption2,
652
+ previewChartOption,
653
+ RADAR_RADIUS_DEFAULT as RADAR_RADIUS_DEFAULT2,
654
+ readFunnelPadding,
655
+ readPaletteKey,
656
+ readRadarRadius,
657
+ renderChartToSvg as renderChartToSvg2,
658
+ resolveChartPanelFields as resolveChartPanelFields2,
659
+ syncSeriesCount,
660
+ writeFunnelPadding,
661
+ writeRadarRadius
662
+ } from "@worm-print-platform/echarts/kit";
663
+ var CANVAS_STYLE = "width:100%;height:100%;min-width:0;min-height:0;pointer-events:none";
664
+ var STYLES = [
665
+ ".echarts-canvas-element{overflow:hidden}",
666
+ ".echarts-field-row{display:flex;gap:6px;align-items:center}",
667
+ ".echarts-field-row>.pd-input{flex:1;min-width:0}",
668
+ ".echarts-field-row>.pd-button{flex:none}"
669
+ ].join("");
670
+ var CHART_OPTION_KEYS = [
671
+ "chartOption",
672
+ "chartDataSource",
673
+ "chartCategoryField",
674
+ "chartValueFields",
675
+ "chartSeriesField",
676
+ "chartBubble"
677
+ ];
678
+ var SEARCH_KEYWORDS = [
679
+ "\u56FE\u8868",
680
+ "echarts",
681
+ "option",
682
+ "\u914D\u7F6E",
683
+ "\u6570\u636E\u6E90",
684
+ "\u7C7B\u76EE",
685
+ "\u6570\u503C",
686
+ "\u7CFB\u5217",
687
+ "\u67F1\u72B6",
688
+ "\u6761\u5F62",
689
+ "\u6298\u7EBF",
690
+ "\u9762\u79EF",
691
+ "\u997C",
692
+ "\u73AF\u5F62",
693
+ "\u6563\u70B9",
694
+ "\u96F7\u8FBE",
695
+ "\u6F0F\u6597",
696
+ "\u4EEA\u8868"
697
+ ];
698
+ 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";
699
+ var datalistSeq = 0;
700
+ function escapeHtml2(value) {
701
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
702
+ }
703
+ function elementType(element) {
704
+ return element.printElementType?.type ?? "";
705
+ }
706
+ function rawChartOption(element) {
707
+ const raw = element.options.chartOption;
708
+ return raw && typeof raw === "object" && !Array.isArray(raw) ? raw : void 0;
709
+ }
710
+ function panelOption(element) {
711
+ const raw = rawChartOption(element);
712
+ return cloneChartOption(raw ?? createDefaultChartOption2(elementType(element)));
713
+ }
714
+ function chartHasProperties(element) {
715
+ const options = element?.options;
716
+ if (!options || typeof options !== "object") return false;
717
+ const record = options;
718
+ return CHART_OPTION_KEYS.some((key) => record[key] !== void 0);
719
+ }
720
+ function commitOption(ctx, type, next, patch = {}) {
721
+ ctx.update({ chartOption: normalizeChartOption2(type, next), ...patch });
722
+ }
723
+ function readValueFields(element) {
724
+ const raw = element.options.chartValueFields;
725
+ return Array.isArray(raw) ? raw.map(String) : [];
726
+ }
727
+ function maxValueFields(def) {
728
+ switch (def?.seriesType) {
729
+ case "pie":
730
+ case "funnel":
731
+ case "gauge":
732
+ return 1;
733
+ case "scatter":
734
+ return 2;
735
+ default:
736
+ return 8;
737
+ }
738
+ }
739
+ function valueFieldsLabel(def, limit) {
740
+ if (def?.seriesType === "radar") return "\u7EF4\u5EA6\u5B57\u6BB5\uFF08\u6BCF\u4E2A\u5B57\u6BB5\u4E00\u4E2A\u7EF4\u5EA6\uFF09";
741
+ return limit === 1 ? "\u6570\u503C\u5B57\u6BB5" : "\u6570\u503C\u5B57\u6BB5\uFF08\u591A\u503C\u591A\u7CFB\u5217\uFF09";
742
+ }
743
+ function dataSourceCandidates(data) {
744
+ const first = data?.[0];
745
+ if (!first) return [];
746
+ return Object.keys(first).filter((key) => Array.isArray(first[key]));
747
+ }
748
+ function seriesList(option) {
749
+ return Array.isArray(option.series) ? option.series : [];
750
+ }
751
+ function clamp(value, min, max) {
752
+ return Math.min(max, Math.max(min, value));
753
+ }
754
+ function syncValueFields(ctx, type, nextFields) {
755
+ const next = syncSeriesCount(panelOption(ctx.element), nextFields.length, type);
756
+ const series = Array.isArray(next.series) ? next.series : [];
757
+ series.forEach((item, index) => {
758
+ const name = nextFields[index]?.trim();
759
+ if (name) item.name = name;
760
+ });
761
+ commitOption(ctx, type, next, { chartValueFields: nextFields });
762
+ }
763
+ function renderCanvas(ctx) {
764
+ const element = ctx.element;
765
+ const type = elementType(element);
766
+ const options = element.options;
767
+ const widthMm = Number(options.width) || 0;
768
+ const heightMm = Number(options.height) || 0;
769
+ try {
770
+ const preview = previewChartOption(type, rawChartOption(element) ?? createDefaultChartOption2(type));
771
+ const option = normalizeChartOption2(type, preview);
772
+ if (!option || typeof option !== "object" || Array.isArray(option)) throw new Error("\u56FE\u8868 option \u975E\u6CD5\uFF1A\u9700\u8981\u5BF9\u8C61");
773
+ const fontFamily = typeof options.fontFamily === "string" && options.fontFamily ? options.fontFamily : void 0;
774
+ const svg = renderChartToSvg2({ key: element.id, type, option, widthMm, heightMm, fontFamily });
775
+ return `<div class="echarts-canvas-element" style="${CANVAS_STYLE}">${svg}</div>`;
776
+ } catch {
777
+ const title = typeof options.title === "string" && options.title.trim() ? options.title : getChartKindDefinition2(type)?.label ?? "\u56FE\u8868";
778
+ return `<div class="echarts-canvas-element" style="${CANVAS_STYLE}">${escapeHtml2(title)}</div>`;
779
+ }
780
+ }
781
+ function el(tag, className, text) {
782
+ const node = document.createElement(tag);
783
+ if (className) node.className = className;
784
+ if (text !== void 0) node.textContent = text;
785
+ return node;
786
+ }
787
+ function field(labelText) {
788
+ const wrap = el("div", "pd-field");
789
+ wrap.appendChild(el("span", "pd-label", labelText));
790
+ return wrap;
791
+ }
792
+ function textInput(init, onCommit) {
793
+ const input = el("input", "pd-input");
794
+ if (init.type) input.type = init.type;
795
+ if (init.placeholder) input.placeholder = init.placeholder;
796
+ if (init.min !== void 0) input.min = String(init.min);
797
+ if (init.max !== void 0) input.max = String(init.max);
798
+ if (init.title) input.title = init.title;
799
+ if (init.list) input.setAttribute("list", init.list);
800
+ input.value = init.value;
801
+ input.addEventListener("change", () => onCommit(input.value));
802
+ return input;
803
+ }
804
+ function checkboxField(labelText, checked, onCommit) {
805
+ const wrap = field(labelText);
806
+ wrap.style.cssText = "flex-direction:row;align-items:center;justify-content:space-between";
807
+ const input = el("input", "pd-switch");
808
+ input.type = "checkbox";
809
+ input.checked = checked;
810
+ input.addEventListener("change", () => onCommit(input.checked));
811
+ wrap.appendChild(input);
812
+ return wrap;
813
+ }
814
+ function renderProperty(ctx) {
815
+ const element = ctx.element;
816
+ const type = elementType(element);
817
+ const def = getChartKindDefinition2(type);
818
+ const fields = resolveChartPanelFields2(type);
819
+ const has = (key) => fields.includes(key);
820
+ const options = element.options;
821
+ const widthMm = Number(options.width) || 0;
822
+ const heightMm = Number(options.height) || 0;
823
+ const limit = maxValueFields(def);
824
+ const palettes = getChartPalettes2();
825
+ const root = el("div", "echarts-property");
826
+ const form = el("form", "pd-form");
827
+ form.addEventListener("submit", (event) => event.preventDefault());
828
+ root.appendChild(form);
829
+ if (has("dataSource")) {
830
+ const wrap = field("\u6570\u636E\u6E90");
831
+ const candidates = dataSourceCandidates(ctx.data);
832
+ let datalist;
833
+ if (candidates.length > 0) {
834
+ datalist = el("datalist");
835
+ datalist.id = `echarts-ds-${++datalistSeq}`;
836
+ for (const key of candidates) {
837
+ const optionEl = el("option");
838
+ optionEl.value = key;
839
+ datalist.appendChild(optionEl);
840
+ }
841
+ }
842
+ wrap.appendChild(
843
+ textInput(
844
+ {
845
+ value: String(options.chartDataSource ?? ""),
846
+ placeholder: "\u6570\u636E\u96C6\u8DEF\u5F84\uFF08\u7559\u7A7A\u53D6\u9876\u5C42\u7B2C\u4E00\u4E2A\u6570\u7EC4\uFF09",
847
+ list: datalist?.id
848
+ },
849
+ (value) => commitOption(ctx, type, panelOption(element), { chartDataSource: value })
850
+ )
851
+ );
852
+ if (datalist) wrap.appendChild(datalist);
853
+ form.appendChild(wrap);
854
+ }
855
+ if (has("categoryField")) {
856
+ const wrap = field("\u7C7B\u76EE\u5B57\u6BB5");
857
+ wrap.appendChild(
858
+ textInput(
859
+ { value: String(options.chartCategoryField ?? ""), placeholder: "\u5982 name" },
860
+ (value) => commitOption(ctx, type, panelOption(element), { chartCategoryField: value })
861
+ )
862
+ );
863
+ form.appendChild(wrap);
864
+ }
865
+ if (has("valueFields")) {
866
+ const wrap = field(valueFieldsLabel(def, limit));
867
+ const fieldsNow = readValueFields(element);
868
+ fieldsNow.forEach((value, index) => {
869
+ const row = el("div", "echarts-field-row");
870
+ row.appendChild(
871
+ textInput(
872
+ { value, placeholder: "\u5982 value" },
873
+ (next) => {
874
+ const list = readValueFields(element);
875
+ list[index] = next;
876
+ syncValueFields(ctx, type, list);
877
+ }
878
+ )
879
+ );
880
+ if (fieldsNow.length > 1) {
881
+ const remove = el("button", "pd-button small", "\u2212");
882
+ remove.type = "button";
883
+ remove.title = "\u5220\u9664\u8BE5\u5B57\u6BB5";
884
+ remove.addEventListener("click", () => syncValueFields(ctx, type, readValueFields(element).filter((_, i) => i !== index)));
885
+ row.appendChild(remove);
886
+ }
887
+ wrap.appendChild(row);
888
+ });
889
+ if (fieldsNow.length < limit) {
890
+ const add = el("button", "pd-button small", "+ \u6DFB\u52A0\u5B57\u6BB5");
891
+ add.type = "button";
892
+ add.addEventListener("click", () => syncValueFields(ctx, type, [...readValueFields(element), ""]));
893
+ wrap.appendChild(add);
894
+ }
895
+ form.appendChild(wrap);
896
+ }
897
+ if (has("seriesField")) {
898
+ const wrap = field("\u7CFB\u5217\u62C6\u5206\u5B57\u6BB5");
899
+ wrap.appendChild(
900
+ textInput(
901
+ { value: String(options.chartSeriesField ?? ""), placeholder: "\u53EF\u9009\uFF0C\u5982 region\uFF08\u6309\u503C\u62C6\u6210\u591A\u7CFB\u5217\uFF09" },
902
+ (value) => commitOption(ctx, type, panelOption(element), { chartSeriesField: value })
903
+ )
904
+ );
905
+ form.appendChild(wrap);
906
+ }
907
+ if (has("bubble")) {
908
+ form.appendChild(
909
+ checkboxField("\u6C14\u6CE1\u5927\u5C0F", options.chartBubble === true, (checked) => {
910
+ commitOption(ctx, type, panelOption(element), { chartBubble: checked });
911
+ })
912
+ );
913
+ }
914
+ if (has("title")) {
915
+ const wrap = field("\u56FE\u8868\u6807\u9898");
916
+ wrap.appendChild(
917
+ textInput(
918
+ { value: String(asObject(panelOption(element).title).text ?? ""), placeholder: "\u7559\u7A7A\u4E0D\u663E\u793A\u6807\u9898" },
919
+ (value) => {
920
+ const next = panelOption(element);
921
+ next.title = { ...asObject(next.title), text: value };
922
+ commitOption(ctx, type, next);
923
+ }
924
+ )
925
+ );
926
+ form.appendChild(wrap);
927
+ }
928
+ if (has("legend")) {
929
+ const show = asObject(panelOption(element).legend).show !== false;
930
+ form.appendChild(
931
+ checkboxField("\u663E\u793A\u56FE\u4F8B", show, (checked) => {
932
+ const next = panelOption(element);
933
+ next.legend = { ...asObject(next.legend), show: checked };
934
+ commitOption(ctx, type, next);
935
+ })
936
+ );
937
+ }
938
+ if (has("palette")) {
939
+ const wrap = field("\u914D\u8272");
940
+ const select = el("select", "pd-select");
941
+ for (const palette of palettes) {
942
+ const optionEl = el("option");
943
+ optionEl.value = palette.key;
944
+ optionEl.textContent = palette.label;
945
+ select.appendChild(optionEl);
946
+ }
947
+ select.value = readPaletteKey(panelOption(element), palettes);
948
+ select.addEventListener("change", () => {
949
+ const palette = palettes.find((item) => item.key === select.value) ?? palettes[0];
950
+ const next = panelOption(element);
951
+ next.color = [...palette.colors];
952
+ commitOption(ctx, type, next);
953
+ });
954
+ wrap.appendChild(select);
955
+ form.appendChild(wrap);
956
+ }
957
+ if (has("stack")) {
958
+ const series = seriesList(panelOption(element));
959
+ const stacked = series.some((item) => item.stack !== void 0 && item.stack !== null && item.stack !== "");
960
+ form.appendChild(
961
+ checkboxField("\u5806\u53E0\u663E\u793A", stacked, (checked) => {
962
+ const next = panelOption(element);
963
+ for (const item of seriesList(next)) {
964
+ if (checked) item.stack = "total";
965
+ else delete item.stack;
966
+ }
967
+ commitOption(ctx, type, next);
968
+ })
969
+ );
970
+ }
971
+ if (has("innerRadius")) {
972
+ const wrap = field("\u5185\u5F84\uFF08%\uFF09");
973
+ const radius = seriesList(panelOption(element))[0]?.radius;
974
+ const inner = Array.isArray(radius) ? Number(String(radius[0] ?? "40%").replace("%", "")) || 40 : 40;
975
+ wrap.appendChild(
976
+ textInput({ value: String(inner), type: "number", min: 0, max: 90 }, (value) => {
977
+ const next = panelOption(element);
978
+ const series = seriesList(next);
979
+ if (series[0]) series[0].radius = [`${clamp(Number(value) || 0, 0, 90)}%`, "70%"];
980
+ commitOption(ctx, type, next);
981
+ })
982
+ );
983
+ form.appendChild(wrap);
984
+ }
985
+ if (has("padding")) {
986
+ const wrap = field("\u5185\u8FB9\u8DDD \u4E0A/\u53F3/\u4E0B/\u5DE6 (%)");
987
+ const padding = readFunnelPadding(panelOption(element), widthMm, heightMm);
988
+ const row = el("div", "echarts-field-row");
989
+ const sides = [
990
+ { side: "top", title: "\u4E0A\u8FB9\u8DDD" },
991
+ { side: "right", title: "\u53F3\u8FB9\u8DDD\uFF08\u7559\u5916\u7F6E\u6807\u7B7E\uFF09" },
992
+ { side: "bottom", title: "\u4E0B\u8FB9\u8DDD" },
993
+ { side: "left", title: "\u5DE6\u8FB9\u8DDD" }
994
+ ];
995
+ for (const { side, title } of sides) {
996
+ row.appendChild(
997
+ textInput({ value: String(padding[side]), type: "number", min: 0, max: 60, title }, (value) => {
998
+ const raw = Number(value);
999
+ const next = Number.isFinite(raw) ? clamp(raw, 0, 60) : FUNNEL_PADDING_DEFAULTS2[side];
1000
+ const option = panelOption(element);
1001
+ const current = readFunnelPadding(option, widthMm, heightMm);
1002
+ commitOption(ctx, type, writeFunnelPadding(option, { ...current, [side]: next }));
1003
+ })
1004
+ );
1005
+ }
1006
+ wrap.appendChild(row);
1007
+ form.appendChild(wrap);
1008
+ }
1009
+ if (has("radius")) {
1010
+ const wrap = field("\u534A\u5F84\uFF08%\uFF09");
1011
+ wrap.appendChild(
1012
+ textInput(
1013
+ { value: String(readRadarRadius(panelOption(element), widthMm, heightMm)), type: "number", min: 20, max: 100 },
1014
+ (value) => {
1015
+ const raw = Number(value);
1016
+ const next = Number.isFinite(raw) ? clamp(raw, 20, 100) : RADAR_RADIUS_DEFAULT2;
1017
+ commitOption(ctx, type, writeRadarRadius(panelOption(element), next));
1018
+ }
1019
+ )
1020
+ );
1021
+ form.appendChild(wrap);
1022
+ }
1023
+ if (has("gaugeRange")) {
1024
+ const wrap = field("\u6700\u5C0F / \u6700\u5927\u503C");
1025
+ const series = seriesList(panelOption(element));
1026
+ const row = el("div", "echarts-field-row");
1027
+ row.appendChild(
1028
+ textInput({ value: String(Number(series[0]?.min ?? 0)), type: "number" }, (value) => {
1029
+ const next = panelOption(element);
1030
+ const list = seriesList(next);
1031
+ if (list[0]) list[0].min = Number(value) || 0;
1032
+ commitOption(ctx, type, next);
1033
+ })
1034
+ );
1035
+ row.appendChild(
1036
+ textInput({ value: String(Number(series[0]?.max ?? 100)), type: "number" }, (value) => {
1037
+ const next = panelOption(element);
1038
+ const list = seriesList(next);
1039
+ if (list[0]) list[0].max = Number(value) || 100;
1040
+ commitOption(ctx, type, next);
1041
+ })
1042
+ );
1043
+ wrap.appendChild(row);
1044
+ form.appendChild(wrap);
1045
+ }
1046
+ form.appendChild(el("p", "pd-hint", PANEL_HINT));
1047
+ return root;
1048
+ }
1049
+ var CHART_ELEMENT_UI = defineElementUI({
1050
+ types: CHART_KINDS2,
1051
+ renderCanvas,
1052
+ renderProperty,
1053
+ hasProperties: chartHasProperties,
1054
+ group: "\u56FE\u8868",
1055
+ searchKeywords: SEARCH_KEYWORDS,
1056
+ styles: STYLES
1057
+ });
1058
+ var disposeHandle2;
1059
+ function installChartCommonUI() {
1060
+ disposeHandle2?.();
1061
+ disposeHandle2 = registerElementUI(CHART_ELEMENT_UI);
1062
+ return disposeHandle2;
1063
+ }
1064
+ installChartCommonUI();