x-next 1.7.0 → 1.8.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.
Files changed (88) hide show
  1. package/AI_USAGE.md +129 -4
  2. package/CHANGELOG.md +38 -0
  3. package/dist/_hooks/use-chart-size.d.ts +25 -0
  4. package/dist/_utils/chart/index.d.ts +6 -0
  5. package/dist/_utils/chart/padding.d.ts +15 -0
  6. package/dist/_utils/chart/path.d.ts +34 -0
  7. package/dist/_utils/chart/scale.d.ts +55 -0
  8. package/dist/components/_components/chart/ChartAxis.d.ts +85 -0
  9. package/dist/components/_components/chart/ChartLegend.d.ts +26 -0
  10. package/dist/components/_components/chart/ChartTooltip.d.ts +76 -0
  11. package/dist/components/_components/chart/colors.d.ts +10 -0
  12. package/dist/components/_components/chart/interface.d.ts +38 -0
  13. package/dist/components/bar-chart/BarChart.d.ts +278 -0
  14. package/dist/components/bar-chart/helpers/layout.d.ts +55 -0
  15. package/dist/components/bar-chart/index.d.ts +600 -0
  16. package/dist/components/bar-chart/interface.d.ts +74 -0
  17. package/dist/components/bar-chart/props.d.ts +145 -0
  18. package/dist/components/heatmap/Heatmap.d.ts +10 -0
  19. package/dist/components/heatmap/index.d.ts +30 -0
  20. package/dist/components/index.d.ts +3 -0
  21. package/dist/components/line-chart/LineChart.d.ts +295 -0
  22. package/dist/components/line-chart/helpers/layout.d.ts +74 -0
  23. package/dist/components/line-chart/index.d.ts +614 -0
  24. package/dist/components/line-chart/interface.d.ts +76 -0
  25. package/dist/components/line-chart/props.d.ts +173 -0
  26. package/dist/components/pie-chart/PieChart.d.ts +219 -0
  27. package/dist/components/pie-chart/index.d.ts +470 -0
  28. package/dist/components/pie-chart/interface.d.ts +58 -0
  29. package/dist/components/pie-chart/props.d.ts +107 -0
  30. package/dist/components/trend-chart/components/TrendChart.d.ts +19 -96
  31. package/dist/components/trend-chart/index.d.ts +33 -187
  32. package/dist/components/trend-chart/props.d.ts +9 -78
  33. package/dist/components/trend-chart/themes.d.ts +0 -1
  34. package/dist/es/_hooks/use-chart-size.js +25 -0
  35. package/dist/es/_styles/palette-aliases.js +5 -0
  36. package/dist/es/_utils/chart/padding.js +22 -0
  37. package/dist/es/_utils/chart/path.js +69 -0
  38. package/dist/es/_utils/chart/scale.js +77 -0
  39. package/dist/es/components/_components/chart/ChartAxis.js +79 -0
  40. package/dist/es/components/_components/chart/ChartLegend.js +53 -0
  41. package/dist/es/components/_components/chart/ChartTooltip.js +64 -0
  42. package/dist/es/components/_components/chart/colors.js +12 -0
  43. package/dist/es/components/bar-chart/BarChart.js +470 -0
  44. package/dist/es/components/bar-chart/helpers/layout.js +53 -0
  45. package/dist/es/components/bar-chart/index.js +8 -0
  46. package/dist/es/components/bar-chart/props.js +148 -0
  47. package/dist/es/components/heatmap/Heatmap.js +244 -169
  48. package/dist/es/components/index.js +132 -126
  49. package/dist/es/components/line-chart/LineChart.js +532 -0
  50. package/dist/es/components/line-chart/helpers/layout.js +80 -0
  51. package/dist/es/components/line-chart/index.js +8 -0
  52. package/dist/es/components/line-chart/props.js +178 -0
  53. package/dist/es/components/pie-chart/PieChart.js +397 -0
  54. package/dist/es/components/pie-chart/index.js +8 -0
  55. package/dist/es/components/pie-chart/props.js +104 -0
  56. package/dist/es/components/trend-chart/components/TrendChart.js +143 -183
  57. package/dist/es/components/trend-chart/components/trend-chart-curve.js +85 -81
  58. package/dist/es/components/trend-chart/props.js +28 -74
  59. package/dist/es/components/trend-chart/themes.js +30 -31
  60. package/dist/es/index.js +193 -187
  61. package/dist/es/locale/en-US.js +8 -1
  62. package/dist/es/locale/zh-CN.js +8 -1
  63. package/dist/es/style.css +1 -1
  64. package/dist/index.cjs +4 -4
  65. package/dist/index.umd.js +4 -4
  66. package/dist/locale/interface.d.ts +13 -0
  67. package/dist/style/bar-chart.css +1 -0
  68. package/dist/style/bar-chart.js +2 -0
  69. package/dist/style/base.css +1 -1
  70. package/dist/style/heatmap.css +1 -1
  71. package/dist/style/line-chart.css +1 -0
  72. package/dist/style/line-chart.js +2 -0
  73. package/dist/style/pie-chart.css +1 -0
  74. package/dist/style/pie-chart.js +2 -0
  75. package/dist/style.css +1 -1
  76. package/dist/types.d.ts +3 -0
  77. package/package.json +1 -1
  78. package/volar.d.ts +3 -0
  79. package/dist/components/trend-chart/components/trend-chart-grid.d.ts +0 -55
  80. package/dist/components/trend-chart/components/trend-chart-labels.d.ts +0 -26
  81. package/dist/components/trend-chart/helpers/genPath.d.ts +0 -8
  82. package/dist/components/trend-chart/helpers/getPadding.d.ts +0 -8
  83. package/dist/components/trend-chart/helpers/validatePadding.d.ts +0 -2
  84. package/dist/es/components/trend-chart/components/trend-chart-grid.js +0 -62
  85. package/dist/es/components/trend-chart/components/trend-chart-labels.js +0 -75
  86. package/dist/es/components/trend-chart/helpers/genPath.js +0 -22
  87. package/dist/es/components/trend-chart/helpers/getPadding.js +0 -21
  88. package/dist/es/components/trend-chart/helpers/validatePadding.js +0 -7
