@timefoldai/viz-react 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/LICENSE +202 -0
- package/README.md +240 -2
- 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 +61 -3
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import './BarChart.css';
|
|
2
|
+
// src/charts/BarChart.module.css
|
|
3
|
+
var BarChart_module_default = {
|
|
4
|
+
"bar": "e20vzq_bar",
|
|
5
|
+
"bar-chart": "e20vzq_bar-chart",
|
|
6
|
+
"max": "e20vzq_max",
|
|
7
|
+
"value": "e20vzq_value",
|
|
8
|
+
"viz-distribution-average": "e20vzq_viz-distribution-average"
|
|
9
|
+
};
|
|
10
|
+
export { BarChart_module_default as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** The props of `ChartGrid`, the props of a `div`. */
|
|
2
|
+
export type ChartGridProps = React.ComponentProps<"div">;
|
|
3
|
+
/**
|
|
4
|
+
* The grid a page's distribution charts sit in: as many columns of 13em–25em as fit.
|
|
5
|
+
*
|
|
6
|
+
* @category Charts
|
|
7
|
+
*/
|
|
8
|
+
export default function ChartGrid({ children, className, ...props }: ChartGridProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { c } from "react/compiler-runtime";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import clsx$1 from "clsx";
|
|
4
|
+
// src/charts/ChartGrid.tsx
|
|
5
|
+
/**
|
|
6
|
+
* The grid a page's distribution charts sit in: as many columns of 13em–25em as fit.
|
|
7
|
+
*
|
|
8
|
+
* @category Charts
|
|
9
|
+
*/
|
|
10
|
+
function ChartGrid(t0) {
|
|
11
|
+
const $ = c(10);
|
|
12
|
+
let children;
|
|
13
|
+
let className;
|
|
14
|
+
let props;
|
|
15
|
+
if ($[0] !== t0) {
|
|
16
|
+
({children, className, ...props} = t0);
|
|
17
|
+
$[0] = t0;
|
|
18
|
+
$[1] = children;
|
|
19
|
+
$[2] = className;
|
|
20
|
+
$[3] = props;
|
|
21
|
+
} else {
|
|
22
|
+
children = $[1];
|
|
23
|
+
className = $[2];
|
|
24
|
+
props = $[3];
|
|
25
|
+
}
|
|
26
|
+
let t1;
|
|
27
|
+
if ($[4] !== className) {
|
|
28
|
+
t1 = clsx$1("@container mb-[3em] grid grid-cols-[repeat(auto-fit,minmax(min(100%,13em),1fr))] gap-x-[5em] gap-y-[3em] *:max-w-[25em]", className);
|
|
29
|
+
$[4] = className;
|
|
30
|
+
$[5] = t1;
|
|
31
|
+
} else t1 = $[5];
|
|
32
|
+
let t2;
|
|
33
|
+
if ($[6] !== children || $[7] !== props || $[8] !== t1) {
|
|
34
|
+
t2 = /* @__PURE__ */ jsx("div", {
|
|
35
|
+
"data-slot": "chart-grid",
|
|
36
|
+
className: t1,
|
|
37
|
+
...props,
|
|
38
|
+
children
|
|
39
|
+
});
|
|
40
|
+
$[6] = children;
|
|
41
|
+
$[7] = props;
|
|
42
|
+
$[8] = t1;
|
|
43
|
+
$[9] = t2;
|
|
44
|
+
} else t2 = $[9];
|
|
45
|
+
return t2;
|
|
46
|
+
}
|
|
47
|
+
export { ChartGrid as default };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* One bucket of a distribution chart: its value bounds, label, count and the indices of its values.
|
|
4
|
+
* An open end is `-Infinity` or `Infinity`, and the bucket of `"isolate-min"` has `min` equal to `max`.
|
|
5
|
+
*/
|
|
6
|
+
export interface DistributionChartBucket {
|
|
7
|
+
min: number;
|
|
8
|
+
max: number;
|
|
9
|
+
label: string;
|
|
10
|
+
count: number;
|
|
11
|
+
indices: number[];
|
|
12
|
+
}
|
|
13
|
+
/** The value extent that `DistributionChart` splits into buckets, from `min` to `max`. */
|
|
14
|
+
export interface DistributionChartDomain {
|
|
15
|
+
min: number;
|
|
16
|
+
max: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The extra buckets around `domain`: `"overflow"` adds an under- and an over-domain bucket, `"isolate-min"` gives
|
|
20
|
+
* `domain.min` a bucket of its own, `"both"` does both, and `"plain"` neither, so values outside the domain drop.
|
|
21
|
+
*/
|
|
22
|
+
export type DistributionChartBucketLayout = "plain" | "overflow" | "isolate-min" | "both";
|
|
23
|
+
/** What one bucket shows in place of the defaults, as `bucketOverride` returns it. */
|
|
24
|
+
export interface DistributionChartBucketOverride {
|
|
25
|
+
label?: string;
|
|
26
|
+
/** @see BarChartBar.color */
|
|
27
|
+
color?: string;
|
|
28
|
+
}
|
|
29
|
+
/** The props of `DistributionChart`: the values it buckets and its title. */
|
|
30
|
+
export interface DistributionChartProps extends Pick<React.ComponentProps<"div">, "className" | "style" | "ref"> {
|
|
31
|
+
data: (number | null)[];
|
|
32
|
+
title: string;
|
|
33
|
+
/** @remarks The equal buckets across `domain`; `bucketLayout` adds its extra buckets beside them. */
|
|
34
|
+
bucketCount: number;
|
|
35
|
+
/** @defaultValue `{ min: 0, max: 100 }` */
|
|
36
|
+
domain?: DistributionChartDomain;
|
|
37
|
+
/** @defaultValue `"overflow"` */
|
|
38
|
+
bucketLayout?: DistributionChartBucketLayout;
|
|
39
|
+
/** @defaultValue a percentage, `${value}%` */
|
|
40
|
+
formatValue?: (value: number) => string;
|
|
41
|
+
/** @see BarChartProps.showLabels */
|
|
42
|
+
showLabels?: boolean;
|
|
43
|
+
bucketOverride?: (bucket: DistributionChartBucket) => DistributionChartBucketOverride | undefined;
|
|
44
|
+
/** @see BarChartProps.minBarHeight */
|
|
45
|
+
minBarHeight?: number;
|
|
46
|
+
headline?: string;
|
|
47
|
+
description?: string;
|
|
48
|
+
overflowLabel?: string;
|
|
49
|
+
renderPopover?: (bucket: DistributionChartBucket) => ReactNode;
|
|
50
|
+
/** @defaultValue the bucket's label and count, as its entry in the chart's `aria-label` */
|
|
51
|
+
describeBucket?: (bucket: DistributionChartBucket) => string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A histogram of `data` bucketed into `bucketCount` buckets across `domain`, with the
|
|
55
|
+
* average called out above the bars.
|
|
56
|
+
*
|
|
57
|
+
* @see https://www.w3.org/WAI/ARIA/apg/patterns/tooltip/
|
|
58
|
+
* @category Charts
|
|
59
|
+
*/
|
|
60
|
+
export default function DistributionChart({ data, title, bucketCount, domain, bucketLayout, formatValue, showLabels, bucketOverride, minBarHeight, headline, description, overflowLabel, renderPopover, describeBucket, className, style, ref }: DistributionChartProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import BarChart from "./BarChart.mjs";
|
|
2
|
+
import BarChart_module_default from "./BarChart.module.css.mjs";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { HelpIcon } from "../vendor/components.mjs";
|
|
5
|
+
import clsx$1 from "clsx";
|
|
6
|
+
import { round } from "@timefoldai/viz-core";
|
|
7
|
+
// src/charts/DistributionChart.tsx
|
|
8
|
+
const DEFAULT_DOMAIN = {
|
|
9
|
+
min: 0,
|
|
10
|
+
max: 100
|
|
11
|
+
};
|
|
12
|
+
const formatPercentage = (value) => `${value}%`;
|
|
13
|
+
/**
|
|
14
|
+
* A histogram of `data` bucketed into `bucketCount` buckets across `domain`, with the
|
|
15
|
+
* average called out above the bars.
|
|
16
|
+
*
|
|
17
|
+
* @see https://www.w3.org/WAI/ARIA/apg/patterns/tooltip/
|
|
18
|
+
* @category Charts
|
|
19
|
+
*/
|
|
20
|
+
function DistributionChart({ data, title, bucketCount, domain = DEFAULT_DOMAIN, bucketLayout = "overflow", formatValue = formatPercentage, showLabels, bucketOverride, minBarHeight, headline, description, overflowLabel, renderPopover, describeBucket, className, style, ref }) {
|
|
21
|
+
const distribution = createDistributionData(data, {
|
|
22
|
+
bucketCount,
|
|
23
|
+
domain,
|
|
24
|
+
bucketLayout,
|
|
25
|
+
overflowLabel,
|
|
26
|
+
formatValue
|
|
27
|
+
});
|
|
28
|
+
const bars = distribution.buckets.map(({ id, ...computed }) => {
|
|
29
|
+
const override = bucketOverride?.(computed);
|
|
30
|
+
const bucket = {
|
|
31
|
+
...computed,
|
|
32
|
+
label: override?.label ?? computed.label
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
id,
|
|
36
|
+
value: bucket.count,
|
|
37
|
+
label: bucket.label,
|
|
38
|
+
color: override?.color,
|
|
39
|
+
description: describeBucket?.(bucket),
|
|
40
|
+
bucket
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
44
|
+
ref,
|
|
45
|
+
className: clsx$1("col", className),
|
|
46
|
+
style,
|
|
47
|
+
"data-slot": "distribution-chart",
|
|
48
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
49
|
+
className: "toolbar mb-4 items-baseline md:flex-nowrap",
|
|
50
|
+
"data-slot": "distribution-chart-toolbar",
|
|
51
|
+
children: [
|
|
52
|
+
/* @__PURE__ */ jsx("div", {
|
|
53
|
+
"data-slot": "distribution-chart-title",
|
|
54
|
+
className: "min-w-0 text-[1.125em] leading-[1.2] font-normal text-balance break-words hyphens-auto max-md:basis-full",
|
|
55
|
+
children: title
|
|
56
|
+
}),
|
|
57
|
+
description && /* @__PURE__ */ jsx(HelpIcon, {
|
|
58
|
+
text: description,
|
|
59
|
+
size: "sm"
|
|
60
|
+
}),
|
|
61
|
+
/* @__PURE__ */ jsx("div", {
|
|
62
|
+
className: `right mono shrink-0 whitespace-nowrap ${BarChart_module_default["viz-distribution-average"]}`,
|
|
63
|
+
"data-slot": "distribution-chart-headline",
|
|
64
|
+
children: headline ?? (distribution.average === null ? "—" : formatValue(distribution.average))
|
|
65
|
+
})
|
|
66
|
+
]
|
|
67
|
+
}), /* @__PURE__ */ jsx(BarChart, {
|
|
68
|
+
bars,
|
|
69
|
+
"aria-label": title,
|
|
70
|
+
renderPopover: renderPopover && ((bar) => renderPopover(bar.bucket)),
|
|
71
|
+
showLabels,
|
|
72
|
+
minBarHeight
|
|
73
|
+
})]
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function emptyBucket(id, { min, max }, label) {
|
|
77
|
+
return {
|
|
78
|
+
id,
|
|
79
|
+
min,
|
|
80
|
+
max,
|
|
81
|
+
label,
|
|
82
|
+
count: 0,
|
|
83
|
+
indices: []
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function createDistributionData(data, { bucketCount, domain, bucketLayout, overflowLabel, formatValue }) {
|
|
87
|
+
const includeOverflow = bucketLayout === "overflow" || bucketLayout === "both";
|
|
88
|
+
const isolateMin = bucketLayout === "isolate-min" || bucketLayout === "both";
|
|
89
|
+
const underDomainBuckets = includeOverflow && domain.min > 0 ? 1 : 0;
|
|
90
|
+
const isolatedMinBucket = underDomainBuckets;
|
|
91
|
+
const minOffset = isolateMin ? 1 : 0;
|
|
92
|
+
const firstEqualBucket = underDomainBuckets + minOffset;
|
|
93
|
+
const totalBuckets = bucketCount + minOffset + (includeOverflow ? domain.min > 0 ? 2 : 1 : 0);
|
|
94
|
+
const bucketSize = (domain.max - domain.min) / bucketCount;
|
|
95
|
+
const buckets = Array.from({ length: totalBuckets }, (_, index) => {
|
|
96
|
+
if (includeOverflow) {
|
|
97
|
+
if (domain.min > 0 && index === 0) return emptyBucket("under", {
|
|
98
|
+
min: -1e400,
|
|
99
|
+
max: domain.min
|
|
100
|
+
}, `< ${formatValue(domain.min)}`);
|
|
101
|
+
if (index === totalBuckets - 1) return emptyBucket("over", {
|
|
102
|
+
min: domain.max,
|
|
103
|
+
max: 1e400
|
|
104
|
+
}, overflowLabel ?? `> ${formatValue(domain.max)}`);
|
|
105
|
+
}
|
|
106
|
+
if (isolateMin && index === isolatedMinBucket) {
|
|
107
|
+
const min = round(domain.min, 2);
|
|
108
|
+
return emptyBucket("min", {
|
|
109
|
+
min,
|
|
110
|
+
max: min
|
|
111
|
+
}, formatValue(min));
|
|
112
|
+
}
|
|
113
|
+
const equalIndex = index - firstEqualBucket;
|
|
114
|
+
const lower = round(equalIndex * bucketSize + domain.min, 2);
|
|
115
|
+
const upper = round((equalIndex + 1) * bucketSize + domain.min, 2);
|
|
116
|
+
return emptyBucket(`${lower}-${upper}`, {
|
|
117
|
+
min: lower,
|
|
118
|
+
max: upper
|
|
119
|
+
}, `${formatValue(lower)} - ${formatValue(upper)}`);
|
|
120
|
+
});
|
|
121
|
+
let sumMetric = 0;
|
|
122
|
+
let countMetric = 0;
|
|
123
|
+
for (const [index, metricValue] of data.entries()) {
|
|
124
|
+
if (metricValue === null) continue;
|
|
125
|
+
sumMetric += metricValue;
|
|
126
|
+
countMetric++;
|
|
127
|
+
let bucketIndex;
|
|
128
|
+
if (!includeOverflow && metricValue < domain.min) bucketIndex = null;
|
|
129
|
+
else if (includeOverflow && domain.min > 0 && metricValue < domain.min) bucketIndex = 0;
|
|
130
|
+
else if (isolateMin && metricValue === domain.min) bucketIndex = isolatedMinBucket;
|
|
131
|
+
else {
|
|
132
|
+
let currentIncrement = domain.min + bucketSize;
|
|
133
|
+
let indexMetric = firstEqualBucket;
|
|
134
|
+
while (metricValue > currentIncrement && currentIncrement <= domain.max) {
|
|
135
|
+
currentIncrement += bucketSize;
|
|
136
|
+
indexMetric++;
|
|
137
|
+
}
|
|
138
|
+
bucketIndex = indexMetric < totalBuckets ? indexMetric : null;
|
|
139
|
+
}
|
|
140
|
+
const bucket = bucketIndex === null ? void 0 : buckets[bucketIndex];
|
|
141
|
+
if (bucket) {
|
|
142
|
+
bucket.count++;
|
|
143
|
+
bucket.indices.push(index);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
buckets,
|
|
148
|
+
average: countMetric === 0 ? null : round(sumMetric / countMetric, 2)
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
export { DistributionChart as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** The props of `CodeBlock`: the value it prints and the accessible name of the block. */
|
|
2
|
+
export interface CodeBlockProps extends Omit<React.ComponentProps<"pre">, "children" | "aria-label"> {
|
|
3
|
+
value: unknown;
|
|
4
|
+
"aria-label": string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Read-only, scrollable block of preformatted data — a record's raw input
|
|
8
|
+
* beside the analysis derived from it.
|
|
9
|
+
*
|
|
10
|
+
* @see https://www.w3.org/WAI/ARIA/apg/patterns/landmarks/examples/region.html
|
|
11
|
+
* @category Data display
|
|
12
|
+
*/
|
|
13
|
+
export default function CodeBlock({ value, "aria-label": ariaLabel, className, ...props }: CodeBlockProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { c } from "react/compiler-runtime";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import clsx$1 from "clsx";
|
|
4
|
+
// src/code/CodeBlock.tsx
|
|
5
|
+
function serialize(value) {
|
|
6
|
+
if (typeof value === "string") return value;
|
|
7
|
+
try {
|
|
8
|
+
const json = JSON.stringify(value, null, 2);
|
|
9
|
+
return json === void 0 ? "This value could not be displayed." : json;
|
|
10
|
+
} catch {
|
|
11
|
+
return "This value could not be displayed.";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Read-only, scrollable block of preformatted data — a record's raw input
|
|
16
|
+
* beside the analysis derived from it.
|
|
17
|
+
*
|
|
18
|
+
* @see https://www.w3.org/WAI/ARIA/apg/patterns/landmarks/examples/region.html
|
|
19
|
+
* @category Data display
|
|
20
|
+
*/
|
|
21
|
+
function CodeBlock(t0) {
|
|
22
|
+
const $ = c(14);
|
|
23
|
+
let ariaLabel;
|
|
24
|
+
let className;
|
|
25
|
+
let props;
|
|
26
|
+
let value;
|
|
27
|
+
if ($[0] !== t0) {
|
|
28
|
+
({value, "aria-label": ariaLabel, className, ...props} = t0);
|
|
29
|
+
$[0] = t0;
|
|
30
|
+
$[1] = ariaLabel;
|
|
31
|
+
$[2] = className;
|
|
32
|
+
$[3] = props;
|
|
33
|
+
$[4] = value;
|
|
34
|
+
} else {
|
|
35
|
+
ariaLabel = $[1];
|
|
36
|
+
className = $[2];
|
|
37
|
+
props = $[3];
|
|
38
|
+
value = $[4];
|
|
39
|
+
}
|
|
40
|
+
let t1;
|
|
41
|
+
if ($[5] !== className) {
|
|
42
|
+
t1 = clsx$1("bg-viz-tint text-foreground m-0 max-h-64 overflow-auto rounded-sm p-3 font-mono text-xs leading-normal whitespace-pre", className);
|
|
43
|
+
$[5] = className;
|
|
44
|
+
$[6] = t1;
|
|
45
|
+
} else t1 = $[6];
|
|
46
|
+
let t2;
|
|
47
|
+
if ($[7] !== value) {
|
|
48
|
+
t2 = serialize(value);
|
|
49
|
+
$[7] = value;
|
|
50
|
+
$[8] = t2;
|
|
51
|
+
} else t2 = $[8];
|
|
52
|
+
let t3;
|
|
53
|
+
if ($[9] !== ariaLabel || $[10] !== props || $[11] !== t1 || $[12] !== t2) {
|
|
54
|
+
t3 = /* @__PURE__ */ jsx("pre", {
|
|
55
|
+
className: t1,
|
|
56
|
+
"data-slot": "code-block",
|
|
57
|
+
role: "region",
|
|
58
|
+
"aria-label": ariaLabel,
|
|
59
|
+
tabIndex: 0,
|
|
60
|
+
...props,
|
|
61
|
+
children: t2
|
|
62
|
+
});
|
|
63
|
+
$[9] = ariaLabel;
|
|
64
|
+
$[10] = props;
|
|
65
|
+
$[11] = t1;
|
|
66
|
+
$[12] = t2;
|
|
67
|
+
$[13] = t3;
|
|
68
|
+
} else t3 = $[13];
|
|
69
|
+
return t3;
|
|
70
|
+
}
|
|
71
|
+
export { CodeBlock as default };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SegmentTint } from "../segment-bar/Segment.mjs";
|
|
2
|
+
/** One named share: a segment's `variant` and `state`, as on `Segment`, or a raw `color` for a datum's own colour. */
|
|
3
|
+
export type CompositionBarPart = {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
value: number;
|
|
7
|
+
} & ((SegmentTint & {
|
|
8
|
+
color?: never;
|
|
9
|
+
}) | {
|
|
10
|
+
color: string;
|
|
11
|
+
variant?: never;
|
|
12
|
+
state?: never;
|
|
13
|
+
});
|
|
14
|
+
/** The props of `CompositionBar`: the parts it draws and its accessible label. */
|
|
15
|
+
export interface CompositionBarProps extends Pick<React.ComponentProps<"div">, "className" | "style" | "ref"> {
|
|
16
|
+
parts: CompositionBarPart[];
|
|
17
|
+
"aria-label": string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A proportional bar over its own key, one segment per named share of one whole.
|
|
21
|
+
*
|
|
22
|
+
* @category Data display
|
|
23
|
+
*/
|
|
24
|
+
export default function CompositionBar({ parts, "aria-label": ariaLabel, className, style, ref }: CompositionBarProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { SegmentBox, segmentFill } from "../segment-bar/segment-box.mjs";
|
|
2
|
+
import SegmentBar from "../segment-bar/SegmentBar.mjs";
|
|
3
|
+
import { visibleParts } from "./composition-shares.mjs";
|
|
4
|
+
import { c } from "react/compiler-runtime";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import clsx$1 from "clsx";
|
|
7
|
+
// src/composition-bar/CompositionBar.tsx
|
|
8
|
+
function partFill(part) {
|
|
9
|
+
return part.color ?? segmentFill(part.variant, part.state);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A proportional bar over its own key, one segment per named share of one whole.
|
|
13
|
+
*
|
|
14
|
+
* @category Data display
|
|
15
|
+
*/
|
|
16
|
+
function CompositionBar(t0) {
|
|
17
|
+
const $ = c(26);
|
|
18
|
+
const { parts, "aria-label": ariaLabel, className, style, ref } = t0;
|
|
19
|
+
let t1;
|
|
20
|
+
let t2;
|
|
21
|
+
let t3;
|
|
22
|
+
let t4;
|
|
23
|
+
let t5;
|
|
24
|
+
let t6;
|
|
25
|
+
let t7;
|
|
26
|
+
let t8;
|
|
27
|
+
if ($[0] !== ariaLabel || $[1] !== className || $[2] !== parts || $[3] !== ref || $[4] !== style) {
|
|
28
|
+
const visible = visibleParts(parts);
|
|
29
|
+
t4 = ref;
|
|
30
|
+
if ($[13] !== className) {
|
|
31
|
+
t5 = clsx$1("flex min-w-0 flex-col gap-1.5", className);
|
|
32
|
+
$[13] = className;
|
|
33
|
+
$[14] = t5;
|
|
34
|
+
} else t5 = $[14];
|
|
35
|
+
t6 = style;
|
|
36
|
+
t7 = "composition-bar";
|
|
37
|
+
t8 = /* @__PURE__ */ jsx(SegmentBar, {
|
|
38
|
+
width: "100%",
|
|
39
|
+
"aria-label": ariaLabel,
|
|
40
|
+
children: visible.map(_temp)
|
|
41
|
+
});
|
|
42
|
+
t1 = "composition-bar-key";
|
|
43
|
+
t2 = "m-0 flex list-none flex-wrap items-center gap-x-4 gap-y-1 p-0 text-xs";
|
|
44
|
+
t3 = visible.map(_temp2);
|
|
45
|
+
$[0] = ariaLabel;
|
|
46
|
+
$[1] = className;
|
|
47
|
+
$[2] = parts;
|
|
48
|
+
$[3] = ref;
|
|
49
|
+
$[4] = style;
|
|
50
|
+
$[5] = t1;
|
|
51
|
+
$[6] = t2;
|
|
52
|
+
$[7] = t3;
|
|
53
|
+
$[8] = t4;
|
|
54
|
+
$[9] = t5;
|
|
55
|
+
$[10] = t6;
|
|
56
|
+
$[11] = t7;
|
|
57
|
+
$[12] = t8;
|
|
58
|
+
} else {
|
|
59
|
+
t1 = $[5];
|
|
60
|
+
t2 = $[6];
|
|
61
|
+
t3 = $[7];
|
|
62
|
+
t4 = $[8];
|
|
63
|
+
t5 = $[9];
|
|
64
|
+
t6 = $[10];
|
|
65
|
+
t7 = $[11];
|
|
66
|
+
t8 = $[12];
|
|
67
|
+
}
|
|
68
|
+
let t9;
|
|
69
|
+
if ($[15] !== t1 || $[16] !== t2 || $[17] !== t3) {
|
|
70
|
+
t9 = /* @__PURE__ */ jsx("ul", {
|
|
71
|
+
"data-slot": t1,
|
|
72
|
+
className: t2,
|
|
73
|
+
children: t3
|
|
74
|
+
});
|
|
75
|
+
$[15] = t1;
|
|
76
|
+
$[16] = t2;
|
|
77
|
+
$[17] = t3;
|
|
78
|
+
$[18] = t9;
|
|
79
|
+
} else t9 = $[18];
|
|
80
|
+
let t10;
|
|
81
|
+
if ($[19] !== t4 || $[20] !== t5 || $[21] !== t6 || $[22] !== t7 || $[23] !== t8 || $[24] !== t9) {
|
|
82
|
+
t10 = /* @__PURE__ */ jsxs("div", {
|
|
83
|
+
ref: t4,
|
|
84
|
+
className: t5,
|
|
85
|
+
style: t6,
|
|
86
|
+
"data-slot": t7,
|
|
87
|
+
children: [t8, t9]
|
|
88
|
+
});
|
|
89
|
+
$[19] = t4;
|
|
90
|
+
$[20] = t5;
|
|
91
|
+
$[21] = t6;
|
|
92
|
+
$[22] = t7;
|
|
93
|
+
$[23] = t8;
|
|
94
|
+
$[24] = t9;
|
|
95
|
+
$[25] = t10;
|
|
96
|
+
} else t10 = $[25];
|
|
97
|
+
return t10;
|
|
98
|
+
}
|
|
99
|
+
function _temp2(part_0) {
|
|
100
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
101
|
+
className: "flex items-center gap-1.5",
|
|
102
|
+
children: [
|
|
103
|
+
/* @__PURE__ */ jsx("span", {
|
|
104
|
+
"aria-hidden": "true",
|
|
105
|
+
"data-slot": "composition-bar-swatch",
|
|
106
|
+
className: "h-[0.3125rem] w-5 shrink-0 rounded-[var(--tf-radius-xs)] bg-(--viz-composition-bar-swatch-color)",
|
|
107
|
+
style: { "--viz-composition-bar-swatch-color": partFill(part_0) }
|
|
108
|
+
}),
|
|
109
|
+
part_0.label,
|
|
110
|
+
" ",
|
|
111
|
+
part_0.share,
|
|
112
|
+
"%"
|
|
113
|
+
]
|
|
114
|
+
}, part_0.id);
|
|
115
|
+
}
|
|
116
|
+
function _temp(part) {
|
|
117
|
+
return /* @__PURE__ */ jsx(SegmentBox, {
|
|
118
|
+
percentage: part.share,
|
|
119
|
+
variant: part.variant,
|
|
120
|
+
state: part.state,
|
|
121
|
+
color: part.color
|
|
122
|
+
}, part.id);
|
|
123
|
+
}
|
|
124
|
+
export { CompositionBar as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Whole percentages summing to exactly 100, by largest remainder. */
|
|
2
|
+
export declare function roundedShares(values: number[]): number[];
|
|
3
|
+
/** Parts whose rounded share is above 0, in the same order, with the share attached. */
|
|
4
|
+
export declare function visibleParts<T extends {
|
|
5
|
+
value: number;
|
|
6
|
+
}>(parts: T[]): (T & {
|
|
7
|
+
share: number;
|
|
8
|
+
})[];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/composition-bar/composition-shares.ts
|
|
2
|
+
/** Whole percentages summing to exactly 100, by largest remainder. */
|
|
3
|
+
function roundedShares(values) {
|
|
4
|
+
const total = values.reduce((sum, value) => sum + value, 0);
|
|
5
|
+
if (total === 0) return values.map(() => 0);
|
|
6
|
+
const entries = values.map((value, index) => {
|
|
7
|
+
const exact = value / total * 100;
|
|
8
|
+
const floor = Math.floor(exact);
|
|
9
|
+
return {
|
|
10
|
+
index,
|
|
11
|
+
floor,
|
|
12
|
+
remainder: exact - floor
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
const leftover = 100 - entries.reduce((sum, entry) => sum + entry.floor, 0);
|
|
16
|
+
const boosted = new Set([...entries].sort((a, b) => b.remainder - a.remainder).slice(0, leftover).map((entry) => entry.index));
|
|
17
|
+
return entries.map((entry) => boosted.has(entry.index) ? entry.floor + 1 : entry.floor);
|
|
18
|
+
}
|
|
19
|
+
/** Parts whose rounded share is above 0, in the same order, with the share attached. */
|
|
20
|
+
function visibleParts(parts) {
|
|
21
|
+
const shares = roundedShares(parts.map((part) => part.value));
|
|
22
|
+
return parts.flatMap((part, index) => {
|
|
23
|
+
const share = shares[index];
|
|
24
|
+
return share ? [{
|
|
25
|
+
...part,
|
|
26
|
+
share
|
|
27
|
+
}] : [];
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export { roundedShares, visibleParts };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
/** The props of `DataGateStatusProvider`: whether data is loading, the error to show and the content it gates. */
|
|
3
|
+
export interface DataGateStatusProviderProps {
|
|
4
|
+
busy: boolean;
|
|
5
|
+
error: ReactNode;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Provides both gate statuses at once, for the app root that knows them.
|
|
10
|
+
*
|
|
11
|
+
* @category Feedback
|
|
12
|
+
*/
|
|
13
|
+
export declare function DataGateStatusProvider({ busy, error, children }: DataGateStatusProviderProps): import("react").JSX.Element;
|
|
14
|
+
/**
|
|
15
|
+
* What a gate shows: `loading` the skeleton (or the failure), `empty` the empty label, `ready` its children.
|
|
16
|
+
* An ancestor `DataGateStatusProvider` that is `busy` shows an `empty` gate as `loading`.
|
|
17
|
+
*/
|
|
18
|
+
export type DataGatePhase = "loading" | "empty" | "ready";
|
|
19
|
+
/** The props of `DataGate`: its phase and the labels for an empty or failed result. `className` and `style` reach the
|
|
20
|
+
* skeleton, failure and empty roots; set the height with `--viz-data-gate-height` (`60vh` when unset), not a height class. */
|
|
21
|
+
export interface DataGateProps extends Pick<React.ComponentProps<"div">, "className" | "style"> {
|
|
22
|
+
phase: DataGatePhase;
|
|
23
|
+
/** @defaultValue the `error` of the nearest `DataGateStatusProvider` */
|
|
24
|
+
error?: ReactNode;
|
|
25
|
+
emptyLabel?: ReactNode;
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Loading/empty/error gate: a skeleton until the data arrives, an empty state when it is empty, else `children`.
|
|
30
|
+
* An `error` replaces the skeleton with a static failure state.
|
|
31
|
+
*
|
|
32
|
+
* @category Feedback
|
|
33
|
+
*/
|
|
34
|
+
export default function DataGate({ phase, error, emptyLabel, className, style, children }: DataGateProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { c } from "react/compiler-runtime";
|
|
3
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { createContext, use } from "react";
|
|
5
|
+
import { Skeleton } from "../vendor/components.mjs";
|
|
6
|
+
import clsx$1 from "clsx";
|
|
7
|
+
// src/data-gate/DataGate.tsx
|
|
8
|
+
const DataGateErrorContext = createContext(null);
|
|
9
|
+
const DataGateBusyContext = createContext(false);
|
|
10
|
+
/**
|
|
11
|
+
* Provides both gate statuses at once, for the app root that knows them.
|
|
12
|
+
*
|
|
13
|
+
* @category Feedback
|
|
14
|
+
*/
|
|
15
|
+
function DataGateStatusProvider(t0) {
|
|
16
|
+
const $ = c(6);
|
|
17
|
+
const { busy, error, children } = t0;
|
|
18
|
+
let t1;
|
|
19
|
+
if ($[0] !== children || $[1] !== error) {
|
|
20
|
+
t1 = /* @__PURE__ */ jsx(DataGateErrorContext, {
|
|
21
|
+
value: error,
|
|
22
|
+
children
|
|
23
|
+
});
|
|
24
|
+
$[0] = children;
|
|
25
|
+
$[1] = error;
|
|
26
|
+
$[2] = t1;
|
|
27
|
+
} else t1 = $[2];
|
|
28
|
+
let t2;
|
|
29
|
+
if ($[3] !== busy || $[4] !== t1) {
|
|
30
|
+
t2 = /* @__PURE__ */ jsx(DataGateBusyContext, {
|
|
31
|
+
value: busy,
|
|
32
|
+
children: t1
|
|
33
|
+
});
|
|
34
|
+
$[3] = busy;
|
|
35
|
+
$[4] = t1;
|
|
36
|
+
$[5] = t2;
|
|
37
|
+
} else t2 = $[5];
|
|
38
|
+
return t2;
|
|
39
|
+
}
|
|
40
|
+
const GATE_HEIGHT = "h-[var(--viz-data-gate-height,60vh)]";
|
|
41
|
+
/**
|
|
42
|
+
* Loading/empty/error gate: a skeleton until the data arrives, an empty state when it is empty, else `children`.
|
|
43
|
+
* An `error` replaces the skeleton with a static failure state.
|
|
44
|
+
*
|
|
45
|
+
* @category Feedback
|
|
46
|
+
*/
|
|
47
|
+
function DataGate({ phase, error, emptyLabel = "No data to display", className, style, children }) {
|
|
48
|
+
const inheritedError = use(DataGateErrorContext);
|
|
49
|
+
const inheritedBusy = use(DataGateBusyContext);
|
|
50
|
+
const effectiveError = error ?? inheritedError;
|
|
51
|
+
const shownPhase = phase === "empty" && inheritedBusy ? "loading" : phase;
|
|
52
|
+
if (shownPhase === "loading") {
|
|
53
|
+
if (effectiveError != null) return /* @__PURE__ */ jsx("div", {
|
|
54
|
+
className: clsx$1("text-viz-muted flex items-center justify-center px-4 text-center", GATE_HEIGHT, className),
|
|
55
|
+
"data-slot": "data-gate",
|
|
56
|
+
"data-state": "error",
|
|
57
|
+
style,
|
|
58
|
+
children: effectiveError
|
|
59
|
+
});
|
|
60
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
61
|
+
className: clsx$1("relative", GATE_HEIGHT, className),
|
|
62
|
+
"data-slot": "data-gate",
|
|
63
|
+
"data-state": "loading",
|
|
64
|
+
style,
|
|
65
|
+
children: [/* @__PURE__ */ jsx(Skeleton, { className: "size-full" }), /* @__PURE__ */ jsx("span", {
|
|
66
|
+
className: "text-viz-muted absolute inset-0 flex items-center justify-center px-4 text-center",
|
|
67
|
+
children: "Loading…"
|
|
68
|
+
})]
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (shownPhase === "empty") return /* @__PURE__ */ jsx("div", {
|
|
72
|
+
className: clsx$1("text-viz-muted py-4 text-center", className),
|
|
73
|
+
"data-slot": "data-gate",
|
|
74
|
+
"data-state": "empty",
|
|
75
|
+
style,
|
|
76
|
+
children: emptyLabel
|
|
77
|
+
});
|
|
78
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
79
|
+
}
|
|
80
|
+
export { DataGateStatusProvider, DataGate as default };
|