@aura-react-comp/charts 0.0.0-stage → 0.3.1
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/LICENSE +21 -0
- package/README.md +90 -2
- package/esm/charts/area-chart/index.d.ts +19 -0
- package/esm/charts/area-chart/index.d.ts.map +1 -0
- package/esm/charts/area-chart/index.js +31 -0
- package/esm/charts/bar-chart/index.d.ts +16 -0
- package/esm/charts/bar-chart/index.d.ts.map +1 -0
- package/esm/charts/bar-chart/index.js +28 -0
- package/esm/charts/candlestick-chart/index.d.ts +47 -0
- package/esm/charts/candlestick-chart/index.d.ts.map +1 -0
- package/esm/charts/candlestick-chart/index.js +347 -0
- package/esm/charts/combo-chart/index.d.ts +17 -0
- package/esm/charts/combo-chart/index.d.ts.map +1 -0
- package/esm/charts/combo-chart/index.js +26 -0
- package/esm/charts/funnel-chart/index.d.ts +35 -0
- package/esm/charts/funnel-chart/index.d.ts.map +1 -0
- package/esm/charts/funnel-chart/index.js +200 -0
- package/esm/charts/gauge-chart/index.d.ts +41 -0
- package/esm/charts/gauge-chart/index.d.ts.map +1 -0
- package/esm/charts/gauge-chart/index.js +217 -0
- package/esm/charts/graph-chart/index.d.ts +35 -0
- package/esm/charts/graph-chart/index.d.ts.map +1 -0
- package/esm/charts/graph-chart/index.js +224 -0
- package/esm/charts/heatmap-chart/index.d.ts +47 -0
- package/esm/charts/heatmap-chart/index.d.ts.map +1 -0
- package/esm/charts/heatmap-chart/index.js +281 -0
- package/esm/charts/line-chart/index.d.ts +23 -0
- package/esm/charts/line-chart/index.d.ts.map +1 -0
- package/esm/charts/line-chart/index.js +33 -0
- package/esm/charts/pie-chart/index.d.ts +38 -0
- package/esm/charts/pie-chart/index.d.ts.map +1 -0
- package/esm/charts/pie-chart/index.js +272 -0
- package/esm/charts/radar-chart/index.d.ts +44 -0
- package/esm/charts/radar-chart/index.d.ts.map +1 -0
- package/esm/charts/radar-chart/index.js +263 -0
- package/esm/charts/ring-progress/index.d.ts +38 -0
- package/esm/charts/ring-progress/index.d.ts.map +1 -0
- package/esm/charts/ring-progress/index.js +137 -0
- package/esm/charts/sankey-chart/index.d.ts +34 -0
- package/esm/charts/sankey-chart/index.d.ts.map +1 -0
- package/esm/charts/sankey-chart/index.js +248 -0
- package/esm/charts/scatter-chart/index.d.ts +34 -0
- package/esm/charts/scatter-chart/index.d.ts.map +1 -0
- package/esm/charts/scatter-chart/index.js +305 -0
- package/esm/charts/sparkline/index.d.ts +31 -0
- package/esm/charts/sparkline/index.d.ts.map +1 -0
- package/esm/charts/sparkline/index.js +152 -0
- package/esm/charts/tree-chart/index.d.ts +34 -0
- package/esm/charts/tree-chart/index.d.ts.map +1 -0
- package/esm/charts/tree-chart/index.js +200 -0
- package/esm/charts/treemap-chart/index.d.ts +35 -0
- package/esm/charts/treemap-chart/index.d.ts.map +1 -0
- package/esm/charts/treemap-chart/index.js +239 -0
- package/esm/charts/waterfall-chart/index.d.ts +41 -0
- package/esm/charts/waterfall-chart/index.d.ts.map +1 -0
- package/esm/charts/waterfall-chart/index.js +281 -0
- package/esm/components/Legend.d.ts +24 -0
- package/esm/components/Legend.d.ts.map +1 -0
- package/esm/components/Legend.js +50 -0
- package/esm/components/Tooltip.d.ts +24 -0
- package/esm/components/Tooltip.d.ts.map +1 -0
- package/esm/components/Tooltip.js +85 -0
- package/esm/components/chart/index.d.ts +71 -0
- package/esm/components/chart/index.d.ts.map +1 -0
- package/esm/components/chart/index.js +142 -0
- package/esm/components/chart.less +223 -0
- package/esm/core/animation.d.ts +49 -0
- package/esm/core/animation.d.ts.map +1 -0
- package/esm/core/animation.js +93 -0
- package/esm/core/force.d.ts +43 -0
- package/esm/core/force.d.ts.map +1 -0
- package/esm/core/force.js +134 -0
- package/esm/core/format.d.ts +34 -0
- package/esm/core/format.d.ts.map +1 -0
- package/esm/core/format.js +81 -0
- package/esm/core/hierarchy.d.ts +77 -0
- package/esm/core/hierarchy.d.ts.map +1 -0
- package/esm/core/hierarchy.js +233 -0
- package/esm/core/layout.d.ts +67 -0
- package/esm/core/layout.d.ts.map +1 -0
- package/esm/core/layout.js +121 -0
- package/esm/core/sampling.d.ts +32 -0
- package/esm/core/sampling.d.ts.map +1 -0
- package/esm/core/sampling.js +124 -0
- package/esm/core/sankey.d.ts +67 -0
- package/esm/core/sankey.d.ts.map +1 -0
- package/esm/core/sankey.js +136 -0
- package/esm/core/scale.d.ts +98 -0
- package/esm/core/scale.d.ts.map +1 -0
- package/esm/core/scale.js +207 -0
- package/esm/core/shape.d.ts +60 -0
- package/esm/core/shape.d.ts.map +1 -0
- package/esm/core/shape.js +246 -0
- package/esm/global.d.ts +6 -0
- package/esm/hooks/useChartTheme.d.ts +11 -0
- package/esm/hooks/useChartTheme.d.ts.map +1 -0
- package/esm/hooks/useChartTheme.js +35 -0
- package/esm/hooks/useChartTransition.d.ts +20 -0
- package/esm/hooks/useChartTransition.d.ts.map +1 -0
- package/esm/hooks/useChartTransition.js +120 -0
- package/esm/hooks/useElementSize.d.ts +17 -0
- package/esm/hooks/useElementSize.d.ts.map +1 -0
- package/esm/hooks/useElementSize.js +47 -0
- package/esm/index.d.ts +62 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +48 -0
- package/esm/internal/CartesianChart.d.ts +16 -0
- package/esm/internal/CartesianChart.d.ts.map +1 -0
- package/esm/internal/CartesianChart.js +811 -0
- package/esm/internal/model.d.ts +67 -0
- package/esm/internal/model.d.ts.map +1 -0
- package/esm/internal/model.js +146 -0
- package/esm/scene/canvas.d.ts +18 -0
- package/esm/scene/canvas.d.ts.map +1 -0
- package/esm/scene/canvas.js +138 -0
- package/esm/scene/svg.d.ts +12 -0
- package/esm/scene/svg.d.ts.map +1 -0
- package/esm/scene/svg.js +116 -0
- package/esm/scene/types.d.ts +89 -0
- package/esm/scene/types.d.ts.map +1 -0
- package/esm/scene/types.js +21 -0
- package/esm/style.css +196 -0
- package/esm/theme/index.d.ts +127 -0
- package/esm/theme/index.d.ts.map +1 -0
- package/esm/theme/index.js +300 -0
- package/esm/types.d.ts +168 -0
- package/esm/types.d.ts.map +1 -0
- package/esm/types.js +2 -0
- package/package.json +64 -3
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { ChartDataRow, SeriesConfig, SeriesType } from '../types.js';
|
|
2
|
+
import { type ChartTheme } from '../theme/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* 数据模型归一化。
|
|
5
|
+
*
|
|
6
|
+
* 图表组件不直接消费用户传入的原始 props,而是先过这一层:
|
|
7
|
+
* · 补齐缺省值(颜色、名称、类型);
|
|
8
|
+
* · 计算堆叠基线(柱状图堆叠、面积图堆叠共用一套逻辑);
|
|
9
|
+
* · 判定 y 轴值域。
|
|
10
|
+
* 好处是所有边界情况(null、全零、单点、负值)只在这一处处理。
|
|
11
|
+
*/
|
|
12
|
+
export interface ResolvedSeries {
|
|
13
|
+
config: SeriesConfig;
|
|
14
|
+
index: number;
|
|
15
|
+
key: string;
|
|
16
|
+
name: string;
|
|
17
|
+
color: string;
|
|
18
|
+
type: SeriesType;
|
|
19
|
+
/** 原始值,null 表示缺失 */
|
|
20
|
+
values: (number | null)[];
|
|
21
|
+
/** 堆叠基线,非堆叠时恒为 0 */
|
|
22
|
+
base: number[];
|
|
23
|
+
/** 实际绘制值 = base + value(逐点) */
|
|
24
|
+
top: (number | null)[];
|
|
25
|
+
visible: boolean;
|
|
26
|
+
stackId?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface ResolveSeriesOptions {
|
|
29
|
+
data: ChartDataRow[];
|
|
30
|
+
series: SeriesConfig[];
|
|
31
|
+
theme: ChartTheme;
|
|
32
|
+
defaultType: SeriesType;
|
|
33
|
+
/** 显式隐藏的系列 key */
|
|
34
|
+
hidden?: Set<string>;
|
|
35
|
+
}
|
|
36
|
+
export declare function resolveSeries(options: ResolveSeriesOptions): ResolvedSeries[];
|
|
37
|
+
/**
|
|
38
|
+
* 就地计算堆叠基线。
|
|
39
|
+
*
|
|
40
|
+
* 正负值分开累加(与 ECharts 行为一致):正值从 0 往上堆,
|
|
41
|
+
* 负值从 0 往下堆,两者互不干扰 —— 否则「收入正、支出负」的图会错位。
|
|
42
|
+
*/
|
|
43
|
+
export declare function applyStacking(series: ResolvedSeries[]): void;
|
|
44
|
+
/** 为未显式指定 stack 的系列自动编组(图表级 stack 开关) */
|
|
45
|
+
export declare function assignDefaultStack(series: ResolvedSeries[], enabled: boolean): void;
|
|
46
|
+
export interface DomainOptions {
|
|
47
|
+
/** 只统计某一根 y 轴上的系列:0 左轴,1 右轴,不传为全部 */
|
|
48
|
+
yAxisIndex?: 0 | 1;
|
|
49
|
+
startFromZero?: boolean;
|
|
50
|
+
min?: number;
|
|
51
|
+
max?: number;
|
|
52
|
+
/** 是否把 base 也纳入值域(堆叠面积图需要) */
|
|
53
|
+
includeBase?: boolean;
|
|
54
|
+
}
|
|
55
|
+
/** 计算 y 轴值域 */
|
|
56
|
+
export declare function resolveYDomain(series: readonly ResolvedSeries[], options?: DomainOptions): [number, number];
|
|
57
|
+
/** 提取 x 轴分类值,并做去重保护(重复分类会让 band 定位错乱) */
|
|
58
|
+
export declare function resolveXValues(data: readonly ChartDataRow[], xKey: string): string[];
|
|
59
|
+
/** 按 x 索引取整行的 tooltip 载荷 */
|
|
60
|
+
export declare function buildTooltipItems(series: readonly ResolvedSeries[], index: number): {
|
|
61
|
+
key: string;
|
|
62
|
+
name: string;
|
|
63
|
+
color: string;
|
|
64
|
+
value: number | null;
|
|
65
|
+
formatted: string;
|
|
66
|
+
}[];
|
|
67
|
+
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEvE,OAAO,EAAW,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAEpD;;;;;;;;GAQG;AAEH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,YAAY,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,UAAU,CAAC;IACjB,oBAAoB;IACpB,MAAM,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;IAC1B,oBAAoB;IACpB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,+BAA+B;IAC/B,GAAG,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAQD,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,YAAY,EAAE,CAAC;IACrB,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,KAAK,EAAE,UAAU,CAAC;IAClB,WAAW,EAAE,UAAU,CAAC;IACxB,kBAAkB;IAClB,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACtB;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,cAAc,EAAE,CAsB7E;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,IAAI,CA4C5D;AAED,yCAAyC;AACzC,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,cAAc,EAAE,EACxB,OAAO,EAAE,OAAO,GACf,IAAI,CAKN;AAED,MAAM,WAAW,aAAa;IAC5B,qCAAqC;IACrC,UAAU,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,8BAA8B;IAC9B,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,eAAe;AACf,wBAAgB,cAAc,CAC5B,MAAM,EAAE,SAAS,cAAc,EAAE,EACjC,OAAO,GAAE,aAAkB,GAC1B,CAAC,MAAM,EAAE,MAAM,CAAC,CA6BlB;AAED,yCAAyC;AACzC,wBAAgB,cAAc,CAC5B,IAAI,EAAE,SAAS,YAAY,EAAE,EAC7B,IAAI,EAAE,MAAM,GACX,MAAM,EAAE,CAKV;AAED,4BAA4B;AAC5B,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,SAAS,cAAc,EAAE,EACjC,KAAK,EAAE,MAAM;;;;;;IAgBd"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { extentOf } from "../core/scale";
|
|
3
|
+
import { colorAt } from "../theme";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 数据模型归一化。
|
|
7
|
+
*
|
|
8
|
+
* 图表组件不直接消费用户传入的原始 props,而是先过这一层:
|
|
9
|
+
* · 补齐缺省值(颜色、名称、类型);
|
|
10
|
+
* · 计算堆叠基线(柱状图堆叠、面积图堆叠共用一套逻辑);
|
|
11
|
+
* · 判定 y 轴值域。
|
|
12
|
+
* 好处是所有边界情况(null、全零、单点、负值)只在这一处处理。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
function toNumber(value) {
|
|
16
|
+
if (value === null || value === undefined || value === '') return null;
|
|
17
|
+
const num = typeof value === 'number' ? value : Number(value);
|
|
18
|
+
return Number.isNaN(num) ? null : num;
|
|
19
|
+
}
|
|
20
|
+
export function resolveSeries(options) {
|
|
21
|
+
const {
|
|
22
|
+
data,
|
|
23
|
+
series,
|
|
24
|
+
theme,
|
|
25
|
+
defaultType,
|
|
26
|
+
hidden
|
|
27
|
+
} = options;
|
|
28
|
+
return series.map((config, index) => {
|
|
29
|
+
const values = config.data ? config.data.map(v => toNumber(v)) : data.map(row => toNumber(row[config.key]));
|
|
30
|
+
return {
|
|
31
|
+
config,
|
|
32
|
+
index,
|
|
33
|
+
key: config.key,
|
|
34
|
+
name: config.name ?? config.key,
|
|
35
|
+
color: config.color ?? colorAt(theme, index),
|
|
36
|
+
type: config.type ?? defaultType,
|
|
37
|
+
values,
|
|
38
|
+
base: values.map(() => 0),
|
|
39
|
+
top: values.slice(),
|
|
40
|
+
visible: !config.hidden && !hidden?.has(config.key),
|
|
41
|
+
stackId: config.stack
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 就地计算堆叠基线。
|
|
48
|
+
*
|
|
49
|
+
* 正负值分开累加(与 ECharts 行为一致):正值从 0 往上堆,
|
|
50
|
+
* 负值从 0 往下堆,两者互不干扰 —— 否则「收入正、支出负」的图会错位。
|
|
51
|
+
*/
|
|
52
|
+
export function applyStacking(series) {
|
|
53
|
+
const groups = new Map();
|
|
54
|
+
for (const item of series) {
|
|
55
|
+
if (!item.stackId) {
|
|
56
|
+
// 非堆叠系列:base 归零,top 即原值
|
|
57
|
+
item.base = item.values.map(() => 0);
|
|
58
|
+
item.top = item.values.slice();
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const list = groups.get(item.stackId) ?? [];
|
|
62
|
+
list.push(item);
|
|
63
|
+
groups.set(item.stackId, list);
|
|
64
|
+
}
|
|
65
|
+
for (const group of groups.values()) {
|
|
66
|
+
const length = Math.max(0, ...group.map(item => item.values.length));
|
|
67
|
+
const positive = new Array(length).fill(0);
|
|
68
|
+
const negative = new Array(length).fill(0);
|
|
69
|
+
for (const item of group) {
|
|
70
|
+
const base = [];
|
|
71
|
+
const top = [];
|
|
72
|
+
for (let i = 0; i < length; i += 1) {
|
|
73
|
+
const value = item.values[i] ?? null;
|
|
74
|
+
if (value === null) {
|
|
75
|
+
base.push(0);
|
|
76
|
+
top.push(null);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (value >= 0) {
|
|
80
|
+
base.push(positive[i]);
|
|
81
|
+
top.push(positive[i] + value);
|
|
82
|
+
positive[i] += value;
|
|
83
|
+
} else {
|
|
84
|
+
base.push(negative[i]);
|
|
85
|
+
top.push(negative[i] + value);
|
|
86
|
+
negative[i] += value;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
item.base = base;
|
|
90
|
+
item.top = top;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** 为未显式指定 stack 的系列自动编组(图表级 stack 开关) */
|
|
96
|
+
export function assignDefaultStack(series, enabled) {
|
|
97
|
+
if (!enabled) return;
|
|
98
|
+
for (const item of series) {
|
|
99
|
+
if (!item.stackId) item.stackId = '__default__';
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** 计算 y 轴值域 */
|
|
103
|
+
export function resolveYDomain(series, options = {}) {
|
|
104
|
+
const visible = series.filter(item => item.visible && (options.yAxisIndex === undefined || (item.config.yAxisIndex ?? 0) === options.yAxisIndex));
|
|
105
|
+
const pool = [];
|
|
106
|
+
for (const item of visible) {
|
|
107
|
+
for (let i = 0; i < item.values.length; i += 1) {
|
|
108
|
+
pool.push(item.top[i]);
|
|
109
|
+
if (options.includeBase) pool.push(item.base[i]);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
let [min, max] = extentOf(pool);
|
|
113
|
+
if (options.startFromZero) {
|
|
114
|
+
min = Math.min(0, min);
|
|
115
|
+
max = Math.max(0, max);
|
|
116
|
+
}
|
|
117
|
+
if (options.min !== undefined) min = options.min;
|
|
118
|
+
if (options.max !== undefined) max = options.max;
|
|
119
|
+
|
|
120
|
+
// 全零数据的退化处理:给一个固定的可视高度,否则所有内容压在同一条线上
|
|
121
|
+
if (min === 0 && max === 0) return [0, 1];
|
|
122
|
+
return [min, max];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** 提取 x 轴分类值,并做去重保护(重复分类会让 band 定位错乱) */
|
|
126
|
+
export function resolveXValues(data, xKey) {
|
|
127
|
+
return data.map(row => {
|
|
128
|
+
const raw = row[xKey];
|
|
129
|
+
return raw === null || raw === undefined ? '' : String(raw);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** 按 x 索引取整行的 tooltip 载荷 */
|
|
134
|
+
export function buildTooltipItems(series, index) {
|
|
135
|
+
return series.filter(item => item.visible).map(item => {
|
|
136
|
+
const value = item.values[index] ?? null;
|
|
137
|
+
const formatter = item.config.valueFormatter;
|
|
138
|
+
return {
|
|
139
|
+
key: item.key,
|
|
140
|
+
name: item.name,
|
|
141
|
+
color: item.color,
|
|
142
|
+
value,
|
|
143
|
+
formatted: value === null ? '—' : formatter ? formatter(value) : String(value)
|
|
144
|
+
};
|
|
145
|
+
});
|
|
146
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { SceneNode } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* 场景 → Canvas 2D 绘制。
|
|
4
|
+
*
|
|
5
|
+
* 使用场景:单系列点数超过 `canvasThreshold`(默认 2000)时,
|
|
6
|
+
* SVG 的 DOM 节点数会拖垮布局与重绘,切 Canvas 后只保留一次 draw call 批次。
|
|
7
|
+
*
|
|
8
|
+
* 注意:Canvas 里没有 DOM 节点,也就没有逐图元的事件与无障碍语义。
|
|
9
|
+
* 因此启用 Canvas 时,图表仍会渲染一份**隐藏的无障碍数据表**(见 Chart 组件),
|
|
10
|
+
* tooltip 也退化为按 x 轴索引命中,而非逐 mark 命中。
|
|
11
|
+
*/
|
|
12
|
+
export interface PaintOptions {
|
|
13
|
+
/** 设备像素比,用于高清屏 */
|
|
14
|
+
dpr?: number;
|
|
15
|
+
}
|
|
16
|
+
/** 把场景画到 canvas 上(会先清空并处理 DPR 缩放) */
|
|
17
|
+
export declare function paintScene(canvas: HTMLCanvasElement, nodes: readonly SceneNode[], options?: PaintOptions): void;
|
|
18
|
+
//# sourceMappingURL=canvas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvas.d.ts","sourceRoot":"","sources":["canvas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;;;;;;;;GASG;AAEH,MAAM,WAAW,YAAY;IAC3B,kBAAkB;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAqID,qCAAqC;AACrC,wBAAgB,UAAU,CACxB,MAAM,EAAE,iBAAiB,EACzB,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,OAAO,GAAE,YAAiB,GACzB,IAAI,CAqBN"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
/**
|
|
3
|
+
* 场景 → Canvas 2D 绘制。
|
|
4
|
+
*
|
|
5
|
+
* 使用场景:单系列点数超过 `canvasThreshold`(默认 2000)时,
|
|
6
|
+
* SVG 的 DOM 节点数会拖垮布局与重绘,切 Canvas 后只保留一次 draw call 批次。
|
|
7
|
+
*
|
|
8
|
+
* 注意:Canvas 里没有 DOM 节点,也就没有逐图元的事件与无障碍语义。
|
|
9
|
+
* 因此启用 Canvas 时,图表仍会渲染一份**隐藏的无障碍数据表**(见 Chart 组件),
|
|
10
|
+
* tooltip 也退化为按 x 轴索引命中,而非逐 mark 命中。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
function applyPaint(ctx, node) {
|
|
14
|
+
ctx.fillStyle = node.fill ?? 'transparent';
|
|
15
|
+
ctx.strokeStyle = node.stroke ?? 'transparent';
|
|
16
|
+
ctx.lineWidth = node.strokeWidth ?? 1;
|
|
17
|
+
ctx.globalAlpha = node.opacity ?? 1;
|
|
18
|
+
if (node.strokeDasharray) {
|
|
19
|
+
// "3 3" → [3, 3]
|
|
20
|
+
const parts = node.strokeDasharray.split(/[\s,]+/).map(Number).filter(n => !Number.isNaN(n));
|
|
21
|
+
ctx.setLineDash(parts);
|
|
22
|
+
} else {
|
|
23
|
+
ctx.setLineDash([]);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function drawNodes(ctx, nodes) {
|
|
27
|
+
for (const node of nodes) {
|
|
28
|
+
switch (node.kind) {
|
|
29
|
+
case 'group':
|
|
30
|
+
{
|
|
31
|
+
ctx.save();
|
|
32
|
+
// group 的 transform 是 SVG 写法,这里只支持 translate(...)(当前图表未用到更复杂的)
|
|
33
|
+
if (node.transform) {
|
|
34
|
+
const matched = /translate\(\s*(-?[\d.]+)[,\s]+(-?[\d.]+)\s*\)/.exec(node.transform);
|
|
35
|
+
if (matched) ctx.translate(Number(matched[1]), Number(matched[2]));
|
|
36
|
+
}
|
|
37
|
+
drawNodes(ctx, node.children);
|
|
38
|
+
ctx.restore();
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
case 'rect':
|
|
42
|
+
{
|
|
43
|
+
applyPaint(ctx, node);
|
|
44
|
+
const radius = Math.min(node.radius ?? 0, Math.abs(node.width) / 2, Math.abs(node.height) / 2);
|
|
45
|
+
ctx.beginPath();
|
|
46
|
+
if (radius > 0) {
|
|
47
|
+
// roundRect 在部分旧环境不可用,手写等价路径
|
|
48
|
+
const {
|
|
49
|
+
x,
|
|
50
|
+
y,
|
|
51
|
+
width,
|
|
52
|
+
height
|
|
53
|
+
} = node;
|
|
54
|
+
ctx.moveTo(x + radius, y);
|
|
55
|
+
ctx.lineTo(x + width - radius, y);
|
|
56
|
+
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
|
|
57
|
+
ctx.lineTo(x + width, y + height - radius);
|
|
58
|
+
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
|
|
59
|
+
ctx.lineTo(x + radius, y + height);
|
|
60
|
+
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
|
|
61
|
+
ctx.lineTo(x, y + radius);
|
|
62
|
+
ctx.quadraticCurveTo(x, y, x + radius, y);
|
|
63
|
+
ctx.closePath();
|
|
64
|
+
} else {
|
|
65
|
+
ctx.rect(node.x, node.y, node.width, node.height);
|
|
66
|
+
}
|
|
67
|
+
if (node.fill && node.fill !== 'none') ctx.fill();
|
|
68
|
+
if (node.stroke) ctx.stroke();
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
case 'path':
|
|
72
|
+
{
|
|
73
|
+
applyPaint(ctx, node);
|
|
74
|
+
const path = new Path2D(node.d);
|
|
75
|
+
if (node.fill && node.fill !== 'none') ctx.fill(path);
|
|
76
|
+
if (node.stroke) ctx.stroke(path);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case 'circle':
|
|
80
|
+
{
|
|
81
|
+
applyPaint(ctx, node);
|
|
82
|
+
ctx.beginPath();
|
|
83
|
+
ctx.arc(node.cx, node.cy, Math.max(0, node.r), 0, Math.PI * 2);
|
|
84
|
+
if (node.fill && node.fill !== 'none') ctx.fill();
|
|
85
|
+
if (node.stroke) ctx.stroke();
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case 'line':
|
|
89
|
+
{
|
|
90
|
+
applyPaint(ctx, node);
|
|
91
|
+
ctx.beginPath();
|
|
92
|
+
ctx.moveTo(node.x1, node.y1);
|
|
93
|
+
ctx.lineTo(node.x2, node.y2);
|
|
94
|
+
ctx.stroke();
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
case 'text':
|
|
98
|
+
{
|
|
99
|
+
applyPaint(ctx, {
|
|
100
|
+
...node,
|
|
101
|
+
stroke: undefined
|
|
102
|
+
});
|
|
103
|
+
ctx.font = `${node.fontWeight ?? 400} ${node.fontSize ?? 12}px ${node.fontFamily ?? 'sans-serif'}`;
|
|
104
|
+
ctx.textAlign = node.anchor === 'middle' ? 'center' : node.anchor === 'end' ? 'right' : 'left';
|
|
105
|
+
ctx.textBaseline = node.baseline === 'middle' ? 'middle' : node.baseline === 'hanging' ? 'top' : 'alphabetic';
|
|
106
|
+
if (node.rotate) {
|
|
107
|
+
ctx.save();
|
|
108
|
+
ctx.translate(node.x, node.y);
|
|
109
|
+
ctx.rotate(node.rotate * Math.PI / 180);
|
|
110
|
+
ctx.fillText(node.text, 0, 0);
|
|
111
|
+
ctx.restore();
|
|
112
|
+
} else {
|
|
113
|
+
ctx.fillText(node.text, node.x, node.y);
|
|
114
|
+
}
|
|
115
|
+
ctx.globalAlpha = 1;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
default:
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** 把场景画到 canvas 上(会先清空并处理 DPR 缩放) */
|
|
125
|
+
export function paintScene(canvas, nodes, options = {}) {
|
|
126
|
+
const ctx = canvas.getContext('2d');
|
|
127
|
+
if (!ctx) return;
|
|
128
|
+
const dpr = options.dpr ?? (typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1);
|
|
129
|
+
const width = canvas.clientWidth || canvas.width;
|
|
130
|
+
const height = canvas.clientHeight || canvas.height;
|
|
131
|
+
if (canvas.width !== Math.floor(width * dpr) || canvas.height !== Math.floor(height * dpr)) {
|
|
132
|
+
canvas.width = Math.floor(width * dpr);
|
|
133
|
+
canvas.height = Math.floor(height * dpr);
|
|
134
|
+
}
|
|
135
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
136
|
+
ctx.clearRect(0, 0, width, height);
|
|
137
|
+
drawNodes(ctx, nodes);
|
|
138
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { SceneNode } from './types.js';
|
|
3
|
+
export interface SvgSceneProps {
|
|
4
|
+
nodes: SceneNode[];
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
/** 无障碍描述 */
|
|
8
|
+
ariaLabel?: string;
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function SvgScene({ nodes, width, height, ariaLabel, className, }: SvgSceneProps): React.JSX.Element;
|
|
12
|
+
//# sourceMappingURL=svg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svg.d.ts","sourceRoot":"","sources":["svg.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAwHzC,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,YAAY;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,QAAQ,CAAC,EACvB,KAAK,EACL,KAAK,EACL,MAAM,EACN,SAAS,EACT,SAAS,GACV,EAAE,aAAa,qBAcf"}
|
package/esm/scene/svg.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
/**
|
|
5
|
+
* 场景 → SVG 元素。
|
|
6
|
+
*
|
|
7
|
+
* 为什么 SVG 是默认渲染器:
|
|
8
|
+
* · 每个图元都是真实 DOM,可被测试查询、可被无障碍工具读取;
|
|
9
|
+
* · 打印/导出为矢量不失真;
|
|
10
|
+
* · 主题换色只是改属性,无需重绘位图。
|
|
11
|
+
* 数据量超过阈值时切 Canvas(见 canvas.ts)。
|
|
12
|
+
*/
|
|
13
|
+
function renderNode(node) {
|
|
14
|
+
const common = {
|
|
15
|
+
opacity: node.opacity,
|
|
16
|
+
pointerEvents: node.pointerEvents
|
|
17
|
+
};
|
|
18
|
+
switch (node.kind) {
|
|
19
|
+
case 'group':
|
|
20
|
+
return /*#__PURE__*/_jsx("g", {
|
|
21
|
+
transform: node.transform,
|
|
22
|
+
...common,
|
|
23
|
+
children: node.children.map(renderNode)
|
|
24
|
+
}, node.key);
|
|
25
|
+
case 'rect':
|
|
26
|
+
return /*#__PURE__*/_jsx("rect", {
|
|
27
|
+
x: node.x,
|
|
28
|
+
y: node.y,
|
|
29
|
+
width: Math.max(0, node.width),
|
|
30
|
+
height: Math.max(0, node.height),
|
|
31
|
+
rx: node.radius,
|
|
32
|
+
ry: node.radius,
|
|
33
|
+
fill: node.fill ?? 'none',
|
|
34
|
+
stroke: node.stroke,
|
|
35
|
+
strokeWidth: node.strokeWidth,
|
|
36
|
+
strokeDasharray: node.strokeDasharray,
|
|
37
|
+
...common
|
|
38
|
+
}, node.key);
|
|
39
|
+
case 'path':
|
|
40
|
+
return /*#__PURE__*/_jsx("path", {
|
|
41
|
+
d: node.d,
|
|
42
|
+
fill: node.fill ?? 'none',
|
|
43
|
+
stroke: node.stroke,
|
|
44
|
+
strokeWidth: node.strokeWidth,
|
|
45
|
+
strokeDasharray: node.strokeDasharray,
|
|
46
|
+
strokeLinecap: node.linecap,
|
|
47
|
+
strokeLinejoin: node.linejoin,
|
|
48
|
+
...common
|
|
49
|
+
}, node.key);
|
|
50
|
+
case 'circle':
|
|
51
|
+
return /*#__PURE__*/_jsx("circle", {
|
|
52
|
+
cx: node.cx,
|
|
53
|
+
cy: node.cy,
|
|
54
|
+
r: Math.max(0, node.r),
|
|
55
|
+
fill: node.fill ?? 'none',
|
|
56
|
+
stroke: node.stroke,
|
|
57
|
+
strokeWidth: node.strokeWidth,
|
|
58
|
+
...common
|
|
59
|
+
}, node.key);
|
|
60
|
+
case 'line':
|
|
61
|
+
return /*#__PURE__*/_jsx("line", {
|
|
62
|
+
x1: node.x1,
|
|
63
|
+
y1: node.y1,
|
|
64
|
+
x2: node.x2,
|
|
65
|
+
y2: node.y2,
|
|
66
|
+
stroke: node.stroke,
|
|
67
|
+
strokeWidth: node.strokeWidth ?? 1,
|
|
68
|
+
strokeDasharray: node.strokeDasharray,
|
|
69
|
+
...common
|
|
70
|
+
}, node.key);
|
|
71
|
+
case 'text':
|
|
72
|
+
return /*#__PURE__*/_jsx("text", {
|
|
73
|
+
x: node.x,
|
|
74
|
+
y: node.y,
|
|
75
|
+
fill: node.fill,
|
|
76
|
+
fontSize: node.fontSize,
|
|
77
|
+
fontWeight: node.fontWeight,
|
|
78
|
+
fontFamily: node.fontFamily,
|
|
79
|
+
textAnchor: node.anchor ?? 'start',
|
|
80
|
+
dominantBaseline: node.baseline === 'middle' ? 'central' : node.baseline === 'hanging' ? 'hanging' : 'auto',
|
|
81
|
+
transform: node.rotate ? `rotate(${node.rotate} ${node.x} ${node.y})` : undefined,
|
|
82
|
+
stroke: node.stroke,
|
|
83
|
+
strokeWidth: node.strokeWidth
|
|
84
|
+
// 描边画在填充下面,形成光晕而不是把字吃细
|
|
85
|
+
,
|
|
86
|
+
paintOrder: "stroke",
|
|
87
|
+
strokeLinejoin: "round",
|
|
88
|
+
...common,
|
|
89
|
+
children: node.text
|
|
90
|
+
}, node.key);
|
|
91
|
+
default:
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export function SvgScene({
|
|
96
|
+
nodes,
|
|
97
|
+
width,
|
|
98
|
+
height,
|
|
99
|
+
ariaLabel,
|
|
100
|
+
className
|
|
101
|
+
}) {
|
|
102
|
+
return /*#__PURE__*/_jsx("svg", {
|
|
103
|
+
className: className,
|
|
104
|
+
width: width,
|
|
105
|
+
height: height,
|
|
106
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
107
|
+
role: "img",
|
|
108
|
+
"aria-label": ariaLabel,
|
|
109
|
+
style: {
|
|
110
|
+
display: 'block',
|
|
111
|
+
maxWidth: '100%',
|
|
112
|
+
overflow: 'visible'
|
|
113
|
+
},
|
|
114
|
+
children: nodes.map(renderNode)
|
|
115
|
+
});
|
|
116
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 场景图节点定义。
|
|
3
|
+
*
|
|
4
|
+
* 图表不复用 React 元素树做几何描述(那样 Canvas 渲染器无从下手),
|
|
5
|
+
* 而是先算出一份纯数据化的「场景」:一组带坐标的图元。
|
|
6
|
+
* 于是:
|
|
7
|
+
* · SVG 渲染器 = 场景 → React 元素;
|
|
8
|
+
* · Canvas 渲染器 = 场景 → 2D 绘制指令。
|
|
9
|
+
* 两者消费同一份场景,天然保持一致。
|
|
10
|
+
*/
|
|
11
|
+
export type TextAnchor = 'start' | 'middle' | 'end';
|
|
12
|
+
export type TextBaseline = 'auto' | 'middle' | 'hanging' | 'alphabetic';
|
|
13
|
+
interface Base {
|
|
14
|
+
key: string;
|
|
15
|
+
opacity?: number;
|
|
16
|
+
/** 鼠标事件穿透控制;tooltip 命中区通常需要真实事件 */
|
|
17
|
+
pointerEvents?: 'auto' | 'none';
|
|
18
|
+
}
|
|
19
|
+
export interface GroupNode extends Base {
|
|
20
|
+
kind: 'group';
|
|
21
|
+
children: SceneNode[];
|
|
22
|
+
transform?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface RectNode extends Base {
|
|
25
|
+
kind: 'rect';
|
|
26
|
+
x: number;
|
|
27
|
+
y: number;
|
|
28
|
+
width: number;
|
|
29
|
+
height: number;
|
|
30
|
+
radius?: number;
|
|
31
|
+
fill?: string;
|
|
32
|
+
stroke?: string;
|
|
33
|
+
strokeWidth?: number;
|
|
34
|
+
strokeDasharray?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface PathNode extends Base {
|
|
37
|
+
kind: 'path';
|
|
38
|
+
d: string;
|
|
39
|
+
fill?: string;
|
|
40
|
+
stroke?: string;
|
|
41
|
+
strokeWidth?: number;
|
|
42
|
+
strokeDasharray?: string;
|
|
43
|
+
linecap?: 'butt' | 'round' | 'square';
|
|
44
|
+
linejoin?: 'miter' | 'round' | 'bevel';
|
|
45
|
+
}
|
|
46
|
+
export interface CircleNode extends Base {
|
|
47
|
+
kind: 'circle';
|
|
48
|
+
cx: number;
|
|
49
|
+
cy: number;
|
|
50
|
+
r: number;
|
|
51
|
+
fill?: string;
|
|
52
|
+
stroke?: string;
|
|
53
|
+
strokeWidth?: number;
|
|
54
|
+
}
|
|
55
|
+
export interface LineNode extends Base {
|
|
56
|
+
kind: 'line';
|
|
57
|
+
x1: number;
|
|
58
|
+
y1: number;
|
|
59
|
+
x2: number;
|
|
60
|
+
y2: number;
|
|
61
|
+
stroke: string;
|
|
62
|
+
strokeWidth?: number;
|
|
63
|
+
strokeDasharray?: string;
|
|
64
|
+
}
|
|
65
|
+
export interface TextNode extends Base {
|
|
66
|
+
kind: 'text';
|
|
67
|
+
x: number;
|
|
68
|
+
y: number;
|
|
69
|
+
text: string;
|
|
70
|
+
fill?: string;
|
|
71
|
+
fontSize?: number;
|
|
72
|
+
fontWeight?: number;
|
|
73
|
+
anchor?: TextAnchor;
|
|
74
|
+
baseline?: TextBaseline;
|
|
75
|
+
/** 绕自身锚点旋转的度数(x 轴刻度标签拥挤时用) */
|
|
76
|
+
rotate?: number;
|
|
77
|
+
fontFamily?: string;
|
|
78
|
+
/**
|
|
79
|
+
* 文字描边色。配合 strokeWidth 形成「光晕」,
|
|
80
|
+
* 让文字压在色带/网格上时仍然可读(paint-order 保证描边在填充下方)。
|
|
81
|
+
*/
|
|
82
|
+
stroke?: string;
|
|
83
|
+
strokeWidth?: number;
|
|
84
|
+
}
|
|
85
|
+
export type SceneNode = GroupNode | RectNode | PathNode | CircleNode | LineNode | TextNode;
|
|
86
|
+
/** 递归统计节点数,便于性能告警与测试断言 */
|
|
87
|
+
export declare function countNodes(nodes: readonly SceneNode[]): number;
|
|
88
|
+
export {};
|
|
89
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
/**
|
|
3
|
+
* 场景图节点定义。
|
|
4
|
+
*
|
|
5
|
+
* 图表不复用 React 元素树做几何描述(那样 Canvas 渲染器无从下手),
|
|
6
|
+
* 而是先算出一份纯数据化的「场景」:一组带坐标的图元。
|
|
7
|
+
* 于是:
|
|
8
|
+
* · SVG 渲染器 = 场景 → React 元素;
|
|
9
|
+
* · Canvas 渲染器 = 场景 → 2D 绘制指令。
|
|
10
|
+
* 两者消费同一份场景,天然保持一致。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** 递归统计节点数,便于性能告警与测试断言 */
|
|
14
|
+
export function countNodes(nodes) {
|
|
15
|
+
let total = 0;
|
|
16
|
+
for (const node of nodes) {
|
|
17
|
+
total += 1;
|
|
18
|
+
if (node.kind === 'group') total += countNodes(node.children);
|
|
19
|
+
}
|
|
20
|
+
return total;
|
|
21
|
+
}
|