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
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createShapeChart as e } from "../engine/shapes/chart.js";
|
|
3
|
+
import { useEffect as t, useImperativeHandle as n, useMemo as r, useRef as i, useState as a } from "react";
|
|
4
|
+
import { createPortal as o, flushSync as s } from "react-dom";
|
|
5
|
+
import { jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
6
|
+
//#region src/react/shapes.tsx
|
|
7
|
+
var u = (e, t) => e === void 0 ? t : typeof e == "number" ? `${e}px` : e, d = ({ palette: e, legend: t, tooltip: n, format: i, percentFormat: a, hidden: o, animation: s, padding: c, ariaLabel: l }) => {
|
|
8
|
+
let u = o ? o.join(",") : null, d = r(() => u === null ? void 0 : u ? u.split(",").map(Number) : [], [u]);
|
|
9
|
+
return r(() => ({
|
|
10
|
+
palette: e,
|
|
11
|
+
legend: t,
|
|
12
|
+
tooltip: n,
|
|
13
|
+
format: i,
|
|
14
|
+
percentFormat: a,
|
|
15
|
+
hidden: d,
|
|
16
|
+
animation: s,
|
|
17
|
+
padding: c,
|
|
18
|
+
ariaLabel: l
|
|
19
|
+
}), [
|
|
20
|
+
e,
|
|
21
|
+
t,
|
|
22
|
+
n,
|
|
23
|
+
i,
|
|
24
|
+
a,
|
|
25
|
+
d,
|
|
26
|
+
s,
|
|
27
|
+
c,
|
|
28
|
+
l
|
|
29
|
+
]);
|
|
30
|
+
};
|
|
31
|
+
function f({ options: d, height: f, width: p, className: m, style: h, handleRef: g, renderTooltip: _, ...v }) {
|
|
32
|
+
let y = i(null), b = i(null), x = i(v), S = i(_), [C, w] = a(null), T = r(() => typeof document > "u" ? null : document.createElement("div"), []), E = !!_, D = r(() => {
|
|
33
|
+
if (!E || !T || d.tooltip === !1) return d;
|
|
34
|
+
let e = typeof d.tooltip == "object" ? d.tooltip : {};
|
|
35
|
+
return {
|
|
36
|
+
...d,
|
|
37
|
+
tooltip: {
|
|
38
|
+
...e,
|
|
39
|
+
render: (e) => S.current ? (s(() => w(e)), T) : null
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}, [
|
|
43
|
+
d,
|
|
44
|
+
E,
|
|
45
|
+
T
|
|
46
|
+
]), O = i(D);
|
|
47
|
+
return t(() => {
|
|
48
|
+
x.current = v, S.current = _;
|
|
49
|
+
}), t(() => {
|
|
50
|
+
let t = y.current;
|
|
51
|
+
if (!t) return;
|
|
52
|
+
let n = e(t, O.current);
|
|
53
|
+
b.current = n;
|
|
54
|
+
let r = [
|
|
55
|
+
n.on("hover", (e) => x.current.onHover?.(e)),
|
|
56
|
+
n.on("click", (e) => x.current.onClick?.(e)),
|
|
57
|
+
n.on("toggle", (e) => x.current.onToggle?.(e))
|
|
58
|
+
];
|
|
59
|
+
return () => {
|
|
60
|
+
r.forEach((e) => e()), n.destroy(), b.current = null;
|
|
61
|
+
};
|
|
62
|
+
}, []), t(() => {
|
|
63
|
+
O.current !== D && (O.current = D, b.current?.setOptions(D));
|
|
64
|
+
}, [D]), n(g, () => ({ getInstance: () => b.current }), []), /* @__PURE__ */ l("div", {
|
|
65
|
+
className: m,
|
|
66
|
+
style: {
|
|
67
|
+
position: "relative",
|
|
68
|
+
width: u(p, "100%"),
|
|
69
|
+
height: u(f, "320px"),
|
|
70
|
+
...h
|
|
71
|
+
},
|
|
72
|
+
children: [/* @__PURE__ */ c("div", {
|
|
73
|
+
ref: y,
|
|
74
|
+
style: {
|
|
75
|
+
position: "absolute",
|
|
76
|
+
inset: 0
|
|
77
|
+
}
|
|
78
|
+
}), T && C && _ && o(_(C), T)]
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function p(e) {
|
|
82
|
+
return /* @__PURE__ */ c(h, {
|
|
83
|
+
...e,
|
|
84
|
+
defaultInner: 0
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function m(e) {
|
|
88
|
+
return /* @__PURE__ */ c(h, {
|
|
89
|
+
...e,
|
|
90
|
+
defaultInner: .62
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function h(e) {
|
|
94
|
+
let { data: t, innerRadius: n, startAngle: i, padAngle: a, cornerRadius: o, rose: s, labels: l, labelContent: u, centerValue: f, centerLabel: p, defaultInner: m } = e, h = d(e), g = r(() => ({
|
|
95
|
+
...h,
|
|
96
|
+
type: "pie",
|
|
97
|
+
data: t,
|
|
98
|
+
innerRadius: n ?? m,
|
|
99
|
+
startAngle: i,
|
|
100
|
+
padAngle: a,
|
|
101
|
+
cornerRadius: o,
|
|
102
|
+
rose: s,
|
|
103
|
+
labels: l,
|
|
104
|
+
labelContent: u,
|
|
105
|
+
centerValue: f,
|
|
106
|
+
centerLabel: p
|
|
107
|
+
}), [
|
|
108
|
+
h,
|
|
109
|
+
t,
|
|
110
|
+
n,
|
|
111
|
+
m,
|
|
112
|
+
i,
|
|
113
|
+
a,
|
|
114
|
+
o,
|
|
115
|
+
s,
|
|
116
|
+
l,
|
|
117
|
+
u,
|
|
118
|
+
f,
|
|
119
|
+
p
|
|
120
|
+
]);
|
|
121
|
+
return /* @__PURE__ */ c(b, {
|
|
122
|
+
props: e,
|
|
123
|
+
options: g,
|
|
124
|
+
defaultHeight: 320
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function g(e) {
|
|
128
|
+
let { indicators: t, series: n, shape: i, levels: a, dots: o } = e, s = d(e), l = r(() => ({
|
|
129
|
+
...s,
|
|
130
|
+
type: "radar",
|
|
131
|
+
indicators: t,
|
|
132
|
+
series: n,
|
|
133
|
+
shape: i,
|
|
134
|
+
levels: a,
|
|
135
|
+
dots: o
|
|
136
|
+
}), [
|
|
137
|
+
s,
|
|
138
|
+
t,
|
|
139
|
+
n,
|
|
140
|
+
i,
|
|
141
|
+
a,
|
|
142
|
+
o
|
|
143
|
+
]);
|
|
144
|
+
return /* @__PURE__ */ c(b, {
|
|
145
|
+
props: e,
|
|
146
|
+
options: l,
|
|
147
|
+
defaultHeight: 320
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function _(e) {
|
|
151
|
+
let { value: t, min: n, max: i, label: a, sweep: o, thickness: s, bands: l, color: u, needle: f, ticks: p } = e, m = d(e), h = r(() => ({
|
|
152
|
+
...m,
|
|
153
|
+
type: "gauge",
|
|
154
|
+
value: t,
|
|
155
|
+
min: n,
|
|
156
|
+
max: i,
|
|
157
|
+
label: a,
|
|
158
|
+
sweep: o,
|
|
159
|
+
thickness: s,
|
|
160
|
+
bands: l,
|
|
161
|
+
color: u,
|
|
162
|
+
needle: f,
|
|
163
|
+
ticks: p
|
|
164
|
+
}), [
|
|
165
|
+
m,
|
|
166
|
+
t,
|
|
167
|
+
n,
|
|
168
|
+
i,
|
|
169
|
+
a,
|
|
170
|
+
o,
|
|
171
|
+
s,
|
|
172
|
+
l,
|
|
173
|
+
u,
|
|
174
|
+
f,
|
|
175
|
+
p
|
|
176
|
+
]);
|
|
177
|
+
return /* @__PURE__ */ c(b, {
|
|
178
|
+
props: e,
|
|
179
|
+
options: h,
|
|
180
|
+
defaultHeight: 240
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
function v(e) {
|
|
184
|
+
let { data: t, sort: n, gap: i, conversion: a, shape: o } = e, s = d(e), l = r(() => ({
|
|
185
|
+
...s,
|
|
186
|
+
type: "funnel",
|
|
187
|
+
data: t,
|
|
188
|
+
sort: n,
|
|
189
|
+
gap: i,
|
|
190
|
+
conversion: a,
|
|
191
|
+
shape: o
|
|
192
|
+
}), [
|
|
193
|
+
s,
|
|
194
|
+
t,
|
|
195
|
+
n,
|
|
196
|
+
i,
|
|
197
|
+
a,
|
|
198
|
+
o
|
|
199
|
+
]);
|
|
200
|
+
return /* @__PURE__ */ c(b, {
|
|
201
|
+
props: e,
|
|
202
|
+
options: l,
|
|
203
|
+
defaultHeight: 320
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
function y(e) {
|
|
207
|
+
let { data: t, gap: n, headers: i } = e, a = d(e), o = r(() => ({
|
|
208
|
+
...a,
|
|
209
|
+
type: "treemap",
|
|
210
|
+
data: t,
|
|
211
|
+
gap: n,
|
|
212
|
+
headers: i
|
|
213
|
+
}), [
|
|
214
|
+
a,
|
|
215
|
+
t,
|
|
216
|
+
n,
|
|
217
|
+
i
|
|
218
|
+
]);
|
|
219
|
+
return /* @__PURE__ */ c(b, {
|
|
220
|
+
props: e,
|
|
221
|
+
options: o,
|
|
222
|
+
defaultHeight: 320
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
function b({ props: e, options: t, defaultHeight: n }) {
|
|
226
|
+
return /* @__PURE__ */ c(f, {
|
|
227
|
+
options: t,
|
|
228
|
+
height: e.height ?? n,
|
|
229
|
+
width: e.width,
|
|
230
|
+
className: e.className,
|
|
231
|
+
style: e.style,
|
|
232
|
+
handleRef: e.ref,
|
|
233
|
+
onHover: e.onHover,
|
|
234
|
+
onClick: e.onClick,
|
|
235
|
+
onToggle: e.onToggle,
|
|
236
|
+
renderTooltip: e.renderTooltip
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
//#endregion
|
|
240
|
+
export { m as DonutChart, v as FunnelChart, _ as GaugeChart, p as PieChart, g as RadarChart, y as TreemapChart };
|
|
241
|
+
|
|
242
|
+
//# sourceMappingURL=shapes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shapes.js","names":["size","value","fallback","useCommonOptions","hiddenKey","hidden","stableHidden","useMemo","palette","legend","tooltip","format","percentFormat","animation","padding","ariaLabel","ShapeChartBase","handlers","containerRef","useRef","chartRef","handlersRef","tooltipRef","renderTooltip","tipEvent","setTipEvent","useState","tipHost","customTooltip","resolved","options","base","flushSync","event","optionsRef","useEffect","container","chart","createShapeChart","offs","off","useImperativeHandle","handleRef","width","height","style","createPortal","PieChart","PieBase","props","DonutChart","common","innerRadius","defaultInner","data","startAngle","padAngle","cornerRadius","rose","labels","labelContent","centerValue","centerLabel","ShapeHost","RadarChart","indicators","series","shape","levels","dots","GaugeChart","min","max","label","sweep","thickness","bands","color","needle","ticks","FunnelChart","sort","gap","conversion","TreemapChart","headers","defaultHeight"],"sources":["../../../../charts/src/react/shapes.tsx"],"sourcesContent":["import {\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n type CSSProperties,\n type ReactNode,\n type Ref,\n} from \"react\";\nimport { createPortal, flushSync } from \"react-dom\";\nimport type { ChartPadding } from \"../engine/types\";\nimport { createShapeChart } from \"../engine/shapes/chart\";\nimport type {\n FunnelChartOptions,\n GaugeBand,\n GaugeChartOptions,\n PieChartOptions,\n RadarChartOptions,\n RadarIndicator,\n RadarSeries,\n ShapeChartCommonOptions,\n ShapeChartInstance,\n ShapeChartOptions,\n ShapeDatum,\n ShapeHoverEvent,\n ShapeLegendOptions,\n ShapeToggleEvent,\n ShapeTooltipOptions,\n TreemapChartOptions,\n TreemapNode,\n} from \"../engine/shapes/types\";\n\n/** Imperative handle of the shape chart components (`ref`) */\nexport interface ShapeChartHandle {\n /** The underlying engine instance (minerva-design/charts/core) */\n getInstance(): ShapeChartInstance | null;\n}\n\n/** Props shared by PieChart, DonutChart, RadarChart, GaugeChart, FunnelChart and TreemapChart */\nexport interface ShapeChartCommonProps {\n /**\n * Height of the chart (the legend included); numbers are pixels\n * @default 320 (GaugeChart: 240)\n */\n height?: number | string;\n /**\n * Width of the chart; numbers are pixels\n * @default \"100%\"\n */\n width?: number | string;\n /** Colors of the marks without `color` (defaults to the `--chart-series-1..8` CSS variables, then the theme colors) */\n palette?: readonly string[];\n /**\n * Legend; clicking an item hides / shows its slice, stage or series\n * @default shown for pie, donut, funnel and multi-series radar charts\n */\n legend?: boolean | ShapeLegendOptions;\n /**\n * Tooltip; `false` disables it\n * @default true\n */\n tooltip?: boolean | ShapeTooltipOptions;\n /**\n * Formats the values of the labels and the tooltip\n * @default compact numbers (1.2k, 3.4M)\n */\n format?: (value: number) => string;\n /**\n * Formats the shares (labels, conversion rates, tooltip); `share` is 0-1\n * @default one decimal, e.g. \"40.0%\"\n */\n percentFormat?: (share: number) => string;\n /**\n * Hidden slices / stages / radar series / top-level treemap nodes, by\n * index. Makes the visibility controlled: legend clicks then only call\n * `onToggle`, whose `hiddenIndexes` should be stored and passed back.\n * Leave undefined to let the legend hide / show entries by itself.\n */\n hidden?: readonly number[];\n /**\n * Called when a legend item is clicked (or the instance's `toggle()` is\n * called), with the toggled index and every hidden index after the toggle\n */\n onToggle?: (event: ShapeToggleEvent) => void;\n /**\n * Entry and update animations (skipped when the user prefers reduced motion)\n * @default true\n */\n animation?: boolean;\n /**\n * Space around the drawing, in pixels\n * @default 8 on every side\n */\n padding?: ChartPadding;\n /**\n * Accessible name of the chart\n * @default the chart type, e.g. \"Donut chart\"\n */\n ariaLabel?: string;\n /** Called when the hovered (or keyboard-focused) mark changes */\n onHover?: (event: ShapeHoverEvent | null) => void;\n /** Called when a mark is clicked, tapped or activated with Enter */\n onClick?: (event: ShapeHoverEvent) => void;\n /** React content of the tooltip (replaces the default content) */\n renderTooltip?: (event: ShapeHoverEvent) => ReactNode;\n /** Additional class name of the root element */\n className?: string;\n /** Inline styles of the root element */\n style?: CSSProperties;\n /** Imperative handle */\n ref?: Ref<ShapeChartHandle>;\n}\n\n/** Props of PieChart */\nexport interface PieChartProps extends ShapeChartCommonProps {\n /** Slices: a name, a value (negative values count as 0) and an optional color */\n data: readonly ShapeDatum[];\n /**\n * Inner radius as a fraction of the outer radius: 0 = pie, 0.6 = donut\n * @default 0\n */\n innerRadius?: number;\n /**\n * Angle of the first slice, degrees clockwise from 12 o'clock\n * @default 0\n */\n startAngle?: number;\n /**\n * Gap between the slices, in pixels\n * @default 1 (pie), 2 (donut)\n */\n padAngle?: number;\n /**\n * Corner radius of the slices, in pixels\n * @default 0 (pie), 4 (donut)\n */\n cornerRadius?: number;\n /**\n * Nightingale rose: the radius (instead of the angle) shows the value\n * @default false\n */\n rose?: boolean;\n /**\n * Slice labels: `outside` with leader lines, `inside` the slices, or none\n * @default \"outside\" (up to 12 slices), \"none\" otherwise\n */\n labels?: \"outside\" | \"inside\" | \"none\";\n /**\n * What a label shows: name, value, percent (combinable)\n * @default [\"name\", \"percent\"]\n */\n labelContent?: readonly (\"name\" | \"value\" | \"percent\")[];\n /** Big text in the hole of a donut (e.g. the total) */\n centerValue?: string;\n /** Small text under `centerValue` */\n centerLabel?: string;\n}\n\n/** Props of DonutChart: a PieChart with a hole */\nexport interface DonutChartProps extends PieChartProps {\n /**\n * Inner radius as a fraction of the outer radius\n * @default 0.62\n */\n innerRadius?: number;\n}\n\n/** Props of RadarChart */\nexport interface RadarChartProps extends ShapeChartCommonProps {\n /** Axes of the chart, clockwise from 12 o'clock */\n indicators: readonly RadarIndicator[];\n /** Polygons: one value per indicator */\n series: readonly RadarSeries[];\n /**\n * Grid shape\n * @default \"polygon\"\n */\n shape?: \"polygon\" | \"circle\";\n /**\n * Number of grid rings\n * @default 4\n */\n levels?: number;\n /**\n * Dots on the vertices\n * @default true\n */\n dots?: boolean;\n}\n\n/** Props of GaugeChart */\nexport interface GaugeChartProps extends ShapeChartCommonProps {\n /** Value shown by the arc (clamped to `min` - `max` for the drawing) */\n value: number;\n /**\n * Value at the start of the arc\n * @default 0\n */\n min?: number;\n /**\n * Value at the end of the arc\n * @default 100\n */\n max?: number;\n /** Caption under the value */\n label?: string;\n /**\n * Total angle of the arc, degrees\n * @default 240\n */\n sweep?: number;\n /**\n * Thickness of the arc as a fraction of the radius\n * @default 0.16\n */\n thickness?: number;\n /** Colored ranges of the track; the value arc takes the color of its band */\n bands?: readonly GaugeBand[];\n /**\n * Color of the value arc (when there are no bands)\n * @default the first palette color\n */\n color?: string;\n /**\n * Draws a needle in addition to the value arc\n * @default false\n */\n needle?: boolean;\n /**\n * Tick labels at the ends (and at the band bounds)\n * @default true\n */\n ticks?: boolean;\n}\n\n/** Props of FunnelChart */\nexport interface FunnelChartProps extends ShapeChartCommonProps {\n /** Stages: a name, a value and an optional color */\n data: readonly ShapeDatum[];\n /**\n * Order of the stages\n * @default \"none\" (data order)\n */\n sort?: \"descending\" | \"ascending\" | \"none\";\n /**\n * Vertical gap between the stages, in pixels\n * @default 4\n */\n gap?: number;\n /**\n * Shows the conversion rate from the previous stage\n * @default true\n */\n conversion?: boolean;\n /**\n * Shape of the stages: trapezoids that narrow to the next stage, or centered bars\n * @default \"trapezoid\"\n */\n shape?: \"trapezoid\" | \"bar\";\n}\n\n/** Props of TreemapChart */\nexport interface TreemapChartProps extends ShapeChartCommonProps {\n /** Nodes: leaves carry a value, parents sum their children */\n data: readonly TreemapNode[];\n /**\n * Gap between the cells, in pixels\n * @default 2\n */\n gap?: number;\n /**\n * Draws the names of the parents above their children\n * @default true\n */\n headers?: boolean;\n}\n\ninterface Handlers {\n onHover?: (event: ShapeHoverEvent | null) => void;\n onClick?: (event: ShapeHoverEvent) => void;\n onToggle?: (event: ShapeToggleEvent) => void;\n}\n\ninterface ShapeChartBaseProps extends Handlers {\n options: ShapeChartOptions;\n height: number | string;\n width?: number | string;\n className?: string;\n style?: CSSProperties;\n handleRef?: Ref<ShapeChartHandle>;\n renderTooltip?: (event: ShapeHoverEvent) => ReactNode;\n}\n\nconst size = (value: number | string | undefined, fallback: string) =>\n value === undefined\n ? fallback\n : typeof value === \"number\"\n ? `${value}px`\n : value;\n\n/** Engine options shared by every type, stable while the props are equal */\nconst useCommonOptions = ({\n palette,\n legend,\n tooltip,\n format,\n percentFormat,\n hidden,\n animation,\n padding,\n ariaLabel,\n}: ShapeChartCommonProps): ShapeChartCommonOptions => {\n // a new array with the same indexes keeps the options (and the animation)\n const hiddenKey = hidden ? hidden.join(\",\") : null;\n const stableHidden = useMemo(\n () =>\n hiddenKey === null\n ? undefined\n : hiddenKey\n ? hiddenKey.split(\",\").map(Number)\n : [],\n [hiddenKey],\n );\n return useMemo(\n () => ({\n palette,\n legend,\n tooltip,\n format,\n percentFormat,\n hidden: stableHidden,\n animation,\n padding,\n ariaLabel,\n }),\n [\n palette,\n legend,\n tooltip,\n format,\n percentFormat,\n stableHidden,\n animation,\n padding,\n ariaLabel,\n ],\n );\n};\n\n/** Mounts the engine in a sized <div> and forwards option / handler changes */\nfunction ShapeChartBase({\n options,\n height,\n width,\n className,\n style,\n handleRef,\n renderTooltip,\n ...handlers\n}: ShapeChartBaseProps) {\n const containerRef = useRef<HTMLDivElement>(null);\n const chartRef = useRef<ShapeChartInstance | null>(null);\n const handlersRef = useRef<Handlers>(handlers);\n const tooltipRef = useRef(renderTooltip);\n const [tipEvent, setTipEvent] = useState<ShapeHoverEvent | null>(null);\n const tipHost = useMemo(\n () =>\n typeof document === \"undefined\" ? null : document.createElement(\"div\"),\n [],\n );\n const customTooltip = !!renderTooltip;\n\n const resolved = useMemo((): ShapeChartOptions => {\n if (!customTooltip || !tipHost || options.tooltip === false) return options;\n const base = typeof options.tooltip === \"object\" ? options.tooltip : {};\n return {\n ...options,\n tooltip: {\n ...base,\n render: (event) => {\n if (!tooltipRef.current) return null;\n // render synchronously so the engine measures the final size\n flushSync(() => setTipEvent(event));\n return tipHost;\n },\n },\n };\n }, [options, customTooltip, tipHost]);\n const optionsRef = useRef(resolved);\n\n useEffect(() => {\n handlersRef.current = handlers;\n tooltipRef.current = renderTooltip;\n });\n\n useEffect(() => {\n const container = containerRef.current;\n if (!container) return;\n const chart = createShapeChart(container, optionsRef.current);\n chartRef.current = chart;\n const offs = [\n chart.on(\"hover\", (e) => handlersRef.current.onHover?.(e)),\n chart.on(\"click\", (e) => handlersRef.current.onClick?.(e)),\n chart.on(\"toggle\", (e) => handlersRef.current.onToggle?.(e)),\n ];\n return () => {\n offs.forEach((off) => off());\n chart.destroy();\n chartRef.current = null;\n };\n }, []);\n\n useEffect(() => {\n if (optionsRef.current === resolved) return;\n optionsRef.current = resolved;\n chartRef.current?.setOptions(resolved);\n }, [resolved]);\n\n useImperativeHandle(\n handleRef,\n () => ({ getInstance: () => chartRef.current }),\n [],\n );\n\n return (\n <div\n className={className}\n style={{\n position: \"relative\",\n width: size(width, \"100%\"),\n height: size(height, \"320px\"),\n ...style,\n }}\n >\n <div ref={containerRef} style={{ position: \"absolute\", inset: 0 }} />\n {tipHost &&\n tipEvent &&\n renderTooltip &&\n createPortal(renderTooltip(tipEvent), tipHost)}\n </div>\n );\n}\n\n/**\n * Pie chart (or a donut with `innerRadius`, or a Nightingale rose with\n * `rose`): slices with gaps, outside labels with leader lines, legend toggles.\n */\nexport function PieChart(props: PieChartProps) {\n return <PieBase {...props} defaultInner={0} />;\n}\n\n/** Donut chart: a PieChart with a hole and optional center texts */\nexport function DonutChart(props: DonutChartProps) {\n return <PieBase {...props} defaultInner={0.62} />;\n}\n\nfunction PieBase(props: PieChartProps & { defaultInner: number }) {\n const {\n data,\n innerRadius,\n startAngle,\n padAngle,\n cornerRadius,\n rose,\n labels,\n labelContent,\n centerValue,\n centerLabel,\n defaultInner,\n } = props;\n const common = useCommonOptions(props);\n const options = useMemo(\n (): PieChartOptions => ({\n ...common,\n type: \"pie\",\n data,\n innerRadius: innerRadius ?? defaultInner,\n startAngle,\n padAngle,\n cornerRadius,\n rose,\n labels,\n labelContent,\n centerValue,\n centerLabel,\n }),\n [\n common,\n data,\n innerRadius,\n defaultInner,\n startAngle,\n padAngle,\n cornerRadius,\n rose,\n labels,\n labelContent,\n centerValue,\n centerLabel,\n ],\n );\n return <ShapeHost props={props} options={options} defaultHeight={320} />;\n}\n\n/** Radar (spider) chart comparing series over several indicators */\nexport function RadarChart(props: RadarChartProps) {\n const { indicators, series, shape, levels, dots } = props;\n const common = useCommonOptions(props);\n const options = useMemo(\n (): RadarChartOptions => ({\n ...common,\n type: \"radar\",\n indicators,\n series,\n shape,\n levels,\n dots,\n }),\n [common, indicators, series, shape, levels, dots],\n );\n return <ShapeHost props={props} options={options} defaultHeight={320} />;\n}\n\n/** Gauge (speedometer) showing one value on an arc, with colored bands */\nexport function GaugeChart(props: GaugeChartProps) {\n const {\n value,\n min,\n max,\n label,\n sweep,\n thickness,\n bands,\n color,\n needle,\n ticks,\n } = props;\n const common = useCommonOptions(props);\n const options = useMemo(\n (): GaugeChartOptions => ({\n ...common,\n type: \"gauge\",\n value,\n min,\n max,\n label,\n sweep,\n thickness,\n bands,\n color,\n needle,\n ticks,\n }),\n [\n common,\n value,\n min,\n max,\n label,\n sweep,\n thickness,\n bands,\n color,\n needle,\n ticks,\n ],\n );\n return <ShapeHost props={props} options={options} defaultHeight={240} />;\n}\n\n/** Funnel chart of the stages of a process, with conversion rates */\nexport function FunnelChart(props: FunnelChartProps) {\n const { data, sort, gap, conversion, shape } = props;\n const common = useCommonOptions(props);\n const options = useMemo(\n (): FunnelChartOptions => ({\n ...common,\n type: \"funnel\",\n data,\n sort,\n gap,\n conversion,\n shape,\n }),\n [common, data, sort, gap, conversion, shape],\n );\n return <ShapeHost props={props} options={options} defaultHeight={320} />;\n}\n\n/** Treemap: nested rectangles of areas proportional to the values */\nexport function TreemapChart(props: TreemapChartProps) {\n const { data, gap, headers } = props;\n const common = useCommonOptions(props);\n const options = useMemo(\n (): TreemapChartOptions => ({\n ...common,\n type: \"treemap\",\n data,\n gap,\n headers,\n }),\n [common, data, gap, headers],\n );\n return <ShapeHost props={props} options={options} defaultHeight={320} />;\n}\n\nfunction ShapeHost({\n props,\n options,\n defaultHeight,\n}: {\n props: ShapeChartCommonProps;\n options: ShapeChartOptions;\n defaultHeight: number;\n}) {\n return (\n <ShapeChartBase\n options={options}\n height={props.height ?? defaultHeight}\n width={props.width}\n className={props.className}\n style={props.style}\n handleRef={props.ref}\n onHover={props.onHover}\n onClick={props.onClick}\n onToggle={props.onToggle}\n renderTooltip={props.renderTooltip}\n />\n );\n}\n"],"mappings":";;;;;;AAsSA,IAAMA,KAAQ,GAAoC,MAChDC,MAAU,KAAA,IACNC,IACA,OAAOD,KAAU,WACf,GAAGA,EAAM,MACTA,GAGFE,KAAoB,EACxB,YACA,WACA,YACA,WACA,kBACA,WACA,cACA,YACA,mBACoD;CAEpD,IAAMC,IAAYC,IAASA,EAAO,KAAK,GAAG,IAAI,MACxCC,IAAeC,QAEjBH,MAAc,OACV,KAAA,IACAA,IACEA,EAAU,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM,IAC/B,CAAC,GACT,CAACA,CAAS,CACZ;CACA,OAAOG,SACE;EACL;EACA;EACA;EACA;EACA;EACA,QAAQD;EACR;EACA;EACA;CACF,IACA;EACEE;EACAC;EACAC;EACAC;EACAC;EACAN;EACAO;EACAC;EACAC;CACF,CACF;AACF;AAGA,SAASC,EAAe,EACtB,YACA,WACA,UACA,cACA,UACA,cACA,kBACA,GAAGC,KACmB;CACtB,IAAMC,IAAeC,EAAuB,IAAI,GAC1CC,IAAWD,EAAkC,IAAI,GACjDE,IAAcF,EAAiBF,CAAQ,GACvCK,IAAaH,EAAOI,CAAa,GACjC,CAACC,GAAUC,KAAeC,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A;AAEL"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CSSProperties, ReactNode, Ref } from 'react';
|
|
2
|
-
import { ChartAnnotation, ChartAxisOptions, ChartHoverEvent, ChartInstance, ChartLegendOptions, ChartInteractionOptions, ChartPadding, ChartPlotClickEvent, ChartRendererKind, ChartRendererPreference, ChartSeries, ChartTooltipOptions, ChartView } from '../engine/types.cjs';
|
|
3
|
-
import { QuadrantConfig, QuadrantCorner, QuadrantPoint } from '../engine/presets.cjs';
|
|
4
|
-
export type { QuadrantAxisLabels, QuadrantConfig, QuadrantCorner, QuadrantPoint, QuadrantRegion, QuadrantRegions, } from '../engine/presets.cjs';
|
|
2
|
+
import { ChartAnnotation, ChartAxisOptions, ChartCurve, ChartHoverEvent, ChartInstance, ChartLegendOptions, ChartInteractionOptions, ChartPadding, ChartPlotClickEvent, ChartRendererKind, ChartRendererPreference, ChartSeries, ChartTooltipOptions, ChartView } from '../engine/types.cjs';
|
|
3
|
+
import { HeatmapConfig, QuadrantConfig, QuadrantCorner, QuadrantPoint, SparklineConfig } from '../engine/presets.cjs';
|
|
4
|
+
export type { HeatmapCell, HeatmapConfig, QuadrantAxisLabels, QuadrantConfig, QuadrantCorner, QuadrantPoint, QuadrantRegion, QuadrantRegions, SparklineConfig, } from '../engine/presets.cjs';
|
|
5
5
|
/** Imperative handle of the chart components (`ref`) */
|
|
6
6
|
export interface ChartHandle {
|
|
7
7
|
/** Shows the whole data range */
|
|
@@ -74,10 +74,15 @@ export interface ChartCommonProps {
|
|
|
74
74
|
/** Imperative handle */
|
|
75
75
|
ref?: Ref<ChartHandle>;
|
|
76
76
|
}
|
|
77
|
-
/** Props of Chart: any mix of line, area, bar and
|
|
77
|
+
/** Props of Chart: any mix of line, area, bar, scatter, candlestick and heatmap series */
|
|
78
78
|
export interface ChartProps extends ChartCommonProps {
|
|
79
79
|
/** Data series; each sets its own `type` */
|
|
80
80
|
series: readonly ChartSeries[];
|
|
81
|
+
/**
|
|
82
|
+
* `percent` scales every stack to 100% at each x
|
|
83
|
+
* @default "normal"
|
|
84
|
+
*/
|
|
85
|
+
stackMode?: "normal" | "percent";
|
|
81
86
|
}
|
|
82
87
|
/** Props of LineChart */
|
|
83
88
|
export interface LineChartProps extends ChartCommonProps {
|
|
@@ -88,6 +93,41 @@ export interface LineChartProps extends ChartCommonProps {
|
|
|
88
93
|
* @default false
|
|
89
94
|
*/
|
|
90
95
|
area?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Shape of the lines: straight, smooth (monotone) or steps
|
|
98
|
+
* @default "linear"
|
|
99
|
+
*/
|
|
100
|
+
curve?: ChartCurve;
|
|
101
|
+
/**
|
|
102
|
+
* Stacks the series on top of each other
|
|
103
|
+
* @default false
|
|
104
|
+
*/
|
|
105
|
+
stacked?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Scales the stacks to 100% (with `stacked`)
|
|
108
|
+
* @default false
|
|
109
|
+
*/
|
|
110
|
+
percent?: boolean;
|
|
111
|
+
}
|
|
112
|
+
/** Props of AreaChart */
|
|
113
|
+
export interface AreaChartProps extends ChartCommonProps {
|
|
114
|
+
/** Series drawn as areas unless they set a `type` */
|
|
115
|
+
series: readonly ChartSeries[];
|
|
116
|
+
/**
|
|
117
|
+
* Shape of the edges: straight, smooth (monotone) or steps
|
|
118
|
+
* @default "smooth"
|
|
119
|
+
*/
|
|
120
|
+
curve?: ChartCurve;
|
|
121
|
+
/**
|
|
122
|
+
* Stacks the areas on top of each other
|
|
123
|
+
* @default false
|
|
124
|
+
*/
|
|
125
|
+
stacked?: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Scales the stacks to 100% (implies `stacked`)
|
|
128
|
+
* @default false
|
|
129
|
+
*/
|
|
130
|
+
percent?: boolean;
|
|
91
131
|
}
|
|
92
132
|
/** Props of BarChart */
|
|
93
133
|
export interface BarChartProps extends ChartCommonProps {
|
|
@@ -98,6 +138,35 @@ export interface BarChartProps extends ChartCommonProps {
|
|
|
98
138
|
* @default false
|
|
99
139
|
*/
|
|
100
140
|
stacked?: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Scales the stacks to 100% (implies `stacked`)
|
|
143
|
+
* @default false
|
|
144
|
+
*/
|
|
145
|
+
percent?: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Writes the value above every bar
|
|
148
|
+
* @default false
|
|
149
|
+
*/
|
|
150
|
+
labels?: boolean;
|
|
151
|
+
}
|
|
152
|
+
/** Props of CandlestickChart */
|
|
153
|
+
export interface CandlestickChartProps extends ChartCommonProps {
|
|
154
|
+
/**
|
|
155
|
+
* Series drawn as candles unless they set a `type` (e.g. a moving average
|
|
156
|
+
* `line`); data points carry `open`, `high`, `low` and `y` (the close)
|
|
157
|
+
*/
|
|
158
|
+
series: readonly ChartSeries[];
|
|
159
|
+
}
|
|
160
|
+
/** Props of HeatmapChart */
|
|
161
|
+
export interface HeatmapChartProps extends Omit<ChartCommonProps, "crosshair">, HeatmapConfig {
|
|
162
|
+
}
|
|
163
|
+
/** Props of Sparkline */
|
|
164
|
+
export interface SparklineProps extends Pick<ChartCommonProps, "width" | "renderer" | "tooltip" | "palette" | "ariaLabel" | "onHover" | "renderTooltip" | "className" | "style" | "ref">, SparklineConfig {
|
|
165
|
+
/**
|
|
166
|
+
* Height of the sparkline; numbers are pixels
|
|
167
|
+
* @default 48
|
|
168
|
+
*/
|
|
169
|
+
height?: number | string;
|
|
101
170
|
}
|
|
102
171
|
/** Props of ScatterChart */
|
|
103
172
|
export interface ScatterChartProps extends ChartCommonProps {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CSSProperties, ReactNode, Ref } from 'react';
|
|
2
|
-
import { ChartAnnotation, ChartAxisOptions, ChartHoverEvent, ChartInstance, ChartLegendOptions, ChartInteractionOptions, ChartPadding, ChartPlotClickEvent, ChartRendererKind, ChartRendererPreference, ChartSeries, ChartTooltipOptions, ChartView } from '../engine/types.js';
|
|
3
|
-
import { QuadrantConfig, QuadrantCorner, QuadrantPoint } from '../engine/presets.js';
|
|
4
|
-
export type { QuadrantAxisLabels, QuadrantConfig, QuadrantCorner, QuadrantPoint, QuadrantRegion, QuadrantRegions, } from '../engine/presets.js';
|
|
2
|
+
import { ChartAnnotation, ChartAxisOptions, ChartCurve, ChartHoverEvent, ChartInstance, ChartLegendOptions, ChartInteractionOptions, ChartPadding, ChartPlotClickEvent, ChartRendererKind, ChartRendererPreference, ChartSeries, ChartTooltipOptions, ChartView } from '../engine/types.js';
|
|
3
|
+
import { HeatmapConfig, QuadrantConfig, QuadrantCorner, QuadrantPoint, SparklineConfig } from '../engine/presets.js';
|
|
4
|
+
export type { HeatmapCell, HeatmapConfig, QuadrantAxisLabels, QuadrantConfig, QuadrantCorner, QuadrantPoint, QuadrantRegion, QuadrantRegions, SparklineConfig, } from '../engine/presets.js';
|
|
5
5
|
/** Imperative handle of the chart components (`ref`) */
|
|
6
6
|
export interface ChartHandle {
|
|
7
7
|
/** Shows the whole data range */
|
|
@@ -74,10 +74,15 @@ export interface ChartCommonProps {
|
|
|
74
74
|
/** Imperative handle */
|
|
75
75
|
ref?: Ref<ChartHandle>;
|
|
76
76
|
}
|
|
77
|
-
/** Props of Chart: any mix of line, area, bar and
|
|
77
|
+
/** Props of Chart: any mix of line, area, bar, scatter, candlestick and heatmap series */
|
|
78
78
|
export interface ChartProps extends ChartCommonProps {
|
|
79
79
|
/** Data series; each sets its own `type` */
|
|
80
80
|
series: readonly ChartSeries[];
|
|
81
|
+
/**
|
|
82
|
+
* `percent` scales every stack to 100% at each x
|
|
83
|
+
* @default "normal"
|
|
84
|
+
*/
|
|
85
|
+
stackMode?: "normal" | "percent";
|
|
81
86
|
}
|
|
82
87
|
/** Props of LineChart */
|
|
83
88
|
export interface LineChartProps extends ChartCommonProps {
|
|
@@ -88,6 +93,41 @@ export interface LineChartProps extends ChartCommonProps {
|
|
|
88
93
|
* @default false
|
|
89
94
|
*/
|
|
90
95
|
area?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Shape of the lines: straight, smooth (monotone) or steps
|
|
98
|
+
* @default "linear"
|
|
99
|
+
*/
|
|
100
|
+
curve?: ChartCurve;
|
|
101
|
+
/**
|
|
102
|
+
* Stacks the series on top of each other
|
|
103
|
+
* @default false
|
|
104
|
+
*/
|
|
105
|
+
stacked?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Scales the stacks to 100% (with `stacked`)
|
|
108
|
+
* @default false
|
|
109
|
+
*/
|
|
110
|
+
percent?: boolean;
|
|
111
|
+
}
|
|
112
|
+
/** Props of AreaChart */
|
|
113
|
+
export interface AreaChartProps extends ChartCommonProps {
|
|
114
|
+
/** Series drawn as areas unless they set a `type` */
|
|
115
|
+
series: readonly ChartSeries[];
|
|
116
|
+
/**
|
|
117
|
+
* Shape of the edges: straight, smooth (monotone) or steps
|
|
118
|
+
* @default "smooth"
|
|
119
|
+
*/
|
|
120
|
+
curve?: ChartCurve;
|
|
121
|
+
/**
|
|
122
|
+
* Stacks the areas on top of each other
|
|
123
|
+
* @default false
|
|
124
|
+
*/
|
|
125
|
+
stacked?: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Scales the stacks to 100% (implies `stacked`)
|
|
128
|
+
* @default false
|
|
129
|
+
*/
|
|
130
|
+
percent?: boolean;
|
|
91
131
|
}
|
|
92
132
|
/** Props of BarChart */
|
|
93
133
|
export interface BarChartProps extends ChartCommonProps {
|
|
@@ -98,6 +138,35 @@ export interface BarChartProps extends ChartCommonProps {
|
|
|
98
138
|
* @default false
|
|
99
139
|
*/
|
|
100
140
|
stacked?: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Scales the stacks to 100% (implies `stacked`)
|
|
143
|
+
* @default false
|
|
144
|
+
*/
|
|
145
|
+
percent?: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Writes the value above every bar
|
|
148
|
+
* @default false
|
|
149
|
+
*/
|
|
150
|
+
labels?: boolean;
|
|
151
|
+
}
|
|
152
|
+
/** Props of CandlestickChart */
|
|
153
|
+
export interface CandlestickChartProps extends ChartCommonProps {
|
|
154
|
+
/**
|
|
155
|
+
* Series drawn as candles unless they set a `type` (e.g. a moving average
|
|
156
|
+
* `line`); data points carry `open`, `high`, `low` and `y` (the close)
|
|
157
|
+
*/
|
|
158
|
+
series: readonly ChartSeries[];
|
|
159
|
+
}
|
|
160
|
+
/** Props of HeatmapChart */
|
|
161
|
+
export interface HeatmapChartProps extends Omit<ChartCommonProps, "crosshair">, HeatmapConfig {
|
|
162
|
+
}
|
|
163
|
+
/** Props of Sparkline */
|
|
164
|
+
export interface SparklineProps extends Pick<ChartCommonProps, "width" | "renderer" | "tooltip" | "palette" | "ariaLabel" | "onHover" | "renderTooltip" | "className" | "style" | "ref">, SparklineConfig {
|
|
165
|
+
/**
|
|
166
|
+
* Height of the sparkline; numbers are pixels
|
|
167
|
+
* @default 48
|
|
168
|
+
*/
|
|
169
|
+
height?: number | string;
|
|
101
170
|
}
|
|
102
171
|
/** Props of ScatterChart */
|
|
103
172
|
export interface ScatterChartProps extends ChartCommonProps {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=e=>e<0?0:e>1?1:e,t=e=>{let t=e.slice(1);if(!/^[0-9a-f]+$/i.test(t))return null;let n=t.length===3||t.length===4;if(!n&&t.length!==6&&t.length!==8)return null;let r=e=>n?parseInt(t[e]+t[e],16)/255:parseInt(t.slice(e*2,e*2+2),16)/255,i=t.length===4||t.length===8;return[r(0),r(1),r(2),i?r(3):1]},n=(e,t)=>{let n=parseFloat(e);return Number.isNaN(n)?0:e.trim().endsWith(`%`)?n/100:n/t},r=e=>{let[t,n]=e.split(`/`),r=t.split(/[\s,]+/).filter(Boolean);return n!==void 0&&r.push(n.trim()),r},i=i=>{let a=i.trim().toLowerCase();if(a.startsWith(`#`))return t(a);if(a===`transparent`)return[0,0,0,0];let o=/^rgba?\((.*)\)$/.exec(a);if(o){let t=r(o[1]);return t.length<3?null:[e(n(t[0],255)),e(n(t[1],255)),e(n(t[2],255)),t[3]===void 0?1:e(n(t[3],1))]}if(o=/^color\(srgb\s+(.*)\)$/.exec(a),o){let t=r(o[1]);return t.length<3?null:[e(n(t[0],1)),e(n(t[1],1)),e(n(t[2],1)),t[3]===void 0?1:e(n(t[3],1))]}return null},a=e=>{let t=/^var\(\s*(--[\w-]+)\s*(?:,([\s\S]*))?\)$/.exec(e.trim());if(!t)return null;let n=t[2]?.trim();return{name:t[1],...n?{fallback:n}:{}}},o=(e,t={},n=[.4,.4,.4,1],r=0)=>{let c=i(e);if(c)return c;let l=r<8?a(e):null;if(l){let e=t[l.name];if(e)return o(e,t,n,r+1);if(l.fallback)return o(l.fallback,t,n,r+1)}return s[e.trim().toLowerCase()]??n},s={black:[0,0,0,1],white:[1,1,1,1],red:[1,0,0,1],green:[0,128/255,0,1],blue:[0,0,1,1],gray:[128/255,128/255,128/255,1],grey:[128/255,128/255,128/255,1],orange:[1,165/255,0,1]},c=(e,t=1)=>`rgba(${Math.round(e[0]*255)}, ${Math.round(e[1]*255)}, ${Math.round(e[2]*255)}, ${+(e[3]*t).toFixed(3)})`,l=(e,t,n)=>[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n,e[3]+(t[3]-e[3])*n];exports.mix=l,exports.parseColor=i,exports.resolveStaticColor=o,exports.toCss=c;
|
|
1
|
+
var e=e=>e<0?0:e>1?1:e,t=e=>{let t=e.slice(1);if(!/^[0-9a-f]+$/i.test(t))return null;let n=t.length===3||t.length===4;if(!n&&t.length!==6&&t.length!==8)return null;let r=e=>n?parseInt(t[e]+t[e],16)/255:parseInt(t.slice(e*2,e*2+2),16)/255,i=t.length===4||t.length===8;return[r(0),r(1),r(2),i?r(3):1]},n=(e,t)=>{let n=parseFloat(e);return Number.isNaN(n)?0:e.trim().endsWith(`%`)?n/100:n/t},r=e=>{let[t,n]=e.split(`/`),r=t.split(/[\s,]+/).filter(Boolean);return n!==void 0&&r.push(n.trim()),r},i=i=>{let a=i.trim().toLowerCase();if(a.startsWith(`#`))return t(a);if(a===`transparent`)return[0,0,0,0];let o=/^rgba?\((.*)\)$/.exec(a);if(o){let t=r(o[1]);return t.length<3?null:[e(n(t[0],255)),e(n(t[1],255)),e(n(t[2],255)),t[3]===void 0?1:e(n(t[3],1))]}if(o=/^color\(srgb\s+(.*)\)$/.exec(a),o){let t=r(o[1]);return t.length<3?null:[e(n(t[0],1)),e(n(t[1],1)),e(n(t[2],1)),t[3]===void 0?1:e(n(t[3],1))]}return null},a=e=>{let t=/^var\(\s*(--[\w-]+)\s*(?:,([\s\S]*))?\)$/.exec(e.trim());if(!t)return null;let n=t[2]?.trim();return{name:t[1],...n?{fallback:n}:{}}},o=(e,t={},n=[.4,.4,.4,1],r=0)=>{let c=i(e);if(c)return c;let l=r<8?a(e):null;if(l){let e=t[l.name];if(e)return o(e,t,n,r+1);if(l.fallback)return o(l.fallback,t,n,r+1)}return s[e.trim().toLowerCase()]??n},s={black:[0,0,0,1],white:[1,1,1,1],red:[1,0,0,1],green:[0,128/255,0,1],blue:[0,0,1,1],gray:[128/255,128/255,128/255,1],grey:[128/255,128/255,128/255,1],orange:[1,165/255,0,1]},c=(e,t=1)=>`rgba(${Math.round(e[0]*255)}, ${Math.round(e[1]*255)}, ${Math.round(e[2]*255)}, ${+(e[3]*t).toFixed(3)})`,l=t=>(Math.round(e(t[3])*255)<<24|Math.round(e(t[2])*255)<<16|Math.round(e(t[1])*255)<<8|Math.round(e(t[0])*255))>>>0,u=(e,t,n)=>[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n,e[3]+(t[3]-e[3])*n],d=e=>[(e&255)/255,(e>>>8&255)/255,(e>>>16&255)/255,(e>>>24&255)/255],f=(t,n)=>{if(t.length===1)return t[0];let r=e(n)*(t.length-1),i=Math.min(t.length-2,Math.floor(r));return u(t[i],t[i+1],r-i)};exports.mix=u,exports.packColor=l,exports.parseColor=i,exports.rampColor=f,exports.resolveStaticColor=o,exports.toCss=c,exports.unpackColor=d;
|
|
2
2
|
//# sourceMappingURL=color.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color.cjs","names":["clamp01","v","parseHex","h","hex","expand","channel","i","hasAlpha","parseComponent","part","scale","splitArgs","main","alpha","args","parts","parseColor","value","input","match","parseVar","fallback","resolveStaticColor","direct","ref","depth","defined","variables","NAMED","toCss","c","mix","a","b","t"],"sources":["../../../../../../charts/src/engine/color.ts"],"sourcesContent":["// Color parsing to straight (non-premultiplied) RGBA in 0-1.\n\nexport type Rgba = readonly [number, number, number, number];\n\nconst clamp01 = (v: number) => (v < 0 ? 0 : v > 1 ? 1 : v);\n\nconst parseHex = (hex: string): Rgba | null => {\n const h = hex.slice(1);\n if (!/^[0-9a-f]+$/i.test(h)) return null;\n const expand = h.length === 3 || h.length === 4;\n if (!expand && h.length !== 6 && h.length !== 8) return null;\n const channel = (i: number) =>\n expand\n ? parseInt(h[i] + h[i], 16) / 255\n : parseInt(h.slice(i * 2, i * 2 + 2), 16) / 255;\n const hasAlpha = h.length === 4 || h.length === 8;\n return [channel(0), channel(1), channel(2), hasAlpha ? channel(3) : 1];\n};\n\nconst parseComponent = (part: string, scale: number): number => {\n const v = parseFloat(part);\n if (Number.isNaN(v)) return 0;\n return part.trim().endsWith(\"%\") ? v / 100 : v / scale;\n};\n\n/** Splits `a b c / d` or `a, b, c, d` */\nconst splitArgs = (args: string): string[] => {\n const [main, alpha] = args.split(\"/\");\n const parts = main.split(/[\\s,]+/).filter(Boolean);\n if (alpha !== undefined) parts.push(alpha.trim());\n return parts;\n};\n\n/**\n * Parses the color syntaxes returned by `getComputedStyle` (`rgb()`,\n * `rgba()`, `color(srgb ...)`) and hex colors; `null` for anything else\n * (named colors, `oklch()`, ... are resolved by `resolveColor`).\n */\nexport const parseColor = (input: string): Rgba | null => {\n const value = input.trim().toLowerCase();\n if (value.startsWith(\"#\")) return parseHex(value);\n if (value === \"transparent\") return [0, 0, 0, 0];\n let match = /^rgba?\\((.*)\\)$/.exec(value);\n if (match) {\n const parts = splitArgs(match[1]);\n if (parts.length < 3) return null;\n return [\n clamp01(parseComponent(parts[0], 255)),\n clamp01(parseComponent(parts[1], 255)),\n clamp01(parseComponent(parts[2], 255)),\n parts[3] === undefined ? 1 : clamp01(parseComponent(parts[3], 1)),\n ];\n }\n match = /^color\\(srgb\\s+(.*)\\)$/.exec(value);\n if (match) {\n const parts = splitArgs(match[1]);\n if (parts.length < 3) return null;\n return [\n clamp01(parseComponent(parts[0], 1)),\n clamp01(parseComponent(parts[1], 1)),\n clamp01(parseComponent(parts[2], 1)),\n parts[3] === undefined ? 1 : clamp01(parseComponent(parts[3], 1)),\n ];\n }\n return null;\n};\n\nlet probeContext: CanvasRenderingContext2D | null | undefined;\n\n/** Lets the browser convert any CSS color (named, hsl, oklch, color-mix, ...) */\nconst parseWithCanvas = (value: string): Rgba | null => {\n if (typeof document === \"undefined\") return null;\n if (probeContext === undefined) {\n const canvas = document.createElement(\"canvas\");\n canvas.width = 1;\n canvas.height = 1;\n probeContext = canvas.getContext(\"2d\", { willReadFrequently: true });\n }\n const ctx = probeContext;\n if (!ctx) return null;\n ctx.clearRect(0, 0, 1, 1);\n ctx.fillStyle = \"#000\";\n ctx.fillStyle = value;\n ctx.fillRect(0, 0, 1, 1);\n const [r, g, b, a] = ctx.getImageData(0, 0, 1, 1).data;\n if (a === 0) return [0, 0, 0, 0];\n // getImageData returns premultiplied-then-unpremultiplied values\n return [r / 255, g / 255, b / 255, a / 255];\n};\n\n/**\n * Resolves a CSS color in the context of `element`: `var(--x)`,\n * `color-mix()`, named colors, ... Falls back to `fallback` when the color\n * cannot be resolved (e.g. outside a browser).\n */\nexport const resolveColor = (\n value: string,\n element: Element | null,\n fallback: Rgba = [0.4, 0.4, 0.4, 1],\n): Rgba => {\n const direct = parseColor(value);\n if (direct) return direct;\n let computed = value;\n if (element && typeof getComputedStyle === \"function\") {\n const probe = element.ownerDocument.createElement(\"span\");\n probe.style.display = \"none\";\n probe.style.color = value;\n element.appendChild(probe);\n computed = getComputedStyle(probe).color || value;\n probe.remove();\n const parsed = parseColor(computed);\n if (parsed) return parsed;\n }\n return parseWithCanvas(computed) ?? resolveStaticColor(value, {}, fallback);\n};\n\n/** Resolves a color to RGBA, falling back to `fallback` */\nexport type ColorResolver = (value: string, fallback: Rgba) => Rgba;\n\n/** Splits the arguments of `var(--name, fallback)` (the fallback may contain commas) */\nconst parseVar = (\n value: string,\n): { name: string; fallback?: string } | null => {\n const match = /^var\\(\\s*(--[\\w-]+)\\s*(?:,([\\s\\S]*))?\\)$/.exec(value.trim());\n if (!match) return null;\n const fallback = match[2]?.trim();\n return { name: match[1], ...(fallback ? { fallback } : {}) };\n};\n\n/**\n * Resolves a color without a DOM (mini-programs, React Native, workers):\n * hex, `rgb()`, `transparent` and `var(--name, fallback)` looked up in\n * `variables` (nested fallbacks included).\n */\nexport const resolveStaticColor = (\n value: string,\n variables: Readonly<Record<string, string>> = {},\n fallback: Rgba = [0.4, 0.4, 0.4, 1],\n depth = 0,\n): Rgba => {\n const direct = parseColor(value);\n if (direct) return direct;\n const ref = depth < 8 ? parseVar(value) : null;\n if (ref) {\n const defined = variables[ref.name];\n if (defined)\n return resolveStaticColor(defined, variables, fallback, depth + 1);\n if (ref.fallback)\n return resolveStaticColor(ref.fallback, variables, fallback, depth + 1);\n }\n return NAMED[value.trim().toLowerCase()] ?? fallback;\n};\n\nconst NAMED: Record<string, Rgba> = {\n black: [0, 0, 0, 1],\n white: [1, 1, 1, 1],\n red: [1, 0, 0, 1],\n green: [0, 128 / 255, 0, 1],\n blue: [0, 0, 1, 1],\n gray: [128 / 255, 128 / 255, 128 / 255, 1],\n grey: [128 / 255, 128 / 255, 128 / 255, 1],\n orange: [1, 165 / 255, 0, 1],\n};\n\n/** Resolver of the DOM: CSS variables and any CSS color syntax of `element` */\nexport const domColorResolver =\n (element: Element | null): ColorResolver =>\n (value, fallback) =>\n resolveColor(value, element, fallback);\n\nconst hex2 = (v: number) =>\n Math.round(clamp01(v) * 255)\n .toString(16)\n .padStart(2, \"0\");\n\n/** `rgba()` string usable by Canvas2D and the DOM */\nexport const toCss = (c: Rgba, alpha = 1): string =>\n `rgba(${Math.round(c[0] * 255)}, ${Math.round(c[1] * 255)}, ${Math.round(c[2] * 255)}, ${+(c[3] * alpha).toFixed(3)})`;\n\n/** `#rrggbb` (alpha dropped) */\nexport const toHex = (c: Rgba): string =>\n `#${hex2(c[0])}${hex2(c[1])}${hex2(c[2])}`;\n\n/** Packs a color as little-endian `unorm8x4` (r in the lowest byte) */\nexport const packColor = (c: Rgba): number =>\n ((Math.round(clamp01(c[3]) * 255) << 24) |\n (Math.round(clamp01(c[2]) * 255) << 16) |\n (Math.round(clamp01(c[1]) * 255) << 8) |\n Math.round(clamp01(c[0]) * 255)) >>>\n 0;\n\n/** Mixes two colors (t = 0 -> a, 1 -> b) */\nexport const mix = (a: Rgba, b: Rgba, t: number): Rgba => [\n a[0] + (b[0] - a[0]) * t,\n a[1] + (b[1] - a[1]) * t,\n a[2] + (b[2] - a[2]) * t,\n a[3] + (b[3] - a[3]) * t,\n];\n\n/** Relative luminance (sRGB approximation) */\nexport const luminance = (c: Rgba): number =>\n 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2];\n"],"mappings":"AAIA,IAAMA,EAAW,GAAeC,EAAI,EAAI,EAAIA,EAAI,EAAI,EAAIA,EAElDC,EAAY,GAA6B,CAC7C,IAAMC,EAAIC,EAAI,MAAM,CAAC,EACrB,GAAI,CAAC,eAAe,KAAKD,CAAC,EAAG,OAAO,KACpC,IAAME,EAASF,EAAE,SAAW,GAAKA,EAAE,SAAW,EAC9C,GAAI,CAACE,GAAUF,EAAE,SAAW,GAAKA,EAAE,SAAW,EAAG,OAAO,KACxD,IAAMG,EAAW,GACfD,EACI,SAASF,EAAEI,GAAKJ,EAAEI,GAAI,EAAE,EAAI,IAC5B,SAASJ,EAAE,MAAMI,EAAI,EAAGA,EAAI,EAAI,CAAC,EAAG,EAAE,EAAI,IAC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AAK,IAAM,IAAK,CAAC,EACzC,KAAM,CAAC,IAAM,IAAK,IAAM,IAAK,IAAM,IAAK,CAAC,EACzC,OAAQ,CAAC,EAAG,IAAM,IAAK,EAAG,CAAC,CAC7B,EAcaC,GAAS,EAAS,EAAQ,IACrC,QAAQ,KAAK,MAAMC,EAAE,GAAK,GAAG,EAAE,IAAI,KAAK,MAAMA,EAAE,GAAK,GAAG,EAAE,IAAI,KAAK,MAAMA,EAAE,GAAK,GAAG,EAAE,IAAI,EAAEA,EAAE,GAAKjB,EAAA,CAAO,QAAQ,CAAC,EAAE,GAezGkB,GAAO,EAAS,EAAS,IAAoB,CACxDC,EAAE,IAAMC,EAAE,GAAKD,EAAE,IAAME,EACvBF,EAAE,IAAMC,EAAE,GAAKD,EAAE,IAAME,EACvBF,EAAE,IAAMC,EAAE,GAAKD,EAAE,IAAME,EACvBF,EAAE,IAAMC,EAAE,GAAKD,EAAE,IAAME,CACzB"}
|
|
1
|
+
{"version":3,"file":"color.cjs","names":["clamp01","v","parseHex","h","hex","expand","channel","i","hasAlpha","parseComponent","part","scale","splitArgs","main","alpha","args","parts","parseColor","value","input","match","parseVar","fallback","resolveStaticColor","direct","ref","depth","defined","variables","NAMED","toCss","c","packColor","mix","a","b","t","unpackColor","packed","rampColor","stops","p"],"sources":["../../../../../../charts/src/engine/color.ts"],"sourcesContent":["// Color parsing to straight (non-premultiplied) RGBA in 0-1.\n\nexport type Rgba = readonly [number, number, number, number];\n\nconst clamp01 = (v: number) => (v < 0 ? 0 : v > 1 ? 1 : v);\n\nconst parseHex = (hex: string): Rgba | null => {\n const h = hex.slice(1);\n if (!/^[0-9a-f]+$/i.test(h)) return null;\n const expand = h.length === 3 || h.length === 4;\n if (!expand && h.length !== 6 && h.length !== 8) return null;\n const channel = (i: number) =>\n expand\n ? parseInt(h[i] + h[i], 16) / 255\n : parseInt(h.slice(i * 2, i * 2 + 2), 16) / 255;\n const hasAlpha = h.length === 4 || h.length === 8;\n return [channel(0), channel(1), channel(2), hasAlpha ? channel(3) : 1];\n};\n\nconst parseComponent = (part: string, scale: number): number => {\n const v = parseFloat(part);\n if (Number.isNaN(v)) return 0;\n return part.trim().endsWith(\"%\") ? v / 100 : v / scale;\n};\n\n/** Splits `a b c / d` or `a, b, c, d` */\nconst splitArgs = (args: string): string[] => {\n const [main, alpha] = args.split(\"/\");\n const parts = main.split(/[\\s,]+/).filter(Boolean);\n if (alpha !== undefined) parts.push(alpha.trim());\n return parts;\n};\n\n/**\n * Parses the color syntaxes returned by `getComputedStyle` (`rgb()`,\n * `rgba()`, `color(srgb ...)`) and hex colors; `null` for anything else\n * (named colors, `oklch()`, ... are resolved by `resolveColor`).\n */\nexport const parseColor = (input: string): Rgba | null => {\n const value = input.trim().toLowerCase();\n if (value.startsWith(\"#\")) return parseHex(value);\n if (value === \"transparent\") return [0, 0, 0, 0];\n let match = /^rgba?\\((.*)\\)$/.exec(value);\n if (match) {\n const parts = splitArgs(match[1]);\n if (parts.length < 3) return null;\n return [\n clamp01(parseComponent(parts[0], 255)),\n clamp01(parseComponent(parts[1], 255)),\n clamp01(parseComponent(parts[2], 255)),\n parts[3] === undefined ? 1 : clamp01(parseComponent(parts[3], 1)),\n ];\n }\n match = /^color\\(srgb\\s+(.*)\\)$/.exec(value);\n if (match) {\n const parts = splitArgs(match[1]);\n if (parts.length < 3) return null;\n return [\n clamp01(parseComponent(parts[0], 1)),\n clamp01(parseComponent(parts[1], 1)),\n clamp01(parseComponent(parts[2], 1)),\n parts[3] === undefined ? 1 : clamp01(parseComponent(parts[3], 1)),\n ];\n }\n return null;\n};\n\nlet probeContext: CanvasRenderingContext2D | null | undefined;\n\n/** Lets the browser convert any CSS color (named, hsl, oklch, color-mix, ...) */\nconst parseWithCanvas = (value: string): Rgba | null => {\n if (typeof document === \"undefined\") return null;\n if (probeContext === undefined) {\n const canvas = document.createElement(\"canvas\");\n canvas.width = 1;\n canvas.height = 1;\n probeContext = canvas.getContext(\"2d\", { willReadFrequently: true });\n }\n const ctx = probeContext;\n if (!ctx) return null;\n ctx.clearRect(0, 0, 1, 1);\n ctx.fillStyle = \"#000\";\n ctx.fillStyle = value;\n ctx.fillRect(0, 0, 1, 1);\n const [r, g, b, a] = ctx.getImageData(0, 0, 1, 1).data;\n if (a === 0) return [0, 0, 0, 0];\n // getImageData returns premultiplied-then-unpremultiplied values\n return [r / 255, g / 255, b / 255, a / 255];\n};\n\n/**\n * Resolves a CSS color in the context of `element`: `var(--x)`,\n * `color-mix()`, named colors, ... Falls back to `fallback` when the color\n * cannot be resolved (e.g. outside a browser).\n */\nexport const resolveColor = (\n value: string,\n element: Element | null,\n fallback: Rgba = [0.4, 0.4, 0.4, 1],\n): Rgba => {\n const direct = parseColor(value);\n if (direct) return direct;\n let computed = value;\n if (element && typeof getComputedStyle === \"function\") {\n const probe = element.ownerDocument.createElement(\"span\");\n probe.style.display = \"none\";\n probe.style.color = value;\n element.appendChild(probe);\n computed = getComputedStyle(probe).color || value;\n probe.remove();\n const parsed = parseColor(computed);\n if (parsed) return parsed;\n }\n return parseWithCanvas(computed) ?? resolveStaticColor(value, {}, fallback);\n};\n\n/** Resolves a color to RGBA, falling back to `fallback` */\nexport type ColorResolver = (value: string, fallback: Rgba) => Rgba;\n\n/** Splits the arguments of `var(--name, fallback)` (the fallback may contain commas) */\nconst parseVar = (\n value: string,\n): { name: string; fallback?: string } | null => {\n const match = /^var\\(\\s*(--[\\w-]+)\\s*(?:,([\\s\\S]*))?\\)$/.exec(value.trim());\n if (!match) return null;\n const fallback = match[2]?.trim();\n return { name: match[1], ...(fallback ? { fallback } : {}) };\n};\n\n/**\n * Resolves a color without a DOM (mini-programs, React Native, workers):\n * hex, `rgb()`, `transparent` and `var(--name, fallback)` looked up in\n * `variables` (nested fallbacks included).\n */\nexport const resolveStaticColor = (\n value: string,\n variables: Readonly<Record<string, string>> = {},\n fallback: Rgba = [0.4, 0.4, 0.4, 1],\n depth = 0,\n): Rgba => {\n const direct = parseColor(value);\n if (direct) return direct;\n const ref = depth < 8 ? parseVar(value) : null;\n if (ref) {\n const defined = variables[ref.name];\n if (defined)\n return resolveStaticColor(defined, variables, fallback, depth + 1);\n if (ref.fallback)\n return resolveStaticColor(ref.fallback, variables, fallback, depth + 1);\n }\n return NAMED[value.trim().toLowerCase()] ?? fallback;\n};\n\nconst NAMED: Record<string, Rgba> = {\n black: [0, 0, 0, 1],\n white: [1, 1, 1, 1],\n red: [1, 0, 0, 1],\n green: [0, 128 / 255, 0, 1],\n blue: [0, 0, 1, 1],\n gray: [128 / 255, 128 / 255, 128 / 255, 1],\n grey: [128 / 255, 128 / 255, 128 / 255, 1],\n orange: [1, 165 / 255, 0, 1],\n};\n\n/** Resolver of the DOM: CSS variables and any CSS color syntax of `element` */\nexport const domColorResolver =\n (element: Element | null): ColorResolver =>\n (value, fallback) =>\n resolveColor(value, element, fallback);\n\n/** A resolver remembering its results; `null` marks unresolvable colors */\nexport interface MemoizedColorResolver extends ColorResolver {\n readonly cache: ReadonlyMap<string, Rgba | null>;\n}\n\nconst UNRESOLVED: Rgba = [NaN, NaN, NaN, NaN];\n\n/**\n * Caches the colors of `resolve` by input string (DOM probes force a style\n * recalculation). `resolve` must return `fallback` itself when it cannot\n * resolve a color, as the resolvers of this module do. Create a new one to\n * invalidate it (e.g. when the theme changes).\n */\nexport const memoizeColorResolver = (\n resolve: ColorResolver,\n): MemoizedColorResolver => {\n const cache = new Map<string, Rgba | null>();\n const memoized = (value: string, fallback: Rgba): Rgba => {\n let hit = cache.get(value);\n if (hit === undefined) {\n const resolved = resolve(value, UNRESOLVED);\n hit = resolved === UNRESOLVED ? null : resolved;\n cache.set(value, hit);\n }\n return hit ?? fallback;\n };\n return Object.assign(memoized, { cache });\n};\n\n/** Same channels (both `null` included) */\nexport const sameColor = (a: Rgba | null, b: Rgba | null): boolean =>\n a === b ||\n (!!a &&\n !!b &&\n a[0] === b[0] &&\n a[1] === b[1] &&\n a[2] === b[2] &&\n a[3] === b[3]);\n\nconst hex2 = (v: number) =>\n Math.round(clamp01(v) * 255)\n .toString(16)\n .padStart(2, \"0\");\n\n/** `rgba()` string usable by Canvas2D and the DOM */\nexport const toCss = (c: Rgba, alpha = 1): string =>\n `rgba(${Math.round(c[0] * 255)}, ${Math.round(c[1] * 255)}, ${Math.round(c[2] * 255)}, ${+(c[3] * alpha).toFixed(3)})`;\n\n/** `#rrggbb` (alpha dropped) */\nexport const toHex = (c: Rgba): string =>\n `#${hex2(c[0])}${hex2(c[1])}${hex2(c[2])}`;\n\n/** Packs a color as little-endian `unorm8x4` (r in the lowest byte) */\nexport const packColor = (c: Rgba): number =>\n ((Math.round(clamp01(c[3]) * 255) << 24) |\n (Math.round(clamp01(c[2]) * 255) << 16) |\n (Math.round(clamp01(c[1]) * 255) << 8) |\n Math.round(clamp01(c[0]) * 255)) >>>\n 0;\n\n/** Mixes two colors (t = 0 -> a, 1 -> b) */\nexport const mix = (a: Rgba, b: Rgba, t: number): Rgba => [\n a[0] + (b[0] - a[0]) * t,\n a[1] + (b[1] - a[1]) * t,\n a[2] + (b[2] - a[2]) * t,\n a[3] + (b[3] - a[3]) * t,\n];\n\n/** Inverse of `packColor` */\nexport const unpackColor = (packed: number): Rgba => [\n (packed & 0xff) / 255,\n ((packed >>> 8) & 0xff) / 255,\n ((packed >>> 16) & 0xff) / 255,\n ((packed >>> 24) & 0xff) / 255,\n];\n\n/** Color at `t` (0-1) of a ramp through `stops` */\nexport const rampColor = (stops: readonly Rgba[], t: number): Rgba => {\n if (stops.length === 1) return stops[0];\n const p = clamp01(t) * (stops.length - 1);\n const i = Math.min(stops.length - 2, Math.floor(p));\n return mix(stops[i], stops[i + 1], p - i);\n};\n\n/** Relative luminance (sRGB approximation) */\nexport const luminance = (c: Rgba): number =>\n 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2];\n"],"mappings":"AAIA,IAAMA,EAAW,GAAeC,EAAI,EAAI,EAAIA,EAAI,EAAI,EAAIA,EAElDC,EAAY,GAA6B,CAC7C,IAAMC,EAAIC,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,IAAW,EAAK,KAAQ,KACxBA,IAAW,GAAM,KAAQ,KACzBA,IAAW,GAAM,KAAQ,GAC7B,EAGaC,GAAa,EAAwB,IAAoB,CACpE,GAAIC,EAAM,SAAW,EAAG,OAAOA,EAAM,GACrC,IAAMC,EAAIzC,EAAQoC,CAAC,GAAKI,EAAM,OAAS,GACjC,EAAI,KAAK,IAAIA,EAAM,OAAS,EAAG,KAAK,MAAMC,CAAC,CAAC,EAClD,OAAOR,EAAIO,EAAM,GAAIA,EAAM,EAAI,GAAIC,EAAI,CAAC,CAC1C"}
|
|
@@ -118,13 +118,22 @@ var e = (e) => e < 0 ? 0 : e > 1 ? 1 : e, t = (e) => {
|
|
|
118
118
|
0,
|
|
119
119
|
1
|
|
120
120
|
]
|
|
121
|
-
}, c = (e, t = 1) => `rgba(${Math.round(e[0] * 255)}, ${Math.round(e[1] * 255)}, ${Math.round(e[2] * 255)}, ${+(e[3] * t).toFixed(3)})`, l = (e, t, n) => [
|
|
121
|
+
}, c = (e, t = 1) => `rgba(${Math.round(e[0] * 255)}, ${Math.round(e[1] * 255)}, ${Math.round(e[2] * 255)}, ${+(e[3] * t).toFixed(3)})`, l = (t) => (Math.round(e(t[3]) * 255) << 24 | Math.round(e(t[2]) * 255) << 16 | Math.round(e(t[1]) * 255) << 8 | Math.round(e(t[0]) * 255)) >>> 0, u = (e, t, n) => [
|
|
122
122
|
e[0] + (t[0] - e[0]) * n,
|
|
123
123
|
e[1] + (t[1] - e[1]) * n,
|
|
124
124
|
e[2] + (t[2] - e[2]) * n,
|
|
125
125
|
e[3] + (t[3] - e[3]) * n
|
|
126
|
-
]
|
|
126
|
+
], d = (e) => [
|
|
127
|
+
(e & 255) / 255,
|
|
128
|
+
(e >>> 8 & 255) / 255,
|
|
129
|
+
(e >>> 16 & 255) / 255,
|
|
130
|
+
(e >>> 24 & 255) / 255
|
|
131
|
+
], f = (t, n) => {
|
|
132
|
+
if (t.length === 1) return t[0];
|
|
133
|
+
let r = e(n) * (t.length - 1), i = Math.min(t.length - 2, Math.floor(r));
|
|
134
|
+
return u(t[i], t[i + 1], r - i);
|
|
135
|
+
};
|
|
127
136
|
//#endregion
|
|
128
|
-
export {
|
|
137
|
+
export { u as mix, l as packColor, i as parseColor, f as rampColor, o as resolveStaticColor, c as toCss, d as unpackColor };
|
|
129
138
|
|
|
130
139
|
//# sourceMappingURL=color.js.map
|