@bigpixelrocket/uiok 0.2.0 → 0.2.2

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 CHANGED
@@ -6,6 +6,25 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.2.2] - 2026-11-20
10
+
11
+ ### Added
12
+
13
+ - `LineChart` `references` (`LineReference`: `value`, `label`, `tone`; `LineReferenceTone`: `'neutral'`, `'warning'`, `'danger'`): dashed horizontal lines across the plot under the series, in `--text-dim`, `--warning`, or `--danger`. The legend lists each after the series with a dashed swatch and its value ("Warning: 90 °C"); the read-out and hover dots leave them out, and the automatic value axis grows to show them. A reference whose value is not finite is left out.
14
+ - `LineChart` `valueMin` and `valueMax`: fix either end of the value axis exactly; an unset end still scales to the values. A non-finite end counts as unset, and a `valueMax` not above `valueMin` drops both. Lines beyond a fixed end are cut at the plot's edge, and references and dots there are not drawn; the read-out still shows the true value.
15
+ - `LineChart` `valueAxisWidth`: a fixed gutter for the value labels, so charts stacked over one time window line up.
16
+ - `LineSeries` `colour`: a CSS colour for one series' line, dots, and swatches; the other series keep their positions' `--chart-*` tokens.
17
+
18
+ ### Fixed
19
+
20
+ - A number or time axis over a narrow span far from zero (a fixed `LineChart` range, a deep `ScatterChart` zoom) no longer puts a tick outside the axis.
21
+
22
+ ## [0.2.1] - 2026-11-16
23
+
24
+ ### Added
25
+
26
+ - `DataGridColumn` `sortable`: `false` keeps a column's heading a plain label in a grid that sorts, for values with no order such as a JSON document or a geometric point. It draws no sort button or mark, keeps no room for the mark in its first width, has no `aria-sort`, and a click on it never asks `onSort`; it still marks, resizes, and drags as any heading does. Other columns sort as before.
27
+
9
28
  ## [0.2.0] - 2026-11-13
10
29
 
11
30
  ### Added
