@rinzai/zen 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -5
- package/dist/animated-number/index.js +33 -0
- package/dist/avatar/index.js +38 -0
- package/dist/backdrop/index.d.ts +7 -3
- package/dist/backdrop/index.d.ts.map +1 -1
- package/dist/backdrop/index.js +98 -0
- package/dist/badge/index.d.ts +1 -1
- package/dist/badge/index.js +24 -0
- package/dist/button/index.d.ts +10 -3
- package/dist/button/index.d.ts.map +1 -1
- package/dist/button/index.js +54 -0
- package/dist/calendar/index.d.ts +44 -0
- package/dist/calendar/index.d.ts.map +1 -0
- package/dist/calendar/index.js +161 -0
- package/dist/card/index.d.ts +15 -6
- package/dist/card/index.d.ts.map +1 -1
- package/dist/card/index.js +60 -0
- package/dist/chart/donut.d.ts +30 -0
- package/dist/chart/donut.d.ts.map +1 -0
- package/dist/chart/donut.js +107 -0
- package/dist/chart/index.d.ts +81 -0
- package/dist/chart/index.d.ts.map +1 -0
- package/dist/chart/index.js +364 -0
- package/dist/chart/tooltip.d.ts +25 -0
- package/dist/chart/tooltip.d.ts.map +1 -0
- package/dist/chart/tooltip.js +51 -0
- package/dist/checkbox/index.d.ts +20 -0
- package/dist/checkbox/index.d.ts.map +1 -0
- package/dist/checkbox/index.js +61 -0
- package/dist/chip/index.d.ts +12 -0
- package/dist/chip/index.d.ts.map +1 -0
- package/dist/chip/index.js +14 -0
- package/dist/code-block/index.js +36 -0
- package/dist/collapse/index.d.ts +17 -7
- package/dist/collapse/index.d.ts.map +1 -1
- package/dist/collapse/index.js +82 -0
- package/dist/combobox/index.d.ts +89 -0
- package/dist/combobox/index.d.ts.map +1 -0
- package/dist/combobox/index.js +264 -0
- package/dist/confirm-dialog/index.d.ts.map +1 -1
- package/dist/confirm-dialog/index.js +25 -0
- package/dist/date-picker/index.d.ts +48 -0
- package/dist/date-picker/index.d.ts.map +1 -0
- package/dist/date-picker/index.js +112 -0
- package/dist/dialog/index.d.ts +14 -2
- package/dist/dialog/index.d.ts.map +1 -1
- package/dist/dialog/index.js +77 -0
- package/dist/disclosure/index.d.ts +25 -0
- package/dist/disclosure/index.d.ts.map +1 -0
- package/dist/disclosure/index.js +66 -0
- package/dist/editable-cell/index.js +24 -0
- package/dist/field/index.d.ts +42 -3
- package/dist/field/index.d.ts.map +1 -1
- package/dist/field/index.js +66 -0
- package/dist/header/index.js +17 -0
- package/dist/icons/chevron-down.js +21 -0
- package/dist/icons/chevron-left.js +21 -0
- package/dist/icons/chevron-right.js +21 -0
- package/dist/icons/chevron-up.js +21 -0
- package/dist/icons/ellipsis.d.ts +4 -0
- package/dist/icons/ellipsis.d.ts.map +1 -0
- package/dist/icons/ellipsis.js +31 -0
- package/dist/icons/index.d.ts +1 -0
- package/dist/icons/index.d.ts.map +1 -1
- package/dist/icons/search.js +21 -0
- package/dist/icons/x-mark.js +21 -0
- package/dist/index.d.ts +22 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/input/index.d.ts.map +1 -1
- package/dist/input/index.js +16 -0
- package/dist/input-group/index.d.ts.map +1 -1
- package/dist/input-group/index.js +36 -0
- package/dist/inset/index.d.ts +16 -0
- package/dist/inset/index.d.ts.map +1 -0
- package/dist/inset/index.js +23 -0
- package/dist/lib.js +74 -0
- package/dist/menu/index.d.ts +55 -0
- package/dist/menu/index.d.ts.map +1 -0
- package/dist/menu/index.js +118 -0
- package/dist/meter/index.d.ts +4 -3
- package/dist/meter/index.d.ts.map +1 -1
- package/dist/meter/index.js +42 -0
- package/dist/money-input/index.d.ts +84 -15
- package/dist/money-input/index.d.ts.map +1 -1
- package/dist/money-input/index.js +322 -0
- package/dist/month-picker/index.d.ts +4 -3
- package/dist/month-picker/index.d.ts.map +1 -1
- package/dist/month-picker/index.js +93 -0
- package/dist/page-header/index.js +26 -0
- package/dist/pills/index.d.ts +35 -0
- package/dist/pills/index.d.ts.map +1 -0
- package/dist/pills/index.js +50 -0
- package/dist/popover/index.d.ts +41 -22
- package/dist/popover/index.d.ts.map +1 -1
- package/dist/popover/index.js +76 -0
- package/dist/progress-ring/index.js +49 -0
- package/dist/radio-cards/index.d.ts +34 -0
- package/dist/radio-cards/index.d.ts.map +1 -0
- package/dist/radio-cards/index.js +48 -0
- package/dist/radio-group/index.d.ts +39 -0
- package/dist/radio-group/index.d.ts.map +1 -0
- package/dist/radio-group/index.js +63 -0
- package/dist/segmented/index.d.ts +16 -6
- package/dist/segmented/index.d.ts.map +1 -1
- package/dist/segmented/index.js +58 -0
- package/dist/select/index.d.ts +28 -14
- package/dist/select/index.d.ts.map +1 -1
- package/dist/select/index.js +187 -0
- package/dist/side-nav/index.js +37 -0
- package/dist/skeleton/index.js +12 -0
- package/dist/slider/index.js +34 -0
- package/dist/spinner/index.js +14 -0
- package/dist/tab-bar/index.d.ts +3 -0
- package/dist/tab-bar/index.d.ts.map +1 -1
- package/dist/tab-bar/index.js +34 -0
- package/dist/table/index.js +148 -0
- package/dist/table-of-contents/index.js +37 -0
- package/dist/tabs/index.d.ts +3 -2
- package/dist/tabs/index.d.ts.map +1 -1
- package/dist/tabs/index.js +114 -0
- package/dist/tailwind.css +1 -1
- package/dist/textarea/index.d.ts.map +1 -1
- package/dist/textarea/index.js +16 -0
- package/dist/theme-toggle/index.js +43 -0
- package/dist/theme.css +197 -31
- package/dist/toast/index.d.ts +6 -1
- package/dist/toast/index.d.ts.map +1 -1
- package/dist/toast/index.js +248 -0
- package/dist/toggle/index.d.ts.map +1 -1
- package/dist/toggle/index.js +26 -0
- package/dist/tooltip/index.d.ts +25 -0
- package/dist/tooltip/index.d.ts.map +1 -0
- package/dist/tooltip/index.js +110 -0
- package/dist/tree/index.d.ts.map +1 -1
- package/dist/tree/index.js +135 -0
- package/dist/utils/cva.js +25 -0
- package/dist/utils/cx.js +6 -0
- package/dist/utils/date.d.ts +37 -0
- package/dist/utils/date.d.ts.map +1 -0
- package/dist/utils/date.js +68 -0
- package/dist/utils/field-chevron.js +19 -0
- package/dist/utils/fx.d.ts +30 -0
- package/dist/utils/fx.d.ts.map +1 -0
- package/dist/utils/fx.js +21 -0
- package/dist/utils/graphics.js +33 -0
- package/dist/utils/indicator.d.ts +24 -0
- package/dist/utils/indicator.d.ts.map +1 -0
- package/dist/utils/indicator.js +37 -0
- package/dist/utils/merge.js +305 -0
- package/dist/utils/money.js +73 -0
- package/dist/utils/month.js +46 -0
- package/dist/utils/slot.d.ts +9 -5
- package/dist/utils/slot.d.ts.map +1 -1
- package/dist/utils/slot.js +25 -0
- package/dist/utils/status-icons.js +48 -0
- package/dist/utils/styles.d.ts +6 -6
- package/dist/utils/styles.d.ts.map +1 -1
- package/dist/utils/styles.js +6 -0
- package/dist/utils/theme.js +200 -0
- package/dist/utils/useAnchoredPopup.d.ts +28 -6
- package/dist/utils/useAnchoredPopup.d.ts.map +1 -1
- package/dist/utils/useAnchoredPopup.js +119 -0
- package/dist/utils/useHydrated.js +9 -0
- package/dist/utils/useVirtualList.js +45 -0
- package/dist/variables.css +22 -0
- package/dist/zen.css +1 -1
- package/package.json +9 -4
- package/dist/actions-menu/index.d.ts +0 -18
- package/dist/actions-menu/index.d.ts.map +0 -1
- package/dist/dropdown/index.d.ts +0 -28
- package/dist/dropdown/index.d.ts.map +0 -1
- package/dist/nav-pills/index.d.ts +0 -31
- package/dist/nav-pills/index.d.ts.map +0 -1
- package/dist/zen.js +0 -2970
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cx as e } from "../utils/cx.js";
|
|
3
|
+
import { Slot as t } from "../utils/slot.js";
|
|
4
|
+
import { jsx as n, jsxs as r } from "react/jsx-runtime";
|
|
5
|
+
//#region packages/card/index.tsx
|
|
6
|
+
function i({ className: t, ...r }) {
|
|
7
|
+
return /* @__PURE__ */ n("section", {
|
|
8
|
+
className: e("zen__card glass glow-edge text-card-foreground rounded-xl p-4 md:p-5", t),
|
|
9
|
+
...r
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
function a({ className: t, ...r }) {
|
|
13
|
+
return /* @__PURE__ */ n("header", {
|
|
14
|
+
className: e("mb-4 flex items-center justify-between gap-4", t),
|
|
15
|
+
...r
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function o({ className: t, ...r }) {
|
|
19
|
+
return /* @__PURE__ */ n("p", {
|
|
20
|
+
className: e("text-muted-foreground text-xs", t),
|
|
21
|
+
...r
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function s({ asChild: r, className: i, children: a, ...o }) {
|
|
25
|
+
let s = {
|
|
26
|
+
...o,
|
|
27
|
+
className: e("text-base font-semibold tracking-tight", i)
|
|
28
|
+
};
|
|
29
|
+
return n(r ? t : "h4", {
|
|
30
|
+
...s,
|
|
31
|
+
children: a
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function c({ label: t, value: i, hint: a, tone: o = "default", className: s }) {
|
|
35
|
+
return /* @__PURE__ */ r("div", {
|
|
36
|
+
className: e("zen__stat glass glow-edge flex flex-col gap-1 rounded-xl p-3.5 md:p-4", s),
|
|
37
|
+
children: [
|
|
38
|
+
/* @__PURE__ */ n("span", {
|
|
39
|
+
className: "text-muted-foreground truncate text-[0.68rem] tracking-[0.1em] uppercase sm:text-xs",
|
|
40
|
+
children: t
|
|
41
|
+
}),
|
|
42
|
+
/* @__PURE__ */ n("span", {
|
|
43
|
+
className: e("truncate text-lg font-semibold tracking-tight tabular-nums sm:text-xl md:text-2xl", o === "positive" && "text-primary text-glow", o === "negative" && "text-destructive"),
|
|
44
|
+
children: i
|
|
45
|
+
}),
|
|
46
|
+
a && /* @__PURE__ */ n("span", {
|
|
47
|
+
className: "text-muted-foreground text-xs",
|
|
48
|
+
children: a
|
|
49
|
+
})
|
|
50
|
+
]
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function l({ children: t, className: r }) {
|
|
54
|
+
return /* @__PURE__ */ n("div", {
|
|
55
|
+
className: e("grid grid-cols-2 gap-3 sm:grid-cols-3 md:gap-4 [&>*]:min-w-0", "[&>*:last-child:nth-child(odd)]:col-span-2 sm:[&>*:last-child:nth-child(odd)]:col-span-1", r),
|
|
56
|
+
children: t
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { o as CardDescription, a as CardHeader, s as CardTitle, c as Stat, l as StatRow, i as default };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A ring of parts of a whole (e.g. spending by category), with your content in
|
|
4
|
+
* the middle (e.g. the total). Segments are parted by a small gap, with
|
|
5
|
+
* rounded corners; pointing at one (or focusing it) lifts it and shows its
|
|
6
|
+
* value. Best for a handful of parts: past about six, use bars. Colours default
|
|
7
|
+
* to the chart palette in order.
|
|
8
|
+
*/
|
|
9
|
+
export default function DonutChart({ items, label, size, thickness, formatValue, children, className, }: DonutChartProps): import('react').JSX.Element;
|
|
10
|
+
export interface DonutChartProps {
|
|
11
|
+
/** The parts, in order round the ring from 12 o'clock. */
|
|
12
|
+
items: {
|
|
13
|
+
key: string;
|
|
14
|
+
label: string;
|
|
15
|
+
value: number;
|
|
16
|
+
color?: string;
|
|
17
|
+
}[];
|
|
18
|
+
/** Names the chart for screen readers. */
|
|
19
|
+
label: string;
|
|
20
|
+
/** Diameter in px. */
|
|
21
|
+
size?: number;
|
|
22
|
+
/** Ring thickness as a share of the radius. */
|
|
23
|
+
thickness?: number;
|
|
24
|
+
/** Values in the tooltip and for screen readers. */
|
|
25
|
+
formatValue?: (value: number) => string;
|
|
26
|
+
/** Content in the middle, e.g. the total. */
|
|
27
|
+
children?: ReactNode;
|
|
28
|
+
className?: string;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=donut.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"donut.d.ts","sourceRoot":"","sources":["../../packages/chart/donut.tsx"],"names":[],"mappings":"AACA,OAAO,EAAiB,SAAS,EAAY,MAAM,OAAO,CAAC;AAI3D;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EAC/B,KAAK,EACL,KAAK,EACL,IAAU,EACV,SAAgB,EAChB,WAAoB,EACpB,QAAQ,EACR,SAAS,GACZ,EAAE,eAAe,+BA+FjB;AAmDD,MAAM,WAAW,eAAe;IAC5B,0DAA0D;IAC1D,KAAK,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACvE,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,sBAAsB;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IACxC,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cx as e } from "../utils/cx.js";
|
|
3
|
+
import { ChartTooltipCard as t } from "./tooltip.js";
|
|
4
|
+
import { useState as n } from "react";
|
|
5
|
+
import { jsx as r, jsxs as i } from "react/jsx-runtime";
|
|
6
|
+
//#region packages/chart/donut.tsx
|
|
7
|
+
function a({ items: a, label: s, size: u = 200, thickness: d = .32, formatValue: f = String, children: p, className: m }) {
|
|
8
|
+
let [h, g] = n(null), _ = a.reduce((e, t) => e + Math.max(0, t.value), 0), v = u / 2, y = v * (1 - d), b = Math.min(4, (v - y) / 4), x = a.filter((e) => e.value > 0).length > 1 ? 1.5 : 0, S = -Math.PI / 2, C = a.map((e, t) => {
|
|
9
|
+
let n = _ ? Math.max(0, e.value) / _ * Math.PI * 2 : 0, r = {
|
|
10
|
+
start: S,
|
|
11
|
+
end: S + n,
|
|
12
|
+
color: e.color ?? `var(--chart-${Math.min(t + 1, 8)})`
|
|
13
|
+
};
|
|
14
|
+
return S += n, r;
|
|
15
|
+
}), w = h === null ? null : a[h];
|
|
16
|
+
return /* @__PURE__ */ i("div", {
|
|
17
|
+
className: e("zen__donut relative shrink-0", m),
|
|
18
|
+
style: {
|
|
19
|
+
width: u,
|
|
20
|
+
height: u
|
|
21
|
+
},
|
|
22
|
+
children: [
|
|
23
|
+
/* @__PURE__ */ r("svg", {
|
|
24
|
+
width: u,
|
|
25
|
+
height: u,
|
|
26
|
+
viewBox: `${-v} ${-v} ${u} ${u}`,
|
|
27
|
+
role: "list",
|
|
28
|
+
"aria-label": s,
|
|
29
|
+
className: "overflow-visible",
|
|
30
|
+
children: C.map((e, t) => {
|
|
31
|
+
let n = e.end - e.start >= Math.PI * 2 - 1e-6, i = n ? l(y, v, e.start, e.end) : c(y + b, v - b, e.start, e.end, x + b);
|
|
32
|
+
if (!i) return null;
|
|
33
|
+
let o = (e.start + e.end) / 2, s = h === t && !n ? 4 : 0, u = _ ? Math.round(a[t].value / _ * 100) : 0;
|
|
34
|
+
return /* @__PURE__ */ r("path", {
|
|
35
|
+
role: "listitem",
|
|
36
|
+
tabIndex: 0,
|
|
37
|
+
"aria-label": `${a[t].label}: ${f(a[t].value)} (${u}%)`,
|
|
38
|
+
d: i,
|
|
39
|
+
strokeWidth: n ? 0 : b * 2,
|
|
40
|
+
strokeLinejoin: "round",
|
|
41
|
+
onPointerEnter: () => g(t),
|
|
42
|
+
onPointerLeave: () => g(null),
|
|
43
|
+
onFocus: () => g(t),
|
|
44
|
+
onBlur: () => g(null),
|
|
45
|
+
className: "zen__chart-fade focus-visible:outline-hidden",
|
|
46
|
+
style: {
|
|
47
|
+
fill: e.color,
|
|
48
|
+
stroke: e.color,
|
|
49
|
+
opacity: h !== null && h !== t ? .55 : 1,
|
|
50
|
+
transform: `translate(${Math.cos(o) * s}px, ${Math.sin(o) * s}px)`,
|
|
51
|
+
transition: "transform 200ms ease-out, opacity 200ms",
|
|
52
|
+
animationDelay: `${t * 60}ms`,
|
|
53
|
+
filter: h === t ? `drop-shadow(0 0 10px ${e.color})` : void 0
|
|
54
|
+
}
|
|
55
|
+
}, a[t].key);
|
|
56
|
+
})
|
|
57
|
+
}),
|
|
58
|
+
p && /* @__PURE__ */ r("div", {
|
|
59
|
+
className: "pointer-events-none absolute inset-0 flex flex-col items-center justify-center text-center",
|
|
60
|
+
children: p
|
|
61
|
+
}),
|
|
62
|
+
w && h !== null && /* @__PURE__ */ r("div", {
|
|
63
|
+
className: "pointer-events-none absolute z-10 -translate-y-1/2",
|
|
64
|
+
style: o((C[h].start + C[h].end) / 2, v),
|
|
65
|
+
children: /* @__PURE__ */ r(t, {
|
|
66
|
+
title: w.label,
|
|
67
|
+
rows: [{
|
|
68
|
+
label: `${_ ? Math.round(w.value / _ * 100) : 0}%`,
|
|
69
|
+
value: f(w.value),
|
|
70
|
+
color: C[h].color
|
|
71
|
+
}]
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
]
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function o(e, t) {
|
|
78
|
+
let n = t + Math.cos(e) * (t + 10), r = t + Math.sin(e) * (t + 10);
|
|
79
|
+
return Math.cos(e) >= 0 ? {
|
|
80
|
+
left: n,
|
|
81
|
+
top: r
|
|
82
|
+
} : {
|
|
83
|
+
right: 2 * t - n,
|
|
84
|
+
top: r
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function s(e, t) {
|
|
88
|
+
let n = (e) => Math.round(e * 1e3) / 1e3;
|
|
89
|
+
return `${n(e * Math.cos(t))},${n(e * Math.sin(t))}`;
|
|
90
|
+
}
|
|
91
|
+
function c(e, t, n, r, i) {
|
|
92
|
+
let a = (e) => Math.asin(Math.min(1, i / e)), [o, c] = [n + a(t), r - a(t)];
|
|
93
|
+
if (c <= o) return "";
|
|
94
|
+
let [l, u] = [n + a(e), r - a(e)];
|
|
95
|
+
return u < l && (l = u = (n + r) / 2), `${`M${s(t, o)}A${t},${t} 0 ${+(c - o > Math.PI)} 1 ${s(t, c)}`}${u > l ? `L${s(e, u)}A${e},${e} 0 ${+(u - l > Math.PI)} 0 ${s(e, l)}` : `L${s(e, l)}`}Z`;
|
|
96
|
+
}
|
|
97
|
+
function l(e, t, n, r) {
|
|
98
|
+
if (r <= n) return "";
|
|
99
|
+
let i = +(r - n > Math.PI);
|
|
100
|
+
if (r - n >= Math.PI * 2 - 1e-6) {
|
|
101
|
+
let r = n + Math.PI;
|
|
102
|
+
return `M${s(t, n)}A${t},${t} 0 1 1 ${s(t, r)}A${t},${t} 0 1 1 ${s(t, n)}M${s(e, n)}A${e},${e} 0 1 0 ${s(e, r)}A${e},${e} 0 1 0 ${s(e, n)}Z`;
|
|
103
|
+
}
|
|
104
|
+
return `M${s(t, n)}A${t},${t} 0 ${i} 1 ${s(t, r)}L${s(e, r)}A${e},${e} 0 ${i} 0 ${s(e, n)}Z`;
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
export { a as default };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
type Row = Record<string, unknown>;
|
|
3
|
+
/** A line with a soft fill down to the baseline. */
|
|
4
|
+
export declare const ChartArea: (props: ChartAreaProps) => null;
|
|
5
|
+
/** A 2px line. Gaps (null values) break it, so one series can be split into solid and dashed parts. */
|
|
6
|
+
export declare const ChartLine: (props: ChartLineProps) => null;
|
|
7
|
+
/** Bars, grouped with the other bar series, growing from the baseline. */
|
|
8
|
+
export declare const ChartBar: (props: ChartBarProps) => null;
|
|
9
|
+
/** A marker across the plot: a horizontal line at `y` (e.g. zero), or a vertical one at the row whose x is `x` (e.g. today). */
|
|
10
|
+
export declare const ChartReference: (props: ChartReferenceProps) => null;
|
|
11
|
+
/**
|
|
12
|
+
* A chart on one axis: areas, lines and bars over rows of data (e.g. months),
|
|
13
|
+
* with a recessive grid, a crosshair and a tooltip listing every series at the
|
|
14
|
+
* pointer (or keyboard: focus it and use the arrow keys), a legend for two or
|
|
15
|
+
* more series, and a table of the values for screen readers. Series draw in
|
|
16
|
+
* as they appear. Colours default to the chart palette (--chart-1…8) in the
|
|
17
|
+
* order the series are written; give each its own `color` for meaning (e.g.
|
|
18
|
+
* the theme's glow).
|
|
19
|
+
*/
|
|
20
|
+
export default function Chart<T extends Row, X extends keyof T & string = keyof T & string>({ data, x, label, summary, height, formatX, formatY, formatTooltipX, renderTooltip, legend, className, children, }: ChartProps<T, X>): import('react').JSX.Element;
|
|
21
|
+
/** Round tick values covering [min, max]: 0 / 5k / 10k, never 0 / 3,127 / 6,254. */
|
|
22
|
+
export declare function niceTicks(min: number, max: number, count?: number): number[];
|
|
23
|
+
export interface ChartSeriesProps {
|
|
24
|
+
/** The row field holding this series' values (numbers; null for none). */
|
|
25
|
+
dataKey: string;
|
|
26
|
+
/** Its name in the legend, the tooltip and the table. */
|
|
27
|
+
label: string;
|
|
28
|
+
/** Any CSS colour. Defaults to the next of --chart-1…8. */
|
|
29
|
+
color?: string;
|
|
30
|
+
/** Dashed (e.g. a projection). */
|
|
31
|
+
dashed?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface ChartAreaProps extends ChartSeriesProps {
|
|
34
|
+
/** Smooth (default) or straight between points. */
|
|
35
|
+
curve?: 'monotone' | 'linear';
|
|
36
|
+
}
|
|
37
|
+
export type ChartLineProps = ChartAreaProps;
|
|
38
|
+
export interface ChartBarProps extends Omit<ChartSeriesProps, 'dashed'> {
|
|
39
|
+
/** Rows whose bar is faded, e.g. months still to come. */
|
|
40
|
+
dim?: (row: Row, index: number) => boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface ChartReferenceProps {
|
|
43
|
+
/** A horizontal line at this value. */
|
|
44
|
+
y?: number;
|
|
45
|
+
/** A vertical line at the row whose x field equals this. */
|
|
46
|
+
x?: unknown;
|
|
47
|
+
/** Text beside a vertical line, e.g. "Today". */
|
|
48
|
+
label?: string;
|
|
49
|
+
/** Destructive for a line that warns (e.g. below zero). */
|
|
50
|
+
tone?: 'muted' | 'destructive';
|
|
51
|
+
/** Vertical lines are dashed unless `dashed={false}`; horizontal ones solid unless `dashed`. */
|
|
52
|
+
dashed?: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface ChartProps<T extends Row, X extends keyof T & string = keyof T & string> {
|
|
55
|
+
/** One row per point on the x axis (e.g. a month). */
|
|
56
|
+
data: readonly T[];
|
|
57
|
+
/** The row field placed along the x axis. */
|
|
58
|
+
x: X;
|
|
59
|
+
/** Names the chart for screen readers. */
|
|
60
|
+
label: string;
|
|
61
|
+
/** A sentence on what the chart shows, for screen readers (e.g. its highest and lowest points). */
|
|
62
|
+
summary?: string;
|
|
63
|
+
/** Height in px, including the axis labels. */
|
|
64
|
+
height?: number;
|
|
65
|
+
/** Axis labels for x values. */
|
|
66
|
+
formatX?: (value: T[X]) => string;
|
|
67
|
+
/** The tooltip's title for an x value (defaults to formatX). */
|
|
68
|
+
formatTooltipX?: (value: T[X]) => string;
|
|
69
|
+
/** Axis ticks and tooltip values (defaults to compact numbers: 1.2K). */
|
|
70
|
+
formatY?: (value: number) => string;
|
|
71
|
+
/** Your own tooltip for a row (build it from ChartTooltipCard). */
|
|
72
|
+
renderTooltip?: (row: T, index: number) => ReactNode;
|
|
73
|
+
/** Show the legend. Defaults to on for two or more series. */
|
|
74
|
+
legend?: boolean;
|
|
75
|
+
className?: string;
|
|
76
|
+
/** ChartArea, ChartLine, ChartBar and ChartReference parts. */
|
|
77
|
+
children: ReactNode;
|
|
78
|
+
}
|
|
79
|
+
export { ChartTooltipCard, type ChartTooltipCardProps } from './tooltip';
|
|
80
|
+
export { default as DonutChart, type DonutChartProps } from './donut';
|
|
81
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/chart/index.tsx"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cx as e } from "../utils/cx.js";
|
|
3
|
+
import { ChartTooltipCard as t, Key as n } from "./tooltip.js";
|
|
4
|
+
import r from "./donut.js";
|
|
5
|
+
import { Children as i, isValidElement as a, useEffect as o, useId as s, useMemo as c, useRef as l, useState as u } from "react";
|
|
6
|
+
import { Fragment as d, jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
7
|
+
//#region packages/chart/index.tsx
|
|
8
|
+
var m = () => null, h = () => null, g = () => null, _ = () => null, ee = /* @__PURE__ */ new Map([
|
|
9
|
+
[m, "area"],
|
|
10
|
+
[h, "line"],
|
|
11
|
+
[g, "bar"]
|
|
12
|
+
]), v = {
|
|
13
|
+
top: 12,
|
|
14
|
+
right: 8,
|
|
15
|
+
bottom: 26
|
|
16
|
+
}, y = 11;
|
|
17
|
+
function b({ data: n, x: r, label: o, summary: m, height: h = 240, formatX: g = String, formatY: b = D, formatTooltipX: E, renderTooltip: k, legend: A, className: j, children: M }) {
|
|
18
|
+
let N = s().replace(/[^\w-]/g, ""), P = l(null), F = w(P), [I, L] = u(null), [R, z] = u(null), B = c(() => {
|
|
19
|
+
let e = i.toArray(M).filter(a), t = 0, o = [], s = [];
|
|
20
|
+
for (let n of e) {
|
|
21
|
+
n.type === _ && s.push(n.props);
|
|
22
|
+
let e = ee.get(n.type);
|
|
23
|
+
if (!e) continue;
|
|
24
|
+
let r = n.props;
|
|
25
|
+
t++, o.push({
|
|
26
|
+
...r,
|
|
27
|
+
kind: e,
|
|
28
|
+
color: r.color ?? `var(--chart-${Math.min(t, 8)})`
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
let c = n, l = o.flatMap((e) => c.map((t) => x(t, e.dataKey))).filter((e) => e !== null);
|
|
32
|
+
for (let e of s) e.y !== void 0 && l.push(e.y);
|
|
33
|
+
o.some((e) => e.kind !== "line") && l.push(0);
|
|
34
|
+
let u = T(l.length ? Math.min(...l) : 0, l.length ? Math.max(...l) : 1), [m, S] = [u[0], u[u.length - 1]], C = u.map((e) => b(e)), w = Math.ceil(Math.max(...C.map((e) => e.length)) * y * .62) + 10, E = Math.max(0, F - w - v.right), D = Math.max(0, h - v.top - v.bottom), O = c.length, k = o.filter((e) => e.kind === "bar"), A = k.length > 0 || O === 1, j = O ? A ? E / O : E / (O - 1) : 0, P = (e) => w + (A ? (e + .5) * j : e * j), I = (e) => v.top + (S === m ? D / 2 : (S - e) / (S - m) * D), L = I(Math.min(Math.max(0, m), S)), R = k.length ? Math.max(2, Math.min(24, j * .72 / k.length - 2)) : 0, z = (e, t) => P(e) - (k.length * (R + 2) - 2) / 2 + t * (R + 2), B = c.map((e) => g(e[r])), V = Math.max(1, ...B.map((e) => e.length)) * y * .6 + 12, H = j ? Math.max(1, Math.ceil(V / j)) : 1;
|
|
35
|
+
return {
|
|
36
|
+
series: o,
|
|
37
|
+
rows: c,
|
|
38
|
+
n: O,
|
|
39
|
+
bars: k,
|
|
40
|
+
banded: A,
|
|
41
|
+
step: j,
|
|
42
|
+
left: w,
|
|
43
|
+
plotH: D,
|
|
44
|
+
cx0: P,
|
|
45
|
+
cy: I,
|
|
46
|
+
base: L,
|
|
47
|
+
barW: R,
|
|
48
|
+
barX: z,
|
|
49
|
+
back: /* @__PURE__ */ p(d, { children: [
|
|
50
|
+
/* @__PURE__ */ f("defs", { children: o.map((e, t) => e.kind === "area" ? /* @__PURE__ */ p("linearGradient", {
|
|
51
|
+
id: `${N}-fill-${t}`,
|
|
52
|
+
x1: "0",
|
|
53
|
+
y1: "0",
|
|
54
|
+
x2: "0",
|
|
55
|
+
y2: "1",
|
|
56
|
+
children: [/* @__PURE__ */ f("stop", {
|
|
57
|
+
offset: "0%",
|
|
58
|
+
style: { stopColor: e.color },
|
|
59
|
+
stopOpacity: e.dashed ? .16 : .32
|
|
60
|
+
}), /* @__PURE__ */ f("stop", {
|
|
61
|
+
offset: "100%",
|
|
62
|
+
style: { stopColor: e.color },
|
|
63
|
+
stopOpacity: 0
|
|
64
|
+
})]
|
|
65
|
+
}, t) : null) }),
|
|
66
|
+
u.map((e, t) => /* @__PURE__ */ p("g", { children: [/* @__PURE__ */ f("line", {
|
|
67
|
+
x1: w,
|
|
68
|
+
x2: w + E,
|
|
69
|
+
y1: I(e),
|
|
70
|
+
y2: I(e),
|
|
71
|
+
className: "stroke-tint/[0.07]",
|
|
72
|
+
shapeRendering: "crispEdges"
|
|
73
|
+
}), /* @__PURE__ */ f("text", {
|
|
74
|
+
x: w - 8,
|
|
75
|
+
y: I(e),
|
|
76
|
+
dy: "0.32em",
|
|
77
|
+
textAnchor: "end",
|
|
78
|
+
className: "fill-muted-foreground tabular-nums",
|
|
79
|
+
style: { fontSize: y },
|
|
80
|
+
children: C[t]
|
|
81
|
+
})] }, e)),
|
|
82
|
+
B.map((e, t) => t % H === 0 ? /* @__PURE__ */ f("text", {
|
|
83
|
+
x: P(t),
|
|
84
|
+
y: h - 8,
|
|
85
|
+
textAnchor: !k.length && O > 1 && t === 0 ? "start" : !k.length && t === O - 1 ? "end" : "middle",
|
|
86
|
+
className: "fill-muted-foreground",
|
|
87
|
+
style: { fontSize: y },
|
|
88
|
+
children: e
|
|
89
|
+
}, t) : null)
|
|
90
|
+
] }),
|
|
91
|
+
front: /* @__PURE__ */ p(d, { children: [o.map((e, t) => e.kind === "bar" ? null : te(c.map((t, n) => {
|
|
92
|
+
let r = x(t, e.dataKey);
|
|
93
|
+
return r === null ? null : [P(n), I(r)];
|
|
94
|
+
})).map((n, r) => {
|
|
95
|
+
let i = (e.curve === "linear" ? ne : re)(n);
|
|
96
|
+
return /* @__PURE__ */ p("g", { children: [e.kind === "area" && /* @__PURE__ */ f("path", {
|
|
97
|
+
d: `${i}L${n[n.length - 1][0]},${L}L${n[0][0]},${L}Z`,
|
|
98
|
+
fill: `url(#${N}-fill-${t})`,
|
|
99
|
+
className: "zen__chart-fade"
|
|
100
|
+
}), /* @__PURE__ */ f("path", {
|
|
101
|
+
d: i,
|
|
102
|
+
fill: "none",
|
|
103
|
+
strokeWidth: e.kind === "area" && !e.dashed ? 2.5 : 2,
|
|
104
|
+
strokeLinecap: "round",
|
|
105
|
+
strokeLinejoin: "round",
|
|
106
|
+
pathLength: e.dashed ? void 0 : 1,
|
|
107
|
+
strokeDasharray: e.dashed ? "5 5" : void 0,
|
|
108
|
+
className: e.dashed ? "zen__chart-fade" : "zen__chart-draw",
|
|
109
|
+
style: { stroke: e.color }
|
|
110
|
+
})] }, `${t}-${r}`);
|
|
111
|
+
})), s.map((e, t) => {
|
|
112
|
+
let n = e.tone === "destructive" ? "stroke-destructive/45" : "stroke-muted-foreground/60";
|
|
113
|
+
if (e.y !== void 0) return /* @__PURE__ */ f("line", {
|
|
114
|
+
x1: w,
|
|
115
|
+
x2: w + E,
|
|
116
|
+
y1: I(e.y),
|
|
117
|
+
y2: I(e.y),
|
|
118
|
+
className: n,
|
|
119
|
+
strokeDasharray: e.dashed ? "3 4" : void 0,
|
|
120
|
+
shapeRendering: "crispEdges"
|
|
121
|
+
}, t);
|
|
122
|
+
let i = c.findIndex((t) => t[r] === e.x);
|
|
123
|
+
if (i < 0) return null;
|
|
124
|
+
let a = !!e.label && P(i) - 6 - e.label.length * y * .6 < w;
|
|
125
|
+
return /* @__PURE__ */ p("g", { children: [/* @__PURE__ */ f("line", {
|
|
126
|
+
x1: P(i),
|
|
127
|
+
x2: P(i),
|
|
128
|
+
y1: v.top,
|
|
129
|
+
y2: v.top + D,
|
|
130
|
+
className: n,
|
|
131
|
+
strokeDasharray: e.dashed === !1 ? void 0 : "3 4"
|
|
132
|
+
}), e.label && /* @__PURE__ */ f("text", {
|
|
133
|
+
x: P(i) + (a ? 6 : -6),
|
|
134
|
+
y: v.top + 4,
|
|
135
|
+
dy: "0.7em",
|
|
136
|
+
textAnchor: a ? "start" : "end",
|
|
137
|
+
className: "fill-muted-foreground",
|
|
138
|
+
style: { fontSize: y },
|
|
139
|
+
children: e.label
|
|
140
|
+
})] }, t);
|
|
141
|
+
})] })
|
|
142
|
+
};
|
|
143
|
+
}, [
|
|
144
|
+
M,
|
|
145
|
+
n,
|
|
146
|
+
r,
|
|
147
|
+
F,
|
|
148
|
+
h,
|
|
149
|
+
g,
|
|
150
|
+
b,
|
|
151
|
+
N
|
|
152
|
+
]), { series: V, rows: H, n: U, bars: W, banded: ie, step: G, left: K, plotH: q, cx0: J, cy: Y, base: X, barW: Z, barX: ae } = B, oe = c(() => W.map((e, t) => H.map((n, r) => {
|
|
153
|
+
let i = x(n, e.dataKey);
|
|
154
|
+
if (i === null) return null;
|
|
155
|
+
let a = Y(i), o = Math.abs(X - a), s = i < 0;
|
|
156
|
+
return /* @__PURE__ */ f("path", {
|
|
157
|
+
d: O(ae(r, t), s ? X : a, Z, o, s),
|
|
158
|
+
"data-negative": s || void 0,
|
|
159
|
+
className: "zen__chart-grow transition-opacity duration-200",
|
|
160
|
+
style: {
|
|
161
|
+
fill: e.color,
|
|
162
|
+
opacity: (e.dim?.(n, r) ? .35 : .9) * (I !== null && I !== r ? .7 : 1),
|
|
163
|
+
animationDelay: `${Math.min(r * 25, 400)}ms`
|
|
164
|
+
}
|
|
165
|
+
}, `${t}-${r}`);
|
|
166
|
+
})), [
|
|
167
|
+
W,
|
|
168
|
+
H,
|
|
169
|
+
Y,
|
|
170
|
+
X,
|
|
171
|
+
ae,
|
|
172
|
+
Z,
|
|
173
|
+
I
|
|
174
|
+
]), se = c(() => /* @__PURE__ */ p("table", {
|
|
175
|
+
className: "sr-only",
|
|
176
|
+
children: [
|
|
177
|
+
/* @__PURE__ */ f("caption", { children: o }),
|
|
178
|
+
/* @__PURE__ */ f("thead", { children: /* @__PURE__ */ p("tr", { children: [/* @__PURE__ */ f("th", {
|
|
179
|
+
scope: "col",
|
|
180
|
+
children: String(r)
|
|
181
|
+
}), V.map((e) => /* @__PURE__ */ f("th", {
|
|
182
|
+
scope: "col",
|
|
183
|
+
children: e.label
|
|
184
|
+
}, e.dataKey))] }) }),
|
|
185
|
+
/* @__PURE__ */ f("tbody", { children: H.map((e, t) => /* @__PURE__ */ p("tr", { children: [/* @__PURE__ */ f("th", {
|
|
186
|
+
scope: "row",
|
|
187
|
+
children: (E ?? g)(e[r])
|
|
188
|
+
}), V.map((t) => {
|
|
189
|
+
let n = x(e, t.dataKey);
|
|
190
|
+
return /* @__PURE__ */ f("td", { children: n === null ? "" : b(n) }, t.dataKey);
|
|
191
|
+
})] }, t)) })
|
|
192
|
+
]
|
|
193
|
+
}), [
|
|
194
|
+
o,
|
|
195
|
+
r,
|
|
196
|
+
V,
|
|
197
|
+
H,
|
|
198
|
+
E,
|
|
199
|
+
g,
|
|
200
|
+
b
|
|
201
|
+
]), ce = (e) => {
|
|
202
|
+
if (!U || !G) return null;
|
|
203
|
+
let t = ie ? Math.floor((e - K) / G) : Math.round((e - K) / G);
|
|
204
|
+
return Math.min(U - 1, Math.max(0, t));
|
|
205
|
+
}, le = (e) => {
|
|
206
|
+
let t = e.currentTarget.getBoundingClientRect(), n = e.clientX - t.left, r = Math.round(e.clientY - t.top);
|
|
207
|
+
L(ce(n)), z((e) => e?.y === r ? e : { y: r });
|
|
208
|
+
}, ue = (e) => {
|
|
209
|
+
if (!U) return;
|
|
210
|
+
let t = {
|
|
211
|
+
ArrowRight: 1,
|
|
212
|
+
ArrowLeft: -1
|
|
213
|
+
}[e.key];
|
|
214
|
+
if (e.key === "Escape") return L(null);
|
|
215
|
+
if (e.key === "Home" || e.key === "End") return e.preventDefault(), z(null), L(e.key === "Home" ? 0 : U - 1);
|
|
216
|
+
t && (e.preventDefault(), z(null), L((e) => e === null ? t > 0 ? 0 : U - 1 : Math.min(U - 1, Math.max(0, e + t))));
|
|
217
|
+
}, de = A ?? V.length > 1, Q = I === null ? null : H[I], $ = I === null ? 0 : J(I), fe = R?.y ?? v.top;
|
|
218
|
+
return /* @__PURE__ */ p("figure", {
|
|
219
|
+
"aria-label": o,
|
|
220
|
+
className: e("zen__chart m-0 flex flex-col gap-3", j),
|
|
221
|
+
children: [
|
|
222
|
+
de && /* @__PURE__ */ f(S, { series: V }),
|
|
223
|
+
/* @__PURE__ */ p("div", {
|
|
224
|
+
ref: P,
|
|
225
|
+
tabIndex: 0,
|
|
226
|
+
"aria-label": `${o}: use the arrow keys to read values`,
|
|
227
|
+
onPointerMove: le,
|
|
228
|
+
onPointerLeave: () => {
|
|
229
|
+
L(null), z(null);
|
|
230
|
+
},
|
|
231
|
+
onKeyDown: ue,
|
|
232
|
+
onBlur: () => L(null),
|
|
233
|
+
className: "focus-visible:ring-ring/50 relative rounded-lg outline-hidden focus-visible:ring-2",
|
|
234
|
+
style: { height: h },
|
|
235
|
+
children: [F > 0 && /* @__PURE__ */ p("svg", {
|
|
236
|
+
width: F,
|
|
237
|
+
height: h,
|
|
238
|
+
"aria-hidden": !0,
|
|
239
|
+
className: "block overflow-visible",
|
|
240
|
+
children: [
|
|
241
|
+
B.back,
|
|
242
|
+
I !== null && (W.length ? /* @__PURE__ */ f("rect", {
|
|
243
|
+
x: J(I) - G / 2,
|
|
244
|
+
y: v.top,
|
|
245
|
+
width: G,
|
|
246
|
+
height: q,
|
|
247
|
+
className: "fill-tint/[0.04]"
|
|
248
|
+
}) : /* @__PURE__ */ f("line", {
|
|
249
|
+
x1: $,
|
|
250
|
+
x2: $,
|
|
251
|
+
y1: v.top,
|
|
252
|
+
y2: v.top + q,
|
|
253
|
+
className: "stroke-glow/40"
|
|
254
|
+
})),
|
|
255
|
+
oe,
|
|
256
|
+
B.front,
|
|
257
|
+
I !== null && V.map((e, t) => {
|
|
258
|
+
if (e.kind === "bar") return null;
|
|
259
|
+
let n = x(H[I], e.dataKey);
|
|
260
|
+
return n === null ? null : /* @__PURE__ */ f("circle", {
|
|
261
|
+
cx: $,
|
|
262
|
+
cy: Y(n),
|
|
263
|
+
r: 4,
|
|
264
|
+
strokeWidth: 2,
|
|
265
|
+
className: "stroke-card",
|
|
266
|
+
style: { fill: e.color }
|
|
267
|
+
}, t);
|
|
268
|
+
})
|
|
269
|
+
]
|
|
270
|
+
}), Q && I !== null && /* @__PURE__ */ f("div", {
|
|
271
|
+
className: "pointer-events-none absolute top-0 z-10 transition-[translate] duration-75",
|
|
272
|
+
style: C($, fe, F, h),
|
|
273
|
+
children: k ? k(Q, I) : /* @__PURE__ */ f(t, {
|
|
274
|
+
title: (E ?? g)(Q[r]),
|
|
275
|
+
rows: V.map((e) => ({
|
|
276
|
+
s: e,
|
|
277
|
+
v: x(Q, e.dataKey)
|
|
278
|
+
})).filter(({ v: e }) => e !== null).map(({ s: e, v: t }) => ({
|
|
279
|
+
label: e.label,
|
|
280
|
+
value: b(t),
|
|
281
|
+
color: e.color,
|
|
282
|
+
dashed: e.dashed
|
|
283
|
+
}))
|
|
284
|
+
})
|
|
285
|
+
})]
|
|
286
|
+
}),
|
|
287
|
+
m && /* @__PURE__ */ f("figcaption", {
|
|
288
|
+
className: "sr-only",
|
|
289
|
+
children: m
|
|
290
|
+
}),
|
|
291
|
+
se
|
|
292
|
+
]
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
function x(e, t) {
|
|
296
|
+
let n = e[t];
|
|
297
|
+
return typeof n == "number" && Number.isFinite(n) ? n : null;
|
|
298
|
+
}
|
|
299
|
+
function S({ series: e }) {
|
|
300
|
+
return /* @__PURE__ */ f("ul", {
|
|
301
|
+
className: "text-muted-foreground flex flex-wrap gap-x-4 gap-y-1 text-xs",
|
|
302
|
+
"aria-label": "Legend",
|
|
303
|
+
children: e.map((e) => /* @__PURE__ */ p("li", {
|
|
304
|
+
className: "flex items-center gap-1.5",
|
|
305
|
+
children: [/* @__PURE__ */ f(n, {
|
|
306
|
+
color: e.color,
|
|
307
|
+
dashed: e.dashed,
|
|
308
|
+
kind: e.kind
|
|
309
|
+
}), e.label]
|
|
310
|
+
}, e.dataKey))
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
function C(e, t, n, r) {
|
|
314
|
+
let i = e > n / 2, a = Math.round(Math.min(Math.max(0, t - 20), r - 80));
|
|
315
|
+
return i ? {
|
|
316
|
+
right: 0,
|
|
317
|
+
translate: `${Math.round(e - 12 - n)}px ${a}px`
|
|
318
|
+
} : {
|
|
319
|
+
left: 0,
|
|
320
|
+
translate: `${Math.round(e + 12)}px ${a}px`
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
function w(e) {
|
|
324
|
+
let [t, n] = u(0);
|
|
325
|
+
return o(() => {
|
|
326
|
+
let t = e.current;
|
|
327
|
+
if (!t || (n(t.clientWidth), typeof ResizeObserver > "u")) return;
|
|
328
|
+
let r = new ResizeObserver(() => n(t.clientWidth));
|
|
329
|
+
return r.observe(t), () => r.disconnect();
|
|
330
|
+
}, [e]), t;
|
|
331
|
+
}
|
|
332
|
+
function T(e, t, n = 5) {
|
|
333
|
+
e === t && ([e, t] = e === 0 ? [0, 1] : [Math.min(0, e), Math.max(0, t)]);
|
|
334
|
+
let r = (t - e) / n, i = 10 ** Math.floor(Math.log10(r)), a = r / i, o = i * (a >= 7.5 ? 10 : a >= 3.5 ? 5 : a >= 1.5 ? 2 : 1), s = Math.floor(e / o), c = Math.ceil(t / o);
|
|
335
|
+
return Array.from({ length: c - s + 1 }, (e, t) => Number(((s + t) * o).toPrecision(12)));
|
|
336
|
+
}
|
|
337
|
+
var E = new Intl.NumberFormat("en", {
|
|
338
|
+
notation: "compact",
|
|
339
|
+
maximumFractionDigits: 1
|
|
340
|
+
}), D = (e) => E.format(e);
|
|
341
|
+
function te(e) {
|
|
342
|
+
let t = [], n = [];
|
|
343
|
+
for (let r of e) r ? n.push(r) : n.length && (t.push(n), n = []);
|
|
344
|
+
return n.length && t.push(n), t;
|
|
345
|
+
}
|
|
346
|
+
function ne(e) {
|
|
347
|
+
return e.map(([e, t], n) => `${n ? "L" : "M"}${e},${t}`).join("");
|
|
348
|
+
}
|
|
349
|
+
function re(e) {
|
|
350
|
+
let t = e.length;
|
|
351
|
+
if (t < 3) return ne(e);
|
|
352
|
+
let n = e.slice(1).map((t, n) => t[0] - e[n][0]), r = e.slice(1).map((t, r) => (t[1] - e[r][1]) / n[r]), i = e.map((e, i) => i === 0 ? r[0] : i === t - 1 ? r[t - 2] : r[i - 1] * r[i] <= 0 ? 0 : 3 * (n[i - 1] + n[i]) / ((2 * n[i] + n[i - 1]) / r[i - 1] + (n[i] + 2 * n[i - 1]) / r[i])), a = `M${e[0][0]},${e[0][1]}`;
|
|
353
|
+
for (let r = 0; r < t - 1; r++) {
|
|
354
|
+
let t = n[r] / 3;
|
|
355
|
+
a += `C${e[r][0] + t},${e[r][1] + i[r] * t},${e[r + 1][0] - t},${e[r + 1][1] - i[r + 1] * t},${e[r + 1][0]},${e[r + 1][1]}`;
|
|
356
|
+
}
|
|
357
|
+
return a;
|
|
358
|
+
}
|
|
359
|
+
function O(e, t, n, r, i) {
|
|
360
|
+
let a = Math.min(4, n / 2, r);
|
|
361
|
+
return i ? `M${e},${t}V${t + r - a}Q${e},${t + r} ${e + a},${t + r}H${e + n - a}Q${e + n},${t + r} ${e + n},${t + r - a}V${t}Z` : `M${e},${t + r}V${t + a}Q${e},${t} ${e + a},${t}H${e + n - a}Q${e + n},${t} ${e + n},${t + a}V${t + r}Z`;
|
|
362
|
+
}
|
|
363
|
+
//#endregion
|
|
364
|
+
export { m as ChartArea, g as ChartBar, h as ChartLine, _ as ChartReference, t as ChartTooltipCard, r as DonutChart, b as default, T as niceTicks };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export type Kind = 'area' | 'line' | 'bar';
|
|
3
|
+
/**
|
|
4
|
+
* The tooltip's card: a title and one row per series, the value first and the
|
|
5
|
+
* series keyed by a short stroke of its colour. Use it in `renderTooltip` to
|
|
6
|
+
* show your own rows.
|
|
7
|
+
*/
|
|
8
|
+
export declare function ChartTooltipCard({ title, rows, className }: ChartTooltipCardProps): import('react').JSX.Element;
|
|
9
|
+
/** A series' key: a short line for lines (dashed if the series is), a rounded swatch for bars and areas. */
|
|
10
|
+
export declare function Key({ color, dashed, kind }: {
|
|
11
|
+
color: string;
|
|
12
|
+
dashed?: boolean;
|
|
13
|
+
kind?: Kind;
|
|
14
|
+
}): import('react').JSX.Element;
|
|
15
|
+
export interface ChartTooltipCardProps {
|
|
16
|
+
title: ReactNode;
|
|
17
|
+
rows: {
|
|
18
|
+
label: string;
|
|
19
|
+
value: string;
|
|
20
|
+
color?: string;
|
|
21
|
+
dashed?: boolean;
|
|
22
|
+
}[];
|
|
23
|
+
className?: string;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=tooltip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../packages/chart/tooltip.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;AAE3C;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,qBAAqB,+BAiBjF;AAED,4GAA4G;AAC5G,wBAAgB,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAa,EAAE,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,IAAI,CAAA;CAAE,+BAiBrG;AAED,MAAM,WAAW,qBAAqB;IAClC,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;IAC3E,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB"}
|