@zsherman/charts 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE +373 -0
- package/README.md +13 -2
- package/THIRD_PARTY_NOTICES.md +33 -0
- package/dist/dom/bar-list/bar-list.js +386 -0
- package/dist/dom/bar-list/bar-list.styles.js +171 -0
- package/dist/dom/bar-list/index.js +1 -0
- package/dist/dom/chart/chart.js +716 -0
- package/dist/dom/chart/chart.styles.js +165 -0
- package/dist/dom/chart/index.js +1 -0
- package/dist/dom/chart-grid/chart-grid.js +67 -0
- package/dist/dom/chart-grid/index.js +1 -0
- package/dist/dom/donut/donut.js +565 -0
- package/dist/dom/donut/donut.styles.js +111 -0
- package/dist/dom/donut/index.js +1 -0
- package/dist/dom/heat-graph/calendar.js +118 -0
- package/dist/dom/heat-graph/heat-graph.js +423 -0
- package/dist/dom/heat-graph/heat-graph.styles.js +168 -0
- package/dist/dom/heat-graph/index.js +1 -0
- package/dist/dom/heat-matrix/heat-matrix.js +346 -0
- package/dist/dom/heat-matrix/heat-matrix.styles.js +155 -0
- package/dist/dom/heat-matrix/index.js +1 -0
- package/dist/dom/heat-matrix/model.js +41 -0
- package/dist/dom/index.js +13 -0
- package/dist/dom/internal/colors.js +44 -0
- package/dist/dom/internal/floating-tip.js +83 -0
- package/dist/dom/internal/format.js +43 -0
- package/dist/dom/internal/grid-context.js +5 -0
- package/dist/dom/internal/hidden.styles.js +16 -0
- package/dist/dom/internal/legend.js +112 -0
- package/dist/dom/internal/legend.styles.js +108 -0
- package/dist/dom/internal/markers.js +101 -0
- package/dist/dom/internal/options.js +300 -0
- package/dist/dom/internal/place.js +27 -0
- package/dist/dom/internal/scheme-watch.js +73 -0
- package/dist/dom/internal/share.js +28 -0
- package/dist/dom/internal/types.js +0 -0
- package/dist/dom/row-chart/index.js +1 -0
- package/dist/dom/row-chart/model.js +59 -0
- package/dist/dom/row-chart/row-chart.js +691 -0
- package/dist/dom/row-chart/row-chart.styles.js +242 -0
- package/dist/dom/segmented-bar/index.js +1 -0
- package/dist/dom/segmented-bar/segmented-bar.js +280 -0
- package/dist/dom/segmented-bar/segmented-bar.styles.js +88 -0
- package/dist/dom/sparkline/index.js +1 -0
- package/dist/dom/sparkline/sparkline.js +145 -0
- package/dist/dom/stacked-histogram/histogram.js +137 -0
- package/dist/dom/stacked-histogram/index.js +1 -0
- package/dist/dom/stacked-histogram/stacked-histogram.js +761 -0
- package/dist/dom/stacked-histogram/stacked-histogram.styles.js +211 -0
- package/dist/dom/state-timeline/index.js +1 -0
- package/dist/dom/state-timeline/model.js +166 -0
- package/dist/dom/state-timeline/state-timeline.js +729 -0
- package/dist/dom/state-timeline/state-timeline.styles.js +171 -0
- package/dist/dom/status-history/index.js +1 -0
- package/dist/dom/status-history/status-history.js +542 -0
- package/dist/dom/status-history/status-history.styles.js +171 -0
- package/dist/solid/bar-list/bar-list.jsx +139 -0
- package/dist/solid/bar-list/bar-list.styles.jsx +171 -0
- package/dist/solid/bar-list/index.jsx +1 -0
- package/dist/solid/chart/chart.jsx +454 -0
- package/dist/solid/chart/chart.styles.jsx +165 -0
- package/dist/solid/chart/index.jsx +1 -0
- package/dist/solid/chart-grid/chart-grid.jsx +46 -0
- package/dist/solid/chart-grid/index.jsx +1 -0
- package/dist/solid/donut/donut.jsx +291 -0
- package/dist/solid/donut/donut.styles.jsx +111 -0
- package/dist/solid/donut/index.jsx +1 -0
- package/dist/solid/heat-graph/calendar.jsx +118 -0
- package/dist/solid/heat-graph/heat-graph.jsx +228 -0
- package/dist/solid/heat-graph/heat-graph.styles.jsx +168 -0
- package/dist/solid/heat-graph/index.jsx +1 -0
- package/dist/solid/heat-matrix/heat-matrix.jsx +165 -0
- package/dist/solid/heat-matrix/heat-matrix.styles.jsx +155 -0
- package/dist/solid/heat-matrix/index.jsx +1 -0
- package/dist/solid/heat-matrix/model.jsx +41 -0
- package/dist/solid/index.jsx +13 -0
- package/dist/solid/internal/colors.jsx +44 -0
- package/dist/solid/internal/floating-tip.jsx +68 -0
- package/dist/solid/internal/format.jsx +43 -0
- package/dist/solid/internal/grid-context.jsx +5 -0
- package/dist/solid/internal/hidden.styles.jsx +16 -0
- package/dist/solid/internal/legend.jsx +35 -0
- package/dist/solid/internal/legend.styles.jsx +108 -0
- package/dist/solid/internal/markers.jsx +101 -0
- package/dist/solid/internal/options.jsx +300 -0
- package/dist/solid/internal/place.jsx +27 -0
- package/dist/solid/internal/scheme-watch.jsx +73 -0
- package/dist/solid/internal/share.jsx +28 -0
- package/dist/solid/internal/types.jsx +0 -0
- package/dist/solid/row-chart/index.jsx +1 -0
- package/dist/solid/row-chart/model.jsx +59 -0
- package/dist/solid/row-chart/row-chart.jsx +312 -0
- package/dist/solid/row-chart/row-chart.styles.jsx +242 -0
- package/dist/solid/segmented-bar/index.jsx +1 -0
- package/dist/solid/segmented-bar/segmented-bar.jsx +125 -0
- package/dist/solid/segmented-bar/segmented-bar.styles.jsx +88 -0
- package/dist/solid/sparkline/index.jsx +1 -0
- package/dist/solid/sparkline/sparkline.jsx +88 -0
- package/dist/solid/stacked-histogram/histogram.jsx +137 -0
- package/dist/solid/stacked-histogram/index.jsx +1 -0
- package/dist/solid/stacked-histogram/stacked-histogram.jsx +381 -0
- package/dist/solid/stacked-histogram/stacked-histogram.styles.jsx +211 -0
- package/dist/solid/state-timeline/index.jsx +1 -0
- package/dist/solid/state-timeline/model.jsx +166 -0
- package/dist/solid/state-timeline/state-timeline.jsx +387 -0
- package/dist/solid/state-timeline/state-timeline.styles.jsx +171 -0
- package/dist/solid/status-history/index.jsx +1 -0
- package/dist/solid/status-history/status-history.jsx +279 -0
- package/dist/solid/status-history/status-history.styles.jsx +171 -0
- package/dist/styles.css +1 -0
- package/dist/types/bar-list/bar-list.d.ts +91 -0
- package/dist/types/bar-list/bar-list.styles.d.ts +148 -0
- package/dist/types/bar-list/index.d.ts +3 -0
- package/dist/types/chart/chart.d.ts +98 -0
- package/dist/types/chart/chart.styles.d.ts +145 -0
- package/dist/types/chart/index.d.ts +3 -0
- package/dist/types/chart-grid/chart-grid.d.ts +35 -0
- package/dist/types/chart-grid/index.d.ts +2 -0
- package/dist/types/donut/donut.d.ts +124 -0
- package/dist/types/donut/donut.styles.d.ts +96 -0
- package/dist/types/donut/index.d.ts +3 -0
- package/dist/types/heat-graph/calendar.d.ts +61 -0
- package/dist/types/heat-graph/heat-graph.d.ts +82 -0
- package/dist/types/heat-graph/heat-graph.styles.d.ts +141 -0
- package/dist/types/heat-graph/index.d.ts +4 -0
- package/dist/types/heat-matrix/heat-matrix.d.ts +65 -0
- package/dist/types/heat-matrix/heat-matrix.styles.d.ts +135 -0
- package/dist/types/heat-matrix/index.d.ts +3 -0
- package/dist/types/heat-matrix/model.d.ts +15 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/internal/colors.d.ts +22 -0
- package/dist/types/internal/floating-tip.d.ts +15 -0
- package/dist/types/internal/format.d.ts +7 -0
- package/dist/types/internal/grid-context.d.ts +9 -0
- package/dist/types/internal/hidden.styles.d.ts +15 -0
- package/dist/types/internal/legend.d.ts +18 -0
- package/dist/types/internal/legend.styles.d.ts +96 -0
- package/dist/types/internal/markers.d.ts +16 -0
- package/dist/types/internal/options.d.ts +59 -0
- package/dist/types/internal/place.d.ts +20 -0
- package/dist/types/internal/scheme-watch.d.ts +12 -0
- package/dist/types/internal/share.d.ts +19 -0
- package/dist/types/internal/types.d.ts +163 -0
- package/dist/types/row-chart/index.d.ts +4 -0
- package/dist/types/row-chart/model.d.ts +50 -0
- package/dist/types/row-chart/row-chart.d.ts +148 -0
- package/dist/types/row-chart/row-chart.styles.d.ts +216 -0
- package/dist/types/segmented-bar/index.d.ts +3 -0
- package/dist/types/segmented-bar/segmented-bar.d.ts +65 -0
- package/dist/types/segmented-bar/segmented-bar.styles.d.ts +75 -0
- package/dist/types/sparkline/index.d.ts +3 -0
- package/dist/types/sparkline/sparkline.d.ts +38 -0
- package/dist/types/stacked-histogram/histogram.d.ts +48 -0
- package/dist/types/stacked-histogram/index.d.ts +4 -0
- package/dist/types/stacked-histogram/stacked-histogram.d.ts +73 -0
- package/dist/types/stacked-histogram/stacked-histogram.styles.d.ts +187 -0
- package/dist/types/state-timeline/index.d.ts +3 -0
- package/dist/types/state-timeline/model.d.ts +63 -0
- package/dist/types/state-timeline/state-timeline.d.ts +108 -0
- package/dist/types/state-timeline/state-timeline.styles.d.ts +151 -0
- package/dist/types/status-history/index.d.ts +3 -0
- package/dist/types/status-history/status-history.d.ts +72 -0
- package/dist/types/status-history/status-history.styles.d.ts +150 -0
- package/docs/api.json +1346 -0
- package/docs/bar-list.md +190 -0
- package/docs/chart-grid.md +77 -0
- package/docs/chart.md +355 -0
- package/docs/donut.md +182 -0
- package/docs/heat-graph.md +121 -0
- package/docs/heat-matrix.md +108 -0
- package/docs/llms.txt +68 -0
- package/docs/row-chart.md +193 -0
- package/docs/search-index.json +291 -0
- package/docs/segmented-bar.md +128 -0
- package/docs/sparkline.md +82 -0
- package/docs/stacked-histogram.md +123 -0
- package/docs/state-timeline.md +141 -0
- package/docs/status-history.md +121 -0
- package/package.json +104 -4
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { cssColor } from "../internal/colors.jsx";
|
|
2
|
+
import { dayKey, layout } from "./calendar.jsx";
|
|
3
|
+
import { levels, styles } from "./heat-graph.styles.jsx";
|
|
4
|
+
import * as stylex from "@stylexjs/stylex";
|
|
5
|
+
import { useLocale, useMessages } from "@zsherman/kit/locale-provider";
|
|
6
|
+
import { For, Show, createEffect, createMemo, createSignal, omit } from "solid-js";
|
|
7
|
+
// src/heat-graph/heat-graph.tsx
|
|
8
|
+
/** Area-proportional mark size: a 30% diameter at zero, the full cell at the busiest day. */
|
|
9
|
+
const markSize = (count, max) => `${Math.sqrt(.09 + .91 * (max > 0 ? Math.min(1, count / max) : 0)) * 100}%`;
|
|
10
|
+
/** The locale's first weekday (`Intl.Locale` week info), Monday where the engine doesn't say. */
|
|
11
|
+
function localeWeekStart(locale) {
|
|
12
|
+
try {
|
|
13
|
+
const info = new Intl.Locale(locale);
|
|
14
|
+
return (info.getWeekInfo?.().firstDay ?? info.weekInfo?.firstDay) === 7 ? "sunday" : "monday";
|
|
15
|
+
} catch {
|
|
16
|
+
return "monday";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A calendar of daily counts, one cell per day in week columns, shaded by level: which days and weekdays
|
|
21
|
+
* are busy across weeks or months. A grid with one tab stop: the arrow keys move by day and week, each
|
|
22
|
+
* day is named with its count and date, and the tooltip follows the pointer and the focus.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* <HeatGraph label="Commits in 2026: 1,204, busiest in March" data={commits} start="2026-01-01" end="2026-12-31" />
|
|
26
|
+
*/
|
|
27
|
+
function HeatGraph(props) {
|
|
28
|
+
const rest = omit(props, "label", "data", "start", "end", "weekStart", "thresholds", "color", "shape", "sizeEncoding", "cellSize", "cellGap", "monthLabels", "dayLabels", "legend", "onSelectDay", "labels", "class");
|
|
29
|
+
const locale = useLocale();
|
|
30
|
+
const messages = useMessages("heatGraph");
|
|
31
|
+
const text = {
|
|
32
|
+
less: () => props.labels?.less ?? messages()?.less ?? "Less",
|
|
33
|
+
more: () => props.labels?.more ?? messages()?.more ?? "More",
|
|
34
|
+
count: (n) => {
|
|
35
|
+
const formatted = new Intl.NumberFormat(locale()).format(n);
|
|
36
|
+
const custom = props.labels?.count ?? messages()?.count;
|
|
37
|
+
return custom ? custom(n, formatted) : `${formatted} ${n === 1 ? "activity" : "activities"}`;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const weekStart = () => props.weekStart ?? localeWeekStart(locale());
|
|
41
|
+
const model = createMemo(() => layout({
|
|
42
|
+
data: props.data,
|
|
43
|
+
start: props.start,
|
|
44
|
+
end: props.end,
|
|
45
|
+
weekStart: weekStart(),
|
|
46
|
+
thresholds: props.thresholds
|
|
47
|
+
}));
|
|
48
|
+
const formats = createMemo(() => ({
|
|
49
|
+
month: new Intl.DateTimeFormat(locale(), {
|
|
50
|
+
month: "short",
|
|
51
|
+
timeZone: "UTC"
|
|
52
|
+
}),
|
|
53
|
+
weekday: new Intl.DateTimeFormat(locale(), {
|
|
54
|
+
weekday: "short",
|
|
55
|
+
timeZone: "UTC"
|
|
56
|
+
}),
|
|
57
|
+
long: new Intl.DateTimeFormat(locale(), {
|
|
58
|
+
dateStyle: "full",
|
|
59
|
+
timeZone: "UTC"
|
|
60
|
+
}),
|
|
61
|
+
short: new Intl.DateTimeFormat(locale(), {
|
|
62
|
+
dateStyle: "medium",
|
|
63
|
+
timeZone: "UTC"
|
|
64
|
+
})
|
|
65
|
+
}));
|
|
66
|
+
/**
|
|
67
|
+
* The days with their words, computed once per layout or locale: each cell renders plain values, so a
|
|
68
|
+
* change re-renders the grid once instead of re-running hundreds of cell bindings.
|
|
69
|
+
*/
|
|
70
|
+
const cells = createMemo(() => {
|
|
71
|
+
const f = formats();
|
|
72
|
+
const max = model()?.max ?? 0;
|
|
73
|
+
const last = model()?.days.at(-1)?.key;
|
|
74
|
+
return (model()?.days ?? []).map((d) => ({
|
|
75
|
+
...d,
|
|
76
|
+
name: `${text.count(d.count)}, ${f.long.format(d.date)}`,
|
|
77
|
+
tip: `${text.count(d.count)} · ${f.short.format(d.date)}`,
|
|
78
|
+
mark: props.sizeEncoding === "value" ? markSize(d.count, max) : void 0,
|
|
79
|
+
latest: d.key === last
|
|
80
|
+
}));
|
|
81
|
+
});
|
|
82
|
+
const byKey = createMemo(() => new Map(cells().map((d) => [d.key, d])));
|
|
83
|
+
const rows = createMemo(() => {
|
|
84
|
+
const out = Array.from({ length: 7 }, () => []);
|
|
85
|
+
for (const d of cells()) out[d.row].push(d);
|
|
86
|
+
return out;
|
|
87
|
+
});
|
|
88
|
+
/** A row's weekday name: Monday, Wednesday and Friday are labelled, whichever day the week starts on. */
|
|
89
|
+
const weekdayOf = (row) => {
|
|
90
|
+
const day = model()?.days.find((d) => d.row === row);
|
|
91
|
+
return day && [
|
|
92
|
+
1,
|
|
93
|
+
3,
|
|
94
|
+
5
|
|
95
|
+
].includes(day.date.getUTCDay()) ? formats().weekday.format(day.date) : "";
|
|
96
|
+
};
|
|
97
|
+
const [active, setActive] = createSignal();
|
|
98
|
+
const [tip, setTip] = createSignal();
|
|
99
|
+
const current = () => {
|
|
100
|
+
const key = active();
|
|
101
|
+
return key && byKey().has(key) ? key : model()?.days.at(-1)?.key;
|
|
102
|
+
};
|
|
103
|
+
let root;
|
|
104
|
+
let gridEl;
|
|
105
|
+
createEffect(current, (key) => {
|
|
106
|
+
if (!gridEl) return;
|
|
107
|
+
for (const el of gridEl.querySelectorAll("[tabindex=\"0\"]")) el.tabIndex = -1;
|
|
108
|
+
if (key) {
|
|
109
|
+
const el = gridEl.querySelector(`[data-date="${key}"]`);
|
|
110
|
+
if (el) el.tabIndex = 0;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
const cellOf = (key) => gridEl.querySelector(`[data-date="${key}"]`);
|
|
114
|
+
function showTip(key) {
|
|
115
|
+
const cell = cellOf(key);
|
|
116
|
+
if (!cell) return;
|
|
117
|
+
const box = root.getBoundingClientRect();
|
|
118
|
+
const r = cell.getBoundingClientRect();
|
|
119
|
+
const x = r.left + r.width / 2 - box.left;
|
|
120
|
+
const align = x > box.width - 96 ? "end" : x < 96 ? "start" : "center";
|
|
121
|
+
const left = align === "end" ? r.right - box.left : align === "start" ? r.left - box.left : x;
|
|
122
|
+
setTip({
|
|
123
|
+
key,
|
|
124
|
+
left,
|
|
125
|
+
top: r.top - box.top,
|
|
126
|
+
align
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function move(event) {
|
|
130
|
+
const key = current();
|
|
131
|
+
if (!key) return;
|
|
132
|
+
const day = byKey().get(key);
|
|
133
|
+
const rtl = getComputedStyle(root).direction === "rtl";
|
|
134
|
+
const step = {
|
|
135
|
+
ArrowUp: -1,
|
|
136
|
+
ArrowDown: 1,
|
|
137
|
+
ArrowLeft: rtl ? 7 : -7,
|
|
138
|
+
ArrowRight: rtl ? -7 : 7
|
|
139
|
+
};
|
|
140
|
+
let next;
|
|
141
|
+
if (event.key in step) next = dayKey(new Date(day.date.getTime() + step[event.key] * 864e5));
|
|
142
|
+
else if (event.key === "Home") next = model()?.days[0]?.key;
|
|
143
|
+
else if (event.key === "End") next = model()?.days.at(-1)?.key;
|
|
144
|
+
else if ((event.key === "Enter" || event.key === " ") && props.onSelectDay) {
|
|
145
|
+
event.preventDefault();
|
|
146
|
+
props.onSelectDay(day);
|
|
147
|
+
return;
|
|
148
|
+
} else if (event.key === "Escape") {
|
|
149
|
+
setTip(void 0);
|
|
150
|
+
return;
|
|
151
|
+
} else return;
|
|
152
|
+
event.preventDefault();
|
|
153
|
+
if (!next || !byKey().has(next)) return;
|
|
154
|
+
setActive(next);
|
|
155
|
+
cellOf(next)?.focus();
|
|
156
|
+
}
|
|
157
|
+
const keyFrom = (event) => event.target.closest("[data-date]")?.dataset["date"];
|
|
158
|
+
const columns = () => {
|
|
159
|
+
const weeks = model()?.weeks ?? 1;
|
|
160
|
+
const cell = props.cellSize ? `${props.cellSize}px` : "minmax(0, 1fr)";
|
|
161
|
+
return `${props.dayLabels === false ? "0" : "max-content"} repeat(${weeks}, ${cell})`;
|
|
162
|
+
};
|
|
163
|
+
return <div {...rest} ref={(el) => root = el} data-slot="heat-graph" class={[stylex.props(styles.root).className, props.class]} style={{
|
|
164
|
+
"--hg-color": cssColor(props.color ?? "chart-1", 0),
|
|
165
|
+
"--hg-gap": `${props.cellGap ?? 3}px`,
|
|
166
|
+
"--hg-columns": columns(),
|
|
167
|
+
...props.cellSize ? { "--hg-cell-size": `${props.cellSize}px` } : {},
|
|
168
|
+
width: props.cellSize ? "max-content" : void 0
|
|
169
|
+
}}>
|
|
170
|
+
<div {...stylex.attrs(styles.frame)}>
|
|
171
|
+
<Show when={props.monthLabels !== false && model()}>
|
|
172
|
+
<div aria-hidden="true" data-slot="heat-graph-months" {...stylex.attrs(styles.months)}>
|
|
173
|
+
<For each={model().months}>
|
|
174
|
+
{(m) => <span {...stylex.attrs(styles.monthLabel)} style={{ "grid-column": `${m.column + 2}` }}>
|
|
175
|
+
{formats().month.format(m.date)}
|
|
176
|
+
</span>}
|
|
177
|
+
</For>
|
|
178
|
+
</div>
|
|
179
|
+
</Show>
|
|
180
|
+
<div ref={(el) => gridEl = el} role="grid" aria-label={props.label} aria-readonly="true" aria-colcount={model()?.weeks ?? 0} data-slot="heat-graph-grid" {...stylex.attrs(styles.grid)} onKeyDown={move} onPointerOver={(e) => {
|
|
181
|
+
const key = keyFrom(e);
|
|
182
|
+
if (key) showTip(key);
|
|
183
|
+
}} onPointerLeave={() => setTip(void 0)} onFocusIn={(e) => {
|
|
184
|
+
const key = keyFrom(e);
|
|
185
|
+
if (key) {
|
|
186
|
+
setActive(key);
|
|
187
|
+
showTip(key);
|
|
188
|
+
}
|
|
189
|
+
}} onFocusOut={() => setTip(void 0)} onClick={(e) => {
|
|
190
|
+
const key = keyFrom(e);
|
|
191
|
+
const day = key ? byKey().get(key) : void 0;
|
|
192
|
+
if (day && props.onSelectDay) props.onSelectDay(day);
|
|
193
|
+
}}>
|
|
194
|
+
<For each={rows()}>
|
|
195
|
+
{(days, row) => <div role="row" {...stylex.attrs(styles.row)}>
|
|
196
|
+
<span aria-hidden="true" {...stylex.attrs(styles.dayLabel)}>
|
|
197
|
+
{props.dayLabels === false ? "" : weekdayOf(row())}
|
|
198
|
+
</span>
|
|
199
|
+
<For each={days}>
|
|
200
|
+
{(d) => <div role="gridcell" data-date={d.key} data-level={d.level} aria-label={d.name} aria-colindex={d.column + 1} tabindex={d.latest ? 0 : -1} {...stylex.attrs(styles.cell, props.onSelectDay && styles.clickable)} style={{ "grid-column": `${d.column + 2}` }}>
|
|
201
|
+
<span aria-hidden="true" data-slot="heat-graph-mark" {...stylex.attrs(styles.mark, styles[props.shape ?? "rounded"], levels[d.level])} style={d.mark ? { "--hg-mark": d.mark } : void 0} />
|
|
202
|
+
</div>}
|
|
203
|
+
</For>
|
|
204
|
+
</div>}
|
|
205
|
+
</For>
|
|
206
|
+
</div>
|
|
207
|
+
</div>
|
|
208
|
+
<Show when={props.legend !== false}>
|
|
209
|
+
<div aria-hidden="true" data-slot="heat-graph-legend" {...stylex.attrs(styles.legend)}>
|
|
210
|
+
<span>{text.less()}</span>
|
|
211
|
+
<For each={levels}>
|
|
212
|
+
{(level) => <span {...stylex.attrs(styles.legendMark, styles[props.shape ?? "rounded"], level)} />}
|
|
213
|
+
</For>
|
|
214
|
+
<span>{text.more()}</span>
|
|
215
|
+
</div>
|
|
216
|
+
</Show>
|
|
217
|
+
<Show when={tip()}>
|
|
218
|
+
{(t) => <div aria-hidden="true" data-slot="heat-graph-tooltip" {...stylex.attrs(styles.tooltip)} style={{
|
|
219
|
+
left: `${t().left}px`,
|
|
220
|
+
top: `${t().top}px`,
|
|
221
|
+
transform: `translate(${t().align === "end" ? "-100%" : t().align === "start" ? "0" : "-50%"}, calc(-100% - 6px))`
|
|
222
|
+
}}>
|
|
223
|
+
{byKey().get(t().key)?.tip}
|
|
224
|
+
</div>}
|
|
225
|
+
</Show>
|
|
226
|
+
</div>;
|
|
227
|
+
}
|
|
228
|
+
export { HeatGraph };
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import "@stylexjs/stylex";
|
|
2
|
+
// src/heat-graph/heat-graph.styles.ts
|
|
3
|
+
const styles = {
|
|
4
|
+
root: {
|
|
5
|
+
kVAEAm: "x1n2onr6",
|
|
6
|
+
kB7OPa: "x9f619",
|
|
7
|
+
k1xSpc: "xrvj5dj",
|
|
8
|
+
kOIVth: "x8rwxmg",
|
|
9
|
+
k7Eaqz: "xeuugli",
|
|
10
|
+
kMv6JI: "x13rcfk",
|
|
11
|
+
kMwMTN: "x1yjpjgc",
|
|
12
|
+
$$css: true
|
|
13
|
+
},
|
|
14
|
+
frame: {
|
|
15
|
+
k1xSpc: "xrvj5dj",
|
|
16
|
+
kumcoG: "x1lsewcy",
|
|
17
|
+
k1C7PZ: "xruald1",
|
|
18
|
+
khm7nJ: "xefgwda",
|
|
19
|
+
k7Eaqz: "xeuugli",
|
|
20
|
+
$$css: true
|
|
21
|
+
},
|
|
22
|
+
months: {
|
|
23
|
+
kBCFzs: "x1osaytk",
|
|
24
|
+
k1xSpc: "xrvj5dj",
|
|
25
|
+
kumcoG: "x4w6khx",
|
|
26
|
+
$$css: true
|
|
27
|
+
},
|
|
28
|
+
monthLabel: {
|
|
29
|
+
kbNqZ1: "x1ms6mhf",
|
|
30
|
+
kGuDYH: "xb5fjo1",
|
|
31
|
+
kLWn49: "xau0z5x",
|
|
32
|
+
kMwMTN: "xe2mk2a",
|
|
33
|
+
khDVqt: "xuxw1ft",
|
|
34
|
+
kVQacm: "x1rea2x4",
|
|
35
|
+
k7Eaqz: "xeuugli",
|
|
36
|
+
$$css: true
|
|
37
|
+
},
|
|
38
|
+
grid: {
|
|
39
|
+
kBCFzs: "x1osaytk",
|
|
40
|
+
k1xSpc: "xrvj5dj",
|
|
41
|
+
kumcoG: "x4w6khx",
|
|
42
|
+
khm7nJ: "xefgwda",
|
|
43
|
+
k3XXqK: "x1t137rt",
|
|
44
|
+
$$css: true
|
|
45
|
+
},
|
|
46
|
+
row: {
|
|
47
|
+
kBCFzs: "x1osaytk",
|
|
48
|
+
k1xSpc: "xrvj5dj",
|
|
49
|
+
kumcoG: "x4w6khx",
|
|
50
|
+
kGNEyG: "x6s0dn4",
|
|
51
|
+
$$css: true
|
|
52
|
+
},
|
|
53
|
+
dayLabel: {
|
|
54
|
+
kBCFzs: "xgkxs2y",
|
|
55
|
+
kwRFfy: "xea92sw",
|
|
56
|
+
kGuDYH: "xb5fjo1",
|
|
57
|
+
kLWn49: "xo5v014",
|
|
58
|
+
kMwMTN: "xe2mk2a",
|
|
59
|
+
khDVqt: "xuxw1ft",
|
|
60
|
+
$$css: true
|
|
61
|
+
},
|
|
62
|
+
cell: {
|
|
63
|
+
kVAEAm: "x1n2onr6",
|
|
64
|
+
kB7OPa: "x9f619",
|
|
65
|
+
k1xSpc: "xrvj5dj",
|
|
66
|
+
kgQiWS: "x1ku5rj1",
|
|
67
|
+
kzqmXN: "xzbjvqy",
|
|
68
|
+
kOBAk4: "x1plog1",
|
|
69
|
+
k7Eaqz: "xeuugli",
|
|
70
|
+
kmVPX3: "x1717udv",
|
|
71
|
+
kaIpWk: "x1b6xorz",
|
|
72
|
+
kkrTdU: "xt0e3qv",
|
|
73
|
+
k3XXqK: "x1t137rt x9v5kkp",
|
|
74
|
+
kMeerF: "x1de99jn",
|
|
75
|
+
kInvED: "x1y3gkto",
|
|
76
|
+
kjBf7l: "xi1ptex x1x84bn5",
|
|
77
|
+
$$css: true
|
|
78
|
+
},
|
|
79
|
+
clickable: {
|
|
80
|
+
kkrTdU: "x1ypdohk",
|
|
81
|
+
$$css: true
|
|
82
|
+
},
|
|
83
|
+
mark: {
|
|
84
|
+
k1xSpc: "x1lliihq",
|
|
85
|
+
kzqmXN: "xz950gh",
|
|
86
|
+
kZKoxP: "x1arfg6c",
|
|
87
|
+
kAXs8y: "x1kzknox",
|
|
88
|
+
$$css: true
|
|
89
|
+
},
|
|
90
|
+
square: {
|
|
91
|
+
kaIpWk: "x1cum3z5",
|
|
92
|
+
$$css: true
|
|
93
|
+
},
|
|
94
|
+
rounded: {
|
|
95
|
+
kaIpWk: "x1ijmkg9",
|
|
96
|
+
$$css: true
|
|
97
|
+
},
|
|
98
|
+
circle: {
|
|
99
|
+
kaIpWk: "x16rqkct",
|
|
100
|
+
$$css: true
|
|
101
|
+
},
|
|
102
|
+
level0: {
|
|
103
|
+
kWkggS: "x1rjxnwd",
|
|
104
|
+
$$css: true
|
|
105
|
+
},
|
|
106
|
+
level1: {
|
|
107
|
+
kWkggS: "xus7kxw",
|
|
108
|
+
$$css: true
|
|
109
|
+
},
|
|
110
|
+
level2: {
|
|
111
|
+
kWkggS: "xzu3jkp",
|
|
112
|
+
$$css: true
|
|
113
|
+
},
|
|
114
|
+
level3: {
|
|
115
|
+
kWkggS: "x16hdbtb",
|
|
116
|
+
$$css: true
|
|
117
|
+
},
|
|
118
|
+
level4: {
|
|
119
|
+
kWkggS: "x1olrfse",
|
|
120
|
+
$$css: true
|
|
121
|
+
},
|
|
122
|
+
legend: {
|
|
123
|
+
k1xSpc: "x78zum5",
|
|
124
|
+
kGNEyG: "x6s0dn4",
|
|
125
|
+
kjj79g: "x13a6bvl",
|
|
126
|
+
kOIVth: "xz09phk",
|
|
127
|
+
kGuDYH: "xb5fjo1",
|
|
128
|
+
kMwMTN: "xe2mk2a",
|
|
129
|
+
$$css: true
|
|
130
|
+
},
|
|
131
|
+
legendMark: {
|
|
132
|
+
k1xSpc: "x1lliihq",
|
|
133
|
+
kzqmXN: "x1fsd2vl",
|
|
134
|
+
kZKoxP: "x170jfvy",
|
|
135
|
+
kAXs8y: "x1kzknox",
|
|
136
|
+
$$css: true
|
|
137
|
+
},
|
|
138
|
+
tooltip: {
|
|
139
|
+
kVAEAm: "x10l6tqk",
|
|
140
|
+
kY2c9j: "x1vjfegm",
|
|
141
|
+
k87sOh: "x13vifvy",
|
|
142
|
+
kbCHJM: "xu96u03",
|
|
143
|
+
kB7OPa: "x9f619",
|
|
144
|
+
k8WAf4: "x1ncfnsi",
|
|
145
|
+
kg3NbH: "x1d6xsf",
|
|
146
|
+
kaIpWk: "x1b6xorz",
|
|
147
|
+
kWkggS: "x1878pr6",
|
|
148
|
+
kMwMTN: "xsi4m1h",
|
|
149
|
+
kMzoRj: "xmkeg23",
|
|
150
|
+
ksu8eU: "x1y0btm7",
|
|
151
|
+
kVAM5u: "x9r1u3d x1w1tqly",
|
|
152
|
+
kGVxlE: "xfw8du2",
|
|
153
|
+
kGuDYH: "xb5fjo1",
|
|
154
|
+
k63SB2: "x1vmg6u2",
|
|
155
|
+
kLWn49: "xau0z5x",
|
|
156
|
+
khDVqt: "xuxw1ft",
|
|
157
|
+
kfzvcC: "x47corl",
|
|
158
|
+
$$css: true
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const levels = [
|
|
162
|
+
styles.level0,
|
|
163
|
+
styles.level1,
|
|
164
|
+
styles.level2,
|
|
165
|
+
styles.level3,
|
|
166
|
+
styles.level4
|
|
167
|
+
];
|
|
168
|
+
export { levels, styles };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { HeatGraph } from "./heat-graph.jsx";
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { numberFormat } from "../internal/format.jsx";
|
|
2
|
+
import { hidden } from "../internal/hidden.styles.jsx";
|
|
3
|
+
import { defaultThresholds, stepOf, validThresholds } from "./model.jsx";
|
|
4
|
+
import { steps, styles } from "./heat-matrix.styles.jsx";
|
|
5
|
+
import * as stylex from "@stylexjs/stylex";
|
|
6
|
+
import { useLocale, useMessages } from "@zsherman/kit/locale-provider";
|
|
7
|
+
import { For, Show, createMemo, createSignal, omit, onSettled } from "solid-js";
|
|
8
|
+
// src/heat-matrix/heat-matrix.tsx
|
|
9
|
+
const DEFAULT_LABELS = {
|
|
10
|
+
missing: "No data",
|
|
11
|
+
empty: "No data",
|
|
12
|
+
legend: (label) => `${label}: scale`
|
|
13
|
+
};
|
|
14
|
+
const STEP_STYLES = [
|
|
15
|
+
void 0,
|
|
16
|
+
steps.s1,
|
|
17
|
+
steps.s2,
|
|
18
|
+
steps.s3,
|
|
19
|
+
steps.s4,
|
|
20
|
+
steps.s5
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* A table of values between two sets of things (routes from one region to another, services by hour),
|
|
24
|
+
* each cell shaded on a five-step heat scale from cool to hot, its value written on it. A real table: the
|
|
25
|
+
* headers name every cell for assistive technology. Plain DOM, so it renders on the server.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* <HeatMatrix
|
|
29
|
+
* label="Route RTT, peak increase over the range minimum"
|
|
30
|
+
* rows={["eu-central", "us-east"]}
|
|
31
|
+
* columns={["eu-central", "us-east"]}
|
|
32
|
+
* values={[[0.1, 4.6], [4.6, 0.1]]}
|
|
33
|
+
* format={(v) => `${v.toFixed(1)} ms`}
|
|
34
|
+
* muteDiagonal
|
|
35
|
+
* />
|
|
36
|
+
*/
|
|
37
|
+
function HeatMatrix(props) {
|
|
38
|
+
const rest = omit(props, "label", "rows", "columns", "values", "corner", "format", "thresholds", "muteDiagonal", "legend", "cellHeight", "labels", "class");
|
|
39
|
+
const locale = useLocale();
|
|
40
|
+
const messages = useMessages("heatMatrix");
|
|
41
|
+
const text = (k) => props.labels?.[k] ?? messages()?.[k] ?? DEFAULT_LABELS[k];
|
|
42
|
+
const muted = (r, c) => props.muteDiagonal === true && props.rows[r] !== void 0 && props.rows[r] === props.columns[c];
|
|
43
|
+
const model = createMemo(() => {
|
|
44
|
+
const scaled = [];
|
|
45
|
+
props.rows.forEach((_row, r) => props.columns.forEach((_col, c) => {
|
|
46
|
+
const v = props.values[r]?.[c];
|
|
47
|
+
if (v != null && Number.isFinite(v) && !muted(r, c)) scaled.push(v);
|
|
48
|
+
}));
|
|
49
|
+
const thresholds = validThresholds(props.thresholds) ?? defaultThresholds(scaled);
|
|
50
|
+
const largest = scaled.length ? Math.max(...scaled.map(Math.abs)) : 0;
|
|
51
|
+
const format = props.format ?? numberFormat(locale(), largest);
|
|
52
|
+
return {
|
|
53
|
+
rows: props.rows.map((label, r) => ({
|
|
54
|
+
label,
|
|
55
|
+
cells: props.columns.map((column, c) => {
|
|
56
|
+
const v = props.values[r]?.[c];
|
|
57
|
+
const value = v != null && Number.isFinite(v) ? v : null;
|
|
58
|
+
return {
|
|
59
|
+
column,
|
|
60
|
+
value,
|
|
61
|
+
text: value == null ? "–" : format(value),
|
|
62
|
+
step: muted(r, c) ? 0 : stepOf(value, thresholds)
|
|
63
|
+
};
|
|
64
|
+
})
|
|
65
|
+
})),
|
|
66
|
+
scale: thresholds.every(Number.isFinite) ? [
|
|
67
|
+
1,
|
|
68
|
+
2,
|
|
69
|
+
3,
|
|
70
|
+
4,
|
|
71
|
+
5
|
|
72
|
+
].map((step) => {
|
|
73
|
+
const lo = thresholds[step - 2];
|
|
74
|
+
const hi = thresholds[step - 1];
|
|
75
|
+
return {
|
|
76
|
+
step,
|
|
77
|
+
text: lo === void 0 ? `< ${format(hi)}` : hi === void 0 ? `≥ ${format(lo)}` : `${format(lo)} – ${format(hi)}`
|
|
78
|
+
};
|
|
79
|
+
}) : []
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
const [active, setActive] = createSignal(null);
|
|
83
|
+
const indexOf = (event) => {
|
|
84
|
+
const cell = event.target.closest("[data-r]");
|
|
85
|
+
return cell ? {
|
|
86
|
+
r: Number(cell.dataset["r"]),
|
|
87
|
+
c: Number(cell.dataset["c"])
|
|
88
|
+
} : null;
|
|
89
|
+
};
|
|
90
|
+
let scroller;
|
|
91
|
+
let observer;
|
|
92
|
+
const [scrolls, setScrolls] = createSignal(false);
|
|
93
|
+
onSettled(() => {
|
|
94
|
+
observer = new ResizeObserver(() => {
|
|
95
|
+
if (scroller?.isConnected) setScrolls(scroller.scrollWidth > scroller.clientWidth + 1);
|
|
96
|
+
});
|
|
97
|
+
if (scroller) observer.observe(scroller);
|
|
98
|
+
return () => observer?.disconnect();
|
|
99
|
+
});
|
|
100
|
+
/** The row headers' column: wide enough for the longest label, within reason. */
|
|
101
|
+
const headerWidth = () => {
|
|
102
|
+
return `min(${Math.max(4, ...props.rows.map((r) => r.length)) + 3}ch, 14rem)`;
|
|
103
|
+
};
|
|
104
|
+
return <div {...rest} data-slot="heat-matrix" class={[stylex.props(styles.root).className, props.class]} style={{
|
|
105
|
+
"--hm-cell-height": `${props.cellHeight ?? 32}px`,
|
|
106
|
+
"--hm-header": headerWidth()
|
|
107
|
+
}}>
|
|
108
|
+
<Show when={props.rows.length && props.columns.length} fallback={<p data-slot="heat-matrix-empty" {...stylex.attrs(styles.emptyText)}>
|
|
109
|
+
{text("empty")}
|
|
110
|
+
</p>}>
|
|
111
|
+
<div ref={(el) => {
|
|
112
|
+
scroller = el;
|
|
113
|
+
observer?.observe(el);
|
|
114
|
+
}} data-slot="heat-matrix-scroller" tabindex={scrolls() ? 0 : void 0} role={scrolls() ? "region" : void 0} aria-label={scrolls() ? props.label : void 0} {...stylex.attrs(styles.scroller)}>
|
|
115
|
+
<table aria-label={props.label} data-slot="heat-matrix-table" {...stylex.attrs(styles.table)} style={{ "min-width": `calc(var(--hm-header) + ${props.columns.length} * 4.5rem)` }} onPointerOver={(e) => setActive(indexOf(e))} onPointerLeave={() => setActive(null)}>
|
|
116
|
+
<colgroup>
|
|
117
|
+
<col {...stylex.attrs(styles.headerColumn)} />
|
|
118
|
+
</colgroup>
|
|
119
|
+
<thead>
|
|
120
|
+
<tr>
|
|
121
|
+
<td data-slot="heat-matrix-corner" {...stylex.attrs(styles.corner)}>
|
|
122
|
+
{props.corner}
|
|
123
|
+
</td>
|
|
124
|
+
<For each={props.columns}>
|
|
125
|
+
{(column, c) => <th scope="col" title={column} data-slot="heat-matrix-column" data-active={active()?.c === c() ? "" : void 0} {...stylex.attrs(styles.columnHeader)}>
|
|
126
|
+
{column}
|
|
127
|
+
</th>}
|
|
128
|
+
</For>
|
|
129
|
+
</tr>
|
|
130
|
+
</thead>
|
|
131
|
+
<tbody>
|
|
132
|
+
<For each={model().rows} keyed={false}>
|
|
133
|
+
{(row, r) => <tr>
|
|
134
|
+
<th scope="row" title={row().label} data-slot="heat-matrix-row" data-active={active()?.r === r ? "" : void 0} {...stylex.attrs(styles.rowHeader)}>
|
|
135
|
+
{row().label}
|
|
136
|
+
</th>
|
|
137
|
+
<For each={row().cells} keyed={false}>
|
|
138
|
+
{(cell, c) => <td data-slot="heat-matrix-cell" data-r={r} data-c={c} data-step={cell().step} data-active={active()?.r === r && active()?.c === c ? "" : void 0} {...stylex.attrs(styles.cell, cell().step === 0 ? styles.empty : STEP_STYLES[cell().step])}>
|
|
139
|
+
<Show when={cell().value != null} fallback={<>
|
|
140
|
+
<span aria-hidden="true">–</span>
|
|
141
|
+
<span {...stylex.attrs(hidden.visually)}>{text("missing")}</span>
|
|
142
|
+
</>}>
|
|
143
|
+
{cell().text}
|
|
144
|
+
</Show>
|
|
145
|
+
</td>}
|
|
146
|
+
</For>
|
|
147
|
+
</tr>}
|
|
148
|
+
</For>
|
|
149
|
+
</tbody>
|
|
150
|
+
</table>
|
|
151
|
+
</div>
|
|
152
|
+
<Show when={props.legend !== false && model().scale.length}>
|
|
153
|
+
<ul data-slot="heat-matrix-legend" aria-label={text("legend")(props.label)} {...stylex.attrs(styles.legend)}>
|
|
154
|
+
<For each={model().scale} keyed={false}>
|
|
155
|
+
{(s) => <li {...stylex.attrs(styles.legendItem)}>
|
|
156
|
+
<span aria-hidden="true" {...stylex.attrs(styles.legendSwatch, STEP_STYLES[s().step])} />
|
|
157
|
+
{s().text}
|
|
158
|
+
</li>}
|
|
159
|
+
</For>
|
|
160
|
+
</ul>
|
|
161
|
+
</Show>
|
|
162
|
+
</Show>
|
|
163
|
+
</div>;
|
|
164
|
+
}
|
|
165
|
+
export { HeatMatrix };
|