@@ -146,7 +165,9 @@ The first published version. The package is published to npm as `@bigpixelrocket
146
165
  - `lucide-react` 1.31 or later within 1.x is a peer dependency.
147
166
  - Terminal (`@bigpixelrocket/uiok/terminal`, `docs/components/terminal.md`): `Terminal`, Ghostty's VT engine as WebAssembly drawn on a canvas, read-only without `onInput`, with a Copy and Paste menu whose chords come from `menuChords`, a visual bell, line-editing actions bound by `actionForKey`, and `TerminalScrollbackContext`. The package root does not export it, so an app without a terminal never loads its assets. Its words are the new `terminal` label group; the package now ships a `NOTICE` with the engine's, adapter's, and font's licences.
148
167
 
149
- [Unreleased]: https://github.com/Bigpixelrocket/uiok/compare/v0.2.0...HEAD
168
+ [Unreleased]: https://github.com/Bigpixelrocket/uiok/compare/v0.2.2...HEAD
169
+ [0.2.2]: https://github.com/Bigpixelrocket/uiok/compare/v0.2.1...v0.2.2
170
+ [0.2.1]: https://github.com/Bigpixelrocket/uiok/compare/v0.2.0...v0.2.1
150
171
  [0.2.0]: https://github.com/Bigpixelrocket/uiok/compare/v0.1.4...v0.2.0
151
172
  [0.1.4]: https://github.com/Bigpixelrocket/uiok/compare/v0.1.3...v0.1.4
152
173
  [0.1.3]: https://github.com/Bigpixelrocket/uiok/compare/v0.1.2...v0.1.3
@@ -4,12 +4,26 @@ export interface LinePoint {
4
4
  readonly at: number;
5
5
  readonly value: number | null;
6
6
  }
7
+ /** The ends of the value axis a chart fixes; an end left out is scaled to the values. */
8
+ export interface ValueRange {
9
+ readonly min?: number;
10
+ readonly max?: number;
11
+ }
12
+ /**
13
+ * The fixed ends a chart can use: a non-finite end counts as unset, and
14
+ * both are dropped when the top is not above the bottom, so the axis
15
+ * scales to its values as if neither were given.
16
+ */
17
+ export declare function valueRange(min: number | undefined, max: number | undefined): ValueRange;
7
18
  /**
8
19
  * The value axis's domain over every value shown: from zero, or the lowest
9
20
  * value where one is below zero, to the highest, with a tenth to spare
10
21
  * above it; the unit domain when nothing is shown or every value is zero.
22
+ * An end `fixed` sets (after `valueRange`'s checks) is used exactly, with
23
+ * nothing to spare, and the other end scales as above over the values and
24
+ * the fixed end; a value beyond a fixed end does not move it.
11
25
  */
12
- export declare function valueDomain(values: readonly (number | null)[]): Domain;
26
+ export declare function valueDomain(values: readonly (number | null)[], fixed?: ValueRange): Domain;
13
27
  /**
14
28
  * A series' path through its points, each placed by `x` and `y`: a line
15
29
  * from one value to the next, broken where a value is missing, a lone
@@ -1,16 +1,39 @@
1
1
  /*
2
- * The geometry of the line chart (`LineChart.tsx`): the value axis's domain,
2
+ * The geometry of the line chart (`LineChart.tsx`): the value axis's domain
3
+ * (scaled to the values, or between the ends the chart fixes),
3
4
  * each series' path with its gaps, the point nearest a moment for the
4
5
  * hover's read-out, and where the time labels fit.
5
6
  */
7
+ /**
8
+ * The fixed ends a chart can use: a non-finite end counts as unset, and
9
+ * both are dropped when the top is not above the bottom, so the axis
10
+ * scales to its values as if neither were given.
11
+ */
12
+ export function valueRange(min, max) {
13
+ const low = min !== undefined && Number.isFinite(min) ? min : undefined;
14
+ const high = max !== undefined && Number.isFinite(max) ? max : undefined;
15
+ if (low !== undefined && high !== undefined && high <= low)
16
+ return {};
17
+ return {
18
+ ...(low === undefined ? {} : { min: low }),
19
+ ...(high === undefined ? {} : { max: high })
20
+ };
21
+ }
6
22
  /**
7
23
  * The value axis's domain over every value shown: from zero, or the lowest
8
24
  * value where one is below zero, to the highest, with a tenth to spare
9
25
  * above it; the unit domain when nothing is shown or every value is zero.
26
+ * An end `fixed` sets (after `valueRange`'s checks) is used exactly, with
27
+ * nothing to spare, and the other end scales as above over the values and
28
+ * the fixed end; a value beyond a fixed end does not move it.
10
29
  */
11
- export function valueDomain(values) {
12
- let min = 0;
13
- let max = 0;
30
+ export function valueDomain(values, fixed = {}) {
31
+ const range = valueRange(fixed.min, fixed.max);
32
+ if (range.min !== undefined && range.max !== undefined)
33
+ return { min: range.min, max: range.max };
34
+ let min = range.min ?? 0;
35
+ // The free top starts from zero, as on an axis with no fixed end, or from a fixed bottom above it.
36
+ let max = Math.max(0, range.min ?? 0);
14
37
  for (const value of values) {
15
38
  if (value === null || !Number.isFinite(value))
16
39
  continue;
@@ -19,6 +42,16 @@ export function valueDomain(values) {
19
42
  if (value > max)
20
43
  max = value;
21
44
  }
45
+ if (range.min !== undefined) {
46
+ return max > range.min
47
+ ? { min: range.min, max: max + (max - range.min) / 10 }
48
+ : { min: range.min, max: range.min + 1 };
49
+ }
50
+ if (range.max !== undefined) {
51
+ return min < range.max
52
+ ? { min: min < 0 ? min - (range.max - min) / 10 : min, max: range.max }
53
+ : { min: range.max - 1, max: range.max };
54
+ }
22
55
  if (max === min)
23
56
  return { min, max: min + 1 };
24
57
  return { min: min < 0 ? min - (max - min) / 10 : min, max: max + (max - min) / 10 };
@@ -4,12 +4,30 @@ import { type LinePoint } from './Line.logic.js';
4
4
  export interface LineSeries {
5
5
  readonly label: string;
6
6
  readonly points: readonly LinePoint[];
7
+ /**
8
+ * A CSS colour for this series' line, dots, and swatches in place of its
9
+ * position's chart token (`'var(--text)'`); the other series keep theirs.
10
+ */
11
+ readonly colour?: string;
12
+ }
13
+ /** The tone of a {@link LineReference}: `neutral` in `--text-dim`, `warning` in `--warning`, `danger` in `--danger`. */
14
+ export type LineReferenceTone = 'neutral' | 'warning' | 'danger';
15
+ /**
16
+ * A horizontal reference line across a {@link LineChart}'s plot at `value`
17
+ * (a limit, a target), dashed in its tone and listed in the legend after
18
+ * the series with its value ("Warning: 90 °C").
19
+ */
20
+ export interface LineReference {
21
+ readonly value: number;
22
+ readonly label: string;
23
+ /** Defaults to `'neutral'`. */
24
+ readonly tone?: LineReferenceTone;
7
25
  }
8
26
  /** Props for {@link LineChart}. */
9
27
  export interface LineChartProps {
10
28
  /** What the chart shows, for screen readers ("Questions"). */
11
29
  readonly label: string;
12
- /** The series, each drawn in the next chart token. */
30
+ /** The series, each drawn in the next chart token unless it names its own `colour`. */
13
31
  readonly series: readonly LineSeries[];
14
32
  /** The time axis's start, in Unix milliseconds. */
15
33
  readonly from: number;
@@ -21,6 +39,23 @@ export interface LineChartProps {
21
39
  readonly timeText: (at: number) => string;
22
40
  /** Hands over the time range a drag across the plot picked, earlier end first; without it the plot only reads out. */
23
41
  readonly onSelect?: (from: number, to: number) => void;
42
+ /** Dashed horizontal lines under the series, in the legend after them; a non-finite value is left out. */
43
+ readonly references?: readonly LineReference[];
44
+ /** The value axis's fixed bottom, used exactly; unset, it scales to the values. */
45
+ readonly valueMin?: number;
46
+ /**
47
+ * The value axis's fixed top, used exactly; unset, it scales to the
48
+ * values. A non-finite end counts as unset, and a top not above the
49
+ * bottom drops both. A line beyond a fixed end is cut at the plot's
50
+ * edge; a reference or dot beyond it is not drawn.
51
+ */
52
+ readonly valueMax?: number;
53
+ /**
54
+ * The pixels left of the plot for the value labels, in place of the
55
+ * widest label's width, so stacked charts given the same width line up;
56
+ * it should fit the widest label. Ignored unless finite and above zero.
57
+ */
58
+ readonly valueAxisWidth?: number;
24
59
  }
25
60
  /**
26
61
  * A time-series line chart drawn in SVG from the chart tokens, in light and
@@ -30,5 +65,10 @@ export interface LineChartProps {
30
65
  * value there. With `onSelect`, dragging across the plot picks the time
31
66
  * range between the press and the release and hands it over. The chart is
32
67
  * as wide as its frame and 55% as high, between 120 and 360 pixels.
68
+ *
69
+ * `references` draws dashed limits under the lines, which the value axis
70
+ * makes room for and the read-out leaves out; `valueMin` and `valueMax`
71
+ * pin the value axis's ends; `valueAxisWidth` fixes the gutter left of the
72
+ * plot so stacked charts align; a series' `colour` replaces its token.
33
73
  */
34
- export declare function LineChart({ label, series, from, to, format, timeText, onSelect }: LineChartProps): ReactElement;
74
+ export declare function LineChart({ label, series, from, to, format, timeText, onSelect, references, valueMin, valueMax, valueAxisWidth }: LineChartProps): ReactElement;
@@ -1,11 +1,20 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useEffect, useLayoutEffect, useRef, useState } from 'react';
2
+ import { useEffect, useId, useLayoutEffect, useRef, useState } from 'react';
3
3
  import { useLabels } from '../labels/UiokProvider.js';
4
- import { linePath, lonePoints, nearestMoment, timeTickLabels, valueDomain } from './Line.logic.js';
4
+ import { linePath, lonePoints, nearestMoment, timeTickLabels, valueDomain, valueRange } from './Line.logic.js';
5
5
  import { scaled, ticksOf, unscaled } from './Scatter.logic.js';
6
6
  import { seriesColour } from './seriesColour.js';
7
7
  /** The room the axes' ticks take around the plot. */
8
8
  const MARGIN = { top: 8, right: 10, bottom: 22, left: 52 };
9
+ /**
10
+ * How far past the plot's edges the clip of a chart with a fixed end
11
+ * reaches: half the 1.5px stroke of a series line (`charts.css`), so a
12
+ * line on a fixed end, or ending at the time axis's start or end, keeps
13
+ * its whole stroke, and one beyond a fixed end is cut there. Dots and
14
+ * reference lines are not clipped: one beyond a fixed end, or a dot
15
+ * outside the time axis, is not drawn.
16
+ */
17
+ const CLIP_SPARE = 0.75;
9
18
  /**
10
19
  * A time-series line chart drawn in SVG from the chart tokens, in light and
11
20
  * dark: a line per series over a time axis from `from` to `to` and a value
@@ -14,9 +23,15 @@ const MARGIN = { top: 8, right: 10, bottom: 22, left: 52 };
14
23
  * value there. With `onSelect`, dragging across the plot picks the time
15
24
  * range between the press and the release and hands it over. The chart is
16
25
  * as wide as its frame and 55% as high, between 120 and 360 pixels.
26
+ *
27
+ * `references` draws dashed limits under the lines, which the value axis
28
+ * makes room for and the read-out leaves out; `valueMin` and `valueMax`
29
+ * pin the value axis's ends; `valueAxisWidth` fixes the gutter left of the
30
+ * plot so stacked charts align; a series' `colour` replaces its token.
17
31
  */
18
- export function LineChart({ label, series, from, to, format, timeText, onSelect }) {
32
+ export function LineChart({ label, series, from, to, format, timeText, onSelect, references = [], valueMin, valueMax, valueAxisWidth }) {
19
33
  const labels = useLabels().charts;
34
+ const clipId = `line-clip-${useId().replace(/[^\w-]/g, '')}`;
20
35
  const frame = useRef(null);
21
36
  const svg = useRef(null);
22
37
  const [labelWidths, setLabelWidths] = useState({});
@@ -39,9 +54,18 @@ export function LineChart({ label, series, from, to, format, timeText, onSelect
39
54
  // The first layout uses a conservative estimate; SVG supplies real glyph widths
40
55
  // before paint, including locale-specific numeric separators and units.
41
56
  const widthOf = (text) => labelWidths[text] ?? Array.from(text).length * 8;
42
- const values = valueDomain(series.flatMap((entry) => entry.points.map((point) => point.value)));
57
+ const lines = references.filter((reference) => Number.isFinite(reference.value));
58
+ const fixed = valueRange(valueMin, valueMax);
59
+ // Only a fixed end can leave a value outside the plot, so only then is it cut.
60
+ const clipPath = fixed.min === undefined && fixed.max === undefined ? undefined : `url(#${clipId})`;
61
+ const values = valueDomain([
62
+ ...series.flatMap((entry) => entry.points.map((point) => point.value)),
63
+ ...lines.map((reference) => reference.value)
64
+ ], fixed);
43
65
  const valueTicks = ticksOf(values, 'number', Math.max(2, Math.floor((height - MARGIN.top - MARGIN.bottom) / 40)));
44
- const left = Math.max(MARGIN.left, ...valueTicks.map((tick) => widthOf(format(tick)) + 8));
66
+ const left = valueAxisWidth !== undefined && Number.isFinite(valueAxisWidth) && valueAxisWidth > 0
67
+ ? valueAxisWidth
68
+ : Math.max(MARGIN.left, ...valueTicks.map((tick) => widthOf(format(tick)) + 8));
45
69
  const plotWidth = Math.max(40, width - left - MARGIN.right);
46
70
  const plotHeight = Math.max(40, height - MARGIN.top - MARGIN.bottom);
47
71
  const time = { min: from, max: to > from ? to : from + 1 };
@@ -74,10 +98,18 @@ export function LineChart({ label, series, from, to, format, timeText, onSelect
74
98
  return unscaled(x, time, 0, plotWidth);
75
99
  };
76
100
  const shown = hover === null ? null : nearestMoment(moments, hover);
77
- return (_jsxs("figure", { "aria-label": label, className: "line-chart", children: [_jsxs("div", { className: "line-frame", ref: frame, children: [!drawable ? (_jsx("div", { className: "chart-empty", style: { height }, children: labels.noValue })) : (_jsxs("svg", { "aria-hidden": true, className: "line-svg", height: height, ref: svg, width: width, children: [_jsx("g", { className: "line-tick line-measure", visibility: "hidden", children: [...new Set([...timeTicks.map(timeText), ...valueTicks.map(format)])].map((text) => (_jsx("text", { children: text }, text))) }), _jsxs("g", { transform: `translate(${left} ${MARGIN.top})`, children: [timeTicks.map((tick) => (_jsx("line", { className: "line-grid", x1: px(tick), x2: px(tick), y1: 0, y2: plotHeight }, `grid${tick}`))), timeLabels.map((tick) => (_jsx("g", { className: "line-tick", children: _jsx("text", { dy: "1.1em", textAnchor: "start", x: tick.left, y: plotHeight + 4, children: tick.text }) }, `x${tick.at}`))), valueTicks.map((tick) => (_jsxs("g", { className: "line-tick", transform: `translate(0 ${py(tick)})`, children: [_jsx("line", { className: "line-grid", x1: 0, x2: plotWidth }), _jsx("text", { dy: "0.32em", textAnchor: "end", x: -6, children: format(tick) })] }, `y${tick}`))), _jsx("path", { className: "line-axes", d: `M0 0V${plotHeight}H${plotWidth}` }), series.map((entry, index) => (_jsx("path", { className: "line-series", d: linePath(entry.points.filter((point) => point.at >= time.min && point.at <= time.max), px, py), stroke: seriesColour(index) }, `${index}:${entry.label}`))), series.map((entry, index) => lonePoints(entry.points.filter((point) => point.at >= time.min && point.at <= time.max)).map((point) => (_jsx("circle", { className: "line-dot", cx: px(point.at), cy: py(point.value ?? 0), fill: seriesColour(index), r: 3 }, `lone${index}:${entry.label}:${point.at}`)))), shown !== null && (_jsx("line", { className: "line-guide", x1: px(shown), x2: px(shown), y1: 0, y2: plotHeight })), shown !== null &&
101
+ /** Whether a reference or dot at `value` is drawn: always, unless it lies beyond a fixed end. */
102
+ const onAxis = (value) => clipPath === undefined || (value >= values.min && value <= values.max);
103
+ /** Whether a dot at moment `at` and `value` is drawn: with a fixed end, only inside the plot. */
104
+ const onPlot = (at, value) => onAxis(value) && (clipPath === undefined || (at >= time.min && at <= time.max));
105
+ /** A series' colour: its own, or its position's chart token. */
106
+ const colourOf = (entry, index) => entry.colour ?? seriesColour(index);
107
+ return (_jsxs("figure", { "aria-label": label, className: "line-chart", children: [_jsxs("div", { className: "line-frame", ref: frame, children: [!drawable ? (_jsx("div", { className: "chart-empty", style: { height }, children: labels.noValue })) : (_jsxs("svg", { "aria-hidden": true, className: "line-svg", height: height, ref: svg, width: width, children: [_jsx("g", { className: "line-tick line-measure", visibility: "hidden", children: [...new Set([...timeTicks.map(timeText), ...valueTicks.map(format)])].map((text) => (_jsx("text", { children: text }, text))) }), _jsxs("g", { transform: `translate(${left} ${MARGIN.top})`, children: [clipPath !== undefined && (_jsx("defs", { children: _jsx("clipPath", { id: clipId, children: _jsx("rect", { height: plotHeight + 2 * CLIP_SPARE, width: plotWidth + 2 * CLIP_SPARE, x: -CLIP_SPARE, y: -CLIP_SPARE }) }) })), timeTicks.map((tick) => (_jsx("line", { className: "line-grid", x1: px(tick), x2: px(tick), y1: 0, y2: plotHeight }, `grid${tick}`))), timeLabels.map((tick) => (_jsx("g", { className: "line-tick", children: _jsx("text", { dy: "1.1em", textAnchor: "start", x: tick.left, y: plotHeight + 4, children: tick.text }) }, `x${tick.at}`))), valueTicks.map((tick) => (_jsxs("g", { className: "line-tick", transform: `translate(0 ${py(tick)})`, children: [_jsx("line", { className: "line-grid", x1: 0, x2: plotWidth }), _jsx("text", { dy: "0.32em", textAnchor: "end", x: -6, children: format(tick) })] }, `y${tick}`))), _jsx("path", { className: "line-axes", d: `M0 0V${plotHeight}H${plotWidth}` }), lines.map((reference, index) => onAxis(reference.value) ? (_jsx("line", { className: `line-reference line-reference-${reference.tone ?? 'neutral'}`, x1: 0, x2: plotWidth, y1: py(reference.value), y2: py(reference.value) }, `ref${index}:${reference.label}`)) : null), series.map((entry, index) => (_jsx("path", { className: "line-series", d: linePath(entry.points.filter((point) => point.at >= time.min && point.at <= time.max), px, py), clipPath: clipPath, stroke: colourOf(entry, index) }, `${index}:${entry.label}`))), series.map((entry, index) => lonePoints(entry.points.filter((point) => point.at >= time.min && point.at <= time.max))
108
+ .filter((point) => onPlot(point.at, point.value ?? 0))
109
+ .map((point) => (_jsx("circle", { className: "line-dot", cx: px(point.at), cy: py(point.value ?? 0), fill: colourOf(entry, index), r: 3 }, `lone${index}:${entry.label}:${point.at}`)))), shown !== null && (_jsx("line", { className: "line-guide", x1: px(shown), x2: px(shown), y1: 0, y2: plotHeight })), shown !== null &&
78
110
  series.map((entry, index) => {
79
111
  const value = entry.points.find((point) => point.at === shown)?.value ?? null;
80
- return value === null ? null : (_jsx("circle", { className: "line-dot", cx: px(shown), cy: py(value), fill: seriesColour(index), r: 3 }, `dot${index}:${entry.label}`));
112
+ return value === null || !onPlot(shown, value) ? null : (_jsx("circle", { className: "line-dot", cx: px(shown), cy: py(value), fill: colourOf(entry, index), r: 3 }, `dot${index}:${entry.label}`));
81
113
  }), drag !== null && (_jsx("rect", { className: "line-selection", height: plotHeight, width: Math.abs(px(drag.to) - px(drag.from)), x: Math.min(px(drag.from), px(drag.to)) })), _jsx("rect", { className: onSelect === undefined ? 'line-plot' : 'line-plot selectable', "data-testid": "line-plot", height: plotHeight, onPointerDown: (event) => {
82
114
  if (onSelect === undefined || event.button !== 0)
83
115
  return;
@@ -102,6 +134,6 @@ export function LineChart({ label, series, from, to, format, timeText, onSelect
102
134
  ? { right: width - left - px(shown) + 8 }
103
135
  : { left: left + px(shown) + 8 }, children: [_jsx("strong", { children: labels.time(timeText(shown)) }), series.map((entry, index) => {
104
136
  const value = entry.points.find((point) => point.at === shown)?.value ?? null;
105
- return (_jsxs("span", { children: [_jsx("span", { "aria-hidden": true, className: "line-swatch", style: { background: seriesColour(index) } }), labels.seriesValue(entry.label, value === null ? '---' : format(value))] }, `${index}:${entry.label}`));
106
- })] }))] }), _jsx("ul", { className: "line-legend", children: series.map((entry, index) => (_jsxs("li", { children: [_jsx("span", { "aria-hidden": true, className: "line-swatch", style: { background: seriesColour(index) } }), entry.label] }, `${index}:${entry.label}`))) })] }));
137
+ return (_jsxs("span", { children: [_jsx("span", { "aria-hidden": true, className: "line-swatch", style: { background: colourOf(entry, index) } }), labels.seriesValue(entry.label, value === null ? '---' : format(value))] }, `${index}:${entry.label}`));
138
+ })] }))] }), _jsxs("ul", { className: "line-legend", children: [series.map((entry, index) => (_jsxs("li", { children: [_jsx("span", { "aria-hidden": true, className: "line-swatch", style: { background: colourOf(entry, index) } }), entry.label] }, `${index}:${entry.label}`))), lines.map((reference, index) => (_jsxs("li", { children: [_jsx("span", { "aria-hidden": true, className: `line-swatch line-swatch-dashed line-reference-${reference.tone ?? 'neutral'}` }), labels.seriesValue(reference.label, format(reference.value))] }, `ref${index}:${reference.label}`)))] })] }));
107
139
  }
@@ -88,8 +88,13 @@ function stepTicks(domain, kind, count) {
88
88
  const at = (first + index) * step;
89
89
  if (at > domain.max)
90
90
  break;
91
- // Round away the float error a multiple of the step carries.
92
- const tick = Number(at.toPrecision(12));
91
+ // Round away the float error a multiple of the step carries, unless rounding would
92
+ // move the tick out of the domain (a narrow span far from zero).
93
+ const rounded = Number(at.toPrecision(12));
94
+ const tick = rounded < domain.min || rounded > domain.max ? at : rounded;
95
+ // A first multiple the division left a float's width below the domain is not on the axis.
96
+ if (tick < domain.min)
97
+ continue;
93
98
  if (tick !== ticks.at(-1))
94
99
  ticks.push(tick);
95
100
  }
@@ -4,8 +4,10 @@
4
4
 
5
5
  One vocabulary for every chart: caption-size type in the interface face
6
6
  with tabular figures; a 10px swatch with a 2px corner (a 10 by 3 dash for
7
- a line series); a plot with a left axis and a baseline in --border-strong
8
- and grid lines in --border-faint, never a box around it; the picked or
7
+ a line series, broken in two for a reference line); a plot with a left
8
+ axis and a baseline in --border-strong and grid lines in --border-faint,
9
+ never a box around it; a reference line dashed in its tone (--text-dim,
10
+ --warning, or --danger); the picked or
9
11
  hovered mark ringed in --text; a dragged range in the accent wash; a
10
12
  read-out in the tooltip's look; and, with nothing to draw, the plot's
11
13
  place kept with one dim line centred in it. */
@@ -151,9 +153,16 @@
151
153
  border-radius: var(--radius-xs);
152
154
  }
153
155
 
154
- /* LineChart: a frame as wide as its cell, the plot's grid and axes, a line
155
- per series in the series colours, the hover's guide with a dot on every
156
- line and the read-out, a dragged time range, and the legend under it. */
156
+ /* A reference line's swatch: the dash broken as its line is, 4px on, 2px
157
+ off, 4px on, in the tone's colour. */
158
+ .line-swatch-dashed {
159
+ background: repeating-linear-gradient(90deg, var(--line-reference) 0 4px, transparent 4px 6px);
160
+ }
161
+
162
+ /* LineChart: a frame as wide as its cell, the plot's grid and axes, dashed
163
+ reference lines under a line per series in the series colours (or the
164
+ colour a series names), the hover's guide with a dot on every line and
165
+ the read-out, a dragged time range, and the legend under it. */
157
166
  .line-chart {
158
167
  display: flex;
159
168
  flex-direction: column;
@@ -200,6 +209,27 @@
200
209
  stroke-linecap: round;
201
210
  }
202
211
 
212
+ /* A reference line (a limit, a target) and its swatch take their tone's
213
+ colour; the dash sets it apart from a series in any hue. */
214
+ .line-reference-neutral {
215
+ --line-reference: var(--text-dim);
216
+ }
217
+
218
+ .line-reference-warning {
219
+ --line-reference: var(--warning);
220
+ }
221
+
222
+ .line-reference-danger {
223
+ --line-reference: var(--danger);
224
+ }
225
+
226
+ .line-reference {
227
+ stroke: var(--line-reference);
228
+ stroke-width: 1.5;
229
+ stroke-dasharray: 4 2;
230
+ pointer-events: none;
231
+ }
232
+
203
233
  .line-guide {
204
234
  stroke: var(--text-dim);
205
235
  stroke-dasharray: 2 2;
@@ -6,7 +6,7 @@
6
6
  */
7
7
  export { svgMarkup, svgPng, tokenColour } from './Drawing.js';
8
8
  export type { LinePoint } from './Line.logic.js';
9
- export { LineChart, type LineChartProps, type LineSeries } from './LineChart.js';
9
+ export { LineChart, type LineChartProps, type LineReference, type LineReferenceTone, type LineSeries } from './LineChart.js';
10
10
  export type { PieSlice } from './Pie.logic.js';
11
11
  export { PieChart, type PieChartProps } from './PieChart.js';
12
12
  export { ResultChart, type ResultChartProps } from './ResultChart.js';
@@ -9,6 +9,13 @@ export interface DataGridColumn {
9
9
  readonly align?: 'right';
10
10
  /** Names the column across reorders, so its width follows it; its index when absent. */
11
11
  readonly id?: string;
12
+ /**
13
+ * False keeps the header a plain label while the grid sorts (a value with
14
+ * no order, such as a JSON document or a point): no sort control, no room
15
+ * for the sort mark, no `aria-sort`, and a click on it never asks
16
+ * `onSort`. Sortable when absent or true.
17
+ */
18
+ readonly sortable?: boolean;
12
19
  }
13
20
  /** The column a grid is sorted by, and which way. */
14
21
  export interface DataGridSort {
@@ -87,7 +94,10 @@ export interface DataGridProps {
87
94
  readonly sort?: DataGridSort | null;
88
95
  /** The columns the rows are sorted by, in order, each header numbered while there are several. */
89
96
  readonly sorts?: readonly DataGridSortMark[];
90
- /** Makes each header a control that asks to sort by its column; the caller orders the rows. */
97
+ /**
98
+ * Makes each header a control that asks to sort by its column, except a
99
+ * column with `sortable: false`; the caller orders the rows.
100
+ */
91
101
  readonly onSort?: (column: number, click: DataGridSortClick) => void;
92
102
  /** Lets a header be dragged to another column's place; the caller reorders `columns`. */
93
103
  readonly onReorder?: (from: number, to: number) => void;
@@ -87,12 +87,16 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
87
87
  window.clearTimeout(pendingLink.current);
88
88
  }, []);
89
89
  const keyOf = (column, index) => column.id ?? String(index);
90
+ /** Whether a column's header is a sort control: the grid sorts and the column allows it. */
91
+ const sortsBy = (column) => onSort !== undefined && column.sortable !== false;
92
+ /** The room a column's heading keeps beside its label for the sort mark. */
93
+ const labelRoom = (column) => (sortsBy(column) ? SORT_MARK_ROOM : 0);
90
94
  const [widths, setWidths] = useState(() => new Map(columns.map((column, index) => [
91
95
  keyOf(column, index),
92
- initialWidth(column.label, Array.from({ length: Math.min(rowCount, 20) }, (_, row) => cell(row, index)?.text ?? ''), CHAR_WIDTH, onSort === undefined ? 0 : SORT_MARK_ROOM)
96
+ initialWidth(column.label, Array.from({ length: Math.min(rowCount, 20) }, (_, row) => cell(row, index)?.text ?? ''), CHAR_WIDTH, labelRoom(column))
93
97
  ])));
94
98
  const widthOf = (column, index) => widths.get(keyOf(column, index)) ??
95
- initialWidth(column.label, [], CHAR_WIDTH, onSort === undefined ? 0 : SORT_MARK_ROOM);
99
+ initialWidth(column.label, [], CHAR_WIDTH, labelRoom(column));
96
100
  // The rows drawn last while they still cover where the grid stands, a fresh window otherwise.
97
101
  const held = committed.current;
98
102
  const { from, to } = held !== null &&
@@ -107,7 +111,8 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
107
111
  .filter((part) => part !== null)
108
112
  .join(' ');
109
113
  const page = Math.max(1, Math.floor(viewportHeight / ROW_HEIGHT) - 1);
110
- const marks = sorts ?? (sort === null || sort === undefined ? [] : [{ ...sort, position: 1 }]);
114
+ // A column that does not sort shows no mark, whatever the sort names, and is not counted.
115
+ const marks = (sorts ?? (sort === null || sort === undefined ? [] : [{ ...sort, position: 1 }])).filter((mark) => columns[mark.column]?.sortable !== false);
111
116
  useLayoutEffect(() => {
112
117
  const element = viewport.current;
113
118
  if (element === null || typeof ResizeObserver === 'undefined')
@@ -412,6 +417,7 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
412
417
  return (_jsx("div", { className: pointer ? 'data-grid pointer' : 'data-grid', ref: frame,
413
418
  // The frame's own height, border included; the well fills what is left.
414
419
  style: { maxHeight: maxHeight }, children: _jsxs("div", { "aria-activedescendant": cursor === null ? undefined : cellId(cursor.row, cursor.column), "aria-colcount": columns.length, "aria-label": label, "aria-multiselectable": onMarkRow === undefined ? undefined : true, "aria-rowcount": rowCount + 1, className: fades ? 'data-grid-scroll scroll-fade-x' : 'data-grid-scroll', onKeyDown: onKeyDown, ref: viewport, role: "grid", tabIndex: 0, children: [_jsxs("div", { "aria-rowindex": 1, className: "data-grid-header", ref: header, role: "row", style: { gridTemplateColumns: template }, children: [rowLead !== undefined && _jsx("div", { className: "data-grid-lead" }), columns.map((column, index) => {
420
+ const sortable = sortsBy(column);
415
421
  const mark = marks.find((entry) => entry.column === index);
416
422
  return (_jsxs("div", { "aria-colindex": index + 1, "aria-sort": mark?.direction, className: [
417
423
  'data-grid-heading',
@@ -431,10 +437,10 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
431
437
  return;
432
438
  onMarkColumn?.(index);
433
439
  }, onDoubleClick: () => onHeaderDoubleClick?.(index), onPointerDown: (event) => onHeadingPointerDown(event, index), role: "columnheader", ...(column.tip === undefined
434
- ? onSort === undefined
435
- ? cutTooltip(column.label)
436
- : {}
437
- : describedTooltip(column.tip)), children: [onSort === undefined ? (_jsx("span", { className: "data-grid-label", children: column.label })) : (_jsxs("button", { className: "data-grid-label data-grid-sort", onClick: (event) => {
440
+ ? sortable
441
+ ? {}
442
+ : cutTooltip(column.label)
443
+ : describedTooltip(column.tip)), children: [onSort === undefined || !sortable ? (_jsx("span", { className: "data-grid-label", children: column.label })) : (_jsxs("button", { className: "data-grid-label data-grid-sort", onClick: (event) => {
438
444
  event.stopPropagation();
439
445
  // A double-click's second click (`detail` 2) leaves the sort its first made.
440
446
  if (draggedClick(event) || event.detail > 1)
@@ -1173,7 +1173,8 @@ const BASE_TOKEN_NAMES = [
1173
1173
  '--update-note-rows',
1174
1174
  '--pager-height',
1175
1175
  '--menu-font-size',
1176
- '--channel-tag-bg'
1176
+ '--channel-tag-bg',
1177
+ '--line-reference'
1177
1178
  ];
1178
1179
  /** Every token name uiok defines: the fixed tokens, those a theme sets, and the stylesheet's own. */
1179
1180
  const UIOK_TOKEN_NAMES = new Set([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigpixelrocket/uiok",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "A React UI library with a retro look: themeable design tokens and accessible components.",
5
5
  "keywords": [
6
6
  "react",