@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.
@@ -1,5 +1,5 @@
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
@@ -23,7 +23,7 @@ var CHART_KIND_DEFINITIONS = [
23
23
  icon: "ChartColumn",
24
24
  seriesType: "bar",
25
25
  orientation: "vertical",
26
- fields: [...DATA_FIELDS, ...STYLE_FIELDS, "stack"],
26
+ fields: [...DATA_FIELDS, ...STYLE_FIELDS, "stack", "label"],
27
27
  requiredOptionKeys: BASE_REQUIRED,
28
28
  defaultWidth: 100,
29
29
  defaultHeight: 60,
@@ -35,7 +35,7 @@ var CHART_KIND_DEFINITIONS = [
35
35
  icon: "ChartBar",
36
36
  seriesType: "bar",
37
37
  orientation: "horizontal",
38
- fields: [...DATA_FIELDS, ...STYLE_FIELDS, "stack"],
38
+ fields: [...DATA_FIELDS, ...STYLE_FIELDS, "stack", "label"],
39
39
  requiredOptionKeys: BASE_REQUIRED,
40
40
  defaultWidth: 100,
41
41
  defaultHeight: 60,
@@ -46,7 +46,7 @@ var CHART_KIND_DEFINITIONS = [
46
46
  label: "\u6298\u7EBF\u56FE",
47
47
  icon: "ChartLine",
48
48
  seriesType: "line",
49
- fields: [...DATA_FIELDS, ...STYLE_FIELDS, "stack"],
49
+ fields: [...DATA_FIELDS, ...STYLE_FIELDS, "stack", "label"],
50
50
  requiredOptionKeys: BASE_REQUIRED,
51
51
  defaultWidth: 100,
52
52
  defaultHeight: 60,
@@ -57,7 +57,7 @@ var CHART_KIND_DEFINITIONS = [
57
57
  label: "\u9762\u79EF\u56FE",
58
58
  icon: "ChartArea",
59
59
  seriesType: "line",
60
- fields: [...DATA_FIELDS, ...STYLE_FIELDS, "stack"],
60
+ fields: [...DATA_FIELDS, ...STYLE_FIELDS, "stack", "label"],
61
61
  requiredOptionKeys: BASE_REQUIRED,
62
62
  defaultWidth: 100,
63
63
  defaultHeight: 60,
@@ -68,7 +68,7 @@ var CHART_KIND_DEFINITIONS = [
68
68
  label: "\u997C\u56FE",
69
69
  icon: "ChartPie",
70
70
  seriesType: "pie",
71
- fields: ["dataSource", "categoryField", "valueFields", ...STYLE_FIELDS],
71
+ fields: ["dataSource", "categoryField", "valueFields", ...STYLE_FIELDS, "label"],
72
72
  requiredOptionKeys: BASE_REQUIRED,
73
73
  defaultWidth: 60,
74
74
  defaultHeight: 60,
@@ -79,7 +79,7 @@ var CHART_KIND_DEFINITIONS = [
79
79
  label: "\u73AF\u5F62\u56FE",
80
80
  icon: "Donut",
81
81
  seriesType: "pie",
82
- fields: ["dataSource", "categoryField", "valueFields", ...STYLE_FIELDS, "innerRadius"],
82
+ fields: ["dataSource", "categoryField", "valueFields", ...STYLE_FIELDS, "innerRadius", "label"],
83
83
  requiredOptionKeys: BASE_REQUIRED,
84
84
  defaultWidth: 60,
85
85
  defaultHeight: 60,
@@ -90,7 +90,7 @@ var CHART_KIND_DEFINITIONS = [
90
90
  label: "\u6563\u70B9\u56FE",
91
91
  icon: "ChartScatter",
92
92
  seriesType: "scatter",
93
- fields: ["dataSource", "categoryField", "valueFields", ...STYLE_FIELDS, "bubble"],
93
+ fields: ["dataSource", "categoryField", "valueFields", ...STYLE_FIELDS, "bubble", "label"],
94
94
  requiredOptionKeys: BASE_REQUIRED,
95
95
  defaultWidth: 80,
96
96
  defaultHeight: 60,
@@ -101,7 +101,7 @@ var CHART_KIND_DEFINITIONS = [
101
101
  label: "\u96F7\u8FBE\u56FE",
102
102
  icon: "Radar",
103
103
  seriesType: "radar",
104
- fields: ["dataSource", "categoryField", "valueFields", ...STYLE_FIELDS, "radius"],
104
+ fields: ["dataSource", "categoryField", "valueFields", ...STYLE_FIELDS, "radius", "label"],
105
105
  requiredOptionKeys: BASE_REQUIRED,
106
106
  defaultWidth: 70,
107
107
  defaultHeight: 60,
@@ -112,7 +112,7 @@ var CHART_KIND_DEFINITIONS = [
112
112
  label: "\u6F0F\u6597\u56FE",
113
113
  icon: "Funnel",
114
114
  seriesType: "funnel",
115
- fields: ["dataSource", "categoryField", "valueFields", ...STYLE_FIELDS, "padding"],
115
+ fields: ["dataSource", "categoryField", "valueFields", ...STYLE_FIELDS, "padding", "label"],
116
116
  requiredOptionKeys: BASE_REQUIRED,
117
117
  defaultWidth: 60,
118
118
  defaultHeight: 60,
@@ -123,7 +123,7 @@ var CHART_KIND_DEFINITIONS = [
123
123
  label: "\u4EEA\u8868\u76D8",
124
124
  icon: "Gauge",
125
125
  seriesType: "gauge",
126
- fields: ["dataSource", "valueFields", ...STYLE_FIELDS, "gaugeRange"],
126
+ fields: ["dataSource", "valueFields", ...STYLE_FIELDS, "gaugeRange", "label"],
127
127
  requiredOptionKeys: BASE_REQUIRED,
128
128
  defaultWidth: 60,
129
129
  defaultHeight: 60,
@@ -134,6 +134,9 @@ var CHART_KINDS = CHART_KIND_DEFINITIONS.map((def) => def.type);
134
134
  function getChartKindDefinition(type) {
135
135
  return CHART_KIND_DEFINITIONS.find((def) => def.type === type);
136
136
  }
137
+ function resolveChartPanelFields(type) {
138
+ return getChartKindDefinition(type)?.fields ?? [];
139
+ }
137
140
 
138
141
  // src/bind.ts
139
142
  import { evaluateTemplate } from "@worm-print-platform/core";
@@ -141,16 +144,18 @@ function chartNumber(value) {
141
144
  const n = typeof value === "number" ? value : Number(value);
142
145
  return Number.isFinite(n) ? n : 0;
143
146
  }
144
- function evaluateChartOption(node, data) {
147
+ function evaluateChartOption(node, data, keepStrings = false) {
145
148
  if (typeof node === "string") {
146
149
  if (node.startsWith("$data")) return node;
150
+ if (keepStrings) return node;
147
151
  return node.includes("{") ? evaluateTemplate(node, data) : node;
148
152
  }
149
- if (Array.isArray(node)) return node.map((item) => evaluateChartOption(item, data));
153
+ if (Array.isArray(node)) return node.map((item) => evaluateChartOption(item, data, keepStrings));
150
154
  if (node && typeof node === "object") {
151
155
  const out = {};
152
156
  for (const [key, value] of Object.entries(node)) {
153
- out[key] = evaluateChartOption(value, data);
157
+ const childKeep = keepStrings || key === "label" || key === "detail";
158
+ out[key] = evaluateChartOption(value, data, childKeep);
154
159
  }
155
160
  return out;
156
161
  }
@@ -317,8 +322,17 @@ import { configurePlugin, getPluginConfig } from "@worm-print-platform/core/desi
317
322
 
318
323
  // src/constants.ts
319
324
  var CHART_PLUGIN_ID = "@worm-print-platform/echarts";
325
+ var CHART_PALETTES = [
326
+ { key: "default", label: "\u9ED8\u8BA4\u84DD", colors: ["#5470c6", "#91cc75", "#fac858", "#ee6666", "#73c0de"] },
327
+ { key: "fresh", label: "\u6E05\u65B0\u7EFF", colors: ["#2f9e6e", "#5cc9a7", "#9ad6c1", "#f2c94c", "#4a90e2"] },
328
+ { key: "warm", label: "\u6696\u6A59\u7EA2", colors: ["#f2704e", "#f7a35c", "#f7d56d", "#c54e3f", "#8f5a4a"] },
329
+ { key: "purple", label: "\u7D2B\u7070", colors: ["#7b61ff", "#9b8cff", "#c3baff", "#596275", "#8d99ae"] }
330
+ ];
331
+ var FALLBACK_SAMPLE_CATEGORIES = ["\u793A\u4F8B\u4E00", "\u793A\u4F8B\u4E8C", "\u793A\u4F8B\u4E09"];
320
332
  var FUNNEL_PADDING_DEFAULTS = { top: 6, right: 25, bottom: 6, left: 5 };
321
333
  var RADAR_RADIUS_DEFAULT = 75;
334
+ var ECHARTS_RADAR_RADIUS_DEFAULT = 50;
335
+ var ECHARTS_FUNNEL_PADDING_PX = { top: 60, right: 80, bottom: 65, left: 80 };
322
336
 
323
337
  // src/defaults.ts
324
338
  var GRID = { left: "8%", right: "8%", bottom: "12%", top: "18%", containLabel: true };
@@ -396,6 +410,19 @@ function createDefaultChartOption(type) {
396
410
  function getChartPluginConfig() {
397
411
  return getPluginConfig(CHART_PLUGIN_ID);
398
412
  }
413
+ function getChartPalettes() {
414
+ const overrides = getChartPluginConfig().palettes ?? {};
415
+ const builtin = CHART_PALETTES.map((palette) => {
416
+ const custom = overrides[palette.key];
417
+ return custom ? { key: palette.key, label: custom.label ?? palette.label, colors: custom.colors } : { key: palette.key, label: palette.label, colors: palette.colors };
418
+ });
419
+ 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 }));
420
+ return [...builtin, ...extra];
421
+ }
422
+ function getSampleCategories() {
423
+ const custom = getChartPluginConfig().sampleCategories;
424
+ return Array.isArray(custom) && custom.length > 0 ? custom : FALLBACK_SAMPLE_CATEGORIES;
425
+ }
399
426
  function chartFactoryDefaults(type, partial) {
400
427
  const config = getChartPluginConfig();
401
428
  const def = getChartKindDefinition(type);
@@ -447,6 +474,416 @@ function applyExtraComponents() {
447
474
  for (const item of fresh) appliedComponents.add(item);
448
475
  }
449
476
 
477
+ // src/units.ts
478
+ var PX_PER_MM = 96 / 25.4;
479
+ function mmToChartPx(mm) {
480
+ const value = Number.isFinite(mm) ? mm : 0;
481
+ return Math.max(1, Math.round(value * PX_PER_MM));
482
+ }
483
+
484
+ // src/option-utils.ts
485
+ var SAMPLE_VALUES = [12, 20, 15];
486
+ function cloneChartOption(value) {
487
+ try {
488
+ return JSON.parse(JSON.stringify(value));
489
+ } catch {
490
+ return value;
491
+ }
492
+ }
493
+ function previewChartOption(type, option) {
494
+ if (!option || typeof option !== "object" || Array.isArray(option)) return {};
495
+ const next = cloneChartOption(option);
496
+ const def = getChartKindDefinition(type);
497
+ const categories = [...getSampleCategories()];
498
+ const values = [...SAMPLE_VALUES];
499
+ const series = Array.isArray(next.series) ? next.series : [];
500
+ const replaceSeriesData = (mapper) => {
501
+ for (const item of series) {
502
+ if (Array.isArray(item.data) && item.data.includes("$data")) item.data = mapper(item);
503
+ }
504
+ };
505
+ const replaceAxisData = () => {
506
+ for (const key of ["xAxis", "yAxis"]) {
507
+ const axes = Array.isArray(next[key]) ? next[key] : next[key] ? [next[key]] : [];
508
+ for (const axis of axes) {
509
+ if (axis && Array.isArray(axis.data) && axis.data.includes("$data")) axis.data = [...categories];
510
+ }
511
+ }
512
+ };
513
+ switch (def?.seriesType) {
514
+ case "pie":
515
+ replaceSeriesData(() => categories.map((name, index) => ({ name, value: values[index] ?? 10 })));
516
+ break;
517
+ case "funnel":
518
+ replaceSeriesData(() => categories.map((name, index) => ({ name, value: values[index] ?? 10 })));
519
+ break;
520
+ case "scatter":
521
+ replaceSeriesData(() => values.map((value) => [value, value + 6]));
522
+ break;
523
+ case "radar":
524
+ next.radar = {
525
+ ...next.radar ?? {},
526
+ indicator: categories.map((name) => ({ name, max: 30 }))
527
+ };
528
+ replaceSeriesData(() => [{ name: "\u793A\u4F8B", value: values }]);
529
+ break;
530
+ case "gauge":
531
+ replaceSeriesData(() => [{ value: values[0] ?? 40, name: "\u6570\u91CF" }]);
532
+ break;
533
+ default:
534
+ replaceSeriesData(() => [...values]);
535
+ replaceAxisData();
536
+ break;
537
+ }
538
+ return next;
539
+ }
540
+ function readPaletteKey(option, palettes) {
541
+ const color = Array.isArray(option?.color) ? (option?.color).map(String) : [];
542
+ const hit = palettes.find((palette) => palette.colors.every((c, i) => c === color[i]) && color.length === palette.colors.length);
543
+ return hit?.key ?? "default";
544
+ }
545
+ function asObject(node) {
546
+ if (Array.isArray(node)) return node[0] && typeof node[0] === "object" ? { ...node[0] } : {};
547
+ return node && typeof node === "object" ? { ...node } : {};
548
+ }
549
+ function syncSeriesCount(option, count, type) {
550
+ const next = cloneChartOption(option);
551
+ const rawSeries = Array.isArray(next.series) ? next.series : [];
552
+ const def = getChartKindDefinition(type);
553
+ const template = rawSeries[0] ?? { type: def?.seriesType === "line" ? "line" : "bar", data: ["$data"] };
554
+ next.series = Array.from({ length: Math.max(count, 1) }, (_, index) => ({
555
+ ...template,
556
+ ...rawSeries[index] ?? {},
557
+ data: ["$data"]
558
+ }));
559
+ return next;
560
+ }
561
+ var round1 = (value) => Math.round(value * 10) / 10;
562
+ function pxToPercent(px, totalPx) {
563
+ return totalPx > 0 ? round1(px / totalPx * 100) : 0;
564
+ }
565
+ function readInsetPercent(value, totalPx, echartsPx) {
566
+ if (typeof value === "string" && value.trim().endsWith("%")) {
567
+ const parsed = Number.parseFloat(value);
568
+ if (Number.isFinite(parsed)) return round1(parsed);
569
+ }
570
+ if (typeof value === "number" && Number.isFinite(value)) return pxToPercent(value, totalPx);
571
+ return pxToPercent(echartsPx, totalPx);
572
+ }
573
+ function clamp(value, min, max) {
574
+ return Math.min(max, Math.max(min, value));
575
+ }
576
+ function percentString(value) {
577
+ return `${clamp(round1(value), 0, 100)}%`;
578
+ }
579
+ function firstSeries(option) {
580
+ const series = Array.isArray(option.series) ? option.series : [];
581
+ const first = series[0];
582
+ return first && typeof first === "object" ? first : {};
583
+ }
584
+ function readFunnelPadding(option, widthMm, heightMm) {
585
+ const source = option && typeof option === "object" ? option : {};
586
+ const series = firstSeries(source);
587
+ const widthPx = mmToChartPx(widthMm);
588
+ const heightPx = mmToChartPx(heightMm);
589
+ return {
590
+ top: readInsetPercent(series.top, heightPx, ECHARTS_FUNNEL_PADDING_PX.top),
591
+ right: readInsetPercent(series.right, widthPx, ECHARTS_FUNNEL_PADDING_PX.right),
592
+ bottom: readInsetPercent(series.bottom, heightPx, ECHARTS_FUNNEL_PADDING_PX.bottom),
593
+ left: readInsetPercent(series.left, widthPx, ECHARTS_FUNNEL_PADDING_PX.left)
594
+ };
595
+ }
596
+ function writeFunnelPadding(option, padding) {
597
+ const next = cloneChartOption(option);
598
+ const series = Array.isArray(next.series) ? next.series : [];
599
+ if (series.length === 0) series.push({ type: "funnel", data: ["$data"] });
600
+ const first = series[0];
601
+ first.top = percentString(padding.top);
602
+ first.right = percentString(padding.right);
603
+ first.bottom = percentString(padding.bottom);
604
+ first.left = percentString(padding.left);
605
+ next.series = series;
606
+ return next;
607
+ }
608
+ function readRadarRadius(option, widthMm, heightMm) {
609
+ const source = option && typeof option === "object" ? option : {};
610
+ const raw = asObject(source.radar).radius;
611
+ const value = Array.isArray(raw) ? raw[raw.length - 1] : raw;
612
+ const widthPx = mmToChartPx(widthMm);
613
+ const heightPx = mmToChartPx(heightMm);
614
+ const viewSize = Math.min(widthPx, heightPx) / 2;
615
+ if (typeof value === "string" && value.trim().endsWith("%")) {
616
+ const parsed = Number.parseFloat(value);
617
+ if (Number.isFinite(parsed)) return round1(parsed);
618
+ }
619
+ if (typeof value === "number" && Number.isFinite(value)) return pxToPercent(value, viewSize);
620
+ return ECHARTS_RADAR_RADIUS_DEFAULT;
621
+ }
622
+ function writeRadarRadius(option, percent) {
623
+ const next = cloneChartOption(option);
624
+ next.radar = { ...asObject(next.radar), radius: percentString(clamp(percent, 20, 100)) };
625
+ return next;
626
+ }
627
+
628
+ // src/label.ts
629
+ var LABEL_PRESETS = [
630
+ { key: "value", label: "\u6570\u503C", formatter: "{c}" },
631
+ { key: "name-value", label: "\u540D\u79F0: \u6570\u503C", formatter: "{b}: {c}" },
632
+ { key: "name", label: "\u540D\u79F0", formatter: "{b}" },
633
+ { key: "percent", label: "\u767E\u5206\u6BD4", formatter: "{d}%" }
634
+ ];
635
+ var LABEL_POSITIONS = {
636
+ bar: [
637
+ { value: "top", label: "\u9876\u90E8" },
638
+ { value: "inside", label: "\u5185\u90E8" },
639
+ { value: "insideTop", label: "\u5185\u90E8\u9876\u7AEF" },
640
+ { value: "bottom", label: "\u5E95\u90E8" },
641
+ { value: "insideBottom", label: "\u5185\u90E8\u5E95\u7AEF" },
642
+ { value: "right", label: "\u53F3\u4FA7" },
643
+ { value: "left", label: "\u5DE6\u4FA7" },
644
+ { value: "middle", label: "\u5C45\u4E2D" }
645
+ ],
646
+ line: [
647
+ { value: "top", label: "\u9876\u90E8" },
648
+ { value: "bottom", label: "\u5E95\u90E8" },
649
+ { value: "inside", label: "\u5185\u90E8" },
650
+ { value: "left", label: "\u5DE6\u4FA7" },
651
+ { value: "right", label: "\u53F3\u4FA7" }
652
+ ],
653
+ pie: [
654
+ { value: "outside", label: "\u5916\u4FA7" },
655
+ { value: "inside", label: "\u5185\u90E8" },
656
+ { value: "center", label: "\u4E2D\u5FC3" }
657
+ ],
658
+ scatter: [
659
+ { value: "top", label: "\u9876\u90E8" },
660
+ { value: "bottom", label: "\u5E95\u90E8" },
661
+ { value: "left", label: "\u5DE6\u4FA7" },
662
+ { value: "right", label: "\u53F3\u4FA7" },
663
+ { value: "inside", label: "\u5185\u90E8" }
664
+ ],
665
+ radar: [
666
+ { value: "top", label: "\u9876\u90E8" },
667
+ { value: "bottom", label: "\u5E95\u90E8" },
668
+ { value: "left", label: "\u5DE6\u4FA7" },
669
+ { value: "right", label: "\u53F3\u4FA7" },
670
+ { value: "inside", label: "\u5185\u90E8" }
671
+ ],
672
+ funnel: [
673
+ { value: "outer", label: "\u5916\u4FA7" },
674
+ { value: "inner", label: "\u5185\u90E8" },
675
+ { value: "left", label: "\u5DE6\u4FA7" },
676
+ { value: "right", label: "\u53F3\u4FA7" },
677
+ { value: "top", label: "\u9876\u90E8" },
678
+ { value: "bottom", label: "\u5E95\u90E8" }
679
+ ],
680
+ gauge: []
681
+ };
682
+ var NATIVE_SHOW = {
683
+ bar: false,
684
+ line: false,
685
+ pie: true,
686
+ scatter: false,
687
+ radar: false,
688
+ funnel: true,
689
+ gauge: true
690
+ };
691
+ var ENABLE_DEFAULTS = {
692
+ bar: { position: "top", fontSize: 12 },
693
+ line: { position: "top", fontSize: 12 },
694
+ pie: { position: "outside", overflow: "none", fontSize: 11 },
695
+ scatter: { position: "top", fontSize: 11 },
696
+ radar: { position: "top", fontSize: 10 },
697
+ funnel: { position: "outer", fontSize: 11 },
698
+ gauge: { fontSize: 14 }
699
+ };
700
+ var TYPE_DEFAULTS = {
701
+ barHChart: { position: "right", fontSize: 12 }
702
+ };
703
+ var FIELDS_BY_SERIES = {
704
+ bar: [
705
+ "formatter",
706
+ "overflow",
707
+ "position",
708
+ "rotate",
709
+ "offset",
710
+ "fontSize",
711
+ "fontWeight",
712
+ "color",
713
+ "backgroundColor",
714
+ "borderColor",
715
+ "borderWidth",
716
+ "borderRadius",
717
+ "padding"
718
+ ],
719
+ line: [
720
+ "formatter",
721
+ "overflow",
722
+ "position",
723
+ "rotate",
724
+ "offset",
725
+ "fontSize",
726
+ "fontWeight",
727
+ "color",
728
+ "backgroundColor",
729
+ "borderColor",
730
+ "borderWidth",
731
+ "borderRadius",
732
+ "padding"
733
+ ],
734
+ pie: [
735
+ "formatter",
736
+ "overflow",
737
+ "position",
738
+ "distance",
739
+ "offset",
740
+ "fontSize",
741
+ "fontWeight",
742
+ "color",
743
+ "backgroundColor",
744
+ "borderColor",
745
+ "borderWidth",
746
+ "borderRadius",
747
+ "padding",
748
+ "labelLine.show",
749
+ "labelLine.length",
750
+ "labelLine.length2",
751
+ "labelLine.smooth"
752
+ ],
753
+ scatter: [
754
+ "formatter",
755
+ "overflow",
756
+ "position",
757
+ "distance",
758
+ "rotate",
759
+ "offset",
760
+ "fontSize",
761
+ "fontWeight",
762
+ "color",
763
+ "backgroundColor",
764
+ "borderColor",
765
+ "borderWidth",
766
+ "borderRadius",
767
+ "padding"
768
+ ],
769
+ radar: ["formatter", "fontSize", "fontWeight", "color"],
770
+ funnel: [
771
+ "formatter",
772
+ "overflow",
773
+ "position",
774
+ "distance",
775
+ "fontSize",
776
+ "fontWeight",
777
+ "color",
778
+ "labelLine.show",
779
+ "labelLine.length",
780
+ "labelLine.smooth"
781
+ ],
782
+ gauge: ["formatter", "fontSize", "fontWeight", "color", "offset"]
783
+ };
784
+ var VALUE_KEYS = [
785
+ "formatter",
786
+ "overflow",
787
+ "position",
788
+ "distance",
789
+ "rotate",
790
+ "offset",
791
+ "fontSize",
792
+ "fontWeight",
793
+ "color",
794
+ "backgroundColor",
795
+ "borderColor",
796
+ "borderWidth",
797
+ "borderRadius",
798
+ "padding"
799
+ ];
800
+ function seriesOf2(option) {
801
+ const series = option?.series;
802
+ return Array.isArray(series) ? series : [];
803
+ }
804
+ function asRecord(node) {
805
+ return node && typeof node === "object" && !Array.isArray(node) ? { ...node } : {};
806
+ }
807
+ function normalizeLabelOffsetInPlace(target) {
808
+ if (typeof target.offsetX !== "number" && typeof target.offsetY !== "number") return;
809
+ if (!Array.isArray(target.offset)) {
810
+ target.offset = [
811
+ typeof target.offsetX === "number" ? target.offsetX : 0,
812
+ typeof target.offsetY === "number" ? target.offsetY : 0
813
+ ];
814
+ }
815
+ delete target.offsetX;
816
+ delete target.offsetY;
817
+ }
818
+ function labelTargetOf(type) {
819
+ return getChartKindDefinition(type)?.seriesType === "gauge" ? "detail" : "label";
820
+ }
821
+ function labelFieldsOf(type) {
822
+ const def = getChartKindDefinition(type);
823
+ return def ? FIELDS_BY_SERIES[def.seriesType] : [];
824
+ }
825
+ function readChartLabel(option, type) {
826
+ const def = getChartKindDefinition(type);
827
+ const series = seriesOf2(option);
828
+ const target = asRecord(series[0]?.[labelTargetOf(type)]);
829
+ normalizeLabelOffsetInPlace(target);
830
+ const state = {
831
+ show: typeof target.show === "boolean" ? target.show : def ? NATIVE_SHOW[def.seriesType] : false,
832
+ // labelLine 在 ECharts 里是 series 顶层键(与 label 平级),不是 label 的子键
833
+ labelLine: asRecord(series[0]?.labelLine)
834
+ };
835
+ for (const key of VALUE_KEYS) {
836
+ const value = target[key];
837
+ if (key === "offset") continue;
838
+ if (typeof value === "string" || typeof value === "number") state[key] = value;
839
+ }
840
+ const offset = target.offset;
841
+ if (Array.isArray(offset) && typeof offset[0] === "number" && typeof offset[1] === "number") {
842
+ state.offset = [offset[0], offset[1]];
843
+ }
844
+ return state;
845
+ }
846
+ function defaultSetOf(type) {
847
+ const def = getChartKindDefinition(type);
848
+ if (!def) return {};
849
+ return { ...ENABLE_DEFAULTS[def.seriesType], ...TYPE_DEFAULTS[type] };
850
+ }
851
+ function isEmpty(value) {
852
+ return value === null || value === void 0 || value === "";
853
+ }
854
+ function updateChartLabel(option, type, patch) {
855
+ const next = cloneChartOption(option ?? {});
856
+ const series = Array.isArray(next.series) ? next.series : [];
857
+ const def = getChartKindDefinition(type);
858
+ if (!def || series.length === 0) return next;
859
+ const targetKey = labelTargetOf(type);
860
+ const { enabled, labelLine, ...values } = patch;
861
+ for (const item of series) {
862
+ if (!item || typeof item !== "object") continue;
863
+ const current = asRecord(item[targetKey]);
864
+ normalizeLabelOffsetInPlace(current);
865
+ if (enabled === true) {
866
+ Object.assign(current, { ...defaultSetOf(type), ...current, show: true });
867
+ } else if (enabled === false) {
868
+ current.show = false;
869
+ }
870
+ for (const [key, value] of Object.entries(values)) {
871
+ if (isEmpty(value)) delete current[key];
872
+ else current[key] = value;
873
+ }
874
+ if (labelLine) {
875
+ const line = asRecord(item.labelLine);
876
+ for (const [key, value] of Object.entries(labelLine)) {
877
+ if (isEmpty(value)) delete line[key];
878
+ else line[key] = value;
879
+ }
880
+ item.labelLine = line;
881
+ }
882
+ item[targetKey] = current;
883
+ }
884
+ return next;
885
+ }
886
+
450
887
  // src/normalize.ts
451
888
  function asArray(value) {
452
889
  if (Array.isArray(value)) return value.map((item) => ({ ...item }));
@@ -475,6 +912,15 @@ function normalizeChartOption(type, option) {
475
912
  const next = structuredClone(option);
476
913
  const series = asArray(next.series);
477
914
  if (series.length === 0) return next;
915
+ const labelKey = labelTargetOf(type);
916
+ for (const item of series) {
917
+ const label = item[labelKey];
918
+ if (label && typeof label === "object" && !Array.isArray(label)) {
919
+ const nextLabel = { ...label };
920
+ normalizeLabelOffsetInPlace(nextLabel);
921
+ item[labelKey] = nextLabel;
922
+ }
923
+ }
478
924
  if (def.seriesType === "pie") {
479
925
  next.series = series.map((item) => ({
480
926
  ...item,
@@ -516,13 +962,6 @@ function normalizeChartOption(type, option) {
516
962
  return next;
517
963
  }
518
964
 
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
965
  // src/renderer.ts
527
966
  function fitSvgRoot(svg, widthPx, heightPx) {
528
967
  const match = /<svg\b[^>]*>/i.exec(svg);
@@ -640,32 +1079,28 @@ registerChartPlugin();
640
1079
 
641
1080
  // src/ui.ts
642
1081
  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";
1082
+ import { render } from "@worm-print-platform/plugin-kit/dom";
1083
+ import { colorPicker } from "@worm-print-platform/plugin-kit/controls";
663
1084
  var CANVAS_STYLE = "width:100%;height:100%;min-width:0;min-height:0;pointer-events:none";
664
1085
  var STYLES = [
665
1086
  ".echarts-canvas-element{overflow:hidden}",
666
1087
  ".echarts-field-row{display:flex;gap:6px;align-items:center}",
667
1088
  ".echarts-field-row>.pd-input{flex:1;min-width:0}",
668
- ".echarts-field-row>.pd-button{flex:none}"
1089
+ ".echarts-field-row>.pd-button{flex:none}",
1090
+ ".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}",
1091
+ ".echarts-dropdown-trigger:hover{border-color:var(--pd-text-faint,#b4b9c4)}",
1092
+ '.echarts-dropdown-trigger[aria-expanded="true"]{border-color:var(--pd-accent,#165dff);box-shadow:0 0 0 2px rgb(22 93 255 / 12%)}',
1093
+ ".echarts-dropdown-value{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
1094
+ ".echarts-dropdown-arrow{flex:none;color:var(--pd-text-muted,#909399);font-size:10px;transition:transform .14s}",
1095
+ '.echarts-dropdown-trigger[aria-expanded="true"] .echarts-dropdown-arrow{transform:rotate(180deg)}',
1096
+ ".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}",
1097
+ ".echarts-dropdown-option{padding:5px 8px;border-radius:4px;cursor:pointer;font-size:12px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}",
1098
+ ".echarts-dropdown-option:hover{background:var(--pd-accent-soft,rgb(22 93 255 / 9%))}",
1099
+ ".echarts-dropdown-option.is-active{background:var(--pd-accent-soft,rgb(22 93 255 / 9%));color:var(--pd-accent,#165dff)}",
1100
+ ".echarts-label-group{margin-top:8px;border-top:1px solid var(--pd-border,#e5e7eb);padding-top:8px}",
1101
+ ".echarts-label-group>summary{display:flex;align-items:center;cursor:pointer;list-style:none;font-size:12px;font-weight:600}",
1102
+ ".echarts-label-summary>.pd-field{flex:1;margin:0;font-weight:400}",
1103
+ ".echarts-label-sub{font-size:11px;color:var(--pd-text-secondary,#6b7280);margin:8px 0 4px}"
669
1104
  ].join("");
670
1105
  var CHART_OPTION_KEYS = [
671
1106
  "chartOption",
@@ -693,10 +1128,12 @@ var SEARCH_KEYWORDS = [
693
1128
  "\u6563\u70B9",
694
1129
  "\u96F7\u8FBE",
695
1130
  "\u6F0F\u6597",
696
- "\u4EEA\u8868"
1131
+ "\u4EEA\u8868",
1132
+ "\u6570\u636E\u6807\u7B7E",
1133
+ "\u6570\u503C\u6807\u7B7E",
1134
+ "label"
697
1135
  ];
698
1136
  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
1137
  function escapeHtml2(value) {
701
1138
  return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
702
1139
  }
@@ -709,7 +1146,7 @@ function rawChartOption(element) {
709
1146
  }
710
1147
  function panelOption(element) {
711
1148
  const raw = rawChartOption(element);
712
- return cloneChartOption(raw ?? createDefaultChartOption2(elementType(element)));
1149
+ return cloneChartOption(raw ?? createDefaultChartOption(elementType(element)));
713
1150
  }
714
1151
  function chartHasProperties(element) {
715
1152
  const options = element?.options;
@@ -718,7 +1155,7 @@ function chartHasProperties(element) {
718
1155
  return CHART_OPTION_KEYS.some((key) => record[key] !== void 0);
719
1156
  }
720
1157
  function commitOption(ctx, type, next, patch = {}) {
721
- ctx.update({ chartOption: normalizeChartOption2(type, next), ...patch });
1158
+ ctx.update({ chartOption: normalizeChartOption(type, next), ...patch });
722
1159
  }
723
1160
  function readValueFields(element) {
724
1161
  const raw = element.options.chartValueFields;
@@ -745,10 +1182,37 @@ function dataSourceCandidates(data) {
745
1182
  if (!first) return [];
746
1183
  return Object.keys(first).filter((key) => Array.isArray(first[key]));
747
1184
  }
1185
+ function dataRowFields(data, dataSource) {
1186
+ const first = data?.[0];
1187
+ if (!first) return [];
1188
+ const key = dataSource && Array.isArray(first[dataSource]) ? dataSource : Object.keys(first).find((k) => Array.isArray(first[k]));
1189
+ if (!key) return [];
1190
+ const rows = first[key];
1191
+ return rows.length > 0 && typeof rows[0] === "object" && rows[0] !== null ? Object.keys(rows[0]) : [];
1192
+ }
1193
+ function fieldLabelMap(fields) {
1194
+ const map = /* @__PURE__ */ new Map();
1195
+ for (const field2 of fields ?? []) {
1196
+ if (field2.fieldKey && field2.fieldLabel) map.set(field2.fieldKey, field2.fieldLabel);
1197
+ }
1198
+ return map;
1199
+ }
1200
+ function optionLabel(value, labels, fallbackSuffix) {
1201
+ if (!value) return fallbackSuffix ?? "\uFF08\u9ED8\u8BA4\uFF09";
1202
+ const name = labels.get(value);
1203
+ const base = name ? `${name}\uFF08${value}\uFF09` : value;
1204
+ return fallbackSuffix ? `${base}${fallbackSuffix}` : base;
1205
+ }
1206
+ function dropdownOptions(candidates, current, labels = /* @__PURE__ */ new Map()) {
1207
+ const opts = candidates.map((value) => ({ value, label: optionLabel(value, labels) }));
1208
+ if (current && !candidates.includes(current)) opts.unshift({ value: current, label: optionLabel(current, labels, "\uFF08\u5F53\u524D\uFF09") });
1209
+ if (!current) opts.unshift({ value: "", label: "\uFF08\u9ED8\u8BA4\uFF1A\u9876\u5C42\u7B2C\u4E00\u4E2A\u6570\u7EC4\uFF09" });
1210
+ return opts;
1211
+ }
748
1212
  function seriesList(option) {
749
1213
  return Array.isArray(option.series) ? option.series : [];
750
1214
  }
751
- function clamp(value, min, max) {
1215
+ function clamp2(value, min, max) {
752
1216
  return Math.min(max, Math.max(min, value));
753
1217
  }
754
1218
  function syncValueFields(ctx, type, nextFields) {
@@ -767,14 +1231,14 @@ function renderCanvas(ctx) {
767
1231
  const widthMm = Number(options.width) || 0;
768
1232
  const heightMm = Number(options.height) || 0;
769
1233
  try {
770
- const preview = previewChartOption(type, rawChartOption(element) ?? createDefaultChartOption2(type));
771
- const option = normalizeChartOption2(type, preview);
1234
+ const preview = previewChartOption(type, rawChartOption(element) ?? createDefaultChartOption(type));
1235
+ const option = normalizeChartOption(type, preview);
772
1236
  if (!option || typeof option !== "object" || Array.isArray(option)) throw new Error("\u56FE\u8868 option \u975E\u6CD5\uFF1A\u9700\u8981\u5BF9\u8C61");
773
1237
  const fontFamily = typeof options.fontFamily === "string" && options.fontFamily ? options.fontFamily : void 0;
774
- const svg = renderChartToSvg2({ key: element.id, type, option, widthMm, heightMm, fontFamily });
1238
+ const svg = renderChartToSvg({ key: element.id, type, option, widthMm, heightMm, fontFamily });
775
1239
  return `<div class="echarts-canvas-element" style="${CANVAS_STYLE}">${svg}</div>`;
776
1240
  } catch {
777
- const title = typeof options.title === "string" && options.title.trim() ? options.title : getChartKindDefinition2(type)?.label ?? "\u56FE\u8868";
1241
+ const title = typeof options.title === "string" && options.title.trim() ? options.title : getChartKindDefinition(type)?.label ?? "\u56FE\u8868";
778
1242
  return `<div class="echarts-canvas-element" style="${CANVAS_STYLE}">${escapeHtml2(title)}</div>`;
779
1243
  }
780
1244
  }
@@ -811,52 +1275,305 @@ function checkboxField(labelText, checked, onCommit) {
811
1275
  wrap.appendChild(input);
812
1276
  return wrap;
813
1277
  }
1278
+ function selectInput(options, value, onCommit) {
1279
+ const select = el("select", "pd-select");
1280
+ for (const item of options) {
1281
+ const optionEl = el("option");
1282
+ optionEl.value = item.value;
1283
+ optionEl.textContent = item.label;
1284
+ select.appendChild(optionEl);
1285
+ }
1286
+ select.value = value;
1287
+ select.addEventListener("change", () => onCommit(select.value));
1288
+ return select;
1289
+ }
1290
+ var activeDropdown = null;
1291
+ function composedPathOf(ev) {
1292
+ const composed = typeof ev.composedPath === "function" ? ev.composedPath() : [];
1293
+ return composed.length ? composed : [ev.target];
1294
+ }
1295
+ function dropdownSelect(options, value, onCommit) {
1296
+ const current = options.find((item) => item.value === value) ?? { value, label: value || "\uFF08\u9ED8\u8BA4\uFF09" };
1297
+ const trigger = el("button", "echarts-dropdown-trigger");
1298
+ trigger.type = "button";
1299
+ trigger.setAttribute("aria-haspopup", "listbox");
1300
+ trigger.setAttribute("aria-expanded", "false");
1301
+ const valueEl = el("span", "echarts-dropdown-value", current.label);
1302
+ const arrow = el("span", "echarts-dropdown-arrow", "\u25BE");
1303
+ trigger.appendChild(valueEl);
1304
+ trigger.appendChild(arrow);
1305
+ let panel = null;
1306
+ let off = [];
1307
+ const close = () => {
1308
+ off.forEach((fn) => fn());
1309
+ off = [];
1310
+ panel?.remove();
1311
+ panel = null;
1312
+ trigger.setAttribute("aria-expanded", "false");
1313
+ if (activeDropdown?.close === close) activeDropdown = null;
1314
+ };
1315
+ const open = () => {
1316
+ activeDropdown?.close();
1317
+ const root = trigger.getRootNode();
1318
+ const mount = root instanceof ShadowRoot ? root : document.body;
1319
+ panel = el("div", "echarts-dropdown-panel");
1320
+ panel.setAttribute("role", "listbox");
1321
+ for (const item of options) {
1322
+ const optionEl = el("div", `echarts-dropdown-option${item.value === value ? " is-active" : ""}`, item.label);
1323
+ optionEl.setAttribute("role", "option");
1324
+ optionEl.setAttribute("aria-selected", item.value === value ? "true" : "false");
1325
+ optionEl.addEventListener("click", (ev) => {
1326
+ ev.stopPropagation();
1327
+ close();
1328
+ onCommit(item.value);
1329
+ });
1330
+ panel.appendChild(optionEl);
1331
+ }
1332
+ mount.appendChild(panel);
1333
+ const rect = trigger.getBoundingClientRect();
1334
+ panel.style.left = `${rect.left}px`;
1335
+ panel.style.top = `${rect.bottom + 4}px`;
1336
+ panel.style.minWidth = `${rect.width}px`;
1337
+ trigger.setAttribute("aria-expanded", "true");
1338
+ activeDropdown = { close };
1339
+ const onPointerDown = (ev) => {
1340
+ const path = composedPathOf(ev);
1341
+ if (path.includes(trigger) || path.includes(panel)) return;
1342
+ close();
1343
+ };
1344
+ const onKeydown = (ev) => {
1345
+ if (ev.key === "Escape") close();
1346
+ };
1347
+ const onScroll = () => close();
1348
+ document.addEventListener("pointerdown", onPointerDown, true);
1349
+ document.addEventListener("keydown", onKeydown);
1350
+ window.addEventListener("scroll", onScroll, true);
1351
+ window.addEventListener("resize", onScroll);
1352
+ root.addEventListener("scroll", onScroll, true);
1353
+ off.push(
1354
+ () => document.removeEventListener("pointerdown", onPointerDown, true),
1355
+ () => document.removeEventListener("keydown", onKeydown),
1356
+ () => window.removeEventListener("scroll", onScroll, true),
1357
+ () => window.removeEventListener("resize", onScroll),
1358
+ () => root.removeEventListener("scroll", onScroll, true)
1359
+ );
1360
+ };
1361
+ trigger.addEventListener("click", (ev) => {
1362
+ ev.stopPropagation();
1363
+ if (panel) close();
1364
+ else open();
1365
+ });
1366
+ return trigger;
1367
+ }
1368
+ var OVERFLOW_OPTIONS = [
1369
+ { value: "", label: "\u9ED8\u8BA4" },
1370
+ { value: "none", label: "\u4E0D\u5904\u7406\uFF08\u663E\u793A\u5B8C\u6574\uFF09" },
1371
+ { value: "truncate", label: "\u622A\u65AD" },
1372
+ { value: "break", label: "\u6362\u884C" }
1373
+ ];
1374
+ var FONT_WEIGHT_OPTIONS = [
1375
+ { value: "", label: "\u9ED8\u8BA4" },
1376
+ { value: "normal", label: "\u5E38\u89C4" },
1377
+ { value: "bold", label: "\u52A0\u7C97" }
1378
+ ];
1379
+ var STYLE_FIELD_LABELS = {
1380
+ distance: "\u8DDD\u79BB",
1381
+ rotate: "\u65CB\u8F6C\uFF08\u5EA6\uFF09",
1382
+ fontSize: "\u5B57\u53F7",
1383
+ fontWeight: "\u5B57\u91CD",
1384
+ color: "\u6587\u5B57\u989C\u8272",
1385
+ backgroundColor: "\u80CC\u666F\u8272",
1386
+ borderColor: "\u8FB9\u6846\u8272",
1387
+ borderWidth: "\u8FB9\u6846\u5BBD\u5EA6",
1388
+ borderRadius: "\u5706\u89D2",
1389
+ padding: "\u5185\u8FB9\u8DDD"
1390
+ };
1391
+ function renderLabelGroup(ctx, type) {
1392
+ const element = ctx.element;
1393
+ const def = getChartKindDefinition(type);
1394
+ const fields = labelFieldsOf(type);
1395
+ const has = (key) => fields.includes(key);
1396
+ const state = readChartLabel(panelOption(element), type);
1397
+ const commit = (patch) => {
1398
+ commitOption(ctx, type, updateChartLabel(panelOption(element), type, patch));
1399
+ };
1400
+ const commitNumber = (key, raw) => {
1401
+ if (raw.trim() === "") return commit({ [key]: null });
1402
+ const value = Number(raw);
1403
+ if (!Number.isFinite(value)) return;
1404
+ commit({ [key]: value });
1405
+ };
1406
+ const commitLineNumber = (key, raw) => {
1407
+ if (raw.trim() === "") return commit({ labelLine: { [key]: null } });
1408
+ const value = Number(raw);
1409
+ if (!Number.isFinite(value)) return;
1410
+ commit({ labelLine: { [key]: value } });
1411
+ };
1412
+ const numberField = (key, value) => {
1413
+ const wrap = field(STYLE_FIELD_LABELS[key] ?? key);
1414
+ wrap.appendChild(
1415
+ textInput({ value: value === void 0 ? "" : String(value), type: "number" }, (raw) => commitNumber(key, raw))
1416
+ );
1417
+ return wrap;
1418
+ };
1419
+ const colorField = (key, value) => {
1420
+ const wrap = field(STYLE_FIELD_LABELS[key] ?? key);
1421
+ const holder = el("span");
1422
+ render(colorPicker({
1423
+ value: value ?? "",
1424
+ title: STYLE_FIELD_LABELS[key] ?? key,
1425
+ onChange: (next) => commit({ [key]: next ?? "" })
1426
+ }), holder);
1427
+ wrap.appendChild(holder);
1428
+ return wrap;
1429
+ };
1430
+ const group = el("details", "echarts-label-group");
1431
+ group.open = state.show;
1432
+ const summary = el("summary", "echarts-label-summary");
1433
+ const toggle = checkboxField("\u663E\u793A\u6570\u636E\u6807\u7B7E", state.show, (checked) => commit({ enabled: checked }));
1434
+ toggle.querySelector("input")?.addEventListener("click", (event) => event.stopPropagation());
1435
+ summary.appendChild(toggle);
1436
+ group.appendChild(summary);
1437
+ if (has("formatter") || has("overflow")) {
1438
+ group.appendChild(el("div", "echarts-label-sub", "\u5185\u5BB9"));
1439
+ if (has("formatter")) {
1440
+ const wrap = field("\u6570\u636E\u6807\u7B7E\u5185\u5BB9");
1441
+ wrap.appendChild(
1442
+ selectInput(
1443
+ [{ value: "", label: "\u81EA\u5B9A\u4E49 / \u9ED8\u8BA4" }, ...LABEL_PRESETS.map((preset) => ({ value: preset.formatter, label: preset.label }))],
1444
+ state.formatter ?? "",
1445
+ (value) => commit({ formatter: value })
1446
+ )
1447
+ );
1448
+ wrap.appendChild(
1449
+ textInput({ value: state.formatter ?? "", placeholder: "\u5982 {b}: {c}" }, (value) => commit({ formatter: value }))
1450
+ );
1451
+ group.appendChild(wrap);
1452
+ }
1453
+ if (has("overflow")) {
1454
+ const wrap = field("\u6EA2\u51FA\u5904\u7406");
1455
+ wrap.appendChild(selectInput(OVERFLOW_OPTIONS, state.overflow ?? "", (value) => commit({ overflow: value })));
1456
+ group.appendChild(wrap);
1457
+ }
1458
+ }
1459
+ if (has("position") || has("distance") || has("rotate") || has("offset")) {
1460
+ group.appendChild(el("div", "echarts-label-sub", "\u4F4D\u7F6E"));
1461
+ if (has("position")) {
1462
+ const wrap = field("\u6807\u7B7E\u4F4D\u7F6E");
1463
+ const positions = def ? LABEL_POSITIONS[def.seriesType] ?? [] : [];
1464
+ wrap.appendChild(
1465
+ selectInput([{ value: "", label: "\u9ED8\u8BA4" }, ...positions], state.position ?? "", (value) => commit({ position: value }))
1466
+ );
1467
+ group.appendChild(wrap);
1468
+ }
1469
+ if (has("distance")) group.appendChild(numberField("distance", state.distance));
1470
+ if (has("rotate")) group.appendChild(numberField("rotate", state.rotate));
1471
+ if (has("offset")) {
1472
+ let commitOffset2 = function() {
1473
+ const parse = (input, fallback) => {
1474
+ const text = input.value.trim();
1475
+ if (text === "") return 0;
1476
+ const value = Number(text);
1477
+ return Number.isFinite(value) ? value : fallback;
1478
+ };
1479
+ commit({ offset: [parse(inputX, current[0] ?? 0), parse(inputY, current[1] ?? 0)] });
1480
+ };
1481
+ var commitOffset = commitOffset2;
1482
+ const wrap = field("\u504F\u79FB X / Y");
1483
+ const row = el("div", "echarts-field-row");
1484
+ const current = state.offset ?? [0, 0];
1485
+ const inputX = textInput({ value: String(current[0] ?? 0), type: "number" }, () => commitOffset2());
1486
+ const inputY = textInput({ value: String(current[1] ?? 0), type: "number" }, () => commitOffset2());
1487
+ row.appendChild(inputX);
1488
+ row.appendChild(inputY);
1489
+ wrap.appendChild(row);
1490
+ group.appendChild(wrap);
1491
+ }
1492
+ }
1493
+ const styleKeys = ["fontSize", "fontWeight", "color", "backgroundColor", "borderColor", "borderWidth", "borderRadius", "padding"];
1494
+ if (styleKeys.some(has)) {
1495
+ group.appendChild(el("div", "echarts-label-sub", "\u6837\u5F0F"));
1496
+ if (has("fontSize")) group.appendChild(numberField("fontSize", state.fontSize));
1497
+ if (has("fontWeight")) {
1498
+ const wrap = field("\u5B57\u91CD");
1499
+ wrap.appendChild(selectInput(FONT_WEIGHT_OPTIONS, state.fontWeight ?? "", (value) => commit({ fontWeight: value })));
1500
+ group.appendChild(wrap);
1501
+ }
1502
+ for (const key of ["color", "backgroundColor", "borderColor"]) {
1503
+ if (has(key)) group.appendChild(colorField(key, state[key]));
1504
+ }
1505
+ for (const key of ["borderWidth", "borderRadius", "padding"]) {
1506
+ if (has(key)) group.appendChild(numberField(key, state[key]));
1507
+ }
1508
+ }
1509
+ if (has("labelLine.show")) {
1510
+ group.appendChild(el("div", "echarts-label-sub", "\u5F15\u5BFC\u7EBF"));
1511
+ group.appendChild(
1512
+ checkboxField("\u663E\u793A\u5F15\u5BFC\u7EBF", state.labelLine.show === true, (checked) => commit({ labelLine: { show: checked } }))
1513
+ );
1514
+ if (has("labelLine.length")) {
1515
+ const wrap = field("\u5F15\u5BFC\u7EBF\u957F\u5EA6");
1516
+ wrap.appendChild(
1517
+ textInput(
1518
+ { value: state.labelLine.length === void 0 ? "" : String(state.labelLine.length), type: "number" },
1519
+ (raw) => commitLineNumber("length", raw)
1520
+ )
1521
+ );
1522
+ group.appendChild(wrap);
1523
+ }
1524
+ if (has("labelLine.length2")) {
1525
+ const wrap = field("\u7B2C\u4E8C\u6BB5\u957F\u5EA6");
1526
+ wrap.appendChild(
1527
+ textInput(
1528
+ { value: state.labelLine.length2 === void 0 ? "" : String(state.labelLine.length2), type: "number" },
1529
+ (raw) => commitLineNumber("length2", raw)
1530
+ )
1531
+ );
1532
+ group.appendChild(wrap);
1533
+ }
1534
+ if (has("labelLine.smooth")) {
1535
+ group.appendChild(
1536
+ checkboxField("\u5E73\u6ED1\u5F15\u5BFC\u7EBF", state.labelLine.smooth === true, (checked) => commit({ labelLine: { smooth: checked } }))
1537
+ );
1538
+ }
1539
+ }
1540
+ return group;
1541
+ }
814
1542
  function renderProperty(ctx) {
815
1543
  const element = ctx.element;
816
1544
  const type = elementType(element);
817
- const def = getChartKindDefinition2(type);
818
- const fields = resolveChartPanelFields2(type);
1545
+ const def = getChartKindDefinition(type);
1546
+ const fields = resolveChartPanelFields(type);
819
1547
  const has = (key) => fields.includes(key);
820
1548
  const options = element.options;
821
1549
  const widthMm = Number(options.width) || 0;
822
1550
  const heightMm = Number(options.height) || 0;
823
1551
  const limit = maxValueFields(def);
824
- const palettes = getChartPalettes2();
1552
+ const palettes = getChartPalettes();
1553
+ const fieldLabels = fieldLabelMap(ctx.fields);
825
1554
  const root = el("div", "echarts-property");
826
1555
  const form = el("form", "pd-form");
827
1556
  form.addEventListener("submit", (event) => event.preventDefault());
828
1557
  root.appendChild(form);
829
1558
  if (has("dataSource")) {
830
1559
  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
- }
1560
+ const current = String(options.chartDataSource ?? "");
842
1561
  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
- },
1562
+ dropdownSelect(
1563
+ dropdownOptions(dataSourceCandidates(ctx.data), current, fieldLabels),
1564
+ current,
849
1565
  (value) => commitOption(ctx, type, panelOption(element), { chartDataSource: value })
850
1566
  )
851
1567
  );
852
- if (datalist) wrap.appendChild(datalist);
853
1568
  form.appendChild(wrap);
854
1569
  }
855
1570
  if (has("categoryField")) {
856
1571
  const wrap = field("\u7C7B\u76EE\u5B57\u6BB5");
1572
+ const current = String(options.chartCategoryField ?? "");
857
1573
  wrap.appendChild(
858
- textInput(
859
- { value: String(options.chartCategoryField ?? ""), placeholder: "\u5982 name" },
1574
+ dropdownSelect(
1575
+ dropdownOptions(dataRowFields(ctx.data, String(options.chartDataSource ?? "")), current, fieldLabels),
1576
+ current,
860
1577
  (value) => commitOption(ctx, type, panelOption(element), { chartCategoryField: value })
861
1578
  )
862
1579
  );
@@ -868,8 +1585,9 @@ function renderProperty(ctx) {
868
1585
  fieldsNow.forEach((value, index) => {
869
1586
  const row = el("div", "echarts-field-row");
870
1587
  row.appendChild(
871
- textInput(
872
- { value, placeholder: "\u5982 value" },
1588
+ dropdownSelect(
1589
+ dropdownOptions(dataRowFields(ctx.data, String(options.chartDataSource ?? "")), value, fieldLabels),
1590
+ value,
873
1591
  (next) => {
874
1592
  const list = readValueFields(element);
875
1593
  list[index] = next;
@@ -954,6 +1672,9 @@ function renderProperty(ctx) {
954
1672
  wrap.appendChild(select);
955
1673
  form.appendChild(wrap);
956
1674
  }
1675
+ if (has("label")) {
1676
+ form.appendChild(renderLabelGroup(ctx, type));
1677
+ }
957
1678
  if (has("stack")) {
958
1679
  const series = seriesList(panelOption(element));
959
1680
  const stacked = series.some((item) => item.stack !== void 0 && item.stack !== null && item.stack !== "");
@@ -976,7 +1697,7 @@ function renderProperty(ctx) {
976
1697
  textInput({ value: String(inner), type: "number", min: 0, max: 90 }, (value) => {
977
1698
  const next = panelOption(element);
978
1699
  const series = seriesList(next);
979
- if (series[0]) series[0].radius = [`${clamp(Number(value) || 0, 0, 90)}%`, "70%"];
1700
+ if (series[0]) series[0].radius = [`${clamp2(Number(value) || 0, 0, 90)}%`, "70%"];
980
1701
  commitOption(ctx, type, next);
981
1702
  })
982
1703
  );
@@ -996,7 +1717,7 @@ function renderProperty(ctx) {
996
1717
  row.appendChild(
997
1718
  textInput({ value: String(padding[side]), type: "number", min: 0, max: 60, title }, (value) => {
998
1719
  const raw = Number(value);
999
- const next = Number.isFinite(raw) ? clamp(raw, 0, 60) : FUNNEL_PADDING_DEFAULTS2[side];
1720
+ const next = Number.isFinite(raw) ? clamp2(raw, 0, 60) : FUNNEL_PADDING_DEFAULTS[side];
1000
1721
  const option = panelOption(element);
1001
1722
  const current = readFunnelPadding(option, widthMm, heightMm);
1002
1723
  commitOption(ctx, type, writeFunnelPadding(option, { ...current, [side]: next }));
@@ -1013,7 +1734,7 @@ function renderProperty(ctx) {
1013
1734
  { value: String(readRadarRadius(panelOption(element), widthMm, heightMm)), type: "number", min: 20, max: 100 },
1014
1735
  (value) => {
1015
1736
  const raw = Number(value);
1016
- const next = Number.isFinite(raw) ? clamp(raw, 20, 100) : RADAR_RADIUS_DEFAULT2;
1737
+ const next = Number.isFinite(raw) ? clamp2(raw, 20, 100) : RADAR_RADIUS_DEFAULT;
1017
1738
  commitOption(ctx, type, writeRadarRadius(panelOption(element), next));
1018
1739
  }
1019
1740
  )
@@ -1047,7 +1768,7 @@ function renderProperty(ctx) {
1047
1768
  return root;
1048
1769
  }
1049
1770
  var CHART_ELEMENT_UI = defineElementUI({
1050
- types: CHART_KINDS2,
1771
+ types: CHART_KINDS,
1051
1772
  renderCanvas,
1052
1773
  renderProperty,
1053
1774
  hasProperties: chartHasProperties,