@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.
- package/esm/charts/area-chart/index.d.ts +2 -2
- package/esm/charts/area-chart/index.js +28 -23
- package/esm/charts/bar-chart/index.d.ts +1 -1
- package/esm/charts/bar-chart/index.js +18 -21
- package/esm/charts/candlestick-chart/index.d.ts +2 -2
- package/esm/charts/candlestick-chart/index.js +243 -180
- package/esm/charts/combo-chart/index.d.ts +1 -1
- package/esm/charts/combo-chart/index.js +9 -20
- package/esm/charts/funnel-chart/index.d.ts +2 -2
- package/esm/charts/funnel-chart/index.js +134 -108
- package/esm/charts/gauge-chart/index.d.ts +1 -1
- package/esm/charts/gauge-chart/index.js +103 -105
- package/esm/charts/graph-chart/index.d.ts +3 -3
- package/esm/charts/graph-chart/index.js +155 -114
- package/esm/charts/heatmap-chart/index.d.ts +2 -2
- package/esm/charts/heatmap-chart/index.js +180 -135
- package/esm/charts/line-chart/index.d.ts +2 -2
- package/esm/charts/line-chart/index.js +29 -24
- package/esm/charts/pie-chart/index.d.ts +2 -2
- package/esm/charts/pie-chart/index.d.ts.map +1 -1
- package/esm/charts/pie-chart/index.js +199 -139
- package/esm/charts/radar-chart/index.d.ts +2 -2
- package/esm/charts/radar-chart/index.d.ts.map +1 -1
- package/esm/charts/radar-chart/index.js +155 -128
- package/esm/charts/ring-progress/index.d.ts +1 -1
- package/esm/charts/ring-progress/index.js +82 -82
- package/esm/charts/sankey-chart/index.d.ts +3 -3
- package/esm/charts/sankey-chart/index.js +172 -141
- package/esm/charts/scatter-chart/index.d.ts +3 -3
- package/esm/charts/scatter-chart/index.d.ts.map +1 -1
- package/esm/charts/scatter-chart/index.js +226 -159
- package/esm/charts/sparkline/index.d.ts +1 -1
- package/esm/charts/sparkline/index.js +82 -66
- package/esm/charts/tree-chart/index.d.ts +3 -3
- package/esm/charts/tree-chart/index.js +129 -102
- package/esm/charts/treemap-chart/index.d.ts +3 -3
- package/esm/charts/treemap-chart/index.js +163 -141
- package/esm/charts/waterfall-chart/index.d.ts +2 -2
- package/esm/charts/waterfall-chart/index.js +166 -121
- package/esm/components/Legend.d.ts +5 -4
- package/esm/components/Legend.d.ts.map +1 -1
- package/esm/components/Legend.js +80 -48
- package/esm/components/Tooltip.d.ts +2 -2
- package/esm/components/Tooltip.js +63 -71
- package/esm/components/chart/index.d.ts +5 -2
- package/esm/components/chart/index.d.ts.map +1 -1
- package/esm/components/chart/index.js +81 -102
- package/esm/components/chart.less +13 -0
- package/esm/core/animation.js +32 -43
- package/esm/core/export.d.ts +34 -0
- package/esm/core/export.d.ts.map +1 -0
- package/esm/core/export.js +390 -0
- package/esm/core/force.js +23 -45
- package/esm/core/format.js +49 -52
- package/esm/core/hierarchy.d.ts +1 -1
- package/esm/core/hierarchy.js +61 -92
- package/esm/core/layout.d.ts +1 -1
- package/esm/core/layout.js +33 -50
- package/esm/core/sampling.js +31 -53
- package/esm/core/sankey.js +36 -55
- package/esm/core/scale.js +73 -86
- package/esm/core/shape.js +102 -133
- package/esm/core/sync.d.ts +41 -0
- package/esm/core/sync.d.ts.map +1 -0
- package/esm/core/sync.js +120 -0
- package/esm/hooks/useChartExport.d.ts +19 -0
- package/esm/hooks/useChartExport.d.ts.map +1 -0
- package/esm/hooks/useChartExport.js +35 -0
- package/esm/hooks/useChartTheme.d.ts +6 -5
- package/esm/hooks/useChartTheme.d.ts.map +1 -1
- package/esm/hooks/useChartTheme.js +18 -18
- package/esm/hooks/useChartTransition.d.ts +1 -1
- package/esm/hooks/useChartTransition.js +59 -73
- package/esm/hooks/useElementSize.js +20 -28
- package/esm/hooks/usePlotPointer.d.ts +23 -0
- package/esm/hooks/usePlotPointer.d.ts.map +1 -0
- package/esm/hooks/usePlotPointer.js +94 -0
- package/esm/index.d.ts +56 -50
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +137 -47
- package/esm/internal/CartesianChart.d.ts +1 -1
- package/esm/internal/CartesianChart.d.ts.map +1 -1
- package/esm/internal/CartesianChart.js +667 -485
- package/esm/internal/model.d.ts +2 -2
- package/esm/internal/model.js +45 -60
- package/esm/scene/canvas.d.ts +1 -1
- package/esm/scene/canvas.js +101 -107
- package/esm/scene/svg.d.ts +1 -1
- package/esm/scene/svg.js +107 -99
- package/esm/scene/types.js +9 -15
- package/esm/style.css +10 -0
- package/esm/theme/index.d.ts +2 -2
- package/esm/theme/index.d.ts.map +1 -1
- package/esm/theme/index.js +145 -170
- package/esm/types.d.ts +7 -3
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js +1 -1
- package/package.json +2 -2
package/esm/core/shape.js
CHANGED
|
@@ -1,40 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
* · SVG 渲染器把它直接写进 `<path d>`;
|
|
6
|
-
* · Canvas 渲染器把它交给 `new Path2D(d)`。
|
|
7
|
-
* 两条渲染路径共用同一份几何计算,因此不存在「SVG 与 Canvas 画得不一样」的问题。
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/** 曲线上的点允许为 null,表示此处数据缺失、路径应断开 */
|
|
11
|
-
|
|
12
|
-
const f = value => Number.isFinite(value) ? String(Math.round(value * 100) / 100) : '0';
|
|
13
|
-
|
|
14
|
-
/** 把点序列拆成若干连续段,段与段之间是 null 造成的断点 */
|
|
15
|
-
export function splitSegments(points) {
|
|
1
|
+
'use client';
|
|
2
|
+
// src/core/shape.ts
|
|
3
|
+
var f = (value) => Number.isFinite(value) ? String(Math.round(value * 100) / 100) : "0";
|
|
4
|
+
function splitSegments(points) {
|
|
16
5
|
const segments = [];
|
|
17
6
|
let current = [];
|
|
18
7
|
for (const point of points) {
|
|
19
|
-
if (point)
|
|
8
|
+
if (point)
|
|
9
|
+
current.push(point);
|
|
10
|
+
else if (current.length) {
|
|
20
11
|
segments.push(current);
|
|
21
12
|
current = [];
|
|
22
13
|
}
|
|
23
14
|
}
|
|
24
|
-
if (current.length)
|
|
15
|
+
if (current.length)
|
|
16
|
+
segments.push(current);
|
|
25
17
|
return segments;
|
|
26
18
|
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Fritsch–Carlson 单调切线。
|
|
30
|
-
*
|
|
31
|
-
* 目的:让平滑折线在数据极值处不「鼓包」。
|
|
32
|
-
* 普通 Catmull-Rom 会让曲线冲出数据范围(视觉上像在说谎),
|
|
33
|
-
* 折线图必须避免这种失真,因此默认曲线类型用的是 monotone。
|
|
34
|
-
*/
|
|
35
19
|
function monotoneTangents(xs, ys) {
|
|
36
20
|
const n = xs.length;
|
|
37
|
-
if (n < 2)
|
|
21
|
+
if (n < 2)
|
|
22
|
+
return [0];
|
|
38
23
|
const dx = [];
|
|
39
24
|
const slopes = [];
|
|
40
25
|
for (let i = 0; i < n - 1; i += 1) {
|
|
@@ -49,7 +34,7 @@ function monotoneTangents(xs, ys) {
|
|
|
49
34
|
const s0 = slopes[i - 1];
|
|
50
35
|
const s1 = slopes[i];
|
|
51
36
|
if (s0 * s1 <= 0) {
|
|
52
|
-
m[i] = 0;
|
|
37
|
+
m[i] = 0;
|
|
53
38
|
} else {
|
|
54
39
|
const w1 = 2 * dx[i] + dx[i - 1];
|
|
55
40
|
const w2 = dx[i] + 2 * dx[i - 1];
|
|
@@ -58,43 +43,33 @@ function monotoneTangents(xs, ys) {
|
|
|
58
43
|
}
|
|
59
44
|
return m;
|
|
60
45
|
}
|
|
61
|
-
|
|
62
|
-
/** 单个点序列 → path 命令(不含 M 之外的前缀处理) */
|
|
63
46
|
function segmentToPath(points, curve) {
|
|
64
47
|
if (points.length === 1) {
|
|
65
|
-
|
|
66
|
-
const {
|
|
67
|
-
x,
|
|
68
|
-
y
|
|
69
|
-
} = points[0];
|
|
48
|
+
const { x, y } = points[0];
|
|
70
49
|
return `M${f(x)},${f(y)}L${f(x)},${f(y)}`;
|
|
71
50
|
}
|
|
72
|
-
if (curve ===
|
|
73
|
-
return points.map((p, i) => `${i === 0 ?
|
|
51
|
+
if (curve === "linear") {
|
|
52
|
+
return points.map((p, i) => `${i === 0 ? "M" : "L"}${f(p.x)},${f(p.y)}`).join("");
|
|
74
53
|
}
|
|
75
|
-
if (curve ===
|
|
76
|
-
let
|
|
54
|
+
if (curve === "step") {
|
|
55
|
+
let d2 = `M${f(points[0].x)},${f(points[0].y)}`;
|
|
77
56
|
for (let i = 1; i < points.length; i += 1) {
|
|
78
57
|
const prev = points[i - 1];
|
|
79
58
|
const curr = points[i];
|
|
80
59
|
const midX = (prev.x + curr.x) / 2;
|
|
81
|
-
|
|
60
|
+
d2 += `H${f(midX)}V${f(curr.y)}H${f(curr.x)}`;
|
|
82
61
|
}
|
|
83
|
-
return
|
|
62
|
+
return d2;
|
|
84
63
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const xs = points.map(p => p.x);
|
|
88
|
-
const ys = points.map(p => p.y);
|
|
64
|
+
const xs = points.map((p) => p.x);
|
|
65
|
+
const ys = points.map((p) => p.y);
|
|
89
66
|
const tangents = monotoneTangents(xs, ys);
|
|
90
67
|
let d = `M${f(points[0].x)},${f(points[0].y)}`;
|
|
91
68
|
for (let i = 0; i < points.length - 1; i += 1) {
|
|
92
69
|
const p0 = points[i];
|
|
93
70
|
const p1 = points[i + 1];
|
|
94
71
|
const dx = (p1.x - p0.x) / 3;
|
|
95
|
-
|
|
96
|
-
// smooth 在单调切线基础上放大 20%,视觉更「圆润」但仍不越界
|
|
97
|
-
const grow = curve === 'smooth' ? 1.2 : 1;
|
|
72
|
+
const grow = curve === "smooth" ? 1.2 : 1;
|
|
98
73
|
const c1x = p0.x + dx;
|
|
99
74
|
const c1y = p0.y + tangents[i] * dx * grow;
|
|
100
75
|
const c2x = p1.x - dx;
|
|
@@ -103,43 +78,29 @@ function segmentToPath(points, curve) {
|
|
|
103
78
|
}
|
|
104
79
|
return d;
|
|
105
80
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
export function linePath(points, curve = 'monotone') {
|
|
109
|
-
return splitSegments(points).map(segment => segmentToPath(segment, curve)).filter(Boolean).join('');
|
|
81
|
+
function linePath(points, curve = "monotone") {
|
|
82
|
+
return splitSegments(points).map((segment) => segmentToPath(segment, curve)).filter(Boolean).join("");
|
|
110
83
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
* @param points 上边界点集
|
|
116
|
-
* @param baseline 基线像素 y(通常是 0 值所在位置)
|
|
117
|
-
*/
|
|
118
|
-
export function areaPath(points, baseline, curve = 'monotone') {
|
|
119
|
-
return splitSegments(points).map(segment => {
|
|
120
|
-
if (segment.length === 0) return '';
|
|
84
|
+
function areaPath(points, baseline, curve = "monotone") {
|
|
85
|
+
return splitSegments(points).map((segment) => {
|
|
86
|
+
if (segment.length === 0)
|
|
87
|
+
return "";
|
|
121
88
|
const top = segmentToPath(segment, curve);
|
|
122
89
|
const last = segment[segment.length - 1];
|
|
123
90
|
const first = segment[0];
|
|
124
91
|
return `${top}L${f(last.x)},${f(baseline)}L${f(first.x)},${f(baseline)}Z`;
|
|
125
|
-
}).filter(Boolean).join(
|
|
92
|
+
}).filter(Boolean).join("");
|
|
126
93
|
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* 扇形路径(饼图 / 环图 / 玫瑰图)。
|
|
130
|
-
*
|
|
131
|
-
* @param cx 圆心 x
|
|
132
|
-
* @param cy 圆心 y
|
|
133
|
-
* @param innerRadius 内半径,大于 0 即为环形
|
|
134
|
-
* @param outerRadius 外半径
|
|
135
|
-
* @param startAngle 起始角(弧度,0 指向 3 点钟方向,顺时针为正)
|
|
136
|
-
* @param endAngle 结束角
|
|
137
|
-
*/
|
|
138
|
-
export function arcPath(cx, cy, innerRadius, outerRadius, startAngle, endAngle) {
|
|
94
|
+
function arcPath(cx, cy, innerRadius, outerRadius, startAngle, endAngle) {
|
|
139
95
|
const sweep = endAngle - startAngle;
|
|
140
|
-
// 整圆无法用单段 A 命令表达(起终点重合),拆成两个半圆
|
|
141
96
|
if (Math.abs(sweep) >= Math.PI * 2 - 1e-6) {
|
|
142
|
-
return [
|
|
97
|
+
return [
|
|
98
|
+
`M${f(cx - outerRadius)},${f(cy)}`,
|
|
99
|
+
`A${f(outerRadius)},${f(outerRadius)} 0 1 1 ${f(cx + outerRadius)},${f(cy)}`,
|
|
100
|
+
`A${f(outerRadius)},${f(outerRadius)} 0 1 1 ${f(cx - outerRadius)},${f(cy)}`,
|
|
101
|
+
innerRadius > 0 ? `M${f(cx - innerRadius)},${f(cy)}A${f(innerRadius)},${f(innerRadius)} 0 1 0 ${f(cx + innerRadius)},${f(cy)}A${f(innerRadius)},${f(innerRadius)} 0 1 0 ${f(cx - innerRadius)},${f(cy)}` : "",
|
|
102
|
+
"Z"
|
|
103
|
+
].join("");
|
|
143
104
|
}
|
|
144
105
|
const largeArc = Math.abs(sweep) > Math.PI ? 1 : 0;
|
|
145
106
|
const direction = sweep > 0 ? 1 : 0;
|
|
@@ -154,82 +115,81 @@ export function arcPath(cx, cy, innerRadius, outerRadius, startAngle, endAngle)
|
|
|
154
115
|
const iy1 = cy + innerRadius * Math.sin(endAngle);
|
|
155
116
|
const ix0 = cx + innerRadius * Math.cos(startAngle);
|
|
156
117
|
const iy0 = cy + innerRadius * Math.sin(startAngle);
|
|
157
|
-
return [
|
|
118
|
+
return [
|
|
119
|
+
`M${f(x0)},${f(y0)}`,
|
|
120
|
+
`A${f(outerRadius)},${f(outerRadius)} 0 ${largeArc} ${direction} ${f(x1)},${f(y1)}`,
|
|
121
|
+
`L${f(ix1)},${f(iy1)}`,
|
|
122
|
+
`A${f(innerRadius)},${f(innerRadius)} 0 ${largeArc} ${direction === 1 ? 0 : 1} ${f(ix0)},${f(iy0)}`,
|
|
123
|
+
"Z"
|
|
124
|
+
].join("");
|
|
158
125
|
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* 圆角矩形路径。
|
|
162
|
-
*
|
|
163
|
-
* 柱状图的圆角通常只在上方两个角(负值柱则在下两个角),
|
|
164
|
-
* 因此用 corners 精确控制,而不是简单给 rect 加 rx(那会四角全圆)。
|
|
165
|
-
*/
|
|
166
|
-
export function roundedRectPath(x, y, width, height, radius, corners = {
|
|
126
|
+
function roundedRectPath(x, y, width, height, radius, corners = {
|
|
167
127
|
tl: true,
|
|
168
128
|
tr: true
|
|
169
129
|
}) {
|
|
170
|
-
const r = Math.max(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
} = corners;
|
|
130
|
+
const r = Math.max(
|
|
131
|
+
0,
|
|
132
|
+
Math.min(radius, Math.abs(width) / 2, Math.abs(height) / 2)
|
|
133
|
+
);
|
|
134
|
+
if (r === 0)
|
|
135
|
+
return `M${f(x)},${f(y)}H${f(x + width)}V${f(y + height)}H${f(x)}Z`;
|
|
136
|
+
const { tl = true, tr = true, br = false, bl = false } = corners;
|
|
178
137
|
const rtl = tl ? r : 0;
|
|
179
138
|
const rtr = tr ? r : 0;
|
|
180
139
|
const rbr = br ? r : 0;
|
|
181
140
|
const rbl = bl ? r : 0;
|
|
182
141
|
const x1 = x + width;
|
|
183
142
|
const y1 = y + height;
|
|
184
|
-
return [
|
|
143
|
+
return [
|
|
144
|
+
`M${f(x + rtl)},${f(y)}`,
|
|
145
|
+
`H${f(x1 - rtr)}`,
|
|
146
|
+
rtr ? `A${f(rtr)},${f(rtr)} 0 0 1 ${f(x1)},${f(y + rtr)}` : "",
|
|
147
|
+
`V${f(y1 - rbr)}`,
|
|
148
|
+
rbr ? `A${f(rbr)},${f(rbr)} 0 0 1 ${f(x1 - rbr)},${f(y1)}` : "",
|
|
149
|
+
`H${f(x + rbl)}`,
|
|
150
|
+
rbl ? `A${f(rbl)},${f(rbl)} 0 0 1 ${f(x)},${f(y1 - rbl)}` : "",
|
|
151
|
+
`V${f(y + rtl)}`,
|
|
152
|
+
rtl ? `A${f(rtl)},${f(rtl)} 0 0 1 ${f(x + rtl)},${f(y)}` : "",
|
|
153
|
+
"Z"
|
|
154
|
+
].join("");
|
|
185
155
|
}
|
|
186
|
-
|
|
187
|
-
/** 散点图形符号 */
|
|
188
|
-
|
|
189
|
-
export function symbolPath(type, cx, cy, size) {
|
|
156
|
+
function symbolPath(type, cx, cy, size) {
|
|
190
157
|
const s = size / 2;
|
|
191
158
|
switch (type) {
|
|
192
|
-
case
|
|
159
|
+
case "square":
|
|
193
160
|
return `M${f(cx - s)},${f(cy - s)}H${f(cx + s)}V${f(cy + s)}H${f(cx - s)}Z`;
|
|
194
|
-
case
|
|
161
|
+
case "diamond":
|
|
195
162
|
return `M${f(cx)},${f(cy - s)}L${f(cx + s)},${f(cy)}L${f(cx)},${f(cy + s)}L${f(cx - s)},${f(cy)}Z`;
|
|
196
|
-
case
|
|
163
|
+
case "triangle":
|
|
197
164
|
return `M${f(cx)},${f(cy - s)}L${f(cx + s)},${f(cy + s)}L${f(cx - s)},${f(cy + s)}Z`;
|
|
198
|
-
case
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
case 'circle':
|
|
214
|
-
default:
|
|
215
|
-
{
|
|
216
|
-
// 用两段圆弧表达圆形,保证与 rect/path 渲染器行为一致
|
|
217
|
-
return `M${f(cx - s)},${f(cy)}A${f(s)},${f(s)} 0 1 0 ${f(cx + s)},${f(cy)}A${f(s)},${f(s)} 0 1 0 ${f(cx - s)},${f(cy)}Z`;
|
|
165
|
+
case "cross": {
|
|
166
|
+
const t = s / 3;
|
|
167
|
+
return [
|
|
168
|
+
`M${f(cx - s)},${f(cy - t)}H${f(cx - t)}V${f(cy - s)}H${f(cx + t)}V${f(cy - t)}`,
|
|
169
|
+
`H${f(cx + s)}V${f(cy + t)}H${f(cx + t)}V${f(cy + s)}H${f(cx - t)}V${f(cy + t)}H${f(cx - s)}Z`
|
|
170
|
+
].join("");
|
|
171
|
+
}
|
|
172
|
+
case "star": {
|
|
173
|
+
const points = [];
|
|
174
|
+
for (let i = 0; i < 10; i += 1) {
|
|
175
|
+
const radius = i % 2 === 0 ? s : s * 0.45;
|
|
176
|
+
const angle = Math.PI / 5 * i - Math.PI / 2;
|
|
177
|
+
points.push(
|
|
178
|
+
`${f(cx + radius * Math.cos(angle))},${f(cy + radius * Math.sin(angle))}`
|
|
179
|
+
);
|
|
218
180
|
}
|
|
181
|
+
return `M${points.join("L")}Z`;
|
|
182
|
+
}
|
|
183
|
+
case "circle":
|
|
184
|
+
default: {
|
|
185
|
+
return `M${f(cx - s)},${f(cy)}A${f(s)},${f(s)} 0 1 0 ${f(cx + s)},${f(cy)}A${f(s)},${f(s)} 0 1 0 ${f(cx - s)},${f(cy)}Z`;
|
|
186
|
+
}
|
|
219
187
|
}
|
|
220
188
|
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* 圆弧中心线路径。
|
|
224
|
-
*
|
|
225
|
-
* 与 arcPath 的区别:arcPath 生成的是「环带 + 填充」的闭合区域,
|
|
226
|
-
* 而这里只生成一条中心线圆弧,供 stroke 使用(仪表盘、进度环都用它)。
|
|
227
|
-
*/
|
|
228
|
-
export function arcLinePath(cx, cy, radius, startAngle, endAngle) {
|
|
189
|
+
function arcLinePath(cx, cy, radius, startAngle, endAngle) {
|
|
229
190
|
const sweep = endAngle - startAngle;
|
|
230
|
-
if (Math.abs(sweep) < 1e-6 || radius <= 0)
|
|
231
|
-
|
|
232
|
-
// 整圆无法用单段弧表达,拆成两段
|
|
191
|
+
if (Math.abs(sweep) < 1e-6 || radius <= 0)
|
|
192
|
+
return "";
|
|
233
193
|
if (Math.abs(sweep) >= Math.PI * 2 - 1e-6) {
|
|
234
194
|
const x = cx + radius * Math.cos(startAngle);
|
|
235
195
|
const y = cy + radius * Math.sin(startAngle);
|
|
@@ -242,4 +202,13 @@ export function arcLinePath(cx, cy, radius, startAngle, endAngle) {
|
|
|
242
202
|
const x1 = cx + radius * Math.cos(endAngle);
|
|
243
203
|
const y1 = cy + radius * Math.sin(endAngle);
|
|
244
204
|
return `M${f(x0)},${f(y0)}A${f(radius)},${f(radius)} 0 ${largeArc} ${direction} ${f(x1)},${f(y1)}`;
|
|
245
|
-
}
|
|
205
|
+
}
|
|
206
|
+
export {
|
|
207
|
+
arcLinePath,
|
|
208
|
+
arcPath,
|
|
209
|
+
areaPath,
|
|
210
|
+
linePath,
|
|
211
|
+
roundedRectPath,
|
|
212
|
+
splitSegments,
|
|
213
|
+
symbolPath
|
|
214
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/** 跨图表联动广播载荷 */
|
|
3
|
+
export interface ChartSyncPayload {
|
|
4
|
+
/** 触发本次联动的图表实例 ID */
|
|
5
|
+
sourceId: string;
|
|
6
|
+
/** 高亮类目索引;null 表示离开 / 清除高亮 */
|
|
7
|
+
index: number | null;
|
|
8
|
+
/** 对应的 x 轴类目标签(用于多图表类目对齐) */
|
|
9
|
+
label?: string | number;
|
|
10
|
+
}
|
|
11
|
+
/** ChartSyncProvider 属性 */
|
|
12
|
+
export interface ChartSyncProviderProps {
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 跨图表联动作用域容器。
|
|
17
|
+
*
|
|
18
|
+
* 内部通过恒定引用的订阅 store 分发联动事件,Context 值永不变更,
|
|
19
|
+
* 因此不会引发无关子组件的整树重渲染;同时为多面板或单测提供完全隔离的作用域。
|
|
20
|
+
*/
|
|
21
|
+
export declare function ChartSyncProvider({ children }: ChartSyncProviderProps): React.JSX.Element;
|
|
22
|
+
export declare namespace ChartSyncProvider {
|
|
23
|
+
var displayName: string;
|
|
24
|
+
}
|
|
25
|
+
/** useChartSync 返回值 */
|
|
26
|
+
export interface UseChartSyncResult {
|
|
27
|
+
/** 当前图表唯一源标识 */
|
|
28
|
+
sourceId: string;
|
|
29
|
+
/** 来自同组其他图表的联动载荷;无联动或已清除时为 null */
|
|
30
|
+
synced: ChartSyncPayload | null;
|
|
31
|
+
/** 向同组广播高亮索引与标签 */
|
|
32
|
+
emit: (index: number | null, label?: string | number) => void;
|
|
33
|
+
/** 清除本图表发出的联动高亮 */
|
|
34
|
+
clear: () => void;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 订阅并参与跨图表联动。
|
|
38
|
+
* 未传入 `group` 时为空操作,不建立订阅、不产生额外渲染。
|
|
39
|
+
*/
|
|
40
|
+
export declare function useChartSync(group?: string): UseChartSyncResult;
|
|
41
|
+
//# sourceMappingURL=sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["sync.tsx"],"names":[],"mappings":"AAAA,OAAO,KAQN,MAAM,OAAO,CAAC;AAEf,gBAAgB;AAChB,MAAM,WAAW,gBAAgB;IAC/B,qBAAqB;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,6BAA6B;IAC7B,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AAoED,2BAA2B;AAC3B,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,QAAQ,EAAE,EAAE,sBAAsB,qBAUrE;yBAVe,iBAAiB;;;AAcjC,uBAAuB;AACvB,MAAM,WAAW,kBAAkB;IACjC,gBAAgB;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,mCAAmC;IACnC,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAChC,mBAAmB;IACnB,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,KAAK,IAAI,CAAC;IAC9D,mBAAmB;IACnB,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,kBAAkB,CAqD/D"}
|
package/esm/core/sync.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
// src/core/sync.tsx
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
useCallback,
|
|
6
|
+
useContext,
|
|
7
|
+
useEffect,
|
|
8
|
+
useId,
|
|
9
|
+
useRef,
|
|
10
|
+
useState
|
|
11
|
+
} from "react";
|
|
12
|
+
import { jsx } from "react/jsx-runtime";
|
|
13
|
+
function isSamePayload(a, b) {
|
|
14
|
+
if (a === b)
|
|
15
|
+
return true;
|
|
16
|
+
if (!a || !b)
|
|
17
|
+
return false;
|
|
18
|
+
return a.sourceId === b.sourceId && a.index === b.index && a.label === b.label;
|
|
19
|
+
}
|
|
20
|
+
function createChartSyncStore() {
|
|
21
|
+
const channels = /* @__PURE__ */ new Map();
|
|
22
|
+
const getOrCreate = (group) => {
|
|
23
|
+
let channel = channels.get(group);
|
|
24
|
+
if (!channel) {
|
|
25
|
+
channel = { state: null, listeners: /* @__PURE__ */ new Set() };
|
|
26
|
+
channels.set(group, channel);
|
|
27
|
+
}
|
|
28
|
+
return channel;
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
subscribe(group, listener) {
|
|
32
|
+
const channel = getOrCreate(group);
|
|
33
|
+
channel.listeners.add(listener);
|
|
34
|
+
return () => {
|
|
35
|
+
channel.listeners.delete(listener);
|
|
36
|
+
if (channel.listeners.size === 0) {
|
|
37
|
+
channels.delete(group);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
publish(group, payload) {
|
|
42
|
+
const channel = channels.get(group);
|
|
43
|
+
if (!channel)
|
|
44
|
+
return;
|
|
45
|
+
if (isSamePayload(channel.state, payload))
|
|
46
|
+
return;
|
|
47
|
+
channel.state = payload;
|
|
48
|
+
channel.listeners.forEach((listener) => listener(payload));
|
|
49
|
+
},
|
|
50
|
+
getSnapshot(group) {
|
|
51
|
+
var _a;
|
|
52
|
+
return ((_a = channels.get(group)) == null ? void 0 : _a.state) ?? null;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
var defaultSyncStore = createChartSyncStore();
|
|
57
|
+
var ChartSyncContext = createContext(defaultSyncStore);
|
|
58
|
+
function ChartSyncProvider({ children }) {
|
|
59
|
+
const storeRef = useRef(null);
|
|
60
|
+
if (!storeRef.current) {
|
|
61
|
+
storeRef.current = createChartSyncStore();
|
|
62
|
+
}
|
|
63
|
+
return /* @__PURE__ */ jsx(ChartSyncContext.Provider, { value: storeRef.current, children });
|
|
64
|
+
}
|
|
65
|
+
ChartSyncProvider.displayName = "ChartSyncProvider";
|
|
66
|
+
function useChartSync(group) {
|
|
67
|
+
const store = useContext(ChartSyncContext);
|
|
68
|
+
const sourceId = useId();
|
|
69
|
+
const [synced, setSynced] = useState(null);
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (!group) {
|
|
72
|
+
setSynced(null);
|
|
73
|
+
return void 0;
|
|
74
|
+
}
|
|
75
|
+
const initial = store.getSnapshot(group);
|
|
76
|
+
if (initial && initial.sourceId !== sourceId && initial.index !== null) {
|
|
77
|
+
setSynced(initial);
|
|
78
|
+
} else {
|
|
79
|
+
setSynced(null);
|
|
80
|
+
}
|
|
81
|
+
const unsubscribe = store.subscribe(group, (payload) => {
|
|
82
|
+
if (!payload || payload.sourceId === sourceId)
|
|
83
|
+
return;
|
|
84
|
+
setSynced(payload.index === null ? null : payload);
|
|
85
|
+
});
|
|
86
|
+
return () => {
|
|
87
|
+
unsubscribe();
|
|
88
|
+
const latest = store.getSnapshot(group);
|
|
89
|
+
if (latest && latest.sourceId === sourceId && latest.index !== null) {
|
|
90
|
+
store.publish(group, { sourceId, index: null });
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}, [store, group, sourceId]);
|
|
94
|
+
const emit = useCallback(
|
|
95
|
+
(index, label) => {
|
|
96
|
+
if (!group)
|
|
97
|
+
return;
|
|
98
|
+
if (index === null) {
|
|
99
|
+
const latest = store.getSnapshot(group);
|
|
100
|
+
if (latest && latest.sourceId !== sourceId)
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
store.publish(group, { sourceId, index, label });
|
|
104
|
+
},
|
|
105
|
+
[store, group, sourceId]
|
|
106
|
+
);
|
|
107
|
+
const clear = useCallback(() => {
|
|
108
|
+
if (!group)
|
|
109
|
+
return;
|
|
110
|
+
const latest = store.getSnapshot(group);
|
|
111
|
+
if (latest && latest.sourceId !== sourceId)
|
|
112
|
+
return;
|
|
113
|
+
store.publish(group, { sourceId, index: null });
|
|
114
|
+
}, [store, group, sourceId]);
|
|
115
|
+
return { sourceId, synced, emit, clear };
|
|
116
|
+
}
|
|
117
|
+
export {
|
|
118
|
+
ChartSyncProvider,
|
|
119
|
+
useChartSync
|
|
120
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { type DownloadChartOptions, type ExportChartOptions } from '../core/export.js';
|
|
3
|
+
/** useChartExport 返回值 */
|
|
4
|
+
export interface UseChartExportResult<T extends HTMLElement = HTMLDivElement> {
|
|
5
|
+
/** 绑定到图表外层容器的 ref */
|
|
6
|
+
containerRef: React.RefObject<T>;
|
|
7
|
+
/** 导出独立 SVG 字符串 */
|
|
8
|
+
exportSvg: (options?: ExportChartOptions) => string;
|
|
9
|
+
/** 导出 DataURL(支持 png / jpeg / svg) */
|
|
10
|
+
exportDataUrl: (options?: ExportChartOptions) => Promise<string>;
|
|
11
|
+
/** 触发浏览器下载图表文件 */
|
|
12
|
+
download: (options?: DownloadChartOptions) => Promise<string>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 图表导出轻量 Hook。
|
|
16
|
+
* 将返回的 `containerRef` 挂载到图表外层容器,即可一键调用 SVG / PNG / JPEG 导出与下载。
|
|
17
|
+
*/
|
|
18
|
+
export declare function useChartExport<T extends HTMLElement = HTMLDivElement>(): UseChartExportResult<T>;
|
|
19
|
+
//# sourceMappingURL=useChartExport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChartExport.d.ts","sourceRoot":"","sources":["useChartExport.ts"],"names":[],"mappings":";AACA,OAAO,EAIL,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAExB,yBAAyB;AACzB,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS,WAAW,GAAG,cAAc;IAC1E,qBAAqB;IACrB,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACjC,mBAAmB;IACnB,SAAS,EAAE,CAAC,OAAO,CAAC,EAAE,kBAAkB,KAAK,MAAM,CAAC;IACpD,sCAAsC;IACtC,aAAa,EAAE,CAAC,OAAO,CAAC,EAAE,kBAAkB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACjE,kBAAkB;IAClB,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,oBAAoB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CAC/D;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,CAAC,SAAS,WAAW,GAAG,cAAc,KACnC,oBAAoB,CAAC,CAAC,CAAC,CA0B3B"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
// src/hooks/useChartExport.ts
|
|
3
|
+
import { useCallback, useRef } from "react";
|
|
4
|
+
import {
|
|
5
|
+
downloadChart,
|
|
6
|
+
exportChartDataUrl,
|
|
7
|
+
exportChartSvg
|
|
8
|
+
} from "../core/export";
|
|
9
|
+
function useChartExport() {
|
|
10
|
+
const containerRef = useRef(null);
|
|
11
|
+
const exportSvg = useCallback((options) => {
|
|
12
|
+
const el = containerRef.current;
|
|
13
|
+
if (!el)
|
|
14
|
+
throw new Error("图表导出失败:containerRef 尚未挂载");
|
|
15
|
+
return exportChartSvg(el, options);
|
|
16
|
+
}, []);
|
|
17
|
+
const exportDataUrl = useCallback((options) => {
|
|
18
|
+
const el = containerRef.current;
|
|
19
|
+
if (!el) {
|
|
20
|
+
return Promise.reject(new Error("图表导出失败:containerRef 尚未挂载"));
|
|
21
|
+
}
|
|
22
|
+
return exportChartDataUrl(el, options);
|
|
23
|
+
}, []);
|
|
24
|
+
const download = useCallback((options) => {
|
|
25
|
+
const el = containerRef.current;
|
|
26
|
+
if (!el) {
|
|
27
|
+
return Promise.reject(new Error("图表导出失败:containerRef 尚未挂载"));
|
|
28
|
+
}
|
|
29
|
+
return downloadChart(el, options);
|
|
30
|
+
}, []);
|
|
31
|
+
return { containerRef, exportSvg, exportDataUrl, download };
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
useChartExport
|
|
35
|
+
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { type ChartTheme, type ChartThemeInput } from '../theme';
|
|
1
|
+
import { type ChartTheme, type ChartThemeInput } from '../theme/index.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* 解析图表主题,并在主题属性变化时重新读取。
|
|
4
4
|
*
|
|
5
|
-
* 为什么需要订阅:Aura
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* 为什么需要订阅:Aura 的主题是 `document.documentElement` 上的双轴属性
|
|
6
|
+
* (`data-mode`=明暗 × `data-palette`=色板,见 ui/theme/tokens.css)。
|
|
7
|
+
* 图表颜色若是挂载时读一次,用户点切换后图表会停在旧配色 ——
|
|
8
|
+
* 视觉上和整站脱节。旧的 `data-theme` 键继续监听以兼容历史用法。
|
|
8
9
|
*/
|
|
9
10
|
export declare function useChartTheme(input?: ChartThemeInput, palette?: string[]): ChartTheme;
|
|
10
11
|
//# sourceMappingURL=useChartTheme.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useChartTheme.d.ts","sourceRoot":"","sources":["useChartTheme.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,UAAU,CAAC;AAE/E
|
|
1
|
+
{"version":3,"file":"useChartTheme.d.ts","sourceRoot":"","sources":["useChartTheme.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,UAAU,CAAC;AAE/E;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,KAAK,CAAC,EAAE,eAAe,EACvB,OAAO,CAAC,EAAE,MAAM,EAAE,GACjB,UAAU,CAiCZ"}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
// src/hooks/useChartTheme.ts
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
2
4
|
import { resolveTheme } from "../theme";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 解析图表主题,并在 `data-theme` 变化时重新读取。
|
|
6
|
-
*
|
|
7
|
-
* 为什么需要订阅:Aura 的暗色模式是通过 `document.documentElement.dataset.theme`
|
|
8
|
-
* 切换的(见 ui/theme/ThemeProvider)。图表颜色若是挂载时读一次,
|
|
9
|
-
* 用户点切换后图表会停在旧配色 —— 视觉上和整站脱节。
|
|
10
|
-
*/
|
|
11
|
-
export function useChartTheme(input, palette) {
|
|
5
|
+
function useChartTheme(input, palette) {
|
|
12
6
|
const [theme, setTheme] = useState(() => resolveTheme(input));
|
|
13
7
|
useEffect(() => {
|
|
14
8
|
const update = () => {
|
|
15
9
|
const next = resolveTheme(input);
|
|
16
|
-
setTheme(palette && palette.length ? {
|
|
17
|
-
...next,
|
|
18
|
-
palette
|
|
19
|
-
} : next);
|
|
10
|
+
setTheme(palette && palette.length ? { ...next, palette } : next);
|
|
20
11
|
};
|
|
21
12
|
update();
|
|
22
|
-
if (typeof MutationObserver ===
|
|
23
|
-
return
|
|
13
|
+
if (typeof MutationObserver === "undefined" || typeof document === "undefined") {
|
|
14
|
+
return void 0;
|
|
24
15
|
}
|
|
25
16
|
const observer = new MutationObserver(update);
|
|
26
17
|
observer.observe(document.documentElement, {
|
|
27
18
|
attributes: true,
|
|
28
|
-
attributeFilter: [
|
|
19
|
+
attributeFilter: [
|
|
20
|
+
"data-mode",
|
|
21
|
+
"data-palette",
|
|
22
|
+
"data-theme",
|
|
23
|
+
"class",
|
|
24
|
+
"style"
|
|
25
|
+
]
|
|
29
26
|
});
|
|
30
27
|
return () => observer.disconnect();
|
|
31
28
|
}, [input, palette]);
|
|
32
29
|
return theme;
|
|
33
|
-
}
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
useChartTheme
|
|
33
|
+
};
|