minerva-design 1.2.0 → 1.3.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/CHANGELOG.md +7 -0
- package/dist/charts/canvas.d.cts +4 -1
- package/dist/charts/canvas.d.ts +4 -1
- package/dist/charts/core.cjs +1 -1
- package/dist/charts/core.d.cts +5 -2
- package/dist/charts/core.d.ts +5 -2
- package/dist/charts/core.js +6 -4
- package/dist/charts/engine/canvas.cjs +1 -1
- package/dist/charts/engine/canvas.cjs.map +1 -1
- package/dist/charts/engine/canvas.js +65 -53
- package/dist/charts/engine/canvas.js.map +1 -1
- package/dist/charts/engine/chart.cjs +1 -2
- package/dist/charts/engine/chart.cjs.map +1 -1
- package/dist/charts/engine/chart.js +342 -323
- package/dist/charts/engine/chart.js.map +1 -1
- package/dist/charts/engine/color.cjs +1 -1
- package/dist/charts/engine/color.cjs.map +1 -1
- package/dist/charts/engine/color.d.cts +17 -0
- package/dist/charts/engine/color.d.ts +17 -0
- package/dist/charts/engine/color.js +27 -3
- package/dist/charts/engine/color.js.map +1 -1
- package/dist/charts/engine/controller.cjs +2 -2
- package/dist/charts/engine/controller.cjs.map +1 -1
- package/dist/charts/engine/controller.d.cts +6 -0
- package/dist/charts/engine/controller.d.ts +6 -0
- package/dist/charts/engine/controller.js +317 -253
- package/dist/charts/engine/controller.js.map +1 -1
- package/dist/charts/engine/curve.cjs +2 -0
- package/dist/charts/engine/curve.cjs.map +1 -0
- package/dist/charts/engine/curve.d.cts +15 -0
- package/dist/charts/engine/curve.d.ts +15 -0
- package/dist/charts/engine/curve.js +56 -0
- package/dist/charts/engine/curve.js.map +1 -0
- package/dist/charts/engine/data.cjs +1 -1
- package/dist/charts/engine/data.cjs.map +1 -1
- package/dist/charts/engine/data.d.cts +15 -2
- package/dist/charts/engine/data.d.ts +15 -2
- package/dist/charts/engine/data.js +98 -38
- package/dist/charts/engine/data.js.map +1 -1
- package/dist/charts/engine/dom.cjs +1 -1
- package/dist/charts/engine/dom.cjs.map +1 -1
- package/dist/charts/engine/dom.d.cts +5 -3
- package/dist/charts/engine/dom.d.ts +5 -3
- package/dist/charts/engine/dom.js +27 -22
- package/dist/charts/engine/dom.js.map +1 -1
- package/dist/charts/engine/items.cjs +1 -1
- package/dist/charts/engine/items.cjs.map +1 -1
- package/dist/charts/engine/items.js +132 -61
- package/dist/charts/engine/items.js.map +1 -1
- package/dist/charts/engine/model.cjs +1 -1
- package/dist/charts/engine/model.cjs.map +1 -1
- package/dist/charts/engine/model.d.cts +30 -3
- package/dist/charts/engine/model.d.ts +30 -3
- package/dist/charts/engine/model.js +225 -108
- package/dist/charts/engine/model.js.map +1 -1
- package/dist/charts/engine/overlay.cjs +1 -1
- package/dist/charts/engine/overlay.cjs.map +1 -1
- package/dist/charts/engine/overlay.d.cts +2 -0
- package/dist/charts/engine/overlay.d.ts +2 -0
- package/dist/charts/engine/overlay.js +16 -16
- package/dist/charts/engine/overlay.js.map +1 -1
- package/dist/charts/engine/presets.cjs +2 -2
- package/dist/charts/engine/presets.cjs.map +1 -1
- package/dist/charts/engine/presets.d.cts +71 -5
- package/dist/charts/engine/presets.d.ts +71 -5
- package/dist/charts/engine/presets.js +120 -33
- package/dist/charts/engine/presets.js.map +1 -1
- package/dist/charts/engine/renderers/canvas2d.cjs +1 -1
- package/dist/charts/engine/renderers/canvas2d.cjs.map +1 -1
- package/dist/charts/engine/renderers/canvas2d.js +149 -111
- package/dist/charts/engine/renderers/canvas2d.js.map +1 -1
- package/dist/charts/engine/renderers/range.cjs +1 -1
- package/dist/charts/engine/renderers/range.cjs.map +1 -1
- package/dist/charts/engine/renderers/range.js +4 -4
- package/dist/charts/engine/renderers/range.js.map +1 -1
- package/dist/charts/engine/renderers/shaders.cjs +37 -19
- package/dist/charts/engine/renderers/shaders.cjs.map +1 -1
- package/dist/charts/engine/renderers/shaders.d.cts +2 -2
- package/dist/charts/engine/renderers/shaders.d.ts +2 -2
- package/dist/charts/engine/renderers/shaders.js +37 -19
- package/dist/charts/engine/renderers/shaders.js.map +1 -1
- package/dist/charts/engine/renderers/types.cjs.map +1 -1
- package/dist/charts/engine/renderers/types.d.cts +11 -4
- package/dist/charts/engine/renderers/types.d.ts +11 -4
- package/dist/charts/engine/renderers/types.js.map +1 -1
- package/dist/charts/engine/renderers/webgl2.cjs +1 -1
- package/dist/charts/engine/renderers/webgl2.cjs.map +1 -1
- package/dist/charts/engine/renderers/webgl2.js +33 -12
- package/dist/charts/engine/renderers/webgl2.js.map +1 -1
- package/dist/charts/engine/renderers/webgpu.cjs +1 -1
- package/dist/charts/engine/renderers/webgpu.cjs.map +1 -1
- package/dist/charts/engine/renderers/webgpu.js +18 -15
- package/dist/charts/engine/renderers/webgpu.js.map +1 -1
- package/dist/charts/engine/scene.cjs +1 -1
- package/dist/charts/engine/scene.cjs.map +1 -1
- package/dist/charts/engine/scene.d.cts +19 -6
- package/dist/charts/engine/scene.d.ts +19 -6
- package/dist/charts/engine/scene.js +201 -89
- package/dist/charts/engine/scene.js.map +1 -1
- package/dist/charts/engine/shapes/canvas.cjs +2 -0
- package/dist/charts/engine/shapes/canvas.cjs.map +1 -0
- package/dist/charts/engine/shapes/canvas.d.cts +58 -0
- package/dist/charts/engine/shapes/canvas.d.ts +58 -0
- package/dist/charts/engine/shapes/canvas.js +159 -0
- package/dist/charts/engine/shapes/canvas.js.map +1 -0
- package/dist/charts/engine/shapes/chart.cjs +2 -0
- package/dist/charts/engine/shapes/chart.cjs.map +1 -0
- package/dist/charts/engine/shapes/chart.d.cts +6 -0
- package/dist/charts/engine/shapes/chart.d.ts +6 -0
- package/dist/charts/engine/shapes/chart.js +273 -0
- package/dist/charts/engine/shapes/chart.js.map +1 -0
- package/dist/charts/engine/shapes/draw.cjs +2 -0
- package/dist/charts/engine/shapes/draw.cjs.map +1 -0
- package/dist/charts/engine/shapes/draw.d.cts +20 -0
- package/dist/charts/engine/shapes/draw.d.ts +20 -0
- package/dist/charts/engine/shapes/draw.js +152 -0
- package/dist/charts/engine/shapes/draw.js.map +1 -0
- package/dist/charts/engine/shapes/funnel.cjs +2 -0
- package/dist/charts/engine/shapes/funnel.cjs.map +1 -0
- package/dist/charts/engine/shapes/funnel.d.cts +6 -0
- package/dist/charts/engine/shapes/funnel.d.ts +6 -0
- package/dist/charts/engine/shapes/funnel.js +149 -0
- package/dist/charts/engine/shapes/funnel.js.map +1 -0
- package/dist/charts/engine/shapes/gauge.cjs +2 -0
- package/dist/charts/engine/shapes/gauge.cjs.map +1 -0
- package/dist/charts/engine/shapes/gauge.d.cts +7 -0
- package/dist/charts/engine/shapes/gauge.d.ts +7 -0
- package/dist/charts/engine/shapes/gauge.js +173 -0
- package/dist/charts/engine/shapes/gauge.js.map +1 -0
- package/dist/charts/engine/shapes/hit.cjs +2 -0
- package/dist/charts/engine/shapes/hit.cjs.map +1 -0
- package/dist/charts/engine/shapes/hit.d.cts +28 -0
- package/dist/charts/engine/shapes/hit.d.ts +28 -0
- package/dist/charts/engine/shapes/hit.js +124 -0
- package/dist/charts/engine/shapes/hit.js.map +1 -0
- package/dist/charts/engine/shapes/index.d.cts +9 -0
- package/dist/charts/engine/shapes/index.d.ts +9 -0
- package/dist/charts/engine/shapes/layout.cjs +3 -0
- package/dist/charts/engine/shapes/layout.cjs.map +1 -0
- package/dist/charts/engine/shapes/layout.d.cts +88 -0
- package/dist/charts/engine/shapes/layout.d.ts +88 -0
- package/dist/charts/engine/shapes/layout.js +266 -0
- package/dist/charts/engine/shapes/layout.js.map +1 -0
- package/dist/charts/engine/shapes/pie.cjs +2 -0
- package/dist/charts/engine/shapes/pie.cjs.map +1 -0
- package/dist/charts/engine/shapes/pie.d.cts +20 -0
- package/dist/charts/engine/shapes/pie.d.ts +20 -0
- package/dist/charts/engine/shapes/pie.js +302 -0
- package/dist/charts/engine/shapes/pie.js.map +1 -0
- package/dist/charts/engine/shapes/radar.cjs +2 -0
- package/dist/charts/engine/shapes/radar.cjs.map +1 -0
- package/dist/charts/engine/shapes/radar.d.cts +8 -0
- package/dist/charts/engine/shapes/radar.d.ts +8 -0
- package/dist/charts/engine/shapes/radar.js +197 -0
- package/dist/charts/engine/shapes/radar.js.map +1 -0
- package/dist/charts/engine/shapes/runtime.cjs +2 -0
- package/dist/charts/engine/shapes/runtime.cjs.map +1 -0
- package/dist/charts/engine/shapes/runtime.d.cts +29 -0
- package/dist/charts/engine/shapes/runtime.d.ts +29 -0
- package/dist/charts/engine/shapes/runtime.js +97 -0
- package/dist/charts/engine/shapes/runtime.js.map +1 -0
- package/dist/charts/engine/shapes/scene.cjs +2 -0
- package/dist/charts/engine/shapes/scene.cjs.map +1 -0
- package/dist/charts/engine/shapes/scene.d.cts +257 -0
- package/dist/charts/engine/shapes/scene.d.ts +257 -0
- package/dist/charts/engine/shapes/scene.js +123 -0
- package/dist/charts/engine/shapes/scene.js.map +1 -0
- package/dist/charts/engine/shapes/treemap.cjs +2 -0
- package/dist/charts/engine/shapes/treemap.cjs.map +1 -0
- package/dist/charts/engine/shapes/treemap.d.cts +14 -0
- package/dist/charts/engine/shapes/treemap.d.ts +14 -0
- package/dist/charts/engine/shapes/treemap.js +213 -0
- package/dist/charts/engine/shapes/treemap.js.map +1 -0
- package/dist/charts/engine/shapes/types.d.cts +292 -0
- package/dist/charts/engine/shapes/types.d.ts +292 -0
- package/dist/charts/engine/signature.cjs +2 -0
- package/dist/charts/engine/signature.cjs.map +1 -0
- package/dist/charts/engine/signature.d.cts +9 -0
- package/dist/charts/engine/signature.d.ts +9 -0
- package/dist/charts/engine/signature.js +13 -0
- package/dist/charts/engine/signature.js.map +1 -0
- package/dist/charts/engine/theme.cjs +1 -1
- package/dist/charts/engine/theme.cjs.map +1 -1
- package/dist/charts/engine/theme.d.cts +10 -1
- package/dist/charts/engine/theme.d.ts +10 -1
- package/dist/charts/engine/theme.js +40 -16
- package/dist/charts/engine/theme.js.map +1 -1
- package/dist/charts/engine/types.d.cts +70 -9
- package/dist/charts/engine/types.d.ts +70 -9
- package/dist/charts/index.cjs +1 -1
- package/dist/charts/index.d.cts +4 -2
- package/dist/charts/index.d.ts +4 -2
- package/dist/charts/index.js +8 -5
- package/dist/charts/react/Chart.cjs +1 -1
- package/dist/charts/react/Chart.cjs.map +1 -1
- package/dist/charts/react/Chart.d.cts +8 -1
- package/dist/charts/react/Chart.d.ts +8 -1
- package/dist/charts/react/Chart.js +66 -47
- package/dist/charts/react/Chart.js.map +1 -1
- package/dist/charts/react/charts.cjs +1 -1
- package/dist/charts/react/charts.cjs.map +1 -1
- package/dist/charts/react/charts.d.cts +10 -2
- package/dist/charts/react/charts.d.ts +10 -2
- package/dist/charts/react/charts.js +174 -51
- package/dist/charts/react/charts.js.map +1 -1
- package/dist/charts/react/shapes.cjs +2 -0
- package/dist/charts/react/shapes.cjs.map +1 -0
- package/dist/charts/react/shapes.d.cts +255 -0
- package/dist/charts/react/shapes.d.ts +255 -0
- package/dist/charts/react/shapes.js +242 -0
- package/dist/charts/react/shapes.js.map +1 -0
- package/dist/charts/react/types.d.cts +73 -4
- package/dist/charts/react/types.d.ts +73 -4
- package/dist/native/charts/src/engine/color.cjs +1 -1
- package/dist/native/charts/src/engine/color.cjs.map +1 -1
- package/dist/native/charts/src/engine/color.js +12 -3
- package/dist/native/charts/src/engine/color.js.map +1 -1
- package/dist/native/charts/src/engine/controller.cjs +2 -2
- package/dist/native/charts/src/engine/controller.cjs.map +1 -1
- package/dist/native/charts/src/engine/controller.js +334 -270
- package/dist/native/charts/src/engine/controller.js.map +1 -1
- package/dist/native/charts/src/engine/curve.cjs +2 -0
- package/dist/native/charts/src/engine/curve.cjs.map +1 -0
- package/dist/native/charts/src/engine/curve.js +56 -0
- package/dist/native/charts/src/engine/curve.js.map +1 -0
- package/dist/native/charts/src/engine/data.cjs +1 -1
- package/dist/native/charts/src/engine/data.cjs.map +1 -1
- package/dist/native/charts/src/engine/data.js +98 -38
- package/dist/native/charts/src/engine/data.js.map +1 -1
- package/dist/native/charts/src/engine/model.cjs +1 -1
- package/dist/native/charts/src/engine/model.cjs.map +1 -1
- package/dist/native/charts/src/engine/model.js +229 -112
- package/dist/native/charts/src/engine/model.js.map +1 -1
- package/dist/native/charts/src/engine/overlay.cjs +1 -1
- package/dist/native/charts/src/engine/overlay.cjs.map +1 -1
- package/dist/native/charts/src/engine/overlay.js +16 -16
- package/dist/native/charts/src/engine/overlay.js.map +1 -1
- package/dist/native/charts/src/engine/presets.cjs +1 -1
- package/dist/native/charts/src/engine/presets.cjs.map +1 -1
- package/dist/native/charts/src/engine/presets.js +11 -4
- package/dist/native/charts/src/engine/presets.js.map +1 -1
- package/dist/native/charts/src/engine/scene.cjs +1 -1
- package/dist/native/charts/src/engine/scene.cjs.map +1 -1
- package/dist/native/charts/src/engine/scene.js +209 -97
- package/dist/native/charts/src/engine/scene.js.map +1 -1
- package/dist/native/charts/src/engine/theme.cjs.map +1 -1
- package/dist/native/charts/src/engine/theme.js.map +1 -1
- package/dist/native/components/Chart/scene.cjs +1 -1
- package/dist/native/components/Chart/scene.cjs.map +1 -1
- package/dist/native/components/Chart/scene.js +31 -19
- package/dist/native/components/Chart/scene.js.map +1 -1
- package/dist/native/source/components/Chart/scene.tsx +54 -20
- package/dist/taro/index.js +1059 -579
- package/dist/uni/charts-canvas.js +3 -1
- package/dist/weapp/controls.js +966 -225
- package/package.json +1 -1
|
@@ -1,14 +1,101 @@
|
|
|
1
1
|
//#region src/engine/presets.ts
|
|
2
|
-
var e = (e, t, n) => e.map((e) =>
|
|
2
|
+
var e = (e, t, n, r) => e.map((e) => {
|
|
3
|
+
let i = e.type ?? t;
|
|
4
|
+
return {
|
|
5
|
+
...e,
|
|
6
|
+
type: i,
|
|
7
|
+
...n !== void 0 && i === t ? { stack: e.stack ?? n } : {},
|
|
8
|
+
...r !== void 0 && (i === "line" || i === "area") ? { curve: e.curve ?? r } : {}
|
|
9
|
+
};
|
|
10
|
+
}), t = (t, n = !1, r = {}) => e(t, n ? "area" : "line", r.stacked ? "stack" : void 0, r.curve), n = (e, n = {}) => t(e, !0, n), r = (t, n = !1, r = !1) => e(t, "bar", n ? "stack" : void 0).map((e) => r && e.type === "bar" ? {
|
|
3
11
|
...e,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
12
|
+
showLabels: e.showLabels ?? !0
|
|
13
|
+
} : e), i = (t) => e(t, "scatter"), a = (t) => e(t, "candlestick"), o = (e, t = {}) => {
|
|
14
|
+
let n = e.data.some((e) => typeof e.x == "number"), r = e.data.some((e) => typeof e.y == "number");
|
|
15
|
+
return {
|
|
16
|
+
...t,
|
|
17
|
+
series: [{
|
|
18
|
+
id: "heatmap",
|
|
19
|
+
name: e.name ?? "Value",
|
|
20
|
+
type: "heatmap",
|
|
21
|
+
data: e.data.map((e) => ({
|
|
22
|
+
x: e.x,
|
|
23
|
+
y: e.y,
|
|
24
|
+
value: e.value
|
|
25
|
+
})),
|
|
26
|
+
colorScale: e.colorScale,
|
|
27
|
+
valueRange: e.valueRange,
|
|
28
|
+
radius: e.radius,
|
|
29
|
+
format: e.format
|
|
30
|
+
}],
|
|
31
|
+
xAxis: {
|
|
32
|
+
...n ? {} : {
|
|
33
|
+
type: "category",
|
|
34
|
+
categories: e.xCategories
|
|
35
|
+
},
|
|
36
|
+
grid: !1,
|
|
37
|
+
...t.xAxis
|
|
38
|
+
},
|
|
39
|
+
yAxis: {
|
|
40
|
+
...r ? {} : {
|
|
41
|
+
type: "category",
|
|
42
|
+
categories: e.yCategories
|
|
43
|
+
},
|
|
44
|
+
grid: !1,
|
|
45
|
+
...t.yAxis
|
|
46
|
+
},
|
|
47
|
+
legend: t.legend ?? !1,
|
|
48
|
+
interaction: t.interaction ?? { zoom: !1 },
|
|
49
|
+
tooltip: t.tooltip ?? { mode: "nearest" }
|
|
50
|
+
};
|
|
51
|
+
}, s = (e, t = {}) => {
|
|
52
|
+
let n = e.type ?? "line";
|
|
53
|
+
return {
|
|
54
|
+
...t,
|
|
55
|
+
series: [{
|
|
56
|
+
id: "sparkline",
|
|
57
|
+
name: e.name ?? "Value",
|
|
58
|
+
type: n,
|
|
59
|
+
data: e.data,
|
|
60
|
+
color: e.color,
|
|
61
|
+
curve: n === "bar" ? void 0 : e.curve ?? "smooth",
|
|
62
|
+
lineWidth: 1.5,
|
|
63
|
+
opacity: n === "area" ? .22 : void 0,
|
|
64
|
+
radius: n === "bar" ? 1.5 : void 0,
|
|
65
|
+
format: e.format
|
|
66
|
+
}],
|
|
67
|
+
xAxis: {
|
|
68
|
+
visible: !1,
|
|
69
|
+
grid: !1,
|
|
70
|
+
...t.xAxis
|
|
71
|
+
},
|
|
72
|
+
yAxis: {
|
|
73
|
+
visible: !1,
|
|
74
|
+
grid: !1,
|
|
75
|
+
nice: !1,
|
|
76
|
+
...t.yAxis
|
|
77
|
+
},
|
|
78
|
+
legend: !1,
|
|
79
|
+
padding: t.padding ?? {
|
|
80
|
+
top: 4,
|
|
81
|
+
right: 4,
|
|
82
|
+
bottom: 4,
|
|
83
|
+
left: 4
|
|
84
|
+
},
|
|
85
|
+
interaction: t.interaction ?? { zoom: !1 },
|
|
86
|
+
annotations: e.reference === void 0 ? t.annotations : [...t.annotations ?? [], {
|
|
87
|
+
type: "line",
|
|
88
|
+
axis: "y",
|
|
89
|
+
value: e.reference,
|
|
90
|
+
dash: [2, 3]
|
|
91
|
+
}]
|
|
92
|
+
};
|
|
93
|
+
}, c = {
|
|
7
94
|
topLeft: "var(--danger-color, #ef4444)",
|
|
8
95
|
topRight: "var(--primary-color, #4f46e5)",
|
|
9
96
|
bottomLeft: "var(--warning-color, #f59e0b)",
|
|
10
97
|
bottomRight: "var(--text-secondary-color, #64748b)"
|
|
11
|
-
},
|
|
98
|
+
}, l = "var(--border-strong-color, var(--border-color, #cbd5e1))", u = (e) => {
|
|
12
99
|
let [t, n] = e.xDomain ?? [0, 10], [r, i] = e.yDomain ?? [0, 10];
|
|
13
100
|
return {
|
|
14
101
|
x0: t,
|
|
@@ -18,17 +105,17 @@ var e = (e, t, n) => e.map((e) => ({
|
|
|
18
105
|
xs: e.xSplit ?? (t + n) / 2,
|
|
19
106
|
ys: e.ySplit ?? (r + i) / 2
|
|
20
107
|
};
|
|
21
|
-
},
|
|
22
|
-
let { xs: r, ys: i } =
|
|
108
|
+
}, d = (e, t, n) => {
|
|
109
|
+
let { xs: r, ys: i } = u(e), a = e.reverseX ? t < r : t >= r;
|
|
23
110
|
return n >= i ? a ? "topRight" : "topLeft" : a ? "bottomRight" : "bottomLeft";
|
|
24
|
-
},
|
|
25
|
-
let { x0: n, x1: r, y0: i, y1: a, xs:
|
|
111
|
+
}, f = (e, t) => {
|
|
112
|
+
let { x0: n, x1: r, y0: i, y1: a, xs: o, ys: s } = u(e), c = t.endsWith("Right");
|
|
26
113
|
return {
|
|
27
|
-
x: (e.reverseX ? !
|
|
28
|
-
y: t.startsWith("top") ? (
|
|
114
|
+
x: (e.reverseX ? !c : c) ? (o + r) / 2 : (n + o) / 2,
|
|
115
|
+
y: t.startsWith("top") ? (s + a) / 2 : (i + s) / 2
|
|
29
116
|
};
|
|
30
|
-
},
|
|
31
|
-
let { x0: n, x1: r, y0:
|
|
117
|
+
}, p = (e, t = {}) => {
|
|
118
|
+
let { x0: n, x1: r, y0: i, y1: a, xs: o, ys: s } = u(e), f = !!e.reverseX, p = (t) => e.quadrants?.[t]?.color ?? c[t], m = [{
|
|
32
119
|
type: "scatter",
|
|
33
120
|
name: e.name ?? "",
|
|
34
121
|
pointSize: e.pointSize ?? 12,
|
|
@@ -39,9 +126,9 @@ var e = (e, t, n) => e.map((e) => ({
|
|
|
39
126
|
y: t.y,
|
|
40
127
|
label: t.label,
|
|
41
128
|
size: t.size,
|
|
42
|
-
color: t.color ?? p(
|
|
129
|
+
color: t.color ?? p(d(e, t.x, t.y))
|
|
43
130
|
}))
|
|
44
|
-
}], h = f ? [
|
|
131
|
+
}], h = f ? [o, r] : [n, o], g = f ? [n, o] : [o, r], _ = (t, [n, r], [i, a], o) => ({
|
|
45
132
|
type: "rect",
|
|
46
133
|
x0: n,
|
|
47
134
|
x1: r,
|
|
@@ -54,50 +141,50 @@ var e = (e, t, n) => e.map((e) => ({
|
|
|
54
141
|
}), v = e.axisLabels ?? {}, y = f ? r : n, b = f ? n : r, x = [
|
|
55
142
|
...v.top ? [{
|
|
56
143
|
type: "text",
|
|
57
|
-
x:
|
|
58
|
-
y:
|
|
144
|
+
x: o,
|
|
145
|
+
y: a,
|
|
59
146
|
text: v.top,
|
|
60
147
|
anchor: "top"
|
|
61
148
|
}] : [],
|
|
62
149
|
...v.bottom ? [{
|
|
63
150
|
type: "text",
|
|
64
|
-
x:
|
|
65
|
-
y:
|
|
151
|
+
x: o,
|
|
152
|
+
y: i,
|
|
66
153
|
text: v.bottom,
|
|
67
154
|
anchor: "bottom"
|
|
68
155
|
}] : [],
|
|
69
156
|
...v.left ? [{
|
|
70
157
|
type: "text",
|
|
71
158
|
x: y,
|
|
72
|
-
y:
|
|
159
|
+
y: s,
|
|
73
160
|
text: v.left,
|
|
74
161
|
anchor: "left"
|
|
75
162
|
}] : [],
|
|
76
163
|
...v.right ? [{
|
|
77
164
|
type: "text",
|
|
78
165
|
x: b,
|
|
79
|
-
y:
|
|
166
|
+
y: s,
|
|
80
167
|
text: v.right,
|
|
81
168
|
anchor: "right"
|
|
82
169
|
}] : []
|
|
83
170
|
], S = [
|
|
84
|
-
_("topLeft", h, [
|
|
85
|
-
_("topRight", g, [
|
|
86
|
-
_("bottomLeft", h, [
|
|
87
|
-
_("bottomRight", g, [
|
|
171
|
+
_("topLeft", h, [s, a], "top-left"),
|
|
172
|
+
_("topRight", g, [s, a], "top-right"),
|
|
173
|
+
_("bottomLeft", h, [i, s], "bottom-left"),
|
|
174
|
+
_("bottomRight", g, [i, s], "bottom-right"),
|
|
88
175
|
{
|
|
89
176
|
type: "line",
|
|
90
177
|
axis: "x",
|
|
91
|
-
value:
|
|
178
|
+
value: o,
|
|
92
179
|
dash: [],
|
|
93
|
-
color:
|
|
180
|
+
color: l
|
|
94
181
|
},
|
|
95
182
|
{
|
|
96
183
|
type: "line",
|
|
97
184
|
axis: "y",
|
|
98
|
-
value:
|
|
185
|
+
value: s,
|
|
99
186
|
dash: [],
|
|
100
|
-
color:
|
|
187
|
+
color: l
|
|
101
188
|
},
|
|
102
189
|
...x,
|
|
103
190
|
...t.annotations ?? []
|
|
@@ -113,7 +200,7 @@ var e = (e, t, n) => e.map((e) => ({
|
|
|
113
200
|
tooltip: t.tooltip ?? (C ? void 0 : { render: (t) => {
|
|
114
201
|
let n = t.items[0];
|
|
115
202
|
if (!n) return null;
|
|
116
|
-
let r = e.quadrants?.[
|
|
203
|
+
let r = e.quadrants?.[d(e, n.x, n.y)]?.label;
|
|
117
204
|
return [n.label ?? e.name ?? "", r ?? ""].filter(Boolean).join("\n");
|
|
118
205
|
} }),
|
|
119
206
|
xAxis: {
|
|
@@ -128,8 +215,8 @@ var e = (e, t, n) => e.map((e) => ({
|
|
|
128
215
|
...C ? {} : { format: () => "" }
|
|
129
216
|
},
|
|
130
217
|
yAxis: {
|
|
131
|
-
min:
|
|
132
|
-
max:
|
|
218
|
+
min: i,
|
|
219
|
+
max: a,
|
|
133
220
|
title: e.yLabel,
|
|
134
221
|
nice: !1,
|
|
135
222
|
grid: !1,
|
|
@@ -148,6 +235,6 @@ var e = (e, t, n) => e.map((e) => ({
|
|
|
148
235
|
};
|
|
149
236
|
};
|
|
150
237
|
//#endregion
|
|
151
|
-
export {
|
|
238
|
+
export { c as DEFAULT_QUADRANT_COLORS, n as areaSeries, r as barSeries, a as candlestickSeries, o as heatmapChartOptions, t as lineSeries, f as quadrantCenter, p as quadrantChartOptions, d as quadrantOf, i as scatterSeries, s as sparklineOptions, e as withSeriesType };
|
|
152
239
|
|
|
153
240
|
//# sourceMappingURL=presets.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presets.js","names":["withSeriesType","series","s","type","stack","lineSeries","area","barSeries","stacked","scatterSeries","DEFAULT_QUADRANT_COLORS","DIVIDER","splits","x0","x1","config","y0","y1","quadrantOf","right","x","xs","y","ys","quadrantCenter","visualRight","corner","quadrantChartOptions","reverseX","color","p","left","rect","xa","xb","ya","yb","position","ends","visualLeft","texts","annotations","base","showTicks","interaction","item","event","region"],"sources":["../../../../charts/src/engine/presets.ts"],"sourcesContent":["// Option presets of the chart components, shared by every platform (React,\n// mini-programs, React Native): they turn component props into engine\n// options.\n\nimport type {\n ChartAnnotation,\n ChartInteractionOptions,\n ChartOptions,\n ChartSeries,\n ChartSeriesType,\n} from \"./types\";\n\n/** Gives the series without a `type` the type of the component */\nexport const withSeriesType = (\n series: readonly ChartSeries[],\n type: ChartSeriesType,\n stack?: string,\n): ChartSeries[] =>\n series.map((s) => ({\n ...s,\n type: s.type ?? type,\n ...(stack !== undefined && (s.type ?? type) === \"bar\"\n ? { stack: s.stack ?? stack }\n : {}),\n }));\n\n/** Series of a LineChart (`area` fills them) */\nexport const lineSeries = (series: readonly ChartSeries[], area = false) =>\n withSeriesType(series, area ? \"area\" : \"line\");\n\n/** Series of a BarChart (`stacked` stacks them) */\nexport const barSeries = (series: readonly ChartSeries[], stacked = false) =>\n withSeriesType(series, \"bar\", stacked ? \"stack\" : undefined);\n\n/** Series of a ScatterChart */\nexport const scatterSeries = (series: readonly ChartSeries[]) =>\n withSeriesType(series, \"scatter\");\n\n/** A point of a QuadrantChart */\nexport interface QuadrantPoint {\n /** Position on the horizontal axis */\n x: number;\n /** Position on the vertical axis */\n y: number;\n /** Text drawn next to the dot and shown in the tooltip */\n label?: string;\n /** Dot color (any CSS color); the color of its quadrant by default */\n color?: string;\n /** Dot diameter in pixels */\n size?: number;\n}\n\n/** Title and color of a quadrant */\nexport interface QuadrantRegion {\n /** Title drawn in the outer corner of the quadrant */\n label?: string;\n /** Background tint and default dot color (any CSS color) */\n color?: string;\n}\n\n/** The four quadrants of a QuadrantChart */\nexport interface QuadrantRegions {\n topLeft?: QuadrantRegion;\n topRight?: QuadrantRegion;\n bottomLeft?: QuadrantRegion;\n bottomRight?: QuadrantRegion;\n}\n\n/** A quadrant, as seen on screen */\nexport type QuadrantCorner = keyof QuadrantRegions;\n\n/** Texts at the four ends of the dividers, inside the plot */\nexport interface QuadrantAxisLabels {\n top?: string;\n bottom?: string;\n left?: string;\n right?: string;\n}\n\n/** Settings of a quadrant matrix (the props of QuadrantChart) */\nexport interface QuadrantConfig {\n /** Points to place */\n points: readonly QuadrantPoint[];\n /**\n * Range of the horizontal axis\n * @default [0, 10]\n */\n xDomain?: [number, number];\n /**\n * Range of the vertical axis\n * @default [0, 10]\n */\n yDomain?: [number, number];\n /** X value of the vertical divider (the middle of `xDomain` by default) */\n xSplit?: number;\n /** Y value of the horizontal divider (the middle of `yDomain` by default) */\n ySplit?: number;\n /** Titles and colors of the quadrants */\n quadrants?: QuadrantRegions;\n /** Title of the horizontal axis */\n xLabel?: string;\n /** Title of the vertical axis */\n yLabel?: string;\n /** Texts at the ends of the dividers, drawn inside the plot (e.g. \"Important\" at the top) */\n axisLabels?: QuadrantAxisLabels;\n /**\n * Shows the numeric ticks of the axes; `false` keeps only the matrix\n * @default true\n */\n showTicks?: boolean;\n /** Reverses the horizontal axis (e.g. \"urgent\" on the left) */\n reverseX?: boolean;\n /**\n * Draws the labels next to the dots (overlapping labels are skipped)\n * @default true\n */\n showLabels?: boolean;\n /**\n * Dot diameter in pixels\n * @default 12\n */\n pointSize?: number;\n /** Name of the points in the tooltip */\n name?: string;\n /** Lets the user drag the dots (`drag` / `drop` events) */\n draggable?: boolean;\n}\n\nexport const DEFAULT_QUADRANT_COLORS: Required<Record<QuadrantCorner, string>> =\n {\n topLeft: \"var(--danger-color, #ef4444)\",\n topRight: \"var(--primary-color, #4f46e5)\",\n bottomLeft: \"var(--warning-color, #f59e0b)\",\n bottomRight: \"var(--text-secondary-color, #64748b)\",\n };\n\nconst DIVIDER = \"var(--border-strong-color, var(--border-color, #cbd5e1))\";\n\nconst splits = (config: QuadrantConfig) => {\n const [x0, x1] = config.xDomain ?? [0, 10];\n const [y0, y1] = config.yDomain ?? [0, 10];\n return {\n x0,\n x1,\n y0,\n y1,\n xs: config.xSplit ?? (x0 + x1) / 2,\n ys: config.ySplit ?? (y0 + y1) / 2,\n };\n};\n\n/** Quadrant of a data position, as seen on screen */\nexport const quadrantOf = (\n config: Pick<\n QuadrantConfig,\n \"xDomain\" | \"yDomain\" | \"xSplit\" | \"ySplit\" | \"reverseX\"\n >,\n x: number,\n y: number,\n): QuadrantCorner => {\n const { xs, ys } = splits(config as QuadrantConfig);\n const right = config.reverseX ? x < xs : x >= xs;\n const top = y >= ys;\n return top\n ? right\n ? \"topRight\"\n : \"topLeft\"\n : right\n ? \"bottomRight\"\n : \"bottomLeft\";\n};\n\n/** Center of a quadrant in data coordinates */\nexport const quadrantCenter = (\n config: Pick<\n QuadrantConfig,\n \"xDomain\" | \"yDomain\" | \"xSplit\" | \"ySplit\" | \"reverseX\"\n >,\n corner: QuadrantCorner,\n): { x: number; y: number } => {\n const { x0, x1, y0, y1, xs, ys } = splits(config as QuadrantConfig);\n const visualRight = corner.endsWith(\"Right\");\n const dataHigh = config.reverseX ? !visualRight : visualRight;\n return {\n x: dataHigh ? (xs + x1) / 2 : (x0 + xs) / 2,\n y: corner.startsWith(\"top\") ? (ys + y1) / 2 : (y0 + ys) / 2,\n };\n};\n\n/** Engine options of a quadrant matrix */\nexport const quadrantChartOptions = (\n config: QuadrantConfig,\n base: Omit<ChartOptions, \"series\"> = {},\n): ChartOptions => {\n const { x0, x1, y0, y1, xs, ys } = splits(config);\n const reverseX = !!config.reverseX;\n const color = (corner: QuadrantCorner) =>\n config.quadrants?.[corner]?.color ?? DEFAULT_QUADRANT_COLORS[corner];\n\n const series: ChartSeries[] = [\n {\n type: \"scatter\",\n name: config.name ?? \"\",\n pointSize: config.pointSize ?? 12,\n showLabels: config.showLabels ?? true,\n opacity: 0.9,\n data: config.points.map((p) => ({\n x: p.x,\n y: p.y,\n label: p.label,\n size: p.size,\n color: p.color ?? color(quadrantOf(config, p.x, p.y)),\n })),\n },\n ];\n\n // visual left / right -> data ranges\n const left: [number, number] = reverseX ? [xs, x1] : [x0, xs];\n const right: [number, number] = reverseX ? [x0, xs] : [xs, x1];\n const rect = (\n corner: QuadrantCorner,\n [xa, xb]: [number, number],\n [ya, yb]: [number, number],\n position: \"top-left\" | \"top-right\" | \"bottom-left\" | \"bottom-right\",\n ): ChartAnnotation => ({\n type: \"rect\",\n x0: xa,\n x1: xb,\n y0: ya,\n y1: yb,\n color: color(corner),\n opacity: 0.07,\n label: config.quadrants?.[corner]?.label,\n labelPosition: position,\n });\n const ends = config.axisLabels ?? {};\n const visualLeft = reverseX ? x1 : x0;\n const visualRight = reverseX ? x0 : x1;\n const texts: ChartAnnotation[] = [\n ...(ends.top\n ? [{ type: \"text\", x: xs, y: y1, text: ends.top, anchor: \"top\" } as const]\n : []),\n ...(ends.bottom\n ? [\n {\n type: \"text\",\n x: xs,\n y: y0,\n text: ends.bottom,\n anchor: \"bottom\",\n } as const,\n ]\n : []),\n ...(ends.left\n ? [\n {\n type: \"text\",\n x: visualLeft,\n y: ys,\n text: ends.left,\n anchor: \"left\",\n } as const,\n ]\n : []),\n ...(ends.right\n ? [\n {\n type: \"text\",\n x: visualRight,\n y: ys,\n text: ends.right,\n anchor: \"right\",\n } as const,\n ]\n : []),\n ];\n\n const annotations: ChartAnnotation[] = [\n rect(\"topLeft\", left, [ys, y1], \"top-left\"),\n rect(\"topRight\", right, [ys, y1], \"top-right\"),\n rect(\"bottomLeft\", left, [y0, ys], \"bottom-left\"),\n rect(\"bottomRight\", right, [y0, ys], \"bottom-right\"),\n { type: \"line\", axis: \"x\", value: xs, dash: [], color: DIVIDER },\n { type: \"line\", axis: \"y\", value: ys, dash: [], color: DIVIDER },\n ...texts,\n ...(base.annotations ?? []),\n ];\n\n const showTicks = config.showTicks ?? true;\n const interaction: boolean | ChartInteractionOptions =\n base.interaction === false\n ? false\n : {\n zoom: false,\n ...(typeof base.interaction === \"object\" ? base.interaction : {}),\n ...(config.draggable ? { dragPoints: true } : {}),\n };\n\n return {\n ...base,\n series,\n annotations,\n tooltip:\n base.tooltip ??\n (showTicks\n ? undefined\n : {\n render: (event) => {\n const item = event.items[0];\n if (!item) return null;\n const region =\n config.quadrants?.[quadrantOf(config, item.x, item.y)]?.label;\n return [item.label ?? config.name ?? \"\", region ?? \"\"]\n .filter(Boolean)\n .join(\"\\n\");\n },\n }),\n xAxis: {\n min: x0,\n max: x1,\n title: config.xLabel,\n reverse: reverseX,\n nice: false,\n grid: false,\n tickCount: 4,\n visible: showTicks || !!config.xLabel,\n ...(showTicks ? {} : { format: () => \"\" }),\n },\n yAxis: {\n min: y0,\n max: y1,\n title: config.yLabel,\n nice: false,\n grid: false,\n tickCount: 4,\n visible: showTicks || !!config.yLabel,\n ...(showTicks ? {} : { format: () => \"\" }),\n },\n legend: base.legend ?? false,\n padding:\n base.padding ??\n (showTicks ? undefined : { top: 4, right: 4, bottom: 4, left: 4 }),\n interaction,\n };\n};\n"],"mappings":";AAaA,IAAaA,KACX,GACA,GACA,MAEAC,EAAO,KAAK,OAAO;CACjB,GAAGC;CACH,MAAMA,EAAE,QAAQC;CAChB,GAAIC,MAAU,KAAA,MAAcF,EAAE,QAAQC,OAAU,QAC5C,EAAE,OAAOD,EAAE,SAASE,EAAM,IAC1B,CAAC;AACP,EAAE,GAGSC,KAAc,GAAgC,IAAO,OAChEL,EAAeC,GAAQK,IAAO,SAAS,MAAM,GAGlCC,KAAa,GAAgC,IAAU,OAClEP,EAAeC,GAAQ,OAAOO,IAAU,UAAU,KAAA,CAAS,GAGhDC,KAAiB,MAC5BT,EAAeC,GAAQ,SAAS,GA4FrBS,IACX;CACE,SAAS;CACT,UAAU;CACV,YAAY;CACZ,aAAa;AACf,GAEIC,IAAU,4DAEVC,KAAU,MAA2B;CACzC,IAAM,CAACC,GAAIC,KAAMC,EAAO,WAAW,CAAC,GAAG,EAAE,GACnC,CAACC,GAAIC,KAAMF,EAAO,WAAW,CAAC,GAAG,EAAE;CACzC,OAAO;EACL;EACA;EACA;EACA;EACA,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AAOZ;EAAQ;EAC/D,GAAG6B;EACH,GAAIE,EAAK,eAAe,CAAC;CAC3B,GAEMC,IAAY5B,EAAO,aAAa,IAChC6B,IACJF,EAAK,gBAAgB,MAEjB;EACE,MAAM;EACN,GAAI,OAAOA,EAAK,eAAgB,WAAWA,EAAK,cAAc,CAAC;EAC/D,GAAI3B,EAAO,YAAY,EAAE,YAAY,GAAK,IAAI,CAAC;CACjD;CAEN,OAAO;EACL,GAAG2B;EACH;EACA;EACA,SACEA,EAAK,YACJC,IACG,KAAA,IACA,EACE,SAAS,MAAU;GACjB,IAAME,IAAOC,EAAM,MAAM;GACzB,IAAI,CAACD,GAAM,OAAO;GAClB,IAAME,IACJhC,EAAO,YAAYG,EAAWH,GAAQ8B,EAAK,GAAGA,EAAK,CAAC,EAAE,EAAE;GAC1D,OAAO,CAACA,EAAK,SAAS9B,EAAO,QAAQ,IAAIgC,KAAU,EAAE,CAAC,CACnD,OAAO,OAAO,CAAC,CACf,KAAK,IAAI;EACd,EACF;EACN,OAAO;GACL,KAAKlC;GACL,KAAKC;GACL,OAAOC,EAAO;GACd,SAASa;GACT,MAAM;GACN,MAAM;GACN,WAAW;GACX,SAASe,KAAa,CAAC,CAAC5B,EAAO;GAC/B,GAAI4B,IAAY,CAAC,IAAI,EAAE,cAAc,GAAG;EAC1C;EACA,OAAO;GACL,KAAK3B;GACL,KAAKC;GACL,OAAOF,EAAO;GACd,MAAM;GACN,MAAM;GACN,WAAW;GACX,SAAS4B,KAAa,CAAC,CAAC5B,EAAO;GAC/B,GAAI4B,IAAY,CAAC,IAAI,EAAE,cAAc,GAAG;EAC1C;EACA,QAAQD,EAAK,UAAU;EACvB,SACEA,EAAK,YACJC,IAAY,KAAA,IAAY;GAAE,KAAK;GAAG,OAAO;GAAG,QAAQ;GAAG,MAAM;EAAE;EAClE;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"presets.js","names":["withSeriesType","series","t","s","type","stack","curve","lineSeries","area","extra","areaSeries","barSeries","stacked","labels","scatterSeries","candlestickSeries","heatmapChartOptions","numericX","config","c","numericY","base","sparklineOptions","DEFAULT_QUADRANT_COLORS","DIVIDER","splits","x0","x1","y0","y1","quadrantOf","right","x","xs","y","ys","quadrantCenter","visualRight","corner","quadrantChartOptions","reverseX","color","p","left","rect","xa","xb","ya","yb","position","ends","visualLeft","texts","annotations","showTicks","interaction","item","event","region"],"sources":["../../../../charts/src/engine/presets.ts"],"sourcesContent":["// Option presets of the chart components, shared by every platform (React,\n// mini-programs, React Native): they turn component props into engine\n// options.\n\nimport type {\n ChartAnnotation,\n ChartCurve,\n ChartInteractionOptions,\n ChartOptions,\n ChartSeries,\n ChartSeriesType,\n} from \"./types\";\n\n/** Gives the series without a `type` the type of the component */\nexport const withSeriesType = (\n series: readonly ChartSeries[],\n type: ChartSeriesType,\n stack?: string,\n curve?: ChartCurve,\n): ChartSeries[] =>\n series.map((s) => {\n const t = s.type ?? type;\n return {\n ...s,\n type: t,\n ...(stack !== undefined && t === type ? { stack: s.stack ?? stack } : {}),\n ...(curve !== undefined && (t === \"line\" || t === \"area\")\n ? { curve: s.curve ?? curve }\n : {}),\n };\n });\n\n/** Options of the line-like components */\nexport interface LineSeriesOptions {\n /** Stacks the series on top of each other */\n stacked?: boolean;\n /** Shape of the lines */\n curve?: ChartCurve;\n}\n\n/** Series of a LineChart (`area` fills them) */\nexport const lineSeries = (\n series: readonly ChartSeries[],\n area = false,\n extra: LineSeriesOptions = {},\n) =>\n withSeriesType(\n series,\n area ? \"area\" : \"line\",\n extra.stacked ? \"stack\" : undefined,\n extra.curve,\n );\n\n/** Series of an AreaChart */\nexport const areaSeries = (\n series: readonly ChartSeries[],\n extra: LineSeriesOptions = {},\n) => lineSeries(series, true, extra);\n\n/** Series of a BarChart (`stacked` stacks them, `labels` shows the values) */\nexport const barSeries = (\n series: readonly ChartSeries[],\n stacked = false,\n labels = false,\n) =>\n withSeriesType(series, \"bar\", stacked ? \"stack\" : undefined).map((s) =>\n labels && s.type === \"bar\" ? { ...s, showLabels: s.showLabels ?? true } : s,\n );\n\n/** Series of a ScatterChart */\nexport const scatterSeries = (series: readonly ChartSeries[]) =>\n withSeriesType(series, \"scatter\");\n\n/** Series of a CandlestickChart */\nexport const candlestickSeries = (series: readonly ChartSeries[]) =>\n withSeriesType(series, \"candlestick\");\n\n/** A cell of a HeatmapChart */\nexport interface HeatmapCell {\n /** Column: a category name (or a number on a numeric axis) */\n x: string | number;\n /** Row: a category name (or a number on a numeric axis) */\n y: string | number;\n /** Value mapped to the color scale; `null` leaves the cell empty */\n value: number | null;\n}\n\n/** Settings of a heatmap (the props of HeatmapChart) */\nexport interface HeatmapConfig {\n /** Cells */\n data: readonly HeatmapCell[];\n /** Column names in order (collected from the data when omitted) */\n xCategories?: readonly string[];\n /** Row names from bottom to top (collected from the data when omitted) */\n yCategories?: readonly string[];\n /** Colors from the lowest to the highest value; a ramp of the first palette color by default */\n colorScale?: readonly string[];\n /** Values at the ends of the color scale; the data range by default */\n valueRange?: readonly [number, number];\n /** Name of the value in the tooltip */\n name?: string;\n /** Corner radius of the cells, in pixels */\n radius?: number;\n /** Formats the values in the tooltip */\n format?: (value: number) => string;\n}\n\n/** Engine options of a heatmap */\nexport const heatmapChartOptions = (\n config: HeatmapConfig,\n base: Partial<ChartOptions> = {},\n): ChartOptions => {\n const numericX = config.data.some((c) => typeof c.x === \"number\");\n const numericY = config.data.some((c) => typeof c.y === \"number\");\n return {\n ...base,\n series: [\n {\n id: \"heatmap\",\n name: config.name ?? \"Value\",\n type: \"heatmap\",\n data: config.data.map((c) => ({ x: c.x, y: c.y, value: c.value })),\n colorScale: config.colorScale,\n valueRange: config.valueRange,\n radius: config.radius,\n format: config.format,\n },\n ],\n xAxis: {\n ...(numericX\n ? {}\n : { type: \"category\" as const, categories: config.xCategories }),\n grid: false,\n ...base.xAxis,\n },\n yAxis: {\n ...(numericY\n ? {}\n : { type: \"category\" as const, categories: config.yCategories }),\n grid: false,\n ...base.yAxis,\n },\n legend: base.legend ?? false,\n interaction: base.interaction ?? { zoom: false },\n tooltip: base.tooltip ?? { mode: \"nearest\" },\n };\n};\n\n/** Settings of a sparkline (the props of Sparkline) */\nexport interface SparklineConfig {\n /** Values (or `[x, y]` pairs, typed arrays, ...) */\n data: ChartSeries[\"data\"];\n /**\n * How the values are drawn\n * @default \"line\"\n */\n type?: \"line\" | \"area\" | \"bar\";\n /** Color (any CSS color); the first palette color by default */\n color?: string;\n /**\n * Shape of the line\n * @default \"smooth\"\n */\n curve?: ChartCurve;\n /** Name shown in the tooltip */\n name?: string;\n /** Draws a reference line at this value (e.g. a target or the average) */\n reference?: number;\n /** Formats the value in the tooltip */\n format?: (value: number) => string;\n}\n\n/** Engine options of a sparkline: no axes, no legend, a tooltip only */\nexport const sparklineOptions = (\n config: SparklineConfig,\n base: Partial<ChartOptions> = {},\n): ChartOptions => {\n const type = config.type ?? \"line\";\n return {\n ...base,\n series: [\n {\n id: \"sparkline\",\n name: config.name ?? \"Value\",\n type,\n data: config.data,\n color: config.color,\n curve: type === \"bar\" ? undefined : (config.curve ?? \"smooth\"),\n lineWidth: 1.5,\n opacity: type === \"area\" ? 0.22 : undefined,\n radius: type === \"bar\" ? 1.5 : undefined,\n format: config.format,\n },\n ],\n xAxis: { visible: false, grid: false, ...base.xAxis },\n yAxis: { visible: false, grid: false, nice: false, ...base.yAxis },\n legend: false,\n padding: base.padding ?? { top: 4, right: 4, bottom: 4, left: 4 },\n interaction: base.interaction ?? { zoom: false },\n annotations:\n config.reference !== undefined\n ? [\n ...(base.annotations ?? []),\n {\n type: \"line\",\n axis: \"y\",\n value: config.reference,\n dash: [2, 3],\n },\n ]\n : base.annotations,\n };\n};\n\n/** A point of a QuadrantChart */\nexport interface QuadrantPoint {\n /** Position on the horizontal axis */\n x: number;\n /** Position on the vertical axis */\n y: number;\n /** Text drawn next to the dot and shown in the tooltip */\n label?: string;\n /** Dot color (any CSS color); the color of its quadrant by default */\n color?: string;\n /** Dot diameter in pixels */\n size?: number;\n}\n\n/** Title and color of a quadrant */\nexport interface QuadrantRegion {\n /** Title drawn in the outer corner of the quadrant */\n label?: string;\n /** Background tint and default dot color (any CSS color) */\n color?: string;\n}\n\n/** The four quadrants of a QuadrantChart */\nexport interface QuadrantRegions {\n topLeft?: QuadrantRegion;\n topRight?: QuadrantRegion;\n bottomLeft?: QuadrantRegion;\n bottomRight?: QuadrantRegion;\n}\n\n/** A quadrant, as seen on screen */\nexport type QuadrantCorner = keyof QuadrantRegions;\n\n/** Texts at the four ends of the dividers, inside the plot */\nexport interface QuadrantAxisLabels {\n top?: string;\n bottom?: string;\n left?: string;\n right?: string;\n}\n\n/** Settings of a quadrant matrix (the props of QuadrantChart) */\nexport interface QuadrantConfig {\n /** Points to place */\n points: readonly QuadrantPoint[];\n /**\n * Range of the horizontal axis\n * @default [0, 10]\n */\n xDomain?: [number, number];\n /**\n * Range of the vertical axis\n * @default [0, 10]\n */\n yDomain?: [number, number];\n /** X value of the vertical divider (the middle of `xDomain` by default) */\n xSplit?: number;\n /** Y value of the horizontal divider (the middle of `yDomain` by default) */\n ySplit?: number;\n /** Titles and colors of the quadrants */\n quadrants?: QuadrantRegions;\n /** Title of the horizontal axis */\n xLabel?: string;\n /** Title of the vertical axis */\n yLabel?: string;\n /** Texts at the ends of the dividers, drawn inside the plot (e.g. \"Important\" at the top) */\n axisLabels?: QuadrantAxisLabels;\n /**\n * Shows the numeric ticks of the axes; `false` keeps only the matrix\n * @default true\n */\n showTicks?: boolean;\n /** Reverses the horizontal axis (e.g. \"urgent\" on the left) */\n reverseX?: boolean;\n /**\n * Draws the labels next to the dots (overlapping labels are skipped)\n * @default true\n */\n showLabels?: boolean;\n /**\n * Dot diameter in pixels\n * @default 12\n */\n pointSize?: number;\n /** Name of the points in the tooltip */\n name?: string;\n /** Lets the user drag the dots (`drag` / `drop` events) */\n draggable?: boolean;\n}\n\nexport const DEFAULT_QUADRANT_COLORS: Required<Record<QuadrantCorner, string>> =\n {\n topLeft: \"var(--danger-color, #ef4444)\",\n topRight: \"var(--primary-color, #4f46e5)\",\n bottomLeft: \"var(--warning-color, #f59e0b)\",\n bottomRight: \"var(--text-secondary-color, #64748b)\",\n };\n\nconst DIVIDER = \"var(--border-strong-color, var(--border-color, #cbd5e1))\";\n\nconst splits = (config: QuadrantConfig) => {\n const [x0, x1] = config.xDomain ?? [0, 10];\n const [y0, y1] = config.yDomain ?? [0, 10];\n return {\n x0,\n x1,\n y0,\n y1,\n xs: config.xSplit ?? (x0 + x1) / 2,\n ys: config.ySplit ?? (y0 + y1) / 2,\n };\n};\n\n/** Quadrant of a data position, as seen on screen */\nexport const quadrantOf = (\n config: Pick<\n QuadrantConfig,\n \"xDomain\" | \"yDomain\" | \"xSplit\" | \"ySplit\" | \"reverseX\"\n >,\n x: number,\n y: number,\n): QuadrantCorner => {\n const { xs, ys } = splits(config as QuadrantConfig);\n const right = config.reverseX ? x < xs : x >= xs;\n const top = y >= ys;\n return top\n ? right\n ? \"topRight\"\n : \"topLeft\"\n : right\n ? \"bottomRight\"\n : \"bottomLeft\";\n};\n\n/** Center of a quadrant in data coordinates */\nexport const quadrantCenter = (\n config: Pick<\n QuadrantConfig,\n \"xDomain\" | \"yDomain\" | \"xSplit\" | \"ySplit\" | \"reverseX\"\n >,\n corner: QuadrantCorner,\n): { x: number; y: number } => {\n const { x0, x1, y0, y1, xs, ys } = splits(config as QuadrantConfig);\n const visualRight = corner.endsWith(\"Right\");\n const dataHigh = config.reverseX ? !visualRight : visualRight;\n return {\n x: dataHigh ? (xs + x1) / 2 : (x0 + xs) / 2,\n y: corner.startsWith(\"top\") ? (ys + y1) / 2 : (y0 + ys) / 2,\n };\n};\n\n/** Engine options of a quadrant matrix */\nexport const quadrantChartOptions = (\n config: QuadrantConfig,\n base: Omit<ChartOptions, \"series\"> = {},\n): ChartOptions => {\n const { x0, x1, y0, y1, xs, ys } = splits(config);\n const reverseX = !!config.reverseX;\n const color = (corner: QuadrantCorner) =>\n config.quadrants?.[corner]?.color ?? DEFAULT_QUADRANT_COLORS[corner];\n\n const series: ChartSeries[] = [\n {\n type: \"scatter\",\n name: config.name ?? \"\",\n pointSize: config.pointSize ?? 12,\n showLabels: config.showLabels ?? true,\n opacity: 0.9,\n data: config.points.map((p) => ({\n x: p.x,\n y: p.y,\n label: p.label,\n size: p.size,\n color: p.color ?? color(quadrantOf(config, p.x, p.y)),\n })),\n },\n ];\n\n // visual left / right -> data ranges\n const left: [number, number] = reverseX ? [xs, x1] : [x0, xs];\n const right: [number, number] = reverseX ? [x0, xs] : [xs, x1];\n const rect = (\n corner: QuadrantCorner,\n [xa, xb]: [number, number],\n [ya, yb]: [number, number],\n position: \"top-left\" | \"top-right\" | \"bottom-left\" | \"bottom-right\",\n ): ChartAnnotation => ({\n type: \"rect\",\n x0: xa,\n x1: xb,\n y0: ya,\n y1: yb,\n color: color(corner),\n opacity: 0.07,\n label: config.quadrants?.[corner]?.label,\n labelPosition: position,\n });\n const ends = config.axisLabels ?? {};\n const visualLeft = reverseX ? x1 : x0;\n const visualRight = reverseX ? x0 : x1;\n const texts: ChartAnnotation[] = [\n ...(ends.top\n ? [{ type: \"text\", x: xs, y: y1, text: ends.top, anchor: \"top\" } as const]\n : []),\n ...(ends.bottom\n ? [\n {\n type: \"text\",\n x: xs,\n y: y0,\n text: ends.bottom,\n anchor: \"bottom\",\n } as const,\n ]\n : []),\n ...(ends.left\n ? [\n {\n type: \"text\",\n x: visualLeft,\n y: ys,\n text: ends.left,\n anchor: \"left\",\n } as const,\n ]\n : []),\n ...(ends.right\n ? [\n {\n type: \"text\",\n x: visualRight,\n y: ys,\n text: ends.right,\n anchor: \"right\",\n } as const,\n ]\n : []),\n ];\n\n const annotations: ChartAnnotation[] = [\n rect(\"topLeft\", left, [ys, y1], \"top-left\"),\n rect(\"topRight\", right, [ys, y1], \"top-right\"),\n rect(\"bottomLeft\", left, [y0, ys], \"bottom-left\"),\n rect(\"bottomRight\", right, [y0, ys], \"bottom-right\"),\n { type: \"line\", axis: \"x\", value: xs, dash: [], color: DIVIDER },\n { type: \"line\", axis: \"y\", value: ys, dash: [], color: DIVIDER },\n ...texts,\n ...(base.annotations ?? []),\n ];\n\n const showTicks = config.showTicks ?? true;\n const interaction: boolean | ChartInteractionOptions =\n base.interaction === false\n ? false\n : {\n zoom: false,\n ...(typeof base.interaction === \"object\" ? base.interaction : {}),\n ...(config.draggable ? { dragPoints: true } : {}),\n };\n\n return {\n ...base,\n series,\n annotations,\n tooltip:\n base.tooltip ??\n (showTicks\n ? undefined\n : {\n render: (event) => {\n const item = event.items[0];\n if (!item) return null;\n const region =\n config.quadrants?.[quadrantOf(config, item.x, item.y)]?.label;\n return [item.label ?? config.name ?? \"\", region ?? \"\"]\n .filter(Boolean)\n .join(\"\\n\");\n },\n }),\n xAxis: {\n min: x0,\n max: x1,\n title: config.xLabel,\n reverse: reverseX,\n nice: false,\n grid: false,\n tickCount: 4,\n visible: showTicks || !!config.xLabel,\n ...(showTicks ? {} : { format: () => \"\" }),\n },\n yAxis: {\n min: y0,\n max: y1,\n title: config.yLabel,\n nice: false,\n grid: false,\n tickCount: 4,\n visible: showTicks || !!config.yLabel,\n ...(showTicks ? {} : { format: () => \"\" }),\n },\n legend: base.legend ?? false,\n padding:\n base.padding ??\n (showTicks ? undefined : { top: 4, right: 4, bottom: 4, left: 4 }),\n interaction,\n };\n};\n"],"mappings":";AAcA,IAAaA,KACX,GACA,GACA,GACA,MAEAC,EAAO,KAAK,MAAM;CAChB,IAAMC,IAAIC,EAAE,QAAQC;CACpB,OAAO;EACL,GAAGD;EACH,MAAMD;EACN,GAAIG,MAAU,KAAA,KAAaH,MAAME,IAAO,EAAE,OAAOD,EAAE,SAASE,EAAM,IAAI,CAAC;EACvE,GAAIC,MAAU,KAAA,MAAcJ,MAAM,UAAUA,MAAM,UAC9C,EAAE,OAAOC,EAAE,SAASG,EAAM,IAC1B,CAAC;CACP;AACF,CAAC,GAWUC,KACX,GACA,IAAO,IACP,IAA2B,CAAC,MAE5BP,EACEC,GACAO,IAAO,S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c,CAAC;EAC/D,GAAIH,EAAO,YAAY,EAAE,YAAY,GAAK,IAAI,CAAC;CACjD;CAEN,OAAO;EACL,GAAGG;EACH;EACA;EACA,SACEA,EAAK,YACJiC,IACG,KAAA,IACA,EACE,SAAS,MAAU;GACjB,IAAME,IAAOC,EAAM,MAAM;GACzB,IAAI,CAACD,GAAM,OAAO;GAClB,IAAME,IACJxC,EAAO,YAAYY,EAAWZ,GAAQsC,EAAK,GAAGA,EAAK,CAAC,EAAE,EAAE;GAC1D,OAAO,CAACA,EAAK,SAAStC,EAAO,QAAQ,IAAIwC,KAAU,EAAE,CAAC,CACnD,OAAO,OAAO,CAAC,CACf,KAAK,IAAI;EACd,EACF;EACN,OAAO;GACL,KAAKhC;GACL,KAAKC;GACL,OAAOT,EAAO;GACd,SAASsB;GACT,MAAM;GACN,MAAM;GACN,WAAW;GACX,SAASc,KAAa,CAAC,CAACpC,EAAO;GAC/B,GAAIoC,IAAY,CAAC,IAAI,EAAE,cAAc,GAAG;EAC1C;EACA,OAAO;GACL,KAAK1B;GACL,KAAKC;GACL,OAAOX,EAAO;GACd,MAAM;GACN,MAAM;GACN,WAAW;GACX,SAASoC,KAAa,CAAC,CAACpC,EAAO;GAC/B,GAAIoC,IAAY,CAAC,IAAI,EAAE,cAAc,GAAG;EAC1C;EACA,QAAQjC,EAAK,UAAU;EACvB,SACEA,EAAK,YACJiC,IAAY,KAAA,IAAY;GAAE,KAAK;GAAG,OAAO;GAAG,QAAQ;GAAG,MAAM;EAAE;EAClE;CACF;AACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./types.cjs"),
|
|
1
|
+
const e=require("../color.cjs"),t=require("./types.cjs"),n=require("../decimate.cjs");var r=2e4,i=(e,t)=>`rgba(${Math.round(e[0]*255)},${Math.round(e[1]*255)},${Math.round(e[2]*255)},${e[3]*t})`,a=e=>!Number.isFinite(e)||Math.abs(e)>=15e37,o=(e,t,n,r=2)=>{let i=0,a=t;for(;i<a;){let t=i+a>>>1;e[t*r]<n?i=t+1:a=t}return i},s=(e,t,n,r)=>{let i=new Float64Array(Math.max(0,n-t)*3),o=0,s=t=>{i[o*3]=e[t*3],i[o*3+1]=e[t*3+1],i[o*3+2]=e[t*3+2],o++},c=NaN,l=-1,u=-1,d=-1,f=-1,p=()=>{if(l<0)return;let e=[l,u,d,f].sort((e,t)=>e-t),t=-1;for(let n of e)n!==t&&s(n),t=n;l=-1};for(let i=t;i<n;i++){let t=e[i*3+1];if(a(e[i*3])||a(t)||a(e[i*3+2])){p(),c=NaN,s(i);continue}let n=Math.floor(r(e[i*3]));n!==c||l<0?(p(),c=n,l=u=d=f=i):(t<e[u*3+1]&&(u=i),t>e[d*3+1]&&(d=i),f=i)}return p(),{points:i,length:o}},c=(r,c)=>{let l=null,u=e=>{let{xScale:t,xOffset:n,yScale:r,yOffset:i}=e.transform,a=e.width,o=e.height;return{px:e=>((e*t+n)*.5+.5)*a,py:e=>(1-((e*r+i)*.5+.5))*o,xRange:()=>{let e=(-1-n)/t,r=(1-n)/t;return e<r?[e,r]:[r,e]}}},d=(e,r)=>{if(!e.sorted||e.count<=r.width*2)return{points:e.points,length:e.count};let i=u(r),[a,s]=i.xRange(),c=Math.max(0,o(e.points,e.count,a)-1),l=Math.min(e.count,o(e.points,e.count,s)+1),d=n.decimateMinMax(e.points,c,l,i.px,t.GAP*.5);return{points:d.points,length:d.length}},f=(e,t)=>{let n=u(t),{points:o,length:s}=d(e,t);r.beginPath();let c=!1;for(let e=0;e<s;e++){let t=o[e*2],i=o[e*2+1];if(a(t)||a(i)){c=!1;continue}c?r.lineTo(n.px(t),n.py(i)):r.moveTo(n.px(t),n.py(i)),c=!0}r.lineWidth=e.width*t.dpr,r.lineJoin=`round`,r.lineCap=`round`,r.strokeStyle=i(e.color,1),r.stroke()},p=(e,t)=>{let n=u(t),c=e.points,l=e.count;if(e.sorted&&e.count>t.width*2){let[t,r]=n.xRange(),i=Math.max(0,o(e.points,e.count,t,3)-1),a=Math.min(e.count,o(e.points,e.count,r,3)+1);({points:c,length:l}=s(e.points,i,a,n.px))}let d=r.createLinearGradient(0,0,0,t.height);d.addColorStop(0,i(e.color,e.opacity)),d.addColorStop(1,i(e.color,e.opacity*.25)),r.fillStyle=d,r.beginPath();let f=-1,p=e=>{if(!(f<0)){for(let t=e-1;t>=f;t--)r.lineTo(n.px(c[t*3]),n.py(c[t*3+2]));r.closePath(),f=-1}};for(let e=0;e<l;e++){let t=c[e*3],i=c[e*3+1];if(a(t)||a(i)||a(c[e*3+2])){p(e);continue}f<0?(f=e,r.moveTo(n.px(t),n.py(i))):r.lineTo(n.px(t),n.py(i))}p(l),r.fill()},m=(t,n)=>{let o=u(n),s=n.dpr,c=t.minHalf*s,l=Math.abs(t.halfWidth*n.transform.xScale)*.5*n.width,d=t.radius*s,f=new Float32Array(t.instances,0,t.count*4),p=new Uint32Array(t.instances,0,t.count*4),[m,h]=o.xRange(),g=Math.abs(t.halfWidth),_=new Map;for(let e=0;e<t.count;e++){let t=f[e*4];if(a(t)||a(f[e*4+1])||a(f[e*4+2])||t<m-g||t>h+g)continue;let n=p[e*4+3],r=_.get(n);r||_.set(n,r=[]),r.push(e)}let v=typeof r.roundRect==`function`;for(let[n,a]of _){r.fillStyle=i(e.unpackColor(n),1),r.beginPath();for(let e of a){let n=o.px(f[e*4]),i=o.py(f[e*4+1]),a=o.py(f[e*4+2]),u=Math.abs(i-a)/2,p=Math.min(1,Math.max(0,(Math.min(l,u)-3*s)/(2*s))),m=t.inset*s*p-(t.inset>0?.5*(1-p):0),h=Math.max(l-m,.5,c),g=Math.max(u-m,c);if(g<=0)continue;let _=(i+a)/2,y=Math.min(d,h,g);y>.5&&v?r.roundRect(n-h,_-g,h*2,g*2,y):r.rect(n-h,_-g,h*2,g*2)}r.fill()}},h=(t,n)=>{let o=u(n),s=n.width,c=n.height,l=new Float32Array(t.instances,0,t.count*4),d=new Uint32Array(t.instances,0,t.count*4),f=0;for(let e=0;e<Math.min(t.count,64);e++)f=Math.max(f,l[e*4+2]);f=Math.max(1,Math.round((f||2)*n.dpr*.8));let p=Math.ceil(s/f),m=Math.ceil(c/f),h=new Int32Array(p*m).fill(-1);for(let e=0;e<t.count;e++){let t=l[e*4],n=l[e*4+1];if(a(t)||a(n)||!(l[e*4+2]>0))continue;let r=Math.floor(o.px(t)/f),i=Math.floor(o.py(n)/f);r<0||i<0||r>=p||i>=m||(h[i*p+r]=e)}let g=new Map;for(let e=0;e<h.length;e++){let t=h[e];if(t<0)continue;let n=d[t*4+3],r=g.get(n);r||g.set(n,r=[]),r.push(e)}for(let[n,a]of g){r.fillStyle=i(e.unpackColor(n),Math.max(t.opacity,.6));for(let e of a)r.fillRect(e%p*f,Math.floor(e/p)*f,f,f)}},g=(e,t)=>{let n=u(t),i=t.width,o=t.height;if(l??(l=c?.()??null),!l){h(e,t);return}l.width=i,l.height=o;let s=l.getContext(`2d`);if(!s)return;let d=s.createImageData(i,o),f=d.data,p=new Float32Array(e.instances,0,e.count*4),m=new Uint32Array(e.instances,0,e.count*4);for(let r=0;r<e.count;r++){let s=p[r*4],c=p[r*4+1],l=p[r*4+2];if(a(s)||a(c)||!(l>0))continue;let u=n.px(s),d=n.py(c),h=Math.max(1,Math.round(l*t.dpr*.8)),g=Math.round(u-h/2),_=Math.round(d-h/2),v=m[r*4+3],y=(v>>>24&255)/255*Math.max(e.opacity,.6),b=v&255,x=v>>>8&255,S=v>>>16&255;for(let e=Math.max(0,_);e<Math.min(o,_+h);e++)for(let t=Math.max(0,g);t<Math.min(i,g+h);t++){let n=(e*i+t)*4,r=f[n+3]/255,a=y+r*(1-y);f[n]=(b*y+f[n]*r*(1-y))/a,f[n+1]=(x*y+f[n+1]*r*(1-y))/a,f[n+2]=(S*y+f[n+2]*r*(1-y))/a,f[n+3]=a*255}}s.putImageData(d,0,0),r.drawImage(l,0,0)},_=(t,n)=>{if(t.count>2e4){g(t,n);return}let o=u(n),s=new Float32Array(t.instances,0,t.count*4),c=new Uint32Array(t.instances,0,t.count*4),l=new Map;for(let e=0;e<t.count;e++){let t=c[e*4+3],n=l.get(t);n||l.set(t,n=[]),n.push(e)}let d=t.stroke*n.dpr;for(let[c,u]of l){let l=e.unpackColor(c);r.beginPath();for(let e of u){let t=s[e*4],i=s[e*4+1],c=s[e*4+2];if(a(t)||a(i)||!(c>0))continue;let l=o.px(t),u=o.py(i),d=c*n.dpr/2;r.moveTo(l+d,u),r.arc(l,u,d,0,Math.PI*2)}if(r.fillStyle=i(l,t.opacity),r.fill(),d>0){r.beginPath();for(let e of u){let t=s[e*4],i=s[e*4+1],c=s[e*4+2];if(a(t)||a(i)||!(c>0))continue;let l=Math.max(0,c*n.dpr/2-d/2),u=o.px(t),f=o.py(i);r.moveTo(u+l,f),r.arc(u,f,l,0,Math.PI*2)}r.lineWidth=d,r.strokeStyle=i(l,1),r.stroke()}}};return{paint(e,t,n=0,i=0){r.save(),r.setTransform(1,0,0,1,n,i),r.beginPath(),r.rect(0,0,t.width,t.height),r.clip();for(let n of e)switch(n.kind){case`line`:n.count>1&&f(n,t);break;case`area`:n.count>1&&p(n,t);break;case`bar`:m(n,t);break;default:_(n,t)}r.restore()},destroy(){l=null}}},l=e=>{let t=e.getContext(`2d`);if(!t)return null;let n=c(t,()=>typeof document>`u`?null:document.createElement(`canvas`));return{kind:`canvas2d`,canvas:e,resize(t,n){e.width=Math.max(1,t),e.height=Math.max(1,n)},render(r,i){t.setTransform(1,0,0,1,0,0),t.clearRect(0,0,e.width,e.height),n.paint(r,i)},destroy(){n.destroy(),e.width=0,e.height=0}}};exports.SCATTER_PIXEL_THRESHOLD=r,exports.createCanvas2dPainter=c,exports.createCanvas2dRenderer=l;
|
|
2
2
|
//# sourceMappingURL=canvas2d.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas2d.cjs","names":["decimateMinMax","GAP","require_types","require_decimate","SCATTER_PIXEL_THRESHOLD","rgba","c","alpha","unpack","packed","isGap","v","lowerBoundX","lo","hi","count","mid","points","value","createCanvas2dPainter","scratch","mapper","frame","w","h","x","xScale","xOffset","y","yScale","yOffset","a","b","visiblePoints","item","m","x0","x1","start","end","result","drawLine","ctx","pen","i","length","drawArea","base","gradient","runStart","lastX","close","px","drawBars","half","r","y0","y1","cx","top","height","radius","drawScatterCells","f","u","cell","cols","rows","owner","cy","groups","list","cells","drawScatterPixels","scratchCanvas","sctx","image","data","size","s","g","py","o","da","outA","drawScatter","stroke","color","left","items","createCanvas2dRenderer","canvas","painter","width"],"sources":["../../../../../charts/src/engine/renderers/canvas2d.ts"],"sourcesContent":["// Canvas2D backend: the fallback without GPU. Lines are decimated to a few\n// points per pixel column and very large scatter sets are written pixel by\n// pixel, so it stays usable with large data sets.\n\nimport { decimateMinMax } from \"../decimate\";\nimport type { Rgba } from \"../color\";\nimport {\n GAP,\n type ChartRenderer,\n type RenderFrame,\n type RenderItem,\n type ScatterItem,\n} from \"./types\";\n\n/** Scatter sets above this size are rasterized through ImageData */\nexport const SCATTER_PIXEL_THRESHOLD = 20000;\n\nconst rgba = (c: Rgba, alpha: number) =>\n `rgba(${Math.round(c[0] * 255)},${Math.round(c[1] * 255)},${Math.round(c[2] * 255)},${c[3] * alpha})`;\n\nconst unpack = (packed: number): Rgba => [\n (packed & 0xff) / 255,\n ((packed >>> 8) & 0xff) / 255,\n ((packed >>> 16) & 0xff) / 255,\n ((packed >>> 24) & 0xff) / 255,\n];\n\nconst isGap = (v: number) => !Number.isFinite(v) || Math.abs(v) >= GAP * 0.5;\n\n/** First point index whose relative x is >= value (sorted, interleaved) */\nconst lowerBoundX = (points: Float32Array, count: number, value: number) => {\n let lo = 0;\n let hi = count;\n while (lo < hi) {\n const mid = (lo + hi) >>> 1;\n if (points[mid * 2] < value) lo = mid + 1;\n else hi = mid;\n }\n return lo;\n};\n\nexport interface Canvas2dPainter {\n /**\n * Draws the items in a `frame.width` x `frame.height` device-pixel area\n * whose top-left corner is at (`left`, `top`) device pixels; nothing is\n * cleared\n */\n paint(\n items: readonly RenderItem[],\n frame: RenderFrame,\n left?: number,\n top?: number,\n ): void;\n destroy(): void;\n}\n\n/**\n * Data layer drawn with any 2D context (browser canvases, mini-program\n * canvases, OffscreenCanvas). `scratchCanvas` creates the canvas used to\n * rasterize very large scatter sets; without it they are drawn as one\n * square per occupied pixel cell.\n */\nexport const createCanvas2dPainter = (\n ctx: CanvasRenderingContext2D,\n scratchCanvas?: () => HTMLCanvasElement | null,\n): Canvas2dPainter => {\n let scratch: HTMLCanvasElement | null = null;\n\n const mapper = (frame: RenderFrame) => {\n const { xScale, xOffset, yScale, yOffset } = frame.transform;\n const w = frame.width;\n const h = frame.height;\n return {\n px: (x: number) => ((x * xScale + xOffset) * 0.5 + 0.5) * w,\n py: (y: number) => (1 - ((y * yScale + yOffset) * 0.5 + 0.5)) * h,\n /** Visible relative x range */\n xRange: (): [number, number] => {\n const a = (-1 - xOffset) / xScale;\n const b = (1 - xOffset) / xScale;\n return a < b ? [a, b] : [b, a];\n },\n };\n };\n\n /** Points actually drawn: decimated when there are many per pixel */\n const visiblePoints = (\n item: Extract<RenderItem, { kind: \"line\" | \"area\" }>,\n frame: RenderFrame,\n ): { points: ArrayLike<number>; length: number } => {\n if (!item.sorted || item.count <= frame.width * 2) {\n return { points: item.points, length: item.count };\n }\n const m = mapper(frame);\n const [x0, x1] = m.xRange();\n const start = Math.max(0, lowerBoundX(item.points, item.count, x0) - 1);\n const end = Math.min(\n item.count,\n lowerBoundX(item.points, item.count, x1) + 1,\n );\n const result = decimateMinMax(item.points, start, end, m.px, GAP * 0.5);\n return { points: result.points, length: result.length };\n };\n\n const drawLine = (\n item: Extract<RenderItem, { kind: \"line\" }>,\n frame: RenderFrame,\n ) => {\n const m = mapper(frame);\n const { points, length } = visiblePoints(item, frame);\n ctx.beginPath();\n let pen = false;\n for (let i = 0; i < length; i++) {\n const x = points[i * 2];\n const y = points[i * 2 + 1];\n if (isGap(x) || isGap(y)) {\n pen = false;\n continue;\n }\n if (pen) ctx.lineTo(m.px(x), m.py(y));\n else ctx.moveTo(m.px(x), m.py(y));\n pen = true;\n }\n ctx.lineWidth = item.width * frame.dpr;\n ctx.lineJoin = \"round\";\n ctx.lineCap = \"round\";\n ctx.strokeStyle = rgba(item.color, 1);\n ctx.stroke();\n };\n\n const drawArea = (\n item: Extract<RenderItem, { kind: \"area\" }>,\n frame: RenderFrame,\n ) => {\n const m = mapper(frame);\n const { points, length } = visiblePoints(item, frame);\n const base = m.py(item.baseline);\n const gradient = ctx.createLinearGradient(0, 0, 0, base);\n gradient.addColorStop(0, rgba(item.color, item.opacity));\n gradient.addColorStop(1, rgba(item.color, item.opacity * 0.3));\n ctx.fillStyle = gradient;\n ctx.beginPath();\n let runStart = -1;\n let lastX = 0;\n const close = () => {\n if (runStart < 0) return;\n ctx.lineTo(lastX, base);\n ctx.closePath();\n runStart = -1;\n };\n for (let i = 0; i < length; i++) {\n const x = points[i * 2];\n const y = points[i * 2 + 1];\n if (isGap(x) || isGap(y)) {\n close();\n continue;\n }\n const px = m.px(x);\n if (runStart < 0) {\n runStart = i;\n ctx.moveTo(px, base);\n }\n ctx.lineTo(px, m.py(y));\n lastX = px;\n }\n close();\n ctx.fill();\n };\n\n const drawBars = (\n item: Extract<RenderItem, { kind: \"bar\" }>,\n frame: RenderFrame,\n ) => {\n const m = mapper(frame);\n const half = Math.max(\n Math.abs(item.halfWidth * frame.transform.xScale) * 0.5 * frame.width,\n 0.5,\n );\n const r = item.radius * frame.dpr;\n ctx.fillStyle = rgba(item.color, 1);\n ctx.beginPath();\n const v = item.instances;\n for (let i = 0; i < item.count; i++) {\n const x = v[i * 3];\n const y0 = v[i * 3 + 1];\n const y1 = v[i * 3 + 2];\n if (isGap(x) || isGap(y0) || isGap(y1)) continue;\n const cx = m.px(x);\n const a = m.py(y0);\n const b = m.py(y1);\n const top = Math.min(a, b);\n const height = Math.abs(a - b);\n const radius = Math.min(r, half, height / 2);\n if (radius > 0.5 && typeof ctx.roundRect === \"function\") {\n ctx.roundRect(cx - half, top, half * 2, height, radius);\n } else {\n ctx.rect(cx - half, top, half * 2, height);\n }\n }\n ctx.fill();\n };\n\n /** One square per occupied cell (the last point of a cell wins, like the GPU) */\n const drawScatterCells = (item: ScatterItem, frame: RenderFrame) => {\n const m = mapper(frame);\n const w = frame.width;\n const h = frame.height;\n const f = new Float32Array(item.instances, 0, item.count * 4);\n const u = new Uint32Array(item.instances, 0, item.count * 4);\n let cell = 0;\n for (let i = 0; i < Math.min(item.count, 64); i++)\n cell = Math.max(cell, f[i * 4 + 2]);\n cell = Math.max(1, Math.round((cell || 2) * frame.dpr * 0.8));\n const cols = Math.ceil(w / cell);\n const rows = Math.ceil(h / cell);\n const owner = new Int32Array(cols * rows).fill(-1);\n for (let i = 0; i < item.count; i++) {\n const x = f[i * 4];\n const y = f[i * 4 + 1];\n if (isGap(x) || isGap(y) || !(f[i * 4 + 2] > 0)) continue;\n const cx = Math.floor(m.px(x) / cell);\n const cy = Math.floor(m.py(y) / cell);\n if (cx < 0 || cy < 0 || cx >= cols || cy >= rows) continue;\n owner[cy * cols + cx] = i;\n }\n const groups = new Map<number, number[]>();\n for (let c = 0; c < owner.length; c++) {\n const i = owner[c];\n if (i < 0) continue;\n const packed = u[i * 4 + 3];\n let list = groups.get(packed);\n if (!list) groups.set(packed, (list = []));\n list.push(c);\n }\n for (const [packed, cells] of groups) {\n ctx.fillStyle = rgba(unpack(packed), Math.max(item.opacity, 0.6));\n for (const c of cells) {\n ctx.fillRect(\n (c % cols) * cell,\n Math.floor(c / cols) * cell,\n cell,\n cell,\n );\n }\n }\n };\n\n const drawScatterPixels = (item: ScatterItem, frame: RenderFrame) => {\n const m = mapper(frame);\n const w = frame.width;\n const h = frame.height;\n scratch ??= scratchCanvas?.() ?? null;\n if (!scratch) {\n drawScatterCells(item, frame);\n return;\n }\n scratch.width = w;\n scratch.height = h;\n const sctx = scratch.getContext(\"2d\");\n if (!sctx) return;\n const image = sctx.createImageData(w, h);\n const data = image.data;\n const f = new Float32Array(item.instances, 0, item.count * 4);\n const u = new Uint32Array(item.instances, 0, item.count * 4);\n for (let i = 0; i < item.count; i++) {\n const x = f[i * 4];\n const y = f[i * 4 + 1];\n const size = f[i * 4 + 2];\n if (isGap(x) || isGap(y) || !(size > 0)) continue;\n const cx = m.px(x);\n const cy = m.py(y);\n const s = Math.max(1, Math.round(size * frame.dpr * 0.8));\n const x0 = Math.round(cx - s / 2);\n const y0 = Math.round(cy - s / 2);\n const packed = u[i * 4 + 3];\n const alpha =\n (((packed >>> 24) & 0xff) / 255) * Math.max(item.opacity, 0.6);\n const r = packed & 0xff;\n const g = (packed >>> 8) & 0xff;\n const b = (packed >>> 16) & 0xff;\n for (let py = Math.max(0, y0); py < Math.min(h, y0 + s); py++) {\n for (let px = Math.max(0, x0); px < Math.min(w, x0 + s); px++) {\n const o = (py * w + px) * 4;\n const da = data[o + 3] / 255;\n const outA = alpha + da * (1 - alpha);\n // straight-alpha \"over\"\n data[o] = (r * alpha + data[o] * da * (1 - alpha)) / outA;\n data[o + 1] = (g * alpha + data[o + 1] * da * (1 - alpha)) / outA;\n data[o + 2] = (b * alpha + data[o + 2] * da * (1 - alpha)) / outA;\n data[o + 3] = outA * 255;\n }\n }\n }\n sctx.putImageData(image, 0, 0);\n ctx.drawImage(scratch, 0, 0);\n };\n\n const drawScatter = (item: ScatterItem, frame: RenderFrame) => {\n if (item.count > SCATTER_PIXEL_THRESHOLD) {\n drawScatterPixels(item, frame);\n return;\n }\n const m = mapper(frame);\n const f = new Float32Array(item.instances, 0, item.count * 4);\n const u = new Uint32Array(item.instances, 0, item.count * 4);\n const groups = new Map<number, number[]>();\n for (let i = 0; i < item.count; i++) {\n const packed = u[i * 4 + 3];\n let list = groups.get(packed);\n if (!list) groups.set(packed, (list = []));\n list.push(i);\n }\n const stroke = item.stroke * frame.dpr;\n for (const [packed, list] of groups) {\n const color = unpack(packed);\n ctx.beginPath();\n for (const i of list) {\n const x = f[i * 4];\n const y = f[i * 4 + 1];\n const size = f[i * 4 + 2];\n if (isGap(x) || isGap(y) || !(size > 0)) continue;\n const cx = m.px(x);\n const cy = m.py(y);\n const r = (size * frame.dpr) / 2;\n ctx.moveTo(cx + r, cy);\n ctx.arc(cx, cy, r, 0, Math.PI * 2);\n }\n ctx.fillStyle = rgba(color, item.opacity);\n ctx.fill();\n if (stroke > 0) {\n ctx.beginPath();\n for (const i of list) {\n const x = f[i * 4];\n const y = f[i * 4 + 1];\n const size = f[i * 4 + 2];\n if (isGap(x) || isGap(y) || !(size > 0)) continue;\n const r = Math.max(0, (size * frame.dpr) / 2 - stroke / 2);\n const cx = m.px(x);\n const cy = m.py(y);\n ctx.moveTo(cx + r, cy);\n ctx.arc(cx, cy, r, 0, Math.PI * 2);\n }\n ctx.lineWidth = stroke;\n ctx.strokeStyle = rgba(color, 1);\n ctx.stroke();\n }\n }\n };\n\n return {\n paint(items, frame, left = 0, top = 0) {\n ctx.save();\n ctx.setTransform(1, 0, 0, 1, left, top);\n ctx.beginPath();\n ctx.rect(0, 0, frame.width, frame.height);\n ctx.clip();\n for (const item of items) {\n switch (item.kind) {\n case \"line\":\n if (item.count > 1) drawLine(item, frame);\n break;\n case \"area\":\n if (item.count > 1) drawArea(item, frame);\n break;\n case \"bar\":\n drawBars(item, frame);\n break;\n default:\n drawScatter(item, frame);\n break;\n }\n }\n ctx.restore();\n },\n destroy() {\n scratch = null;\n },\n };\n};\n\nexport const createCanvas2dRenderer = (\n canvas: HTMLCanvasElement,\n): ChartRenderer | null => {\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) return null;\n const painter = createCanvas2dPainter(ctx, () =>\n typeof document === \"undefined\" ? null : document.createElement(\"canvas\"),\n );\n return {\n kind: \"canvas2d\",\n canvas,\n resize(width, height) {\n canvas.width = Math.max(1, width);\n canvas.height = Math.max(1, height);\n },\n render(items, frame) {\n ctx.setTransform(1, 0, 0, 1, 0, 0);\n ctx.clearRect(0, 0, canvas.width, canvas.height);\n painter.paint(items, frame);\n },\n destroy() {\n painter.destroy();\n canvas.width =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D,EACjB,OAAQvD,EAAK,KAAb,CACE,IAAK,OACCA,EAAK,MAAQ,GAAGO,EAASP,EAAMZ,CAAK,EACxC,MACF,IAAK,OACCY,EAAK,MAAQ,GAAGY,EAASZ,EAAMZ,CAAK,EACxC,MACF,IAAK,MACH+B,EAASnB,EAAMZ,CAAK,EACpB,MACF,QACE+D,EAAYnD,EAAMZ,CAAK,CAE3B,CAEFoB,EAAI,QAAQ,CACd,EACA,SAAU,CACR,EAAU,IACZ,CACF,CACF,EAEagD,EACX,GACyB,CACzB,IAAMhD,EAAMiD,EAAO,WAAW,IAAI,EAClC,GAAI,CAACjD,EAAK,OAAO,KACjB,IAAMkD,EAAUzE,EAAsBuB,MACpC,OAAO,SAAa,IAAc,KAAO,SAAS,cAAc,QAAQ,CAC1E,EACA,MAAO,CACL,KAAM,WACN,SACA,OAAO,EAAO,EAAQ,CACpB,EAAO,MAAQ,KAAK,IAAI,EAAGmD,CAAK,EAChC,EAAO,OAAS,KAAK,IAAI,EAAGjC,CAAM,CACpC,EACA,OAAO,EAAO,EAAO,CACnBlB,EAAI,aAAa,EAAG,EAAG,EAAG,EAAG,EAAG,CAAC,EACjCA,EAAI,UAAU,EAAG,EAAGiD,EAAO,MAAOA,EAAO,MAAM,EAC/CC,EAAQ,MAAMH,EAAOnE,CAAK,CAC5B,EACA,SAAU,CACRsE,EAAQ,QAAQ,EAChB,EAAO,MAAQ,EACf,EAAO,OAAS,CAClB,CACF,CACF"}
|
|
1
|
+
{"version":3,"file":"canvas2d.cjs","names":["decimateMinMax","GAP","unpack","require_color","require_types","require_decimate","SCATTER_PIXEL_THRESHOLD","rgba","c","alpha","isGap","v","lowerBoundX","lo","hi","count","mid","points","stride","value","decimateArea","out","end","start","length","push","i","col","first","min","max","last","flush","picks","a","b","prev","y","column","createCanvas2dPainter","scratch","mapper","frame","w","h","x","xScale","xOffset","yScale","yOffset","visiblePoints","item","m","x0","x1","result","drawLine","ctx","pen","drawArea","gradient","runStart","close","k","drawBars","dpr","minHalf","rawHalf","r","u","pad","groups","packed","list","rounded","cx","rawHh","fade","inset","half","hh","cy","radius","drawScatterCells","f","cell","cols","rows","owner","cells","drawScatterPixels","scratchCanvas","sctx","image","data","size","s","y0","g","py","px","o","da","outA","drawScatter","stroke","color","left","top","items","createCanvas2dRenderer","canvas","painter","width","height"],"sources":["../../../../../charts/src/engine/renderers/canvas2d.ts"],"sourcesContent":["// Canvas2D backend: the fallback without GPU. Lines are decimated to a few\n// points per pixel column and very large scatter sets are written pixel by\n// pixel, so it stays usable with large data sets.\n\nimport { decimateMinMax } from \"../decimate\";\nimport { unpackColor as unpack, type Rgba } from \"../color\";\nimport {\n AREA_STRIDE,\n GAP,\n type AreaItem,\n type BarItem,\n type ChartRenderer,\n type RenderFrame,\n type RenderItem,\n type ScatterItem,\n} from \"./types\";\n\n/** Scatter sets above this size are rasterized through ImageData */\nexport const SCATTER_PIXEL_THRESHOLD = 20000;\n\nconst rgba = (c: Rgba, alpha: number) =>\n `rgba(${Math.round(c[0] * 255)},${Math.round(c[1] * 255)},${Math.round(c[2] * 255)},${c[3] * alpha})`;\n\nconst isGap = (v: number) => !Number.isFinite(v) || Math.abs(v) >= GAP * 0.5;\n\n/** First point index whose relative x is >= value (sorted, interleaved) */\nconst lowerBoundX = (\n points: Float32Array,\n count: number,\n value: number,\n stride = 2,\n) => {\n let lo = 0;\n let hi = count;\n while (lo < hi) {\n const mid = (lo + hi) >>> 1;\n if (points[mid * stride] < value) lo = mid + 1;\n else hi = mid;\n }\n return lo;\n};\n\n/**\n * Min-max decimation of area points (x, top, bottom): per pixel column the\n * first, lowest, highest and last tops are kept with their bottoms\n */\nconst decimateArea = (\n points: Float32Array,\n start: number,\n end: number,\n column: (x: number) => number,\n): { points: Float64Array; length: number } => {\n const out = new Float64Array(Math.max(0, end - start) * AREA_STRIDE);\n let length = 0;\n const push = (i: number) => {\n out[length * 3] = points[i * 3];\n out[length * 3 + 1] = points[i * 3 + 1];\n out[length * 3 + 2] = points[i * 3 + 2];\n length++;\n };\n let col = NaN;\n let first = -1;\n let min = -1;\n let max = -1;\n let last = -1;\n const flush = () => {\n if (first < 0) return;\n const picks = [first, min, max, last].sort((a, b) => a - b);\n let prev = -1;\n for (const i of picks) {\n if (i !== prev) push(i);\n prev = i;\n }\n first = -1;\n };\n for (let i = start; i < end; i++) {\n const y = points[i * 3 + 1];\n if (isGap(points[i * 3]) || isGap(y) || isGap(points[i * 3 + 2])) {\n flush();\n col = NaN;\n push(i);\n continue;\n }\n const c = Math.floor(column(points[i * 3]));\n if (c !== col || first < 0) {\n flush();\n col = c;\n first = min = max = last = i;\n } else {\n if (y < points[min * 3 + 1]) min = i;\n if (y > points[max * 3 + 1]) max = i;\n last = i;\n }\n }\n flush();\n return { points: out, length };\n};\n\nexport interface Canvas2dPainter {\n /**\n * Draws the items in a `frame.width` x `frame.height` device-pixel area\n * whose top-left corner is at (`left`, `top`) device pixels; nothing is\n * cleared\n */\n paint(\n items: readonly RenderItem[],\n frame: RenderFrame,\n left?: number,\n top?: number,\n ): void;\n destroy(): void;\n}\n\n/**\n * Data layer drawn with any 2D context (browser canvases, mini-program\n * canvases, OffscreenCanvas). `scratchCanvas` creates the canvas used to\n * rasterize very large scatter sets; without it they are drawn as one\n * square per occupied pixel cell.\n */\nexport const createCanvas2dPainter = (\n ctx: CanvasRenderingContext2D,\n scratchCanvas?: () => HTMLCanvasElement | null,\n): Canvas2dPainter => {\n let scratch: HTMLCanvasElement | null = null;\n\n const mapper = (frame: RenderFrame) => {\n const { xScale, xOffset, yScale, yOffset } = frame.transform;\n const w = frame.width;\n const h = frame.height;\n return {\n px: (x: number) => ((x * xScale + xOffset) * 0.5 + 0.5) * w,\n py: (y: number) => (1 - ((y * yScale + yOffset) * 0.5 + 0.5)) * h,\n /** Visible relative x range */\n xRange: (): [number, number] => {\n const a = (-1 - xOffset) / xScale;\n const b = (1 - xOffset) / xScale;\n return a < b ? [a, b] : [b, a];\n },\n };\n };\n\n /** Points actually drawn: decimated when there are many per pixel */\n const visiblePoints = (\n item: Extract<RenderItem, { kind: \"line\" }>,\n frame: RenderFrame,\n ): { points: ArrayLike<number>; length: number } => {\n if (!item.sorted || item.count <= frame.width * 2) {\n return { points: item.points, length: item.count };\n }\n const m = mapper(frame);\n const [x0, x1] = m.xRange();\n const start = Math.max(0, lowerBoundX(item.points, item.count, x0) - 1);\n const end = Math.min(\n item.count,\n lowerBoundX(item.points, item.count, x1) + 1,\n );\n const result = decimateMinMax(item.points, start, end, m.px, GAP * 0.5);\n return { points: result.points, length: result.length };\n };\n\n const drawLine = (\n item: Extract<RenderItem, { kind: \"line\" }>,\n frame: RenderFrame,\n ) => {\n const m = mapper(frame);\n const { points, length } = visiblePoints(item, frame);\n ctx.beginPath();\n let pen = false;\n for (let i = 0; i < length; i++) {\n const x = points[i * 2];\n const y = points[i * 2 + 1];\n if (isGap(x) || isGap(y)) {\n pen = false;\n continue;\n }\n if (pen) ctx.lineTo(m.px(x), m.py(y));\n else ctx.moveTo(m.px(x), m.py(y));\n pen = true;\n }\n ctx.lineWidth = item.width * frame.dpr;\n ctx.lineJoin = \"round\";\n ctx.lineCap = \"round\";\n ctx.strokeStyle = rgba(item.color, 1);\n ctx.stroke();\n };\n\n const drawArea = (item: AreaItem, frame: RenderFrame) => {\n const m = mapper(frame);\n let points: ArrayLike<number> = item.points;\n let length = item.count;\n if (item.sorted && item.count > frame.width * 2) {\n const [x0, x1] = m.xRange();\n const start = Math.max(\n 0,\n lowerBoundX(item.points, item.count, x0, AREA_STRIDE) - 1,\n );\n const end = Math.min(\n item.count,\n lowerBoundX(item.points, item.count, x1, AREA_STRIDE) + 1,\n );\n ({ points, length } = decimateArea(item.points, start, end, m.px));\n }\n const gradient = ctx.createLinearGradient(0, 0, 0, frame.height);\n gradient.addColorStop(0, rgba(item.color, item.opacity));\n gradient.addColorStop(1, rgba(item.color, item.opacity * 0.25));\n ctx.fillStyle = gradient;\n ctx.beginPath();\n // each run without gaps: along the tops, back along the bottoms\n let runStart = -1;\n const close = (end: number) => {\n if (runStart < 0) return;\n for (let k = end - 1; k >= runStart; k--) {\n ctx.lineTo(m.px(points[k * 3]), m.py(points[k * 3 + 2]));\n }\n ctx.closePath();\n runStart = -1;\n };\n for (let i = 0; i < length; i++) {\n const x = points[i * 3];\n const y = points[i * 3 + 1];\n if (isGap(x) || isGap(y) || isGap(points[i * 3 + 2])) {\n close(i);\n continue;\n }\n if (runStart < 0) {\n runStart = i;\n ctx.moveTo(m.px(x), m.py(y));\n } else {\n ctx.lineTo(m.px(x), m.py(y));\n }\n }\n close(length);\n ctx.fill();\n };\n\n const drawBars = (item: BarItem, frame: RenderFrame) => {\n const m = mapper(frame);\n const dpr = frame.dpr;\n const minHalf = item.minHalf * dpr;\n const rawHalf =\n Math.abs(item.halfWidth * frame.transform.xScale) * 0.5 * frame.width;\n const r = item.radius * dpr;\n const f = new Float32Array(item.instances, 0, item.count * 4);\n const u = new Uint32Array(item.instances, 0, item.count * 4);\n const [x0, x1] = m.xRange();\n const pad = Math.abs(item.halfWidth);\n // one path per color\n const groups = new Map<number, number[]>();\n for (let i = 0; i < item.count; i++) {\n const x = f[i * 4];\n if (isGap(x) || isGap(f[i * 4 + 1]) || isGap(f[i * 4 + 2])) continue;\n if (x < x0 - pad || x > x1 + pad) continue;\n const packed = u[i * 4 + 3];\n let list = groups.get(packed);\n if (!list) groups.set(packed, (list = []));\n list.push(i);\n }\n const rounded = typeof ctx.roundRect === \"function\";\n for (const [packed, list] of groups) {\n ctx.fillStyle = rgba(unpack(packed), 1);\n ctx.beginPath();\n for (const i of list) {\n const cx = m.px(f[i * 4]);\n const a = m.py(f[i * 4 + 1]);\n const b = m.py(f[i * 4 + 2]);\n const rawHh = Math.abs(a - b) / 2;\n // the gap between cells fades out on small cells (like the shaders)\n const fade = Math.min(\n 1,\n Math.max(0, (Math.min(rawHalf, rawHh) - 3 * dpr) / (2 * dpr)),\n );\n const inset =\n item.inset * dpr * fade - (item.inset > 0 ? 0.5 * (1 - fade) : 0);\n const half = Math.max(rawHalf - inset, 0.5, minHalf);\n const hh = Math.max(rawHh - inset, minHalf);\n if (hh <= 0) continue;\n const cy = (a + b) / 2;\n const radius = Math.min(r, half, hh);\n if (radius > 0.5 && rounded) {\n ctx.roundRect(cx - half, cy - hh, half * 2, hh * 2, radius);\n } else {\n ctx.rect(cx - half, cy - hh, half * 2, hh * 2);\n }\n }\n ctx.fill();\n }\n };\n\n /** One square per occupied cell (the last point of a cell wins, like the GPU) */\n const drawScatterCells = (item: ScatterItem, frame: RenderFrame) => {\n const m = mapper(frame);\n const w = frame.width;\n const h = frame.height;\n const f = new Float32Array(item.instances, 0, item.count * 4);\n const u = new Uint32Array(item.instances, 0, item.count * 4);\n let cell = 0;\n for (let i = 0; i < Math.min(item.count, 64); i++)\n cell = Math.max(cell, f[i * 4 + 2]);\n cell = Math.max(1, Math.round((cell || 2) * frame.dpr * 0.8));\n const cols = Math.ceil(w / cell);\n const rows = Math.ceil(h / cell);\n const owner = new Int32Array(cols * rows).fill(-1);\n for (let i = 0; i < item.count; i++) {\n const x = f[i * 4];\n const y = f[i * 4 + 1];\n if (isGap(x) || isGap(y) || !(f[i * 4 + 2] > 0)) continue;\n const cx = Math.floor(m.px(x) / cell);\n const cy = Math.floor(m.py(y) / cell);\n if (cx < 0 || cy < 0 || cx >= cols || cy >= rows) continue;\n owner[cy * cols + cx] = i;\n }\n const groups = new Map<number, number[]>();\n for (let c = 0; c < owner.length; c++) {\n const i = owner[c];\n if (i < 0) continue;\n const packed = u[i * 4 + 3];\n let list = groups.get(packed);\n if (!list) groups.set(packed, (list = []));\n list.push(c);\n }\n for (const [packed, cells] of groups) {\n ctx.fillStyle = rgba(unpack(packed), Math.max(item.opacity, 0.6));\n for (const c of cells) {\n ctx.fillRect(\n (c % cols) * cell,\n Math.floor(c / cols) * cell,\n cell,\n cell,\n );\n }\n }\n };\n\n const drawScatterPixels = (item: ScatterItem, frame: RenderFrame) => {\n const m = mapper(frame);\n const w = frame.width;\n const h = frame.height;\n scratch ??= scratchCanvas?.() ?? null;\n if (!scratch) {\n drawScatterCells(item, frame);\n return;\n }\n scratch.width = w;\n scratch.height = h;\n const sctx = scratch.getContext(\"2d\");\n if (!sctx) return;\n const image = sctx.createImageData(w, h);\n const data = image.data;\n const f = new Float32Array(item.instances, 0, item.count * 4);\n const u = new Uint32Array(item.instances, 0, item.count * 4);\n for (let i = 0; i < item.count; i++) {\n const x = f[i * 4];\n const y = f[i * 4 + 1];\n const size = f[i * 4 + 2];\n if (isGap(x) || isGap(y) || !(size > 0)) continue;\n const cx = m.px(x);\n const cy = m.py(y);\n const s = Math.max(1, Math.round(size * frame.dpr * 0.8));\n const x0 = Math.round(cx - s / 2);\n const y0 = Math.round(cy - s / 2);\n const packed = u[i * 4 + 3];\n const alpha =\n (((packed >>> 24) & 0xff) / 255) * Math.max(item.opacity, 0.6);\n const r = packed & 0xff;\n const g = (packed >>> 8) & 0xff;\n const b = (packed >>> 16) & 0xff;\n for (let py = Math.max(0, y0); py < Math.min(h, y0 + s); py++) {\n for (let px = Math.max(0, x0); px < Math.min(w, x0 + s); px++) {\n const o = (py * w + px) * 4;\n const da = data[o + 3] / 255;\n const outA = alpha + da * (1 - alpha);\n // straight-alpha \"over\"\n data[o] = (r * alpha + data[o] * da * (1 - alpha)) / outA;\n data[o + 1] = (g * alpha + data[o + 1] * da * (1 - alpha)) / outA;\n data[o + 2] = (b * alpha + data[o + 2] * da * (1 - alpha)) / outA;\n data[o + 3] = outA * 255;\n }\n }\n }\n sctx.putImageData(image, 0, 0);\n ctx.drawImage(scratch, 0, 0);\n };\n\n const drawScatter = (item: ScatterItem, frame: RenderFrame) => {\n if (item.count > SCATTER_PIXEL_THRESHOLD) {\n drawScatterPixels(item, frame);\n return;\n }\n const m = mapper(frame);\n const f = new Float32Array(item.instances, 0, item.count * 4);\n const u = new Uint32Array(item.instances, 0, item.count * 4);\n const groups = new Map<number, number[]>();\n for (let i = 0; i < item.count; i++) {\n const packed = u[i * 4 + 3];\n let list = groups.get(packed);\n if (!list) groups.set(packed, (list = []));\n list.push(i);\n }\n const stroke = item.stroke * frame.dpr;\n for (const [packed, list] of groups) {\n const color = unpack(packed);\n ctx.beginPath();\n for (const i of list) {\n const x = f[i * 4];\n const y = f[i * 4 + 1];\n const size = f[i * 4 + 2];\n if (isGap(x) || isGap(y) || !(size > 0)) continue;\n const cx = m.px(x);\n const cy = m.py(y);\n const r = (size * frame.dpr) / 2;\n ctx.moveTo(cx + r, cy);\n ctx.arc(cx, cy, r, 0, Math.PI * 2);\n }\n ctx.fillStyle = rgba(color, item.opacity);\n ctx.fill();\n if (stroke > 0) {\n ctx.beginPath();\n for (const i of list) {\n const x = f[i * 4];\n const y = f[i * 4 + 1];\n const size = f[i * 4 + 2];\n if (isGap(x) || isGap(y) || !(size > 0)) continue;\n const r = Math.max(0, (size * frame.dpr) / 2 - stroke / 2);\n const cx = m.px(x);\n const cy = m.py(y);\n ctx.moveTo(cx + r, cy);\n ctx.arc(cx, cy, r, 0, Math.PI * 2);\n }\n ctx.lineWidth = stroke;\n ctx.strokeStyle = rgba(color, 1);\n ctx.stroke();\n }\n }\n };\n\n return {\n paint(items, frame, left = 0, top = 0) {\n ctx.save();\n ctx.setTransform(1, 0, 0, 1, left, top);\n ctx.beginPath();\n ctx.rect(0, 0, frame.width, frame.height);\n ctx.clip();\n for (const item of items) {\n switch (item.kind) {\n case \"line\":\n if (item.count > 1) drawLine(item, frame);\n break;\n case \"area\":\n if (item.count > 1) drawArea(item, frame);\n break;\n case \"bar\":\n drawBars(item, frame);\n break;\n default:\n drawScatter(item, frame);\n break;\n }\n }\n ctx.restore();\n },\n destroy() {\n scratch = null;\n },\n };\n};\n\nexport const createCanvas2dRenderer = (\n canvas: HTMLCanvasElement,\n): ChartRenderer | null => {\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) return null;\n const painter = createCanvas2dPainter(ctx, () =>\n typeof document === \"undefined\" ? null : document.createElement(\"canvas\"),\n );\n return {\n kind: \"canvas2d\",\n canvas,\n resize(width, height) {\n canvas.width = Math.max(1, width);\n canvas.height = Math.max(1, height);\n },\n render(items, frame) {\n ctx.setTransform(1, 0, 0, 1, 0, 0);\n ctx.clearRect(0, 0, canvas.width, canvas.height);\n painter.paint(items, frame);\n },\n destroy() {\n painter.destroy();\n canvas.width = 0;\n canvas.height = 0;\n },\n };\n};\n"],"mappings":"sFAkBA,IAAaM,EAA0B,IAEjCC,GAAQ,EAAS,IACrB,QAAQ,KAAK,MAAMC,EAAE,GAAK,GAAG,EAAE,GAAG,KAAK,MAAMA,EAAE,GAAK,GAAG,EAAE,GAAG,KAAK,MAAMA,EAAE,GAAK,GAAG,EAAE,GAAGA,EAAE,GAAKC,EAAM,GAE/FC,EAAS,GAAc,CAAC,OAAO,SAASC,CAAC,GAAK,KAAK,IAAIA,CAAC,GAAA,MAGxDC,GACJ,EACA,EACA,EACA,EAAS,IACN,CACH,IAAIC,EAAK,EACLC,EAAKC,EACT,KAAOF,EAAKC,GAAI,CACd,IAAME,EAAOH,EAAKC,IAAQ,EACtBG,EAAOD,EAAME,GAAUC,EAAO,EAAKH,EAAM,EACxC,EAAKA,CACZ,CACA,OAAOH,CACT,EAMMO,GACJ,EACA,EACA,EACA,IAC6C,CAC7C,IAAMC,EAAM,IAAI,aAAa,KAAK,IAAI,EAAGC,EAAMC,CAAK,EAAA,CAAe,EAC/DC,EAAS,EACPC,EAAQ,GAAc,CAC1B,EAAID,EAAS,GAAKP,EAAOS,EAAI,GAC7B,EAAIF,EAAS,EAAI,GAAKP,EAAOS,EAAI,EAAI,GACrC,EAAIF,EAAS,EAAI,GAAKP,EAAOS,EAAI,EAAI,GACrC,GACF,EACIC,EAAM,IACNC,EAAQ,GACRC,EAAM,GACNC,EAAM,GACNC,EAAO,GACLC,MAAc,CAClB,GAAIJ,EAAQ,EAAG,OACf,IAAMK,EAAQ,CAACL,EAAOC,EAAKC,EAAKC,CAAI,CAAC,CAAC,MAAM,EAAG,IAAMG,EAAIC,CAAC,EACtDC,EA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