@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,21 +1,11 @@
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
- import { Fragment as _Fragment } from "react/jsx-runtime";
6
- const TOOLTIP_MAX_WIDTH = 280;
7
- const EDGE_GAP = 8;
8
- /** tooltip 与锚点之间的间隙 */
9
- const HEAD_GAP = 12;
10
-
11
- /**
12
- * 悬浮提示。
13
- *
14
- * 渲染为绝对定位的 DOM 而非 SVG foreignObject:
15
- * · foreignObject 在部分导出/打印场景下会失效;
16
- * · DOM 能自然继承字体与换行,样式维护成本更低。
17
- */
18
- export function Tooltip({
1
+ 'use client';
2
+ // src/components/Tooltip.tsx
3
+ import { classNames, prefixCls } from "@aura-react-comp/shared";
4
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
+ var TOOLTIP_MAX_WIDTH = 280;
6
+ var EDGE_GAP = 8;
7
+ var HEAD_GAP = 12;
8
+ function Tooltip({
19
9
  payload,
20
10
  x,
21
11
  y,
@@ -24,61 +14,63 @@ export function Tooltip({
24
14
  theme,
25
15
  config
26
16
  }) {
27
- if (!payload || config === false) return null;
28
- const options = typeof config === 'object' ? config : {};
29
- if (options.show === false) return null;
30
- const custom = options.formatter?.(payload);
31
- if (custom === null) return null;
32
-
33
- // 水平收敛:按「最大宽度的一半」留足空间,避免贴边被裁
17
+ var _a;
18
+ if (!payload || config === false)
19
+ return null;
20
+ const options = typeof config === "object" ? config : {};
21
+ if (options.show === false)
22
+ return null;
23
+ const custom = (_a = options.formatter) == null ? void 0 : _a.call(options, payload);
24
+ if (custom === null)
25
+ return null;
34
26
  const half = TOOLTIP_MAX_WIDTH / 2;
35
- const clampedX = Math.max(Math.min(x, containerWidth - half - EDGE_GAP), Math.min(half + EDGE_GAP, Math.max(0, containerWidth / 2)));
36
-
37
- /**
38
- * 垂直翻转:默认浮在锚点上方,上方放不下就翻到下方。
39
- *
40
- * 高度估算而非测量——测量要等一帧,会看到 tooltip 先闪错位置。
41
- * 标题一行 + 每行数据约 18px,估得略大为好(宁可提前翻转)。
42
- */
27
+ const clampedX = Math.max(
28
+ Math.min(x, containerWidth - half - EDGE_GAP),
29
+ Math.min(half + EDGE_GAP, Math.max(0, containerWidth / 2))
30
+ );
43
31
  const estimatedHeight = 30 + payload.series.length * 18;
44
32
  const fitsAbove = y - estimatedHeight - EDGE_GAP >= 0;
45
33
  const placeBelow = Boolean(containerHeight) && !fitsAbove;
46
34
  const top = placeBelow ? y + 12 : Math.max(y - HEAD_GAP, 0);
47
- return /*#__PURE__*/_jsxs("div", {
48
- className: classNames(prefixCls('chart__tooltip')),
49
- style: {
50
- left: clampedX,
51
- top,
52
- transform: placeBelow ? 'translate(-50%, 0)' : 'translate(-50%, -100%)',
53
- background: theme.tooltip.background,
54
- borderColor: theme.tooltip.border,
55
- color: theme.tooltip.text,
56
- boxShadow: theme.tooltip.shadow,
57
- borderRadius: theme.tooltip.radius
58
- },
59
- role: "tooltip",
60
- children: [/*#__PURE__*/_jsx("div", {
61
- className: prefixCls('chart__tooltip-title'),
62
- children: payload.label
63
- }), custom ?? /*#__PURE__*/_jsx(_Fragment, {
64
- children: payload.series.map(item => /*#__PURE__*/_jsxs("div", {
65
- className: prefixCls('chart__tooltip-item'),
66
- children: [/*#__PURE__*/_jsxs("span", {
67
- className: prefixCls('chart__tooltip-label'),
68
- children: [/*#__PURE__*/_jsx("span", {
69
- style: {
70
- width: 8,
71
- height: 8,
72
- borderRadius: 2,
73
- background: item.color,
74
- flex: '0 0 auto'
75
- }
76
- }), item.name]
77
- }), /*#__PURE__*/_jsx("span", {
78
- className: prefixCls('chart__tooltip-value'),
79
- children: item.formatted
80
- })]
81
- }, item.key))
82
- })]
83
- });
84
- }
35
+ return /* @__PURE__ */ jsxs(
36
+ "div",
37
+ {
38
+ className: classNames(prefixCls("chart__tooltip")),
39
+ style: {
40
+ left: clampedX,
41
+ top,
42
+ transform: placeBelow ? "translate(-50%, 0)" : "translate(-50%, -100%)",
43
+ background: theme.tooltip.background,
44
+ borderColor: theme.tooltip.border,
45
+ color: theme.tooltip.text,
46
+ boxShadow: theme.tooltip.shadow,
47
+ borderRadius: theme.tooltip.radius
48
+ },
49
+ role: "tooltip",
50
+ children: [
51
+ /* @__PURE__ */ jsx("div", { className: prefixCls("chart__tooltip-title"), children: payload.label }),
52
+ custom ?? /* @__PURE__ */ jsx(Fragment, { children: payload.series.map((item) => /* @__PURE__ */ jsxs("div", { className: prefixCls("chart__tooltip-item"), children: [
53
+ /* @__PURE__ */ jsxs("span", { className: prefixCls("chart__tooltip-label"), children: [
54
+ /* @__PURE__ */ jsx(
55
+ "span",
56
+ {
57
+ style: {
58
+ width: 8,
59
+ height: 8,
60
+ borderRadius: 2,
61
+ background: item.color,
62
+ flex: "0 0 auto"
63
+ }
64
+ }
65
+ ),
66
+ item.name
67
+ ] }),
68
+ /* @__PURE__ */ jsx("span", { className: prefixCls("chart__tooltip-value"), children: item.formatted })
69
+ ] }, item.key)) })
70
+ ]
71
+ }
72
+ );
73
+ }
74
+ export {
75
+ Tooltip
76
+ };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import type { ChartThemeInput } from '../../theme';
2
+ import type { ChartThemeInput } from '../../theme/index.js';
3
3
  /** ECharts 风格的系列配置(支持子集) */
4
4
  export interface ChartOptionSeries {
5
5
  type?: 'line' | 'bar' | 'scatter' | 'area' | 'pie';
@@ -33,6 +33,7 @@ export interface ChartOption {
33
33
  legend?: {
34
34
  show?: boolean;
35
35
  top?: number | string;
36
+ selectable?: boolean;
36
37
  };
37
38
  tooltip?: {
38
39
  show?: boolean;
@@ -53,6 +54,8 @@ export interface ChartProps {
53
54
  theme?: ChartThemeInput;
54
55
  palette?: string[];
55
56
  animation?: boolean;
57
+ /** 跨图表联动分组名 */
58
+ syncGroup?: string;
56
59
  className?: string;
57
60
  style?: React.CSSProperties;
58
61
  }
@@ -67,5 +70,5 @@ export interface ChartProps {
67
70
  * 明确只支持常用子集(直角坐标系的 line / bar / area / scatter 与 pie)。
68
71
  * 不做「假装全支持」:未识别的系列类型会被跳过,而不是静默画错。
69
72
  */
70
- export declare function Chart({ option, width, height, theme, palette, animation, className, style, }: ChartProps): React.JSX.Element;
73
+ export declare function Chart({ option, width, height, theme, palette, animation, syncGroup, className, style, }: ChartProps): React.JSX.Element;
71
74
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAGvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAOnD,4BAA4B;AAC5B,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,GAAG,MAAM,GAAG,KAAK,CAAC;IACnD,IAAI,CAAC,EAAE,MAAM,CAAC;I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B;AAID;;;;;;;;;;GAUG;AACH,wBAAgB,KAAK,CAAC,EACpB,MAAM,EACN,KAAc,EACd,MAAY,EACZ,KAAK,EACL,OAAO,EACP,SAAgB,EAChB,SAAS,EACT,SAAS,EACT,KAAK,GACN,EAAE,UAAU,qBAuIZ"}
@@ -1,104 +1,90 @@
1
- import React, { useMemo } from 'react';
2
- import { classNames, prefixCls } from '@aura-react-comp/shared';
1
+ 'use client';
2
+ // src/components/chart/index.tsx
3
+ import { useMemo } from "react";
4
+ import { classNames, prefixCls } from "@aura-react-comp/shared";
3
5
  import { LineChart } from "../../charts/line-chart";
4
6
  import { BarChart } from "../../charts/bar-chart";
5
7
  import { AreaChart } from "../../charts/area-chart";
6
8
  import { PieChart } from "../../charts/pie-chart";
7
9
  import { ComboChart } from "../../charts/combo-chart";
8
-
9
- /** ECharts 风格的系列配置(支持子集) */
10
- import { jsx as _jsx } from "react/jsx-runtime";
11
- import { jsxs as _jsxs } from "react/jsx-runtime";
12
- const X_KEY = '__aura_x__';
13
-
14
- /**
15
- * 配置式图表(兼容 ECharts 风格的 option)。
16
- *
17
- * 存在意义有两个:
18
- * 1. 迁移成本 —— 已有 ECharts 配置的项目可以低成本试用;
19
- * 2. **AI 友好** —— 让模型生成 JSON 配置比生成 JSX 组合可靠得多,
20
- * 尤其在需要动态拼装系列时。
21
- *
22
- * 明确只支持常用子集(直角坐标系的 line / bar / area / scatter 与 pie)。
23
- * 不做「假装全支持」:未识别的系列类型会被跳过,而不是静默画错。
24
- */
25
- export function Chart({
10
+ import { jsx, jsxs } from "react/jsx-runtime";
11
+ var X_KEY = "__aura_x__";
12
+ function Chart({
26
13
  option,
27
- width = '100%',
14
+ width = "100%",
28
15
  height = 320,
29
16
  theme,
30
17
  palette,
31
18
  animation = true,
19
+ syncGroup,
32
20
  className,
33
21
  style
34
22
  }) {
35
- const xValues = useMemo(() => (option.xAxis?.data ?? []).map(item => String(item)), [option.xAxis]);
23
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
24
+ const xValues = useMemo(
25
+ () => {
26
+ var _a2;
27
+ return (((_a2 = option.xAxis) == null ? void 0 : _a2.data) ?? []).map((item) => String(item));
28
+ },
29
+ [option.xAxis]
30
+ );
36
31
  const paletteOrOption = palette ?? option.color;
37
- const {
38
- rows,
39
- seriesConfig,
40
- primaryType
41
- } = useMemo(() => {
32
+ const { rows, seriesConfig, primaryType } = useMemo(() => {
33
+ var _a2;
42
34
  const list = option.series ?? [];
43
35
  const nextRows = xValues.map((value, index) => {
44
- const row = {
45
- [X_KEY]: value
46
- };
36
+ const row = { [X_KEY]: value };
47
37
  list.forEach((item, seriesIndex) => {
48
- row[`s${seriesIndex}`] = item.data?.[index] ?? null;
38
+ var _a3;
39
+ row[`s${seriesIndex}`] = ((_a3 = item.data) == null ? void 0 : _a3[index]) ?? null;
49
40
  });
50
41
  return row;
51
42
  });
52
- const configs = list.map((item, index) => ({
53
- key: `s${index}`,
54
- name: item.name ?? `系列 ${index + 1}`,
55
- color: item.itemStyle?.color,
56
- type: item.type === 'area' ? 'area' : item.type === 'bar' ? 'bar' : item.type === 'scatter' ? 'scatter' : 'line',
57
- stack: item.stack,
58
- curve: item.smooth ? 'smooth' : 'monotone',
59
- area: item.areaStyle !== undefined && item.areaStyle !== false
60
- }));
61
- const first = list[0]?.type ?? 'line';
62
- const primary = first === 'bar' ? 'bar' : first === 'pie' ? 'pie' : first === 'area' ? 'area' : 'line';
63
- return {
64
- rows: nextRows,
65
- seriesConfig: configs,
66
- primaryType: primary
67
- };
43
+ const configs = list.map((item, index) => {
44
+ var _a3;
45
+ return {
46
+ key: `s${index}`,
47
+ name: item.name ?? `系列 ${index + 1}`,
48
+ color: (_a3 = item.itemStyle) == null ? void 0 : _a3.color,
49
+ type: item.type === "area" ? "area" : item.type === "bar" ? "bar" : item.type === "scatter" ? "scatter" : "line",
50
+ stack: item.stack,
51
+ curve: item.smooth ? "smooth" : "monotone",
52
+ area: item.areaStyle !== void 0 && item.areaStyle !== false
53
+ };
54
+ });
55
+ const first = ((_a2 = list[0]) == null ? void 0 : _a2.type) ?? "line";
56
+ const primary = first === "bar" ? "bar" : first === "pie" ? "pie" : first === "area" ? "area" : "line";
57
+ return { rows: nextRows, seriesConfig: configs, primaryType: primary };
68
58
  }, [option.series, xValues]);
69
- const isPie = primaryType === 'pie';
70
- const legendVisible = option.legend?.show !== false;
71
- const tooltipVisible = option.tooltip?.show !== false;
72
- const gridVisible = option.grid?.show !== false;
73
- const titleNode = option.title?.text ? /*#__PURE__*/_jsxs("div", {
74
- className: prefixCls('chart__title'),
75
- children: [/*#__PURE__*/_jsx("div", {
76
- className: prefixCls('chart__title-main'),
77
- children: option.title.text
78
- }), option.title.subtext ? /*#__PURE__*/_jsx("div", {
79
- className: prefixCls('chart__title-sub'),
80
- children: option.title.subtext
81
- }) : null]
82
- }) : null;
59
+ const isPie = primaryType === "pie";
60
+ const legendConfig = ((_a = option.legend) == null ? void 0 : _a.show) === false ? false : ((_b = option.legend) == null ? void 0 : _b.selectable) === false ? { show: true, selectable: false } : true;
61
+ const tooltipVisible = ((_c = option.tooltip) == null ? void 0 : _c.show) !== false;
62
+ const gridVisible = ((_d = option.grid) == null ? void 0 : _d.show) !== false;
63
+ const titleNode = ((_e = option.title) == null ? void 0 : _e.text) ? /* @__PURE__ */ jsxs("div", { className: prefixCls("chart__title"), children: [
64
+ /* @__PURE__ */ jsx("div", { className: prefixCls("chart__title-main"), children: option.title.text }),
65
+ option.title.subtext ? /* @__PURE__ */ jsx("div", { className: prefixCls("chart__title-sub"), children: option.title.subtext }) : null
66
+ ] }) : null;
83
67
  if (isPie) {
84
- const pieData = (option.series?.[0]?.data ?? []).map((value, index) => ({
68
+ const pieData = (((_g = (_f = option.series) == null ? void 0 : _f[0]) == null ? void 0 : _g.data) ?? []).map((value, index) => ({
85
69
  name: xValues[index] ?? `项 ${index + 1}`,
86
70
  value: Number(value ?? 0)
87
71
  }));
88
- return /*#__PURE__*/_jsxs("div", {
89
- className: classNames(className),
90
- style: style,
91
- children: [titleNode, /*#__PURE__*/_jsx(PieChart, {
92
- data: pieData,
93
- width: width,
94
- height: height,
95
- theme: theme,
96
- palette: paletteOrOption,
97
- legend: legendVisible,
98
- tooltip: tooltipVisible,
99
- animation: animation
100
- })]
101
- });
72
+ return /* @__PURE__ */ jsxs("div", { className: classNames(className), style, children: [
73
+ titleNode,
74
+ /* @__PURE__ */ jsx(
75
+ PieChart,
76
+ {
77
+ data: pieData,
78
+ width,
79
+ height,
80
+ theme,
81
+ palette: paletteOrOption,
82
+ legend: legendConfig,
83
+ tooltip: tooltipVisible,
84
+ animation
85
+ }
86
+ )
87
+ ] });
102
88
  }
103
89
  const common = {
104
90
  data: rows,
@@ -108,34 +94,27 @@ export function Chart({
108
94
  height,
109
95
  theme,
110
96
  palette: paletteOrOption,
111
- legend: legendVisible,
112
- tooltip: tooltipVisible ? {
113
- trigger: option.tooltip?.trigger ?? 'axis'
114
- } : false,
97
+ legend: legendConfig,
98
+ tooltip: tooltipVisible ? { trigger: ((_h = option.tooltip) == null ? void 0 : _h.trigger) ?? "axis" } : false,
115
99
  grid: gridVisible,
116
100
  animation,
101
+ syncGroup,
117
102
  yAxis: {
118
- title: option.yAxis?.name,
119
- min: option.yAxis?.min,
120
- max: option.yAxis?.max
103
+ title: (_i = option.yAxis) == null ? void 0 : _i.name,
104
+ min: (_j = option.yAxis) == null ? void 0 : _j.min,
105
+ max: (_k = option.yAxis) == null ? void 0 : _k.max
121
106
  },
122
- xAxis: {
123
- title: option.xAxis?.name
124
- }
107
+ xAxis: { title: (_l = option.xAxis) == null ? void 0 : _l.name }
125
108
  };
126
- const hasMixed = seriesConfig.some(item => item.type !== seriesConfig[0].type);
127
- const chart = primaryType === 'bar' && !hasMixed ? /*#__PURE__*/_jsx(BarChart, {
128
- ...common
129
- }) : primaryType === 'area' ? /*#__PURE__*/_jsx(AreaChart, {
130
- ...common
131
- }) : primaryType === 'line' && !hasMixed ? /*#__PURE__*/_jsx(LineChart, {
132
- ...common
133
- }) : /*#__PURE__*/_jsx(ComboChart, {
134
- ...common
135
- });
136
- return /*#__PURE__*/_jsxs("div", {
137
- className: classNames(className),
138
- style: style,
139
- children: [titleNode, chart]
140
- });
141
- }
109
+ const hasMixed = seriesConfig.some(
110
+ (item) => item.type !== seriesConfig[0].type
111
+ );
112
+ const chart = primaryType === "bar" && !hasMixed ? /* @__PURE__ */ jsx(BarChart, { ...common }) : primaryType === "area" ? /* @__PURE__ */ jsx(AreaChart, { ...common }) : primaryType === "line" && !hasMixed ? /* @__PURE__ */ jsx(LineChart, { ...common }) : /* @__PURE__ */ jsx(ComboChart, { ...common });
113
+ return /* @__PURE__ */ jsxs("div", { className: classNames(className), style, children: [
114
+ titleNode,
115
+ chart
116
+ ] });
117
+ }
118
+ export {
119
+ Chart
120
+ };
@@ -53,6 +53,18 @@
53
53
 
54
54
  &--inactive {
55
55
  opacity: 0.45;
56
+
57
+ .aura-chart__legend-text {
58
+ text-decoration: line-through;
59
+ }
60
+ }
61
+
62
+ &--static {
63
+ cursor: default;
64
+
65
+ &:hover {
66
+ opacity: 1;
67
+ }
56
68
  }
57
69
  }
58
70
 
@@ -69,6 +81,7 @@
69
81
  min-height: 0;
70
82
  width: 100%;
71
83
  overflow: hidden;
84
+ touch-action: pan-y;
72
85
  }
73
86
 
74
87
  &__zoom {
@@ -1,37 +1,28 @@
1
- /**
2
- * 动画基础设施。
3
- *
4
- * 设计目标(针对「生硬」的根因):
5
- * 1. 缓动不能只有一种 —— 默认改用 easeOutQuint,尾部更慢,收得更柔和;
6
- * 2. 图元不能同时到齐 —— 提供 stagger(错峰),让动画「扫过」而非「弹起」;
7
- * 3. 数据更新不能重播入场 —— 交给 useChartTransition 做值插值。
8
- */
9
-
10
- const easingFns = {
11
- linear: t => t,
12
- easeOutCubic: t => 1 - (1 - t) ** 3,
1
+ 'use client';
2
+ // src/core/animation.ts
3
+ var easingFns = {
4
+ linear: (t) => t,
5
+ easeOutCubic: (t) => 1 - (1 - t) ** 3,
13
6
  // 比 cubic 尾部更松:数字类、柱状生长用它的减速感最自然
14
- easeOutQuint: t => 1 - (1 - t) ** 5,
15
- easeInOutCubic: t => t < 0.5 ? 4 * t ** 3 : 1 - (-2 * t + 2) ** 3 / 2,
7
+ easeOutQuint: (t) => 1 - (1 - t) ** 5,
8
+ easeInOutCubic: (t) => t < 0.5 ? 4 * t ** 3 : 1 - (-2 * t + 2) ** 3 / 2,
16
9
  // 轻微回弹(约 10% 过冲),仅用于环形/雷达这类「展开」动作
17
- easeOutBack: t => {
10
+ easeOutBack: (t) => {
18
11
  const c1 = 1.70158;
19
12
  const c3 = c1 + 1;
20
13
  return 1 + c3 * (t - 1) ** 3 + c1 * (t - 1) ** 2;
21
14
  }
22
15
  };
23
- export function getEasing(name) {
16
+ function getEasing(name) {
24
17
  return easingFns[name] ?? easingFns.easeOutQuint;
25
18
  }
26
- export const DEFAULT_ANIMATION = {
19
+ var DEFAULT_ANIMATION = {
27
20
  duration: 620,
28
- easing: 'easeOutQuint',
21
+ easing: "easeOutQuint",
29
22
  stagger: 0.35,
30
23
  delay: 0
31
24
  };
32
-
33
- /** 统一解析 boolean | 配置对象 */
34
- export function resolveAnimation(input, defaultEnabled = true) {
25
+ function resolveAnimation(input, defaultEnabled = true) {
35
26
  if (input === false) {
36
27
  return {
37
28
  enabled: false,
@@ -39,10 +30,10 @@ export function resolveAnimation(input, defaultEnabled = true) {
39
30
  easing: DEFAULT_ANIMATION.easing,
40
31
  stagger: 0,
41
32
  delay: 0,
42
- ease: t => t
33
+ ease: (t) => t
43
34
  };
44
35
  }
45
- const options = typeof input === 'object' ? input : {};
36
+ const options = typeof input === "object" ? input : {};
46
37
  const easing = options.easing ?? DEFAULT_ANIMATION.easing;
47
38
  return {
48
39
  enabled: defaultEnabled,
@@ -53,33 +44,22 @@ export function resolveAnimation(input, defaultEnabled = true) {
53
44
  ease: getEasing(easing)
54
45
  };
55
46
  }
56
- export function clamp01(value) {
47
+ function clamp01(value) {
57
48
  return value < 0 ? 0 : value > 1 ? 1 : value;
58
49
  }
59
-
60
- /**
61
- * 计算第 index 个元素的局部进度。
62
- *
63
- * 把全局进度 t 切成 count 段:第 i 个元素从 `stagger * i / (count-1)` 开始,
64
- * 在剩余 `1 - stagger` 的窗口内走完自己的 0→1。
65
- *
66
- * 这样整组图元不是「同时弹起」,而是像画笔从左到右扫过去。
67
- */
68
- export function staggerProgress(t, index, count, stagger) {
69
- if (count <= 1 || stagger <= 0) return clamp01(t);
50
+ function staggerProgress(t, index, count, stagger) {
51
+ if (count <= 1 || stagger <= 0)
52
+ return clamp01(t);
70
53
  const delay = stagger * index / (count - 1);
71
54
  const span = 1 - stagger;
72
- if (span <= 0) return t >= delay ? 1 : 0;
55
+ if (span <= 0)
56
+ return t >= delay ? 1 : 0;
73
57
  return clamp01((t - delay) / span);
74
58
  }
75
-
76
- /** 数值插值 */
77
- export function lerp(from, to, t) {
59
+ function lerp(from, to, t) {
78
60
  return from + (to - from) * t;
79
61
  }
80
-
81
- /** 矩阵的轻量指纹,用于判断「数据是否真的变了」 */
82
- export function hashMatrix(matrix) {
62
+ function hashMatrix(matrix) {
83
63
  let hash = matrix.length * 2654435761;
84
64
  for (const row of matrix) {
85
65
  hash = hash * 31 + row.length | 0;
@@ -89,4 +69,13 @@ export function hashMatrix(matrix) {
89
69
  }
90
70
  }
91
71
  return hash;
92
- }
72
+ }
73
+ export {
74
+ DEFAULT_ANIMATION,
75
+ clamp01,
76
+ getEasing,
77
+ hashMatrix,
78
+ lerp,
79
+ resolveAnimation,
80
+ staggerProgress
81
+ };
@@ -0,0 +1,34 @@
1
+ /** 导出图片格式 */
2
+ export type ChartExportFormat = 'png' | 'jpeg' | 'svg';
3
+ /** 图表导出选项 */
4
+ export interface ExportChartOptions {
5
+ /** 导出格式,默认 `'png'` */
6
+ format?: ChartExportFormat;
7
+ /** 导出倍率(用于高清屏),默认 `2` */
8
+ pixelRatio?: number;
9
+ /** 背景色;缺省时读取容器或当前主题背景,未设置时 png/svg 透明、jpeg 兜底实色 */
10
+ backgroundColor?: string;
11
+ /** JPEG 压缩质量(0~1),默认 `0.92` */
12
+ quality?: number;
13
+ }
14
+ /** 图表下载选项 */
15
+ export interface DownloadChartOptions extends ExportChartOptions {
16
+ /** 下载文件名(默认 `aura-chart.<format>`) */
17
+ filename?: string;
18
+ }
19
+ /**
20
+ * 导出图表内的主 `<svg>` 为独立 SVG 字符串。
21
+ * 会将节点上的 `var(--aura-*)`、字体、文字颜色及背景矩形内联,确保脱离页面后独立渲染。
22
+ */
23
+ export declare function exportChartSvg(container: HTMLElement, options?: ExportChartOptions): string;
24
+ /**
25
+ * 将图表导出为 DataURL(支持 `'png' | 'jpeg' | 'svg'`)。
26
+ * 自动识别 `<canvas>` 与 `<svg>` 内核,若同时存在多层则按 DOM 层序合成绘制。
27
+ */
28
+ export declare function exportChartDataUrl(container: HTMLElement, options?: ExportChartOptions): Promise<string>;
29
+ /**
30
+ * 导出并触发浏览器下载图表文件。
31
+ * 默认文件名 `aura-chart.<format>`,下载触发后安全释放 ObjectURL。
32
+ */
33
+ export declare function downloadChart(container: HTMLElement, options?: DownloadChartOptions): Promise<string>;
34
+ //# sourceMappingURL=export.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export.d.ts","sourceRoot":"","sources":["export.ts"],"names":[],"mappings":"AAEA,aAAa;AACb,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,CAAC;AAEvD,aAAa;AACb,MAAM,WAAW,kBAAkB;IACjC,sBAAsB;IACtB,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,yBAAyB;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mDAAmD;IACnD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,+BAA+B;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,aAAa;AACb,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB;IAC9D,sCAAsC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAmTD;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,WAAW,EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,MAAM,CAaR;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,WAAW,EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,MAAM,CAAC,CA6HjB;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,WAAW,EACtB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,MAAM,CAAC,CA8CjB"}