@adecore/charts 0.0.0-stage → 0.34.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.
Files changed (108) hide show
  1. package/LICENSE +110 -0
  2. package/README.md +59 -2
  3. package/dist/Heatmap.d.ts +27 -0
  4. package/dist/Heatmap.js +455 -0
  5. package/dist/Root.d.ts +35 -0
  6. package/dist/Root.js +1126 -0
  7. package/dist/SeriesLegend.d.ts +32 -0
  8. package/dist/SeriesLegend.js +301 -0
  9. package/dist/Sparkline.d.ts +14 -0
  10. package/dist/Sparkline.js +179 -0
  11. package/dist/access.d.ts +6 -0
  12. package/dist/access.js +30 -0
  13. package/dist/annotations.d.ts +30 -0
  14. package/dist/annotations.js +556 -0
  15. package/dist/axes.d.ts +47 -0
  16. package/dist/axes.js +743 -0
  17. package/dist/band.d.ts +50 -0
  18. package/dist/band.js +181 -0
  19. package/dist/color.d.ts +3 -0
  20. package/dist/color.js +19 -0
  21. package/dist/context.d.ts +94 -0
  22. package/dist/context.js +13 -0
  23. package/dist/create-chart.d.ts +18 -0
  24. package/dist/create-chart.js +5 -0
  25. package/dist/cursor.d.ts +5 -0
  26. package/dist/cursor.js +93 -0
  27. package/dist/group-axes.d.ts +9 -0
  28. package/dist/group-axes.js +86 -0
  29. package/dist/heat.d.ts +9 -0
  30. package/dist/heat.js +75 -0
  31. package/dist/index.d.ts +18 -0
  32. package/dist/index.js +9 -0
  33. package/dist/index.parts.d.ts +30 -0
  34. package/dist/index.parts.js +27 -0
  35. package/dist/layer.d.ts +15 -0
  36. package/dist/layer.js +118 -0
  37. package/dist/legend.d.ts +3 -0
  38. package/dist/legend.js +11 -0
  39. package/dist/locales/en.d.ts +39 -0
  40. package/dist/locales/en.js +38 -0
  41. package/dist/locales/nl.d.ts +39 -0
  42. package/dist/locales/nl.js +38 -0
  43. package/dist/locales.d.ts +2 -0
  44. package/dist/locales.js +10 -0
  45. package/dist/overlays.d.ts +49 -0
  46. package/dist/overlays.js +835 -0
  47. package/dist/points.d.ts +12 -0
  48. package/dist/points.js +105 -0
  49. package/dist/register.d.ts +12 -0
  50. package/dist/register.js +74 -0
  51. package/dist/scale.d.ts +34 -0
  52. package/dist/scale.js +278 -0
  53. package/dist/scatter.d.ts +24 -0
  54. package/dist/scatter.js +282 -0
  55. package/dist/series.d.ts +60 -0
  56. package/dist/series.js +1041 -0
  57. package/dist/spark.d.ts +9 -0
  58. package/dist/spark.js +29 -0
  59. package/dist/store.d.ts +70 -0
  60. package/dist/store.js +119 -0
  61. package/dist/time-format.d.ts +3 -0
  62. package/dist/time-format.js +23 -0
  63. package/dist/timeline-layout.d.ts +51 -0
  64. package/dist/timeline-layout.js +166 -0
  65. package/dist/timeline.d.ts +52 -0
  66. package/dist/timeline.js +776 -0
  67. package/dist/timeline.parts.d.ts +1 -0
  68. package/dist/timeline.parts.js +1 -0
  69. package/dist/types.d.ts +43 -0
  70. package/dist/types.js +1 -0
  71. package/dist/use-chart.d.ts +13 -0
  72. package/dist/use-chart.js +37 -0
  73. package/package.json +61 -4
  74. package/src/Heatmap.tsx +274 -0
  75. package/src/Root.tsx +784 -0
  76. package/src/SeriesLegend.tsx +175 -0
  77. package/src/Sparkline.tsx +72 -0
  78. package/src/access.ts +39 -0
  79. package/src/annotations.tsx +144 -0
  80. package/src/axes.tsx +431 -0
  81. package/src/band.ts +162 -0
  82. package/src/color.ts +23 -0
  83. package/src/context.ts +119 -0
  84. package/src/create-chart.ts +24 -0
  85. package/src/cursor.ts +97 -0
  86. package/src/group-axes.ts +60 -0
  87. package/src/heat.ts +63 -0
  88. package/src/index.parts.ts +43 -0
  89. package/src/index.ts +42 -0
  90. package/src/layer.tsx +44 -0
  91. package/src/legend.ts +14 -0
  92. package/src/locales/en.ts +38 -0
  93. package/src/locales/nl.ts +39 -0
  94. package/src/locales.ts +9 -0
  95. package/src/overlays.tsx +323 -0
  96. package/src/points.ts +104 -0
  97. package/src/register.ts +44 -0
  98. package/src/scale.ts +277 -0
  99. package/src/scatter.tsx +120 -0
  100. package/src/series.tsx +466 -0
  101. package/src/spark.ts +33 -0
  102. package/src/store.ts +211 -0
  103. package/src/time-format.ts +28 -0
  104. package/src/timeline-layout.ts +190 -0
  105. package/src/timeline.parts.ts +1 -0
  106. package/src/timeline.tsx +459 -0
  107. package/src/types.ts +73 -0
  108. package/src/use-chart.ts +36 -0
