@aura-react-comp/charts 0.2.0 → 0.4.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 (98) hide show
  1. package/esm/charts/area-chart/index.d.ts +2 -2
  2. package/esm/charts/area-chart/index.js +28 -23
  3. package/esm/charts/bar-chart/index.d.ts +1 -1
  4. package/esm/charts/bar-chart/index.js +18 -21
  5. package/esm/charts/candlestick-chart/index.d.ts +2 -2
  6. package/esm/charts/candlestick-chart/index.js +243 -180
  7. package/esm/charts/combo-chart/index.d.ts +1 -1
  8. package/esm/charts/combo-chart/index.js +9 -20
  9. package/esm/charts/funnel-chart/index.d.ts +2 -2
  10. package/esm/charts/funnel-chart/index.js +134 -108
  11. package/esm/charts/gauge-chart/index.d.ts +1 -1
  12. package/esm/charts/gauge-chart/index.js +103 -105
  13. package/esm/charts/graph-chart/index.d.ts +3 -3
  14. package/esm/charts/graph-chart/index.js +155 -114
  15. package/esm/charts/heatmap-chart/index.d.ts +2 -2
  16. package/esm/charts/heatmap-chart/index.js +180 -135
  17. package/esm/charts/line-chart/index.d.ts +2 -2
  18. package/esm/charts/line-chart/index.js +29 -24
  19. package/esm/charts/pie-chart/index.d.ts +2 -2
  20. package/esm/charts/pie-chart/index.d.ts.map +1 -1
  21. package/esm/charts/pie-chart/index.js +199 -139
  22. package/esm/charts/radar-chart/index.d.ts +2 -2
  23. package/esm/charts/radar-chart/index.d.ts.map +1 -1
  24. package/esm/charts/radar-chart/index.js +155 -128
  25. package/esm/charts/ring-progress/index.d.ts +1 -1
  26. package/esm/charts/ring-progress/index.js +82 -82
  27. package/esm/charts/sankey-chart/index.d.ts +3 -3
  28. package/esm/charts/sankey-chart/index.js +172 -141
  29. package/esm/charts/scatter-chart/index.d.ts +3 -3
  30. package/esm/charts/scatter-chart/index.d.ts.map +1 -1
  31. package/esm/charts/scatter-chart/index.js +226 -159
  32. package/esm/charts/sparkline/index.d.ts +1 -1
  33. package/esm/charts/sparkline/index.js +82 -66
  34. package/esm/charts/tree-chart/index.d.ts +3 -3
  35. package/esm/charts/tree-chart/index.js +129 -102
  36. package/esm/charts/treemap-chart/index.d.ts +3 -3
  37. package/esm/charts/treemap-chart/index.js +163 -141
  38. package/esm/charts/waterfall-chart/index.d.ts +2 -2
  39. package/esm/charts/waterfall-chart/index.js +166 -121
  40. package/esm/components/Legend.d.ts +5 -4
  41. package/esm/components/Legend.d.ts.map +1 -1
  42. package/esm/components/Legend.js +80 -48
  43. package/esm/components/Tooltip.d.ts +2 -2
  44. package/esm/components/Tooltip.js +63 -71
  45. package/esm/components/chart/index.d.ts +5 -2
  46. package/esm/components/chart/index.d.ts.map +1 -1
  47. package/esm/components/chart/index.js +81 -102
  48. package/esm/components/chart.less +13 -0
  49. package/esm/core/animation.js +32 -43
  50. package/esm/core/export.d.ts +34 -0
  51. package/esm/core/export.d.ts.map +1 -0
  52. package/esm/core/export.js +390 -0
  53. package/esm/core/force.js +23 -45
  54. package/esm/core/format.js +49 -52
  55. package/esm/core/hierarchy.d.ts +1 -1
  56. package/esm/core/hierarchy.js +61 -92
  57. package/esm/core/layout.d.ts +1 -1
  58. package/esm/core/layout.js +33 -50
  59. package/esm/core/sampling.js +31 -53
  60. package/esm/core/sankey.js +36 -55
  61. package/esm/core/scale.js +73 -86
  62. package/esm/core/shape.js +102 -133
  63. package/esm/core/sync.d.ts +41 -0
  64. package/esm/core/sync.d.ts.map +1 -0
  65. package/esm/core/sync.js +120 -0
  66. package/esm/hooks/useChartExport.d.ts +19 -0
  67. package/esm/hooks/useChartExport.d.ts.map +1 -0
  68. package/esm/hooks/useChartExport.js +35 -0
  69. package/esm/hooks/useChartTheme.d.ts +6 -5
  70. package/esm/hooks/useChartTheme.d.ts.map +1 -1
  71. package/esm/hooks/useChartTheme.js +18 -18
  72. package/esm/hooks/useChartTransition.d.ts +1 -1
  73. package/esm/hooks/useChartTransition.js +59 -73
  74. package/esm/hooks/useElementSize.js +20 -28
  75. package/esm/hooks/usePlotPointer.d.ts +23 -0
  76. package/esm/hooks/usePlotPointer.d.ts.map +1 -0
  77. package/esm/hooks/usePlotPointer.js +94 -0
  78. package/esm/index.d.ts +56 -50
  79. package/esm/index.d.ts.map +1 -1
  80. package/esm/index.js +137 -47
  81. package/esm/internal/CartesianChart.d.ts +1 -1
  82. package/esm/internal/CartesianChart.d.ts.map +1 -1
  83. package/esm/internal/CartesianChart.js +667 -485
  84. package/esm/internal/model.d.ts +2 -2
  85. package/esm/internal/model.js +45 -60
  86. package/esm/scene/canvas.d.ts +1 -1
  87. package/esm/scene/canvas.js +101 -107
  88. package/esm/scene/svg.d.ts +1 -1
  89. package/esm/scene/svg.js +107 -99
  90. package/esm/scene/types.js +9 -15
  91. package/esm/style.css +10 -0
  92. package/esm/theme/index.d.ts +2 -2
  93. package/esm/theme/index.d.ts.map +1 -1
  94. package/esm/theme/index.js +145 -170
  95. package/esm/types.d.ts +7 -3
  96. package/esm/types.d.ts.map +1 -1
  97. package/esm/types.js +1 -1
  98. package/package.json +2 -2