@@ -0,0 +1,178 @@
1
+ import { definePropType as t } from "../../_utils/vue-eco.js";
2
+ import { defaultValueFormatter as a } from "../../_utils/chart/scale.js";
3
+ import { validatePadding as l } from "../../_utils/chart/padding.js";
4
+ const d = {
5
+ /**
6
+ * @zh 类目轴标签,与每个系列 data 的下标一一对应;缺省时按 1、2、3… 显示
7
+ * @en Category axis labels, aligned by index with each series data
8
+ */
9
+ categories: {
10
+ type: Array,
11
+ default: () => []
12
+ },
13
+ /**
14
+ * @zh 数据系列;单系列为普通折线,多系列可叠放或堆叠
15
+ * @en Data series; a single series renders a plain line, multiple series can
16
+ * overlap or stack
17
+ */
18
+ series: {
19
+ required: !0,
20
+ type: t(Array),
21
+ default: () => []
22
+ },
23
+ /**
24
+ * @zh 堆叠多系列;折线按值累加,面积按下界与上界填充(堆叠面积)
25
+ * @en Stack multiple series; lines accumulate and areas fill between the
26
+ * lower and upper bounds
27
+ * @defaultValue false
28
+ */
29
+ stack: {
30
+ type: Boolean,
31
+ default: !1
32
+ },
33
+ /**
34
+ * @zh 是否绘制面积填充
35
+ * @en Whether to fill the area under the line
36
+ * @defaultValue false
37
+ */
38
+ area: {
39
+ type: Boolean,
40
+ default: !1
41
+ },
42
+ /**
43
+ * @zh 平滑曲线
44
+ * @en Smooth curve
45
+ * @defaultValue true
46
+ */
47
+ smooth: {
48
+ type: Boolean,
49
+ default: !0
50
+ },
51
+ /**
52
+ * @zh 缺测点(null)是否跨过连接;默认断开,避免「没有数据」被画成跌到 0
53
+ * @en Whether null points are connected; by default the line breaks so that
54
+ * missing data is not drawn as a drop to zero
55
+ * @defaultValue false
56
+ */
57
+ connectNulls: {
58
+ type: Boolean,
59
+ default: !1
60
+ },
61
+ /**
62
+ * @zh 数据点显示策略:true 常显、false 不显示、auto 时点数少时常显
63
+ * @en Data point strategy: true always, false never, auto shows points when
64
+ * there are few of them
65
+ * @defaultValue 'auto'
66
+ */
67
+ showPoints: {
68
+ type: [Boolean, String],
69
+ default: "auto",
70
+ validator: (e) => typeof e == "boolean" || e === "auto"
71
+ },
72
+ /**
73
+ * @zh 图表高度,数字按 px 处理
74
+ * @en Chart height; numbers are treated as px
75
+ * @defaultValue 280
76
+ */
77
+ height: {
78
+ type: [Number, String],
79
+ default: 280
80
+ },
81
+ /**
82
+ * @zh 图表宽度,数字按 px 处理,默认撑满父容器
83
+ * @en Chart width; numbers are treated as px, defaults to filling the parent
84
+ * @defaultValue '100%'
85
+ */
86
+ width: {
87
+ type: [Number, String],
88
+ default: "100%"
89
+ },
90
+ /**
91
+ * @zh 数值轴上界;传入后不再自动计算「好看」的刻度
92
+ * @en Upper bound of the value axis; disables nice-tick calculation
93
+ */
94
+ max: {
95
+ type: Number
96
+ },
97
+ /**
98
+ * @zh 数值轴下界;数据含负值时自动扩展,也可手动锁定
99
+ * @en Lower bound of the value axis; expands automatically for negative data
100
+ */
101
+ min: {
102
+ type: Number
103
+ },
104
+ /**
105
+ * @zh 绘制边距,支持 1-4 个非负数字字符串或单个非负数字
106
+ * @en Plot padding; supports a single non-negative number or CSS-like 1-4 values
107
+ * @defaultValue '8'
108
+ */
109
+ padding: {
110
+ default: "8",
111
+ type: [String, Number],
112
+ validator(e) {
113
+ return l(e);
114
+ }
115
+ },
116
+ /**
117
+ * @zh 横向网格线配置
118
+ * @en Horizontal grid line options
119
+ */
120
+ grid: {
121
+ default: null,
122
+ type: t(Object)
123
+ },
124
+ /**
125
+ * @zh 坐标轴标签配置
126
+ * @en Axis label options
127
+ */
128
+ labels: {
129
+ default: null,
130
+ type: t(Object)
131
+ },
132
+ /**
133
+ * @zh 悬浮提示
134
+ * @en Hover tooltip
135
+ * @defaultValue true
136
+ */
137
+ tooltip: {
138
+ type: Boolean,
139
+ default: !0
140
+ },
141
+ /**
142
+ * @zh 图例;多系列时建议开启,点击图例项可临时隐藏/显示对应系列
143
+ * @en Legend; recommended for multiple series, clicking an item toggles the
144
+ * series visibility
145
+ * @defaultValue false
146
+ */
147
+ legend: {
148
+ type: Boolean,
149
+ default: !1
150
+ },
151
+ /**
152
+ * @zh 数值格式化函数,用于提示、图例与数值轴
153
+ * @en Value formatter used by tooltip, legend and the value axis
154
+ */
155
+ valueFormatter: {
156
+ type: Function,
157
+ default: a
158
+ },
159
+ /**
160
+ * @zh 加载中
161
+ * @en Loading state
162
+ * @defaultValue false
163
+ */
164
+ loading: {
165
+ type: [Boolean, Object],
166
+ default: !1
167
+ },
168
+ /**
169
+ * @zh 无障碍名称;设置后画布带 role="img"
170
+ * @en Accessible name; adds role="img" to the canvas when set
171
+ */
172
+ ariaLabel: {
173
+ type: String
174
+ }
175
+ };
176
+ export {
177
+ d as lineChartProps
178
+ };
@@ -0,0 +1,397 @@
1
+ import { defineComponent as se, createVNode as o, mergeProps as ce, Fragment as le, ref as U, reactive as de, computed as r, watch as ae } from "vue";
2
+ import { getComponentPrefix as ue, getClassNameMixin as he } from "../../_utils/config.js";
3
+ import { useLocale as me } from "../../locale/index.js";
4
+ import { isObject as fe } from "../../_utils/is.js";
5
+ import { useChartSize as ve } from "../../_hooks/use-chart-size.js";
6
+ import { getSeriesColor as ie } from "../_components/chart/colors.js";
7
+ import { Spin as xe } from "../spin/index.js";
8
+ import pe from "../_components/chart/ChartLegend.js";
9
+ import { pieChartProps as ge } from "./props.js";
10
+ import { describeArcSegment as be } from "../../_utils/chart/path.js";
11
+ const ye = 0.6, Ie = 160, oe = 10, we = 0.04, re = (l) => `${Math.round(l * 1e3) / 10}%`, $e = /* @__PURE__ */ se({
12
+ name: ue("PieChart"),
13
+ props: ge,
14
+ emits: {
15
+ /**
16
+ * @zh 点击分片时触发
17
+ * @en Emitted when a slice is clicked
18
+ */
19
+ "item-click": (l) => !0,
20
+ /**
21
+ * @zh 图例切换后触发,参数为当前可见的分片下标
22
+ * @en Emitted after a legend toggle, with the visible item indexes
23
+ */
24
+ "legend-change": (l) => !0
25
+ },
26
+ slots: Object,
27
+ setup(l, {
28
+ emit: g,
29
+ slots: L
30
+ }) {
31
+ const {
32
+ t: F
33
+ } = me(), s = he("pie-chart"), P = U(null), I = U(null), w = U(null), M = {
34
+ root: P,
35
+ canvas: I,
36
+ tooltip: w
37
+ }, i = de({
38
+ activeIndex: null,
39
+ hiddenIndexes: [],
40
+ keyboardActive: !1,
41
+ /** 悬浮提示的锚点(相对画布),由分片中心推算 */
42
+ pointer: {
43
+ x: 0,
44
+ y: 0
45
+ },
46
+ tooltipWidth: 0
47
+ }), {
48
+ size: h
49
+ } = ve({
50
+ elementRef: I,
51
+ width: () => l.width,
52
+ height: () => l.height
53
+ }), c = r(() => (l.data ?? []).map((e, t) => ({
54
+ name: e.name ?? String(t + 1),
55
+ value: Number.isFinite(e.value) && e.value > 0 ? e.value : 0
56
+ }))), u = r(() => c.value.length === 0 ? [] : c.value.map((e, t) => t).filter((e) => !i.hiddenIndexes.includes(e))), m = r(() => u.value.reduce((e, t) => {
57
+ var n;
58
+ return e + (((n = c.value[t]) == null ? void 0 : n.value) ?? 0);
59
+ }, 0)), R = r(() => m.value > 0), v = r(() => l.valueFormatter), S = r(() => typeof l.labels == "object" && l.labels ? l.labels : {}), $ = r(() => S.value.fontSize ?? 12), A = r(() => S.value.color ?? "var(--x-chart-color-axis-text)"), D = r(() => (typeof l.center == "object" && l.center ? l.center : {}).fontSize ?? 18), z = r(() => {
60
+ const e = l.innerRadius;
61
+ if (typeof e == "string" && e.endsWith("%")) {
62
+ const n = Number.parseFloat(e) / 100;
63
+ return Number.isFinite(n) ? Math.min(0.9, Math.max(0, n)) : 0;
64
+ }
65
+ const t = Number(e);
66
+ return Number.isFinite(t) && t > 0 ? t : 0;
67
+ }), b = r(() => {
68
+ const e = l.labels === !1 ? 0 : oe + 20, t = Math.min(h.width, h.height) - e * 2, n = Math.max(0, Math.min(Ie, t / 2)), a = z.value, d = typeof l.innerRadius == "string" && l.innerRadius.endsWith("%") ? n * a : Math.min(n * 0.9, a);
69
+ return {
70
+ cx: h.width / 2,
71
+ cy: h.height / 2,
72
+ radius: n,
73
+ inner: d
74
+ };
75
+ }), x = r(() => {
76
+ const e = m.value;
77
+ if (e <= 0) return [];
78
+ const n = u.value.filter((E) => {
79
+ var f;
80
+ return (((f = c.value[E]) == null ? void 0 : f.value) ?? 0) > 0;
81
+ }).length > 1 ? ye : 0, {
82
+ cx: a,
83
+ cy: d,
84
+ radius: p,
85
+ inner: T
86
+ } = b.value, J = [];
87
+ let H = -90;
88
+ return u.value.forEach((E) => {
89
+ const f = c.value[E];
90
+ if (!f || f.value <= 0) return;
91
+ const Y = f.value / e, Q = Y * 360, Z = H + n / 2, ee = H + Q - n / 2, te = (Z + ee) / 2, q = te * Math.PI / 180, ne = p + oe;
92
+ J.push({
93
+ index: E,
94
+ name: f.name,
95
+ value: f.value,
96
+ percent: Y,
97
+ color: ie(E),
98
+ d: be({
99
+ cx: a,
100
+ cy: d,
101
+ outerRadius: p,
102
+ innerRadius: T,
103
+ startAngle: Z,
104
+ endAngle: ee
105
+ }),
106
+ labelX: a + ne * Math.cos(q),
107
+ labelY: d + ne * Math.sin(q),
108
+ labelAnchor: Math.cos(q) >= 0 ? "start" : "end",
109
+ showLabel: Y >= we && l.labels !== !1,
110
+ midAngle: te
111
+ }), H += Q;
112
+ }), J;
113
+ }), k = (e) => ({
114
+ index: e.index,
115
+ name: e.name,
116
+ value: e.value,
117
+ percent: e.percent,
118
+ color: e.color,
119
+ total: m.value,
120
+ formatValue: v.value,
121
+ formatPercent: re
122
+ }), C = r(() => {
123
+ const e = i.activeIndex;
124
+ if (e === null) return null;
125
+ const t = x.value.find((n) => n.index === e);
126
+ return t ? k(t) : null;
127
+ }), _ = r(() => c.value.map((e, t) => ({
128
+ key: t,
129
+ name: e.name,
130
+ color: ie(t),
131
+ hidden: i.hiddenIndexes.includes(t),
132
+ value: `${v.value(e.value)}·${m.value > 0 ? re(e.value / m.value) : "0%"}`
133
+ }))), V = r(() => {
134
+ if (!C.value) return {};
135
+ const t = i.tooltipWidth / 2 || 0, n = t + 4, a = Math.max(n, h.width - t - 4), d = Math.min(Math.max(i.pointer.x, n), a), p = Math.max(8, i.pointer.y - 8);
136
+ return {
137
+ left: `${d}px`,
138
+ top: `${p}px`
139
+ };
140
+ }), W = (e) => {
141
+ const {
142
+ cx: t,
143
+ cy: n,
144
+ radius: a,
145
+ inner: d
146
+ } = b.value, p = e.midAngle * Math.PI / 180, T = d > 0 ? (a + d) / 2 : a * 0.62;
147
+ return {
148
+ x: t + T * Math.cos(p),
149
+ y: n + T * Math.sin(p)
150
+ };
151
+ };
152
+ ae(() => c.value.length, (e) => {
153
+ i.activeIndex !== null && i.activeIndex >= e && (i.activeIndex = null), i.hiddenIndexes = i.hiddenIndexes.filter((t) => t < e);
154
+ }), ae(() => i.activeIndex, (e) => {
155
+ var n;
156
+ if (e === null) return;
157
+ const t = x.value.find((a) => a.index === e);
158
+ if (t) {
159
+ const a = W(t);
160
+ i.pointer = a;
161
+ }
162
+ (n = window.requestAnimationFrame) == null || n.call(window, () => {
163
+ var d;
164
+ const a = ((d = w.value) == null ? void 0 : d.offsetWidth) ?? 0;
165
+ a !== i.tooltipWidth && (i.tooltipWidth = a);
166
+ });
167
+ });
168
+ const N = (e, t = !1) => {
169
+ i.keyboardActive = t, i.activeIndex = e;
170
+ }, y = () => {
171
+ i.activeIndex = null, i.keyboardActive = !1;
172
+ }, j = (e) => {
173
+ l.tooltip && N(e);
174
+ }, O = (e, t) => {
175
+ const n = x.value.find((a) => a.index === e);
176
+ n && g("item-click", {
177
+ ...k(n)
178
+ });
179
+ }, B = (e) => {
180
+ if (!l.tooltip) return;
181
+ const t = x.value;
182
+ if (!t.length) return;
183
+ const n = t.findIndex((d) => d.index === i.activeIndex);
184
+ let a = null;
185
+ if (e.key === "ArrowRight") a = (n + 1 + t.length) % t.length;
186
+ else if (e.key === "ArrowLeft") a = (n - 1 + t.length) % t.length;
187
+ else if (e.key === "Home") a = 0;
188
+ else if (e.key === "End") a = t.length - 1;
189
+ else if (e.key === "Escape") {
190
+ y();
191
+ return;
192
+ }
193
+ a !== null && (e.preventDefault(), N(t[a].index, !0));
194
+ }, G = (e) => {
195
+ const t = i.hiddenIndexes.includes(e) ? i.hiddenIndexes.filter((n) => n !== e) : [...i.hiddenIndexes, e];
196
+ i.hiddenIndexes = t, g("legend-change", c.value.map((n, a) => a).filter((n) => !t.includes(n)));
197
+ }, K = r(() => {
198
+ const e = C.value;
199
+ return !i.keyboardActive || !e ? "" : `${e.name}:${e.formatValue(e.value)},${e.formatPercent(e.percent)}`;
200
+ }), X = r(() => l.center !== !1 && b.value.inner > 0 && R.value);
201
+ return {
202
+ className: s,
203
+ state: i,
204
+ size: h,
205
+ refs: M,
206
+ slots: L,
207
+ t: F,
208
+ items: c,
209
+ visibleIndexes: u,
210
+ total: m,
211
+ hasData: R,
212
+ geometry: b,
213
+ segments: x,
214
+ activeData: C,
215
+ legendItems: _,
216
+ centerVisible: X,
217
+ labelFontSize: $,
218
+ labelColor: A,
219
+ centerFontSize: D,
220
+ formatValue: v,
221
+ tooltipStyle: V,
222
+ handleSegmentEnter: j,
223
+ handleClick: O,
224
+ handleKeydown: B,
225
+ clearActive: y,
226
+ toggleItem: G,
227
+ liveText: K,
228
+ setTooltipElement: (e) => {
229
+ w.value = e;
230
+ }
231
+ };
232
+ },
233
+ render() {
234
+ const {
235
+ className: l,
236
+ state: g,
237
+ size: L,
238
+ refs: F,
239
+ slots: s,
240
+ t: P,
241
+ items: I,
242
+ visibleIndexes: w,
243
+ total: M,
244
+ hasData: i,
245
+ geometry: h,
246
+ segments: c,
247
+ activeData: u,
248
+ legendItems: m,
249
+ centerVisible: R,
250
+ labelFontSize: v,
251
+ labelColor: S,
252
+ centerFontSize: $,
253
+ formatValue: A,
254
+ tooltipStyle: D,
255
+ handleSegmentEnter: z,
256
+ handleClick: b,
257
+ handleKeydown: x,
258
+ clearActive: k,
259
+ toggleItem: C,
260
+ liveText: _,
261
+ setTooltipElement: V
262
+ } = this, W = typeof this.width == "number" ? `${this.width}px` : this.width, N = typeof this.height == "number" ? `${this.height}px` : this.height, y = L.width > 0 && L.height > 0 && h.radius > 0, j = () => c.map((e) => {
263
+ const t = g.activeIndex === e.index, n = g.activeIndex !== null && !t;
264
+ return o("path", {
265
+ key: e.index,
266
+ class: [l.element("segment"), {
267
+ [l.is("active")]: t,
268
+ [l.is("dimmed")]: n
269
+ }],
270
+ d: e.d,
271
+ fill: e.color,
272
+ "data-pie-index": e.index,
273
+ onMouseenter: () => z(e.index),
274
+ onClick: (a) => b(e.index, a)
275
+ }, null);
276
+ }), O = () => this.labels === !1 || !y ? null : o("g", {
277
+ class: l.element("labels")
278
+ }, [c.filter((e) => e.showLabel).map((e) => {
279
+ const t = {
280
+ index: e.index,
281
+ name: e.name,
282
+ value: e.value,
283
+ percent: e.percent,
284
+ color: e.color,
285
+ total: M,
286
+ formatValue: A,
287
+ formatPercent: (n) => `${Math.round(n * 1e3) / 10}%`
288
+ };
289
+ return o("text", {
290
+ key: e.index,
291
+ class: l.element("label"),
292
+ x: e.labelX,
293
+ y: e.labelY,
294
+ "text-anchor": e.labelAnchor,
295
+ "dominant-baseline": "middle",
296
+ style: {
297
+ fontSize: `${v}px`,
298
+ fill: S
299
+ }
300
+ }, [s.label ? s.label(t) : e.name]);
301
+ })]), B = () => !R || !y ? null : s.center ? o("g", {
302
+ class: l.element("center")
303
+ }, [s.center({
304
+ total: M,
305
+ formatValue: A
306
+ })]) : o("g", {
307
+ class: l.element("center")
308
+ }, [o("text", {
309
+ class: l.element("center-label"),
310
+ x: h.cx,
311
+ y: h.cy - v * 0.7,
312
+ "text-anchor": "middle",
313
+ style: {
314
+ fontSize: `${v}px`,
315
+ fill: S
316
+ }
317
+ }, [P("chart.pieTotal")]), o("text", {
318
+ class: l.element("center-value"),
319
+ x: h.cx,
320
+ y: h.cy + $ * 0.7,
321
+ "text-anchor": "middle",
322
+ style: {
323
+ fontSize: `${$}px`,
324
+ fill: "var(--x-color-text-1)"
325
+ }
326
+ }, [A(M)])]), G = () => !this.legend || I.length === 0 ? null : o(pe, {
327
+ items: m,
328
+ onToggle: C
329
+ }, s.legend ? {
330
+ default: () => {
331
+ var e;
332
+ return (e = s.legend) == null ? void 0 : e.call(s, {
333
+ items: I,
334
+ hiddenIndexes: g.hiddenIndexes
335
+ });
336
+ }
337
+ } : void 0), K = () => !this.tooltip || !u ? null : o("div", {
338
+ ref: V,
339
+ class: ["x-chart--tooltip", l.is("visible")],
340
+ style: D,
341
+ role: "tooltip"
342
+ }, [s.tooltip ? s.tooltip(u) : o(le, null, [o("div", {
343
+ class: "x-chart--tooltip-title"
344
+ }, [u.name]), o("div", {
345
+ class: "x-chart--tooltip-list"
346
+ }, [o("div", {
347
+ class: "x-chart--tooltip-item"
348
+ }, [o("span", {
349
+ class: "x-chart--tooltip-swatch",
350
+ style: {
351
+ backgroundColor: u.color
352
+ }
353
+ }, null), o("span", {
354
+ class: "x-chart--tooltip-name"
355
+ }, [u.formatValue(u.value)]), o("span", {
356
+ class: "x-chart--tooltip-value"
357
+ }, [u.formatPercent(u.percent)])])])])]), X = () => i && w.length > 0 ? null : o("div", {
358
+ class: "x-chart--empty"
359
+ }, [s.empty ? s.empty() : P("common.noData")]);
360
+ return o("div", {
361
+ ref: F.root,
362
+ class: l.block
363
+ }, [o(xe, ce(fe(this.loading) ? this.loading : {
364
+ loading: this.loading
365
+ }, {
366
+ display: "block"
367
+ }), {
368
+ default: () => [o("div", {
369
+ ref: F.canvas,
370
+ class: l.element("canvas"),
371
+ role: this.ariaLabel ? "img" : void 0,
372
+ "aria-label": this.ariaLabel
373
+ }, [o("svg", {
374
+ class: l.element("svg"),
375
+ xmlns: "http://www.w3.org/2000/svg",
376
+ style: {
377
+ width: W,
378
+ height: N
379
+ },
380
+ "aria-hidden": this.ariaLabel ? "true" : void 0,
381
+ tabindex: this.tooltip ? 0 : void 0,
382
+ onMouseleave: k,
383
+ onBlur: k,
384
+ onFocus: () => {
385
+ c.length && z(c[0].index);
386
+ },
387
+ onKeydown: x
388
+ }, [y && o(le, null, [j(), O(), B()])]), K(), X()])]
389
+ }), G(), o("span", {
390
+ class: "x-chart--live",
391
+ "aria-live": "polite"
392
+ }, [_])]);
393
+ }
394
+ });
395
+ export {
396
+ $e as default
397
+ };
@@ -0,0 +1,8 @@
1
+ import t from "./PieChart.js";
2
+ import { generateComponent as e } from "../../_utils/vue-eco.js";
3
+ import { getComponentPrefix as o } from "../../_utils/config.js";
4
+ const a = e(o("PieChart"), t);
5
+ export {
6
+ a as PieChart,
7
+ a as default
8
+ };
@@ -0,0 +1,104 @@
1
+ import { definePropType as e } from "../../_utils/vue-eco.js";
2
+ import { defaultValueFormatter as t } from "../../_utils/chart/scale.js";
3
+ const l = {
4
+ /**
5
+ * @zh 分片数据;值为负或非有限数按 0 处理并跳过
6
+ * @en Slice data; negative or non-finite values are treated as 0 and skipped
7
+ */
8
+ data: {
9
+ required: !0,
10
+ type: e(Array),
11
+ default: () => []
12
+ },
13
+ /**
14
+ * @zh 内半径:0 为实心饼图,数字按 px,'60%' 按外半径比例;大于 0 时渲染为环形图
15
+ * @en Inner radius: 0 renders a pie, numbers are px, '60%' is relative to the
16
+ * outer radius; values above 0 render a donut
17
+ * @defaultValue 0
18
+ */
19
+ innerRadius: {
20
+ type: [Number, String],
21
+ default: 0
22
+ },
23
+ /**
24
+ * @zh 图表高度,数字按 px 处理
25
+ * @en Chart height; numbers are treated as px
26
+ * @defaultValue 280
27
+ */
28
+ height: {
29
+ type: [Number, String],
30
+ default: 280
31
+ },
32
+ /**
33
+ * @zh 图表宽度,数字按 px 处理,默认撑满父容器
34
+ * @en Chart width; numbers are treated as px, defaults to filling the parent
35
+ * @defaultValue '100%'
36
+ */
37
+ width: {
38
+ type: [Number, String],
39
+ default: "100%"
40
+ },
41
+ /**
42
+ * @zh 外围标签:false 不显示,也可传字号与颜色
43
+ * @en Outer labels: false hides them; an object configures font size and color
44
+ * @defaultValue true
45
+ */
46
+ labels: {
47
+ type: [Boolean, Object],
48
+ default: !0
49
+ },
50
+ /**
51
+ * @zh 环形中心内容;不传时在环形模式下展示合计,传 false 隐藏
52
+ * @en Donut center content; defaults to the total for donuts, false hides it
53
+ * @defaultValue true
54
+ */
55
+ center: {
56
+ type: [Boolean, Object],
57
+ default: !0
58
+ },
59
+ /**
60
+ * @zh 悬浮提示
61
+ * @en Hover tooltip
62
+ * @defaultValue true
63
+ */
64
+ tooltip: {
65
+ type: Boolean,
66
+ default: !0
67
+ },
68
+ /**
69
+ * @zh 图例;点击图例项可临时隐藏/显示对应分片,数据在点击分片上触发
70
+ * @en Legend; clicking an item toggles the slice visibility
71
+ * @defaultValue false
72
+ */
73
+ legend: {
74
+ type: Boolean,
75
+ default: !1
76
+ },
77
+ /**
78
+ * @zh 数值格式化函数,用于提示、图例与中心内容
79
+ * @en Value formatter used by tooltip, legend and the center content
80
+ */
81
+ valueFormatter: {
82
+ type: Function,
83
+ default: t
84
+ },
85
+ /**
86
+ * @zh 加载中
87
+ * @en Loading state
88
+ * @defaultValue false
89
+ */
90
+ loading: {
91
+ type: [Boolean, Object],
92
+ default: !1
93
+ },
94
+ /**
95
+ * @zh 无障碍名称;设置后画布带 role="img"
96
+ * @en Accessible name; adds role="img" to the canvas when set
97
+ */
98
+ ariaLabel: {
99
+ type: String
100
+ }
101
+ };
102
+ export {
103
+ l as pieChartProps
104
+ };