package/LICENSE ADDED
@@ -0,0 +1,110 @@
1
+ # Functional Source License, Version 1.1, MIT Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-MIT
6
+
7
+ ## Notice
8
+
9
+ Copyright 2026 - present Bas Milius
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the MIT license that is effective on the second anniversary of the date we make
91
+ the Software available. On or after that date, you may use the Software under
92
+ the MIT license, in which case the following will apply:
93
+
94
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
95
+ this software and associated documentation files (the "Software"), to deal in
96
+ the Software without restriction, including without limitation the rights to
97
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
98
+ of the Software, and to permit persons to whom the Software is furnished to do
99
+ so, subject to the following conditions:
100
+
101
+ The above copyright notice and this permission notice shall be included in all
102
+ copies or substantial portions of the Software.
103
+
104
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
105
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
106
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
107
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
108
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
109
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
110
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,60 @@
1
- # Temporary Holding Version
1
+ # @adecore/charts
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Charts in the theme of [`@adecore/ui`](https://adecore.dev/ui/): lines, areas and columns over time or per category, scatters with a legend of many series, heatmaps, trace timelines and sparklines, with markers and bands, a tooltip, a legend and a table of values. A chart follows the width of its container, draws on whole pixels, and is one stop for the keyboard that a screen reader reads bucket by bucket. `d3-scale` and `d3-shape` do the math.
4
+
5
+ **[Documentation](https://adecore.dev/charts/)**
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ bun add @adecore/charts
11
+ ```
12
+
13
+ `@adecore/ui`, React 19, `react-dom`, `i18next` and `react-i18next` are peer dependencies. Let Tailwind scan the package next to `@adecore/ui`, and add the `charts` namespace to the app's i18next:
14
+
15
+ ```css
16
+ @import "tailwindcss";
17
+ @import "@adecore/ui/theme.css";
18
+ @source "../node_modules/@adecore/ui/dist";
19
+ @source "../node_modules/@adecore/charts/dist";
20
+ ```
21
+
22
+ ```ts
23
+ import { CHARTS_NAMESPACE, CHARTS_RESOURCES } from '@adecore/charts';
24
+
25
+ for (const [language, words] of Object.entries(CHARTS_RESOURCES)) {
26
+ i18n.addResourceBundle(language, CHARTS_NAMESPACE, words);
27
+ }
28
+ ```
29
+
30
+ ## Use
31
+
32
+ ```tsx
33
+ import { Chart } from '@adecore/charts';
34
+
35
+ <Chart.Root data={buckets} x="at" xScale="time" label="Events per hour" height={220}>
36
+ <Chart.Grid />
37
+ <Chart.XAxis />
38
+ <Chart.YAxis />
39
+ <Chart.Area value="errors" label="Errors" tone="error" />
40
+ <Chart.Line value="warnings" label="Warnings" tone="needsYou" />
41
+ <Chart.Tooltip />
42
+ <Chart.Legend />
43
+ </Chart.Root>
44
+ ```
45
+
46
+ `Timeline` draws the spans of a trace as a tree of rows that folds, each with a bar on one axis of durations:
47
+
48
+ ```tsx
49
+ import { Timeline } from '@adecore/charts';
50
+
51
+ <Timeline.Root data={spans} kinds={kinds} label="Spans of GET /orders">
52
+ <Timeline.Legend />
53
+ <Timeline.Axis heading="Span" />
54
+ <Timeline.Rows />
55
+ </Timeline.Root>
56
+ ```
57
+
58
+ ## License
59
+
60
+ FSL-1.1-MIT, see [LICENSE](./LICENSE).
@@ -0,0 +1,27 @@
1
+ import { type Ref } from 'react';
2
+ import { type HeatCell } from './heat.ts';
3
+ import type { ChartColor } from './types.ts';
4
+ export type HeatmapCell = HeatCell;
5
+ export interface HeatmapAxisItem {
6
+ readonly key: string | number;
7
+ readonly label: string;
8
+ readonly short?: string | null;
9
+ }
10
+ export interface HeatmapProps {
11
+ readonly rows: readonly HeatmapAxisItem[];
12
+ readonly columns: readonly HeatmapAxisItem[];
13
+ readonly values: readonly (readonly (number | null)[])[];
14
+ readonly label: string;
15
+ readonly valueLabel: string;
16
+ readonly tone?: ChartColor;
17
+ readonly steps?: number;
18
+ readonly max?: number;
19
+ readonly format?: (value: number) => string;
20
+ readonly cellHeight?: number;
21
+ readonly legend?: boolean;
22
+ readonly table?: boolean;
23
+ readonly onActiveChange?: (cell: HeatmapCell | null) => void;
24
+ readonly className?: string;
25
+ readonly ref?: Ref<HTMLDivElement>;
26
+ }
27
+ export declare function Heatmap({ rows, columns, values, label, valueLabel, tone, steps, max, format, cellHeight, legend, table, onActiveChange, className, ref }: HeatmapProps): import("react").JSX.Element;
@@ -0,0 +1,455 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { useId, useState } from 'react';
3
+ import clsx from 'clsx';
4
+ import { useTranslation } from 'react-i18next';
5
+ import { Button, Surface } from '@adecore/ui';
6
+ import { formatNumber } from '@adecore/ui/format';
7
+ import { colorOf } from './color.js';
8
+ import { FLOOR, heatMix, heatShare, moveCell } from './heat.js';
9
+ /* Between a cell and the card beside it. */
10
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
+ const OFFSET = 8;
12
+ // The React Compiler cannot compile optional chaining inside a condition, so the comparison lives out here.
13
+ const sameCell = (one, other) => one === null || other === null ? one === other : one.row === other.row && one.column === other.column;
14
+ const shade = (color, share) => share === 0 ? undefined : `color-mix(in srgb, ${color} ${share}%, transparent)`;
15
+ /* The card hangs toward the side of the grid with the most room, so it covers neither the cell nor the edge. */
16
+ const cardPlace = (toRight, down) => ({
17
+ left: toRight ? `calc(100% + ${OFFSET}px)` : undefined,
18
+ right: toRight ? undefined : `calc(100% + ${OFFSET}px)`,
19
+ top: down ? 0 : undefined,
20
+ bottom: down ? undefined : 0
21
+ });
22
+ /* A grid of rows by columns, each cell shaded by its value, such as events per weekday and hour. */
23
+ export function Heatmap(t0) {
24
+ const $ = _c(89);
25
+ const {
26
+ rows,
27
+ columns,
28
+ values,
29
+ label,
30
+ valueLabel,
31
+ tone: t1,
32
+ steps,
33
+ max,
34
+ format: t2,
35
+ cellHeight: t3,
36
+ legend: t4,
37
+ table: t5,
38
+ onActiveChange,
39
+ className,
40
+ ref
41
+ } = t0;
42
+ const tone = t1 === undefined ? "accent" : t1;
43
+ const format = t2 === undefined ? formatNumber : t2;
44
+ const cellHeight = t3 === undefined ? 16 : t3;
45
+ const legend = t4 === undefined ? true : t4;
46
+ const table = t5 === undefined ? false : t5;
47
+ const {
48
+ t
49
+ } = useTranslation("charts");
50
+ const id = useId();
51
+ const [active, setActive] = useState(null);
52
+ const [announce, setAnnounce] = useState(false);
53
+ const [shown, setShown] = useState(false);
54
+ let current;
55
+ let describe;
56
+ let empty;
57
+ let t6;
58
+ let t7;
59
+ let t8;
60
+ let t9;
61
+ let valueAt;
62
+ if ($[0] !== active || $[1] !== cellHeight || $[2] !== className || $[3] !== columns || $[4] !== format || $[5] !== id || $[6] !== label || $[7] !== legend || $[8] !== max || $[9] !== onActiveChange || $[10] !== ref || $[11] !== rows || $[12] !== steps || $[13] !== t || $[14] !== tone || $[15] !== valueLabel || $[16] !== values) {
63
+ const color = colorOf(tone);
64
+ let t10;
65
+ if ($[25] !== values) {
66
+ t10 = (row, column) => values[row]?.[column] ?? null;
67
+ $[25] = values;
68
+ $[26] = t10;
69
+ } else {
70
+ t10 = $[26];
71
+ }
72
+ valueAt = t10;
73
+ let t11;
74
+ if ($[27] !== max || $[28] !== values) {
75
+ t11 = max ?? Math.max(0, ...values.flatMap(_temp2));
76
+ $[27] = max;
77
+ $[28] = values;
78
+ $[29] = t11;
79
+ } else {
80
+ t11 = $[29];
81
+ }
82
+ const top = t11;
83
+ empty = rows.length === 0 || columns.length === 0;
84
+ let t12;
85
+ if ($[30] !== format || $[31] !== t) {
86
+ t12 = value_0 => value_0 === null ? t("noData") : format(value_0);
87
+ $[30] = format;
88
+ $[31] = t;
89
+ $[32] = t12;
90
+ } else {
91
+ t12 = $[32];
92
+ }
93
+ const write = t12;
94
+ let t13;
95
+ if ($[33] !== columns || $[34] !== format || $[35] !== rows || $[36] !== t || $[37] !== valueAt || $[38] !== valueLabel) {
96
+ t13 = cell => {
97
+ const value_1 = valueAt(cell.row, cell.column);
98
+ return `${rows[cell.row].label}, ${columns[cell.column].label}, ${value_1 === null ? t("noData") : `${valueLabel} ${format(value_1)}`}`;
99
+ };
100
+ $[33] = columns;
101
+ $[34] = format;
102
+ $[35] = rows;
103
+ $[36] = t;
104
+ $[37] = valueAt;
105
+ $[38] = valueLabel;
106
+ $[39] = t13;
107
+ } else {
108
+ t13 = $[39];
109
+ }
110
+ describe = t13;
111
+ current = active !== null && active.row < rows.length && active.column < columns.length ? active : null;
112
+ let t14;
113
+ if ($[40] !== current || $[41] !== onActiveChange) {
114
+ t14 = cell_0 => {
115
+ setActive(cell_0);
116
+ if (!sameCell(cell_0, current)) {
117
+ onActiveChange?.(cell_0);
118
+ }
119
+ };
120
+ $[40] = current;
121
+ $[41] = onActiveChange;
122
+ $[42] = t14;
123
+ } else {
124
+ t14 = $[42];
125
+ }
126
+ const activate = t14;
127
+ let t15;
128
+ if ($[43] !== activate || $[44] !== columns.length || $[45] !== current || $[46] !== rows.length) {
129
+ t15 = e => {
130
+ const target = moveCell(e.key, current, rows.length, columns.length, e.ctrlKey || e.metaKey);
131
+ if (target === undefined) {
132
+ return;
133
+ }
134
+ e.preventDefault();
135
+ setAnnounce(target !== null);
136
+ activate(target);
137
+ };
138
+ $[43] = activate;
139
+ $[44] = columns.length;
140
+ $[45] = current;
141
+ $[46] = rows.length;
142
+ $[47] = t15;
143
+ } else {
144
+ t15 = $[47];
145
+ }
146
+ const onKeyDown = t15;
147
+ t6 = ref;
148
+ if ($[48] !== className) {
149
+ t7 = clsx("flex min-w-0 flex-col gap-2", className);
150
+ $[48] = className;
151
+ $[49] = t7;
152
+ } else {
153
+ t7 = $[49];
154
+ }
155
+ let t16;
156
+ if ($[50] !== t) {
157
+ t16 = t("heatmap.name");
158
+ $[50] = t;
159
+ $[51] = t16;
160
+ } else {
161
+ t16 = $[51];
162
+ }
163
+ const t17 = `${id}-hint`;
164
+ let t18;
165
+ let t19;
166
+ if ($[52] !== activate) {
167
+ t18 = () => activate(null);
168
+ t19 = () => {
169
+ activate(null);
170
+ setAnnounce(false);
171
+ };
172
+ $[52] = activate;
173
+ $[53] = t18;
174
+ $[54] = t19;
175
+ } else {
176
+ t18 = $[53];
177
+ t19 = $[54];
178
+ }
179
+ const t20 = empty ? /*#__PURE__*/_jsx("p", {
180
+ className: "py-6 text-center text-xs text-text-faint",
181
+ children: t("noData")
182
+ }) : /*#__PURE__*/_jsxs("div", {
183
+ "aria-hidden": true,
184
+ className: "grid gap-0.5 text-xs text-text-muted",
185
+ style: {
186
+ gridTemplateColumns: `auto repeat(${columns.length}, minmax(0, 1fr))`
187
+ },
188
+ children: [/*#__PURE__*/_jsx("span", {}), columns.map(_temp3), rows.map((row_0, rowIndex) => /*#__PURE__*/_jsxs("div", {
189
+ className: "contents",
190
+ children: [/*#__PURE__*/_jsx("span", {
191
+ className: "flex items-center pr-2 leading-4 whitespace-nowrap",
192
+ children: row_0.short === undefined ? row_0.label : row_0.short
193
+ }), columns.map((column_1, columnIndex) => {
194
+ const value_2 = valueAt(rowIndex, columnIndex);
195
+ const mix = heatMix(value_2, top, steps);
196
+ const isActive = current !== null && current.row === rowIndex && current.column === columnIndex;
197
+ return /*#__PURE__*/_jsx("span", {
198
+ "data-mix": mix,
199
+ className: clsx("rounded-xs", mix === 0 && "bg-surface-sunken", isActive && "relative z-10 outline-1 outline-offset-1 outline-text"),
200
+ style: {
201
+ height: cellHeight,
202
+ backgroundColor: shade(color, mix)
203
+ },
204
+ onPointerEnter: () => {
205
+ setAnnounce(false);
206
+ activate({
207
+ row: rowIndex,
208
+ column: columnIndex
209
+ });
210
+ },
211
+ children: isActive && /*#__PURE__*/_jsxs(Surface, {
212
+ className: "pointer-events-none absolute flex w-max min-w-36 flex-col gap-1 rounded-lg px-2.5 py-2 text-xs",
213
+ style: cardPlace(columnIndex < columns.length / 2, rowIndex < rows.length / 2),
214
+ children: [/*#__PURE__*/_jsxs("p", {
215
+ className: "font-medium whitespace-nowrap text-text",
216
+ children: [row_0.label, " \xB7 ", column_1.label]
217
+ }), /*#__PURE__*/_jsxs("p", {
218
+ className: "flex items-center gap-2 text-text-muted",
219
+ children: [/*#__PURE__*/_jsx("span", {
220
+ className: clsx("size-2 shrink-0 rounded-xs", mix === 0 && "bg-surface-sunken"),
221
+ style: {
222
+ backgroundColor: shade(color, mix)
223
+ }
224
+ }), /*#__PURE__*/_jsx("span", {
225
+ className: "min-w-0 truncate",
226
+ children: valueLabel
227
+ }), /*#__PURE__*/_jsx("span", {
228
+ className: "ml-auto pl-3 text-text tabular-nums",
229
+ children: write(value_2)
230
+ })]
231
+ })]
232
+ })
233
+ }, column_1.key);
234
+ })]
235
+ }, row_0.key))]
236
+ });
237
+ if ($[55] !== label || $[56] !== onKeyDown || $[57] !== t16 || $[58] !== t17 || $[59] !== t18 || $[60] !== t19 || $[61] !== t20) {
238
+ t8 = /*#__PURE__*/_jsx("div", {
239
+ role: "group",
240
+ tabIndex: 0,
241
+ "aria-roledescription": t16,
242
+ "aria-label": label,
243
+ "aria-describedby": t17,
244
+ className: "focus-ring rounded-xs",
245
+ onKeyDown: onKeyDown,
246
+ onPointerLeave: t18,
247
+ onBlur: t19,
248
+ children: t20
249
+ });
250
+ $[55] = label;
251
+ $[56] = onKeyDown;
252
+ $[57] = t16;
253
+ $[58] = t17;
254
+ $[59] = t18;
255
+ $[60] = t19;
256
+ $[61] = t20;
257
+ $[62] = t8;
258
+ } else {
259
+ t8 = $[62];
260
+ }
261
+ t9 = legend && !empty && /*#__PURE__*/_jsxs("div", {
262
+ "aria-hidden": true,
263
+ className: "flex items-center justify-end gap-1 text-xs text-text-muted",
264
+ children: [/*#__PURE__*/_jsx("span", {
265
+ className: "mr-1",
266
+ children: t("heatmap.less")
267
+ }), steps === undefined ? /*#__PURE__*/_jsxs(_Fragment, {
268
+ children: [/*#__PURE__*/_jsx("span", {
269
+ className: "size-3 rounded-xs bg-surface-sunken"
270
+ }), /*#__PURE__*/_jsx("span", {
271
+ "data-legend": "gradient",
272
+ className: "h-3 w-16 rounded-xs",
273
+ style: {
274
+ backgroundImage: `linear-gradient(to right, ${shade(color, FLOOR)}, ${shade(color, 100)})`
275
+ }
276
+ })]
277
+ }) : Array.from({
278
+ length: steps + 1
279
+ }, (_, step) => /*#__PURE__*/_jsx("span", {
280
+ className: clsx("size-3 rounded-xs", step === 0 && "bg-surface-sunken"),
281
+ style: {
282
+ backgroundColor: shade(color, heatShare(step, steps))
283
+ }
284
+ }, step)), /*#__PURE__*/_jsx("span", {
285
+ className: "ml-1",
286
+ children: t("heatmap.more")
287
+ })]
288
+ });
289
+ $[0] = active;
290
+ $[1] = cellHeight;
291
+ $[2] = className;
292
+ $[3] = columns;
293
+ $[4] = format;
294
+ $[5] = id;
295
+ $[6] = label;
296
+ $[7] = legend;
297
+ $[8] = max;
298
+ $[9] = onActiveChange;
299
+ $[10] = ref;
300
+ $[11] = rows;
301
+ $[12] = steps;
302
+ $[13] = t;
303
+ $[14] = tone;
304
+ $[15] = valueLabel;
305
+ $[16] = values;
306
+ $[17] = current;
307
+ $[18] = describe;
308
+ $[19] = empty;
309
+ $[20] = t6;
310
+ $[21] = t7;
311
+ $[22] = t8;
312
+ $[23] = t9;
313
+ $[24] = valueAt;
314
+ } else {
315
+ current = $[17];
316
+ describe = $[18];
317
+ empty = $[19];
318
+ t6 = $[20];
319
+ t7 = $[21];
320
+ t8 = $[22];
321
+ t9 = $[23];
322
+ valueAt = $[24];
323
+ }
324
+ let t10;
325
+ if ($[63] !== columns || $[64] !== empty || $[65] !== format || $[66] !== id || $[67] !== label || $[68] !== rows || $[69] !== shown || $[70] !== t || $[71] !== table || $[72] !== valueAt) {
326
+ t10 = !empty && /*#__PURE__*/_jsxs("div", {
327
+ className: table ? "flex flex-col items-start gap-2" : undefined,
328
+ children: [table && /*#__PURE__*/_jsx(Button, {
329
+ size: "sm",
330
+ "aria-expanded": shown,
331
+ "aria-controls": `${id}-table`,
332
+ onClick: () => setShown(_temp4),
333
+ children: shown ? t("values.hide") : t("values.show")
334
+ }), /*#__PURE__*/_jsx("div", {
335
+ id: `${id}-table`,
336
+ className: table && shown ? "max-h-80 w-full overflow-auto rounded-md border border-border-soft" : "sr-only",
337
+ children: /*#__PURE__*/_jsxs("table", {
338
+ className: table && shown ? "w-full border-collapse text-xs tabular-nums" : undefined,
339
+ children: [/*#__PURE__*/_jsx("caption", {
340
+ className: "sr-only",
341
+ children: t("values.caption", {
342
+ label
343
+ })
344
+ }), /*#__PURE__*/_jsx("thead", {
345
+ className: table && shown ? "sticky top-0 bg-surface-hover" : undefined,
346
+ children: /*#__PURE__*/_jsxs("tr", {
347
+ children: [/*#__PURE__*/_jsx("td", {}), columns.map(column_2 => /*#__PURE__*/_jsx("th", {
348
+ scope: "col",
349
+ className: table && shown ? "h-8 px-2 text-right font-medium whitespace-nowrap text-text-muted" : undefined,
350
+ children: column_2.label
351
+ }, column_2.key))]
352
+ })
353
+ }), /*#__PURE__*/_jsx("tbody", {
354
+ children: rows.map((row_1, rowIndex_0) => /*#__PURE__*/_jsxs("tr", {
355
+ className: table && shown ? "border-t border-border-soft" : undefined,
356
+ children: [/*#__PURE__*/_jsx("th", {
357
+ scope: "row",
358
+ className: table && shown ? "h-8 px-2 text-left font-normal whitespace-nowrap text-text-muted" : undefined,
359
+ children: row_1.label
360
+ }), columns.map((column_3, columnIndex_0) => {
361
+ const value_3 = valueAt(rowIndex_0, columnIndex_0);
362
+ return /*#__PURE__*/_jsx("td", {
363
+ className: table && shown ? "h-8 px-2 text-right whitespace-nowrap text-text" : undefined,
364
+ children: value_3 === null ? "" : format(value_3)
365
+ }, column_3.key);
366
+ })]
367
+ }, row_1.key))
368
+ })]
369
+ })
370
+ })]
371
+ });
372
+ $[63] = columns;
373
+ $[64] = empty;
374
+ $[65] = format;
375
+ $[66] = id;
376
+ $[67] = label;
377
+ $[68] = rows;
378
+ $[69] = shown;
379
+ $[70] = t;
380
+ $[71] = table;
381
+ $[72] = valueAt;
382
+ $[73] = t10;
383
+ } else {
384
+ t10 = $[73];
385
+ }
386
+ const t11 = `${id}-hint`;
387
+ let t12;
388
+ if ($[74] !== t) {
389
+ t12 = t("heatmap.keyboard");
390
+ $[74] = t;
391
+ $[75] = t12;
392
+ } else {
393
+ t12 = $[75];
394
+ }
395
+ let t13;
396
+ if ($[76] !== t11 || $[77] !== t12) {
397
+ t13 = /*#__PURE__*/_jsx("p", {
398
+ id: t11,
399
+ className: "sr-only",
400
+ children: t12
401
+ });
402
+ $[76] = t11;
403
+ $[77] = t12;
404
+ $[78] = t13;
405
+ } else {
406
+ t13 = $[78];
407
+ }
408
+ const t14 = announce && current !== null ? describe(current) : "";
409
+ let t15;
410
+ if ($[79] !== t14) {
411
+ t15 = /*#__PURE__*/_jsx("p", {
412
+ "aria-live": "polite",
413
+ className: "sr-only",
414
+ children: t14
415
+ });
416
+ $[79] = t14;
417
+ $[80] = t15;
418
+ } else {
419
+ t15 = $[80];
420
+ }
421
+ let t16;
422
+ if ($[81] !== t10 || $[82] !== t13 || $[83] !== t15 || $[84] !== t6 || $[85] !== t7 || $[86] !== t8 || $[87] !== t9) {
423
+ t16 = /*#__PURE__*/_jsxs("div", {
424
+ ref: t6,
425
+ className: t7,
426
+ children: [t8, t9, t10, t13, t15]
427
+ });
428
+ $[81] = t10;
429
+ $[82] = t13;
430
+ $[83] = t15;
431
+ $[84] = t6;
432
+ $[85] = t7;
433
+ $[86] = t8;
434
+ $[87] = t9;
435
+ $[88] = t16;
436
+ } else {
437
+ t16 = $[88];
438
+ }
439
+ return t16;
440
+ }
441
+ function _temp4(open) {
442
+ return !open;
443
+ }
444
+ function _temp3(column_0) {
445
+ return /*#__PURE__*/_jsx("span", {
446
+ className: "flex justify-center leading-4 whitespace-nowrap tabular-nums",
447
+ children: column_0.short === undefined ? column_0.label : column_0.short
448
+ }, column_0.key);
449
+ }
450
+ function _temp2(line) {
451
+ return line.filter(_temp);
452
+ }
453
+ function _temp(value) {
454
+ return value !== null && Number.isFinite(value);
455
+ }
package/dist/Root.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ import { type ReactNode, type Ref } from 'react';
2
+ import type { ChartAccessor, ChartMargin, ChartRows, ChartX, ChartXInput, ChartXOptions, ChartXScale, ChartYOptions, ChartYScale } from './types.ts';
3
+ export interface ChartRootProps<Row> {
4
+ readonly data: readonly Row[];
5
+ readonly x: ChartAccessor<Row, ChartXInput | null | undefined>;
6
+ readonly xScale?: ChartXScale;
7
+ readonly rows?: ChartRows;
8
+ readonly rowKey?: ChartAccessor<Row, string>;
9
+ readonly rowLabel?: ChartAccessor<Row, string>;
10
+ readonly format?: (value: number) => string;
11
+ readonly xOptions?: ChartXOptions;
12
+ readonly step?: number;
13
+ readonly yScale?: ChartYScale;
14
+ readonly y?: ChartYOptions;
15
+ readonly label: string;
16
+ readonly height?: number;
17
+ readonly grow?: boolean;
18
+ readonly activeX?: ChartX | null;
19
+ readonly onActiveXChange?: (x: ChartX | null) => void;
20
+ readonly margin?: ChartMargin;
21
+ readonly surface?: 'base' | 'raised';
22
+ readonly group?: ChartAccessor<Row, string>;
23
+ readonly groupLabel?: ChartAccessor<Row, string>;
24
+ readonly groupGap?: number;
25
+ readonly minBucketWidth?: number;
26
+ readonly selected?: readonly ChartX[];
27
+ readonly interactive?: boolean;
28
+ readonly cursor?: 'full' | 'line' | 'none';
29
+ readonly onActivate?: (row: Row, index: number) => void;
30
+ readonly dimmed?: (row: Row, index: number) => boolean;
31
+ readonly children?: ReactNode;
32
+ readonly className?: string;
33
+ readonly ref?: Ref<HTMLDivElement>;
34
+ }
35
+ export declare function ChartRoot<Row>({ data, x, xScale, rows, rowKey, rowLabel, format, xOptions, step: stepProp, yScale, y, label, height: leastHeight, grow, margin, surface, activeX, onActiveXChange, group, groupLabel, groupGap, minBucketWidth, selected, interactive, cursor, onActivate, dimmed, children, className, ref }: ChartRootProps<Row>): import("react").JSX.Element;