@lucasromero/matrix-ui 0.10.0 → 0.12.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +1 -0
  3. package/dist/components/AreaChart/AreaChart.d.ts +3 -0
  4. package/dist/components/AreaChart/AreaChart.js +14 -0
  5. package/dist/components/AreaChart/index.d.ts +1 -0
  6. package/dist/components/BarChart/BarChart.d.ts +3 -0
  7. package/dist/components/BarChart/BarChart.js +134 -0
  8. package/dist/components/BarChart/index.d.ts +1 -0
  9. package/dist/components/Chart/ChartAxes.d.ts +2 -0
  10. package/dist/components/Chart/ChartAxes.js +28 -0
  11. package/dist/components/Chart/ChartFrame.d.ts +7 -0
  12. package/dist/components/Chart/ChartFrame.js +108 -0
  13. package/dist/components/Chart/ChartPatterns.d.ts +3 -0
  14. package/dist/components/Chart/ChartPatterns.js +27 -0
  15. package/dist/components/Chart/ChartPlot.d.ts +2 -0
  16. package/dist/components/Chart/ChartPlot.js +101 -0
  17. package/dist/components/Chart/LinearChart.d.ts +3 -0
  18. package/dist/components/Chart/LinearChart.js +133 -0
  19. package/dist/components/Chart/RadialChart.d.ts +20 -0
  20. package/dist/components/Chart/RadialChart.js +112 -0
  21. package/dist/components/Chart/index.module.js +38 -0
  22. package/dist/components/Chart/math.d.ts +19 -0
  23. package/dist/components/Chart/math.js +82 -0
  24. package/dist/components/Chart/useChartSize.d.ts +3 -0
  25. package/dist/components/Chart/useChartSize.js +24 -0
  26. package/dist/components/DonutChart/DonutChart.d.ts +19 -0
  27. package/dist/components/DonutChart/DonutChart.js +12 -0
  28. package/dist/components/DonutChart/index.d.ts +1 -0
  29. package/dist/components/LineChart/LineChart.d.ts +3 -0
  30. package/dist/components/LineChart/LineChart.js +14 -0
  31. package/dist/components/LineChart/index.d.ts +1 -0
  32. package/dist/components/PieChart/PieChart.d.ts +17 -0
  33. package/dist/components/PieChart/PieChart.js +12 -0
  34. package/dist/components/PieChart/index.d.ts +1 -0
  35. package/dist/components/Sparkline/Sparkline.d.ts +7 -0
  36. package/dist/components/Sparkline/Sparkline.js +56 -0
  37. package/dist/components/Sparkline/index.d.ts +1 -0
  38. package/dist/components/Sparkline/index.module.js +9 -0
  39. package/dist/components/Table/Table.js +145 -34
  40. package/dist/components/Table/TableSelectAll.d.ts +9 -0
  41. package/dist/components/Table/TableSelectAll.js +18 -0
  42. package/dist/components/Table/index.module.js +14 -3
  43. package/dist/index.d.ts +13 -1
  44. package/dist/index.js +66 -60
  45. package/dist/styles.css +1 -1
  46. package/dist/types/areaChartType.d.ts +5 -0
  47. package/dist/types/barChartType.d.ts +8 -0
  48. package/dist/types/chartType.d.ts +156 -0
  49. package/dist/types/donutChartType.d.ts +6 -0
  50. package/dist/types/index.d.ts +8 -1
  51. package/dist/types/lineChartType.d.ts +5 -0
  52. package/dist/types/pieChartType.d.ts +2 -0
  53. package/dist/types/sparklineType.d.ts +14 -0
  54. package/dist/types/tableType.d.ts +71 -3
  55. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,29 @@
2
2
 
