@bigpixelrocket/uiok 0.1.4 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +95 -1
- package/README.md +1 -1
- package/dist/activity/ActivityBar.d.ts +21 -8
- package/dist/activity/ActivityBar.js +15 -5
- package/dist/activity/activity.css +53 -6
- package/dist/button/Button.d.ts +10 -6
- package/dist/button/Button.js +6 -1
- package/dist/button/button.css +201 -33
- package/dist/charts/Line.logic.d.ts +6 -0
- package/dist/charts/Line.logic.js +9 -0
- package/dist/charts/LineChart.js +11 -4
- package/dist/charts/Pie.logic.d.ts +89 -1
- package/dist/charts/Pie.logic.js +272 -2
- package/dist/charts/PieChart.d.ts +2 -1
- package/dist/charts/PieChart.js +12 -5
- package/dist/charts/PieFill.d.ts +15 -0
- package/dist/charts/PieFill.js +33 -0
- package/dist/charts/ResultChart.d.ts +2 -2
- package/dist/charts/ResultChart.js +173 -47
- package/dist/charts/ResultChart.logic.d.ts +60 -4
- package/dist/charts/ResultChart.logic.js +105 -6
- package/dist/charts/Scatter.logic.d.ts +18 -4
- package/dist/charts/Scatter.logic.js +98 -22
- package/dist/charts/ScatterChart.js +19 -5
- package/dist/charts/charts.css +233 -116
- package/dist/charts/seriesColour.d.ts +2 -0
- package/dist/charts/seriesColour.js +1 -1
- package/dist/datetime/DateTimePicker.d.ts +12 -2
- package/dist/datetime/DateTimePicker.js +61 -16
- package/dist/datetime/DateTimePicker.logic.d.ts +29 -0
- package/dist/datetime/DateTimePicker.logic.js +25 -0
- package/dist/datetime/datetime.css +89 -49
- package/dist/dialog/ConfirmDialog.d.ts +69 -20
- package/dist/dialog/ConfirmDialog.js +39 -12
- package/dist/dialog/DialogLayer.d.ts +25 -0
- package/dist/dialog/DialogLayer.js +24 -0
- package/dist/dialog/DialogLegend.d.ts +2 -1
- package/dist/dialog/DialogLegend.js +10 -5
- package/dist/dialog/DialogLegend.logic.d.ts +15 -3
- package/dist/dialog/DialogLegend.logic.js +8 -4
- package/dist/dialog/DialogLists.d.ts +157 -0
- package/dist/dialog/DialogLists.js +137 -0
- package/dist/dialog/ModalDialog.d.ts +20 -15
- package/dist/dialog/ModalDialog.js +22 -7
- package/dist/dialog/dialog.css +570 -127
- package/dist/dialog/index.d.ts +7 -1
- package/dist/dialog/index.js +7 -1
- package/dist/field/Check.d.ts +15 -0
- package/dist/field/Check.js +23 -0
- package/dist/field/field.css +812 -0
- package/dist/field/index.d.ts +10 -0
- package/dist/field/index.js +10 -0
- package/dist/field/labelHelp.d.ts +33 -0
- package/dist/field/labelHelp.js +22 -0
- package/dist/filter/FilterIcon.js +2 -1
- package/dist/filter/filter.css +72 -20
- package/dist/grid/DataGrid.d.ts +19 -2
- package/dist/grid/DataGrid.js +122 -41
- package/dist/grid/DataGrid.logic.d.ts +15 -3
- package/dist/grid/DataGrid.logic.js +18 -5
- package/dist/grid/grid.css +481 -56
- package/dist/icon/Spinner.d.ts +16 -0
- package/dist/icon/Spinner.js +13 -0
- package/dist/icon/index.d.ts +5 -0
- package/dist/icon/index.js +5 -0
- package/dist/icon/sizes.d.ts +19 -0
- package/dist/icon/sizes.js +19 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/keychord/KeyChord.d.ts +12 -1
- package/dist/keychord/KeyChord.js +2 -2
- package/dist/keychord/index.d.ts +1 -1
- package/dist/keychord/keychord.css +87 -9
- package/dist/labels/dialog.d.ts +12 -1
- package/dist/labels/dialog.js +3 -1
- package/dist/labels/selectAll.d.ts +4 -4
- package/dist/labels/selectAll.js +1 -1
- package/dist/legend/KeyLegendStrip.js +1 -1
- package/dist/legend/legend.css +82 -57
- package/dist/listing/Listing.d.ts +17 -10
- package/dist/listing/Listing.js +33 -26
- package/dist/listing/listing.css +1665 -237
- package/dist/menu/menu.css +227 -67
- package/dist/menu/useBellBeat.js +2 -2
- package/dist/namecut/NameCut.d.ts +3 -1
- package/dist/namecut/NameCut.js +152 -5
- package/dist/namecut/NameCut.logic.d.ts +5 -3
- package/dist/namecut/NameCut.logic.js +20 -5
- package/dist/namecut/namecut.css +27 -7
- package/dist/pager/Pager.d.ts +12 -4
- package/dist/pager/Pager.js +21 -7
- package/dist/pager/pager.css +41 -30
- package/dist/palette/Palette.js +2 -1
- package/dist/palette/palette.css +121 -60
- package/dist/pane/PaneActions.d.ts +56 -14
- package/dist/pane/PaneActions.js +64 -16
- package/dist/pane/PaneFrame.d.ts +37 -5
- package/dist/pane/PaneFrame.js +246 -11
- package/dist/pane/index.d.ts +4 -2
- package/dist/pane/index.js +4 -2
- package/dist/pane/toolWords.d.ts +14 -0
- package/dist/pane/toolWords.js +26 -0
- package/dist/pane/useToolbarFit.d.ts +25 -0
- package/dist/pane/useToolbarFit.js +95 -0
- package/dist/run/RunHeader.d.ts +5 -3
- package/dist/run/RunHeader.js +11 -8
- package/dist/run/run.css +64 -79
- package/dist/segmented/SegmentedChoice.d.ts +18 -2
- package/dist/segmented/SegmentedChoice.js +18 -7
- package/dist/segmented/segmented.css +62 -22
- package/dist/selectall/SelectAllBar.d.ts +4 -3
- package/dist/selectall/SelectAllBar.js +4 -3
- package/dist/selectall/selectall.css +17 -12
- package/dist/shell/shell.css +1073 -0
- package/dist/styles.css +620 -22
- package/dist/surface/surface.css +154 -0
- package/dist/tabs/PageTabs.d.ts +10 -5
- package/dist/tabs/PageTabs.js +126 -37
- package/dist/tabs/tabs.css +131 -51
- package/dist/terminal/Terminal.js +3 -1
- package/dist/terminal/Terminal.logic.d.ts +5 -4
- package/dist/terminal/Terminal.logic.js +9 -4
- package/dist/terminal/TerminalMenu.d.ts +4 -1
- package/dist/terminal/TerminalMenu.js +12 -5
- package/dist/terminal/ghostty/contrast.logic.d.ts +45 -0
- package/dist/terminal/ghostty/contrast.logic.js +130 -0
- package/dist/terminal/ghostty/core.d.ts +6 -0
- package/dist/terminal/ghostty/renderer.d.ts +9 -2
- package/dist/terminal/ghostty/renderer.js +91 -14
- package/dist/terminal/ghostty/surface.d.ts +8 -0
- package/dist/terminal/ghostty/surface.js +27 -1
- package/dist/terminal/terminal.css +87 -61
- package/dist/text/text.css +16 -7
- package/dist/themes/catalog.js +4 -3
- package/dist/themes/themes.generated.css +1307 -264
- package/dist/themes/tokens.d.ts +69 -14
- package/dist/themes/tokens.js +920 -97
- package/dist/tokens.css +239 -0
- package/dist/tooltip/Tooltip.d.ts +6 -0
- package/dist/tooltip/Tooltip.js +48 -6
- package/dist/tooltip/Tooltip.logic.d.ts +89 -12
- package/dist/tooltip/Tooltip.logic.js +142 -20
- package/dist/tooltip/index.d.ts +1 -1
- package/dist/tooltip/index.js +1 -1
- package/dist/tooltip/tooltip.css +39 -9
- package/package.json +3 -3
|
@@ -1,31 +1,50 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { memo, useState, useSyncExternalStore } from 'react';
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { memo, useId, useLayoutEffect, useRef, useState, useSyncExternalStore } from 'react';
|
|
3
3
|
import { useLabels } from '../labels/UiokProvider.js';
|
|
4
|
+
import { VisuallyHidden } from '../VisuallyHidden.js';
|
|
4
5
|
import { createValueStore } from '../store/ValueStore.js';
|
|
5
|
-
import { pieArcs } from './Pie.logic.js';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
6
|
+
import { DISTINCT_SLICE_FILLS, pieArcs, pieFills, pieTagRoom, pieTags, sliceFill } from './Pie.logic.js';
|
|
7
|
+
import { SliceHatches, slicePaint, sliceSwatch } from './PieFill.js';
|
|
8
|
+
import { STACKABLE_CHART_TYPES, cutLabel, fittedLegend, LEGEND_ROW, pieLegendRows, plotTopUnderLegend, pointRuns, shownLabels, spacedTicks, splinePath, stackedRanges, valueDomain } from './ResultChart.logic.js';
|
|
9
|
+
import { domainOf, scaled, tickLabels, ticksOf } from './Scatter.logic.js';
|
|
10
|
+
import { SERIES_COLOURS, seriesColour as colour } from './seriesColour.js';
|
|
9
11
|
/** A value as an axis and the read-out write it: six significant digits, no exponent for everyday sizes. */
|
|
10
12
|
const valueText = (value) => String(Number(value.toPrecision(6)));
|
|
13
|
+
/** The room between the drawing's edge and the plot on a side with no axis. */
|
|
14
|
+
const EDGE = 16;
|
|
15
|
+
/** The most rows a legend draws. */
|
|
16
|
+
const LEGEND_ROWS = 4;
|
|
17
|
+
/** The most characters a legend entry's name shows before it is cut (its whole name in a tooltip). */
|
|
18
|
+
const LEGEND_NAME_CAP = 40;
|
|
11
19
|
/**
|
|
12
|
-
* The value under the pointer
|
|
13
|
-
*
|
|
20
|
+
* The value under the pointer: a floating read-out beside the hovered mark,
|
|
21
|
+
* in the look every chart's read-out has (`.line-readout`), and the same
|
|
22
|
+
* words in a hidden live line for assistive technology. It follows the
|
|
23
|
+
* hover on its own, so the pointer moving from mark to mark draws this
|
|
14
24
|
* alone, never the chart's marks.
|
|
15
25
|
*/
|
|
16
|
-
function ResultChartReadout({ hover, type, categories, series }) {
|
|
26
|
+
function ResultChartReadout({ hover, type, categories, series, width, pieFillOf }) {
|
|
17
27
|
const labels = useLabels().charts;
|
|
18
28
|
const hovered = useSyncExternalStore(hover.subscribe, hover.get);
|
|
19
|
-
const
|
|
29
|
+
const valueAt = (seriesIndex, at) => {
|
|
20
30
|
const value = series[seriesIndex]?.values[at];
|
|
21
|
-
return
|
|
31
|
+
return value === null || value === undefined ? labels.noValue : valueText(value);
|
|
22
32
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
const said = hovered === null
|
|
34
|
+
? null
|
|
35
|
+
: type === 'pie'
|
|
36
|
+
? labels.seriesValue(categories[hovered.at] ?? '', valueAt(0, hovered.at))
|
|
37
|
+
: labels.seriesCategoryValue(series[hovered.series]?.name ?? '', categories[hovered.at] ?? '', valueAt(hovered.series, hovered.at));
|
|
38
|
+
return (_jsxs(_Fragment, { children: [hovered !== null && (_jsxs("div", { "aria-hidden": true, className: "line-readout result-chart-float", style: {
|
|
39
|
+
top: hovered.middle,
|
|
40
|
+
...(hovered.left > width / 2
|
|
41
|
+
? { right: width - hovered.left + 8 }
|
|
42
|
+
: { left: hovered.right + 8 })
|
|
43
|
+
}, children: [type !== 'pie' && _jsx("strong", { children: categories[hovered.at] ?? '' }), _jsxs("span", { children: [_jsx("span", { className: "chart-swatch", style: type === 'pie'
|
|
44
|
+
? sliceSwatch(pieFillOf.get(hovered.at) ?? sliceFill(hovered.at))
|
|
45
|
+
: { background: colour(hovered.series) } }), type === 'pie'
|
|
46
|
+
? labels.seriesValue(categories[hovered.at] ?? '', valueAt(0, hovered.at))
|
|
47
|
+
: labels.seriesValue(series[hovered.series]?.name ?? '', valueAt(hovered.series, hovered.at))] })] })), _jsx(VisuallyHidden, { "aria-live": "polite", className: "result-chart-readout", children: said ?? '' })] }));
|
|
29
48
|
}
|
|
30
49
|
/**
|
|
31
50
|
* A chart of a table of rows, in SVG from the chart tokens: bar
|
|
@@ -33,28 +52,71 @@ function ResultChartReadout({ hover, type, categories, series }) {
|
|
|
33
52
|
* (a monotone curve), and area (filled to zero, or stacked); pie of one
|
|
34
53
|
* series; timeline over a time axis; and scatter over a number axis. Title,
|
|
35
54
|
* legend, and axis labels are drawn inside the SVG, so its picture saves
|
|
36
|
-
* whole; hovering a value reads it out
|
|
55
|
+
* whole; hovering a value reads it out beside its mark. Each mark names
|
|
37
56
|
* its value in `data-series` and `data-at`, which one listener on the
|
|
38
57
|
* drawing reads, and the hover lives in a store the read-out follows, so
|
|
39
58
|
* the marks draw again only when the chart changes.
|
|
40
59
|
*/
|
|
41
60
|
function ResultChartDrawing({ type, stacked, title, xLabel, yLabel, categories, xValues, series, width, height, svgRef }) {
|
|
42
61
|
const labels = useLabels().charts;
|
|
62
|
+
// The masks that keep unstacked area fills from mixing are named from it.
|
|
63
|
+
const maskPrefix = `result-chart-${useId().replace(/[^\w-]/g, '')}`;
|
|
43
64
|
const [hover] = useState(() => createValueStore(null));
|
|
65
|
+
const figure = useRef(null);
|
|
66
|
+
const legend = useRef(null);
|
|
67
|
+
// Each legend name's drawn width, once measured; until then (and where the
|
|
68
|
+
// engine cannot measure) the layout estimates it from its length.
|
|
69
|
+
const [legendWidths, setLegendWidths] = useState([]);
|
|
44
70
|
const stack = stacked && STACKABLE_CHART_TYPES.has(type);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
const top = (title === '' ? 8 : 28) + Math.min(4, legendRows) * 16;
|
|
71
|
+
// The legend names at most as many entries as a pie has fills to tell
|
|
72
|
+
// apart; the rest are counted at its end.
|
|
73
|
+
const legendNames = (type === 'pie' ? categories : series.map((entry) => entry.name)).slice(0, DISTINCT_SLICE_FILLS);
|
|
49
74
|
const values = valueDomain(series, stack);
|
|
50
|
-
|
|
75
|
+
// A chart with no value to draw keeps its plot's place and says so there.
|
|
76
|
+
const empty = categories.length === 0 ||
|
|
77
|
+
!series.some((entry) => entry.values.some((value) => value !== null && Number.isFinite(value)));
|
|
78
|
+
const valueTicks = type === 'pie' || empty ? [] : ticksOf(values, 'number');
|
|
51
79
|
// The value axis's title sits clear of its widest tick (11px figures run about 6.5px each).
|
|
52
80
|
const tickWidth = valueTicks.reduce((widest, tick) => Math.max(widest, valueText(tick).length), 0);
|
|
81
|
+
// A pie has no axes, so its plot sits evenly between the drawing's edges.
|
|
82
|
+
const left = type === 'pie' ? EDGE : type === 'bar' ? 110 : Math.max(64, Math.ceil(tickWidth * 6.5) + 30);
|
|
83
|
+
// The legend starts at the plot's left edge and wraps inside its width.
|
|
84
|
+
// A pie whose colours repeat numbers its legend as it numbers its slices;
|
|
85
|
+
// a name that is its own number is written once.
|
|
86
|
+
// A name longer than the cap is cut before layout (the fitted legend
|
|
87
|
+
// wraps by measured width and counts what it leaves out, so the cap only
|
|
88
|
+
// stops one name taking a whole row), and its entry carries the whole name
|
|
89
|
+
// as its tooltip.
|
|
90
|
+
const legendTexts = legendNames.map((name, at) => type === 'pie' && categories.length > SERIES_COLOURS && name !== String(at + 1)
|
|
91
|
+
? `${at + 1} ${cutLabel(name, LEGEND_NAME_CAP)}`
|
|
92
|
+
: cutLabel(name, LEGEND_NAME_CAP));
|
|
93
|
+
const legendTop = title === '' ? 8 : 28;
|
|
94
|
+
// A pie's legend keeps to a third of the drawing, so a short one leaves
|
|
95
|
+
// the pie room for its tags.
|
|
96
|
+
const legendRowCap = type === 'pie' ? pieLegendRows(height, legendTop, LEGEND_ROWS) : LEGEND_ROWS;
|
|
97
|
+
// Entries the legend leaves out, by either cut, are counted after the
|
|
98
|
+
// last one listed ("+N", a figure in the dim tone with no swatch).
|
|
99
|
+
const { places: legendPlaces, more: legendMore } = fittedLegend(legendTexts, width - left - EDGE, legendRowCap, legendWidths, type === 'pie' ? categories.length : series.length);
|
|
100
|
+
const legendKey = legendTexts.join('\n');
|
|
101
|
+
// Measure the names as drawn, so the gap after each is even whatever its glyphs.
|
|
102
|
+
useLayoutEffect(() => {
|
|
103
|
+
const texts = [
|
|
104
|
+
...(legend.current?.querySelectorAll('text:not(.result-chart-legend-more)') ??
|
|
105
|
+
[])
|
|
106
|
+
];
|
|
107
|
+
const measured = texts.map((text) => typeof text.getComputedTextLength === 'function' ? Math.ceil(text.getComputedTextLength()) : 0);
|
|
108
|
+
if (measured.length === 0 || measured.some((value) => !(value > 0)))
|
|
109
|
+
return;
|
|
110
|
+
setLegendWidths((held) => held.length === measured.length && held.every((value, at) => value === measured[at])
|
|
111
|
+
? held
|
|
112
|
+
: measured);
|
|
113
|
+
}, [legendKey]);
|
|
114
|
+
const legendRows = [...legendPlaces, ...(legendMore === null ? [] : [legendMore])].reduce((rows, place) => Math.max(rows, place.row + 1), 0);
|
|
53
115
|
const margin = {
|
|
54
|
-
top,
|
|
55
|
-
right:
|
|
56
|
-
bottom: 44,
|
|
57
|
-
left
|
|
116
|
+
top: plotTopUnderLegend(legendTop, legendRows),
|
|
117
|
+
right: EDGE,
|
|
118
|
+
bottom: type === 'pie' ? EDGE : 44,
|
|
119
|
+
left
|
|
58
120
|
};
|
|
59
121
|
const plotWidth = Math.max(40, width - margin.left - margin.right);
|
|
60
122
|
const plotHeight = Math.max(40, height - margin.top - margin.bottom);
|
|
@@ -72,9 +134,21 @@ function ResultChartDrawing({ type, stacked, title, xLabel, yLabel, categories,
|
|
|
72
134
|
return band(type === 'bar') * (at + 0.5);
|
|
73
135
|
};
|
|
74
136
|
const plot = [];
|
|
75
|
-
|
|
137
|
+
/** A pie's fill for each category it draws, by category. */
|
|
138
|
+
const pieFillOf = new Map();
|
|
139
|
+
// Area fills go under the grid and the outlines (each series' runs, by
|
|
140
|
+
// series), with the masks that cut them.
|
|
141
|
+
const areaRuns = [];
|
|
142
|
+
const areaFills = [];
|
|
143
|
+
if (empty) {
|
|
144
|
+
plot.push(_jsx("text", { className: "chart-empty-text", dominantBaseline: "middle", textAnchor: "middle", x: plotWidth / 2, y: plotHeight / 2, children: labels.noValue }, "empty"));
|
|
145
|
+
}
|
|
146
|
+
else if (type === 'pie') {
|
|
76
147
|
const first = series[0];
|
|
77
|
-
|
|
148
|
+
// Past the eight series colours, colours repeat, so each slice carries
|
|
149
|
+
// its number on a leader outside the rim, as its legend entry does.
|
|
150
|
+
const numbered = categories.length > SERIES_COLOURS;
|
|
151
|
+
const r = Math.max(10, Math.min(plotWidth, plotHeight) / 2 - 4 - (numbered ? pieTagRoom : 0));
|
|
78
152
|
const slices = categories.map((label, at) => ({
|
|
79
153
|
label,
|
|
80
154
|
value: Math.max(0, first?.values[at] ?? 0)
|
|
@@ -83,10 +157,20 @@ function ResultChartDrawing({ type, stacked, title, xLabel, yLabel, categories,
|
|
|
83
157
|
// pieArcs leaves out slices of nothing, so each arc maps back to the
|
|
84
158
|
// category it came from; the legend and the read-out go by category.
|
|
85
159
|
const kept = slices.flatMap((slice, at) => (slice.value > 0 ? [at] : []));
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
160
|
+
// A tag points to a legend entry, so only the slices the legend lists
|
|
161
|
+
// carry one; the rest are in its "+N".
|
|
162
|
+
const tagged = kept.flatMap((category, at) => (category < legendPlaces.length ? [at] : []));
|
|
163
|
+
const tags = numbered
|
|
164
|
+
? pieTags(tagged.flatMap((at) => (arcs[at] === undefined ? [] : [arcs[at]])), r, tagged.map((at) => String((kept[at] ?? at) + 1)))
|
|
165
|
+
: [];
|
|
166
|
+
// Past the eight colours, slices are hatched, then crosshatched, so no
|
|
167
|
+
// two neighbours and no two legend swatches share a fill.
|
|
168
|
+
const fills = pieFills(kept);
|
|
169
|
+
fills.forEach((fill, at) => pieFillOf.set(kept[at] ?? at, fill));
|
|
170
|
+
plot.push(_jsxs("g", { transform: `translate(${plotWidth / 2} ${plotHeight / 2})`, children: [tags.map((tag) => tag === null ? null : (_jsxs("g", { className: "result-chart-slice-tag", children: [_jsx("line", { x1: tag.fromX, x2: tag.x, y1: tag.fromY, y2: tag.y }), _jsx("text", { dominantBaseline: "middle", textAnchor: tag.anchor, x: tag.textX, y: tag.textY, children: tag.text })] }, `tag-${tag.text}`))), arcs.map((arc, at) => {
|
|
171
|
+
const category = kept[at] ?? at;
|
|
172
|
+
return (_jsx("path", { className: "result-chart-mark", d: arc.path, fill: slicePaint(maskPrefix, fills[at] ?? sliceFill(category)), "data-at": category, "data-series": 0 }, category));
|
|
173
|
+
})] }, "pie"));
|
|
90
174
|
}
|
|
91
175
|
else if (type === 'column' || type === 'bar') {
|
|
92
176
|
const vertical = type === 'bar';
|
|
@@ -122,14 +206,16 @@ function ResultChartDrawing({ type, stacked, title, xLabel, yLabel, categories,
|
|
|
122
206
|
across(at),
|
|
123
207
|
along(stack ? (ranges[seriesIndex]?.[at]?.from ?? 0) : Math.max(values.min, 0))
|
|
124
208
|
]);
|
|
125
|
-
|
|
126
|
-
|
|
209
|
+
// One fill per run of values, the same runs its line draws, so a
|
|
210
|
+
// missing value breaks the fill where it breaks the outline.
|
|
211
|
+
pointRuns(points).forEach((run, runIndex) => {
|
|
127
212
|
const outline = [
|
|
128
|
-
...
|
|
129
|
-
...
|
|
213
|
+
...run.map(({ point }) => point),
|
|
214
|
+
...run.map(({ at }) => base[at] ?? [0, 0]).reverse()
|
|
130
215
|
];
|
|
131
|
-
|
|
132
|
-
|
|
216
|
+
(areaRuns[seriesIndex] ??= [])[runIndex] =
|
|
217
|
+
`${outline.map(([x, y], at) => `${at === 0 ? 'M' : 'L'}${x} ${y}`).join(' ')} Z`;
|
|
218
|
+
});
|
|
133
219
|
}
|
|
134
220
|
if (type !== 'scatter') {
|
|
135
221
|
plot.push(_jsx("path", { className: "result-chart-line", d: type === 'spline'
|
|
@@ -148,28 +234,68 @@ function ResultChartDrawing({ type, stacked, title, xLabel, yLabel, categories,
|
|
|
148
234
|
});
|
|
149
235
|
});
|
|
150
236
|
}
|
|
237
|
+
// Each area's tint shows only where no series drawn after it (in front)
|
|
238
|
+
// has its own fill, so two tints never add up to a hue the legend lacks:
|
|
239
|
+
// a mask keeps the plot and cuts every fill in front. Stacked bands do
|
|
240
|
+
// not overlap and take none, so their shared edges stay seamless.
|
|
241
|
+
areaRuns.forEach((runs, seriesIndex) => {
|
|
242
|
+
const front = stack ? [] : areaRuns.slice(seriesIndex + 1).flat();
|
|
243
|
+
const mask = `${maskPrefix}-area-${seriesIndex}`;
|
|
244
|
+
if (front.length > 0) {
|
|
245
|
+
areaFills.push(_jsxs("mask", { height: plotHeight + 2, id: mask, maskUnits: "userSpaceOnUse", width: plotWidth + 2, x: -1, y: -1, children: [_jsx("rect", { className: "result-chart-mask-keep", height: plotHeight + 2, width: plotWidth + 2, x: -1, y: -1 }), front.map((d, at) => (_jsx("path", { className: "result-chart-mask-cut", d: d }, at)))] }, mask));
|
|
246
|
+
}
|
|
247
|
+
runs.forEach((d, runIndex) => {
|
|
248
|
+
areaFills.push(_jsx("path", { className: "result-chart-area", d: d, fill: colour(seriesIndex), mask: front.length > 0 ? `url(#${mask})` : undefined }, `area-${seriesIndex}-${runIndex}`));
|
|
249
|
+
});
|
|
250
|
+
});
|
|
151
251
|
/** The mark the pointer came onto, read from its `data-` attributes; anything else keeps the last. */
|
|
152
252
|
const onPointerOver = (event) => {
|
|
153
253
|
const mark = event.target instanceof Element ? event.target : null;
|
|
154
254
|
const at = mark?.getAttribute('data-at');
|
|
155
255
|
const seriesIndex = mark?.getAttribute('data-series');
|
|
156
|
-
if (
|
|
256
|
+
if (mark === null ||
|
|
257
|
+
at === null ||
|
|
258
|
+
at === undefined ||
|
|
259
|
+
seriesIndex === null ||
|
|
260
|
+
seriesIndex === undefined) {
|
|
157
261
|
return;
|
|
158
262
|
}
|
|
159
263
|
const held = hover.get();
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
264
|
+
if (held !== null && held.series === Number(seriesIndex) && held.at === Number(at))
|
|
265
|
+
return;
|
|
266
|
+
const box = mark.getBoundingClientRect();
|
|
267
|
+
const frame = figure.current?.getBoundingClientRect();
|
|
268
|
+
const x = frame?.left ?? 0;
|
|
269
|
+
const y = frame?.top ?? 0;
|
|
270
|
+
hover.set({
|
|
271
|
+
series: Number(seriesIndex),
|
|
272
|
+
at: Number(at),
|
|
273
|
+
left: box.left - x,
|
|
274
|
+
right: box.right - x,
|
|
275
|
+
middle: (box.top + box.bottom) / 2 - y
|
|
276
|
+
});
|
|
163
277
|
};
|
|
278
|
+
const xAxis = { title: xLabel, kind: type === 'timeline' ? 'time' : 'number' };
|
|
279
|
+
const xTickValues = numericX
|
|
280
|
+
? ticksOf(xDomain, xAxis.kind, Math.max(2, Math.floor(plotWidth / 90)))
|
|
281
|
+
: [];
|
|
282
|
+
const xTickTexts = tickLabels(xTickValues, xAxis, xDomain);
|
|
283
|
+
const xTicks = spacedTicks(xTickValues.map((tick, at) => ({
|
|
284
|
+
at: scaled(tick, xDomain, 0, plotWidth),
|
|
285
|
+
text: xTickTexts[at] ?? ''
|
|
286
|
+
})), plotWidth);
|
|
164
287
|
const labelled = shownLabels(count, type === 'bar' ? plotHeight : plotWidth, type === 'bar' ? 18 : 72);
|
|
165
|
-
return (_jsxs("figure", { className: "result-chart", children: [_jsxs("svg", { "aria-label": title === '' ? labels.chart : title, height: height, onPointerLeave: () => hover.set(null), onPointerOver: onPointerOver, ref: svgRef, role: "img", viewBox: `0 0 ${width} ${height}`, width: width, children: [title !== '' && (_jsx("text", { className: "result-chart-title", textAnchor: "middle", x:
|
|
166
|
-
?
|
|
167
|
-
|
|
288
|
+
return (_jsxs("figure", { className: "result-chart", ref: figure, children: [_jsxs("svg", { "aria-label": title === '' ? labels.chart : title, height: height, onPointerLeave: () => hover.set(null), onPointerOver: onPointerOver, ref: svgRef, role: "img", viewBox: `0 0 ${width} ${height}`, width: width, children: [title !== '' && (_jsx("text", { className: "result-chart-title", textAnchor: "middle", x: margin.left + plotWidth / 2, y: 18, children: title })), type === 'pie' && (_jsx(SliceHatches, { fills: [...pieFillOf.values(), ...legendNames.map((_, at) => sliceFill(at))], prefix: maskPrefix })), _jsxs("g", { className: "result-chart-legend", ref: legend, transform: `translate(${margin.left} ${legendTop})`, children: [legendPlaces.map((place, at) => (_jsxs("g", { transform: `translate(${place.x} ${place.row * LEGEND_ROW})`, children: [_jsx("rect", { className: "result-chart-legend-swatch", fill: type === 'pie' ? slicePaint(maskPrefix, sliceFill(at)) : colour(at), height: 10, rx: 2, width: 10, y: 1 }), _jsx("text", { x: 14, y: 10, children: place.text }), cutLabel(legendNames[at] ?? '', LEGEND_NAME_CAP) ===
|
|
289
|
+
(legendNames[at] ?? '') ? null : (_jsx("title", { children: legendNames[at] }))] }, at))), legendMore !== null && (_jsx("text", { className: "result-chart-legend-more", transform: `translate(${legendMore.x} ${legendMore.row * LEGEND_ROW})`, y: 10, children: legendMore.text }))] }), _jsxs("g", { transform: `translate(${margin.left} ${margin.top})`, children: [areaFills, type !== 'pie' && (_jsxs("g", { className: "result-chart-axis", children: [valueTicks.map((tick) => type === 'bar' ? (_jsxs("g", { transform: `translate(${along(tick)} 0)`, children: [_jsx("line", { className: "result-chart-grid", y1: 0, y2: plotHeight }), _jsx("text", { textAnchor: "middle", y: plotHeight + 14, children: valueText(tick) })] }, tick)) : (_jsxs("g", { transform: `translate(0 ${along(tick)})`, children: [_jsx("line", { className: "result-chart-grid", x1: 0, x2: plotWidth }), _jsx("text", { dominantBaseline: "middle", textAnchor: "end", x: -6, children: valueText(tick) })] }, tick))), empty
|
|
290
|
+
? null
|
|
291
|
+
: numericX
|
|
292
|
+
? xTicks.map((tick) => (_jsx("text", { textAnchor: "start", x: tick.x, y: plotHeight + 14, children: tick.text }, tick.x)))
|
|
293
|
+
: categories.map((category, at) => labelled.has(at) ? (type === 'bar' ? (_jsx("text", { dominantBaseline: "middle", textAnchor: "end", x: -6, y: across(at), children: cutLabel(category, 16) }, at)) : (_jsx("text", { textAnchor: "middle", x: across(at), y: plotHeight + 14, children: cutLabel(category, 12) }, at))) : null), _jsx("path", { className: "result-chart-baseline", d: `M0 0V${plotHeight}H${plotWidth}` }), _jsx("text", { className: "result-chart-axis-title", textAnchor: "middle", x: plotWidth / 2, y: plotHeight + 34, children: type === 'bar' ? yLabel : xLabel }), _jsx("text", { className: "result-chart-axis-title", textAnchor: "middle", transform: `translate(${-margin.left + 12} ${plotHeight / 2}) rotate(-90)`, children: type === 'bar' ? xLabel : yLabel })] })), plot] })] }), _jsx(ResultChartReadout, { categories: categories, hover: hover, pieFillOf: pieFillOf, series: series, type: type, width: width })] }));
|
|
168
294
|
}
|
|
169
295
|
/**
|
|
170
296
|
* A chart of a table of rows in one of eight types (`ResultChartType`),
|
|
171
297
|
* drawn in SVG from the chart tokens with its title, legend, and axes inside,
|
|
172
|
-
* and a read-out
|
|
298
|
+
* and a read-out beside the mark under the pointer. It draws again only when a
|
|
173
299
|
* prop changes, so keep `categories`, `xValues`, and `series` stable.
|
|
174
300
|
*/
|
|
175
301
|
export const ResultChart = memo(ResultChartDrawing);
|
|
@@ -32,11 +32,67 @@ export declare function shownLabels(count: number, span: number, room?: number):
|
|
|
32
32
|
export declare const cutLabel: (text: string, limit?: number) => string;
|
|
33
33
|
/**
|
|
34
34
|
* Where each legend entry goes: one after another on a row, each as wide
|
|
35
|
-
* as its swatch, its text
|
|
36
|
-
*
|
|
35
|
+
* as its 10px swatch and 4px gap, its text (`widths`, the drawn width of
|
|
36
|
+
* each, where measured; about 6.5 pixels a character where not), and a
|
|
37
|
+
* 14px gap, wrapping to the next row where the next would pass `width`.
|
|
37
38
|
*/
|
|
38
|
-
export declare function legendLayout(texts: readonly string[], width: number):
|
|
39
|
+
export declare function legendLayout(texts: readonly string[], width: number, widths?: readonly number[]): LegendPlace[];
|
|
40
|
+
/** A legend entry's place: its text, its left edge, and its row from zero. */
|
|
41
|
+
export interface LegendPlace {
|
|
39
42
|
readonly text: string;
|
|
40
43
|
readonly x: number;
|
|
41
44
|
readonly row: number;
|
|
42
|
-
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A legend of `total` entries (`texts` names the first of them) held to
|
|
48
|
+
* `rows` rows: the entries it lists (a run from the first, placed as
|
|
49
|
+
* `legendLayout` places them) and, when some are left out, `more`, a count
|
|
50
|
+
* of them written `+N` after the last entry listed,
|
|
51
|
+
* with no swatch. The count's width is reserved: where it would not fit
|
|
52
|
+
* on the last row, entries step back until it does, so it never takes a
|
|
53
|
+
* row of its own past the limit.
|
|
54
|
+
*/
|
|
55
|
+
export declare function fittedLegend(texts: readonly string[], width: number, rows: number, widths?: readonly number[], total?: number): {
|
|
56
|
+
readonly places: LegendPlace[];
|
|
57
|
+
readonly more: LegendPlace | null;
|
|
58
|
+
};
|
|
59
|
+
/** The pitch of a legend's rows, in pixels. */
|
|
60
|
+
export declare const LEGEND_ROW = 16;
|
|
61
|
+
/**
|
|
62
|
+
* How many rows a pie's legend may take in a drawing `height` pixels tall
|
|
63
|
+
* whose legend starts at `legendTop`: at most `most`, and no more than keep
|
|
64
|
+
* the title, the legend, and the room under it within a third of the
|
|
65
|
+
* height, so a short drawing leaves its pie room for its tags. Always one.
|
|
66
|
+
*/
|
|
67
|
+
export declare function pieLegendRows(height: number, legendTop: number, most: number): number;
|
|
68
|
+
/**
|
|
69
|
+
* Where the plot starts under a legend whose first row is at `legendTop`
|
|
70
|
+
* and that draws `rows` rows: its last row's ink plus the same 12px gap
|
|
71
|
+
* whether the legend fits one row or wraps, so a wrapped legend never
|
|
72
|
+
* crowds the plot's top grid line and tick. With no rows, the legend's top.
|
|
73
|
+
*/
|
|
74
|
+
export declare function plotTopUnderLegend(legendTop: number, rows: number): number;
|
|
75
|
+
/** A tick's label as an axis draws it: its left edge, from the plot's start, and its text. */
|
|
76
|
+
export interface PlacedTick {
|
|
77
|
+
readonly x: number;
|
|
78
|
+
readonly text: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Which tick labels a horizontal axis of `span` pixels draws, and where:
|
|
82
|
+
* each centred on its tick at about `charWidth` pixels a character, moved
|
|
83
|
+
* inside the plot where it would pass an edge, and left out where it would
|
|
84
|
+
* come within `gap` pixels of the one before, so no two labels touch and
|
|
85
|
+
* none hangs past the plot.
|
|
86
|
+
*/
|
|
87
|
+
export declare function spacedTicks(ticks: readonly {
|
|
88
|
+
readonly at: number;
|
|
89
|
+
readonly text: string;
|
|
90
|
+
}[], span: number, charWidth?: number, gap?: number): PlacedTick[];
|
|
91
|
+
/**
|
|
92
|
+
* The runs of consecutive points a line or an area draws, each at least
|
|
93
|
+
* one point long; a missing point (null) ends a run.
|
|
94
|
+
*/
|
|
95
|
+
export declare function pointRuns<Point>(points: readonly (Point | null)[]): {
|
|
96
|
+
readonly at: number;
|
|
97
|
+
readonly point: Point;
|
|
98
|
+
}[][];
|
|
@@ -146,15 +146,16 @@ export const cutLabel = (text, limit = 18) => Array.from(text).length <= limit
|
|
|
146
146
|
.join('')}…`;
|
|
147
147
|
/**
|
|
148
148
|
* Where each legend entry goes: one after another on a row, each as wide
|
|
149
|
-
* as its swatch, its text
|
|
150
|
-
*
|
|
149
|
+
* as its 10px swatch and 4px gap, its text (`widths`, the drawn width of
|
|
150
|
+
* each, where measured; about 6.5 pixels a character where not), and a
|
|
151
|
+
* 14px gap, wrapping to the next row where the next would pass `width`.
|
|
151
152
|
*/
|
|
152
|
-
export function legendLayout(texts, width) {
|
|
153
|
+
export function legendLayout(texts, width, widths = []) {
|
|
153
154
|
let x = 0;
|
|
154
155
|
let row = 0;
|
|
155
|
-
return texts.map((text) => {
|
|
156
|
-
const span =
|
|
157
|
-
if (x > 0 && x + span > width) {
|
|
156
|
+
return texts.map((text, at) => {
|
|
157
|
+
const span = legendSpan(text, widths[at]);
|
|
158
|
+
if (x > 0 && x + span - 14 > width) {
|
|
158
159
|
x = 0;
|
|
159
160
|
row += 1;
|
|
160
161
|
}
|
|
@@ -163,3 +164,101 @@ export function legendLayout(texts, width) {
|
|
|
163
164
|
return place;
|
|
164
165
|
});
|
|
165
166
|
}
|
|
167
|
+
/** How far a legend entry reaches along its row: swatch and gap, text, and the gap after it. */
|
|
168
|
+
const legendSpan = (text, measured) => 14 + (measured ?? textWidth(text)) + 14;
|
|
169
|
+
/** A caption text's width estimated from its length, about 6.5 pixels a character. */
|
|
170
|
+
const textWidth = (text) => Array.from(text).length * 6.5;
|
|
171
|
+
/**
|
|
172
|
+
* A legend of `total` entries (`texts` names the first of them) held to
|
|
173
|
+
* `rows` rows: the entries it lists (a run from the first, placed as
|
|
174
|
+
* `legendLayout` places them) and, when some are left out, `more`, a count
|
|
175
|
+
* of them written `+N` after the last entry listed,
|
|
176
|
+
* with no swatch. The count's width is reserved: where it would not fit
|
|
177
|
+
* on the last row, entries step back until it does, so it never takes a
|
|
178
|
+
* row of its own past the limit.
|
|
179
|
+
*/
|
|
180
|
+
export function fittedLegend(texts, width, rows, widths = [], total = texts.length) {
|
|
181
|
+
const places = legendLayout(texts, width, widths);
|
|
182
|
+
let listed = places.filter((place) => place.row < rows).length;
|
|
183
|
+
if (listed === total)
|
|
184
|
+
return { places, more: null };
|
|
185
|
+
for (; listed > 0; listed -= 1) {
|
|
186
|
+
const last = places[listed - 1];
|
|
187
|
+
const text = `+${total - listed}`;
|
|
188
|
+
let x = last === undefined ? 0 : last.x + legendSpan(last.text, widths[listed - 1]);
|
|
189
|
+
let row = last?.row ?? 0;
|
|
190
|
+
if (x > 0 && x + textWidth(text) > width) {
|
|
191
|
+
x = 0;
|
|
192
|
+
row += 1;
|
|
193
|
+
}
|
|
194
|
+
if (row < rows)
|
|
195
|
+
return { places: places.slice(0, listed), more: { text, x, row } };
|
|
196
|
+
}
|
|
197
|
+
return { places: [], more: { text: `+${total}`, x: 0, row: 0 } };
|
|
198
|
+
}
|
|
199
|
+
/** The pitch of a legend's rows, in pixels. */
|
|
200
|
+
export const LEGEND_ROW = 16;
|
|
201
|
+
/** How tall a legend row's ink stands: its 10px swatch, 1px down, and the text beside it. */
|
|
202
|
+
const LEGEND_ROW_INK = 12;
|
|
203
|
+
/** The room under a legend's last row, the same 12px (`--space-6`) whatever the row count. */
|
|
204
|
+
const LEGEND_GAP = 12;
|
|
205
|
+
/**
|
|
206
|
+
* How many rows a pie's legend may take in a drawing `height` pixels tall
|
|
207
|
+
* whose legend starts at `legendTop`: at most `most`, and no more than keep
|
|
208
|
+
* the title, the legend, and the room under it within a third of the
|
|
209
|
+
* height, so a short drawing leaves its pie room for its tags. Always one.
|
|
210
|
+
*/
|
|
211
|
+
export function pieLegendRows(height, legendTop, most) {
|
|
212
|
+
const fit = Math.floor((height / 3 - legendTop - LEGEND_ROW_INK - LEGEND_GAP) / LEGEND_ROW) + 1;
|
|
213
|
+
return Math.max(1, Math.min(most, fit));
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Where the plot starts under a legend whose first row is at `legendTop`
|
|
217
|
+
* and that draws `rows` rows: its last row's ink plus the same 12px gap
|
|
218
|
+
* whether the legend fits one row or wraps, so a wrapped legend never
|
|
219
|
+
* crowds the plot's top grid line and tick. With no rows, the legend's top.
|
|
220
|
+
*/
|
|
221
|
+
export function plotTopUnderLegend(legendTop, rows) {
|
|
222
|
+
return rows <= 0 ? legendTop : legendTop + (rows - 1) * LEGEND_ROW + LEGEND_ROW_INK + LEGEND_GAP;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Which tick labels a horizontal axis of `span` pixels draws, and where:
|
|
226
|
+
* each centred on its tick at about `charWidth` pixels a character, moved
|
|
227
|
+
* inside the plot where it would pass an edge, and left out where it would
|
|
228
|
+
* come within `gap` pixels of the one before, so no two labels touch and
|
|
229
|
+
* none hangs past the plot.
|
|
230
|
+
*/
|
|
231
|
+
export function spacedTicks(ticks, span, charWidth = 6.5, gap = 8) {
|
|
232
|
+
const placed = [];
|
|
233
|
+
let end = -Infinity;
|
|
234
|
+
for (const tick of ticks) {
|
|
235
|
+
const width = Array.from(tick.text).length * charWidth;
|
|
236
|
+
const x = Math.min(Math.max(0, tick.at - width / 2), Math.max(0, span - width));
|
|
237
|
+
if (x < end + gap)
|
|
238
|
+
continue;
|
|
239
|
+
placed.push({ x, text: tick.text });
|
|
240
|
+
end = x + width;
|
|
241
|
+
}
|
|
242
|
+
return placed;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* The runs of consecutive points a line or an area draws, each at least
|
|
246
|
+
* one point long; a missing point (null) ends a run.
|
|
247
|
+
*/
|
|
248
|
+
export function pointRuns(points) {
|
|
249
|
+
const runs = [];
|
|
250
|
+
let run = [];
|
|
251
|
+
points.forEach((point, at) => {
|
|
252
|
+
if (point === null) {
|
|
253
|
+
if (run.length > 0)
|
|
254
|
+
runs.push(run);
|
|
255
|
+
run = [];
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
run.push({ at, point });
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
if (run.length > 0)
|
|
262
|
+
runs.push(run);
|
|
263
|
+
return runs;
|
|
264
|
+
}
|
|
@@ -27,13 +27,27 @@ export declare const unscaled: (pixel: number, domain: Domain, from: number, to:
|
|
|
27
27
|
/**
|
|
28
28
|
* The ticks of an axis over `domain`, about `count` of them: round numbers;
|
|
29
29
|
* round times; or each category in the domain, every few where there are
|
|
30
|
-
* more than `count`.
|
|
31
|
-
*
|
|
32
|
-
*
|
|
30
|
+
* more than `count`. A number or time axis shows at least three where a
|
|
31
|
+
* round step allows, however few `count` asks for, so its span can be read.
|
|
32
|
+
* Each tick is counted from the first, never added up, and a step finer
|
|
33
|
+
* than a double can tell apart at the domain's values (an integer past
|
|
34
|
+
* 2^53, a deep zoom) gives no repeats, so the ticks stay few.
|
|
33
35
|
*/
|
|
34
36
|
export declare function ticksOf(domain: Domain, kind: ScatterAxisKind, count?: number): number[];
|
|
35
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* A tick's label: the number (from a million up in the short form,
|
|
39
|
+
* "1.7936T"), the date or the time of day in UTC, or the category.
|
|
40
|
+
*/
|
|
36
41
|
export declare function tickLabel(value: number, axis: ScatterAxis, domain: Domain): string;
|
|
42
|
+
/**
|
|
43
|
+
* The labels of an axis's ticks, in order. A number axis whose ticks lie
|
|
44
|
+
* so close together for their size that their short forms would differ
|
|
45
|
+
* only past the fourth digit ("1.7936T", "1.7937T") labels the first tick
|
|
46
|
+
* in full and each other by how far past it it lies ("+100M"), so the
|
|
47
|
+
* steps read at a glance. Any other axis labels each tick on its own
|
|
48
|
+
* (`tickLabel`).
|
|
49
|
+
*/
|
|
50
|
+
export declare function tickLabels(ticks: readonly number[], axis: ScatterAxis, domain: Domain): string[];
|
|
37
51
|
/**
|
|
38
52
|
* The domains a rectangle dragged from one pixel to another zooms to, in a
|
|
39
53
|
* plot of `width` by `height` (y grows upward), or null for a rectangle too
|