@tonycodes-ui/mortar 0.29.0 → 0.30.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 +6 -18
- package/catalog.json +463 -361
- package/cli/audit.mjs +1 -1
- package/cli/data.mjs +5 -0
- package/cli/packet.mjs +2 -0
- package/dist/agent-data.json +1 -1
- package/dist/application.d.ts +2 -0
- package/dist/application.js +2 -1
- package/dist/chart-core.d.ts +30 -0
- package/dist/chart-core.js +100 -0
- package/dist/charts.d.ts +3 -0
- package/dist/charts.js +3 -0
- package/dist/sparkline.d.ts +28 -0
- package/dist/sparkline.js +31 -0
- package/docs/charts.md +68 -0
- package/package.json +5 -1
- package/src/application.css +6 -1
- package/src/application.tsx +10 -0
- package/src/chart-core.ts +113 -0
- package/src/charts.css +58 -0
- package/src/charts.ts +6 -0
- package/src/sparkline.tsx +124 -0
- package/src/tokens.css +26 -0
- package/styles.css +1 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { CSSProperties } from "react";
|
|
2
|
+
import { componentRoot, cx } from "./internal.js";
|
|
3
|
+
import {
|
|
4
|
+
areaPath,
|
|
5
|
+
extent,
|
|
6
|
+
linearScale,
|
|
7
|
+
linePath,
|
|
8
|
+
seriesColour,
|
|
9
|
+
type ChartSlot,
|
|
10
|
+
} from "./chart-core.js";
|
|
11
|
+
|
|
12
|
+
export interface SparklineProps {
|
|
13
|
+
/** The values in order, oldest first. Missing values (NaN) break the line. */
|
|
14
|
+
values: readonly number[];
|
|
15
|
+
/** What the values measure, e.g. "Revenue, last 12 months". Read as the start of its summary. */
|
|
16
|
+
label: string;
|
|
17
|
+
/** Formats values in the spoken summary. Defaults to the locale's number format. */
|
|
18
|
+
format?: (value: number) => string;
|
|
19
|
+
/** Series colour slot, 1–8. Default 1. */
|
|
20
|
+
slot?: ChartSlot;
|
|
21
|
+
/** Height in pixels; the width follows the container. Default 32. */
|
|
22
|
+
height?: number;
|
|
23
|
+
/** Mark the latest value with a dot. Default true. */
|
|
24
|
+
showLast?: boolean;
|
|
25
|
+
/** Fill under the line. */
|
|
26
|
+
area?: boolean;
|
|
27
|
+
/** Shade a reference range, such as a target or normal band. */
|
|
28
|
+
band?: { min: number; max: number };
|
|
29
|
+
id?: string;
|
|
30
|
+
className?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const number = new Intl.NumberFormat();
|
|
34
|
+
|
|
35
|
+
/** The spoken summary: label, count, range and latest value. */
|
|
36
|
+
export function sparklineSummary(
|
|
37
|
+
values: readonly number[],
|
|
38
|
+
label: string,
|
|
39
|
+
format: (value: number) => string = (v) => number.format(v),
|
|
40
|
+
) {
|
|
41
|
+
const finite = values.filter(Number.isFinite);
|
|
42
|
+
if (!finite.length) return `${label}: no data`;
|
|
43
|
+
const [min, max] = extent(finite);
|
|
44
|
+
const last = finite[finite.length - 1];
|
|
45
|
+
return finite.length === 1
|
|
46
|
+
? `${label}: ${format(last)}`
|
|
47
|
+
: `${label}: ${finite.length} values from ${format(min)} to ${format(max)}, latest ${format(last)}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** A small, axis-free trend line for a stat tile, table cell or list row. */
|
|
51
|
+
export function Sparkline({
|
|
52
|
+
values,
|
|
53
|
+
label,
|
|
54
|
+
format,
|
|
55
|
+
slot = 1,
|
|
56
|
+
height = 32,
|
|
57
|
+
showLast = true,
|
|
58
|
+
area = false,
|
|
59
|
+
band,
|
|
60
|
+
id,
|
|
61
|
+
className,
|
|
62
|
+
}: SparklineProps) {
|
|
63
|
+
const [min, max] = extent(
|
|
64
|
+
band ? [...values, band.min, band.max] : [...values],
|
|
65
|
+
);
|
|
66
|
+
// A single value maps through a flat domain to the middle.
|
|
67
|
+
const x = linearScale([0, values.length - 1], [0, 100]);
|
|
68
|
+
const y = linearScale([min, max], [100, 0]);
|
|
69
|
+
const points = values.map((v, i) => ({ x: x(i), y: y(v) }));
|
|
70
|
+
let lastIndex = values.length - 1;
|
|
71
|
+
while (lastIndex >= 0 && !Number.isFinite(values[lastIndex])) lastIndex--;
|
|
72
|
+
const last = lastIndex >= 0 ? points[lastIndex] : undefined;
|
|
73
|
+
return (
|
|
74
|
+
<span
|
|
75
|
+
id={id}
|
|
76
|
+
{...componentRoot("Sparkline")}
|
|
77
|
+
className={cx("m-sparkline", className)}
|
|
78
|
+
role="img"
|
|
79
|
+
aria-label={sparklineSummary(values, label, format)}
|
|
80
|
+
style={
|
|
81
|
+
{
|
|
82
|
+
height,
|
|
83
|
+
"--m-sparkline-colour": seriesColour(slot),
|
|
84
|
+
} as CSSProperties
|
|
85
|
+
}
|
|
86
|
+
>
|
|
87
|
+
{/* The plot sits inside padding sized for the dot and its ring, so
|
|
88
|
+
nothing reaches past the sparkline's own box. */}
|
|
89
|
+
<span className="m-sparkline-plot">
|
|
90
|
+
<svg
|
|
91
|
+
viewBox="0 0 100 100"
|
|
92
|
+
preserveAspectRatio="none"
|
|
93
|
+
aria-hidden="true"
|
|
94
|
+
focusable="false"
|
|
95
|
+
>
|
|
96
|
+
{band && (
|
|
97
|
+
<rect
|
|
98
|
+
className="m-sparkline-band"
|
|
99
|
+
x="0"
|
|
100
|
+
width="100"
|
|
101
|
+
y={Math.min(y(band.min), y(band.max))}
|
|
102
|
+
height={Math.abs(y(band.min) - y(band.max))}
|
|
103
|
+
/>
|
|
104
|
+
)}
|
|
105
|
+
{area && (
|
|
106
|
+
<path className="m-sparkline-area" d={areaPath(points, 100)} />
|
|
107
|
+
)}
|
|
108
|
+
<path
|
|
109
|
+
className="m-sparkline-line"
|
|
110
|
+
d={linePath(points)}
|
|
111
|
+
vectorEffect="non-scaling-stroke"
|
|
112
|
+
/>
|
|
113
|
+
</svg>
|
|
114
|
+
{showLast && last && (
|
|
115
|
+
<span
|
|
116
|
+
className="m-sparkline-last"
|
|
117
|
+
style={{ left: `${last.x}%`, top: `${last.y}%` }}
|
|
118
|
+
aria-hidden="true"
|
|
119
|
+
/>
|
|
120
|
+
)}
|
|
121
|
+
</span>
|
|
122
|
+
</span>
|
|
123
|
+
);
|
|
124
|
+
}
|
package/src/tokens.css
CHANGED
|
@@ -90,6 +90,16 @@
|
|
|
90
90
|
--m-warning: #945700;
|
|
91
91
|
--m-danger: #c70014;
|
|
92
92
|
--m-info: #0060c7;
|
|
93
|
+
/* Chart series, in fixed order; validated for colour-blind separation on
|
|
94
|
+
the light and dark surfaces (docs/charts.md). Not for status. */
|
|
95
|
+
--m-chart-1: #2a78d6;
|
|
96
|
+
--m-chart-2: #eb6834;
|
|
97
|
+
--m-chart-3: #1baf7a;
|
|
98
|
+
--m-chart-4: #eda100;
|
|
99
|
+
--m-chart-5: #e87ba4;
|
|
100
|
+
--m-chart-6: #008300;
|
|
101
|
+
--m-chart-7: #6250d6;
|
|
102
|
+
--m-chart-8: #e34948;
|
|
93
103
|
--m-on-feedback: #ffffff;
|
|
94
104
|
--m-code-bg: #000000;
|
|
95
105
|
--m-code-line: rgb(255 255 255 / 0.12);
|
|
@@ -176,6 +186,14 @@
|
|
|
176
186
|
--m-warning: #ffd60a;
|
|
177
187
|
--m-danger: #ff6961;
|
|
178
188
|
--m-info: #5aa9ff;
|
|
189
|
+
--m-chart-1: #3987e5;
|
|
190
|
+
--m-chart-2: #d95926;
|
|
191
|
+
--m-chart-3: #199e70;
|
|
192
|
+
--m-chart-4: #c98500;
|
|
193
|
+
--m-chart-5: #d55181;
|
|
194
|
+
--m-chart-6: #0ca30c;
|
|
195
|
+
--m-chart-7: #9085e9;
|
|
196
|
+
--m-chart-8: #e66767;
|
|
179
197
|
--m-on-feedback: #000000;
|
|
180
198
|
--m-code-bg: #0e0e10;
|
|
181
199
|
--m-code-line: rgb(255 255 255 / 0.1);
|
|
@@ -261,6 +279,14 @@
|
|
|
261
279
|
--m-warning: #ffd60a;
|
|
262
280
|
--m-danger: #ff6961;
|
|
263
281
|
--m-info: #5aa9ff;
|
|
282
|
+
--m-chart-1: #3987e5;
|
|
283
|
+
--m-chart-2: #d95926;
|
|
284
|
+
--m-chart-3: #199e70;
|
|
285
|
+
--m-chart-4: #c98500;
|
|
286
|
+
--m-chart-5: #d55181;
|
|
287
|
+
--m-chart-6: #0ca30c;
|
|
288
|
+
--m-chart-7: #9085e9;
|
|
289
|
+
--m-chart-8: #e66767;
|
|
264
290
|
--m-on-feedback: #000000;
|
|
265
291
|
--m-code-bg: #0e0e10;
|
|
266
292
|
--m-code-line: rgb(255 255 255 / 0.1);
|