@opsinjs/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/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +114 -2
- package/dist/components/accordion.d.ts +82 -0
- package/dist/components/accordion.d.ts.map +1 -0
- package/dist/components/accordion.js +154 -0
- package/dist/components/accordion.js.map +1 -0
- package/dist/components/alert-banner.d.ts +291 -0
- package/dist/components/alert-banner.d.ts.map +1 -0
- package/dist/components/alert-banner.js +529 -0
- package/dist/components/alert-banner.js.map +1 -0
- package/dist/components/avatar.d.ts +45 -0
- package/dist/components/avatar.d.ts.map +1 -0
- package/dist/components/avatar.js +159 -0
- package/dist/components/avatar.js.map +1 -0
- package/dist/components/badge.d.ts +78 -0
- package/dist/components/badge.d.ts.map +1 -0
- package/dist/components/badge.js +32 -0
- package/dist/components/badge.js.map +1 -0
- package/dist/components/body-map.d.ts +51 -0
- package/dist/components/body-map.d.ts.map +1 -0
- package/dist/components/body-map.js +190 -0
- package/dist/components/body-map.js.map +1 -0
- package/dist/components/button.d.ts +260 -0
- package/dist/components/button.d.ts.map +1 -0
- package/dist/components/button.js +609 -0
- package/dist/components/button.js.map +1 -0
- package/dist/components/callout.d.ts +99 -0
- package/dist/components/callout.d.ts.map +1 -0
- package/dist/components/callout.js +285 -0
- package/dist/components/callout.js.map +1 -0
- package/dist/components/card.d.ts +156 -0
- package/dist/components/card.d.ts.map +1 -0
- package/dist/components/card.js +396 -0
- package/dist/components/card.js.map +1 -0
- package/dist/components/care-card.d.ts +182 -0
- package/dist/components/care-card.d.ts.map +1 -0
- package/dist/components/care-card.js +544 -0
- package/dist/components/care-card.js.map +1 -0
- package/dist/components/checkbox.d.ts +58 -0
- package/dist/components/checkbox.d.ts.map +1 -0
- package/dist/components/checkbox.js +167 -0
- package/dist/components/checkbox.js.map +1 -0
- package/dist/components/combobox.d.ts +71 -0
- package/dist/components/combobox.d.ts.map +1 -0
- package/dist/components/combobox.js +204 -0
- package/dist/components/combobox.js.map +1 -0
- package/dist/components/consent-sheet.d.ts +186 -0
- package/dist/components/consent-sheet.d.ts.map +1 -0
- package/dist/components/consent-sheet.js +452 -0
- package/dist/components/consent-sheet.js.map +1 -0
- package/dist/components/dialog.d.ts +108 -0
- package/dist/components/dialog.d.ts.map +1 -0
- package/dist/components/dialog.js +573 -0
- package/dist/components/dialog.js.map +1 -0
- package/dist/components/disclaimer-note.d.ts +144 -0
- package/dist/components/disclaimer-note.d.ts.map +1 -0
- package/dist/components/disclaimer-note.js +486 -0
- package/dist/components/disclaimer-note.js.map +1 -0
- package/dist/components/divider.d.ts +76 -0
- package/dist/components/divider.d.ts.map +1 -0
- package/dist/components/divider.js +101 -0
- package/dist/components/divider.js.map +1 -0
- package/dist/components/dose-tracker.d.ts +137 -0
- package/dist/components/dose-tracker.d.ts.map +1 -0
- package/dist/components/dose-tracker.js +154 -0
- package/dist/components/dose-tracker.js.map +1 -0
- package/dist/components/empty-state.d.ts +171 -0
- package/dist/components/empty-state.d.ts.map +1 -0
- package/dist/components/empty-state.js +387 -0
- package/dist/components/empty-state.js.map +1 -0
- package/dist/components/field.d.ts +195 -0
- package/dist/components/field.d.ts.map +1 -0
- package/dist/components/field.js +282 -0
- package/dist/components/field.js.map +1 -0
- package/dist/components/goal-ring.d.ts +114 -0
- package/dist/components/goal-ring.d.ts.map +1 -0
- package/dist/components/goal-ring.js +254 -0
- package/dist/components/goal-ring.js.map +1 -0
- package/dist/components/icon-button.d.ts +124 -0
- package/dist/components/icon-button.d.ts.map +1 -0
- package/dist/components/icon-button.js +113 -0
- package/dist/components/icon-button.js.map +1 -0
- package/dist/components/link.d.ts +122 -0
- package/dist/components/link.d.ts.map +1 -0
- package/dist/components/link.js +164 -0
- package/dist/components/link.js.map +1 -0
- package/dist/components/log-sheet.d.ts +259 -0
- package/dist/components/log-sheet.d.ts.map +1 -0
- package/dist/components/log-sheet.js +437 -0
- package/dist/components/log-sheet.js.map +1 -0
- package/dist/components/menu.d.ts +69 -0
- package/dist/components/menu.d.ts.map +1 -0
- package/dist/components/menu.js +190 -0
- package/dist/components/menu.js.map +1 -0
- package/dist/components/metric-tile.d.ts +301 -0
- package/dist/components/metric-tile.d.ts.map +1 -0
- package/dist/components/metric-tile.js +533 -0
- package/dist/components/metric-tile.js.map +1 -0
- package/dist/components/number-field.d.ts +62 -0
- package/dist/components/number-field.d.ts.map +1 -0
- package/dist/components/number-field.js +134 -0
- package/dist/components/number-field.js.map +1 -0
- package/dist/components/popover.d.ts +70 -0
- package/dist/components/popover.d.ts.map +1 -0
- package/dist/components/popover.js +174 -0
- package/dist/components/popover.js.map +1 -0
- package/dist/components/progress.d.ts +83 -0
- package/dist/components/progress.d.ts.map +1 -0
- package/dist/components/progress.js +140 -0
- package/dist/components/progress.js.map +1 -0
- package/dist/components/questionnaire.d.ts +123 -0
- package/dist/components/questionnaire.d.ts.map +1 -0
- package/dist/components/questionnaire.js +148 -0
- package/dist/components/questionnaire.js.map +1 -0
- package/dist/components/radio-group.d.ts +66 -0
- package/dist/components/radio-group.d.ts.map +1 -0
- package/dist/components/radio-group.js +186 -0
- package/dist/components/radio-group.js.map +1 -0
- package/dist/components/range-bar.d.ts +172 -0
- package/dist/components/range-bar.d.ts.map +1 -0
- package/dist/components/range-bar.js +578 -0
- package/dist/components/range-bar.js.map +1 -0
- package/dist/components/range-legend.d.ts +97 -0
- package/dist/components/range-legend.d.ts.map +1 -0
- package/dist/components/range-legend.js +166 -0
- package/dist/components/range-legend.js.map +1 -0
- package/dist/components/reading-input.d.ts +225 -0
- package/dist/components/reading-input.d.ts.map +1 -0
- package/dist/components/reading-input.js +651 -0
- package/dist/components/reading-input.js.map +1 -0
- package/dist/components/relative-time.d.ts +177 -0
- package/dist/components/relative-time.d.ts.map +1 -0
- package/dist/components/relative-time.js +603 -0
- package/dist/components/relative-time.js.map +1 -0
- package/dist/components/result-card.d.ts +319 -0
- package/dist/components/result-card.d.ts.map +1 -0
- package/dist/components/result-card.js +614 -0
- package/dist/components/result-card.js.map +1 -0
- package/dist/components/scale-input.d.ts +58 -0
- package/dist/components/scale-input.d.ts.map +1 -0
- package/dist/components/scale-input.js +170 -0
- package/dist/components/scale-input.js.map +1 -0
- package/dist/components/score-dial.d.ts +205 -0
- package/dist/components/score-dial.d.ts.map +1 -0
- package/dist/components/score-dial.js +728 -0
- package/dist/components/score-dial.js.map +1 -0
- package/dist/components/scroll-area.d.ts +38 -0
- package/dist/components/scroll-area.d.ts.map +1 -0
- package/dist/components/scroll-area.js +138 -0
- package/dist/components/scroll-area.js.map +1 -0
- package/dist/components/segmented-control.d.ts +69 -0
- package/dist/components/segmented-control.d.ts.map +1 -0
- package/dist/components/segmented-control.js +259 -0
- package/dist/components/segmented-control.js.map +1 -0
- package/dist/components/select.d.ts +72 -0
- package/dist/components/select.d.ts.map +1 -0
- package/dist/components/select.js +205 -0
- package/dist/components/select.js.map +1 -0
- package/dist/components/sheet.d.ts +192 -0
- package/dist/components/sheet.d.ts.map +1 -0
- package/dist/components/sheet.js +952 -0
- package/dist/components/sheet.js.map +1 -0
- package/dist/components/skeleton.d.ts +104 -0
- package/dist/components/skeleton.d.ts.map +1 -0
- package/dist/components/skeleton.js +266 -0
- package/dist/components/skeleton.js.map +1 -0
- package/dist/components/slider.d.ts +55 -0
- package/dist/components/slider.d.ts.map +1 -0
- package/dist/components/slider.js +170 -0
- package/dist/components/slider.js.map +1 -0
- package/dist/components/source-citation.d.ts +127 -0
- package/dist/components/source-citation.d.ts.map +1 -0
- package/dist/components/source-citation.js +391 -0
- package/dist/components/source-citation.js.map +1 -0
- package/dist/components/spinner.d.ts +86 -0
- package/dist/components/spinner.d.ts.map +1 -0
- package/dist/components/spinner.js +97 -0
- package/dist/components/spinner.js.map +1 -0
- package/dist/components/status-pill.d.ts +90 -0
- package/dist/components/status-pill.d.ts.map +1 -0
- package/dist/components/status-pill.js +259 -0
- package/dist/components/status-pill.js.map +1 -0
- package/dist/components/stepper.d.ts +99 -0
- package/dist/components/stepper.d.ts.map +1 -0
- package/dist/components/stepper.js +152 -0
- package/dist/components/stepper.js.map +1 -0
- package/dist/components/surface.d.ts +92 -0
- package/dist/components/surface.d.ts.map +1 -0
- package/dist/components/surface.js +261 -0
- package/dist/components/surface.js.map +1 -0
- package/dist/components/switch.d.ts +48 -0
- package/dist/components/switch.d.ts.map +1 -0
- package/dist/components/switch.js +152 -0
- package/dist/components/switch.js.map +1 -0
- package/dist/components/symptom-picker.d.ts +69 -0
- package/dist/components/symptom-picker.d.ts.map +1 -0
- package/dist/components/symptom-picker.js +170 -0
- package/dist/components/symptom-picker.js.map +1 -0
- package/dist/components/tab-bar.d.ts +110 -0
- package/dist/components/tab-bar.d.ts.map +1 -0
- package/dist/components/tab-bar.js +118 -0
- package/dist/components/tab-bar.js.map +1 -0
- package/dist/components/table.d.ts +117 -0
- package/dist/components/table.d.ts.map +1 -0
- package/dist/components/table.js +65 -0
- package/dist/components/table.js.map +1 -0
- package/dist/components/tabs.d.ts +106 -0
- package/dist/components/tabs.d.ts.map +1 -0
- package/dist/components/tabs.js +136 -0
- package/dist/components/tabs.js.map +1 -0
- package/dist/components/term.d.ts +243 -0
- package/dist/components/term.d.ts.map +1 -0
- package/dist/components/term.js +562 -0
- package/dist/components/term.js.map +1 -0
- package/dist/components/textarea.d.ts +157 -0
- package/dist/components/textarea.d.ts.map +1 -0
- package/dist/components/textarea.js +66 -0
- package/dist/components/textarea.js.map +1 -0
- package/dist/components/timeline-entry.d.ts +99 -0
- package/dist/components/timeline-entry.d.ts.map +1 -0
- package/dist/components/timeline-entry.js +47 -0
- package/dist/components/timeline-entry.js.map +1 -0
- package/dist/components/toast.d.ts +80 -0
- package/dist/components/toast.d.ts.map +1 -0
- package/dist/components/toast.js +266 -0
- package/dist/components/toast.js.map +1 -0
- package/dist/components/tooltip.d.ts +48 -0
- package/dist/components/tooltip.d.ts.map +1 -0
- package/dist/components/tooltip.js +159 -0
- package/dist/components/tooltip.js.map +1 -0
- package/dist/components/trend-sparkline.d.ts +188 -0
- package/dist/components/trend-sparkline.d.ts.map +1 -0
- package/dist/components/trend-sparkline.js +796 -0
- package/dist/components/trend-sparkline.js.map +1 -0
- package/dist/components/value.d.ts +150 -0
- package/dist/components/value.d.ts.map +1 -0
- package/dist/components/value.js +402 -0
- package/dist/components/value.js.map +1 -0
- package/dist/components/visually-hidden.d.ts +61 -0
- package/dist/components/visually-hidden.d.ts.map +1 -0
- package/dist/components/visually-hidden.js +172 -0
- package/dist/components/visually-hidden.js.map +1 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +72 -0
- package/dist/index.js.map +1 -0
- package/dist/opsinjs.d.ts +443 -0
- package/dist/opsinjs.d.ts.map +1 -0
- package/dist/opsinjs.js +906 -0
- package/dist/opsinjs.js.map +1 -0
- package/dist/status.d.ts +111 -0
- package/dist/status.d.ts.map +1 -0
- package/dist/status.js +125 -0
- package/dist/status.js.map +1 -0
- package/dist/styles.css +2 -0
- package/dist/utils.d.ts +20 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +82 -0
- package/dist/utils.js.map +1 -0
- package/package.json +86 -3
- package/styles/base.css +132 -0
- package/styles/roles.css +412 -0
- package/styles/standalone.css +20 -0
- package/styles/tailwind.css +18 -0
- package/styles/theme.css +309 -0
|
@@ -0,0 +1,796 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* TrendSparkline is a line through readings somebody else took, and a sentence
|
|
4
|
+
* that says what the line shows without saying whether it is welcome news.
|
|
5
|
+
*
|
|
6
|
+
* A sparkline is a claim that a pattern exists, and four points with a slope
|
|
7
|
+
* look exactly like forty points with a slope. Most of this file is about
|
|
8
|
+
* refusing to draw a line the data does not support, and about making sure the
|
|
9
|
+
* words beside the line carry everything the line carries.
|
|
10
|
+
*
|
|
11
|
+
* THE CAPTION IS THE COMPONENT. There is no prop that turns it off, no
|
|
12
|
+
* `sr-only` variant of it and no `showCaption={false}`, because a graphic has no
|
|
13
|
+
* word in it at all. That is worse off than a status pill, whose measured
|
|
14
|
+
* problem is only that four hues cannot be told apart. A reader who cannot see
|
|
15
|
+
* the plot must lose the picture and keep the information. What that promise
|
|
16
|
+
* does NOT survive is `className`: it is merged onto the root with
|
|
17
|
+
* `tailwind-merge`, so a caller who passes `hidden`, `sr-only` or a
|
|
18
|
+
* `[&_[data-slot=…]]:hidden` variant removes the sentence, and nothing here can
|
|
19
|
+
* stop them. That is stated on the page rather than claimed away.
|
|
20
|
+
*
|
|
21
|
+
* NOTHING HERE IS DERIVED FROM A NUMBER THIS FILE CHOSE. There is no reference
|
|
22
|
+
* range, no smoothing, no minimum point count and no rule about how much
|
|
23
|
+
* movement counts as movement. `minimumPoints` and `changeThreshold` both come
|
|
24
|
+
* from the caller: the first is required, and without the second this component
|
|
25
|
+
* prints both endpoints and names no direction at all. Naming a direction from
|
|
26
|
+
* any difference whatever would mean this file had picked a change threshold of
|
|
27
|
+
* zero and applied it to somebody else's metric, which doctrine gives to the
|
|
28
|
+
* metric and not to us.
|
|
29
|
+
*
|
|
30
|
+
* A BAND NEEDS BOTH OF ITS ENDS. A one-sided range is a real range and it is
|
|
31
|
+
* drawn as words, never as a rectangle with an edge this file supplied: taking
|
|
32
|
+
* the missing bound from the data extent or from zero and then telling the
|
|
33
|
+
* reader in the caption that the whole band came from their laboratory credits
|
|
34
|
+
* that laboratory with a number it never gave.
|
|
35
|
+
*
|
|
36
|
+
* THE VISIBLE STATUS AXIS IS NOT DRAWN. `TrendPoint.status` decides which
|
|
37
|
+
* reading is emphasised and what the caption says about it. It puts no status
|
|
38
|
+
* colour on the marker, no status glyph on the plot and no status word there.
|
|
39
|
+
* The rule that forces this is the four-carrier rule. A visible status is
|
|
40
|
+
* colour AND a glyph AND the word, and a six-pixel dot can hold none of the
|
|
41
|
+
* three legibly, so the whole visible verdict is rendered where all three fit,
|
|
42
|
+
* as a StatusPill inside the caption, and the plot stays a picture of numbers.
|
|
43
|
+
* The fourth carrier, `data-status`, is different in kind because it draws
|
|
44
|
+
* nothing: it is the DOM contract the print stylesheet, the greyscale audit and
|
|
45
|
+
* every product test read the level from. That one is stamped on the flagged
|
|
46
|
+
* dot, since a status surface has to be findable where the flagged reading is,
|
|
47
|
+
* and to keep the two colour axes off one element the dot gives up the category
|
|
48
|
+
* tint the line already carries and is drawn in the neutral foreground instead.
|
|
49
|
+
* See the comment on `flagged` below, which is where that decision lives.
|
|
50
|
+
*
|
|
51
|
+
* NOTHING ANIMATES. Not the path, not the marker, not on first paint and not on
|
|
52
|
+
* a change. A path that draws its own length reads as time passing and implies
|
|
53
|
+
* progress; there is no reduced-motion fallback here because there is nothing to
|
|
54
|
+
* fall back from.
|
|
55
|
+
*/
|
|
56
|
+
import { CLINICAL_STATUS_META, HEALTH_CATEGORIES, isClinicalStatus, isDevelopment, isHealthCategory, spokenUnit, warnOnce, } from "../opsinjs.js";
|
|
57
|
+
import { cn } from "../utils.js";
|
|
58
|
+
import { StatusPill } from "./status-pill.js";
|
|
59
|
+
import { Value } from "./value.js";
|
|
60
|
+
/**
|
|
61
|
+
* The drawing surface, in the SVG's own user units.
|
|
62
|
+
*
|
|
63
|
+
* Unitless on purpose: the plot is stretched to whatever width it is given, so
|
|
64
|
+
* these are proportions rather than sizes. The inset keeps the stroke off the
|
|
65
|
+
* edge. Strokes here are drawn in screen pixels rather than user units (see
|
|
66
|
+
* `vectorEffect` below), so without it the topmost reading's line would be
|
|
67
|
+
* sliced in half by the viewBox boundary at every rendered size.
|
|
68
|
+
*/
|
|
69
|
+
const PLOT_WIDTH = 100;
|
|
70
|
+
const PLOT_HEIGHT = 32;
|
|
71
|
+
const PLOT_INSET = 3;
|
|
72
|
+
/**
|
|
73
|
+
* The category tint for the line, written out because Tailwind reads class
|
|
74
|
+
* names out of source as literal strings: `stroke-category-${category}-line`
|
|
75
|
+
* generates no CSS at all and the line renders in the inherited colour.
|
|
76
|
+
*
|
|
77
|
+
* The `-line` role rather than the bare category name. The bare name resolves to
|
|
78
|
+
* `-accent`, which is an identity fill chosen for recognition rather than for
|
|
79
|
+
* contrast, and a chart line is held to the non-text contrast floor against the
|
|
80
|
+
* surface behind it. `-line` is the role that was measured for exactly that.
|
|
81
|
+
*
|
|
82
|
+
* There is no status entry in this table and there never will be one. The whole
|
|
83
|
+
* table is one axis.
|
|
84
|
+
*/
|
|
85
|
+
const LINE_TINT = {
|
|
86
|
+
sleep: "stroke-category-sleep-line",
|
|
87
|
+
heart: "stroke-category-heart-line",
|
|
88
|
+
activity: "stroke-category-activity-line",
|
|
89
|
+
nutrition: "stroke-category-nutrition-line",
|
|
90
|
+
mind: "stroke-category-mind-line",
|
|
91
|
+
labs: "stroke-category-labs-line",
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* The direction word, in the reader's language rather than the API's.
|
|
95
|
+
*
|
|
96
|
+
* `unsettled` is in the table because it is in the type and a caller may write a
|
|
97
|
+
* caption using it. This component never selects it.
|
|
98
|
+
*/
|
|
99
|
+
const DIRECTION_WORD = {
|
|
100
|
+
up: "Up",
|
|
101
|
+
down: "Down",
|
|
102
|
+
level: "Unchanged",
|
|
103
|
+
unsettled: "Unsettled",
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Which development warnings this session has already printed.
|
|
107
|
+
*
|
|
108
|
+
* `tokens/errors.json` states the policy: development only, once per offending
|
|
109
|
+
* call site. The six complaints below all live in a render body. Without a
|
|
110
|
+
* keyed set they print on every render and twice again under Strict Mode, and a
|
|
111
|
+
* row of sparkline tiles fed from one bad series is the largest concentration
|
|
112
|
+
* of them in the registry: an author would have the console full before they
|
|
113
|
+
* reached the first message, and a channel somebody filters is a channel that
|
|
114
|
+
* no longer carries its one real finding.
|
|
115
|
+
*
|
|
116
|
+
* It is a module-local set rather than the substrate's `warnOnce` because
|
|
117
|
+
* `warnOnce` is keyed to an `OpsinErrorCode` and none of the six has one.
|
|
118
|
+
* OPSIN-0004, OPSIN-0010, OPSIN-0012 and the OPSIN-0011/0021 pair are the four
|
|
119
|
+
* that do have one, and they go through `warnOnce` and not through here.
|
|
120
|
+
* Allocating codes in `tokens/errors.json` for the rest and deleting this is a
|
|
121
|
+
* strict improvement.
|
|
122
|
+
*
|
|
123
|
+
* EVERY KEY NAMES THE MISTAKE, NEVER THE SERIES. Keying on a reading or a
|
|
124
|
+
* timestamp would turn "warn once" into "warn every render", because the next
|
|
125
|
+
* tile along carries different data and the same defect. So the keys are the
|
|
126
|
+
* rejected prop value where there is one, and a constant where the message
|
|
127
|
+
* interpolates nothing. The rejected prop value ranges over the handful of
|
|
128
|
+
* values a caller gets wrong.
|
|
129
|
+
*
|
|
130
|
+
* Declared rather than created, the way `warnOnce` does it in the substrate: in
|
|
131
|
+
* a production bundle `isDevelopment()` is statically false, every body that
|
|
132
|
+
* touches this is dead code, and the set is never allocated.
|
|
133
|
+
*/
|
|
134
|
+
let warnedDev;
|
|
135
|
+
function warnDevOnce(key, message) {
|
|
136
|
+
if (warnedDev?.has(key) === true)
|
|
137
|
+
return;
|
|
138
|
+
warnedDev ??= new Set();
|
|
139
|
+
warnedDev.add(key);
|
|
140
|
+
console.warn(message);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* The formatter's ceiling, and the same one `Value` uses. It applies only when
|
|
144
|
+
* a JavaScript caller passed a `precision` that is not a usable count of decimal
|
|
145
|
+
* places; a TypeScript caller cannot, because the prop is required and typed as
|
|
146
|
+
* a number. In every ordinary render this component takes the stated precision
|
|
147
|
+
* and formats both the caption and this accessible name to it, so a rounding
|
|
148
|
+
* decision the component was once not entitled to make is now the caller's,
|
|
149
|
+
* carried by the prop and forwarded rather than guessed.
|
|
150
|
+
*/
|
|
151
|
+
const MAX_FRACTION_DIGITS = 20;
|
|
152
|
+
/**
|
|
153
|
+
* A number for the accessible name, written the way `Value` writes the same
|
|
154
|
+
* number in the caption below it, and to the same stated precision.
|
|
155
|
+
*
|
|
156
|
+
* The spoken name and the printed sentence have to say one number one way, so
|
|
157
|
+
* this takes the component's `precision` and formats to that many decimal
|
|
158
|
+
* places, exactly as the caption's `Value` does. A reader who cannot see the
|
|
159
|
+
* caption is owed the reading it shows, not the seventeen digits an arithmetic
|
|
160
|
+
* result carries. A bare `String()` would also print a full stop where a de-DE
|
|
161
|
+
* reader's locale writes a comma. Separators and grouping are never hand-rolled.
|
|
162
|
+
*
|
|
163
|
+
* Rounding is `halfExpand`, the round-half-away-from-zero that
|
|
164
|
+
* `numbers-units-precision` rule 3 specifies, and it is INHERITED rather than
|
|
165
|
+
* named. `roundingMode` is an ES2023
|
|
166
|
+
* addition to `Intl.NumberFormatOptions`, so spelling it out here makes this
|
|
167
|
+
* file fail to typecheck in a consumer whose `lib` stops at ES2022, and this
|
|
168
|
+
* file ships as source into those projects. `halfExpand` is the formatter's own
|
|
169
|
+
* default, so the behaviour is identical either way; see the longer note in
|
|
170
|
+
* `value.tsx`, which records where the regression was found. Do not put it back.
|
|
171
|
+
*/
|
|
172
|
+
function formatNumber(value, locale, precision) {
|
|
173
|
+
/* Fixed decimal places, both bounds set to the stated precision, so the spoken
|
|
174
|
+
name pads and rounds exactly as the caption's `Value` does. `places` falls
|
|
175
|
+
back to `undefined` only for a precision a JavaScript caller passed that is
|
|
176
|
+
not a whole count from 0 to the ceiling, in which case the formatter is
|
|
177
|
+
opened all the way rather than throwing, and `Value` raises the warning in
|
|
178
|
+
the caption below. This mirrors `value.tsx` so the two cannot drift. */
|
|
179
|
+
const places = Number.isInteger(precision) && precision >= 0 && precision <= MAX_FRACTION_DIGITS
|
|
180
|
+
? precision
|
|
181
|
+
: undefined;
|
|
182
|
+
return new Intl.NumberFormat(locale, {
|
|
183
|
+
minimumFractionDigits: places,
|
|
184
|
+
maximumFractionDigits: places ?? MAX_FRACTION_DIGITS,
|
|
185
|
+
}).format(value);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* A date, or `undefined` when the timestamp is not one.
|
|
189
|
+
*
|
|
190
|
+
* `timeZone: "UTC"` rather than the reader's zone, because this renders on a
|
|
191
|
+
* server and again in a browser: a date that resolved differently in the two
|
|
192
|
+
* places would hydrate into a mismatch, and a date on somebody's reading that
|
|
193
|
+
* moves under them is worse than one that is a few hours out. Same treatment as
|
|
194
|
+
* the sibling components' provenance dates, for the same reason.
|
|
195
|
+
*/
|
|
196
|
+
function formatDate(iso, locale) {
|
|
197
|
+
const instant = new Date(iso);
|
|
198
|
+
if (Number.isNaN(instant.getTime()))
|
|
199
|
+
return undefined;
|
|
200
|
+
return new Intl.DateTimeFormat(locale, {
|
|
201
|
+
dateStyle: "long",
|
|
202
|
+
timeZone: "UTC",
|
|
203
|
+
}).format(instant);
|
|
204
|
+
}
|
|
205
|
+
/** A reading that was taken and is a number. */
|
|
206
|
+
function isReading(point) {
|
|
207
|
+
return point.value !== null && Number.isFinite(point.value);
|
|
208
|
+
}
|
|
209
|
+
/** An entry the caller says nobody recorded. `null` is the shape the API asks for. */
|
|
210
|
+
function isGap(point) {
|
|
211
|
+
return point.value === null;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* An entry that says a reading was taken and did not survive the trip.
|
|
215
|
+
*
|
|
216
|
+
* A FAILURE IS NOT AN ABSENCE. A parse that produced nothing, or a division with
|
|
217
|
+
* no divisor, arrives here as a non-finite number, and folding it into the gap
|
|
218
|
+
* count would tell a reader they recorded nothing on a day they did record
|
|
219
|
+
* something. `uncertainty-and-staleness` rule 6 keeps the two sentences apart:
|
|
220
|
+
* "we could not load this" is not "you have not recorded any readings yet".
|
|
221
|
+
* `Value` keeps the same three states apart for a single number, so the series
|
|
222
|
+
* has to keep them apart too. Counted separately and said separately.
|
|
223
|
+
*/
|
|
224
|
+
function isBrokenReading(point) {
|
|
225
|
+
return point.value !== null && !Number.isFinite(point.value);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* One run of consecutive readings as SVG path data.
|
|
229
|
+
*
|
|
230
|
+
* A run of one becomes `M x y L x y`, a zero-length segment, which a round line
|
|
231
|
+
* cap renders as a dot of the stroke's own width.
|
|
232
|
+
*/
|
|
233
|
+
function pathFor(run) {
|
|
234
|
+
const head = run.at(0);
|
|
235
|
+
if (head === undefined)
|
|
236
|
+
return "";
|
|
237
|
+
const move = `M ${String(head.x)} ${String(head.y)}`;
|
|
238
|
+
const rest = run
|
|
239
|
+
.slice(1)
|
|
240
|
+
.map((reading) => `L ${String(reading.x)} ${String(reading.y)}`)
|
|
241
|
+
.join(" ");
|
|
242
|
+
return rest === "" ? `${move} L ${String(head.x)} ${String(head.y)}` : `${move} ${rest}`;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Direction, from the first real reading to the last, against the change the
|
|
246
|
+
* caller says counts as a change.
|
|
247
|
+
*
|
|
248
|
+
* FIRST AND LAST, NOT A FITTED SLOPE. A regression line is a better summary of a
|
|
249
|
+
* noisy series and a worse thing to print beside one, because a reader cannot
|
|
250
|
+
* check it against the picture. The content guidance for this component asks for
|
|
251
|
+
* a caption whose every word can be checked against the plot, and first-to-last
|
|
252
|
+
* is the only summary that qualifies.
|
|
253
|
+
*
|
|
254
|
+
* `smallestChange` IS THE CALLER'S, ALWAYS. This function is called only when
|
|
255
|
+
* the caller supplied one. Doctrine gives the metric the job of declaring the
|
|
256
|
+
* difference below which a series is presented as unchanged. Below that noise
|
|
257
|
+
* floor, "about the same as last week" is the true statement. A component that
|
|
258
|
+
* answered it would be applying a change threshold of zero to a weight
|
|
259
|
+
* series where a hundred grams is the scale's own resolution. With none
|
|
260
|
+
* supplied there is no direction word at all: the caption prints both endpoints
|
|
261
|
+
* and the accessible name says "with no clear direction", which is the wording
|
|
262
|
+
* `content/alt-text-and-descriptions` gives for this case.
|
|
263
|
+
*/
|
|
264
|
+
function directionOf(first, last, smallestChange) {
|
|
265
|
+
if (Math.abs(last - first) < smallestChange)
|
|
266
|
+
return "level";
|
|
267
|
+
if (last > first)
|
|
268
|
+
return "up";
|
|
269
|
+
if (last < first)
|
|
270
|
+
return "down";
|
|
271
|
+
return "level";
|
|
272
|
+
}
|
|
273
|
+
export function TrendSparkline({ label, unit, precision, series, minimumPoints, window: windowLabel, changeThreshold, range, category, caption, locale, className, }) {
|
|
274
|
+
/* `window` is bound to a differently named local on purpose. The prop is
|
|
275
|
+
called `window` because that is the right word in the API, and a parameter
|
|
276
|
+
of that name shadows the global for the whole function body. So a future
|
|
277
|
+
SSR guard written here as `typeof window === "undefined"` would read the
|
|
278
|
+
prop, get "string", and take the client branch on the server without ever
|
|
279
|
+
reporting. Forking a component is still possible, so this file may be
|
|
280
|
+
edited outside this repository as well as in it. */
|
|
281
|
+
const points = Array.isArray(series) ? series : [];
|
|
282
|
+
const readings = points.filter(isReading);
|
|
283
|
+
const gaps = points.filter(isGap).length;
|
|
284
|
+
const brokenReadings = points.filter(isBrokenReading).length;
|
|
285
|
+
if (isDevelopment()) {
|
|
286
|
+
for (const point of points) {
|
|
287
|
+
if (!isBrokenReading(point))
|
|
288
|
+
continue;
|
|
289
|
+
warnDevOnce(`broken-reading:${String(point.value)}`, `[opsinjs] <TrendSparkline> received ${String(point.value)} as a reading ` +
|
|
290
|
+
`at ${String(point.at)}, which is not a finite number. It has not been ` +
|
|
291
|
+
"drawn, and it is counted and described to the reader as a reading that " +
|
|
292
|
+
"could not be read rather than as a gap. A gap means nobody took a " +
|
|
293
|
+
"reading, and this one says a reading was taken and did not survive the " +
|
|
294
|
+
"trip. Pass `value: null` for a gap and fix the pipeline for the rest.");
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/* An unknown category is refused rather than approximated. This file ships as
|
|
298
|
+
source into JavaScript projects where the union is advice, and a category
|
|
299
|
+
nobody has a ramp for renders an untinted line. That is honest, and is
|
|
300
|
+
better than a `stroke-category-cycle-line` class that generates no CSS and
|
|
301
|
+
leaves the reader wondering why one tile in the grid came out grey. */
|
|
302
|
+
const tinted = isHealthCategory(category) ? category : undefined;
|
|
303
|
+
if (category !== undefined && tinted === undefined) {
|
|
304
|
+
warnOnce("OPSIN-0010", {
|
|
305
|
+
category: String(category),
|
|
306
|
+
known: HEALTH_CATEGORIES.join(", "),
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
const tint = tinted === undefined ? undefined : LINE_TINT[tinted];
|
|
310
|
+
/* OPSIN-0004, at its enforcement point. The type makes `source` required, and
|
|
311
|
+
the type is advice in a JavaScript project. So the check is for the caller
|
|
312
|
+
who has none, and the repair is to draw NO BAND rather than an unowned one.
|
|
313
|
+
A shaded interval with no attribution is the consuming product asking this
|
|
314
|
+
system to vouch for a comparison it has never seen. */
|
|
315
|
+
const rangeOwner = range?.source?.trim();
|
|
316
|
+
const rangeIsOwned = range !== undefined && rangeOwner !== undefined && rangeOwner !== "";
|
|
317
|
+
if (range !== undefined && !rangeIsOwned) {
|
|
318
|
+
warnOnce("OPSIN-0004", { component: "TrendSparkline" });
|
|
319
|
+
}
|
|
320
|
+
/* A BAND NEEDS BOTH ENDS, AND THEY HAVE TO BE IN ORDER.
|
|
321
|
+
`ReferenceRange` says an omitted bound renders as an open end, never as zero
|
|
322
|
+
and never as an assumed limit. A rectangle has four edges, so a one-sided
|
|
323
|
+
range drawn as one would take its missing edge from the data extent or from
|
|
324
|
+
zero and the caption would then credit the caller's source with a bound it
|
|
325
|
+
never gave. The honest rendering of an open end here is the words in the
|
|
326
|
+
caption; the picture declines. Equal or inverted bounds have no width and go
|
|
327
|
+
the same way. */
|
|
328
|
+
const bandLow = rangeIsOwned ? range.low : undefined;
|
|
329
|
+
const bandHigh = rangeIsOwned ? range.high : undefined;
|
|
330
|
+
const bandBounds = bandLow !== undefined && bandHigh !== undefined && bandHigh > bandLow
|
|
331
|
+
? [bandLow, bandHigh]
|
|
332
|
+
: [];
|
|
333
|
+
const bandIsClosed = bandBounds.length > 0;
|
|
334
|
+
if (rangeIsOwned && !bandIsClosed && isDevelopment()) {
|
|
335
|
+
warnDevOnce("range-not-shadeable", "[opsinjs] <TrendSparkline> was given a `range` it cannot shade: a band " +
|
|
336
|
+
"needs a lower bound and an upper bound, with the lower below the upper. " +
|
|
337
|
+
"The interval has been stated in the caption in words instead, open end " +
|
|
338
|
+
"and all. It has NOT been drawn with an edge this component supplied, " +
|
|
339
|
+
"because that edge would then be attributed in the caption to your " +
|
|
340
|
+
"source, which never gave it.");
|
|
341
|
+
}
|
|
342
|
+
/* THE RULE ABOUT DRAWING, AND IT FAILS TOWARDS NOT DRAWING.
|
|
343
|
+
A `minimumPoints` that is not a whole number above zero is a caller who has
|
|
344
|
+
not decided, and a component that treats "not decided" as "no rule" draws a
|
|
345
|
+
two-point line. So an unusable value refuses the line, the same as too few
|
|
346
|
+
readings, and the caption says which of the two happened. */
|
|
347
|
+
const ruleIsUsable = Number.isInteger(minimumPoints) && minimumPoints > 0;
|
|
348
|
+
if (!ruleIsUsable && isDevelopment()) {
|
|
349
|
+
warnDevOnce(`minimum-points:${String(minimumPoints)}`, `[opsinjs] <TrendSparkline> received minimumPoints=${String(minimumPoints)}. ` +
|
|
350
|
+
"It is the number of real readings your product requires before a line may " +
|
|
351
|
+
"be drawn, so it has to be a whole number above zero. No line was drawn, " +
|
|
352
|
+
"because a component with no rule about when a trend exists has no basis " +
|
|
353
|
+
"for drawing one. There is deliberately no default to fall back on: how " +
|
|
354
|
+
"many readings make a trend depends on what was measured.");
|
|
355
|
+
}
|
|
356
|
+
const enoughReadings = ruleIsUsable && readings.length >= minimumPoints;
|
|
357
|
+
/* OPSIN-0012 fires here even though nothing was drawn, and the code's own
|
|
358
|
+
title says "a trend was drawn from too few points". The wording is aimed at
|
|
359
|
+
the defect this component makes structurally impossible; the situation the
|
|
360
|
+
code describes is a caller with fewer readings than their own rule allows,
|
|
361
|
+
which is exactly this one. OPSIN-0012 is the only code in the table
|
|
362
|
+
allocated to this component. A developer whose sparkline has silently
|
|
363
|
+
become a sentence is entitled to know why. */
|
|
364
|
+
if (ruleIsUsable && !enoughReadings) {
|
|
365
|
+
warnOnce("OPSIN-0012", { count: readings.length, minimum: minimumPoints });
|
|
366
|
+
}
|
|
367
|
+
/* THE CHANGE THRESHOLD IS THE CALLER'S OR THERE IS NO DIRECTION WORD.
|
|
368
|
+
Same failure direction as `minimumPoints`, and for the same reason: a value
|
|
369
|
+
that is not a finite number at or above zero is a caller who has not
|
|
370
|
+
decided, and the repair is to say less rather than to guess. */
|
|
371
|
+
const smallestChange = changeThreshold !== undefined &&
|
|
372
|
+
Number.isFinite(changeThreshold) &&
|
|
373
|
+
!(changeThreshold < 0)
|
|
374
|
+
? changeThreshold
|
|
375
|
+
: undefined;
|
|
376
|
+
if (changeThreshold !== undefined && smallestChange === undefined && isDevelopment()) {
|
|
377
|
+
warnDevOnce(`change-threshold:${String(changeThreshold)}`, `[opsinjs] <TrendSparkline> received changeThreshold=${String(changeThreshold)}. ` +
|
|
378
|
+
"It is the smallest difference your metric counts as a change, in the " +
|
|
379
|
+
"reading's own unit, so it has to be a finite number that is not below " +
|
|
380
|
+
"zero. No direction word was printed: the caption gives both endpoints " +
|
|
381
|
+
"and stops. There is deliberately no default, because a difference small " +
|
|
382
|
+
"enough to be the instrument's own noise is a property of what was " +
|
|
383
|
+
"measured.");
|
|
384
|
+
}
|
|
385
|
+
/* THE X-AXIS IS THE SERIES' OWN EXTENT, and it cannot be anything else.
|
|
386
|
+
`window` is a display string, so this component is never told how long the
|
|
387
|
+
period actually is and cannot lay the readings out against it. Timestamps
|
|
388
|
+
are used where they parse AND run forwards across the WHOLE array, not
|
|
389
|
+
merely at its two ends: a middle reading dated before the first one produces
|
|
390
|
+
a fraction below zero, and with `overflow-visible` on the plot that segment is
|
|
391
|
+
drawn outside this component, over whatever sits beside it. Where the check
|
|
392
|
+
fails, position falls back to the index, which is at least stable. The
|
|
393
|
+
consequence is that two sparklines side by side are only comparable when
|
|
394
|
+
their series cover the same span, and it is stated on the page, because the
|
|
395
|
+
repair is a duration prop that the specification does not have. */
|
|
396
|
+
const times = points.map((point) => Date.parse(String(point.at)));
|
|
397
|
+
const firstTime = times.at(0);
|
|
398
|
+
const lastTime = times.at(-1);
|
|
399
|
+
const timesRunForwards = times.every((time, index) => index === 0 || time >= times[index - 1]);
|
|
400
|
+
const timesUsable = firstTime !== undefined &&
|
|
401
|
+
lastTime !== undefined &&
|
|
402
|
+
times.every((time) => Number.isFinite(time)) &&
|
|
403
|
+
timesRunForwards &&
|
|
404
|
+
lastTime > firstTime;
|
|
405
|
+
if (!timesUsable && points.length > 1 && isDevelopment()) {
|
|
406
|
+
warnDevOnce("timestamps-not-chronological", "[opsinjs] <TrendSparkline> could not read its timestamps as a run of ISO " +
|
|
407
|
+
"dates that never goes backwards, so the readings have been spaced evenly " +
|
|
408
|
+
"by their position in the array instead. A gap will therefore sit at the " +
|
|
409
|
+
"wrong place along the line. `TrendPoint.at` is an ISO 8601 timestamp and " +
|
|
410
|
+
"the series is chronological.");
|
|
411
|
+
}
|
|
412
|
+
const xAt = (index) => {
|
|
413
|
+
if (points.length <= 1)
|
|
414
|
+
return PLOT_WIDTH / 2;
|
|
415
|
+
const usable = PLOT_WIDTH - PLOT_INSET * 2;
|
|
416
|
+
const at = times.at(index);
|
|
417
|
+
const fraction = timesUsable && at !== undefined
|
|
418
|
+
? (at - firstTime) / (lastTime - firstTime)
|
|
419
|
+
: index / (points.length - 1);
|
|
420
|
+
return PLOT_INSET + fraction * usable;
|
|
421
|
+
};
|
|
422
|
+
/* THE Y-AXIS INCLUDES ZERO, ALWAYS, and that is the whole of the honesty here.
|
|
423
|
+
Scaling to the data's own smallest and largest reading is what every
|
|
424
|
+
sparkline library does and it is what this component's safety callout
|
|
425
|
+
forbids: it converts ordinary variation into a full-height event, and a
|
|
426
|
+
reader has no way to tell a two-per-cent wobble from something that
|
|
427
|
+
happened. Anchoring at zero means many real series draw as a nearly flat
|
|
428
|
+
line. That is the honest picture, and why the caption carries the
|
|
429
|
+
magnitude in words. There is no `yAxisMin` prop for a caller to reach for
|
|
430
|
+
either; OPSIN-0013 is the code for the mistake this API cannot express.
|
|
431
|
+
|
|
432
|
+
A band that IS drawn widens the scale so that it fits. A band that is not
|
|
433
|
+
drawn does not touch the scale at all, because a bound nobody is shown must
|
|
434
|
+
not move the picture either. */
|
|
435
|
+
const magnitudes = readings.flatMap((point) => point.value === null ? [] : [point.value]);
|
|
436
|
+
const low = Math.min(0, ...magnitudes, ...bandBounds);
|
|
437
|
+
const high = Math.max(0, ...magnitudes, ...bandBounds);
|
|
438
|
+
const spanY = high - low;
|
|
439
|
+
const yAt = (value) => {
|
|
440
|
+
if (spanY <= 0)
|
|
441
|
+
return PLOT_HEIGHT / 2;
|
|
442
|
+
const usable = PLOT_HEIGHT - PLOT_INSET * 2;
|
|
443
|
+
return PLOT_HEIGHT - PLOT_INSET - ((value - low) / spanY) * usable;
|
|
444
|
+
};
|
|
445
|
+
const plotted = [];
|
|
446
|
+
points.forEach((point, index) => {
|
|
447
|
+
const value = point.value;
|
|
448
|
+
if (value === null || !Number.isFinite(value))
|
|
449
|
+
return;
|
|
450
|
+
plotted.push({ index, value, x: xAt(index), y: yAt(value) });
|
|
451
|
+
});
|
|
452
|
+
/* THE LINE BREAKS AT EVERY GAP, and the break is a real one in the path data
|
|
453
|
+
rather than a lighter stroke or a dotted segment. A subpath is opened at
|
|
454
|
+
each run of consecutive readings and closed by the first gap after it, so a
|
|
455
|
+
fortnight of absent data leaves a fortnight of absent line. A reading that
|
|
456
|
+
arrived broken breaks the line the same way, because it cannot be given a
|
|
457
|
+
position. The difference between the two is carried by the words.
|
|
458
|
+
|
|
459
|
+
A run of exactly one reading becomes a zero-length subpath, which with a
|
|
460
|
+
round line cap renders as a dot. That is deliberate: an isolated reading
|
|
461
|
+
between two gaps did happen, and drawing nothing for it would lose a
|
|
462
|
+
measurement rather than decline to invent one. */
|
|
463
|
+
const subpaths = [];
|
|
464
|
+
const gapEdges = [];
|
|
465
|
+
let run = [];
|
|
466
|
+
let cursor = 0;
|
|
467
|
+
let sawGap = false;
|
|
468
|
+
for (const point of points) {
|
|
469
|
+
if (isReading(point)) {
|
|
470
|
+
const reading = plotted.at(cursor);
|
|
471
|
+
cursor += 1;
|
|
472
|
+
if (reading !== undefined) {
|
|
473
|
+
/* A run opened straight after a non-reading entry: its first reading is
|
|
474
|
+
the near side of a hole, so it earns a gap-edge dot. */
|
|
475
|
+
if (run.length === 0 && sawGap)
|
|
476
|
+
gapEdges.push(reading);
|
|
477
|
+
run.push(reading);
|
|
478
|
+
}
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
481
|
+
if (run.length > 0) {
|
|
482
|
+
subpaths.push(pathFor(run));
|
|
483
|
+
/* A run closed by a non-reading entry: its last reading is the far side of
|
|
484
|
+
a hole, so it earns a gap-edge dot too. */
|
|
485
|
+
const tail = run.at(-1);
|
|
486
|
+
if (tail !== undefined)
|
|
487
|
+
gapEdges.push(tail);
|
|
488
|
+
}
|
|
489
|
+
run = [];
|
|
490
|
+
sawGap = true;
|
|
491
|
+
}
|
|
492
|
+
if (run.length > 0)
|
|
493
|
+
subpaths.push(pathFor(run));
|
|
494
|
+
/* GAP-EDGE DOTS, so a hole reads 'reading, nothing, reading' rather than
|
|
495
|
+
'line, hole, line'. A gap has no position, so no segment is drawn into or
|
|
496
|
+
out of it: one null in six entries removes two of five intervals, and the
|
|
497
|
+
absence draws larger than it is. A small dot on the reading each side of a
|
|
498
|
+
hole restores the count the caption states, without asserting a value the
|
|
499
|
+
line cannot span. The series' own first and last readings are the ends of
|
|
500
|
+
the picture rather than the edges of a hole, so they are dropped; a single
|
|
501
|
+
reading marooned between two holes is pushed from both sides, so it is
|
|
502
|
+
deduped to one dot. These dots carry the line's category tint and never a
|
|
503
|
+
status: they say a reading was taken here, which is a fact about coverage
|
|
504
|
+
and not a verdict (the rule by the marked reading above). */
|
|
505
|
+
const firstPlottedIndex = plotted.at(0)?.index;
|
|
506
|
+
const lastPlottedIndex = plotted.at(-1)?.index;
|
|
507
|
+
const seenGapEdge = new Set();
|
|
508
|
+
const gapEdgeMarks = gapEdges.filter((reading) => {
|
|
509
|
+
if (reading.index === firstPlottedIndex || reading.index === lastPlottedIndex) {
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
512
|
+
if (seenGapEdge.has(reading.index))
|
|
513
|
+
return false;
|
|
514
|
+
seenGapEdge.add(reading.index);
|
|
515
|
+
return true;
|
|
516
|
+
});
|
|
517
|
+
/* THE MARKED READING, AND WHAT THE PLOT DOES AND DOES NOT PUT ON IT.
|
|
518
|
+
A visible status is carried by colour AND a glyph AND the word, three
|
|
519
|
+
carriers and never fewer, because the measured colour-vision audit in
|
|
520
|
+
tokens/color.json finds two of the four levels indistinguishable under
|
|
521
|
+
deuteranopia and in greyscale. A marker on a sparkline can hold the colour
|
|
522
|
+
and nothing else, so it holds none of the three: the visible verdict is
|
|
523
|
+
rendered as a StatusPill inside the caption, where all three fit, and the
|
|
524
|
+
plot draws no status colour, no status glyph and no status word. The
|
|
525
|
+
specification permits a status colour on the point and does not require it,
|
|
526
|
+
and taking that permission would be shipping a red dot that a substantial
|
|
527
|
+
minority of readers cannot tell from an amber one.
|
|
528
|
+
|
|
529
|
+
THE FOURTH CARRIER IS STAMPED, NOT DRAWN. `data-status` is the DOM contract
|
|
530
|
+
the print stylesheet, the greyscale audit and every product-side test read
|
|
531
|
+
the level from, and it draws nothing, so it does belong on the plot. It is
|
|
532
|
+
stamped on the flagged value dot below, which is the one element that
|
|
533
|
+
genuinely is the flagged reading. Because the two colour axes may never
|
|
534
|
+
share an element and `data-status` is the status axis, the flagged dot gives
|
|
535
|
+
up the category tint it used to borrow from the line and is drawn in the
|
|
536
|
+
neutral foreground, heavier and ringed so it still reads as the emphasised
|
|
537
|
+
point. The category axis stays on the line, where it always was.
|
|
538
|
+
|
|
539
|
+
A LEVEL OUTSIDE THE FOUR MARKS NOTHING. `unknown` is the likeliest wrong
|
|
540
|
+
answer and it is the absence of an assertion rather than a fifth level, so a
|
|
541
|
+
reading carrying it would otherwise keep the emphasis, which is the halo
|
|
542
|
+
and the heavier marker, while StatusPill declined to render the word.
|
|
543
|
+
Emphasis with no word beside it is this file's own argument turned inside
|
|
544
|
+
out, so the selection is gated on the same predicate the pill uses.
|
|
545
|
+
|
|
546
|
+
AT MOST ONE, and the last one wins. The specification is explicit that the
|
|
547
|
+
status axis appears on a single emphasised point, and the reason is the same
|
|
548
|
+
rule: the caption names one verdict in words, so the plot emphasises one
|
|
549
|
+
reading. A caller who marked several is told which was drawn rather than
|
|
550
|
+
left to discover it. */
|
|
551
|
+
const marked = plotted.filter((reading) => isClinicalStatus(points.at(reading.index)?.status));
|
|
552
|
+
const flagged = marked.at(-1);
|
|
553
|
+
const flaggedPoint = flagged === undefined ? undefined : points.at(flagged.index);
|
|
554
|
+
const flaggedStatus = flaggedPoint?.status;
|
|
555
|
+
for (const point of points) {
|
|
556
|
+
const status = point.status;
|
|
557
|
+
if (status === undefined || isClinicalStatus(status))
|
|
558
|
+
continue;
|
|
559
|
+
warnOnce(status === "unknown" ? "OPSIN-0011" : "OPSIN-0021", {
|
|
560
|
+
component: "TrendSparkline",
|
|
561
|
+
status: String(status),
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
if (marked.length > 1 && isDevelopment()) {
|
|
565
|
+
warnDevOnce(`many-marked:${String(marked.length)}`, `[opsinjs] <TrendSparkline> was given ${String(marked.length)} readings ` +
|
|
566
|
+
"carrying a status and has emphasised the last of them. One reading is " +
|
|
567
|
+
"emphasised because the caption names one verdict in words, and a marker " +
|
|
568
|
+
"with no word beside it would be a status carried by colour alone. If more " +
|
|
569
|
+
"than one reading needs a verdict on screen, that is a table rather than a " +
|
|
570
|
+
"sparkline.");
|
|
571
|
+
}
|
|
572
|
+
const first = plotted.at(0);
|
|
573
|
+
const last = plotted.at(-1);
|
|
574
|
+
const drawn = enoughReadings && first !== undefined && last !== undefined;
|
|
575
|
+
/* WHICH READING WAS MARKED, so the words carry what the marker carries. The
|
|
576
|
+
caption and the plot's accessible name both say it, built from the same
|
|
577
|
+
three facts here so the two cannot drift. The date is read straight from the
|
|
578
|
+
marked reading's own `at` and never invented: when it will not parse,
|
|
579
|
+
`markedOn` is undefined and the sentence names no date rather than a wrong
|
|
580
|
+
one. `markedIsLast` lets "the most recent reading" stand in for a date the
|
|
581
|
+
reader would otherwise have to place by counting back through the series. */
|
|
582
|
+
const markedIsLast = flagged !== undefined && last !== undefined && flagged.index === last.index;
|
|
583
|
+
const markedOn = flagged === undefined
|
|
584
|
+
? undefined
|
|
585
|
+
: formatDate(String(points.at(flagged.index)?.at), locale);
|
|
586
|
+
const direction = first === undefined || last === undefined || smallestChange === undefined
|
|
587
|
+
? undefined
|
|
588
|
+
: directionOf(first.value, last.value, smallestChange);
|
|
589
|
+
const bandDrawn = bandIsClosed && drawn;
|
|
590
|
+
const spoken = spokenUnit(unit, high) ?? unit;
|
|
591
|
+
const lowest = magnitudes.length > 0 ? Math.min(...magnitudes) : undefined;
|
|
592
|
+
const highest = magnitudes.length > 0 ? Math.max(...magnitudes) : undefined;
|
|
593
|
+
/* WHEN, NOT ONLY HOW LONG. `window` is a display string this component can
|
|
594
|
+
never check, so on its own it reads as current at any age: a series whose
|
|
595
|
+
last reading was taken three months ago renders identically to one taken
|
|
596
|
+
this morning. Every point already carries its own `at`, so the last real
|
|
597
|
+
reading's date is printed rather than inferred. No staleness boundary is
|
|
598
|
+
invented here and none is available to be. How old is too old belongs to
|
|
599
|
+
the metric, and a product that wants a verdict about age puts a
|
|
600
|
+
RelativeTime beside the plot. */
|
|
601
|
+
const lastReadingAt = last === undefined ? undefined : points.at(last.index)?.at;
|
|
602
|
+
const measuredOn = lastReadingAt === undefined ? undefined : formatDate(String(lastReadingAt), locale);
|
|
603
|
+
const whenSentence = last === undefined
|
|
604
|
+
? ""
|
|
605
|
+
: measuredOn === undefined
|
|
606
|
+
? " We do not know when the last reading was taken."
|
|
607
|
+
: ` The last reading was taken on ${measuredOn}.`;
|
|
608
|
+
/* The plot's accessible name, which is the picture described as a picture:
|
|
609
|
+
what was measured, over what period, how many readings there are, what they
|
|
610
|
+
range between, which way they went, which reading was marked, and what is
|
|
611
|
+
missing. The pattern is the one in content/alt-text-and-descriptions:
|
|
612
|
+
measure, period, coverage, extent, direction. It includes its own wording
|
|
613
|
+
for a series whose direction nobody has told us how to judge. Its final
|
|
614
|
+
element, a pointer to the table twin, is absent because there is no table
|
|
615
|
+
twin to point at; that gap is recorded on the page rather than papered over
|
|
616
|
+
here. It never says "chart of", "the red zone", or "trending up". The
|
|
617
|
+
marked-reading clause names the reading the plot emphasises, by recency when
|
|
618
|
+
it is the last reading and by its own date otherwise, so a reader who cannot
|
|
619
|
+
see the marker still knows which reading carries the verdict. */
|
|
620
|
+
const extent = lowest === undefined || highest === undefined
|
|
621
|
+
? ""
|
|
622
|
+
: lowest === highest
|
|
623
|
+
? `every one of them ${formatNumber(lowest, locale, precision)} ${spoken}`
|
|
624
|
+
: `between ${formatNumber(lowest, locale, precision)} and ${formatNumber(highest, locale, precision)} ${spoken}`;
|
|
625
|
+
const directionPhrase = direction === undefined
|
|
626
|
+
? "with no clear direction"
|
|
627
|
+
: `${DIRECTION_WORD[direction].toLowerCase()} from the first reading to the last`;
|
|
628
|
+
/* Said as whole entries rather than as a bare count, because "1 with no
|
|
629
|
+
reading" leaves a listener asking one what. Said as two separate sentences,
|
|
630
|
+
because an entry nobody recorded and a reading that arrived broken are two
|
|
631
|
+
different things to be told about your own record. */
|
|
632
|
+
const missingSentence = (gaps === 0
|
|
633
|
+
? ""
|
|
634
|
+
: gaps === 1
|
|
635
|
+
? " 1 entry has no reading."
|
|
636
|
+
: ` ${String(gaps)} entries have no reading.`) +
|
|
637
|
+
(brokenReadings === 0
|
|
638
|
+
? ""
|
|
639
|
+
: brokenReadings === 1
|
|
640
|
+
? " 1 reading could not be read."
|
|
641
|
+
: ` ${String(brokenReadings)} readings could not be read.`);
|
|
642
|
+
const bandSentence = bandDrawn && bandLow !== undefined && bandHigh !== undefined
|
|
643
|
+
? ` A shaded band, ${formatNumber(bandLow, locale, precision)} to ${formatNumber(bandHigh, locale, precision)} ${spoken}, from ${String(rangeOwner)}.`
|
|
644
|
+
: "";
|
|
645
|
+
/* The marked reading, named by recency or by its own date, in the same words
|
|
646
|
+
the caption uses below so the picture and its name cannot disagree. Empty
|
|
647
|
+
when nothing carries a status. The number is `formatNumber` and `spoken`,
|
|
648
|
+
exactly as `extent` above, and the verdict word comes from
|
|
649
|
+
CLINICAL_STATUS_META rather than being spelled a second time here. */
|
|
650
|
+
const markedSentence = flaggedStatus === undefined || flagged === undefined
|
|
651
|
+
? ""
|
|
652
|
+
: markedIsLast
|
|
653
|
+
? ` The most recent reading, ${formatNumber(flagged.value, locale, precision)} ${spoken}, is marked ${CLINICAL_STATUS_META[flaggedStatus].word}.`
|
|
654
|
+
: markedOn !== undefined
|
|
655
|
+
? ` The reading taken on ${markedOn}, ${formatNumber(flagged.value, locale, precision)} ${spoken}, is marked ${CLINICAL_STATUS_META[flaggedStatus].word}.`
|
|
656
|
+
: ` One reading, ${formatNumber(flagged.value, locale, precision)} ${spoken}, is marked ${CLINICAL_STATUS_META[flaggedStatus].word}.`;
|
|
657
|
+
const plotName = extent === ""
|
|
658
|
+
? `${label} over ${windowLabel}. No readings to draw.`
|
|
659
|
+
: `${label} over ${windowLabel}: ${String(readings.length)} readings, ${extent}, ` +
|
|
660
|
+
`${directionPhrase}.${bandSentence}${markedSentence}${missingSentence}${whenSentence}`;
|
|
661
|
+
/* The same two facts as the accessible name's missing sentence, in the
|
|
662
|
+
caption's own grammar, and the one clause a caller's own sentence does not
|
|
663
|
+
displace: how much of the window has no measurement in it. */
|
|
664
|
+
const missingParts = [];
|
|
665
|
+
if (gaps > 0) {
|
|
666
|
+
missingParts.push(gaps === 1
|
|
667
|
+
? "1 gap where nothing was recorded"
|
|
668
|
+
: `${String(gaps)} gaps where nothing was recorded`);
|
|
669
|
+
}
|
|
670
|
+
if (brokenReadings > 0) {
|
|
671
|
+
missingParts.push(brokenReadings === 1
|
|
672
|
+
? "1 reading that could not be read"
|
|
673
|
+
: `${String(brokenReadings)} readings that could not be read`);
|
|
674
|
+
}
|
|
675
|
+
const missingClause = missingParts.length === 0 ? "with none missing." : `and ${missingParts.join(" and ")}.`;
|
|
676
|
+
const ownCaption = caption !== undefined && caption.trim() !== "" ? caption.trim() : undefined;
|
|
677
|
+
/* The words for the caller's interval, open end and all, so that a band the
|
|
678
|
+
picture declines to draw is still a thing the reader has been told. */
|
|
679
|
+
const rangeInterval = bandLow !== undefined && bandHigh !== undefined ? (_jsxs(_Fragment, { children: [_jsx(Value, { value: bandLow, unit: unit, precision: precision, locale: locale }), " to", " ", _jsx(Value, { value: bandHigh, unit: unit, precision: precision, locale: locale })] })) : bandLow !== undefined ? (_jsxs(_Fragment, { children: [_jsx(Value, { value: bandLow, unit: unit, precision: precision, locale: locale }), " and upwards"] })) : bandHigh !== undefined ? (_jsxs(_Fragment, { children: ["up to ", _jsx(Value, { value: bandHigh, unit: unit, precision: precision, locale: locale })] })) : undefined;
|
|
680
|
+
const bandRefusal = !bandIsClosed
|
|
681
|
+
? bandLow !== undefined && bandHigh !== undefined
|
|
682
|
+
? "because its lower bound is not below its upper one"
|
|
683
|
+
: "because a band needs both of its ends"
|
|
684
|
+
: "because no line was drawn";
|
|
685
|
+
return (_jsxs("div", { "data-slot": "trend-sparkline",
|
|
686
|
+
/* The caption sits at `body`, not at `footnote`. The caption is the
|
|
687
|
+
component (see the file header), and body is the scale's anchor for
|
|
688
|
+
prose, so the one sentence that says what changed, how much is missing
|
|
689
|
+
and which reading needs watching is set at the step a reader reads prose
|
|
690
|
+
at. Footnote is reserved for provenance, which here is the window label
|
|
691
|
+
and the freshness clause, not the caption. The size lives on the root so
|
|
692
|
+
a caller who passes a smaller step in `className`, `text-opsin-callout`
|
|
693
|
+
for a dense tile, can still shrink the whole sentence: tailwind-merge
|
|
694
|
+
only lets them win when the size is on the element they are merging
|
|
695
|
+
into. Do not optimise this back down. */
|
|
696
|
+
className: cn("flex w-full flex-col gap-opsin-2 text-opsin-body", className), children: [ownCaption !== undefined && drawn ? (_jsx("p", { "data-slot": "trend-sparkline-window",
|
|
697
|
+
/* The window is a provenance line, the period the plot covers, so it
|
|
698
|
+
sits at `footnote`, the step D10 assigns to provenance, timestamps
|
|
699
|
+
and the freshness line, naming TrendSparkline among the components
|
|
700
|
+
that come up to it from caption1. It carries its own step rather
|
|
701
|
+
than inheriting the caption's, because a class on the element beats
|
|
702
|
+
the one inherited from the root, so raising the caption to body
|
|
703
|
+
leaves this label at footnote. */
|
|
704
|
+
className: "m-0 text-opsin-footnote text-muted-foreground", children: windowLabel })) : null, drawn ? (_jsxs("svg", { "data-slot": "trend-sparkline-plot",
|
|
705
|
+
/* role="img" with a name, and never `meter`, `slider` or
|
|
706
|
+
`progressbar`. All three announce a value the reader can inspect or
|
|
707
|
+
change; this is a picture of readings somebody else took. It is not
|
|
708
|
+
focusable and not in the tab order. `focusable="false"` is
|
|
709
|
+
belt-and-braces for the engines that made SVG focusable by default.
|
|
710
|
+
It is not announced point by point, because a fourteen-point
|
|
711
|
+
series read aloud one point at a time is worse than silence. */
|
|
712
|
+
role: "img", "aria-label": plotName, focusable: "false", viewBox: `0 0 ${String(PLOT_WIDTH)} ${String(PLOT_HEIGHT)}`,
|
|
713
|
+
/* Stretched rather than fitted, so the plot fills whatever column it
|
|
714
|
+
is given. That has a cost the page states: the apparent slope is a
|
|
715
|
+
function of the column's width and of the reader's text size rather
|
|
716
|
+
than of the data, so two of these are comparable only at the same
|
|
717
|
+
width and the same text size. Every stroke below carries
|
|
718
|
+
`vectorEffect` so that the uneven scale does not thin the line at
|
|
719
|
+
one width and thicken it at another, and every marker is a
|
|
720
|
+
zero-length round-capped segment rather than a circle, because a
|
|
721
|
+
circle in a stretched viewBox is an ellipse.
|
|
722
|
+
|
|
723
|
+
That is now only half the story. With `vectorEffect` the used
|
|
724
|
+
stroke width is a CSS length rather than a user-unit length, so each
|
|
725
|
+
width below is stated in `rem` through an arbitrary-property class
|
|
726
|
+
rather than as a unitless `strokeWidth` attribute. A rem resolves
|
|
727
|
+
against the root font size, so when the reader doubles their text
|
|
728
|
+
size and `h-opsin-12` doubles the plot's height the strokes double
|
|
729
|
+
with it, and the graphic no longer thins relative to the type at the
|
|
730
|
+
very setting a reader chose because thin things are hard to see. A
|
|
731
|
+
width takes the space token that equals it exactly, and a literal
|
|
732
|
+
rem only where no token holds that value: 6px and 9px have no token,
|
|
733
|
+
1px is `--opsin-space-px`, 2px `--opsin-space-0-5`, 4px
|
|
734
|
+
`--opsin-space-1`. */
|
|
735
|
+
preserveAspectRatio: "none", className: "h-opsin-12 w-full overflow-visible", children: [_jsx("path", { "data-slot": "trend-sparkline-baseline", d: `M ${String(PLOT_INSET)} ${String(yAt(0))} L ${String(PLOT_WIDTH - PLOT_INSET)} ${String(yAt(0))}`, vectorEffect: "non-scaling-stroke", className: "[stroke-width:var(--opsin-space-px)] stroke-muted-foreground forced-colors:stroke-[CanvasText]" }), bandDrawn && bandLow !== undefined && bandHigh !== undefined ? (_jsx("rect", { "data-slot": "trend-sparkline-band",
|
|
736
|
+
/* Neutral, and neutral is the whole specification for this part. A
|
|
737
|
+
shaded interval in a status colour would be the two-axis
|
|
738
|
+
collision with extra steps: the reader would take the tint for a
|
|
739
|
+
verdict about the readings sitting inside it, which is a
|
|
740
|
+
comparison this component was never given. The dashed edge is
|
|
741
|
+
what distinguishes the band from the line without colour, in
|
|
742
|
+
greyscale and in print. The edge is drawn in the role that
|
|
743
|
+
scripts/check-contrast.mts measures against both the page and
|
|
744
|
+
the band fill, and it clears the non-text contrast floor in
|
|
745
|
+
both themes. The fill does not clear that floor and is not asked
|
|
746
|
+
to, because the band is identified by its edge and by the
|
|
747
|
+
caption's sentence rather than by the tint. */
|
|
748
|
+
x: PLOT_INSET, width: PLOT_WIDTH - PLOT_INSET * 2, y: yAt(bandHigh), height: Math.max(0, yAt(bandLow) - yAt(bandHigh)), vectorEffect: "non-scaling-stroke",
|
|
749
|
+
/* Under forced colours an SVG stroke keeps its author colour while
|
|
750
|
+
the boxes and text around it switch to system colours, so a
|
|
751
|
+
neutral hairline that already sits near the contrast floor
|
|
752
|
+
disappears for the reader who turned the mode on to see it. Every
|
|
753
|
+
stroke in this graphic takes a system colour so the whole picture
|
|
754
|
+
switches together rather than half of it. The band edge is ink.
|
|
755
|
+
|
|
756
|
+
The dash is a screen-space length, not a user-unit one: with
|
|
757
|
+
`vectorEffect` the stroke and its dash are measured in the space
|
|
758
|
+
in effect at render time rather than in viewBox units, so the
|
|
759
|
+
pattern is isotropic and no longer stretches with the column the
|
|
760
|
+
way a unitless `strokeDasharray` did. 0.25rem on and 0.25rem off
|
|
761
|
+
is 4px each at a 16px root, which still reads as a dash on a
|
|
762
|
+
hairline where a 2px pattern flattened toward solid. */
|
|
763
|
+
className: "[stroke-width:var(--opsin-space-px)] [stroke-dasharray:0.25rem_0.25rem] fill-muted stroke-muted-foreground forced-colors:stroke-[CanvasText]" })) : null, _jsx("path", { "data-slot": "trend-sparkline-line", "data-category": tinted, d: subpaths.join(" "), fill: "none", strokeLinecap: "round", strokeLinejoin: "round", vectorEffect: "non-scaling-stroke", className: cn("[stroke-width:var(--opsin-space-0-5)] stroke-foreground", tint, "forced-colors:stroke-[CanvasText]") }), gapEdgeMarks.map((reading) => (_jsx("path", { "data-slot": "trend-sparkline-gap-edge", d: `M ${String(reading.x)} ${String(reading.y)} L ${String(reading.x)} ${String(reading.y)}`, strokeLinecap: "round", vectorEffect: "non-scaling-stroke", className: cn("[stroke-width:var(--opsin-space-1)] stroke-foreground", tint, "forced-colors:stroke-[CanvasText]") }, reading.index))), flagged === undefined ? null : (_jsxs(_Fragment, { children: [_jsx("path", { d: `M ${String(flagged.x)} ${String(flagged.y)} L ${String(flagged.x)} ${String(flagged.y)}`, strokeLinecap: "round", vectorEffect: "non-scaling-stroke",
|
|
764
|
+
/* 0.5625rem is 9px at a 16px root. A literal rem because no
|
|
765
|
+
space token holds this value, unlike the widths that name
|
|
766
|
+
`--opsin-space-*` above. */
|
|
767
|
+
className: "[stroke-width:0.5625rem] stroke-background forced-colors:stroke-[Canvas]" }), _jsx("path", { "data-slot": "trend-sparkline-point", "data-status": flaggedStatus, "data-opsinjs-value": String(flagged.value), d: `M ${String(flagged.x)} ${String(flagged.y)} L ${String(flagged.x)} ${String(flagged.y)}`, strokeLinecap: "round", vectorEffect: "non-scaling-stroke",
|
|
768
|
+
/* 0.375rem is 6px at a 16px root, a literal rem because no space
|
|
769
|
+
token holds this value. Heavier than the line at 0.125rem and
|
|
770
|
+
lighter than the halo at 0.5625rem, and the three keep that
|
|
771
|
+
ordering at every text size because all three now scale. Drawn
|
|
772
|
+
in the neutral foreground, so its weight and its halo, not a
|
|
773
|
+
colour, are what set it apart from the line: this dot carries
|
|
774
|
+
the status contract and must stay off the category axis. */
|
|
775
|
+
className: cn("[stroke-width:0.375rem] stroke-foreground", "forced-colors:stroke-[CanvasText]") })] }))] })) : null, _jsxs("p", { "data-slot": "trend-sparkline-caption", className: "m-0 text-pretty", children: [drawn && first !== undefined && last !== undefined ? (ownCaption ?? (_jsxs(_Fragment, { children: [direction === undefined ? "From" : `${DIRECTION_WORD[direction]}, from`, " ", _jsx(Value, { value: first.value, unit: unit, precision: precision, locale: locale }), " to", " ", _jsx(Value, { value: last.value, unit: unit, precision: precision, locale: locale }), ", over ", windowLabel, "."] }))) : (_jsxs(_Fragment, { children: ["Not enough readings to draw a trend over ", windowLabel, ": there", " ", readings.length === 1 ? "is only 1" : `are ${String(readings.length)}`, ruleIsUsable
|
|
776
|
+
? `, and a trend needs ${String(minimumPoints)}.`
|
|
777
|
+
: ", and the number this needs is not a whole number above zero.", ownCaption === undefined ? null : ` ${ownCaption}`] })), flaggedStatus === undefined || flagged === undefined ? null : (
|
|
778
|
+
/* Names the marked reading, not just its value and verdict: by recency
|
|
779
|
+
when it is the last reading, by its own date otherwise, and by
|
|
780
|
+
neither when that date will not parse. Built from the same
|
|
781
|
+
`markedIsLast` and `markedOn` as the plot's name above, so the two
|
|
782
|
+
read alike. `<Value>` carries the number and `<StatusPill>` the
|
|
783
|
+
word, so the value, the unit, the status word and its icon are all
|
|
784
|
+
still separate carriers. The clause closes with a full stop after
|
|
785
|
+
the pill, so the range attribution that follows begins its own
|
|
786
|
+
sentence rather than running on: StatusPill is inline-flex and
|
|
787
|
+
baseline-aligned, so the stop sits on the text baseline. It renders
|
|
788
|
+
in both branches, because a verdict the product assigned is not
|
|
789
|
+
withdrawn just because too few readings arrived to draw a line. */
|
|
790
|
+
_jsxs(_Fragment, { children: [" ", markedIsLast
|
|
791
|
+
? "The most recent reading, "
|
|
792
|
+
: markedOn !== undefined
|
|
793
|
+
? `The reading taken on ${markedOn}, `
|
|
794
|
+
: "One reading, ", _jsx(Value, { value: flagged.value, unit: unit, precision: precision, locale: locale }), ", is marked", " ", _jsx(StatusPill, { status: flaggedStatus, describes: label }), "."] })), drawn && first !== undefined && last !== undefined ? (_jsxs(_Fragment, { children: [" ", String(readings.length), " readings, ", missingClause] })) : (missingSentence), whenSentence, !rangeIsOwned || rangeInterval === undefined ? null : bandDrawn ? (_jsxs(_Fragment, { children: [" The shaded band, ", rangeInterval, ", comes from ", rangeOwner, "."] })) : (_jsxs(_Fragment, { children: [" ", "The range from ", rangeOwner, " is ", rangeInterval, ". It is not shaded, ", bandRefusal, "."] }))] })] }));
|
|
795
|
+
}
|
|
796
|
+
//# sourceMappingURL=trend-sparkline.js.map
|