@n1kname/components 0.5.1 → 0.7.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/package.json +4 -3
- package/src/DotRows.astro +134 -0
- package/src/Legend.astro +14 -1
- package/src/dotrows.js +37 -0
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@n1kname/components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./*.astro": "./src/*.astro",
|
|
8
8
|
"./type.css": "./src/type.css",
|
|
9
9
|
"./icons": "./src/icons.ts",
|
|
10
|
-
"./datatable.js": "./src/datatable.js"
|
|
10
|
+
"./datatable.js": "./src/datatable.js",
|
|
11
|
+
"./dotrows.js": "./src/dotrows.js"
|
|
11
12
|
},
|
|
12
13
|
"dependencies": {
|
|
13
|
-
"@n1kname/charts": "0.
|
|
14
|
+
"@n1kname/charts": "0.3.0"
|
|
14
15
|
},
|
|
15
16
|
"peerDependencies": {
|
|
16
17
|
"astro": "^7.4.4"
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* One row per thing, a few marks on a shared scale: where each room or item sits, read
|
|
4
|
+
* across. Marks need no zero baseline, which is why this isn't a bar chart.
|
|
5
|
+
*
|
|
6
|
+
* The rows arrive at runtime: fill them with setDotRows from `@n1kname/components/dotrows.js`.
|
|
7
|
+
* `rows` is how many to hold room for until then, so nothing below moves when they come.
|
|
8
|
+
*/
|
|
9
|
+
interface Props {
|
|
10
|
+
id: string;
|
|
11
|
+
rows?: number;
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const { id, rows = 0, class: className, style, ...rest } = Astro.props;
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
<div id={id} class:list={['dot-rows', className]} style={[rows ? `--rows: ${rows}` : '', style ?? ''].filter(Boolean).join('; ') || undefined} {...rest}></div>
|
|
19
|
+
|
|
20
|
+
<style>
|
|
21
|
+
.dot-rows {
|
|
22
|
+
/* A row is 28px; the axis under them 20px. */
|
|
23
|
+
min-height: calc(var(--rows, 0) * 28px + 20px);
|
|
24
|
+
font-size: var(--text-caption);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.dot-rows :global(.row) {
|
|
28
|
+
display: grid;
|
|
29
|
+
grid-template-columns: 6.5rem minmax(0, 1fr);
|
|
30
|
+
align-items: center;
|
|
31
|
+
gap: 0 var(--sp-3);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@media (min-width: 640px) {
|
|
35
|
+
.dot-rows :global(.row) {
|
|
36
|
+
grid-template-columns: 10rem minmax(0, 1fr) 9rem;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.dot-rows :global(.name) {
|
|
41
|
+
padding-block: 6px;
|
|
42
|
+
line-height: 1.25;
|
|
43
|
+
color: var(--c-text);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.dot-rows :global(.tag) {
|
|
47
|
+
margin-left: var(--sp-2);
|
|
48
|
+
padding: 0 var(--sp-1);
|
|
49
|
+
border: 1px solid var(--c-border);
|
|
50
|
+
border-radius: var(--radius-sm);
|
|
51
|
+
font-size: 10px;
|
|
52
|
+
color: var(--c-text-muted);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.dot-rows :global(.track) {
|
|
56
|
+
position: relative;
|
|
57
|
+
height: 28px;
|
|
58
|
+
border-inline: 1px solid var(--c-chart-grid);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.dot-rows :global(.track i) {
|
|
62
|
+
position: absolute;
|
|
63
|
+
top: 50%;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.dot-rows :global(.range) {
|
|
67
|
+
height: 1px;
|
|
68
|
+
background: var(--c-border-strong);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.dot-rows :global(.rule) {
|
|
72
|
+
top: 0 !important;
|
|
73
|
+
bottom: 0;
|
|
74
|
+
width: 1px;
|
|
75
|
+
background: var(--c-text);
|
|
76
|
+
opacity: 0.6;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* A ring of the surface around each dot keeps overlapping dots apart. */
|
|
80
|
+
.dot-rows :global(.dot) {
|
|
81
|
+
width: 10px;
|
|
82
|
+
height: 10px;
|
|
83
|
+
border: 2px solid var(--dot);
|
|
84
|
+
border-radius: 50%;
|
|
85
|
+
background: var(--dot);
|
|
86
|
+
box-shadow: 0 0 0 2px var(--c-surface);
|
|
87
|
+
transform: translate(-50%, -50%);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.dot-rows :global(.dot.hollow) {
|
|
91
|
+
background: var(--c-surface);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.dot-rows :global(.right) {
|
|
95
|
+
display: none;
|
|
96
|
+
text-align: right;
|
|
97
|
+
font-variant-numeric: tabular-nums;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@media (min-width: 640px) {
|
|
101
|
+
.dot-rows :global(.right) {
|
|
102
|
+
display: block;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.dot-rows :global(.right .muted) {
|
|
107
|
+
margin-left: var(--sp-2);
|
|
108
|
+
color: var(--c-text-muted);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.dot-rows :global(.ticks) {
|
|
112
|
+
position: relative;
|
|
113
|
+
height: 20px;
|
|
114
|
+
font: 11px/20px var(--font-mono);
|
|
115
|
+
color: var(--c-text-muted);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.dot-rows :global(.ticks span) {
|
|
119
|
+
position: absolute;
|
|
120
|
+
top: 0;
|
|
121
|
+
transform: translateX(-50%);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.dot-rows :global(.ticks .line-label) {
|
|
125
|
+
font-weight: 600;
|
|
126
|
+
color: var(--c-text);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@media (max-width: 639px) {
|
|
130
|
+
.dot-rows :global(.ticks .crowded) {
|
|
131
|
+
display: none;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
</style>
|
package/src/Legend.astro
CHANGED
|
@@ -9,12 +9,14 @@
|
|
|
9
9
|
* hollow a ring, for a second kind of dot
|
|
10
10
|
* stripes diagonal stripes, for something known and set aside
|
|
11
11
|
* empty an outline only, for "nothing here"
|
|
12
|
+
* faint a paler swatch, for an estimate: no invoice or reading yet
|
|
13
|
+
* dashed paler still with a dashed edge, for a projection of something still running
|
|
12
14
|
*/
|
|
13
15
|
interface Key {
|
|
14
16
|
label: string;
|
|
15
17
|
/** Any CSS colour, best a chart token such as var(--c-chart-1). Not needed for `empty`. */
|
|
16
18
|
color?: string;
|
|
17
|
-
mark?: 'fill' | 'line' | 'dot' | 'hollow' | 'stripes' | 'empty';
|
|
19
|
+
mark?: 'fill' | 'line' | 'dot' | 'hollow' | 'stripes' | 'empty' | 'faint' | 'dashed';
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
interface Props {
|
|
@@ -97,4 +99,15 @@ const { keys, label = 'Legend', class: className, ...rest } = Astro.props;
|
|
|
97
99
|
.empty {
|
|
98
100
|
box-shadow: inset 0 0 0 1px var(--c-border-strong);
|
|
99
101
|
}
|
|
102
|
+
|
|
103
|
+
/* The same fades as a bar chart's unsettled rows, a little stronger so a small swatch still shows. */
|
|
104
|
+
.faint {
|
|
105
|
+
background: color-mix(in oklab, var(--mark) 65%, transparent);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.dashed {
|
|
109
|
+
background: color-mix(in oklab, var(--mark) 37%, transparent);
|
|
110
|
+
outline: 1px dashed var(--mark);
|
|
111
|
+
outline-offset: -1px;
|
|
112
|
+
}
|
|
100
113
|
</style>
|
package/src/dotrows.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Fills a DotRows after the page has loaded, for data that arrives at runtime.
|
|
2
|
+
//
|
|
3
|
+
// Each row is { name, tag?, title, dots, right? }. `dots` are { v, color, hollow? }, drawn in
|
|
4
|
+
// order, so put the subject last: it lands on top. `title` says every value in words; it is
|
|
5
|
+
// what a screen reader hears for the row's marks. `right` is HTML, written as is, so escape
|
|
6
|
+
// anything that came from outside.
|
|
7
|
+
//
|
|
8
|
+
// The scale is [from, to]; values outside it sit at its edge. `ticks` are values on the
|
|
9
|
+
// axis, `crowded` the ones a phone leaves out, and `line` a value every row is read against,
|
|
10
|
+
// { v, label }, drawn across the rows with its label on the axis.
|
|
11
|
+
import { esc } from './datatable.js';
|
|
12
|
+
|
|
13
|
+
export const setDotRows = (box, { rows, scale, ticks, format = String, crowded = [], line }) => {
|
|
14
|
+
const at = (v) => `${((Math.max(scale[0], Math.min(scale[1], v)) - scale[0]) / (scale[1] - scale[0])) * 100}%`;
|
|
15
|
+
const rule = line ? `<i class="rule" style="left: ${at(line.v)}"></i>` : '';
|
|
16
|
+
box.innerHTML =
|
|
17
|
+
rows
|
|
18
|
+
.map((r) => {
|
|
19
|
+
const vs = r.dots.map((d) => d.v);
|
|
20
|
+
const [lo, hi] = [Math.min(...vs), Math.max(...vs)];
|
|
21
|
+
return (
|
|
22
|
+
'<div class="row">' +
|
|
23
|
+
`<div class="name">${esc(r.name)}${r.tag ? `<span class="tag">${esc(r.tag)}</span>` : ''}</div>` +
|
|
24
|
+
`<div class="track" role="img" aria-label="${esc(r.title)}" title="${esc(r.title)}">${rule}` +
|
|
25
|
+
`<i class="range" style="left: ${at(lo)}; width: calc(${at(hi)} - ${at(lo)})"></i>` +
|
|
26
|
+
r.dots.map((d) => `<i class="dot${d.hollow ? ' hollow' : ''}" style="left: ${at(d.v)}; --dot: ${d.color}"></i>`).join('') +
|
|
27
|
+
'</div>' +
|
|
28
|
+
`<div class="right">${r.right ?? ''}</div>` +
|
|
29
|
+
'</div>'
|
|
30
|
+
);
|
|
31
|
+
})
|
|
32
|
+
.join('') +
|
|
33
|
+
'<div class="row axis" aria-hidden="true"><div></div><div class="ticks">' +
|
|
34
|
+
ticks.map((v) => `<span${crowded.includes(v) ? ' class="crowded"' : ''} style="left: ${at(v)}">${esc(format(v))}</span>`).join('') +
|
|
35
|
+
(line ? `<span class="line-label" style="left: ${at(line.v)}">${esc(line.label)}</span>` : '') +
|
|
36
|
+
'</div></div>';
|
|
37
|
+
};
|