@timefoldai/viz-react 0.0.0 → 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/README.md +239 -1
- package/dist/THIRD-PARTY-NOTICES.txt +99 -0
- package/dist/a11y/AccessibleTable.d.mts +42 -0
- package/dist/a11y/AccessibleTable.mjs +82 -0
- package/dist/a11y/activation.d.mts +4 -0
- package/dist/a11y/activation.mjs +0 -0
- package/dist/analytics/AnalyticsProvider.d.mts +16 -0
- package/dist/analytics/AnalyticsProvider.mjs +32 -0
- package/dist/assets/Inter-latin-ext.woff2 +0 -0
- package/dist/badge/Badge.css +122 -0
- package/dist/badge/Badge.d.mts +50 -0
- package/dist/badge/Badge.mjs +145 -0
- package/dist/badge/Badge.module.css.mjs +15 -0
- package/dist/badge/BadgeFacetGroup.d.mts +23 -0
- package/dist/badge/BadgeFacetGroup.mjs +220 -0
- package/dist/badge/BadgeGroup.d.mts +13 -0
- package/dist/badge/BadgeGroup.mjs +53 -0
- package/dist/badge/BadgeList.d.mts +14 -0
- package/dist/badge/BadgeList.mjs +15 -0
- package/dist/badge/badge-facet-fit.d.mts +18 -0
- package/dist/badge/badge-facet-fit.mjs +50 -0
- package/dist/badge/badge-item.d.mts +19 -0
- package/dist/badge/badge-item.mjs +23 -0
- package/dist/button/CopyButton.d.mts +12 -0
- package/dist/button/CopyButton.mjs +52 -0
- package/dist/button/ShowAllButton.d.mts +14 -0
- package/dist/button/ShowAllButton.mjs +61 -0
- package/dist/button/ShowMoreButton.d.mts +13 -0
- package/dist/button/ShowMoreButton.mjs +51 -0
- package/dist/button/SolveButton.d.mts +16 -0
- package/dist/button/SolveButton.mjs +56 -0
- package/dist/charts/BarChart.css +59 -0
- package/dist/charts/BarChart.d.mts +26 -0
- package/dist/charts/BarChart.mjs +167 -0
- package/dist/charts/BarChart.module.css.mjs +10 -0
- package/dist/charts/ChartGrid.d.mts +8 -0
- package/dist/charts/ChartGrid.mjs +47 -0
- package/dist/charts/DistributionChart.d.mts +60 -0
- package/dist/charts/DistributionChart.mjs +151 -0
- package/dist/code/CodeBlock.d.mts +13 -0
- package/dist/code/CodeBlock.mjs +71 -0
- package/dist/composition-bar/CompositionBar.d.mts +24 -0
- package/dist/composition-bar/CompositionBar.mjs +124 -0
- package/dist/composition-bar/composition-shares.d.mts +8 -0
- package/dist/composition-bar/composition-shares.mjs +30 -0
- package/dist/data-gate/DataGate.d.mts +34 -0
- package/dist/data-gate/DataGate.mjs +80 -0
- package/dist/date-scope/DateScope.d.mts +30 -0
- package/dist/date-scope/DateScope.mjs +285 -0
- package/dist/design-system/part-props.d.mts +39 -0
- package/dist/design-system/part-props.mjs +0 -0
- package/dist/detail-panel/DetailPanel.d.mts +22 -0
- package/dist/detail-panel/DetailPanel.mjs +80 -0
- package/dist/detail-panel/DetailPanelSection.d.mts +20 -0
- package/dist/detail-panel/DetailPanelSection.mjs +27 -0
- package/dist/detail-panel/micro-label.d.mts +7 -0
- package/dist/detail-panel/micro-label.mjs +9 -0
- package/dist/env.d.mts +2 -0
- package/dist/env.mjs +4 -0
- package/dist/export/ExportCsvButton.d.mts +19 -0
- package/dist/export/ExportCsvButton.mjs +73 -0
- package/dist/export/download-csv.d.mts +5 -0
- package/dist/export/download-csv.mjs +11 -0
- package/dist/export/download-file.d.mts +11 -0
- package/dist/export/download-file.mjs +32 -0
- package/dist/export/download-json.d.mts +2 -0
- package/dist/export/download-json.mjs +8 -0
- package/dist/filter/FilterGroup.d.mts +24 -0
- package/dist/filter/FilterGroup.mjs +71 -0
- package/dist/filter/FilterGroupTitle.d.mts +3 -0
- package/dist/filter/FilterGroupTitle.mjs +18 -0
- package/dist/filter/FilterItem.d.mts +17 -0
- package/dist/filter/FilterItem.mjs +94 -0
- package/dist/filter/FilterPanel.d.mts +22 -0
- package/dist/filter/FilterPanel.mjs +158 -0
- package/dist/filter/FilterToggleButton.d.mts +15 -0
- package/dist/filter/FilterToggleButton.mjs +30 -0
- package/dist/filter/date-range.d.mts +8 -0
- package/dist/filter/date-range.mjs +13 -0
- package/dist/filter/filter-facet.d.mts +7 -0
- package/dist/filter/filter-facet.mjs +0 -0
- package/dist/heatmap/Heatmap.css +138 -0
- package/dist/heatmap/Heatmap.d.mts +10 -0
- package/dist/heatmap/Heatmap.mjs +370 -0
- package/dist/heatmap/Heatmap.module.css.mjs +17 -0
- package/dist/heatmap/HeatmapCell.d.mts +25 -0
- package/dist/heatmap/HeatmapCell.mjs +124 -0
- package/dist/heatmap/heatmap-scale.d.mts +19 -0
- package/dist/heatmap/heatmap-scale.mjs +43 -0
- package/dist/heatmap/heatmap-types.d.mts +49 -0
- package/dist/heatmap/heatmap-types.mjs +0 -0
- package/dist/hooks/use-controllable-state.d.mts +9 -0
- package/dist/hooks/use-controllable-state.mjs +44 -0
- package/dist/hooks/use-debounced-value.d.mts +1 -0
- package/dist/hooks/use-debounced-value.mjs +27 -0
- package/dist/hooks/use-detail-panel-layout.d.mts +18 -0
- package/dist/hooks/use-detail-panel-layout.mjs +94 -0
- package/dist/hooks/use-hover-card.d.mts +47 -0
- package/dist/hooks/use-hover-card.mjs +190 -0
- package/dist/hooks/use-hover-focus-card.d.mts +38 -0
- package/dist/hooks/use-hover-focus-card.mjs +321 -0
- package/dist/hooks/use-hover-intent.d.mts +6 -0
- package/dist/hooks/use-hover-intent.mjs +55 -0
- package/dist/hooks/use-merged-ref.d.mts +2 -0
- package/dist/hooks/use-merged-ref.mjs +36 -0
- package/dist/hooks/use-tracked-anchor.d.mts +14 -0
- package/dist/hooks/use-tracked-anchor.mjs +42 -0
- package/dist/index.d.mts +97 -0
- package/dist/index.mjs +88 -0
- package/dist/input/MenuButton.d.mts +47 -0
- package/dist/input/MenuButton.mjs +152 -0
- package/dist/interval-strip/IntervalStrip.css +7 -0
- package/dist/interval-strip/IntervalStrip.d.mts +39 -0
- package/dist/interval-strip/IntervalStrip.mjs +233 -0
- package/dist/interval-strip/IntervalStrip.module.css.mjs +4 -0
- package/dist/interval-strip/IntervalStripAxis.d.mts +18 -0
- package/dist/interval-strip/IntervalStripAxis.mjs +73 -0
- package/dist/interval-strip/interval-fill.d.mts +2 -0
- package/dist/interval-strip/interval-fill.mjs +13 -0
- package/dist/interval-strip/interval-layout.d.mts +33 -0
- package/dist/interval-strip/interval-layout.mjs +79 -0
- package/dist/layout/AppShell.css +103 -0
- package/dist/layout/AppShell.d.mts +73 -0
- package/dist/layout/AppShell.mjs +397 -0
- package/dist/layout/AppShell.module.css.mjs +16 -0
- package/dist/layout/ColorSchemeMenu.d.mts +14 -0
- package/dist/layout/ColorSchemeMenu.mjs +92 -0
- package/dist/layout/DemoDataPicker.d.mts +17 -0
- package/dist/layout/DemoDataPicker.mjs +150 -0
- package/dist/layout/OverflowMenu.d.mts +11 -0
- package/dist/layout/OverflowMenu.mjs +94 -0
- package/dist/layout/SidebarLayout.css +70 -0
- package/dist/layout/SidebarLayout.d.mts +33 -0
- package/dist/layout/SidebarLayout.mjs +129 -0
- package/dist/layout/SidebarLayout.module.css.mjs +8 -0
- package/dist/layout/use-date-scope-day.d.mts +23 -0
- package/dist/layout/use-date-scope-day.mjs +63 -0
- package/dist/layout/use-fill-height.d.mts +7 -0
- package/dist/layout/use-fill-height.mjs +50 -0
- package/dist/layout/use-followed-state.d.mts +5 -0
- package/dist/layout/use-followed-state.mjs +75 -0
- package/dist/layout/use-page-route.d.mts +10 -0
- package/dist/layout/use-page-route.mjs +65 -0
- package/dist/legend/Legend.d.mts +54 -0
- package/dist/legend/Legend.mjs +132 -0
- package/dist/map/MapLayersControl.d.mts +11 -0
- package/dist/map/MapLayersControl.mjs +157 -0
- package/dist/map/MapLocator.css +9 -0
- package/dist/map/MapLocator.d.mts +18 -0
- package/dist/map/MapLocator.mjs +97 -0
- package/dist/map/MapLocator.module.css.mjs +4 -0
- package/dist/map/MapMarker.d.mts +29 -0
- package/dist/map/MapMarker.mjs +265 -0
- package/dist/map/MapStops.d.mts +19 -0
- package/dist/map/MapStops.mjs +355 -0
- package/dist/map/MapView.css +24 -0
- package/dist/map/MapView.d.mts +11 -0
- package/dist/map/MapView.mjs +141 -0
- package/dist/map/MapWebgl.d.mts +9 -0
- package/dist/map/MapWebgl.mjs +727 -0
- package/dist/map/area-layers.d.mts +33 -0
- package/dist/map/area-layers.mjs +96 -0
- package/dist/map/control-group.d.mts +6 -0
- package/dist/map/control-group.mjs +12 -0
- package/dist/map/for-each-chunk.d.mts +4 -0
- package/dist/map/for-each-chunk.mjs +14 -0
- package/dist/map/highlight.d.mts +30 -0
- package/dist/map/highlight.mjs +99 -0
- package/dist/map/locator-tile.d.mts +24 -0
- package/dist/map/locator-tile.mjs +41 -0
- package/dist/map/map-sites.d.mts +12 -0
- package/dist/map/map-sites.mjs +39 -0
- package/dist/map/map-style.d.mts +24 -0
- package/dist/map/map-style.mjs +79 -0
- package/dist/map/marker-geometry.d.mts +5 -0
- package/dist/map/marker-geometry.mjs +13 -0
- package/dist/map/marker-icon.d.mts +26 -0
- package/dist/map/marker-icon.mjs +223 -0
- package/dist/map/observe-color-scheme.d.mts +5 -0
- package/dist/map/observe-color-scheme.mjs +19 -0
- package/dist/map/popup-placement.d.mts +20 -0
- package/dist/map/popup-placement.mjs +20 -0
- package/dist/map/route-layers.d.mts +28 -0
- package/dist/map/route-layers.mjs +73 -0
- package/dist/map/types.d.mts +97 -0
- package/dist/map/types.mjs +0 -0
- package/dist/map/use-painted-color-scheme.d.mts +6 -0
- package/dist/map/use-painted-color-scheme.mjs +43 -0
- package/dist/map/use-resolved-colors.d.mts +5 -0
- package/dist/map/use-resolved-colors.mjs +63 -0
- package/dist/pagination/paginationLabels.d.mts +6 -0
- package/dist/pagination/paginationLabels.mjs +8 -0
- package/dist/popover/Popover.css +176 -0
- package/dist/popover/Popover.d.mts +239 -0
- package/dist/popover/Popover.mjs +672 -0
- package/dist/popover/Popover.module.css.mjs +18 -0
- package/dist/popover/PopoverFacts.d.mts +24 -0
- package/dist/popover/PopoverFacts.mjs +63 -0
- package/dist/readout/Readout.d.mts +15 -0
- package/dist/readout/Readout.mjs +53 -0
- package/dist/readout/TimeZoneReadout.d.mts +11 -0
- package/dist/readout/TimeZoneReadout.mjs +46 -0
- package/dist/score-box/ScoreBox.css +62 -0
- package/dist/score-box/ScoreBox.d.mts +12 -0
- package/dist/score-box/ScoreBox.mjs +143 -0
- package/dist/score-box/ScoreBox.module.css.mjs +15 -0
- package/dist/segment-bar/Segment.d.mts +23 -0
- package/dist/segment-bar/Segment.mjs +27 -0
- package/dist/segment-bar/SegmentBar.css +44 -0
- package/dist/segment-bar/SegmentBar.d.mts +35 -0
- package/dist/segment-bar/SegmentBar.mjs +57 -0
- package/dist/segment-bar/SegmentBar.module.css.mjs +9 -0
- package/dist/segment-bar/segment-box.d.mts +10 -0
- package/dist/segment-bar/segment-box.mjs +30 -0
- package/dist/stat/Stat.d.mts +25 -0
- package/dist/stat/Stat.mjs +36 -0
- package/dist/stat/StatTile.d.mts +18 -0
- package/dist/stat/StatTile.mjs +37 -0
- package/dist/styles.css +1 -0
- package/dist/swatch/Swatch.d.mts +8 -0
- package/dist/swatch/Swatch.mjs +30 -0
- package/dist/swatch/legend-swatch.d.mts +3 -0
- package/dist/swatch/legend-swatch.mjs +0 -0
- package/dist/tab-bar/FilteredTabBar.d.mts +32 -0
- package/dist/tab-bar/FilteredTabBar.mjs +181 -0
- package/dist/tab-bar/TabBar.d.mts +22 -0
- package/dist/tab-bar/TabBar.mjs +151 -0
- package/dist/tab-bar/TabPanel.d.mts +9 -0
- package/dist/tab-bar/TabPanel.mjs +55 -0
- package/dist/tab-bar/assert-named-value.d.mts +4 -0
- package/dist/tab-bar/assert-named-value.mjs +6 -0
- package/dist/table/DataTable.d.mts +31 -0
- package/dist/table/DataTable.mjs +43 -0
- package/dist/theme/use-color-scheme.d.mts +14 -0
- package/dist/theme/use-color-scheme.mjs +92 -0
- package/dist/theme.css +58 -0
- package/dist/timeline/Timeline.d.mts +54 -0
- package/dist/timeline/Timeline.mjs +220 -0
- package/dist/timeline/TimelineBand.d.mts +18 -0
- package/dist/timeline/TimelineBand.mjs +30 -0
- package/dist/timeline/TimelineGroup.d.mts +7 -0
- package/dist/timeline/TimelineGroup.mjs +50 -0
- package/dist/timeline/TimelineItem.d.mts +19 -0
- package/dist/timeline/TimelineItem.mjs +64 -0
- package/dist/timeline/TimelineItemChip.css +153 -0
- package/dist/timeline/TimelineItemChip.d.mts +23 -0
- package/dist/timeline/TimelineItemChip.mjs +74 -0
- package/dist/timeline/TimelineItemChip.module.css.mjs +15 -0
- package/dist/timeline/TimelineItemMark.css +38 -0
- package/dist/timeline/TimelineItemMark.d.mts +15 -0
- package/dist/timeline/TimelineItemMark.mjs +129 -0
- package/dist/timeline/TimelineItemMark.module.css.mjs +4 -0
- package/dist/timeline/TimelineRoot.d.mts +19 -0
- package/dist/timeline/TimelineRoot.mjs +742 -0
- package/dist/timeline/TimelineRowHeader.d.mts +23 -0
- package/dist/timeline/TimelineRowHeader.mjs +244 -0
- package/dist/timeline/TimelineZoomHint.d.mts +9 -0
- package/dist/timeline/TimelineZoomHint.mjs +32 -0
- package/dist/timeline/axis-label.d.mts +5 -0
- package/dist/timeline/axis-label.mjs +53 -0
- package/dist/timeline/batched-dataset-writer.d.mts +29 -0
- package/dist/timeline/batched-dataset-writer.mjs +58 -0
- package/dist/timeline/row-card-side.d.mts +7 -0
- package/dist/timeline/row-card-side.mjs +6 -0
- package/dist/timeline/timeline-a11y.d.mts +33 -0
- package/dist/timeline/timeline-a11y.mjs +96 -0
- package/dist/timeline/timeline-context.d.mts +33 -0
- package/dist/timeline/timeline-context.mjs +40 -0
- package/dist/timeline/timeline-types.d.mts +126 -0
- package/dist/timeline/timeline-types.mjs +0 -0
- package/dist/timeline/timeline-utils.d.mts +52 -0
- package/dist/timeline/timeline-utils.mjs +130 -0
- package/dist/timeline/zoom-modifier.d.mts +21 -0
- package/dist/timeline/zoom-modifier.mjs +25 -0
- package/dist/toast/ToastProvider.d.mts +33 -0
- package/dist/toast/ToastProvider.mjs +257 -0
- package/dist/toast/toast-context.d.mts +2 -0
- package/dist/toast/toast-context.mjs +5 -0
- package/dist/tokens.css +1 -0
- package/dist/tooltip/Tooltip.d.mts +17 -0
- package/dist/tooltip/Tooltip.mjs +41 -0
- package/dist/tooltip/hover-open-delay.d.mts +2 -0
- package/dist/tooltip/hover-open-delay.mjs +4 -0
- package/dist/tooltip/is-text-cut.d.mts +1 -0
- package/dist/tooltip/is-text-cut.mjs +5 -0
- package/dist/vendor/components.d.mts +664 -0
- package/dist/vendor/components.mjs +2060 -0
- package/package.json +56 -5
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { isDevBuild } from "../env.mjs";
|
|
3
|
+
import { useHoverFocusCard } from "../hooks/use-hover-focus-card.mjs";
|
|
4
|
+
import Popover from "../popover/Popover.mjs";
|
|
5
|
+
import { defaultFormat, findDuplicateIds, isNoData, normalizeValue, resolveDomain, warnOnce } from "./heatmap-scale.mjs";
|
|
6
|
+
import HeatmapCell from "./HeatmapCell.mjs";
|
|
7
|
+
import Heatmap_module_default from "./Heatmap.module.css.mjs";
|
|
8
|
+
import { c } from "react/compiler-runtime";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
import { useCallback, useEffect, useId, useRef, useState } from "react";
|
|
11
|
+
import clsx$1 from "clsx";
|
|
12
|
+
// src/heatmap/Heatmap.tsx
|
|
13
|
+
function focusRovingCell(grid) {
|
|
14
|
+
grid?.querySelector("[role=\"gridcell\"][tabindex=\"0\"]")?.focus();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Heatmap grid visualization: typed, id-keyed rows/columns with one or more value layers per cell.
|
|
18
|
+
* Accessible as an APG grid with roving tabindex, keyboard navigation, and focus-driven popovers.
|
|
19
|
+
*
|
|
20
|
+
* @see https://www.w3.org/WAI/ARIA/apg/patterns/grid/
|
|
21
|
+
* @category Charts
|
|
22
|
+
*/
|
|
23
|
+
function Heatmap({ rows, columns, layers, renderPopover, onCellActivate, selectedCell, rowAxisPosition = "left", columnAxisPosition = "top", "aria-label": ariaLabel, variant = "chip", className, style, ref }) {
|
|
24
|
+
const gridRef = useRef(null);
|
|
25
|
+
const popupId = useId();
|
|
26
|
+
const factsId = useId();
|
|
27
|
+
const warnedRef = useRef(/* @__PURE__ */ new Set());
|
|
28
|
+
const refocusGrid = useCallback(() => focusRovingCell(gridRef.current), []);
|
|
29
|
+
const [cursor, setCursor] = useState({
|
|
30
|
+
row: 0,
|
|
31
|
+
col: 0
|
|
32
|
+
});
|
|
33
|
+
const pendingWarnings = [];
|
|
34
|
+
const queuedWarningKeys = /* @__PURE__ */ new Set();
|
|
35
|
+
function queueWarning(key, message) {
|
|
36
|
+
if (queuedWarningKeys.has(key)) return;
|
|
37
|
+
queuedWarningKeys.add(key);
|
|
38
|
+
pendingWarnings.push({
|
|
39
|
+
key,
|
|
40
|
+
message
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (isDevBuild) for (const [kind, entries] of [
|
|
44
|
+
["row", rows],
|
|
45
|
+
["column", columns],
|
|
46
|
+
["layer", layers]
|
|
47
|
+
]) for (const id of findDuplicateIds(entries)) queueWarning(`dup:${kind}:${id}`, `duplicate ${kind} id "${id}", ids must be unique.`);
|
|
48
|
+
const rowCtx = rows.map((entry, index) => ({
|
|
49
|
+
...entry,
|
|
50
|
+
index
|
|
51
|
+
}));
|
|
52
|
+
const colCtx = columns.map((entry_0, index_0) => ({
|
|
53
|
+
...entry_0,
|
|
54
|
+
index: index_0
|
|
55
|
+
}));
|
|
56
|
+
const card = useHoverFocusCard({
|
|
57
|
+
popupId,
|
|
58
|
+
renderPopover: (cell) => {
|
|
59
|
+
const row = rowCtx[cell.row];
|
|
60
|
+
const column = colCtx[cell.col];
|
|
61
|
+
return row && column ? renderPopover?.({
|
|
62
|
+
row,
|
|
63
|
+
column
|
|
64
|
+
}) : null;
|
|
65
|
+
},
|
|
66
|
+
refocusFallback: refocusGrid
|
|
67
|
+
});
|
|
68
|
+
const resolvedLayers = layers.map((layer) => {
|
|
69
|
+
const values = rowCtx.map((row_0) => colCtx.map((col) => {
|
|
70
|
+
const raw = layer.value(row_0, col);
|
|
71
|
+
if (raw != null && !Number.isFinite(raw)) {
|
|
72
|
+
queueWarning(`nonfinite:${layer.id}`, `layer "${layer.id}" returned a non-finite value; treating it as no data.`);
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
return raw ?? null;
|
|
76
|
+
}));
|
|
77
|
+
if (Array.isArray(layer.scale) && layer.scale[0] > layer.scale[1]) queueWarning(`domain:${layer.id}`, `layer "${layer.id}" has an inverted [min, max] domain; treating it as [${layer.scale[1]}, ${layer.scale[0]}].`);
|
|
78
|
+
let max = 0;
|
|
79
|
+
for (const rowValues of values) for (const value of rowValues) if (value !== null && value > max) max = value;
|
|
80
|
+
return {
|
|
81
|
+
layer,
|
|
82
|
+
values,
|
|
83
|
+
domain: resolveDomain(layer.scale, max),
|
|
84
|
+
format: layer.formatValue ?? defaultFormat(layer.scale)
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
for (const { key: key_0, message: message_0 } of pendingWarnings) warnOnce(warnedRef.current, key_0, message_0);
|
|
89
|
+
});
|
|
90
|
+
function cellTexts(row_1, col_0) {
|
|
91
|
+
return resolvedLayers.map(({ values: values_0, format: format_0 }) => {
|
|
92
|
+
const value_0 = values_0[row_1.index]?.[col_0.index];
|
|
93
|
+
return isNoData(value_0) ? null : format_0(value_0);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function cellAriaLabel(row_2, col_1) {
|
|
97
|
+
const texts = cellTexts(row_2, col_1);
|
|
98
|
+
const parts = resolvedLayers.map(({ layer: layer_0 }, i) => `${layer_0.label} ${texts[i] ?? "no data"}`);
|
|
99
|
+
return `${col_1.label} ${row_2.label}, ${parts.join(", ")}`;
|
|
100
|
+
}
|
|
101
|
+
function cellLayers(row_3, col_2) {
|
|
102
|
+
return resolvedLayers.map(({ layer: layer_1, values: values_1, domain: domain_0, format: format_1 }) => {
|
|
103
|
+
const value_1 = values_1[row_3.index]?.[col_2.index];
|
|
104
|
+
return isNoData(value_1) ? {
|
|
105
|
+
id: layer_1.id,
|
|
106
|
+
text: null,
|
|
107
|
+
t: 0,
|
|
108
|
+
color: layer_1.color
|
|
109
|
+
} : {
|
|
110
|
+
id: layer_1.id,
|
|
111
|
+
text: format_1(value_1),
|
|
112
|
+
t: normalizeValue(value_1, domain_0),
|
|
113
|
+
color: layer_1.color
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
const activatable = onCellActivate !== void 0;
|
|
118
|
+
function activate(row_4, col_3, source) {
|
|
119
|
+
card.close();
|
|
120
|
+
const rowContext = rowCtx[row_4];
|
|
121
|
+
const colContext = colCtx[col_3];
|
|
122
|
+
if (rowContext && colContext) onCellActivate?.({
|
|
123
|
+
row: rowContext,
|
|
124
|
+
column: colContext
|
|
125
|
+
}, { source });
|
|
126
|
+
}
|
|
127
|
+
function handlePointerIn(row_5, col_4, element) {
|
|
128
|
+
card.hoverIn({
|
|
129
|
+
row: row_5,
|
|
130
|
+
col: col_4,
|
|
131
|
+
element
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function handlePointerOut(row_6, col_5, element_0) {
|
|
135
|
+
card.hoverOut({
|
|
136
|
+
row: row_6,
|
|
137
|
+
col: col_5,
|
|
138
|
+
element: element_0
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function handleFocusIn(row_7, col_6, element_1) {
|
|
142
|
+
setCursor({
|
|
143
|
+
row: row_7,
|
|
144
|
+
col: col_6
|
|
145
|
+
});
|
|
146
|
+
card.focusIn({
|
|
147
|
+
row: row_7,
|
|
148
|
+
col: col_6,
|
|
149
|
+
element: element_1
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
function onGridKeyDown(event) {
|
|
153
|
+
if (event.key === "Tab") {
|
|
154
|
+
card.close();
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (rows.length === 0 || columns.length === 0) return;
|
|
158
|
+
const lastRow = rows.length - 1;
|
|
159
|
+
const lastCol = columns.length - 1;
|
|
160
|
+
const current = {
|
|
161
|
+
row: Math.min(cursor.row, lastRow),
|
|
162
|
+
col: Math.min(cursor.col, lastCol)
|
|
163
|
+
};
|
|
164
|
+
let next;
|
|
165
|
+
switch (event.key) {
|
|
166
|
+
case "ArrowRight":
|
|
167
|
+
next = {
|
|
168
|
+
...current,
|
|
169
|
+
col: Math.min(current.col + 1, lastCol)
|
|
170
|
+
};
|
|
171
|
+
break;
|
|
172
|
+
case "ArrowLeft":
|
|
173
|
+
next = {
|
|
174
|
+
...current,
|
|
175
|
+
col: Math.max(current.col - 1, 0)
|
|
176
|
+
};
|
|
177
|
+
break;
|
|
178
|
+
case "ArrowDown":
|
|
179
|
+
next = {
|
|
180
|
+
...current,
|
|
181
|
+
row: Math.min(current.row + 1, lastRow)
|
|
182
|
+
};
|
|
183
|
+
break;
|
|
184
|
+
case "ArrowUp":
|
|
185
|
+
next = {
|
|
186
|
+
...current,
|
|
187
|
+
row: Math.max(current.row - 1, 0)
|
|
188
|
+
};
|
|
189
|
+
break;
|
|
190
|
+
case "Home":
|
|
191
|
+
next = event.ctrlKey ? {
|
|
192
|
+
row: 0,
|
|
193
|
+
col: 0
|
|
194
|
+
} : {
|
|
195
|
+
...current,
|
|
196
|
+
col: 0
|
|
197
|
+
};
|
|
198
|
+
break;
|
|
199
|
+
case "End":
|
|
200
|
+
next = event.ctrlKey ? {
|
|
201
|
+
row: lastRow,
|
|
202
|
+
col: lastCol
|
|
203
|
+
} : {
|
|
204
|
+
...current,
|
|
205
|
+
col: lastCol
|
|
206
|
+
};
|
|
207
|
+
break;
|
|
208
|
+
case "Enter":
|
|
209
|
+
case " ":
|
|
210
|
+
if (!activatable) return;
|
|
211
|
+
event.preventDefault();
|
|
212
|
+
activate(current.row, current.col, "keyboard");
|
|
213
|
+
return;
|
|
214
|
+
default: return;
|
|
215
|
+
}
|
|
216
|
+
event.preventDefault();
|
|
217
|
+
setCursor(next);
|
|
218
|
+
gridRef.current?.querySelector(`[data-row="${next.row}"][data-col="${next.col}"]`)?.focus();
|
|
219
|
+
}
|
|
220
|
+
const focusCardCell = card.open && card.focusOwned ? card.target : null;
|
|
221
|
+
if (rows.length === 0 || columns.length === 0 || layers.length === 0) return /* @__PURE__ */ jsx("div", {
|
|
222
|
+
ref,
|
|
223
|
+
className: clsx$1("viz-heatmap-container", className),
|
|
224
|
+
style,
|
|
225
|
+
"data-slot": "heatmap",
|
|
226
|
+
"data-variant": variant,
|
|
227
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
228
|
+
className: Heatmap_module_default["viz-heatmap-empty"],
|
|
229
|
+
children: "No data"
|
|
230
|
+
})
|
|
231
|
+
});
|
|
232
|
+
const tabRow = Math.min(cursor.row, rows.length - 1);
|
|
233
|
+
const tabCol = Math.min(cursor.col, columns.length - 1);
|
|
234
|
+
const selectedRow = selectedCell ? rows.findIndex((entry_1) => entry_1.id === selectedCell.row) : -1;
|
|
235
|
+
const selectedCol = selectedCell ? columns.findIndex((entry_2) => entry_2.id === selectedCell.column) : -1;
|
|
236
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
237
|
+
ref,
|
|
238
|
+
className: clsx$1("viz-heatmap-container", className),
|
|
239
|
+
style,
|
|
240
|
+
"data-slot": "heatmap",
|
|
241
|
+
"data-variant": variant,
|
|
242
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
243
|
+
ref: gridRef,
|
|
244
|
+
role: "grid",
|
|
245
|
+
"data-slot": "heatmap-grid",
|
|
246
|
+
"aria-label": ariaLabel,
|
|
247
|
+
className: clsx$1(Heatmap_module_default["viz-heatmap"], rowAxisPosition === "right" && Heatmap_module_default["viz-heatmap-row-axis-right"]),
|
|
248
|
+
style: { "--viz-heatmap-column-count": columns.length },
|
|
249
|
+
onKeyDown: onGridKeyDown,
|
|
250
|
+
children: [
|
|
251
|
+
columnAxisPosition === "top" && /* @__PURE__ */ jsx(AxisLabelRow, {
|
|
252
|
+
entries: columns,
|
|
253
|
+
rowAxisPosition
|
|
254
|
+
}),
|
|
255
|
+
rowCtx.map((row_8) => /* @__PURE__ */ jsxs("div", {
|
|
256
|
+
role: "row",
|
|
257
|
+
className: Heatmap_module_default["viz-heatmap-row"],
|
|
258
|
+
children: [
|
|
259
|
+
rowAxisPosition === "left" && /* @__PURE__ */ jsx(RowHeader, { label: row_8.label }),
|
|
260
|
+
colCtx.map((col_7) => /* @__PURE__ */ jsx(HeatmapCell, {
|
|
261
|
+
row: row_8.index,
|
|
262
|
+
col: col_7.index,
|
|
263
|
+
ariaLabel: cellAriaLabel(row_8, col_7),
|
|
264
|
+
describedBy: focusCardCell?.row === row_8.index && focusCardCell.col === col_7.index ? factsId : void 0,
|
|
265
|
+
tabbable: row_8.index === tabRow && col_7.index === tabCol,
|
|
266
|
+
layers: cellLayers(row_8, col_7),
|
|
267
|
+
hasPopover: renderPopover !== void 0,
|
|
268
|
+
onPointerIn: handlePointerIn,
|
|
269
|
+
onPointerOut: handlePointerOut,
|
|
270
|
+
onFocusIn: handleFocusIn,
|
|
271
|
+
onFocusOut: card.focusOut,
|
|
272
|
+
onActivate: activatable ? (row_9, col_8) => activate(row_9, col_8, "pointer") : void 0,
|
|
273
|
+
selected: row_8.index === selectedRow && col_7.index === selectedCol
|
|
274
|
+
}, col_7.index)),
|
|
275
|
+
rowAxisPosition === "right" && /* @__PURE__ */ jsx(RowHeader, { label: row_8.label })
|
|
276
|
+
]
|
|
277
|
+
}, row_8.index)),
|
|
278
|
+
columnAxisPosition === "bottom" && /* @__PURE__ */ jsx(AxisLabelRow, {
|
|
279
|
+
entries: columns,
|
|
280
|
+
rowAxisPosition
|
|
281
|
+
})
|
|
282
|
+
]
|
|
283
|
+
}), /* @__PURE__ */ jsx(Popover, {
|
|
284
|
+
...card.popoverProps,
|
|
285
|
+
anchor: card.anchor,
|
|
286
|
+
side: "bottom",
|
|
287
|
+
sideOffset: 6,
|
|
288
|
+
id: popupId,
|
|
289
|
+
"aria-label": "Cell details",
|
|
290
|
+
onKeyDown: (event_0) => {
|
|
291
|
+
if (event_0.key !== "Tab") return;
|
|
292
|
+
event_0.preventDefault();
|
|
293
|
+
card.close();
|
|
294
|
+
focusRovingCell(gridRef.current);
|
|
295
|
+
},
|
|
296
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
297
|
+
id: factsId,
|
|
298
|
+
children: card.content
|
|
299
|
+
})
|
|
300
|
+
})]
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
function RowHeader(t0) {
|
|
304
|
+
const $ = c(3);
|
|
305
|
+
const { label } = t0;
|
|
306
|
+
let t1;
|
|
307
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
308
|
+
t1 = clsx$1(Heatmap_module_default["viz-heatmap-axis"], Heatmap_module_default["viz-heatmap-axis-y"]);
|
|
309
|
+
$[0] = t1;
|
|
310
|
+
} else t1 = $[0];
|
|
311
|
+
let t2;
|
|
312
|
+
if ($[1] !== label) {
|
|
313
|
+
t2 = /* @__PURE__ */ jsx("div", {
|
|
314
|
+
role: "rowheader",
|
|
315
|
+
"data-slot": "heatmap-row-header",
|
|
316
|
+
className: t1,
|
|
317
|
+
children: label
|
|
318
|
+
});
|
|
319
|
+
$[1] = label;
|
|
320
|
+
$[2] = t2;
|
|
321
|
+
} else t2 = $[2];
|
|
322
|
+
return t2;
|
|
323
|
+
}
|
|
324
|
+
function AxisLabelRow(t0) {
|
|
325
|
+
const $ = c(7);
|
|
326
|
+
const { entries, rowAxisPosition } = t0;
|
|
327
|
+
let t1;
|
|
328
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
329
|
+
t1 = /* @__PURE__ */ jsx("div", {
|
|
330
|
+
"aria-hidden": "true",
|
|
331
|
+
className: clsx$1(Heatmap_module_default["viz-heatmap-axis"], Heatmap_module_default["viz-heatmap-axis-x"], Heatmap_module_default["viz-heatmap-axis-y"])
|
|
332
|
+
});
|
|
333
|
+
$[0] = t1;
|
|
334
|
+
} else t1 = $[0];
|
|
335
|
+
const corner = t1;
|
|
336
|
+
const t2 = rowAxisPosition === "left" && corner;
|
|
337
|
+
let t3;
|
|
338
|
+
if ($[1] !== entries) {
|
|
339
|
+
t3 = entries.map(_temp);
|
|
340
|
+
$[1] = entries;
|
|
341
|
+
$[2] = t3;
|
|
342
|
+
} else t3 = $[2];
|
|
343
|
+
const t4 = rowAxisPosition === "right" && corner;
|
|
344
|
+
let t5;
|
|
345
|
+
if ($[3] !== t2 || $[4] !== t3 || $[5] !== t4) {
|
|
346
|
+
t5 = /* @__PURE__ */ jsxs("div", {
|
|
347
|
+
role: "row",
|
|
348
|
+
className: Heatmap_module_default["viz-heatmap-row"],
|
|
349
|
+
children: [
|
|
350
|
+
t2,
|
|
351
|
+
t3,
|
|
352
|
+
t4
|
|
353
|
+
]
|
|
354
|
+
});
|
|
355
|
+
$[3] = t2;
|
|
356
|
+
$[4] = t3;
|
|
357
|
+
$[5] = t4;
|
|
358
|
+
$[6] = t5;
|
|
359
|
+
} else t5 = $[6];
|
|
360
|
+
return t5;
|
|
361
|
+
}
|
|
362
|
+
function _temp(entry, index) {
|
|
363
|
+
return /* @__PURE__ */ jsx("div", {
|
|
364
|
+
role: "columnheader",
|
|
365
|
+
"data-slot": "heatmap-column-header",
|
|
366
|
+
className: clsx$1(Heatmap_module_default["viz-heatmap-axis"], Heatmap_module_default["viz-heatmap-axis-x"]),
|
|
367
|
+
children: entry.label
|
|
368
|
+
}, index);
|
|
369
|
+
}
|
|
370
|
+
export { Heatmap as default };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import './Heatmap.css';
|
|
2
|
+
// src/heatmap/Heatmap.module.css
|
|
3
|
+
var Heatmap_module_default = {
|
|
4
|
+
"activatable": "tvyF8a_activatable",
|
|
5
|
+
"viz-heatmap": "tvyF8a_viz-heatmap",
|
|
6
|
+
"viz-heatmap-axis": "tvyF8a_viz-heatmap-axis",
|
|
7
|
+
"viz-heatmap-axis-x": "tvyF8a_viz-heatmap-axis-x",
|
|
8
|
+
"viz-heatmap-axis-y": "tvyF8a_viz-heatmap-axis-y",
|
|
9
|
+
"viz-heatmap-cell": "tvyF8a_viz-heatmap-cell",
|
|
10
|
+
"viz-heatmap-cell-container": "tvyF8a_viz-heatmap-cell-container",
|
|
11
|
+
"viz-heatmap-cell-empty": "tvyF8a_viz-heatmap-cell-empty",
|
|
12
|
+
"viz-heatmap-cell-value": "tvyF8a_viz-heatmap-cell-value",
|
|
13
|
+
"viz-heatmap-empty": "tvyF8a_viz-heatmap-empty",
|
|
14
|
+
"viz-heatmap-row": "tvyF8a_viz-heatmap-row",
|
|
15
|
+
"viz-heatmap-row-axis-right": "tvyF8a_viz-heatmap-row-axis-right"
|
|
16
|
+
};
|
|
17
|
+
export { Heatmap_module_default as default };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** One layer of a cell, fully resolved by Heatmap: formatted text (null = no data), normalised
|
|
2
|
+
* gradient position t ∈ [0, 1], and the layer's token colours. */
|
|
3
|
+
export interface ResolvedCellLayer {
|
|
4
|
+
id: string;
|
|
5
|
+
text: string | null;
|
|
6
|
+
t: number;
|
|
7
|
+
color?: string | [string, string];
|
|
8
|
+
}
|
|
9
|
+
interface HeatmapCellProps {
|
|
10
|
+
row: number;
|
|
11
|
+
col: number;
|
|
12
|
+
ariaLabel: string;
|
|
13
|
+
describedBy?: string;
|
|
14
|
+
tabbable: boolean;
|
|
15
|
+
layers: ResolvedCellLayer[];
|
|
16
|
+
hasPopover: boolean;
|
|
17
|
+
onPointerIn: (row: number, col: number, element: HTMLElement) => void;
|
|
18
|
+
onPointerOut: (row: number, col: number, element: HTMLElement) => void;
|
|
19
|
+
onFocusIn: (row: number, col: number, element: HTMLElement) => void;
|
|
20
|
+
onFocusOut: () => void;
|
|
21
|
+
onActivate?: (row: number, col: number) => void;
|
|
22
|
+
selected?: boolean;
|
|
23
|
+
}
|
|
24
|
+
declare function HeatmapCell({ row, col, ariaLabel, describedBy, tabbable, layers, hasPopover, onPointerIn, onPointerOut, onFocusIn, onFocusOut, onActivate, selected }: HeatmapCellProps): import("react").JSX.Element;
|
|
25
|
+
export { HeatmapCell as default };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import Heatmap_module_default from "./Heatmap.module.css.mjs";
|
|
3
|
+
import { c } from "react/compiler-runtime";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import clsx$1 from "clsx";
|
|
6
|
+
// src/heatmap/HeatmapCell.tsx
|
|
7
|
+
function HeatmapCell(t0) {
|
|
8
|
+
const $ = c(38);
|
|
9
|
+
const { row, col, ariaLabel, describedBy, tabbable, layers, hasPopover, onPointerIn, onPointerOut, onFocusIn, onFocusOut, onActivate, selected } = t0;
|
|
10
|
+
const t1 = onActivate ? Boolean(selected) : void 0;
|
|
11
|
+
const t2 = selected || void 0;
|
|
12
|
+
const t3 = tabbable ? 0 : -1;
|
|
13
|
+
const t4 = hasPopover ? "" : void 0;
|
|
14
|
+
const t5 = onActivate && Heatmap_module_default.activatable;
|
|
15
|
+
let t6;
|
|
16
|
+
if ($[0] !== t5) {
|
|
17
|
+
t6 = clsx$1(Heatmap_module_default["viz-heatmap-cell-container"], t5);
|
|
18
|
+
$[0] = t5;
|
|
19
|
+
$[1] = t6;
|
|
20
|
+
} else t6 = $[1];
|
|
21
|
+
let t7;
|
|
22
|
+
if ($[2] !== col || $[3] !== hasPopover || $[4] !== onPointerIn || $[5] !== row) {
|
|
23
|
+
t7 = hasPopover ? (e) => onPointerIn(row, col, e.currentTarget) : void 0;
|
|
24
|
+
$[2] = col;
|
|
25
|
+
$[3] = hasPopover;
|
|
26
|
+
$[4] = onPointerIn;
|
|
27
|
+
$[5] = row;
|
|
28
|
+
$[6] = t7;
|
|
29
|
+
} else t7 = $[6];
|
|
30
|
+
let t8;
|
|
31
|
+
if ($[7] !== col || $[8] !== hasPopover || $[9] !== onPointerOut || $[10] !== row) {
|
|
32
|
+
t8 = hasPopover ? (e_0) => onPointerOut(row, col, e_0.currentTarget) : void 0;
|
|
33
|
+
$[7] = col;
|
|
34
|
+
$[8] = hasPopover;
|
|
35
|
+
$[9] = onPointerOut;
|
|
36
|
+
$[10] = row;
|
|
37
|
+
$[11] = t8;
|
|
38
|
+
} else t8 = $[11];
|
|
39
|
+
let t9;
|
|
40
|
+
if ($[12] !== col || $[13] !== onFocusIn || $[14] !== row) {
|
|
41
|
+
t9 = (e_1) => onFocusIn(row, col, e_1.currentTarget);
|
|
42
|
+
$[12] = col;
|
|
43
|
+
$[13] = onFocusIn;
|
|
44
|
+
$[14] = row;
|
|
45
|
+
$[15] = t9;
|
|
46
|
+
} else t9 = $[15];
|
|
47
|
+
let t10;
|
|
48
|
+
if ($[16] !== col || $[17] !== onActivate || $[18] !== row) {
|
|
49
|
+
t10 = onActivate ? () => onActivate(row, col) : void 0;
|
|
50
|
+
$[16] = col;
|
|
51
|
+
$[17] = onActivate;
|
|
52
|
+
$[18] = row;
|
|
53
|
+
$[19] = t10;
|
|
54
|
+
} else t10 = $[19];
|
|
55
|
+
let t11;
|
|
56
|
+
if ($[20] !== layers) {
|
|
57
|
+
t11 = layers.map(_temp);
|
|
58
|
+
$[20] = layers;
|
|
59
|
+
$[21] = t11;
|
|
60
|
+
} else t11 = $[21];
|
|
61
|
+
let t12;
|
|
62
|
+
if ($[22] !== ariaLabel || $[23] !== col || $[24] !== describedBy || $[25] !== onFocusOut || $[26] !== row || $[27] !== t1 || $[28] !== t10 || $[29] !== t11 || $[30] !== t2 || $[31] !== t3 || $[32] !== t4 || $[33] !== t6 || $[34] !== t7 || $[35] !== t8 || $[36] !== t9) {
|
|
63
|
+
t12 = /* @__PURE__ */ jsx("div", {
|
|
64
|
+
role: "gridcell",
|
|
65
|
+
"aria-label": ariaLabel,
|
|
66
|
+
"aria-describedby": describedBy,
|
|
67
|
+
"aria-selected": t1,
|
|
68
|
+
"data-selected": t2,
|
|
69
|
+
tabIndex: t3,
|
|
70
|
+
"data-row": row,
|
|
71
|
+
"data-col": col,
|
|
72
|
+
"data-has-popover": t4,
|
|
73
|
+
className: t6,
|
|
74
|
+
onPointerEnter: t7,
|
|
75
|
+
onPointerLeave: t8,
|
|
76
|
+
onFocus: t9,
|
|
77
|
+
onBlur: onFocusOut,
|
|
78
|
+
onClick: t10,
|
|
79
|
+
children: t11
|
|
80
|
+
});
|
|
81
|
+
$[22] = ariaLabel;
|
|
82
|
+
$[23] = col;
|
|
83
|
+
$[24] = describedBy;
|
|
84
|
+
$[25] = onFocusOut;
|
|
85
|
+
$[26] = row;
|
|
86
|
+
$[27] = t1;
|
|
87
|
+
$[28] = t10;
|
|
88
|
+
$[29] = t11;
|
|
89
|
+
$[30] = t2;
|
|
90
|
+
$[31] = t3;
|
|
91
|
+
$[32] = t4;
|
|
92
|
+
$[33] = t6;
|
|
93
|
+
$[34] = t7;
|
|
94
|
+
$[35] = t8;
|
|
95
|
+
$[36] = t9;
|
|
96
|
+
$[37] = t12;
|
|
97
|
+
} else t12 = $[37];
|
|
98
|
+
return t12;
|
|
99
|
+
}
|
|
100
|
+
function _temp(layer) {
|
|
101
|
+
const cssVariables = { "--viz-heatmap-cell-value": Math.round(layer.t * 100) };
|
|
102
|
+
if (typeof layer.color === "string") {
|
|
103
|
+
cssVariables["--viz-heatmap-cell-gradient-end"] = layer.color;
|
|
104
|
+
cssVariables["--viz-heatmap-cell-gradient-start"] = "color-mix(in srgb, var(--viz-heatmap-cell-gradient-end) 15%, var(--tf-color-background))";
|
|
105
|
+
} else if (layer.color) {
|
|
106
|
+
cssVariables["--viz-heatmap-cell-gradient-start"] = layer.color[0];
|
|
107
|
+
cssVariables["--viz-heatmap-cell-gradient-end"] = layer.color[1];
|
|
108
|
+
} else {
|
|
109
|
+
cssVariables["--viz-heatmap-cell-gradient-start"] = "var(--viz-heatmap-from)";
|
|
110
|
+
cssVariables["--viz-heatmap-cell-gradient-end"] = "var(--viz-heatmap-to)";
|
|
111
|
+
}
|
|
112
|
+
return /* @__PURE__ */ jsx("div", {
|
|
113
|
+
"data-slot": "heatmap-cell",
|
|
114
|
+
"data-empty": layer.text === null || void 0,
|
|
115
|
+
className: clsx$1(Heatmap_module_default["viz-heatmap-cell"], layer.text === null && Heatmap_module_default["viz-heatmap-cell-empty"]),
|
|
116
|
+
style: cssVariables,
|
|
117
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
118
|
+
className: Heatmap_module_default["viz-heatmap-cell-value"],
|
|
119
|
+
"data-slot": "heatmap-cell-value",
|
|
120
|
+
children: layer.text ?? "—"
|
|
121
|
+
})
|
|
122
|
+
}, layer.id);
|
|
123
|
+
}
|
|
124
|
+
export { HeatmapCell as default };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { HeatmapScale } from "./heatmap-types.mjs";
|
|
2
|
+
/** No-data check: treats null, undefined, and non-finite numbers (NaN, ±Infinity) as missing.
|
|
3
|
+
* Callers warn once via `warnOnce` instead of letting the value poison the gradient. */
|
|
4
|
+
export declare function isNoData(v: number | null | undefined): v is null | undefined;
|
|
5
|
+
/** Gradient domain for a layer. `"max"` floors at 0 so negative values degrade to [0, 0]
|
|
6
|
+
* instead of inverting; an explicit inverted tuple is sorted ascending. */
|
|
7
|
+
export declare function resolveDomain(scale: HeatmapScale | undefined, layerMax: number): [number, number];
|
|
8
|
+
/** Position of `v` inside the domain as 0–1, clamped; a degenerate
|
|
9
|
+
* `min === max` domain yields 0 (no divide-by-zero). */
|
|
10
|
+
export declare function normalizeValue(v: number, [min, max]: [number, number]): number;
|
|
11
|
+
export declare function defaultFormat(scale: HeatmapScale | undefined): (v: number) => string;
|
|
12
|
+
/** Ids that appear more than once (each reported once) — feeds the
|
|
13
|
+
* duplicate-id dev warning. */
|
|
14
|
+
export declare function findDuplicateIds(entries: {
|
|
15
|
+
id: string;
|
|
16
|
+
}[]): string[];
|
|
17
|
+
/** Dev-only, deduped consumer-mistake warning (duplicate ids, non-finite values); never throws.
|
|
18
|
+
* The dedup set is caller-owned per Heatmap instance so instances can't share a once-slot. */
|
|
19
|
+
export declare function warnOnce(warned: Set<string>, key: string, message: string): void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { isDevBuild } from "../env.mjs";
|
|
2
|
+
// src/heatmap/heatmap-scale.ts
|
|
3
|
+
/** No-data check: treats null, undefined, and non-finite numbers (NaN, ±Infinity) as missing.
|
|
4
|
+
* Callers warn once via `warnOnce` instead of letting the value poison the gradient. */
|
|
5
|
+
function isNoData(v) {
|
|
6
|
+
return v == null || !Number.isFinite(v);
|
|
7
|
+
}
|
|
8
|
+
/** Gradient domain for a layer. `"max"` floors at 0 so negative values degrade to [0, 0]
|
|
9
|
+
* instead of inverting; an explicit inverted tuple is sorted ascending. */
|
|
10
|
+
function resolveDomain(scale, layerMax) {
|
|
11
|
+
if (scale === "fraction") return [0, 1];
|
|
12
|
+
if (Array.isArray(scale)) return scale[0] <= scale[1] ? [scale[0], scale[1]] : [scale[1], scale[0]];
|
|
13
|
+
return [0, Math.max(layerMax, 0)];
|
|
14
|
+
}
|
|
15
|
+
/** Position of `v` inside the domain as 0–1, clamped; a degenerate
|
|
16
|
+
* `min === max` domain yields 0 (no divide-by-zero). */
|
|
17
|
+
function normalizeValue(v, [min, max]) {
|
|
18
|
+
if (min === max) return 0;
|
|
19
|
+
return Math.min(Math.max((v - min) / (max - min), 0), 1);
|
|
20
|
+
}
|
|
21
|
+
function defaultFormat(scale) {
|
|
22
|
+
if (scale === "fraction") return (v) => `${Math.round(v * 100)}%`;
|
|
23
|
+
return (v) => String(v);
|
|
24
|
+
}
|
|
25
|
+
/** Ids that appear more than once (each reported once) — feeds the
|
|
26
|
+
* duplicate-id dev warning. */
|
|
27
|
+
function findDuplicateIds(entries) {
|
|
28
|
+
const seen = /* @__PURE__ */ new Set();
|
|
29
|
+
const duplicates = /* @__PURE__ */ new Set();
|
|
30
|
+
for (const entry of entries) {
|
|
31
|
+
if (seen.has(entry.id)) duplicates.add(entry.id);
|
|
32
|
+
seen.add(entry.id);
|
|
33
|
+
}
|
|
34
|
+
return [...duplicates];
|
|
35
|
+
}
|
|
36
|
+
/** Dev-only, deduped consumer-mistake warning (duplicate ids, non-finite values); never throws.
|
|
37
|
+
* The dedup set is caller-owned per Heatmap instance so instances can't share a once-slot. */
|
|
38
|
+
function warnOnce(warned, key, message) {
|
|
39
|
+
if (!isDevBuild || warned.has(key)) return;
|
|
40
|
+
warned.add(key);
|
|
41
|
+
console.warn(`Heatmap: ${message}`);
|
|
42
|
+
}
|
|
43
|
+
export { defaultFormat, findDuplicateIds, isNoData, normalizeValue, resolveDomain, warnOnce };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ActivationDetails } from "../a11y/activation.mjs";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
/** One row or column of the grid — id-keyed, never positional. */
|
|
4
|
+
export interface HeatmapAxisEntry {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
}
|
|
8
|
+
/** An axis entry plus its index, as handed to value accessors and popovers. */
|
|
9
|
+
export type HeatmapCellContext = HeatmapAxisEntry & {
|
|
10
|
+
index: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* How a layer's values map onto the colour gradient: `"fraction"` pins the domain to [0, 1],
|
|
14
|
+
* `"max"` (default) normalises against the layer's own maximum, `[min, max]` sets an explicit domain.
|
|
15
|
+
*/
|
|
16
|
+
export type HeatmapScale = "fraction" | "max" | [number, number];
|
|
17
|
+
/** A layer of `Heatmap`: the value, label and colour of each cell for one measure. */
|
|
18
|
+
export interface HeatmapLayer {
|
|
19
|
+
id: string;
|
|
20
|
+
label: string;
|
|
21
|
+
value: (row: HeatmapCellContext, column: HeatmapCellContext) => number | null | undefined;
|
|
22
|
+
scale?: HeatmapScale;
|
|
23
|
+
formatValue?: (value: number) => string;
|
|
24
|
+
color?: string | [string, string];
|
|
25
|
+
}
|
|
26
|
+
/** The row and the column of one grid cell, as handed to `renderPopover`. */
|
|
27
|
+
export interface HeatmapCellTarget {
|
|
28
|
+
row: HeatmapCellContext;
|
|
29
|
+
column: HeatmapCellContext;
|
|
30
|
+
}
|
|
31
|
+
/** How a cell shows its value: on a `chip` behind the number, or `flat` on the cell's own colour. */
|
|
32
|
+
export type HeatmapVariant = "chip" | "flat";
|
|
33
|
+
/** The props of `Heatmap`: its layers, axes and cell card. */
|
|
34
|
+
export interface HeatmapProps extends Pick<React.ComponentProps<"div">, "className" | "style" | "ref"> {
|
|
35
|
+
rows: HeatmapAxisEntry[];
|
|
36
|
+
columns: HeatmapAxisEntry[];
|
|
37
|
+
layers: HeatmapLayer[];
|
|
38
|
+
renderPopover?: (cell: HeatmapCellTarget) => ReactNode;
|
|
39
|
+
onCellActivate?: (cell: HeatmapCellTarget, details: ActivationDetails) => void;
|
|
40
|
+
selectedCell?: {
|
|
41
|
+
row: string;
|
|
42
|
+
column: string;
|
|
43
|
+
} | null;
|
|
44
|
+
rowAxisPosition?: "left" | "right";
|
|
45
|
+
columnAxisPosition?: "top" | "bottom";
|
|
46
|
+
"aria-label": string;
|
|
47
|
+
/** @defaultValue "chip" */
|
|
48
|
+
variant?: HeatmapVariant;
|
|
49
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Controlled/uncontrolled state — the library convention behind `value`/`defaultValue`/`onValueChange`. When
|
|
3
|
+
* `controlled` is defined the parent owns the value; otherwise it lives in React state and survives an `<Activity>` hide.
|
|
4
|
+
*/
|
|
5
|
+
export declare function useControllableState<T>({ controlled, default: defaultValue, onChange }: {
|
|
6
|
+
controlled: T | undefined;
|
|
7
|
+
default: T;
|
|
8
|
+
onChange?: (value: T) => void;
|
|
9
|
+
}): readonly [T, (next: T) => void];
|