@seikika/astro-report 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.
@@ -0,0 +1,294 @@
1
+ import type { ReportViews } from "../report-view";
2
+ import type { Summary } from "../lib/summary";
3
+ import type { ReportData } from "../types";
4
+ import { badge, levelLegend, medal } from "../lib/bars";
5
+ import { lockIcon, refs } from "../lib/basis";
6
+ import { levelName, moverBits, nextMedal, nextMedalEl, verifiedMover } from "../lib/campaigns";
7
+ import { el, enc, link } from "../lib/dom";
8
+ import { LEVEL_DEF, ONLY_LEVEL } from "../lib/levels";
9
+ import { bothCounts, capsRepo, isTop, ring, tallyRing, tallyShort, tallyWords, title } from "../lib/rings";
10
+ import { trackPath } from "../lib/routes";
11
+ import { LADDER, rankLevel } from "../lib/rules";
12
+ import { ringWhy, ringWords, shortWhy, trackSlots } from "../lib/status";
13
+ import { prose, rich } from "../lib/text";
14
+ import { furthestTrack, standingChip, trackColor, trackKey, trackStats, tracksSorted } from "../lib/tracks";
15
+ import { firstSentence, plural } from "../lib/words";
16
+
17
+ // The ring is a share at the top level; entities still at none are the other half of the story.
18
+ function atNone(t) {
19
+ // One entity on several scorecards counts once. The row sum stays visible, because the cards below still add to it.
20
+ var n = t.none || 0;
21
+ if (!n) return "";
22
+ var rows = t.noneRows || 0;
23
+ var both = rows > n ? ", on " + plural(rows, "scorecard row", "scorecard rows") : "";
24
+ return "; " + plural(n, "entity", "entities") + " still at none" + both;
25
+ }
26
+
27
+ export const tracksViews = {
28
+ trackCard(D: ReportData, S: Summary, t, flag) {
29
+ var def = t.def;
30
+ var color = trackColor(t);
31
+ var lead: ReturnType<typeof verifiedMover> = null;
32
+ var kids = [
33
+ flag ? el("span", { className: "flag", textContent: flag }) : null,
34
+ el(
35
+ "div",
36
+ { className: "th" },
37
+ t.compare ? tallyRing(t.verdicts, t.rows.length, 60) : ring(t.pct, { size: 60, color: color, label: t.pct == null ? "not scored" : t.pct + "% at the top level" }),
38
+ el("div", {}, el("div", { className: "tt", textContent: def.title || t.name }), el("div", { className: "sub", textContent: t.compare ? "factors ahead, a segment per factor" : (t.averaged > 1 ? ringWords(t) : "of entities at the top level") + atNone(t) })),
39
+ ),
40
+ def.description ? el("div", { className: "td", textContent: prose(firstSentence(def.description)) }) : null,
41
+ ];
42
+ var slots = !t.compare && trackSlots(D, t);
43
+ if (slots) kids.push(slots);
44
+ if (slots && t.capped.length) kids.push(el("div", { className: "capnote tcap" }, lockIcon(), " " + ringWhy(D, t)));
45
+ if (slots && t.short.length) kids.push(el("div", { className: "capnote tcap" }, lockIcon(), " " + shortWhy(D, t) + "."));
46
+ if (t.compare) {
47
+ kids.push(
48
+ bothCounts(t.verdicts, t.rows.length) ||
49
+ el(
50
+ "div",
51
+ { className: "chips" },
52
+ ...["ahead", "parity", "behind", "unknown"]
53
+ .filter(function (v) {
54
+ return t.verdicts[v];
55
+ })
56
+ .map(function (v) {
57
+ return standingChip(v, t.verdicts[v] + " " + v);
58
+ }),
59
+ ),
60
+ );
61
+ } else if (t.cards.length) {
62
+ var shelf = {};
63
+ var shelfTop = {};
64
+ var shelfOrder: any[] = [];
65
+ t.cards.forEach(function (c) {
66
+ var l = c.floor || "not scored";
67
+ if (!shelf[l]) {
68
+ shelf[l] = 0;
69
+ shelfTop[l] = 0;
70
+ shelfOrder.push(l);
71
+ }
72
+ shelf[l]++;
73
+ if (c.floor && isTop(D, c.row.name, c.floor)) shelfTop[l]++;
74
+ });
75
+ shelfOrder.sort(function (a, b) {
76
+ return rankLevel(a === "not scored" ? null : a) - rankLevel(b === "not scored" ? null : b);
77
+ });
78
+ kids.push(
79
+ el(
80
+ "div",
81
+ { className: "shelf", role: "img", ariaLabel: "Scorecards by their weakest entity's level: " + shelfOrder.map(function (l) { return shelf[l] + " " + l + (shelfTop[l] && shelfTop[l] < shelf[l] ? ", " + shelfTop[l] + " of them at its top level" : shelfTop[l] ? ", at its top level" : ""); }).join("; ") },
82
+ el("span", { className: "sub", textContent: "Scorecards by medal:" }),
83
+ ...shelfOrder.map(function (l) {
84
+ var own = ONLY_LEVEL.has(l) && LADDER.indexOf(l) < 0;
85
+ var owner = own
86
+ ? t.cards.find(function (c) {
87
+ return c.floor === l;
88
+ })
89
+ : null;
90
+ var gloss: HTMLElement | null = null;
91
+ if (own) {
92
+ var def = "The one level " + (owner ? title(D, owner.row.name) : "its scorecard") + " has, so reaching it is the top." + (LEVEL_DEF[l] ? " " + LEVEL_DEF[l] : "");
93
+ var abbr = el("abbr", { className: "gloss", tabIndex: 0 }, levelName(l), el("span", { className: "sr", textContent: " (" + def + ")" }));
94
+ abbr.dataset.tip = def;
95
+ gloss = abbr;
96
+ }
97
+ return el("span", { className: "sh" + (own ? " own" : "") }, medal(l, 20), el("b", { textContent: String(shelf[l]) }), " ", gloss || (l === "none" ? "with no medal yet" : levelName(l)), (own ? " ✓ top" : shelfTop[l] === shelf[l] || ONLY_LEVEL.has(l) ? " ✓ top" : shelfTop[l] ? " (" + shelfTop[l] + " ✓ top)" : ""));
98
+ }),
99
+ ),
100
+ );
101
+ var nm = nextMedal(D, t.cards);
102
+ lead = verifiedMover(D, t.cards);
103
+ var wk = t.cards[0] && t.cards[0].floor && !isTop(D, t.cards[0].row.name, t.cards[0].floor) ? t.cards[0] : null;
104
+ // The card's first fix is the same step the overview ranks first. The lowest medal is named on its own,
105
+ // so a zero-point lift is not offered as the next thing to do.
106
+ if (lead) kids.push(el("div", { className: "tnext" }, el("b", { textContent: "Next: " }), ...moverBits(D, lead)));
107
+ if (wk && (!lead || lead.r.name !== wk.row.name)) kids.push(el("div", { className: "tnext" }, el("b", { textContent: "Lowest level: " }), link("scorecard/" + enc(wk.row.name), "", title(D, wk.row.name)), " at ", badge(wk.floor), lead ? ". Lifting it adds no points until those entities reach its top level." : ""));
108
+ if (!lead)
109
+ kids.push(
110
+ nm
111
+ ? el("div", { className: "tnext" }, el("b", { textContent: "Next medal: " }), link("scorecard/" + enc(nm.name), "", title(D, nm.name)), wk && nm.name === wk.row.name ? el("span", {}, " at ", badge(wk.floor), " → " + nm.up) : " to " + nm.up, " · " + plural(nm.low, "entity", "entities") + " to lift")
112
+ : el("div", { className: "tnext good", textContent: "✓ Every scorecard is at its top level" }),
113
+ );
114
+ }
115
+ var weakest = !t.compare && t.cards[0] && t.cards[0].floor ? title(D, t.cards[0].row.name) + " at " + t.cards[0].floor + (capsRepo(D, t.cards[0].row.name, t.cards[0].floor) ? ", its top level, which caps the repository" : isTop(D, t.cards[0].row.name, t.cards[0].floor) ? ", its top level" : "") : null;
116
+ kids.push(
117
+ el(
118
+ "div",
119
+ { className: "foot" },
120
+ el("span", { textContent: plural(t.rows.length, t.compare ? "factor" : "scorecard") + (t.campaigns.length ? " · " + plural(t.campaigns.length, "campaign") : "") }),
121
+ t.compare ? el("span", { textContent: t.behind.length ? "behind on " + t.behind.join(", ") : t.verdicts.unknown >= t.rows.length ? "not measured yet" : t.verdicts.unknown ? "not behind on any measured factor" : "never behind" }) : null,
122
+ ),
123
+ );
124
+ var tl = (kids[1] as HTMLElement).lastChild!.firstChild as HTMLElement;
125
+ var tlink = link(trackPath(D, t.name), "tlink", def.title || t.name);
126
+ tl.replaceChildren(tlink);
127
+ var a = el("div", { className: "track" }, ...kids);
128
+ a.style.setProperty("--tc", color);
129
+ var standing = t.compare ? tallyWords(t.verdicts, t.rows.length) : t.pct == null ? "not scored" : (t.averaged > 1 ? t.pct + "% " + ringWords(t) : t.pct + "% of entities at the top level") + (t.capped.length ? ". " + ringWhy(D, t) : "");
130
+ var leadWords = lead ? ". Next: " + title(D, lead.r.name) : "";
131
+ tlink.setAttribute("aria-label", (def.title || t.name) + ": " + standing + (flag ? ". " + flag : "") + leadWords + (weakest ? ". Lowest level: " + weakest : ""));
132
+ return a;
133
+ },
134
+
135
+ trackGrid(D: ReportData, S: Summary, shown) {
136
+ var self = this;
137
+ var furthest = furthestTrack(D, S);
138
+ return el(
139
+ "div",
140
+ { className: "tracks" },
141
+ ...shown.map(function (t) {
142
+ return self.trackCard(D, S, t, t.name === furthest ? "Furthest from goal" : null);
143
+ }),
144
+ );
145
+ },
146
+
147
+ tracks(D: ReportData, S: Summary, name) {
148
+ if (name) return this.track(D, S, name);
149
+ var all = tracksSorted(D, S);
150
+ if (!all.length) return el("section", {}, el("div", { className: "empty", textContent: "This portal declares no tracks." }));
151
+ var loose = S.rows.filter(function (r) {
152
+ return !r.sc.track || !(D.tracks || {})[r.sc.track];
153
+ });
154
+ return el(
155
+ "div",
156
+ {},
157
+ el(
158
+ "section",
159
+ {},
160
+ el("div", { className: "head" }, el("h2", { textContent: "Tracks" }), el("span", { className: "sub", textContent: "Lowest share at the top level first" })),
161
+ el("p", { className: "lede", textContent: "A track is a long-running line of work: the scorecards that measure it and the campaigns that push on it. Its goal is every entity at the top level." }),
162
+ trackKey(all),
163
+ this.trackGrid(
164
+ D,
165
+ S,
166
+ all.filter(function (t) {
167
+ return !t.compare;
168
+ }),
169
+ ),
170
+ ),
171
+ all.some(function (t) {
172
+ return t.compare;
173
+ })
174
+ ? el(
175
+ "section",
176
+ {},
177
+ el("div", { className: "head" }, el("h2", { textContent: "Measured against a rival" })),
178
+ el("p", { className: "lede", textContent: "Its ring counts the factors where the product leads its rival, so it stands outside the order above." }),
179
+ this.trackGrid(
180
+ D,
181
+ S,
182
+ all.filter(function (t) {
183
+ return t.compare;
184
+ }),
185
+ ),
186
+ )
187
+ : null,
188
+ loose.length
189
+ ? el(
190
+ "section",
191
+ {},
192
+ el("div", { className: "head" }, el("h2", { textContent: "Not on a track" })),
193
+ levelLegend(D, loose),
194
+ this.scorecardTable(D, loose),
195
+ )
196
+ : null,
197
+ );
198
+ },
199
+
200
+ track(D: ReportData, S: Summary, name) {
201
+ var t = trackStats(D, S, name);
202
+ var def = t.def;
203
+ var self = this;
204
+ var color = trackColor(t);
205
+ var owner = def.owner ? def.owner.replace(/^group:/, "") : "";
206
+ var weakest = t.cards[0];
207
+ var goal = t.compare
208
+ ? el("div", {}, el("p", {}, el("b", { textContent: tallyShort(t.verdicts, t.rows.length).replace(/^a/, "A") + ". " }), link("compare", "", "Open the comparison →")), bothCounts(t.verdicts, t.rows.length))
209
+ : el(
210
+ "p",
211
+ {},
212
+ el("b", { textContent: "Goal: every entity at the top level of each scorecard below. " }),
213
+ t.pct == null ? "Nothing is scored yet." : "On average " + t.pct + "% are there" + (t.none ? "; " + plural(t.none, "entity is", "entities are") + " still at none" + (t.noneRows > t.none ? ", on " + plural(t.noneRows, "scorecard row", "scorecard rows") : "") : "") + "." + (t.capped.length ? " " + ringWhy(D, t) + "." : "") + (t.short.length ? " " + shortWhy(D, t) + "." : ""),
214
+ weakest && weakest.floor ? el("span", {}, " The weakest scorecard is ", link("scorecard/" + enc(weakest.row.name), "", title(D, weakest.row.name)), ", at ", badge(weakest.floor), capsRepo(D, weakest.row.name, weakest.floor) ? ", its only top level, so it caps the repository there until it gains a higher one." : isTop(D, weakest.row.name, weakest.floor) ? ", already its top level." : ".") : null,
215
+ );
216
+ var trackNext = t.compare ? null : nextMedalEl(D, t.cards);
217
+ var section = el(
218
+ "section",
219
+ {},
220
+ el("nav", { className: "crumb", ariaLabel: "Breadcrumb" }, link("tracks", "", "Tracks"), " / " + (def.title || name)),
221
+ el(
222
+ "div",
223
+ { className: "ehead" },
224
+ el("div", {}, el("h2", { textContent: def.title || name, tabIndex: -1 }), el("div", { className: "sub", textContent: [owner ? "owned by " + owner : null, plural(t.rows.length, t.compare ? "factor" : "scorecard"), t.campaigns.length ? plural(t.campaigns.length, "campaign") : null].filter(Boolean).join(" · ") })),
225
+ t.compare ? tallyRing(t.verdicts, t.rows.length, 88) : ring(t.pct, { size: 88, color: color, label: t.pct == null ? "not scored" : t.pct + "% at the top level" }),
226
+ ),
227
+ def.description ? el("p", { className: "lede", style: "max-width:80ch" }, ...rich(def.description)) : null,
228
+ refs(def.links),
229
+ goal,
230
+ trackNext ? el("div", { style: "max-width:80ch;margin-top:8px" }, trackNext) : null,
231
+ );
232
+ section.dataset.focus = "";
233
+ var parts = [section];
234
+ if (t.compare) {
235
+ parts.push(el("section", {}, el("div", { className: "head" }, el("h2", { textContent: "Factors" })), this.factorCards(D, t.rows.map(function (r) {
236
+ return r.name;
237
+ }))));
238
+ } else if (t.rows.length) {
239
+ var rows = t.cards.map(function (c) {
240
+ return c.row;
241
+ });
242
+ parts.push(
243
+ el(
244
+ "section",
245
+ {},
246
+ el("div", { className: "head" }, el("h2", { textContent: "Scorecards" }), el("span", { className: "sub", textContent: "Lowest level first" })),
247
+ levelLegend(D, rows),
248
+ this.scorecardTable(D, rows, true),
249
+ ),
250
+ );
251
+ }
252
+ if (t.campaigns.length) {
253
+ parts.push(
254
+ el(
255
+ "section",
256
+ {},
257
+ el("div", { className: "head" }, el("h2", { textContent: "Campaigns on this track" }), el("span", { className: "sub", textContent: "Time-bound pushes toward the goal" })),
258
+ el(
259
+ "div",
260
+ { className: "cards" },
261
+ ...t.campaigns.map(function (n) {
262
+ return self.campaignCard(D, n);
263
+ }),
264
+ ),
265
+ ),
266
+ );
267
+ }
268
+ var others = tracksSorted(D, S).filter(function (o) {
269
+ return o.name !== name;
270
+ });
271
+ if (others.length) parts.push(this.trackStrip(D, S, others, "Other tracks"));
272
+ return el("div", {}, ...parts);
273
+ },
274
+
275
+ // Tracks as a row of small rings; `lead` drops the separator and names each standing.
276
+ trackStrip(D: ReportData, S: Summary, shown, label, lead?) {
277
+ var furthest = furthestTrack(D, S);
278
+ return el(
279
+ "nav",
280
+ { className: "trackstrip" + (lead ? " lead" : ""), ariaLabel: label },
281
+ lead ? null : el("span", { className: "sub", textContent: label }),
282
+ ...shown.map(function (o) {
283
+ var standing = o.compare ? tallyWords(o.verdicts, o.rows.length) : o.pct == null ? "not scored" : o.pct + "% at the top level";
284
+ var flag = lead && o.name === furthest;
285
+ var a = link(trackPath(D, o.name), flag ? "far" : "", [
286
+ o.compare ? tallyRing(o.verdicts, o.rows.length, 30, true) : ring(o.pct, { size: 30, color: trackColor(o), label: standing, bare: true }),
287
+ el("span", {}, el("span", { textContent: o.def.title || o.name }), lead ? el("small", { textContent: (o.compare ? tallyShort(o.verdicts, o.rows.length) : o.pct == null ? "not scored" : o.pct + "%") + (flag ? " · furthest from goal" : "") }) : el("span", { className: "sr", textContent: ": " + standing })),
288
+ ]);
289
+ a.title = standing + (o.capped && o.capped.length ? ". " + ringWhy(D, o) : "");
290
+ return a;
291
+ }),
292
+ );
293
+ },
294
+ } satisfies ThisType<ReportViews>;