3
3
  All notable changes to `@lucasromero/matrix-ui` are recorded here. Matrix UI follows [Semantic Versioning](https://semver.org). While the version is below 1.0.0, a minor release may include breaking changes, and they are listed here.
4
4
 
5
+ ## 0.12.0
6
+
7
+ ### Added
8
+
9
+ - Table sorting: a column's `sortable` makes its header a button, and `sort` and `onSortChange` show and change the order. The sorted column is announced with `aria-sort`. Table does not reorder rows; the application sorts them.
10
+ - Table row selection: `selectedKeys` and `onSelectionChange` add a checkbox to each row, named by its row header, and a "Select all rows" checkbox that shows when only some rows are selected. `selectAllLabel` and `getSelectLabel` change their names.
11
+ - Table row actions: `rowActions` adds buttons to each row, named with the row header, which move into one menu per row on screens 640px wide and narrower. `actionsLabel` names the actions column.
12
+ - Table columns for narrow screens: `hideOnMobile` hides a column on screens 640px wide and narrower, and `noWrap` keeps short values, such as dates, on one line.
13
+ - `--matrix-table-selected-background`, `--matrix-table-focus-color`, `--matrix-table-sort-icon-color`, and `--matrix-table-danger-color` adjust the new parts.
14
+ - `TableSort`, `TableSortDirection`, and `TableRowAction` types.
15
+
16
+ Tables that use none of these look and behave as before, and still work in Server Components.
17
+
18
+ ## 0.11.0
19
+
20
+ ### Added
21
+
22
+ - Charts: `LineChart`, `AreaChart`, `BarChart`, `PieChart`, `DonutChart`, and `Sparkline`. They are drawn with SVG and add no dependencies.
23
+ - Values can be read on hover, by touch, and with the arrow keys, and every chart except `Sparkline` includes its data as a table for assistive technology, which `showTable` shows to everyone.
24
+ - A chart palette, `--matrix-chart-color-1` to `--matrix-chart-color-8`, in light and dark.
25
+ - `--matrix-chart-background`, `--matrix-chart-grid-color`, `--matrix-chart-axis-color`, `--matrix-chart-active-background`, and `--matrix-chart-focus-color` adjust charts.
26
+ - `ChartColor`, `ChartSeries`, `ChartSlice`, and `BarChartOrientation` types, with a props type for each chart.
27
+
5
28
  ## 0.10.0
6
29
 
7
30
  ### Added
package/README.md CHANGED
@@ -82,6 +82,7 @@ Light is the default theme. Add `data-matrix-theme="dark"` to `html` for a dark
82
82
  | Overlays | Dialog, Drawer, DropdownMenu, Popover, Tooltip |
83
83
  | Feedback | Alert, EmptyState, Progress, Skeleton, Spinner, Toast |
84
84
  | Data display | Avatar, AvatarGroup, Badge, CodeBlock, DescriptionList, Table |
85
+ | Charts | AreaChart, BarChart, DonutChart, LineChart, PieChart, Sparkline |
85
86
  | Utilities | VisuallyHidden |
86
87
 
87
88
  The hooks `useDisclosure` and `useMediaQuery` are exported too.
@@ -0,0 +1,3 @@
1
+ import { type ReactElement, type RefAttributes } from "react";
2
+ import type { AreaChartProps } from "../../types/areaChartType.js";
3
+ export declare const AreaChart: <Row extends object>(props: AreaChartProps<Row> & RefAttributes<HTMLElement>) => ReactElement | null;
@@ -0,0 +1,14 @@
1
+ "use client";
2
+ import { LinearChart as e } from "../Chart/LinearChart.js";
3
+ import { forwardRef as t } from "react";
4
+ import { jsx as n } from "react/jsx-runtime";
5
+ var r = t(({ stacked: t = !1, ...r }, i) => /* @__PURE__ */ n(e, {
6
+ ...r,
7
+ ref: i,
8
+ kind: "area",
9
+ includeZero: !0,
10
+ stacked: t
11
+ }));
12
+ r.displayName = "AreaChart";
13
+ var i = r;
14
+ export { i as AreaChart };
@@ -0,0 +1 @@
1
+ export { AreaChart } from "./AreaChart.js";
@@ -0,0 +1,3 @@
1
+ import { type ReactElement, type RefAttributes } from "react";
2
+ import type { BarChartProps } from "../../types/barChartType.js";
3
+ export declare const BarChart: <Row extends object>(props: BarChartProps<Row> & RefAttributes<HTMLElement>) => ReactElement | null;
@@ -0,0 +1,134 @@
1
+ "use client";
2
+ import { ChartAxes as e } from "../Chart/ChartAxes.js";
3
+ import { ChartFrame as t } from "../Chart/ChartFrame.js";
4
+ import { ChartPlot as n } from "../Chart/ChartPlot.js";
5
+ import { barPath as r, createScale as i, fitText as a, formatNumber as o, formatTicks as s, readSeries as c, scaleRatio as l, stackSeries as u, textWidth as d } from "../Chart/math.js";
6
+ import f from "../Chart/index.module.js";
7
+ import { forwardRef as p, useId as m } from "react";
8
+ import { Fragment as h, jsx as g, jsxs as _ } from "react/jsx-runtime";
9
+ // src/components/BarChart/BarChart.tsx
10
+ var v = 2, y = 24, b = p(({ orientation: p = "vertical", stacked: b = !1, data: x, categoryKey: S, series: C, label: w, height: T = 240, formatValue: E = o, formatCategory: D = (e) => e, formatAxisValue: O, categoryLabel: k = "Category", showLegend: A = C.length > 1, keyboardHint: j = "Use the arrow keys to read each value.", ...M }, N) => {
11
+ let P = m(), F = p === "vertical", I = x.map((e) => D(String(e[S]))), L = c(x, C), R = b ? u(L, x.length) : null, z = L.map(({ values: e }, t) => R ? R[t] : e.map((e) => ({
12
+ start: 0,
13
+ end: e ?? 0
14
+ }))), B = z.flat().map(({ end: e }) => e), V = L.every(({ values: e }) => e.every((e) => e === null)), H = i(Math.min(0, ...B), Math.max(0, ...B)), U = O ?? (E === o ? s(H) : E), W = (e) => {
15
+ let t = H.ticks.map((t) => d(U(t), e.fontSize)), n = Math.min(Math.max(0, ...I.map((t) => d(t, e.fontSize))), e.width * .35), r = Math.ceil(F ? Math.max(...t) : n) + 12, i = F ? 4 : Math.ceil(t[t.length - 1] / 2) + 4, a = {
16
+ left: r,
17
+ top: 10,
18
+ width: Math.max(1, e.width - r - i),
19
+ height: Math.max(1, T - 10 - e.fontSize * 2)
20
+ }, o = (F ? a.width : a.height) / Math.max(1, I.length), s = F ? a.left : a.top;
21
+ return {
22
+ box: a,
23
+ band: o,
24
+ positions: I.map((e, t) => s + o * (t + .5))
25
+ };
26
+ };
27
+ return /* @__PURE__ */ g(t, {
28
+ ...M,
29
+ ref: N,
30
+ label: w,
31
+ patternId: P,
32
+ isEmpty: V,
33
+ legend: A ? L.map((e) => ({
34
+ label: e.label,
35
+ color: e.color,
36
+ slot: e.slot,
37
+ mark: "fill"
38
+ })) : [],
39
+ table: {
40
+ headers: [k, ...L.map((e) => e.label)],
41
+ rows: I.map((e, t) => [e, ...L.map(({ values: e }) => {
42
+ let n = e[t];
43
+ return n === null ? "" : E(n);
44
+ })])
45
+ },
46
+ children: /* @__PURE__ */ g(n, {
47
+ label: w,
48
+ height: T,
49
+ hint: j,
50
+ count: I.length,
51
+ patternId: P,
52
+ findIndex: ({ x: e, y: t }, n) => {
53
+ let { box: r, band: i } = W(n), a = Math.floor(F ? (e - r.left) / i : (t - r.top) / i);
54
+ return a >= 0 && a < I.length ? a : null;
55
+ },
56
+ getAnchor: (e, t) => {
57
+ let { box: n, positions: r } = W(t);
58
+ return F ? {
59
+ x: r[e],
60
+ y: 8
61
+ } : {
62
+ x: n.left + n.width / 2,
63
+ y: Math.max(0, r[e] - t.fontSize)
64
+ };
65
+ },
66
+ getTooltip: (e) => ({
67
+ title: I[e],
68
+ rows: L.flatMap(({ label: t, color: n, values: r }) => {
69
+ let i = r[e];
70
+ return i === null ? [] : [{
71
+ label: t,
72
+ value: E(i),
73
+ color: n
74
+ }];
75
+ })
76
+ }),
77
+ render: (t, n) => {
78
+ let { box: i, band: o, positions: s } = W(t), c = R ? 1 : Math.max(1, L.length), u = Math.max(1, Math.min(y, (o * .7 - v * (c - 1)) / c)), d = u * c + v * (c - 1), p = F ? i.height : i.width, m = (e) => l(e, H) * p;
79
+ return /* @__PURE__ */ _(h, { children: [
80
+ n !== null && /* @__PURE__ */ g("rect", {
81
+ className: f.band,
82
+ x: F ? s[n] - o / 2 : i.left,
83
+ y: F ? i.top : s[n] - o / 2,
84
+ width: F ? o : i.width,
85
+ height: F ? i.height : o
86
+ }),
87
+ F ? /* @__PURE__ */ g(e, {
88
+ box: i,
89
+ scale: H,
90
+ size: t,
91
+ categories: I,
92
+ positions: s,
93
+ formatTick: U,
94
+ alignEnds: !1
95
+ }) : /* @__PURE__ */ _(h, { children: [H.ticks.map((e) => {
96
+ let n = i.left + m(e);
97
+ return /* @__PURE__ */ _("g", { children: [/* @__PURE__ */ g("path", {
98
+ className: e === 0 ? f.baseline : f.grid,
99
+ d: `M${n},${i.top}V${i.top + i.height}`
100
+ }), /* @__PURE__ */ g("text", {
101
+ className: f.tick,
102
+ x: n,
103
+ y: i.top + i.height + t.fontSize + 8,
104
+ textAnchor: "middle",
105
+ children: U(e)
106
+ })] }, e);
107
+ }), I.map((e, n) => /* @__PURE__ */ g("text", {
108
+ className: f.tick,
109
+ x: i.left - 8,
110
+ y: s[n],
111
+ dy: "0.35em",
112
+ textAnchor: "end",
113
+ children: a(e, i.left - 12, t.fontSize)
114
+ }, n))] }),
115
+ L.map(({ color: e, slot: t, values: n }, a) => /* @__PURE__ */ g("g", { children: n.map((n, o) => {
116
+ if (!n) return null;
117
+ let { start: c, end: l } = z[a][o], p = m(Math.min(c, l)), h = m(Math.max(c, l)) - p, y = !R || !L.slice(a + 1).some((e) => (e.values[o] ?? 0) * n > 0), b = R && !y ? Math.min(v, h / 2) : 0, x = h - b, S = s[o] - d / 2 + (R ? 0 : a * (u + v)), C = n > 0, w = F ? r(S, i.top + i.height - p - h + (C ? b : 0), u, x, y ? C ? "top" : "bottom" : "none") : r(i.left + p + (C ? 0 : b), S, x, u, y ? C ? "right" : "left" : "none");
118
+ return /* @__PURE__ */ _("g", { children: [/* @__PURE__ */ g("path", {
119
+ style: { fill: e },
120
+ d: w
121
+ }), /* @__PURE__ */ g("path", {
122
+ className: f.pattern,
123
+ fill: `url(#${P}-${(t - 1) % 8 + 1})`,
124
+ d: w
125
+ })] }, o);
126
+ }) }, a))
127
+ ] });
128
+ }
129
+ })
130
+ });
131
+ });
132
+ b.displayName = "BarChart";
133
+ var x = b;
134
+ export { x as BarChart };
@@ -0,0 +1 @@
1
+ export { BarChart } from "./BarChart.js";
@@ -0,0 +1,2 @@
1
+ import type { ChartAxesProps } from "../../types/chartType.js";
2
+ export declare function ChartAxes({ box, scale, size, categories, positions, formatTick, alignEnds, }: ChartAxesProps): import("react").JSX.Element;
@@ -0,0 +1,28 @@
1
+ import { fitText as e, scaleRatio as t, textWidth as n } from "./math.js";
2
+ import r from "./index.module.js";
3
+ import { Fragment as i, jsx as a, jsxs as o } from "react/jsx-runtime";
4
+ // src/components/Chart/ChartAxes.tsx
5
+ function s({ box: s, scale: c, size: l, categories: u, positions: d, formatTick: f, alignEnds: p }) {
6
+ let m = Math.max(0, ...u.map((e) => n(e, l.fontSize))), h = d.length > 1 ? d[1] - d[0] : s.width, g = !p && h > l.fontSize * 4 ? 1 : Math.max(1, Math.ceil((m + 12) / h)), _ = d.length - 1;
7
+ return /* @__PURE__ */ o(i, { children: [c.ticks.map((e) => {
8
+ let n = s.top + s.height * (1 - t(e, c));
9
+ return /* @__PURE__ */ o("g", { children: [/* @__PURE__ */ a("path", {
10
+ className: e === 0 ? r.baseline : r.grid,
11
+ d: `M${s.left},${n}H${s.left + s.width}`
12
+ }), /* @__PURE__ */ a("text", {
13
+ className: r.tick,
14
+ x: s.left - 8,
15
+ y: n,
16
+ dy: "0.35em",
17
+ textAnchor: "end",
18
+ children: f(e)
19
+ })] }, e);
20
+ }), u.map((t, n) => n % g === 0 ? /* @__PURE__ */ a("text", {
21
+ className: r.tick,
22
+ x: d[n],
23
+ y: s.top + s.height + l.fontSize + 8,
24
+ textAnchor: !p || _ === 0 ? "middle" : n === 0 ? "start" : n === _ ? "end" : "middle",
25
+ children: e(t, Math.max(h * g - 8, l.fontSize * 2), l.fontSize)
26
+ }, n) : null)] });
27
+ }
28
+ export { s as ChartAxes };
@@ -0,0 +1,7 @@
1
+ export declare const ChartFrame: import("react").ForwardRefExoticComponent<Omit<import("../../types/chartType.js").ChartBaseProps, "height" | "formatValue" | "categoryLabel" | "keyboardHint"> & {
2
+ children: import("react").ReactNode;
3
+ legend: import("../../types/chartType.js").ChartLegendItem[];
4
+ patternId: string;
5
+ table: import("../../types/chartType.js").ChartTable;
6
+ isEmpty: boolean;
7
+ } & import("react").RefAttributes<HTMLElement>>;
@@ -0,0 +1,108 @@
1
+ "use client";
2
+ import { Inline as e } from "../Inline/Inline.js";
3
+ import { Table as t } from "../Table/Table.js";
4
+ import { Text as n } from "../Text/Text.js";
5
+ import { VisuallyHidden as r } from "../VisuallyHidden/VisuallyHidden.js";
6
+ import { markerPath as i } from "./math.js";
7
+ import a from "./index.module.js";
8
+ import { forwardRef as o, useId as s } from "react";
9
+ import { Fragment as c, jsx as l, jsxs as u } from "react/jsx-runtime";
10
+ // src/components/Chart/ChartFrame.tsx
11
+ function d({ item: e, patternId: t }) {
12
+ return /* @__PURE__ */ l("svg", {
13
+ className: a.swatch,
14
+ viewBox: "0 0 16 12",
15
+ "aria-hidden": "true",
16
+ children: e.mark === "line" ? /* @__PURE__ */ u(c, { children: [/* @__PURE__ */ l("path", {
17
+ className: a.line,
18
+ style: { stroke: e.color },
19
+ d: "M0,6H16"
20
+ }), /* @__PURE__ */ l("path", {
21
+ style: { fill: e.color },
22
+ d: i(e.slot, 8, 6, 3.5)
23
+ })] }) : /* @__PURE__ */ u(c, { children: [/* @__PURE__ */ l("rect", {
24
+ style: { fill: e.color },
25
+ width: "16",
26
+ height: "12",
27
+ rx: "3"
28
+ }), /* @__PURE__ */ l("rect", {
29
+ className: a.pattern,
30
+ fill: `url(#${t}-${(e.slot - 1) % 8 + 1})`,
31
+ width: "16",
32
+ height: "12",
33
+ rx: "3"
34
+ })] })
35
+ });
36
+ }
37
+ var f = o(({ label: i, hideLabel: o = !1, legend: f, patternId: p, patterns: m = !1, table: h, showTable: g = !1, isEmpty: _, emptyMessage: v = "No data to show", className: y, children: b, ...x }, S) => {
38
+ let C = s(), w = h.rows.map((e, t) => ({
39
+ cells: e,
40
+ index: t
41
+ })), T = /* @__PURE__ */ l(t, {
42
+ "aria-label": i,
43
+ columns: h.headers.map((e, t) => ({
44
+ key: `${t}`,
45
+ header: e,
46
+ rowHeader: t === 0,
47
+ cell: (e) => e.cells[t]
48
+ })),
49
+ rows: w,
50
+ getRowKey: (e) => e.index
51
+ });
52
+ return /* @__PURE__ */ u("figure", {
53
+ "aria-labelledby": C,
54
+ ...x,
55
+ ref: S,
56
+ className: [
57
+ a.chart,
58
+ m && a.withPatterns,
59
+ y
60
+ ].filter(Boolean).join(" "),
61
+ children: [/* @__PURE__ */ l("figcaption", {
62
+ id: C,
63
+ className: o ? a.hiddenCaption : a.caption,
64
+ children: o ? /* @__PURE__ */ l(r, { children: i }) : /* @__PURE__ */ l(n, {
65
+ variant: "label",
66
+ className: a.label,
67
+ children: i
68
+ })
69
+ }), _ ? /* @__PURE__ */ l(n, {
70
+ variant: "muted",
71
+ className: a.empty,
72
+ children: v
73
+ }) : /* @__PURE__ */ u(c, { children: [
74
+ f.length > 0 && /* @__PURE__ */ l(e, {
75
+ as: "ul",
76
+ align: "stretch",
77
+ className: a.legend,
78
+ children: f.map((e, t) => /* @__PURE__ */ u("li", {
79
+ className: a.legendItem,
80
+ children: [
81
+ /* @__PURE__ */ l(d, {
82
+ item: e,
83
+ patternId: p
84
+ }),
85
+ /* @__PURE__ */ l("span", { children: e.label }),
86
+ e.value && /* @__PURE__ */ l("span", {
87
+ className: a.legendValue,
88
+ children: e.value
89
+ })
90
+ ]
91
+ }, t))
92
+ }),
93
+ b,
94
+ g ? /* @__PURE__ */ l("div", {
95
+ className: a.table,
96
+ role: "region",
97
+ "aria-label": i,
98
+ tabIndex: 0,
99
+ children: T
100
+ }) : /* @__PURE__ */ l("div", {
101
+ className: a.hiddenTable,
102
+ children: T
103
+ })
104
+ ] })]
105
+ });
106
+ });
107
+ f.displayName = "ChartFrame";
108
+ export { f as ChartFrame };
@@ -0,0 +1,3 @@
1
+ export declare function ChartPatterns({ id }: {
2
+ id: string;
3
+ }): import("react").JSX.Element;
@@ -0,0 +1,27 @@
1
+ import e from "./index.module.js";
2
+ import { jsx as t, jsxs as n } from "react/jsx-runtime";
3
+ // src/components/Chart/ChartPatterns.tsx
4
+ var r = ["M-2,2l4,-4M0,8l8,-8M6,10l4,-4", "M-2,6l4,4M0,0l8,8M6,-2l4,4"];
5
+ function i({ id: i }) {
6
+ return /* @__PURE__ */ t("defs", { children: Array.from({ length: 8 }, (a, o) => /* @__PURE__ */ n("pattern", {
7
+ id: `${i}-${o + 1}`,
8
+ width: 8,
9
+ height: 8,
10
+ patternUnits: "userSpaceOnUse",
11
+ patternTransform: o >= 4 ? "scale(0.6)" : void 0,
12
+ children: [o % 4 != 0 && /* @__PURE__ */ t("path", {
13
+ className: e.patternLine,
14
+ d: [
15
+ r[0],
16
+ r[1],
17
+ r.join("")
18
+ ][o % 4 - 1]
19
+ }), o === 4 && /* @__PURE__ */ t("circle", {
20
+ className: e.patternDot,
21
+ cx: 4,
22
+ cy: 4,
23
+ r: 2
24
+ })]
25
+ }, o)) });
26
+ }
27
+ export { i as ChartPatterns };
@@ -0,0 +1,2 @@
1
+ import type { ChartPlotProps } from "../../types/chartType.js";
2
+ export declare function ChartPlot({ label, height, hint, count, patternId, findIndex, getAnchor, getTooltip, render, overlay, }: ChartPlotProps): import("react").JSX.Element;
@@ -0,0 +1,101 @@
1
+ "use client";
2
+ import { VisuallyHidden as e } from "../VisuallyHidden/VisuallyHidden.js";
3
+ import { ChartPatterns as t } from "./ChartPatterns.js";
4
+ import { useChartSize as n } from "./useChartSize.js";
5
+ import r from "./index.module.js";
6
+ import { useId as i, useRef as a, useState as o } from "react";
7
+ import { jsx as s, jsxs as c } from "react/jsx-runtime";
8
+ // src/components/Chart/ChartPlot.tsx
9
+ var l = (e) => {
10
+ try {
11
+ return e.matches(":focus-visible");
12
+ } catch {
13
+ return !1;
14
+ }
15
+ };
16
+ function u({ label: u, height: d, hint: f, count: p, patternId: m, findIndex: h, getAnchor: g, getTooltip: _, render: v, overlay: y }) {
17
+ let b = i(), x = a(null), S = n(x), [C, w] = o(null), [T, E] = o(!1), D = C !== null && C < p ? C : null, O = D === null ? null : _(D), k = D === null ? null : g(D, S), A = (e, t) => {
18
+ w(e), E(t && e !== null);
19
+ }, j = (e) => {
20
+ let t = e.currentTarget.getBoundingClientRect(), n = {
21
+ x: e.clientX - t.left,
22
+ y: e.clientY - t.top
23
+ };
24
+ A(h(n, S), !1);
25
+ };
26
+ return /* @__PURE__ */ c("div", {
27
+ className: r.plotArea,
28
+ children: [
29
+ /* @__PURE__ */ c("div", {
30
+ ref: x,
31
+ className: r.plot,
32
+ style: { height: d },
33
+ tabIndex: 0,
34
+ role: "img",
35
+ "aria-label": u,
36
+ "aria-describedby": b,
37
+ onKeyDown: (e) => {
38
+ let t = p - 1, n = {
39
+ ArrowRight: D === null ? 0 : Math.min(D + 1, t),
40
+ ArrowDown: D === null ? 0 : Math.min(D + 1, t),
41
+ ArrowLeft: D === null ? t : Math.max(D - 1, 0),
42
+ ArrowUp: D === null ? t : Math.max(D - 1, 0),
43
+ Home: 0,
44
+ End: t
45
+ }[e.key];
46
+ n === void 0 ? e.key === "Escape" && D !== null && (e.stopPropagation(), A(null, !1)) : (e.preventDefault(), A(n, !0));
47
+ },
48
+ onFocus: (e) => {
49
+ D === null && l(e.currentTarget) && A(0, !0);
50
+ },
51
+ onBlur: () => A(null, !1),
52
+ onPointerMove: j,
53
+ onPointerDown: j,
54
+ onPointerLeave: (e) => {
55
+ e.pointerType !== "touch" && A(null, !1);
56
+ },
57
+ children: [/* @__PURE__ */ c("svg", {
58
+ className: r.svg,
59
+ viewBox: `0 0 ${S.width} ${d}`,
60
+ "aria-hidden": "true",
61
+ focusable: "false",
62
+ children: [/* @__PURE__ */ s(t, { id: m }), v(S, D)]
63
+ }), O && k && /* @__PURE__ */ c("div", {
64
+ className: r.tooltip,
65
+ style: {
66
+ left: k.x,
67
+ top: k.y,
68
+ transform: `translate(${k.x > S.width / 2 ? "calc(-100% - 0.75rem)" : "0.75rem"}, 0)`
69
+ },
70
+ children: [O.title && /* @__PURE__ */ s("span", {
71
+ className: r.tooltipTitle,
72
+ children: O.title
73
+ }), O.rows.map((e, t) => /* @__PURE__ */ c("span", {
74
+ className: r.tooltipRow,
75
+ children: [
76
+ /* @__PURE__ */ s("span", {
77
+ className: r.tooltipKey,
78
+ style: { background: e.color }
79
+ }),
80
+ /* @__PURE__ */ s("span", {
81
+ className: r.tooltipValue,
82
+ children: e.value
83
+ }),
84
+ /* @__PURE__ */ s("span", { children: e.label })
85
+ ]
86
+ }, t))]
87
+ })]
88
+ }),
89
+ y,
90
+ /* @__PURE__ */ s(e, {
91
+ id: b,
92
+ children: f
93
+ }),
94
+ /* @__PURE__ */ s(e, {
95
+ role: "status",
96
+ children: T && O && `${O.title ? `${O.title}: ` : ""}${O.rows.map((e) => `${e.label} ${e.value}`).join(", ")}`
97
+ })
98
+ ]
99
+ });
100
+ }
101
+ export { u as ChartPlot };
@@ -0,0 +1,3 @@
1
+ import { type ReactElement, type RefAttributes } from "react";
2
+ import type { LinearChartBaseProps } from "../../types/chartType.js";
3
+ export declare const LinearChart: <Row extends object>(props: LinearChartBaseProps<Row> & RefAttributes<HTMLElement>) => ReactElement | null;
@@ -0,0 +1,133 @@
1
+ "use client";
2
+ import { ChartAxes as e } from "./ChartAxes.js";
3
+ import { ChartFrame as t } from "./ChartFrame.js";
4
+ import { ChartPlot as n } from "./ChartPlot.js";
5
+ import { createScale as r, formatNumber as i, formatTicks as a, linePath as o, markerPath as s, readSeries as c, scaleRatio as l, splitAtGaps as u, stackSeries as d, textWidth as f } from "./math.js";
6
+ import p from "./index.module.js";
7
+ import { forwardRef as m, useId as h } from "react";
8
+ import { Fragment as g, jsx as _, jsxs as v } from "react/jsx-runtime";
9
+ var y = m(({ kind: m, includeZero: y, stacked: b, data: x, categoryKey: S, series: C, label: w, height: T = 240, formatValue: E = i, formatCategory: D = (e) => e, formatAxisValue: O, categoryLabel: k = "Category", showLegend: A = C.length > 1, keyboardHint: j = "Use the arrow keys to read each value.", ...M }, N) => {
10
+ let P = h(), F = m === "area", I = x.map((e) => D(String(e[S]))), L = c(x, C), R = b ? d(L, x.length) : null, z = L.map(({ values: e }, t) => R ? R[t].map(({ end: e }) => e) : e), B = z.flat().filter((e) => e !== null), V = L.every(({ values: e }) => e.every((e) => e === null)), H = r(Math.min(...B, ...y || B.length === 0 ? [0] : []), Math.max(...B, ...y || B.length === 0 ? [0] : [])), U = O ?? (E === i ? a(H) : E), W = (e) => {
11
+ let t = Math.max(...H.ticks.map((t) => f(U(t), e.fontSize))), n = Math.ceil(t) + 12, r = {
12
+ left: n,
13
+ top: 10,
14
+ width: Math.max(1, e.width - n - 10),
15
+ height: Math.max(1, T - 10 - e.fontSize * 2)
16
+ };
17
+ return {
18
+ box: r,
19
+ positions: I.map((e, t) => I.length === 1 ? r.left + r.width / 2 : r.left + t * r.width / (I.length - 1))
20
+ };
21
+ };
22
+ return /* @__PURE__ */ _(t, {
23
+ ...M,
24
+ ref: N,
25
+ label: w,
26
+ patternId: P,
27
+ isEmpty: V,
28
+ legend: A ? L.map((e) => ({
29
+ label: e.label,
30
+ color: e.color,
31
+ slot: e.slot,
32
+ mark: "line"
33
+ })) : [],
34
+ table: {
35
+ headers: [k, ...L.map((e) => e.label)],
36
+ rows: I.map((e, t) => [e, ...L.map(({ values: e }) => {
37
+ let n = e[t];
38
+ return n === null ? "" : E(n);
39
+ })])
40
+ },
41
+ children: /* @__PURE__ */ _(n, {
42
+ label: w,
43
+ height: T,
44
+ hint: j,
45
+ count: I.length,
46
+ patternId: P,
47
+ findIndex: ({ x: e }, t) => {
48
+ let { positions: n } = W(t);
49
+ return n.reduce((t, r, i) => Math.abs(r - e) < Math.abs(n[t] - e) ? i : t, 0);
50
+ },
51
+ getAnchor: (e, t) => ({
52
+ x: W(t).positions[e],
53
+ y: 8
54
+ }),
55
+ getTooltip: (e) => ({
56
+ title: I[e],
57
+ rows: L.flatMap(({ label: t, color: n, values: r }) => {
58
+ let i = r[e];
59
+ return i === null ? [] : [{
60
+ label: t,
61
+ value: E(i),
62
+ color: n
63
+ }];
64
+ })
65
+ }),
66
+ render: (t, n) => {
67
+ let { box: r, positions: i } = W(t), a = (e) => r.top + r.height * (1 - l(e, H)), c = a(Math.min(Math.max(0, H.min), H.max)), d = (e) => z[e].map((e, t) => e === null ? null : {
68
+ x: i[t],
69
+ y: a(e)
70
+ });
71
+ return /* @__PURE__ */ v(g, { children: [
72
+ /* @__PURE__ */ _(e, {
73
+ box: r,
74
+ scale: H,
75
+ size: t,
76
+ categories: I,
77
+ positions: i,
78
+ formatTick: U,
79
+ alignEnds: !0
80
+ }),
81
+ n !== null && /* @__PURE__ */ _("path", {
82
+ className: p.crosshair,
83
+ d: `M${i[n]},${r.top}V${r.top + r.height}`
84
+ }),
85
+ F && L.map(({ color: e, slot: t }, n) => u(d(n)).map((r, s) => {
86
+ let l = R ? R[n].map(({ start: e }, t) => ({
87
+ x: i[t],
88
+ y: a(e)
89
+ })) : [{
90
+ x: r[0].x,
91
+ y: c
92
+ }, {
93
+ x: r[r.length - 1].x,
94
+ y: c
95
+ }], u = `${o([...r, ...l.reverse()])}Z`;
96
+ return /* @__PURE__ */ v("g", { children: [/* @__PURE__ */ _("path", {
97
+ className: R ? p.stackedArea : p.area,
98
+ style: { fill: e },
99
+ d: u
100
+ }), /* @__PURE__ */ _("path", {
101
+ className: p.pattern,
102
+ fill: `url(#${P}-${(t - 1) % 8 + 1})`,
103
+ d: u
104
+ })] }, `${n}-${s}`);
105
+ })),
106
+ L.map(({ color: e, slot: t }, n) => u(d(n)).map((r, i) => r.length === 1 ? /* @__PURE__ */ _("path", {
107
+ className: p.marker,
108
+ style: { fill: e },
109
+ d: s(t, r[0].x, r[0].y, 4)
110
+ }, `${n}-${i}`) : /* @__PURE__ */ _("path", {
111
+ className: p.line,
112
+ style: { stroke: e },
113
+ d: o(r)
114
+ }, `${n}-${i}`))),
115
+ L.map(({ color: e, slot: t, values: r }, o) => {
116
+ let c = r.reduce((e, t, n) => t === null ? e : n, -1);
117
+ return [.../* @__PURE__ */ new Set([c, n ?? c])].map((n) => {
118
+ let c = n < 0 || r[n] === null ? null : z[o][n];
119
+ return c === null ? null : /* @__PURE__ */ _("path", {
120
+ className: p.marker,
121
+ style: { fill: e },
122
+ d: s(t, i[n], a(c), 4)
123
+ }, `${o}-${n}`);
124
+ });
125
+ })
126
+ ] });
127
+ }
128
+ })
129
+ });
130
+ });
131
+ y.displayName = "LinearChart";
132
+ var b = y;
133
+ export { b as LinearChart };
@@ -0,0 +1,20 @@
1
+ export declare const RadialChart: import("react").ForwardRefExoticComponent<Omit<import("react").HTMLAttributes<HTMLElement>, "children"> & {
2
+ label: string;
3
+ hideLabel?: boolean;
4
+ height?: number;
5
+ formatValue?: (value: number) => string;
6
+ showTable?: boolean;
7
+ categoryLabel?: string;
8
+ patterns?: boolean;
9
+ emptyMessage?: import("react").ReactNode;
10
+ keyboardHint?: string;
11
+ } & {
12
+ data: readonly import("../../index.js").ChartSlice[];
13
+ valueLabel?: string;
14
+ shareLabel?: string;
15
+ formatShare?: (share: number) => string;
16
+ showLegend?: boolean;
17
+ } & {
18
+ innerRatio: number;
19
+ center?: import("react").ReactNode;
20
+ } & import("react").RefAttributes<HTMLElement>>;