@@ -1,7 +1,13 @@
1
- import React, { useMemo, useState } from 'react';
2
- import { classNames, prefixCls } from '@aura-react-comp/shared';
1
+ 'use client';
2
+ // src/charts/waterfall-chart/index.tsx
3
+ import { useMemo, useState } from "react";
4
+ import { classNames, prefixCls } from "@aura-react-comp/shared";
3
5
  import { SvgScene } from "../../scene/svg";
4
- import { createBandScale, createLinearScale, linearTicks } from "../../core/scale";
6
+ import {
7
+ createBandScale,
8
+ createLinearScale,
9
+ linearTicks
10
+ } from "../../core/scale";
5
11
  import { computeLayout, suggestTickCount } from "../../core/layout";
6
12
  import { formatNumber } from "../../core/format";
7
13
  import { roundedRectPath } from "../../core/shape";
@@ -11,21 +17,13 @@ import { useElementSize } from "../../hooks/useElementSize";
11
17
  import { useChartTransition } from "../../hooks/useChartTransition";
12
18
  import { resolveAnimation, staggerProgress } from "../../core/animation";
13
19
  import { Tooltip } from "../../components/Tooltip";
14
- import { jsx as _jsx } from "react/jsx-runtime";
15
- import { jsxs as _jsxs } from "react/jsx-runtime";
16
- /**
17
- * 瀑布图。
18
- *
19
- * 用柱子的「起点 + 终点」表达增减过程,最后落到总计。
20
- * 与堆叠柱的区别:堆叠柱的每段都从 0 起算的相对量,瀑布图的每一段都是**增量**,
21
- * 位置取决于此前所有项的累计。
22
- */
23
- export function WaterfallChart({
20
+ import { jsx, jsxs } from "react/jsx-runtime";
21
+ function WaterfallChart({
24
22
  data = [],
25
- width = '100%',
23
+ width = "100%",
26
24
  height = 320,
27
25
  positiveColor,
28
- negativeColor = '#ef4444',
26
+ negativeColor = "#ef4444",
29
27
  totalColor,
30
28
  connector = true,
31
29
  theme: themeInput,
@@ -35,19 +33,16 @@ export function WaterfallChart({
35
33
  className,
36
34
  style,
37
35
  ariaLabel,
38
- emptyText = '暂无数据'
36
+ emptyText = "暂无数据"
39
37
  }) {
40
38
  const theme = useChartTheme(themeInput, palette);
41
- const {
42
- ref,
43
- size
44
- } = useElementSize();
39
+ const { ref, size } = useElementSize();
45
40
  const [activeIndex, setActiveIndex] = useState(null);
46
41
  const rows = useMemo(() => {
47
42
  const up = positiveColor ?? colorAt(theme, 0);
48
43
  const total = totalColor ?? colorAt(theme, 1);
49
44
  let running = 0;
50
- return data.map(item => {
45
+ return data.map((item) => {
51
46
  if (item.isTotal) {
52
47
  const row = {
53
48
  name: item.name,
@@ -72,7 +67,8 @@ export function WaterfallChart({
72
67
  });
73
68
  }, [data, positiveColor, negativeColor, totalColor, theme]);
74
69
  const domain = useMemo(() => {
75
- if (!rows.length) return [0, 1];
70
+ if (!rows.length)
71
+ return [0, 1];
76
72
  let min = 0;
77
73
  let max = 0;
78
74
  for (const row of rows) {
@@ -81,43 +77,61 @@ export function WaterfallChart({
81
77
  }
82
78
  return min === max ? [0, max + 1] : [min, max];
83
79
  }, [rows]);
84
- const yTicks = useMemo(() => linearTicks(domain[0], domain[1], suggestTickCount(Math.max(60, height - 48))), [domain, height]);
85
- const yLabels = useMemo(() => yTicks.map(tick => formatNumber(tick)), [yTicks]);
86
- const layout = useMemo(() => computeLayout({
87
- width: Math.max(size.width, 0),
88
- height: Math.max(size.height, 0),
89
- yLabels,
90
- xLabels: rows.map(row => row.name),
91
- theme
92
- }), [size.width, size.height, yLabels, rows, theme]);
93
- const {
94
- plot
95
- } = layout;
96
- const xScale = useMemo(() => createBandScale({
97
- domain: rows.map(row => row.name),
98
- range: [plot.x, plot.x + plot.width],
99
- paddingInner: 0.36,
100
- paddingOuter: 0.12
101
- }), [rows, plot.x, plot.width]);
102
- const yScale = useMemo(() => createLinearScale({
103
- domain,
104
- range: [plot.y + plot.height, plot.y]
105
- }), [domain, plot.y, plot.height]);
106
- const animKey = typeof animation === 'object' ? JSON.stringify(animation) : String(animation);
107
- const animConfig = useMemo(() => resolveAnimation(animation),
108
- // eslint-disable-next-line react-hooks/exhaustive-deps
109
- [animKey]);
110
-
111
- // 每根柱子用 [起点, 终点] 两个数描述,插值时两端一起平滑移动
112
- const valueMatrix = useMemo(() => rows.map(row => [row.start, row.end]), [rows]);
80
+ const yTicks = useMemo(
81
+ () => linearTicks(
82
+ domain[0],
83
+ domain[1],
84
+ suggestTickCount(Math.max(60, height - 48))
85
+ ),
86
+ [domain, height]
87
+ );
88
+ const yLabels = useMemo(
89
+ () => yTicks.map((tick) => formatNumber(tick)),
90
+ [yTicks]
91
+ );
92
+ const layout = useMemo(
93
+ () => computeLayout({
94
+ width: Math.max(size.width, 0),
95
+ height: Math.max(size.height, 0),
96
+ yLabels,
97
+ xLabels: rows.map((row) => row.name),
98
+ theme
99
+ }),
100
+ [size.width, size.height, yLabels, rows, theme]
101
+ );
102
+ const { plot } = layout;
103
+ const xScale = useMemo(
104
+ () => createBandScale({
105
+ domain: rows.map((row) => row.name),
106
+ range: [plot.x, plot.x + plot.width],
107
+ paddingInner: 0.36,
108
+ paddingOuter: 0.12
109
+ }),
110
+ [rows, plot.x, plot.width]
111
+ );
112
+ const yScale = useMemo(
113
+ () => createLinearScale({ domain, range: [plot.y + plot.height, plot.y] }),
114
+ [domain, plot.y, plot.height]
115
+ );
116
+ const animKey = typeof animation === "object" ? JSON.stringify(animation) : String(animation);
117
+ const animConfig = useMemo(
118
+ () => resolveAnimation(animation),
119
+ // eslint-disable-next-line react-hooks/exhaustive-deps
120
+ [animKey]
121
+ );
122
+ const valueMatrix = useMemo(
123
+ () => rows.map((row) => [row.start, row.end]),
124
+ [rows]
125
+ );
113
126
  const transition = useChartTransition(valueMatrix, animConfig);
114
127
  const progress = transition.progress;
115
128
  const scene = useMemo(() => {
116
- if (!rows.length || plot.width <= 0) return [];
129
+ if (!rows.length || plot.width <= 0)
130
+ return [];
117
131
  const nodes = [];
118
132
  yTicks.forEach((tick, index) => {
119
133
  nodes.push({
120
- kind: 'line',
134
+ kind: "line",
121
135
  key: `grid-${index}`,
122
136
  x1: plot.x,
123
137
  y1: yScale.scale(tick),
@@ -125,27 +139,25 @@ export function WaterfallChart({
125
139
  y2: yScale.scale(tick),
126
140
  stroke: theme.grid.line,
127
141
  strokeWidth: theme.grid.lineWidth,
128
- strokeDasharray: theme.grid.dash.join(' ') || undefined
142
+ strokeDasharray: theme.grid.dash.join(" ") || void 0
129
143
  });
130
144
  nodes.push({
131
- kind: 'text',
145
+ kind: "text",
132
146
  key: `yl-${index}`,
133
147
  x: plot.x - theme.axis.tickSize - 4,
134
148
  y: yScale.scale(tick),
135
149
  text: yLabels[index],
136
150
  fill: theme.axis.label,
137
151
  fontSize: theme.font.size,
138
- anchor: 'end',
139
- baseline: 'middle',
152
+ anchor: "end",
153
+ baseline: "middle",
140
154
  fontFamily: theme.font.family
141
155
  });
142
156
  });
143
-
144
- // 零基线(负值场景下必须显式画出)
145
157
  if (domain[0] < 0) {
146
158
  nodes.push({
147
- kind: 'line',
148
- key: 'zero',
159
+ kind: "line",
160
+ key: "zero",
149
161
  x1: plot.x,
150
162
  y1: yScale.scale(0),
151
163
  x2: plot.x + plot.width,
@@ -156,12 +168,18 @@ export function WaterfallChart({
156
168
  }
157
169
  const barWidth = Math.min(xScale.bandWidth, 56);
158
170
  rows.forEach((row, index) => {
171
+ var _a, _b;
159
172
  const cx = xScale.center(row.name);
160
- if (cx === undefined) return;
161
- // 逐柱错峰 + 从各自起点生长(不是整排从底部弹起)
162
- const local = staggerProgress(progress, index, rows.length, animConfig.stagger);
163
- const animatedStart = transition.values[index]?.[0] ?? row.start;
164
- const animatedEnd = transition.values[index]?.[1] ?? row.end;
173
+ if (cx === void 0)
174
+ return;
175
+ const local = staggerProgress(
176
+ progress,
177
+ index,
178
+ rows.length,
179
+ animConfig.stagger
180
+ );
181
+ const animatedStart = ((_a = transition.values[index]) == null ? void 0 : _a[0]) ?? row.start;
182
+ const animatedEnd = ((_b = transition.values[index]) == null ? void 0 : _b[1]) ?? row.end;
165
183
  const drawnEnd = animatedStart + (animatedEnd - animatedStart) * local;
166
184
  const top = yScale.scale(drawnEnd);
167
185
  const bottom = yScale.scale(animatedStart);
@@ -169,7 +187,7 @@ export function WaterfallChart({
169
187
  const h = Math.max(2, Math.abs(bottom - top));
170
188
  const isActive = activeIndex === index;
171
189
  nodes.push({
172
- kind: 'path',
190
+ kind: "path",
173
191
  key: `bar-${index}`,
174
192
  d: roundedRectPath(cx - barWidth / 2, y, barWidth, h, 3, {
175
193
  tl: true,
@@ -177,17 +195,15 @@ export function WaterfallChart({
177
195
  }),
178
196
  fill: row.color,
179
197
  opacity: activeIndex === null || isActive ? 1 : 0.55,
180
- pointerEvents: 'none'
198
+ pointerEvents: "none"
181
199
  });
182
-
183
- // 连接线:从前一根柱的终点水平引到本柱起点
184
200
  if (connector && index > 0) {
185
201
  const prev = rows[index - 1];
186
202
  const prevCx = xScale.center(prev.name);
187
- if (prevCx !== undefined) {
203
+ if (prevCx !== void 0) {
188
204
  const linkY = yScale.scale(prev.end);
189
205
  nodes.push({
190
- kind: 'line',
206
+ kind: "line",
191
207
  key: `link-${index}`,
192
208
  x1: prevCx + barWidth / 2,
193
209
  y1: linkY,
@@ -195,35 +211,51 @@ export function WaterfallChart({
195
211
  y2: linkY,
196
212
  stroke: theme.axis.line,
197
213
  strokeWidth: 1,
198
- strokeDasharray: '3 3',
199
- pointerEvents: 'none'
214
+ strokeDasharray: "3 3",
215
+ pointerEvents: "none"
200
216
  });
201
217
  }
202
218
  }
203
219
  nodes.push({
204
- kind: 'text',
220
+ kind: "text",
205
221
  key: `xlabel-${index}`,
206
222
  x: cx,
207
223
  y: plot.y + plot.height + theme.axis.tickSize + theme.font.size,
208
224
  text: row.name,
209
225
  fill: theme.axis.label,
210
226
  fontSize: theme.font.size,
211
- anchor: 'middle',
227
+ anchor: "middle",
212
228
  fontFamily: theme.font.family
213
229
  });
214
230
  });
215
231
  return nodes;
216
- }, [rows, plot, yTicks, yLabels, yScale, xScale, theme, progress, activeIndex, domain, connector, transition.values, animConfig.stagger]);
217
- const indexFromPointer = clientX => {
232
+ }, [
233
+ rows,
234
+ plot,
235
+ yTicks,
236
+ yLabels,
237
+ yScale,
238
+ xScale,
239
+ theme,
240
+ progress,
241
+ activeIndex,
242
+ domain,
243
+ connector,
244
+ transition.values,
245
+ animConfig.stagger
246
+ ]);
247
+ const indexFromPointer = (clientX) => {
218
248
  const element = ref.current;
219
- if (!element || !rows.length) return null;
249
+ if (!element || !rows.length)
250
+ return null;
220
251
  const rect = element.getBoundingClientRect();
221
252
  const localX = clientX - rect.left;
222
253
  let nearest = null;
223
254
  let min = Infinity;
224
255
  rows.forEach((row, index) => {
225
256
  const cx = xScale.center(row.name);
226
- if (cx === undefined) return;
257
+ if (cx === void 0)
258
+ return;
227
259
  const distance = Math.abs(cx - localX);
228
260
  if (distance < min) {
229
261
  min = distance;
@@ -236,45 +268,58 @@ export function WaterfallChart({
236
268
  const tooltipPayload = active ? {
237
269
  label: active.name,
238
270
  row: null,
239
- series: [{
240
- key: active.name,
241
- name: active.isTotal ? '累计' : '增减',
242
- color: active.color,
243
- value: active.isTotal ? active.end : active.value,
244
- formatted: formatNumber(active.isTotal ? active.end : active.value)
245
- }]
271
+ series: [
272
+ {
273
+ key: active.name,
274
+ name: active.isTotal ? "累计" : "增减",
275
+ color: active.color,
276
+ value: active.isTotal ? active.end : active.value,
277
+ formatted: formatNumber(active.isTotal ? active.end : active.value)
278
+ }
279
+ ]
246
280
  } : null;
247
- const autoAriaLabel = ariaLabel ?? `瀑布图:${rows.map(row => row.name).join('、')}`;
248
- return /*#__PURE__*/_jsx("div", {
249
- className: classNames(prefixCls('chart'), className),
250
- style: {
251
- width,
252
- height,
253
- ...style
254
- },
255
- "data-aura-chart": "waterfall",
256
- children: /*#__PURE__*/_jsxs("div", {
257
- ref: ref,
258
- className: prefixCls('chart__plot'),
259
- onPointerMove: event => setActiveIndex(indexFromPointer(event.clientX)),
260
- onPointerLeave: () => setActiveIndex(null),
261
- children: [rows.length === 0 || size.width === 0 ? /*#__PURE__*/_jsx("div", {
262
- className: prefixCls('chart__empty'),
263
- children: emptyText
264
- }) : /*#__PURE__*/_jsx(SvgScene, {
265
- nodes: scene,
266
- width: size.width,
267
- height: size.height,
268
- ariaLabel: autoAriaLabel
269
- }), /*#__PURE__*/_jsx(Tooltip, {
270
- payload: tooltipPayload,
271
- x: active ? xScale.center(active.name) ?? 0 : 0,
272
- y: active ? yScale.scale(Math.max(active.start, active.end)) - 10 : 0,
273
- containerWidth: size.width,
274
- containerHeight: size.height,
275
- theme: theme,
276
- config: tooltip
277
- })]
278
- })
279
- });
280
- }
281
+ const autoAriaLabel = ariaLabel ?? `瀑布图:${rows.map((row) => row.name).join("、")}`;
282
+ return /* @__PURE__ */ jsx(
283
+ "div",
284
+ {
285
+ className: classNames(prefixCls("chart"), className),
286
+ style: { width, height, ...style },
287
+ "data-aura-chart": "waterfall",
288
+ children: /* @__PURE__ */ jsxs(
289
+ "div",
290
+ {
291
+ ref,
292
+ className: prefixCls("chart__plot"),
293
+ onPointerMove: (event) => setActiveIndex(indexFromPointer(event.clientX)),
294
+ onPointerLeave: () => setActiveIndex(null),
295
+ children: [
296
+ rows.length === 0 || size.width === 0 ? /* @__PURE__ */ jsx("div", { className: prefixCls("chart__empty"), children: emptyText }) : /* @__PURE__ */ jsx(
297
+ SvgScene,
298
+ {
299
+ nodes: scene,
300
+ width: size.width,
301
+ height: size.height,
302
+ ariaLabel: autoAriaLabel
303
+ }
304
+ ),
305
+ /* @__PURE__ */ jsx(
306
+ Tooltip,
307
+ {
308
+ payload: tooltipPayload,
309
+ x: active ? xScale.center(active.name) ?? 0 : 0,
310
+ y: active ? yScale.scale(Math.max(active.start, active.end)) - 10 : 0,
311
+ containerWidth: size.width,
312
+ containerHeight: size.height,
313
+ theme,
314
+ config: tooltip
315
+ }
316
+ )
317
+ ]
318
+ }
319
+ )
320
+ }
321
+ );
322
+ }
323
+ export {
324
+ WaterfallChart
325
+ };
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- import type { ChartTheme } from '../theme';
3
- import type { LegendConfig } from '../types';
2
+ import type { ChartTheme } from '../theme/index.js';
3
+ import type { LegendConfig } from '../types.js';
4
4
  export interface LegendItem {
5
5
  key: string;
6
6
  name: string;
@@ -11,13 +11,14 @@ export interface LegendProps {
11
11
  items: LegendItem[];
12
12
  theme: ChartTheme;
13
13
  config?: boolean | LegendConfig;
14
- onToggle: (key: string) => void;
14
+ /** 点击切换系列显隐回调;未传或 selectable=false 时仅作静态展示 */
15
+ onToggle?: (key: string) => void;
15
16
  }
16
17
  /**
17
18
  * 图例。
18
19
  *
19
20
  * 刻意用 DOM 而不是画进 SVG:
20
- * · 可以用原生 button,键盘可达、可聚焦,天然符合无障碍要求;
21
+ * · 可筛选时用原生 button,键盘可达、可聚焦,天然符合无障碍要求;
21
22
  * · 换行、省略号交给 CSS,省去手写文本换行计算。
22
23
  */
23
24
  export declare function Legend({ items, theme, config, onToggle }: LegendProps): React.JSX.Element | null;
@@ -1 +1 @@
1
- {"version":3,"file":"Legend.d.ts","sourceRoot":"","sources":["Legend.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;IAChC,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,WAAW,4BA8CrE"}
1
+ {"version":3,"file":"Legend.d.ts","sourceRoot":"","sources":["Legend.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;IAChC,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,WAAW,4BA2ErE"}
@@ -1,49 +1,81 @@
1
- import React from 'react';
2
- import { classNames, prefixCls } from '@aura-react-comp/shared';
3
- import { jsx as _jsx } from "react/jsx-runtime";
4
- import { jsxs as _jsxs } from "react/jsx-runtime";
5
- /**
6
- * 图例。
7
- *
8
- * 刻意用 DOM 而不是画进 SVG:
9
- * · 可以用原生 button,键盘可达、可聚焦,天然符合无障碍要求;
10
- * · 换行、省略号交给 CSS,省去手写文本换行计算。
11
- */
12
- export function Legend({
13
- items,
14
- theme,
15
- config,
16
- onToggle
17
- }) {
18
- if (config === false || items.length === 0) return null;
19
- const options = typeof config === 'object' ? config : {};
20
- const {
21
- position = 'top',
22
- align = 'left'
23
- } = options;
24
- if (options.show === false) return null;
25
- return /*#__PURE__*/_jsx("div", {
26
- className: classNames(prefixCls('chart__legend'), position === 'bottom' && prefixCls('chart__legend--bottom'), align !== 'left' && prefixCls(`chart__legend--${align}`)),
27
- role: "group",
28
- "aria-label": "\u56FE\u4F8B",
29
- children: items.map(item => /*#__PURE__*/_jsxs("button", {
30
- type: "button",
31
- className: classNames(prefixCls('chart__legend-item'), !item.visible && prefixCls('chart__legend-item--inactive')),
32
- "aria-pressed": item.visible,
33
- title: `${item.visible ? '隐藏' : '显示'} ${item.name}`,
34
- onClick: () => onToggle(item.key),
35
- children: [/*#__PURE__*/_jsx("span", {
36
- className: prefixCls('chart__legend-dot'),
37
- style: {
38
- background: item.color,
39
- opacity: item.visible ? 1 : 0.5
1
+ 'use client';
2
+ // src/components/Legend.tsx
3
+ import { classNames, prefixCls } from "@aura-react-comp/shared";
4
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
+ function Legend({ items, theme, config, onToggle }) {
6
+ if (config === false || items.length === 0)
7
+ return null;
8
+ const options = typeof config === "object" ? config : {};
9
+ const { position = "top", align = "left", selectable = true } = options;
10
+ if (options.show === false)
11
+ return null;
12
+ const interactive = selectable !== false && Boolean(onToggle);
13
+ return /* @__PURE__ */ jsx(
14
+ "div",
15
+ {
16
+ className: classNames(
17
+ prefixCls("chart__legend"),
18
+ position === "bottom" && prefixCls("chart__legend--bottom"),
19
+ align !== "left" && prefixCls(`chart__legend--${align}`)
20
+ ),
21
+ role: "group",
22
+ "aria-label": "图例",
23
+ children: items.map((item) => {
24
+ const content = /* @__PURE__ */ jsxs(Fragment, { children: [
25
+ /* @__PURE__ */ jsx(
26
+ "span",
27
+ {
28
+ className: prefixCls("chart__legend-dot"),
29
+ style: {
30
+ background: item.color,
31
+ opacity: item.visible ? 1 : 0.45
32
+ }
33
+ }
34
+ ),
35
+ /* @__PURE__ */ jsx(
36
+ "span",
37
+ {
38
+ className: prefixCls("chart__legend-text"),
39
+ style: {
40
+ color: item.visible ? theme.legend.text : theme.legend.textInactive
41
+ },
42
+ children: item.name
43
+ }
44
+ )
45
+ ] });
46
+ if (!interactive) {
47
+ return /* @__PURE__ */ jsx(
48
+ "span",
49
+ {
50
+ className: classNames(
51
+ prefixCls("chart__legend-item"),
52
+ prefixCls("chart__legend-item--static"),
53
+ !item.visible && prefixCls("chart__legend-item--inactive")
54
+ ),
55
+ children: content
56
+ },
57
+ item.key
58
+ );
40
59
  }
41
- }), /*#__PURE__*/_jsx("span", {
42
- style: {
43
- color: item.visible ? theme.legend.text : theme.legend.textInactive
44
- },
45
- children: item.name
46
- })]
47
- }, item.key))
48
- });
49
- }
60
+ return /* @__PURE__ */ jsx(
61
+ "button",
62
+ {
63
+ type: "button",
64
+ className: classNames(
65
+ prefixCls("chart__legend-item"),
66
+ !item.visible && prefixCls("chart__legend-item--inactive")
67
+ ),
68
+ "aria-pressed": item.visible,
69
+ title: `${item.visible ? "隐藏" : "显示"} ${item.name}`,
70
+ onClick: () => onToggle == null ? void 0 : onToggle(item.key),
71
+ children: content
72
+ },
73
+ item.key
74
+ );
75
+ })
76
+ }
77
+ );
78
+ }
79
+ export {
80
+ Legend
81
+ };
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- import type { ChartTheme } from '../theme';
3
- import type { TooltipConfig, TooltipPayload } from '../types';
2
+ import type { ChartTheme } from '../theme/index.js';
3
+ import type { TooltipConfig, TooltipPayload } from '../types.js';
4
4
  export interface TooltipProps {
5
5
  payload: TooltipPayload | null;
6
6
  /** 相对容器的像素位置 */