analysis-workflow-viewer 0.1.0__py3-none-any.whl
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.
- analysis_workflow_viewer/__init__.py +9 -0
- analysis_workflow_viewer/about.py +101 -0
- analysis_workflow_viewer/cli.py +39 -0
- analysis_workflow_viewer/repo.py +262 -0
- analysis_workflow_viewer/server.py +83 -0
- analysis_workflow_viewer/static/app.js +935 -0
- analysis_workflow_viewer/static/index.html +36 -0
- analysis_workflow_viewer/static/style.css +366 -0
- analysis_workflow_viewer/static/vendor/cytoscape.LICENSE +19 -0
- analysis_workflow_viewer/static/vendor/cytoscape.min.js +32 -0
- analysis_workflow_viewer/static/vendor/dagre.LICENSE +19 -0
- analysis_workflow_viewer/static/vendor/dagre.min.js +3809 -0
- analysis_workflow_viewer-0.1.0.dist-info/METADATA +93 -0
- analysis_workflow_viewer-0.1.0.dist-info/RECORD +17 -0
- analysis_workflow_viewer-0.1.0.dist-info/WHEEL +4 -0
- analysis_workflow_viewer-0.1.0.dist-info/entry_points.txt +2 -0
- analysis_workflow_viewer-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,935 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// The page: the graph of the tasks a clicked artifact rests on, a file explorer beside it (resizable, collapsible),
|
|
4
|
+
// and a card over the graph with what is clicked. Everything leads with what matters and folds the rest away; a
|
|
5
|
+
// colour is explained by its swatch, where and when it is needed. The artifact traced is in the address
|
|
6
|
+
// (#path=...&key=...), so a view can be shared with someone on the same server.
|
|
7
|
+
|
|
8
|
+
const $ = (selector) => document.querySelector(selector);
|
|
9
|
+
let cy = null;
|
|
10
|
+
let repo = { github: null };
|
|
11
|
+
const opened = new Set(); // what is open in the explorer, kept when the repo is read again
|
|
12
|
+
|
|
13
|
+
async function api(route, params = {}) {
|
|
14
|
+
const response = await fetch(`${route}?${new URLSearchParams(params)}`);
|
|
15
|
+
const body = await response.json();
|
|
16
|
+
if (!response.ok) throw new Error(body.error || response.statusText);
|
|
17
|
+
return body;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function el(tag, props = {}, ...children) {
|
|
21
|
+
const node = Object.assign(document.createElement(tag), props);
|
|
22
|
+
for (const child of children.flat(Infinity)) {
|
|
23
|
+
if (child !== null && child !== undefined && child !== false)
|
|
24
|
+
node.append(child);
|
|
25
|
+
}
|
|
26
|
+
return node;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const baseName = (path) => path.split("/").filter(Boolean).pop() || path;
|
|
30
|
+
const plural = (n, word) =>
|
|
31
|
+
`${n.toLocaleString("en")} ${n === 1 ? word : word.replace(/([^aeiou])y$/, "$1ie")}${n === 1 ? "" : "s"}`;
|
|
32
|
+
|
|
33
|
+
// Remembered per browser: whether the explorer is open, and its width. Storage may be unavailable.
|
|
34
|
+
function remember(name, value) {
|
|
35
|
+
try {
|
|
36
|
+
localStorage.setItem(`viewer.${name}`, value);
|
|
37
|
+
} catch {}
|
|
38
|
+
}
|
|
39
|
+
function recall(name) {
|
|
40
|
+
try {
|
|
41
|
+
return localStorage.getItem(`viewer.${name}`);
|
|
42
|
+
} catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// The one way a colour is explained: its swatch, then what it means.
|
|
48
|
+
function swatch(kind, meaning) {
|
|
49
|
+
return el(
|
|
50
|
+
"span",
|
|
51
|
+
{ className: "swatched" },
|
|
52
|
+
el("i", { className: `swatch ${kind}` }),
|
|
53
|
+
meaning,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// A README's sentence, with its links, code and bold shown as such; #12 links to the repo's issue on GitHub.
|
|
58
|
+
|
|
59
|
+
const INLINE =
|
|
60
|
+
/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)|`([^`]+)`|\*\*([^*]+)\*\*|(https?:\/\/[^\s)]+)|(^|[\s(])#(\d+)\b/g;
|
|
61
|
+
|
|
62
|
+
function link(href, text) {
|
|
63
|
+
return el("a", {
|
|
64
|
+
href,
|
|
65
|
+
target: "_blank",
|
|
66
|
+
rel: "noopener",
|
|
67
|
+
textContent: text,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function inline(text) {
|
|
72
|
+
const parts = [];
|
|
73
|
+
let last = 0;
|
|
74
|
+
for (const m of text.matchAll(INLINE)) {
|
|
75
|
+
parts.push(text.slice(last, m.index));
|
|
76
|
+
const [, label, url, code, bold, bare, before, issue] = m;
|
|
77
|
+
if (url) parts.push(link(url, label));
|
|
78
|
+
else if (code) parts.push(el("code", { textContent: code }));
|
|
79
|
+
else if (bold) parts.push(el("strong", { textContent: bold }));
|
|
80
|
+
else if (bare) parts.push(link(bare, bare));
|
|
81
|
+
else if (issue)
|
|
82
|
+
parts.push(
|
|
83
|
+
before,
|
|
84
|
+
repo.github
|
|
85
|
+
? link(`${repo.github}/issues/${issue}`, `#${issue}`)
|
|
86
|
+
: `#${issue}`,
|
|
87
|
+
);
|
|
88
|
+
last = m.index + m[0].length;
|
|
89
|
+
}
|
|
90
|
+
parts.push(text.slice(last));
|
|
91
|
+
return parts;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Something folded away: a summary line, opened on a click. ``onOpen`` fills it the first time it opens.
|
|
95
|
+
function fold(summary, content, onOpen = null) {
|
|
96
|
+
const body = el("div", { className: "folded" }, content);
|
|
97
|
+
const details = el("details", {}, el("summary", {}, summary), body);
|
|
98
|
+
if (onOpen) {
|
|
99
|
+
details.addEventListener("toggle", function first() {
|
|
100
|
+
if (!details.open) return;
|
|
101
|
+
details.removeEventListener("toggle", first);
|
|
102
|
+
onOpen(body);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return details;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// What an artifact is, in a few words: "sparse matrix (CSR) · 91,195 × 38,606 · float32".
|
|
109
|
+
|
|
110
|
+
function bytes(n) {
|
|
111
|
+
const units = ["B", "KB", "MB", "GB", "TB"];
|
|
112
|
+
let i = 0;
|
|
113
|
+
while (n >= 1024 && i < units.length - 1) {
|
|
114
|
+
n /= 1024;
|
|
115
|
+
i += 1;
|
|
116
|
+
}
|
|
117
|
+
return `${n.toFixed(i ? 1 : 0)} ${units[i]}`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function shape(dims) {
|
|
121
|
+
return dims.map((n) => n.toLocaleString("en")).join(" × ");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function summarise(about) {
|
|
125
|
+
const parts = [about.kind];
|
|
126
|
+
if (about.shape)
|
|
127
|
+
parts.push(
|
|
128
|
+
about.shape.length === 1
|
|
129
|
+
? plural(about.shape[0], "value")
|
|
130
|
+
: shape(about.shape),
|
|
131
|
+
);
|
|
132
|
+
if (about.dtype) parts.push(about.dtype);
|
|
133
|
+
if (about.categories !== undefined)
|
|
134
|
+
parts.push(plural(about.categories, "category"));
|
|
135
|
+
if (about.columns !== undefined)
|
|
136
|
+
parts.push(plural(about.columns, "column"));
|
|
137
|
+
if (about.bytes !== undefined) parts.push(bytes(about.bytes));
|
|
138
|
+
if (about.entries !== undefined) parts.push(plural(about.entries, "entry"));
|
|
139
|
+
if (about.elements)
|
|
140
|
+
parts.push(
|
|
141
|
+
Object.entries(about.elements)
|
|
142
|
+
.map(([kind, n]) => `${n} ${kind}`)
|
|
143
|
+
.join(", "),
|
|
144
|
+
);
|
|
145
|
+
return parts.join(" · ");
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// The bar
|
|
149
|
+
|
|
150
|
+
async function showRepo() {
|
|
151
|
+
repo = await api("/api/repo");
|
|
152
|
+
$("#repo").textContent = repo.name;
|
|
153
|
+
$("#branch").textContent =
|
|
154
|
+
repo.worktree && repo.branch ? `on ${repo.branch}` : "";
|
|
155
|
+
document.title = `${repo.name} · lineage`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function setTitle(name, ...notes) {
|
|
159
|
+
$("#title").replaceChildren(
|
|
160
|
+
el("strong", { textContent: name }),
|
|
161
|
+
...notes
|
|
162
|
+
.filter(Boolean)
|
|
163
|
+
.map((note) =>
|
|
164
|
+
el("span", { className: "muted", textContent: ` · ${note}` }),
|
|
165
|
+
),
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Layout: the explorer can be hidden and resized; the graph takes the rest.
|
|
170
|
+
|
|
171
|
+
function setExplorer(open) {
|
|
172
|
+
document.body.classList.toggle("collapsed", !open);
|
|
173
|
+
$("#toggle").setAttribute("aria-expanded", String(open));
|
|
174
|
+
remember("explorer", open ? "open" : "closed");
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function layoutControls() {
|
|
178
|
+
const width = recall("width");
|
|
179
|
+
if (width) document.documentElement.style.setProperty("--nav-width", width);
|
|
180
|
+
setExplorer(recall("explorer") !== "closed");
|
|
181
|
+
$("#toggle").addEventListener("click", () =>
|
|
182
|
+
setExplorer(document.body.classList.contains("collapsed")),
|
|
183
|
+
);
|
|
184
|
+
$("#refresh").addEventListener("click", refresh);
|
|
185
|
+
$("#resizer").addEventListener("pointerdown", (event) => {
|
|
186
|
+
event.preventDefault();
|
|
187
|
+
document.body.classList.add("resizing");
|
|
188
|
+
const move = (e) => {
|
|
189
|
+
const px = `${Math.max(160, Math.min(e.clientX, window.innerWidth * 0.7))}px`;
|
|
190
|
+
document.documentElement.style.setProperty("--nav-width", px);
|
|
191
|
+
};
|
|
192
|
+
const stop = () => {
|
|
193
|
+
document.body.classList.remove("resizing");
|
|
194
|
+
remember(
|
|
195
|
+
"width",
|
|
196
|
+
getComputedStyle(document.documentElement)
|
|
197
|
+
.getPropertyValue("--nav-width")
|
|
198
|
+
.trim(),
|
|
199
|
+
);
|
|
200
|
+
window.removeEventListener("pointermove", move);
|
|
201
|
+
window.removeEventListener("pointerup", stop);
|
|
202
|
+
};
|
|
203
|
+
window.addEventListener("pointermove", move);
|
|
204
|
+
window.addEventListener("pointerup", stop);
|
|
205
|
+
});
|
|
206
|
+
// Whenever the graph's area changes size, the graph is fitted to it again.
|
|
207
|
+
new ResizeObserver(() => {
|
|
208
|
+
cy?.resize();
|
|
209
|
+
cy?.fit(undefined, 40);
|
|
210
|
+
}).observe($("#graph"));
|
|
211
|
+
$("#close").addEventListener("click", closeCard);
|
|
212
|
+
document.addEventListener("keydown", (event) => {
|
|
213
|
+
if (event.key === "Escape") closeCard();
|
|
214
|
+
});
|
|
215
|
+
$("#colour-key").append(
|
|
216
|
+
swatch("traceable", "traceable"),
|
|
217
|
+
swatch("empty", "not traceable"),
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// The card over the graph
|
|
222
|
+
|
|
223
|
+
function openCard(...content) {
|
|
224
|
+
$("#card").replaceChildren(el("div", {}, content));
|
|
225
|
+
$("#details").hidden = false;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// A card is moved by its heading line and resized at its corner; where and how large it was is remembered.
|
|
229
|
+
function cardControls() {
|
|
230
|
+
const card = $("#details");
|
|
231
|
+
const placed = recall("card");
|
|
232
|
+
if (placed) Object.assign(card.style, JSON.parse(placed));
|
|
233
|
+
const save = () =>
|
|
234
|
+
remember(
|
|
235
|
+
"card",
|
|
236
|
+
JSON.stringify({
|
|
237
|
+
left: card.style.left,
|
|
238
|
+
top: card.style.top,
|
|
239
|
+
right: card.style.right,
|
|
240
|
+
width: card.style.width,
|
|
241
|
+
height: card.style.height,
|
|
242
|
+
}),
|
|
243
|
+
);
|
|
244
|
+
card.addEventListener("pointerdown", (event) => {
|
|
245
|
+
if (!event.target.closest(".kicker")) return;
|
|
246
|
+
event.preventDefault();
|
|
247
|
+
const area = card.parentElement.getBoundingClientRect();
|
|
248
|
+
const box = card.getBoundingClientRect();
|
|
249
|
+
const dx = event.clientX - box.left;
|
|
250
|
+
const dy = event.clientY - box.top;
|
|
251
|
+
const move = (e) => {
|
|
252
|
+
const left = Math.max(
|
|
253
|
+
0,
|
|
254
|
+
Math.min(e.clientX - dx - area.left, area.width - box.width),
|
|
255
|
+
);
|
|
256
|
+
const top = Math.max(
|
|
257
|
+
0,
|
|
258
|
+
Math.min(e.clientY - dy - area.top, area.height - 40),
|
|
259
|
+
);
|
|
260
|
+
Object.assign(card.style, {
|
|
261
|
+
left: `${left}px`,
|
|
262
|
+
top: `${top}px`,
|
|
263
|
+
right: "auto",
|
|
264
|
+
});
|
|
265
|
+
};
|
|
266
|
+
const stop = () => {
|
|
267
|
+
window.removeEventListener("pointermove", move);
|
|
268
|
+
window.removeEventListener("pointerup", stop);
|
|
269
|
+
save();
|
|
270
|
+
};
|
|
271
|
+
window.addEventListener("pointermove", move);
|
|
272
|
+
window.addEventListener("pointerup", stop);
|
|
273
|
+
});
|
|
274
|
+
// The browser's own resize handle sets the size; keep it.
|
|
275
|
+
new ResizeObserver(() => {
|
|
276
|
+
if (!card.hidden && (card.style.width || card.style.height)) save();
|
|
277
|
+
}).observe(card);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function closeCard() {
|
|
281
|
+
$("#details").hidden = true;
|
|
282
|
+
cy?.elements().unselect();
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Explorer: blue is traceable; grey is a file with nothing to trace, or a folder that holds none.
|
|
286
|
+
|
|
287
|
+
function row(
|
|
288
|
+
label,
|
|
289
|
+
{
|
|
290
|
+
id = null,
|
|
291
|
+
kind = "file",
|
|
292
|
+
traceable = false,
|
|
293
|
+
empty = false,
|
|
294
|
+
onOpen = null,
|
|
295
|
+
onTrace = null,
|
|
296
|
+
} = {},
|
|
297
|
+
) {
|
|
298
|
+
const twist = el("span", {
|
|
299
|
+
className: "twist",
|
|
300
|
+
textContent: onOpen ? "▸" : "",
|
|
301
|
+
});
|
|
302
|
+
const text = el("span", {
|
|
303
|
+
className: "label",
|
|
304
|
+
textContent: label,
|
|
305
|
+
title: label,
|
|
306
|
+
});
|
|
307
|
+
const classes = ["row", kind, traceable && "traceable", empty && "empty"]
|
|
308
|
+
.filter(Boolean)
|
|
309
|
+
.join(" ");
|
|
310
|
+
const item = el(
|
|
311
|
+
"li",
|
|
312
|
+
{ role: "treeitem" },
|
|
313
|
+
el("div", { className: classes }, twist, text),
|
|
314
|
+
);
|
|
315
|
+
let children = null;
|
|
316
|
+
const toggle = async () => {
|
|
317
|
+
if (children) {
|
|
318
|
+
children.hidden = !children.hidden;
|
|
319
|
+
} else {
|
|
320
|
+
children = el("ul", { role: "group" });
|
|
321
|
+
item.append(children);
|
|
322
|
+
try {
|
|
323
|
+
await onOpen(children);
|
|
324
|
+
} catch (err) {
|
|
325
|
+
children.append(
|
|
326
|
+
el("li", { className: "muted", textContent: err.message }),
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
twist.textContent = children.hidden ? "▸" : "▾";
|
|
331
|
+
if (id) children.hidden ? opened.delete(id) : opened.add(id);
|
|
332
|
+
};
|
|
333
|
+
if (onOpen) twist.addEventListener("click", toggle);
|
|
334
|
+
if (traceable && onTrace) {
|
|
335
|
+
text.addEventListener("click", onTrace);
|
|
336
|
+
} else if (onOpen) {
|
|
337
|
+
text.addEventListener("click", toggle);
|
|
338
|
+
}
|
|
339
|
+
if (id && opened.has(id)) toggle(); // open again after the repo is read again
|
|
340
|
+
return item;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function trace(path, key) {
|
|
344
|
+
location.hash = new URLSearchParams(
|
|
345
|
+
key ? { path, key } : { path },
|
|
346
|
+
).toString();
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
async function openDirectory(list, path) {
|
|
350
|
+
for (const entry of await api("/api/entries", { path })) {
|
|
351
|
+
if (entry.more) {
|
|
352
|
+
list.append(
|
|
353
|
+
el("li", { className: "muted", textContent: entry.name }),
|
|
354
|
+
);
|
|
355
|
+
} else if (entry.dir) {
|
|
356
|
+
list.append(
|
|
357
|
+
row(entry.name, {
|
|
358
|
+
id: entry.path,
|
|
359
|
+
kind: "dir",
|
|
360
|
+
empty: !entry.holds,
|
|
361
|
+
onOpen: (sub) => openDirectory(sub, entry.path),
|
|
362
|
+
}),
|
|
363
|
+
);
|
|
364
|
+
} else if (entry.store) {
|
|
365
|
+
list.append(
|
|
366
|
+
row(entry.name, {
|
|
367
|
+
id: entry.path,
|
|
368
|
+
kind: "store",
|
|
369
|
+
empty: !entry.holds,
|
|
370
|
+
onOpen: (sub) =>
|
|
371
|
+
openStore(sub, entry.path, entry.traceable),
|
|
372
|
+
}),
|
|
373
|
+
);
|
|
374
|
+
} else {
|
|
375
|
+
list.append(
|
|
376
|
+
row(entry.name, {
|
|
377
|
+
traceable: entry.traceable,
|
|
378
|
+
onTrace: () => trace(entry.path),
|
|
379
|
+
}),
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
async function openStore(list, path, traceable) {
|
|
386
|
+
const keys = await api("/api/keys", { path });
|
|
387
|
+
if (traceable) {
|
|
388
|
+
list.append(
|
|
389
|
+
row("trace this store as a whole", {
|
|
390
|
+
traceable: true,
|
|
391
|
+
onTrace: () => trace(path),
|
|
392
|
+
}),
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
if (!keys.length) {
|
|
396
|
+
list.append(
|
|
397
|
+
el("li", {
|
|
398
|
+
className: "muted",
|
|
399
|
+
textContent:
|
|
400
|
+
"No keys found: not an AnnData or SpatialData object.",
|
|
401
|
+
}),
|
|
402
|
+
);
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
// Group keys by their parts: obs/leiden under obs; tables/table/obs/x under tables, tables/table, ...
|
|
406
|
+
const root = { children: new Map() };
|
|
407
|
+
for (const { key, traceable: recorded } of keys) {
|
|
408
|
+
let node = root;
|
|
409
|
+
for (const part of key.split("/")) {
|
|
410
|
+
if (!node.children.has(part))
|
|
411
|
+
node.children.set(part, { children: new Map() });
|
|
412
|
+
node = node.children.get(part);
|
|
413
|
+
}
|
|
414
|
+
Object.assign(node, { key, recorded });
|
|
415
|
+
}
|
|
416
|
+
const anyRecorded = (node) =>
|
|
417
|
+
node.recorded || [...node.children.values()].some(anyRecorded);
|
|
418
|
+
const render = (node, into, prefix) => {
|
|
419
|
+
for (const [name, child] of node.children) {
|
|
420
|
+
const options = {
|
|
421
|
+
traceable: Boolean(child.recorded),
|
|
422
|
+
onTrace: () => trace(path, child.key),
|
|
423
|
+
};
|
|
424
|
+
if (child.children.size) {
|
|
425
|
+
Object.assign(options, {
|
|
426
|
+
id: `${path}#${prefix}${name}`,
|
|
427
|
+
kind: "group",
|
|
428
|
+
empty: !anyRecorded(child),
|
|
429
|
+
onOpen: async (sub) =>
|
|
430
|
+
render(child, sub, `${prefix}${name}/`),
|
|
431
|
+
});
|
|
432
|
+
} else {
|
|
433
|
+
options.kind = "key";
|
|
434
|
+
}
|
|
435
|
+
into.append(row(name, options));
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
render(root, list, "");
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
async function refresh() {
|
|
442
|
+
$("#refresh").disabled = true;
|
|
443
|
+
try {
|
|
444
|
+
const tree = el("ul", { id: "tree", role: "tree" });
|
|
445
|
+
await openDirectory(tree, "");
|
|
446
|
+
$("#tree").replaceWith(tree);
|
|
447
|
+
fromAddress();
|
|
448
|
+
} finally {
|
|
449
|
+
$("#refresh").disabled = false;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// Cards
|
|
454
|
+
|
|
455
|
+
// What an artifact is, read when its fold first opens: for a file its kind, size and date; for a store, each key.
|
|
456
|
+
async function describeInto(body, a) {
|
|
457
|
+
if (a.path.startsWith("/") || a.path.startsWith("~")) return; // outside the repo: its path is all there is
|
|
458
|
+
try {
|
|
459
|
+
if (!a.keys) {
|
|
460
|
+
const about = await api("/api/about", { path: a.path });
|
|
461
|
+
body.append(
|
|
462
|
+
el(
|
|
463
|
+
"dl",
|
|
464
|
+
{},
|
|
465
|
+
el("dt", { textContent: "What" }),
|
|
466
|
+
el("dd", { textContent: summarise(about) }),
|
|
467
|
+
about.modified && el("dt", { textContent: "Changed" }),
|
|
468
|
+
about.modified && el("dd", { textContent: about.modified }),
|
|
469
|
+
),
|
|
470
|
+
);
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
// Keys by element: X and the like on their own, obs/... under obs, tables/<name>/... under that table.
|
|
474
|
+
const groups = new Map();
|
|
475
|
+
for (const about of await api("/api/about", [
|
|
476
|
+
["path", a.path],
|
|
477
|
+
...a.keys.map((k) => ["key", k]),
|
|
478
|
+
])) {
|
|
479
|
+
const parts = about.key.split("/");
|
|
480
|
+
const depth =
|
|
481
|
+
parts[0] === "tables" && parts.length > 2
|
|
482
|
+
? 2
|
|
483
|
+
: parts.length > 1
|
|
484
|
+
? 1
|
|
485
|
+
: 0;
|
|
486
|
+
const group = parts.slice(0, depth).join("/");
|
|
487
|
+
if (!groups.has(group)) groups.set(group, []);
|
|
488
|
+
groups.get(group).push([parts.slice(depth).join("/"), about]);
|
|
489
|
+
}
|
|
490
|
+
const facts = (rows) =>
|
|
491
|
+
el(
|
|
492
|
+
"div",
|
|
493
|
+
{ className: "facts" },
|
|
494
|
+
rows.map(([name, about]) => {
|
|
495
|
+
const text = summarise(about);
|
|
496
|
+
return [
|
|
497
|
+
el("code", { textContent: name, title: about.key }),
|
|
498
|
+
el("span", {
|
|
499
|
+
className: "muted",
|
|
500
|
+
textContent: text,
|
|
501
|
+
title: text,
|
|
502
|
+
}),
|
|
503
|
+
];
|
|
504
|
+
}),
|
|
505
|
+
);
|
|
506
|
+
for (const [group, rows] of groups) {
|
|
507
|
+
body.append(
|
|
508
|
+
group
|
|
509
|
+
? fold(
|
|
510
|
+
`${group} · ${plural(rows.length, "key")}`,
|
|
511
|
+
facts(rows),
|
|
512
|
+
)
|
|
513
|
+
: facts(rows),
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
} catch (err) {
|
|
517
|
+
body.append(el("p", { className: "muted", textContent: err.message }));
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// One artifact: its short name and how many keys; on a click, its path and what it is.
|
|
522
|
+
function artifact(a) {
|
|
523
|
+
const name = a.keys
|
|
524
|
+
? `${baseName(a.path)} · ${plural(a.keys.length, "key")}`
|
|
525
|
+
: baseName(a.path);
|
|
526
|
+
const path = el(
|
|
527
|
+
"dl",
|
|
528
|
+
{},
|
|
529
|
+
el("dt", { textContent: "Path" }),
|
|
530
|
+
el("dd", {}, el("code", { textContent: a.path })),
|
|
531
|
+
);
|
|
532
|
+
return el(
|
|
533
|
+
"li",
|
|
534
|
+
{},
|
|
535
|
+
fold(name, path, (body) => describeInto(body, a)),
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// Artifacts as the folders they are in, below the folder they all share: each folder folded under its name and
|
|
540
|
+
// how many artifacts it holds; a chain of folders with nothing else in them is one line. ``keep`` shared folders
|
|
541
|
+
// stay as the top of the tree, to say where the artifacts are, unless the group they are in (``label``) already
|
|
542
|
+
// ends with that folder's name.
|
|
543
|
+
function artifacts(list, keep = 1, label = "") {
|
|
544
|
+
const dirs = list.map((a) => a.path.split("/").slice(0, -1));
|
|
545
|
+
let shared = 0;
|
|
546
|
+
while (
|
|
547
|
+
dirs.every((d) => d.length > shared && d[shared] === dirs[0][shared])
|
|
548
|
+
)
|
|
549
|
+
shared += 1;
|
|
550
|
+
if (shared && label.split(" · ").pop() === dirs[0][shared - 1]) keep = 0;
|
|
551
|
+
shared = Math.max(0, shared - keep);
|
|
552
|
+
const root = { dirs: new Map(), items: [] };
|
|
553
|
+
for (const [i, a] of list.entries()) {
|
|
554
|
+
let node = root;
|
|
555
|
+
for (const part of dirs[i].slice(shared)) {
|
|
556
|
+
if (!node.dirs.has(part))
|
|
557
|
+
node.dirs.set(part, { dirs: new Map(), items: [] });
|
|
558
|
+
node = node.dirs.get(part);
|
|
559
|
+
}
|
|
560
|
+
node.items.push(a);
|
|
561
|
+
}
|
|
562
|
+
const count = (node) =>
|
|
563
|
+
node.items.length +
|
|
564
|
+
[...node.dirs.values()].reduce((n, d) => n + count(d), 0);
|
|
565
|
+
const render = (node) =>
|
|
566
|
+
el(
|
|
567
|
+
"ul",
|
|
568
|
+
{ className: "artifacts" },
|
|
569
|
+
[...node.dirs].map(([name, dir]) => {
|
|
570
|
+
let label = name;
|
|
571
|
+
while (dir.items.length === 0 && dir.dirs.size === 1) {
|
|
572
|
+
const [[next, sub]] = dir.dirs;
|
|
573
|
+
label = `${label}/${next}`;
|
|
574
|
+
dir = sub;
|
|
575
|
+
}
|
|
576
|
+
return el(
|
|
577
|
+
"li",
|
|
578
|
+
{},
|
|
579
|
+
fold(`${label}/ · ${count(dir)}`, render(dir)),
|
|
580
|
+
);
|
|
581
|
+
}),
|
|
582
|
+
node.items.map(artifact),
|
|
583
|
+
);
|
|
584
|
+
return render(root);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// Artifacts in groups: each group folded under its name and count.
|
|
588
|
+
function byGroup(list, groupOf, keep = 1) {
|
|
589
|
+
const groups = new Map();
|
|
590
|
+
for (const a of list) {
|
|
591
|
+
const group = groupOf(a) || "other";
|
|
592
|
+
if (!groups.has(group)) groups.set(group, []);
|
|
593
|
+
groups.get(group).push(a);
|
|
594
|
+
}
|
|
595
|
+
return [...groups].map(([group, items]) =>
|
|
596
|
+
fold(`${group} · ${items.length}`, artifacts(items, keep, group)),
|
|
597
|
+
);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// Why no task on the path made an artifact: a short name, and a sentence.
|
|
601
|
+
const ELSEWHERE = "task not in this checkout";
|
|
602
|
+
function why(status) {
|
|
603
|
+
if (status === "source")
|
|
604
|
+
return {
|
|
605
|
+
short: "source data",
|
|
606
|
+
sentence:
|
|
607
|
+
"This is source data (raw data, a resource or a file outside the repo): no task made it.",
|
|
608
|
+
};
|
|
609
|
+
if (status === "no record")
|
|
610
|
+
return {
|
|
611
|
+
short: "no record",
|
|
612
|
+
sentence:
|
|
613
|
+
"No task is recorded as having made this, so there is nothing to trace.",
|
|
614
|
+
};
|
|
615
|
+
const where = status.startsWith(ELSEWHERE)
|
|
616
|
+
? status.slice(ELSEWHERE.length + 2)
|
|
617
|
+
: status;
|
|
618
|
+
return {
|
|
619
|
+
short: "made outside this checkout",
|
|
620
|
+
sentence: `It was made by a task that is not in this checkout: ${where}.`,
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
async function showTask(found, task) {
|
|
625
|
+
const node = found.tasks[task];
|
|
626
|
+
const head = [
|
|
627
|
+
el("p", { className: "kicker", textContent: "Task card" }),
|
|
628
|
+
el("h2", { textContent: baseName(task) }),
|
|
629
|
+
task === found.target.task &&
|
|
630
|
+
el("p", {}, swatch("target", "made the artifact you traced")),
|
|
631
|
+
el(
|
|
632
|
+
"dl",
|
|
633
|
+
{},
|
|
634
|
+
el("dt", { textContent: "Started" }),
|
|
635
|
+
el("dd", { textContent: node.date || "—" }),
|
|
636
|
+
el("dt", { textContent: "Author" }),
|
|
637
|
+
el("dd", { textContent: node.author || "—" }),
|
|
638
|
+
el("dt", { textContent: "Folder" }),
|
|
639
|
+
el("dd", {}, el("code", { textContent: task })),
|
|
640
|
+
el("dt", { textContent: "Task id" }),
|
|
641
|
+
el("dd", {}, el("code", { textContent: node.id || "—" })),
|
|
642
|
+
),
|
|
643
|
+
found.undeclared.includes(task) &&
|
|
644
|
+
el(
|
|
645
|
+
"p",
|
|
646
|
+
{ className: "status" },
|
|
647
|
+
swatch(
|
|
648
|
+
"undeclared",
|
|
649
|
+
"It has no inputs.yaml, so what it used is unknown and the trace stops here.",
|
|
650
|
+
),
|
|
651
|
+
),
|
|
652
|
+
];
|
|
653
|
+
openCard(head);
|
|
654
|
+
let summary;
|
|
655
|
+
try {
|
|
656
|
+
summary = (await api("/api/task", { path: task })).summary;
|
|
657
|
+
} catch (err) {
|
|
658
|
+
summary = err.message;
|
|
659
|
+
}
|
|
660
|
+
// Every input it declared: what each earlier task passed it, then what no task on the path made, by place.
|
|
661
|
+
const inputs = [
|
|
662
|
+
...found.edges
|
|
663
|
+
.filter((e) => e.target === task)
|
|
664
|
+
.flatMap((e) =>
|
|
665
|
+
e.artifacts.map((a) => ({
|
|
666
|
+
...a,
|
|
667
|
+
from: `from ${baseName(e.source)}`,
|
|
668
|
+
})),
|
|
669
|
+
),
|
|
670
|
+
...node.consumed.map((a) => ({
|
|
671
|
+
...a,
|
|
672
|
+
from:
|
|
673
|
+
a.status === "source"
|
|
674
|
+
? a.place
|
|
675
|
+
: `${a.place} · ${why(a.status).short}`,
|
|
676
|
+
})),
|
|
677
|
+
];
|
|
678
|
+
const outputsFold = fold("Outputs · …", []);
|
|
679
|
+
openCard(
|
|
680
|
+
head,
|
|
681
|
+
summary && fold("What it set out to do", el("p", {}, inline(summary))),
|
|
682
|
+
fold(
|
|
683
|
+
`Inputs · ${inputs.length}`,
|
|
684
|
+
inputs.length
|
|
685
|
+
? byGroup(inputs, (a) => a.from)
|
|
686
|
+
: el("p", {
|
|
687
|
+
className: "muted",
|
|
688
|
+
textContent: "None declared.",
|
|
689
|
+
}),
|
|
690
|
+
),
|
|
691
|
+
outputsFold,
|
|
692
|
+
);
|
|
693
|
+
// Read with the card, so the summary can say how many there are.
|
|
694
|
+
try {
|
|
695
|
+
const outputs = await api("/api/outputs", { path: task });
|
|
696
|
+
outputsFold.querySelector("summary").textContent =
|
|
697
|
+
`Outputs · ${outputs.length}`;
|
|
698
|
+
outputsFold.querySelector(".folded").append(
|
|
699
|
+
el(
|
|
700
|
+
"div",
|
|
701
|
+
{},
|
|
702
|
+
outputs.length
|
|
703
|
+
? byGroup(outputs, (a) => a.group, 0)
|
|
704
|
+
: el("p", {
|
|
705
|
+
className: "muted",
|
|
706
|
+
textContent: "None found.",
|
|
707
|
+
}),
|
|
708
|
+
),
|
|
709
|
+
);
|
|
710
|
+
} catch (err) {
|
|
711
|
+
outputsFold
|
|
712
|
+
.querySelector(".folded")
|
|
713
|
+
.append(el("p", { className: "muted", textContent: err.message }));
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
function showEdge(edge) {
|
|
718
|
+
openCard(
|
|
719
|
+
el("p", {
|
|
720
|
+
className: "kicker",
|
|
721
|
+
textContent: "Edge card",
|
|
722
|
+
}),
|
|
723
|
+
el("h2", {
|
|
724
|
+
textContent: `${baseName(edge.source)} → ${baseName(edge.target)}`,
|
|
725
|
+
}),
|
|
726
|
+
artifacts(edge.artifacts),
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
// Graph
|
|
731
|
+
|
|
732
|
+
// Lay the tasks out top to bottom with dagre, and give each edge dagre's route: an edge that skips ranks passes
|
|
733
|
+
// beside the tasks in between, never across them.
|
|
734
|
+
function route(graph) {
|
|
735
|
+
const g = new dagre.graphlib.Graph();
|
|
736
|
+
g.setGraph({ rankdir: "TB", nodesep: 40, ranksep: 60, edgesep: 20 });
|
|
737
|
+
g.setDefaultEdgeLabel(() => ({}));
|
|
738
|
+
graph.nodes().forEach((n) => {
|
|
739
|
+
g.setNode(n.id(), { width: n.outerWidth(), height: n.outerHeight() });
|
|
740
|
+
});
|
|
741
|
+
graph.edges().forEach((e) => {
|
|
742
|
+
g.setEdge(e.source().id(), e.target().id());
|
|
743
|
+
});
|
|
744
|
+
dagre.layout(g);
|
|
745
|
+
graph.nodes().forEach((n) => {
|
|
746
|
+
const { x, y } = g.node(n.id());
|
|
747
|
+
n.position({ x, y });
|
|
748
|
+
});
|
|
749
|
+
graph.edges().forEach((e) => {
|
|
750
|
+
const s = e.source().position();
|
|
751
|
+
const t = e.target().position();
|
|
752
|
+
const vx = t.x - s.x;
|
|
753
|
+
const vy = t.y - s.y;
|
|
754
|
+
const length2 = vx * vx + vy * vy || 1;
|
|
755
|
+
const length = Math.sqrt(length2);
|
|
756
|
+
// The route's bends, as cytoscape's segment points: how far along the line from source to target, and how
|
|
757
|
+
// far to the side of it.
|
|
758
|
+
const bends = g
|
|
759
|
+
.edge(e.source().id(), e.target().id())
|
|
760
|
+
.points.slice(1, -1);
|
|
761
|
+
const weights = bends.map(
|
|
762
|
+
(p) => ((p.x - s.x) * vx + (p.y - s.y) * vy) / length2,
|
|
763
|
+
);
|
|
764
|
+
const distances = bends.map(
|
|
765
|
+
(p) => ((p.y - s.y) * vx - (p.x - s.x) * vy) / length,
|
|
766
|
+
);
|
|
767
|
+
e.style({
|
|
768
|
+
"segment-weights": weights.join(" ") || "0.5",
|
|
769
|
+
"segment-distances": distances.join(" ") || "0",
|
|
770
|
+
});
|
|
771
|
+
});
|
|
772
|
+
graph.fit(undefined, 40);
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
function colour(name) {
|
|
776
|
+
return getComputedStyle(document.documentElement)
|
|
777
|
+
.getPropertyValue(name)
|
|
778
|
+
.trim();
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
function showMessage(text) {
|
|
782
|
+
if (cy) cy.elements().remove();
|
|
783
|
+
$("#message").textContent = text;
|
|
784
|
+
$("#message").hidden = false;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
async function showTrace(path, key) {
|
|
788
|
+
const name = key ? `${baseName(path)}: ${key}` : baseName(path);
|
|
789
|
+
setTitle(name, "tracing…");
|
|
790
|
+
$("#message").hidden = true;
|
|
791
|
+
closeCard();
|
|
792
|
+
let found;
|
|
793
|
+
try {
|
|
794
|
+
found = await api("/api/trace", key ? { path, key } : { path });
|
|
795
|
+
} catch (err) {
|
|
796
|
+
setTitle(name);
|
|
797
|
+
showMessage(err.message);
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
const maker = found.target.task;
|
|
801
|
+
if (!maker) {
|
|
802
|
+
setTitle(name, why(found.target.status).short);
|
|
803
|
+
showMessage(why(found.target.status).sentence);
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
const led = `${plural(Object.keys(found.tasks).length, "task")} led to it`;
|
|
807
|
+
setTitle(name, led);
|
|
808
|
+
// What the traced artifact is, once known.
|
|
809
|
+
api(
|
|
810
|
+
"/api/about",
|
|
811
|
+
key
|
|
812
|
+
? [
|
|
813
|
+
["path", path],
|
|
814
|
+
["key", key],
|
|
815
|
+
]
|
|
816
|
+
: { path },
|
|
817
|
+
)
|
|
818
|
+
.then((about) =>
|
|
819
|
+
setTitle(
|
|
820
|
+
name,
|
|
821
|
+
summarise(Array.isArray(about) ? about[0] : about),
|
|
822
|
+
led,
|
|
823
|
+
),
|
|
824
|
+
)
|
|
825
|
+
.catch(() => {});
|
|
826
|
+
const elements = [
|
|
827
|
+
...Object.entries(found.tasks).map(([task, node]) => ({
|
|
828
|
+
data: { id: task, label: `${baseName(task)}\n${node.date || ""}` },
|
|
829
|
+
classes: [
|
|
830
|
+
task === maker ? "target" : "",
|
|
831
|
+
found.undeclared.includes(task) ? "undeclared" : "",
|
|
832
|
+
].join(" "),
|
|
833
|
+
})),
|
|
834
|
+
...found.edges.map((edge) => ({
|
|
835
|
+
data: { id: `${edge.source}→${edge.target}`, ...edge },
|
|
836
|
+
})),
|
|
837
|
+
];
|
|
838
|
+
if (cy) cy.destroy();
|
|
839
|
+
cy = cytoscape({
|
|
840
|
+
container: $("#graph"),
|
|
841
|
+
elements,
|
|
842
|
+
maxZoom: 1.25,
|
|
843
|
+
wheelSensitivity: 0.3,
|
|
844
|
+
layout: { name: "preset" },
|
|
845
|
+
style: [
|
|
846
|
+
{
|
|
847
|
+
selector: "node",
|
|
848
|
+
style: {
|
|
849
|
+
shape: "round-rectangle",
|
|
850
|
+
"background-color": colour("--node"),
|
|
851
|
+
"border-width": 1.5,
|
|
852
|
+
"border-color": colour("--line"),
|
|
853
|
+
label: "data(label)",
|
|
854
|
+
color: colour("--ink"),
|
|
855
|
+
"font-size": 13,
|
|
856
|
+
"text-wrap": "wrap",
|
|
857
|
+
"text-valign": "center",
|
|
858
|
+
width: "label",
|
|
859
|
+
height: "label",
|
|
860
|
+
padding: 12,
|
|
861
|
+
},
|
|
862
|
+
},
|
|
863
|
+
{
|
|
864
|
+
selector: "node.target",
|
|
865
|
+
style: {
|
|
866
|
+
"border-color": colour("--target"),
|
|
867
|
+
"border-width": 3,
|
|
868
|
+
},
|
|
869
|
+
},
|
|
870
|
+
{
|
|
871
|
+
selector: "node.undeclared",
|
|
872
|
+
style: {
|
|
873
|
+
"border-style": "dashed",
|
|
874
|
+
"border-color": colour("--warn"),
|
|
875
|
+
},
|
|
876
|
+
},
|
|
877
|
+
{
|
|
878
|
+
selector: "edge",
|
|
879
|
+
style: {
|
|
880
|
+
width: 2,
|
|
881
|
+
"curve-style": "round-segments",
|
|
882
|
+
"segment-radius": 12,
|
|
883
|
+
"edge-distances": "node-position",
|
|
884
|
+
"line-color": colour("--muted"),
|
|
885
|
+
"target-arrow-color": colour("--muted"),
|
|
886
|
+
"target-arrow-shape": "triangle",
|
|
887
|
+
},
|
|
888
|
+
},
|
|
889
|
+
{
|
|
890
|
+
// What the open card shows: a halo around it, which leaves its own colours as they are.
|
|
891
|
+
selector: ":selected",
|
|
892
|
+
style: {
|
|
893
|
+
"overlay-color": colour("--ink"),
|
|
894
|
+
"overlay-opacity": 0.12,
|
|
895
|
+
"overlay-padding": 7,
|
|
896
|
+
},
|
|
897
|
+
},
|
|
898
|
+
],
|
|
899
|
+
});
|
|
900
|
+
route(cy);
|
|
901
|
+
// Tasks and arrows can be clicked: the pointer says so.
|
|
902
|
+
cy.on("mouseover", "node, edge", () => {
|
|
903
|
+
$("#graph").style.cursor = "pointer";
|
|
904
|
+
});
|
|
905
|
+
cy.on("mouseout", "node, edge", () => {
|
|
906
|
+
$("#graph").style.cursor = "";
|
|
907
|
+
});
|
|
908
|
+
cy.on("tap", "node", (event) => showTask(found, event.target.id()));
|
|
909
|
+
cy.on("tap", "edge", (event) => showEdge(event.target.data()));
|
|
910
|
+
cy.on("tap", (event) => {
|
|
911
|
+
if (event.target === cy) closeCard();
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
function fromAddress() {
|
|
916
|
+
const params = new URLSearchParams(location.hash.slice(1));
|
|
917
|
+
if (params.get("path")) showTrace(params.get("path"), params.get("key"));
|
|
918
|
+
else
|
|
919
|
+
showMessage(
|
|
920
|
+
"Pick a blue file or key on the left to see the tasks that led to it.",
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
layoutControls();
|
|
925
|
+
cardControls();
|
|
926
|
+
showRepo().catch((err) => {
|
|
927
|
+
$("#repo").textContent = err.message;
|
|
928
|
+
});
|
|
929
|
+
window.addEventListener("hashchange", fromAddress);
|
|
930
|
+
openDirectory($("#tree"), "").catch((err) =>
|
|
931
|
+
$("#tree").append(
|
|
932
|
+
el("li", { className: "muted", textContent: err.message }),
|
|
933
|
+
),
|
|
934
|
+
);
|
|
935
|
+
fromAddress();
|