@johnoscott/isometric-engine 0.0.0-stage → 0.9.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/EDITOR-GUIDE.md +317 -0
- package/LICENSE +21 -0
- package/LICENSES/ajv.txt +22 -0
- package/LICENSES/lucide-static.txt +43 -0
- package/LICENSES/yaml.txt +13 -0
- package/README.md +62 -2
- package/assets/app.css +265 -0
- package/assets/default-theme.yaml +99 -0
- package/assets/icons.svg +1 -0
- package/assets/marks.css +35 -0
- package/assets/skin.css +181 -0
- package/iso-editor.d.ts +4 -0
- package/iso-editor.js +550 -0
- package/iso-render.d.ts +3 -0
- package/iso-render.js +388 -0
- package/iso-systems.d.ts +4 -0
- package/iso-systems.js +389 -0
- package/js/iso-core/compile-schema.js +22 -0
- package/js/iso-core/depth.js +55 -0
- package/js/iso-core/errors.js +65 -0
- package/js/iso-core/glyphs.js +100 -0
- package/js/iso-core/index.js +55 -0
- package/js/iso-core/kernel.js +158 -0
- package/js/iso-core/metrics.json +1 -0
- package/js/iso-core/package.json +6 -0
- package/js/iso-core/parse.js +79 -0
- package/js/iso-core/schema-errors.js +170 -0
- package/js/iso-core/shims/crypto.js +125 -0
- package/js/iso-core/shims/path.js +49 -0
- package/js/iso-core/svg-dom.js +144 -0
- package/js/iso-core/theme.js +48 -0
- package/js/iso-core/vdom.js +48 -0
- package/js/iso-editor/adapter.js +0 -0
- package/js/iso-editor/clipboard.js +152 -0
- package/js/iso-editor/commands.js +173 -0
- package/js/iso-editor/complete.js +55 -0
- package/js/iso-editor/doc.js +182 -0
- package/js/iso-editor/index.js +105 -0
- package/js/iso-editor/model.js +210 -0
- package/js/iso-editor/outline.js +111 -0
- package/js/iso-editor/package.json +6 -0
- package/js/iso-editor/path.js +19 -0
- package/js/iso-editor/providers.js +96 -0
- package/js/iso-editor/schema-nav.js +117 -0
- package/js/iso-editor/splice.js +441 -0
- package/js/iso-editor/storage-keys.js +6 -0
- package/js/iso-editor/ui/actions.js +116 -0
- package/js/iso-editor/ui/canvas-layer.js +0 -0
- package/js/iso-editor/ui/canvas.js +1205 -0
- package/js/iso-editor/ui/clip.js +133 -0
- package/js/iso-editor/ui/dialog.js +26 -0
- package/js/iso-editor/ui/flat-canvas.js +54 -0
- package/js/iso-editor/ui/icons.js +15 -0
- package/js/iso-editor/ui/keys.js +26 -0
- package/js/iso-editor/ui/later.js +28 -0
- package/js/iso-editor/ui/layer.js +11 -0
- package/js/iso-editor/ui/menu.js +105 -0
- package/js/iso-editor/ui/monaco-entry.js +2 -0
- package/js/iso-editor/ui/mount-kit.js +0 -0
- package/js/iso-editor/ui/mount.js +767 -0
- package/js/iso-editor/ui/pane.js +0 -0
- package/js/iso-editor/ui/part.js +0 -0
- package/js/iso-editor/ui/plain-icons.js +34 -0
- package/js/iso-editor/ui/props.js +314 -0
- package/js/iso-editor/ui/scope-css.js +81 -0
- package/js/iso-editor/ui/setup.js +145 -0
- package/js/iso-editor/ui/text.js +323 -0
- package/js/iso-editor/ui/tree.js +728 -0
- package/js/iso-editor/validate.js +33 -0
- package/js/iso-editor/window/protocol.js +8 -0
- package/js/iso-objects/assemble.js +43 -0
- package/js/iso-objects/assets.js +88 -0
- package/js/iso-objects/board.js +162 -0
- package/js/iso-objects/compile.js +60 -0
- package/js/iso-objects/css.js +154 -0
- package/js/iso-objects/flat.js +696 -0
- package/js/iso-objects/focus.js +16 -0
- package/js/iso-objects/geometry.js +76 -0
- package/js/iso-objects/index.js +93 -0
- package/js/iso-objects/kinds.js +12 -0
- package/js/iso-objects/labels.js +325 -0
- package/js/iso-objects/package.json +6 -0
- package/js/iso-objects/place.js +347 -0
- package/js/iso-objects/route.js +461 -0
- package/js/iso-objects/scene.js +350 -0
- package/js/iso-objects/steps.js +246 -0
- package/js/iso-objects/types.js +0 -0
- package/js/iso-systems/catalog.js +42 -0
- package/js/iso-systems/compile.js +34 -0
- package/js/iso-systems/css.js +8 -0
- package/js/iso-systems/index.js +16 -0
- package/js/iso-systems/nodes.js +124 -0
- package/js/iso-systems/package.json +6 -0
- package/js/iso-systems/schema.json +311 -0
- package/js/iso-systems/validate.js +35 -0
- package/js/iso-viewer/bundle.js +20 -0
- package/js/iso-viewer/card-motion.js +228 -0
- package/js/iso-viewer/dom.js +14 -0
- package/js/iso-viewer/dual-view.js +212 -0
- package/js/iso-viewer/flat-view.js +124 -0
- package/js/iso-viewer/history.js +990 -0
- package/js/iso-viewer/index.js +98 -0
- package/js/iso-viewer/morph.js +192 -0
- package/js/iso-viewer/overlay.js +199 -0
- package/js/iso-viewer/package.json +6 -0
- package/js/iso-viewer/page.js +138 -0
- package/js/iso-viewer/player.js +409 -0
- package/js/iso-viewer/still.js +81 -0
- package/js/iso-viewer/timeline-contract.js +14 -0
- package/js/iso-viewer/timeline-engine.js +475 -0
- package/js/iso-viewer/timeline-export.js +36 -0
- package/js/iso-viewer/timeline-scale.js +116 -0
- package/js/iso-viewer/timeline-scope.js +58 -0
- package/js/iso-viewer/timeline-search.js +216 -0
- package/js/iso-viewer/timeline-time.js +55 -0
- package/js/iso-viewer/view-css.js +68 -0
- package/js/iso-viewer/viewport.js +177 -0
- package/package.json +502 -4
- package/src/iso-core/compile-schema.ts +23 -0
- package/src/iso-core/depth.ts +56 -0
- package/src/iso-core/errors.ts +73 -0
- package/src/iso-core/glyphs.ts +108 -0
- package/src/iso-core/index.ts +27 -0
- package/src/iso-core/kernel.ts +163 -0
- package/src/iso-core/metrics.json +1 -0
- package/src/iso-core/package.json +6 -0
- package/src/iso-core/parse.ts +91 -0
- package/src/iso-core/schema-errors.ts +163 -0
- package/src/iso-core/shims/crypto.ts +37 -0
- package/src/iso-core/shims/path.ts +24 -0
- package/src/iso-core/svg-dom.ts +103 -0
- package/src/iso-core/theme.ts +64 -0
- package/src/iso-core/vdom.ts +41 -0
- package/src/iso-editor/adapter.ts +128 -0
- package/src/iso-editor/clipboard.ts +163 -0
- package/src/iso-editor/commands.ts +191 -0
- package/src/iso-editor/complete.ts +73 -0
- package/src/iso-editor/doc.ts +207 -0
- package/src/iso-editor/index.ts +67 -0
- package/src/iso-editor/model.ts +234 -0
- package/src/iso-editor/outline.ts +126 -0
- package/src/iso-editor/package.json +6 -0
- package/src/iso-editor/path.ts +18 -0
- package/src/iso-editor/providers.ts +113 -0
- package/src/iso-editor/schema-nav.ts +129 -0
- package/src/iso-editor/splice.ts +472 -0
- package/src/iso-editor/storage-keys.ts +6 -0
- package/src/iso-editor/ui/actions.ts +119 -0
- package/src/iso-editor/ui/app.css +230 -0
- package/src/iso-editor/ui/canvas-layer.ts +56 -0
- package/src/iso-editor/ui/canvas.ts +1071 -0
- package/src/iso-editor/ui/clip.ts +97 -0
- package/src/iso-editor/ui/dialog.ts +25 -0
- package/src/iso-editor/ui/flat-canvas.ts +51 -0
- package/src/iso-editor/ui/icons.ts +21 -0
- package/src/iso-editor/ui/keys.ts +30 -0
- package/src/iso-editor/ui/later.ts +22 -0
- package/src/iso-editor/ui/layer.ts +7 -0
- package/src/iso-editor/ui/marks.css +35 -0
- package/src/iso-editor/ui/menu.ts +67 -0
- package/src/iso-editor/ui/monaco-entry.ts +6 -0
- package/src/iso-editor/ui/mount-kit.ts +35 -0
- package/src/iso-editor/ui/mount.ts +684 -0
- package/src/iso-editor/ui/pane.ts +45 -0
- package/src/iso-editor/ui/part.ts +45 -0
- package/src/iso-editor/ui/plain-icons.ts +83 -0
- package/src/iso-editor/ui/props.ts +347 -0
- package/src/iso-editor/ui/scope-css.ts +65 -0
- package/src/iso-editor/ui/setup.ts +144 -0
- package/src/iso-editor/ui/skin.css +181 -0
- package/src/iso-editor/ui/text.ts +262 -0
- package/src/iso-editor/ui/tree.ts +657 -0
- package/src/iso-editor/validate.ts +62 -0
- package/src/iso-editor/window/protocol.ts +33 -0
- package/src/iso-objects/assemble.ts +57 -0
- package/src/iso-objects/assets.ts +122 -0
- package/src/iso-objects/board.ts +169 -0
- package/src/iso-objects/compile.ts +76 -0
- package/src/iso-objects/css.ts +163 -0
- package/src/iso-objects/flat.ts +653 -0
- package/src/iso-objects/focus.ts +14 -0
- package/src/iso-objects/geometry.ts +86 -0
- package/src/iso-objects/index.ts +33 -0
- package/src/iso-objects/kinds.ts +56 -0
- package/src/iso-objects/labels.ts +310 -0
- package/src/iso-objects/package.json +6 -0
- package/src/iso-objects/place.ts +318 -0
- package/src/iso-objects/route.ts +444 -0
- package/src/iso-objects/scene.ts +376 -0
- package/src/iso-objects/steps.ts +234 -0
- package/src/iso-objects/types.ts +68 -0
- package/src/iso-systems/catalog.ts +31 -0
- package/src/iso-systems/compile.ts +39 -0
- package/src/iso-systems/css.ts +9 -0
- package/src/iso-systems/index.ts +12 -0
- package/src/iso-systems/nodes.ts +126 -0
- package/src/iso-systems/package.json +6 -0
- package/src/iso-systems/schema.json +311 -0
- package/src/iso-systems/validate.ts +34 -0
- package/src/iso-viewer/bundle.ts +15 -0
- package/src/iso-viewer/card-motion.ts +237 -0
- package/src/iso-viewer/dom.ts +13 -0
- package/src/iso-viewer/dual-view.ts +212 -0
- package/src/iso-viewer/flat-view.ts +127 -0
- package/src/iso-viewer/history.ts +781 -0
- package/src/iso-viewer/index.ts +40 -0
- package/src/iso-viewer/morph.ts +191 -0
- package/src/iso-viewer/overlay.ts +212 -0
- package/src/iso-viewer/package.json +6 -0
- package/src/iso-viewer/page.ts +150 -0
- package/src/iso-viewer/player.ts +321 -0
- package/src/iso-viewer/still.ts +74 -0
- package/src/iso-viewer/timeline-contract.ts +342 -0
- package/src/iso-viewer/timeline-engine.ts +420 -0
- package/src/iso-viewer/timeline-export.ts +31 -0
- package/src/iso-viewer/timeline-scale.ts +129 -0
- package/src/iso-viewer/timeline-scope.ts +56 -0
- package/src/iso-viewer/timeline-search.ts +198 -0
- package/src/iso-viewer/timeline-time.ts +54 -0
- package/src/iso-viewer/view-css.ts +59 -0
- package/src/iso-viewer/viewport.ts +142 -0
- package/types/iso-core/compile-schema.d.ts +11 -0
- package/types/iso-core/depth.d.ts +6 -0
- package/types/iso-core/errors.d.ts +24 -0
- package/types/iso-core/glyphs.d.ts +19 -0
- package/types/iso-core/index.d.ts +17 -0
- package/types/iso-core/kernel.d.ts +130 -0
- package/types/iso-core/metrics.json +1 -0
- package/types/iso-core/parse.d.ts +18 -0
- package/types/iso-core/schema-errors.d.ts +14 -0
- package/types/iso-core/shims/crypto.d.ts +9 -0
- package/types/iso-core/svg-dom.d.ts +15 -0
- package/types/iso-core/theme.d.ts +38 -0
- package/types/iso-core/vdom.d.ts +26 -0
- package/types/iso-editor/adapter.d.ts +145 -0
- package/types/iso-editor/clipboard.d.ts +23 -0
- package/types/iso-editor/commands.d.ts +32 -0
- package/types/iso-editor/complete.d.ts +25 -0
- package/types/iso-editor/doc.d.ts +50 -0
- package/types/iso-editor/index.d.ts +57 -0
- package/types/iso-editor/model.d.ts +96 -0
- package/types/iso-editor/outline.d.ts +28 -0
- package/types/iso-editor/path.d.ts +7 -0
- package/types/iso-editor/providers.d.ts +43 -0
- package/types/iso-editor/schema-nav.d.ts +34 -0
- package/types/iso-editor/splice.d.ts +53 -0
- package/types/iso-editor/storage-keys.d.ts +5 -0
- package/types/iso-editor/ui/actions.d.ts +23 -0
- package/types/iso-editor/ui/canvas-layer.d.ts +65 -0
- package/types/iso-editor/ui/canvas.d.ts +279 -0
- package/types/iso-editor/ui/clip.d.ts +14 -0
- package/types/iso-editor/ui/dialog.d.ts +7 -0
- package/types/iso-editor/ui/flat-canvas.d.ts +2 -0
- package/types/iso-editor/ui/icons.d.ts +5 -0
- package/types/iso-editor/ui/keys.d.ts +7 -0
- package/types/iso-editor/ui/later.d.ts +12 -0
- package/types/iso-editor/ui/layer.d.ts +2 -0
- package/types/iso-editor/ui/menu.d.ts +21 -0
- package/types/iso-editor/ui/mount-kit.d.ts +31 -0
- package/types/iso-editor/ui/mount.d.ts +146 -0
- package/types/iso-editor/ui/pane.d.ts +60 -0
- package/types/iso-editor/ui/part.d.ts +40 -0
- package/types/iso-editor/ui/plain-icons.d.ts +10 -0
- package/types/iso-editor/ui/props.d.ts +57 -0
- package/types/iso-editor/ui/scope-css.d.ts +5 -0
- package/types/iso-editor/ui/setup.d.ts +40 -0
- package/types/iso-editor/ui/text.d.ts +19 -0
- package/types/iso-editor/ui/tree.d.ts +100 -0
- package/types/iso-editor/validate.d.ts +36 -0
- package/types/iso-editor/window/protocol.d.ts +60 -0
- package/types/iso-objects/assemble.d.ts +35 -0
- package/types/iso-objects/assets.d.ts +49 -0
- package/types/iso-objects/board.d.ts +36 -0
- package/types/iso-objects/compile.d.ts +35 -0
- package/types/iso-objects/css.d.ts +16 -0
- package/types/iso-objects/flat.d.ts +130 -0
- package/types/iso-objects/focus.d.ts +1 -0
- package/types/iso-objects/geometry.d.ts +59 -0
- package/types/iso-objects/index.d.ts +26 -0
- package/types/iso-objects/kinds.d.ts +53 -0
- package/types/iso-objects/labels.d.ts +92 -0
- package/types/iso-objects/place.d.ts +25 -0
- package/types/iso-objects/route.d.ts +67 -0
- package/types/iso-objects/scene.d.ts +63 -0
- package/types/iso-objects/steps.d.ts +90 -0
- package/types/iso-objects/types.d.ts +140 -0
- package/types/iso-systems/catalog.d.ts +4 -0
- package/types/iso-systems/compile.d.ts +6 -0
- package/types/iso-systems/css.d.ts +3 -0
- package/types/iso-systems/index.d.ts +5 -0
- package/types/iso-systems/nodes.d.ts +3 -0
- package/types/iso-viewer/card-motion.d.ts +56 -0
- package/types/iso-viewer/dom.d.ts +1 -0
- package/types/iso-viewer/dual-view.d.ts +44 -0
- package/types/iso-viewer/flat-view.d.ts +25 -0
- package/types/iso-viewer/history.d.ts +91 -0
- package/types/iso-viewer/index.d.ts +31 -0
- package/types/iso-viewer/morph.d.ts +28 -0
- package/types/iso-viewer/overlay.d.ts +135 -0
- package/types/iso-viewer/page.d.ts +13 -0
- package/types/iso-viewer/still.d.ts +26 -0
- package/types/iso-viewer/timeline-contract.d.ts +345 -0
- package/types/iso-viewer/timeline-engine.d.ts +20 -0
- package/types/iso-viewer/timeline-export.d.ts +5 -0
- package/types/iso-viewer/timeline-scale.d.ts +44 -0
- package/types/iso-viewer/timeline-scope.d.ts +33 -0
- package/types/iso-viewer/timeline-search.d.ts +52 -0
- package/types/iso-viewer/timeline-time.d.ts +8 -0
- package/types/iso-viewer/view-css.d.ts +7 -0
- package/types/iso-viewer/viewport.d.ts +50 -0
|
@@ -0,0 +1,990 @@
|
|
|
1
|
+
import { BIN_MS, SEVERITIES } from "./timeline-contract.js";
|
|
2
|
+
import { highlights, searchFor } from "./timeline-search.js";
|
|
3
|
+
import { crumbs, levelOf, prefixAt } from "./timeline-scope.js";
|
|
4
|
+
import { findGaps, gapKey, gapLabel, ticks, timeScale } from "./timeline-scale.js";
|
|
5
|
+
import { toCSV, toJSON } from "./timeline-export.js";
|
|
6
|
+
import { h } from "./dom.js";
|
|
7
|
+
const SVGNS = "http://www.w3.org/2000/svg";
|
|
8
|
+
const ROW = 22, MROW = 38, AXIS = 26, LABELS = 210, CUT = 24;
|
|
9
|
+
const MIN = 6e4, HOUR = 36e5, DAY = 864e5;
|
|
10
|
+
const QUICK = { "15m": 15 * MIN, "1h": HOUR, "1d": DAY, "1w": 7 * DAY };
|
|
11
|
+
const SEV_RANK = (s) => SEVERITIES.indexOf(s);
|
|
12
|
+
const SHAPE = { debug: "dot", info: "circle", notice: "square", warning: "triangle", error: "diamond" };
|
|
13
|
+
const svgEl = (name, attrs, title) => {
|
|
14
|
+
const e = document.createElementNS(SVGNS, name);
|
|
15
|
+
for (const [k, v] of Object.entries(attrs)) if (v !== void 0) e.setAttribute(k, String(v));
|
|
16
|
+
if (title) {
|
|
17
|
+
const tt = document.createElementNS(SVGNS, "title");
|
|
18
|
+
tt.textContent = title;
|
|
19
|
+
e.append(tt);
|
|
20
|
+
}
|
|
21
|
+
return e;
|
|
22
|
+
};
|
|
23
|
+
const fmtTime = (t, tz) => {
|
|
24
|
+
try {
|
|
25
|
+
return new Intl.DateTimeFormat(void 0, { timeZone: tz, dateStyle: "medium", timeStyle: "medium" }).format(t);
|
|
26
|
+
} catch {
|
|
27
|
+
return new Date(t).toISOString();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const fmtDur = (ms) => ms < 1e3 ? `${Math.round(ms)} ms` : ms < MIN ? `${(ms / 1e3).toFixed(1)} s` : gapLabel(ms);
|
|
31
|
+
const fmtNum = (n, unit) => unit === "bytes" ? n >= 1e9 ? `${(n / 1e9).toFixed(1)} GB` : n >= 1e6 ? `${(n / 1e6).toFixed(1)} MB` : n >= 1e3 ? `${(n / 1e3).toFixed(1)} kB` : `${Math.round(n)} B` : `${Math.round(n * 10) / 10}${unit === "count" ? "" : ` ${unit}`}`;
|
|
32
|
+
function modeFor(span, px) {
|
|
33
|
+
if (span <= 3 * HOUR) return { kind: "single" };
|
|
34
|
+
for (const b of ["1m", "1h", "1d"]) if (span / BIN_MS[b] <= px / 2) return { kind: "binned", bin: b };
|
|
35
|
+
return { kind: "binned", bin: "1d" };
|
|
36
|
+
}
|
|
37
|
+
function activityOf(r, mode, series) {
|
|
38
|
+
const out = [];
|
|
39
|
+
for (const e of r.events ?? []) {
|
|
40
|
+
out.push([e.t, e.t]);
|
|
41
|
+
if (e.dur !== void 0 && !e.open) out.push([e.t + e.dur, e.t + e.dur]);
|
|
42
|
+
}
|
|
43
|
+
for (const e of r.spans ?? []) {
|
|
44
|
+
out.push([e.t, e.t]);
|
|
45
|
+
if (e.dur !== void 0 && !e.open) out.push([e.t + e.dur, e.t + e.dur]);
|
|
46
|
+
}
|
|
47
|
+
const w = mode.kind === "binned" ? BIN_MS[mode.bin] : MIN;
|
|
48
|
+
for (const b of r.bins ?? []) if (b.count) out.push([b.t, b.t + BIN_MS[b.bin]]);
|
|
49
|
+
const last = /* @__PURE__ */ new Map();
|
|
50
|
+
for (const m of r.metrics) {
|
|
51
|
+
const v = "value" in m ? m.value : m.sum, k = `${m.series}|${m.scope}`;
|
|
52
|
+
const moved = (series?.get(m.series) ?? "counter") === "counter" ? v !== 0 : last.get(k) !== v;
|
|
53
|
+
last.set(k, v);
|
|
54
|
+
if (moved) out.push([m.t, m.t + w]);
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
function mountTimeline(el, o) {
|
|
59
|
+
const tz = o.tz ?? Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
60
|
+
const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
61
|
+
const motion = o.motion ?? !reduced;
|
|
62
|
+
el.classList.add(...o.rootClass ?? [], "tlx");
|
|
63
|
+
const { parseSearch, compileSearch } = searchFor(o.catalog);
|
|
64
|
+
const setTheme = (t = "system") => {
|
|
65
|
+
el.style.colorScheme = t === "system" ? "light dark" : t;
|
|
66
|
+
if (t === "system") delete el.dataset.theme;
|
|
67
|
+
else el.dataset.theme = t;
|
|
68
|
+
};
|
|
69
|
+
setTheme(o.theme);
|
|
70
|
+
el.setAttribute("role", "region");
|
|
71
|
+
el.setAttribute("aria-label", "Timeline");
|
|
72
|
+
let catalog;
|
|
73
|
+
let scope = "", depth = 1, q = "", filters = {}, live = false, collapse = o.collapseGaps ?? true;
|
|
74
|
+
let view = { t0: 0, t1: DAY };
|
|
75
|
+
let result, resultKey = "", loaded = { from: 0, to: 0, mode: { kind: "single" }, key: "" };
|
|
76
|
+
let playhead, playState, selected;
|
|
77
|
+
let brush;
|
|
78
|
+
let follow = true, frame = 0, fetching = 0, pending = false, unsub, warnings = [];
|
|
79
|
+
let hits = [], hitAt = -1;
|
|
80
|
+
const expanded = /* @__PURE__ */ new Set(), weights = /* @__PURE__ */ new Map();
|
|
81
|
+
let gaps = [], scale = timeScale(0, DAY, 800);
|
|
82
|
+
const seriesInfo = /* @__PURE__ */ new Map();
|
|
83
|
+
let sensitive = [];
|
|
84
|
+
const crumbsEl = h("nav", { class: "tlx-crumbs", "aria-label": "Scope" });
|
|
85
|
+
const quick = h("div", { class: "segmented tlx-quick", role: "group", "aria-label": "Range" });
|
|
86
|
+
for (const k of ["15m", "1h", "1d", "1w", "run"]) {
|
|
87
|
+
const b = h("button", { type: "button", class: "seg", "data-v": k, title: k === "run" ? "The latest run" : `The last ${k}` }, k === "run" ? "this run" : k);
|
|
88
|
+
b.addEventListener("click", () => setQuick(k));
|
|
89
|
+
quick.append(b);
|
|
90
|
+
}
|
|
91
|
+
const liveBtn = h("button", { type: "button", class: "btn sm tlx-live", "aria-pressed": "false", title: "Follow what happens now" }, "Live");
|
|
92
|
+
const nowBtn = h("button", { type: "button", class: "btn sm quiet tlx-now", hidden: true, title: "Back to the live edge" }, "Back to now");
|
|
93
|
+
const fitBtn = h("button", { type: "button", class: "btn sm quiet tlx-fit", title: "Everything in this scope" }, "Fit");
|
|
94
|
+
const gapsBox = h("input", { type: "checkbox", class: "tlx-gaps" });
|
|
95
|
+
gapsBox.checked = collapse;
|
|
96
|
+
let hideQuiet = true;
|
|
97
|
+
const quietBox = h("input", { type: "checkbox", class: "tlx-quiet" });
|
|
98
|
+
quietBox.checked = hideQuiet;
|
|
99
|
+
const search = h("input", { type: "search", class: "input tlx-q", placeholder: "Search: words, kind:\u2026, source:\u2026, severity:>=warning, -kind:\u2026", "aria-label": "Search the timeline", spellcheck: "false" });
|
|
100
|
+
const hitsEl = h("span", { class: "tlx-hits", role: "status", "aria-live": "polite" });
|
|
101
|
+
const prevBtn = h("button", { type: "button", class: "btn sm quiet tlx-prev", title: "Previous hit (\u21E7N)", "aria-label": "Previous hit" }, "\u2039");
|
|
102
|
+
const nextBtn = h("button", { type: "button", class: "btn sm quiet tlx-next", title: "Next hit (N)", "aria-label": "Next hit" }, "\u203A");
|
|
103
|
+
const facets = h("div", { class: "tlx-facets", role: "group", "aria-label": "Sources" });
|
|
104
|
+
const sevSel = h(
|
|
105
|
+
"select",
|
|
106
|
+
{ class: "input tlx-sev", "aria-label": "Severity" },
|
|
107
|
+
h("option", { value: "" }, "every severity"),
|
|
108
|
+
...SEVERITIES.slice(1).map((s) => h("option", { value: s }, `${s} and above`))
|
|
109
|
+
);
|
|
110
|
+
const viewsSel = h("select", { class: "input tlx-views", "aria-label": "Saved views", hidden: !o.views }, h("option", { value: "" }, "Saved views\u2026"));
|
|
111
|
+
const saveBtn = h("button", { type: "button", class: "btn sm quiet tlx-save", hidden: !o.saveView, title: "Save this view" }, "Save view");
|
|
112
|
+
const warnEl = h("div", { class: "tlx-warn", role: "status", hidden: true });
|
|
113
|
+
const status = h("div", { class: "tlx-status", role: "status" });
|
|
114
|
+
const canvasNote = h("span", { class: "tlx-canvas-note" });
|
|
115
|
+
const labels = h("div", { class: "tlx-labels" });
|
|
116
|
+
const lanes = h("div", { class: "tlx-lanes", tabindex: "0", role: "application", "aria-label": "Timeline lanes: drag to pan, wheel to zoom, drag the axis to choose a range, click it to move the playhead. Keys: \u2190 \u2192 pan, + \u2212 zoom, N next hit" });
|
|
117
|
+
const svg = svgEl("svg", { class: "tlx-svg" });
|
|
118
|
+
lanes.append(svg);
|
|
119
|
+
const scroller = h("div", { class: "tlx-scroll" }, h("div", { class: "tlx-grid" }, labels, lanes));
|
|
120
|
+
const table = h("section", { class: "tlx-table", hidden: true, "aria-label": "The events in the chosen range" });
|
|
121
|
+
const detail = h("aside", { class: "tlx-detail", hidden: true, "aria-label": "The event" });
|
|
122
|
+
el.replaceChildren(
|
|
123
|
+
h(
|
|
124
|
+
"div",
|
|
125
|
+
{ class: "tlx-bar" },
|
|
126
|
+
crumbsEl,
|
|
127
|
+
h("span", { class: "spacer" }),
|
|
128
|
+
quick,
|
|
129
|
+
liveBtn,
|
|
130
|
+
nowBtn,
|
|
131
|
+
fitBtn,
|
|
132
|
+
h("label", { class: "tlx-gaps-label", title: "Draw long empty stretches as narrow breaks" }, gapsBox, "Collapse gaps"),
|
|
133
|
+
h("label", { class: "tlx-gaps-label", title: "Hide the rows with nothing in this range" }, quietBox, "Hide quiet rows")
|
|
134
|
+
),
|
|
135
|
+
h("div", { class: "tlx-bar" }, search, hitsEl, prevBtn, nextBtn, sevSel, viewsSel, saveBtn),
|
|
136
|
+
facets,
|
|
137
|
+
warnEl,
|
|
138
|
+
h("div", { class: "tlx-body" }, scroller, detail),
|
|
139
|
+
h("div", { class: "tlx-foot" }, status, h("span", { class: "spacer" }), canvasNote),
|
|
140
|
+
table
|
|
141
|
+
);
|
|
142
|
+
const width = () => Math.max(200, lanes.clientWidth || 800);
|
|
143
|
+
const lines = () => {
|
|
144
|
+
const collate = (a, b) => (a.own ? -1 : 0) - (b.own ? -1 : 0) || a.scope.localeCompare(b.scope, void 0, { numeric: true });
|
|
145
|
+
const shown = (result?.rows ?? []).filter((r) => !hideQuiet || r.count > 0 || r.own || (result?.rows.length ?? 0) <= 1).sort(collate);
|
|
146
|
+
const rs = shown.map((row) => ({ kind: "row", row }));
|
|
147
|
+
const present = new Set(result?.metrics.map((m) => m.series) ?? []);
|
|
148
|
+
for (const s of [...present].sort()) {
|
|
149
|
+
const i = seriesInfo.get(s);
|
|
150
|
+
rs.push({ kind: "metric", series: s, unit: i?.unit ?? "count", type: i?.type ?? "counter", title: i?.title ?? s });
|
|
151
|
+
}
|
|
152
|
+
return rs;
|
|
153
|
+
};
|
|
154
|
+
const labelOf = (s, fallback) => catalog?.names?.find((n) => n.scope === s)?.label ?? fallback;
|
|
155
|
+
const lineH = (l) => l.kind === "metric" ? MROW : ROW;
|
|
156
|
+
const mode = () => modeFor(view.t1 - view.t0, width());
|
|
157
|
+
const nowT = () => catalog?.now ?? Date.now();
|
|
158
|
+
function currentView() {
|
|
159
|
+
return { timeline: 1, type: "view", name: "", scope, depth, range: { from: Math.round(view.t0), to: Math.round(view.t1) }, ...q ? { q } : {}, ...Object.keys(filters).length ? { filters } : {}, ...live ? { live } : {}, ...collapse ? {} : { collapseGaps: false }, ...hideQuiet ? {} : { quietRows: true } };
|
|
160
|
+
}
|
|
161
|
+
function applyView(v) {
|
|
162
|
+
if (v.scope !== void 0) scope = v.scope;
|
|
163
|
+
if (v.depth !== void 0) depth = v.depth;
|
|
164
|
+
q = v.q ?? "";
|
|
165
|
+
search.value = q;
|
|
166
|
+
filters = v.filters ?? {};
|
|
167
|
+
sevSel.value = filters.severity?.length ? filters.severity[0] : "";
|
|
168
|
+
collapse = v.collapseGaps ?? (o.collapseGaps ?? true);
|
|
169
|
+
gapsBox.checked = collapse;
|
|
170
|
+
hideQuiet = !v.quietRows;
|
|
171
|
+
quietBox.checked = hideQuiet;
|
|
172
|
+
expanded.clear();
|
|
173
|
+
weights.clear();
|
|
174
|
+
const r = v.range;
|
|
175
|
+
if (r && "last" in r) setQuick(r.last, false);
|
|
176
|
+
else if (r) view = { t0: r.from, t1: r.to };
|
|
177
|
+
setLive(!!v.live, false);
|
|
178
|
+
}
|
|
179
|
+
const writeUrl = () => {
|
|
180
|
+
const v = currentView();
|
|
181
|
+
o.onViewChange?.(v);
|
|
182
|
+
if (!o.urlState) return;
|
|
183
|
+
try {
|
|
184
|
+
history.replaceState(null, "", `#timeline=${encodeURIComponent(JSON.stringify(v))}`);
|
|
185
|
+
} catch {
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
const readUrl = () => {
|
|
189
|
+
if (!o.urlState) return void 0;
|
|
190
|
+
const m = /#timeline=(.+)$/.exec(location.hash);
|
|
191
|
+
if (!m) return void 0;
|
|
192
|
+
try {
|
|
193
|
+
return JSON.parse(decodeURIComponent(m[1]));
|
|
194
|
+
} catch {
|
|
195
|
+
return void 0;
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
function query(from, to, md, extra = {}) {
|
|
199
|
+
const c = compileSearch(q, nowT(), from, to);
|
|
200
|
+
warnings = c.warnings;
|
|
201
|
+
const series = q ? [] : filters.source ? [...seriesInfo].filter(([, i]) => filters.source.includes(i.source)).map(([n]) => n) : void 0;
|
|
202
|
+
return { timeline: 1, type: "query", scope, depth, from: c.from, to: c.to, tz, ...md.kind === "binned" ? { bin: md.bin } : {}, ...q ? { q, where: c.where } : {}, ...Object.keys(filters).length ? { filters } : {}, ...series ? { series } : {}, ...extra };
|
|
203
|
+
}
|
|
204
|
+
const keyOf = () => JSON.stringify([scope, depth, q, filters, mode()]);
|
|
205
|
+
async function refresh(force = false) {
|
|
206
|
+
const md = mode(), key = keyOf(), span = view.t1 - view.t0;
|
|
207
|
+
if (!force && result && key === loaded.key && view.t0 >= loaded.from && view.t1 <= loaded.to) {
|
|
208
|
+
later();
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (fetching) {
|
|
212
|
+
pending = true;
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
fetching++;
|
|
216
|
+
const from = view.t0 - span / 2, to = Math.min(view.t1 + span / 2, Math.max(view.t1, nowT() + span * 0.1));
|
|
217
|
+
try {
|
|
218
|
+
let r = await o.source.query(query(from, to, md, md.kind === "single" ? { limit: 1e4 } : {}));
|
|
219
|
+
if (md.kind === "single" && r.next) r = await o.source.query(query(from, to, { kind: "binned", bin: "1m" }));
|
|
220
|
+
result = r;
|
|
221
|
+
resultKey = key;
|
|
222
|
+
loaded = { from, to, mode: md, key };
|
|
223
|
+
} catch (err) {
|
|
224
|
+
status.textContent = `The history couldn't be read: ${String(err?.message ?? err)}`;
|
|
225
|
+
} finally {
|
|
226
|
+
fetching--;
|
|
227
|
+
}
|
|
228
|
+
later();
|
|
229
|
+
writeUrl();
|
|
230
|
+
if (pending) {
|
|
231
|
+
pending = false;
|
|
232
|
+
void refresh();
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function makeScale() {
|
|
236
|
+
const W = width(), md = mode();
|
|
237
|
+
gaps = [];
|
|
238
|
+
if (collapse && result) {
|
|
239
|
+
const types = new Map([...seriesInfo].map(([k, v]) => [k, v.type]));
|
|
240
|
+
gaps = findGaps(activityOf(result, md, types), view.t0, Math.min(view.t1, Math.max(view.t0, nowT())), { minFrac: 0.15, minMs: 10 * MIN });
|
|
241
|
+
if (md.kind === "binned") gaps = gaps.filter((g) => g.to - g.from >= 2 * BIN_MS[md.bin]);
|
|
242
|
+
gaps = gaps.filter((g) => !(expanded.has(gapKey(g)) && (weights.get(gapKey(g)) ?? 1) >= 1));
|
|
243
|
+
}
|
|
244
|
+
scale = timeScale(view.t0, view.t1, W, gaps, { cut: CUT, weights });
|
|
245
|
+
}
|
|
246
|
+
const later = () => {
|
|
247
|
+
if (!frame) frame = requestAnimationFrame(paint);
|
|
248
|
+
};
|
|
249
|
+
function paint() {
|
|
250
|
+
frame = 0;
|
|
251
|
+
makeScale();
|
|
252
|
+
const W = width(), L = lines(), md = loaded.mode;
|
|
253
|
+
const ys = [];
|
|
254
|
+
let y = AXIS;
|
|
255
|
+
for (const l of L) {
|
|
256
|
+
ys.push(y);
|
|
257
|
+
y += lineH(l);
|
|
258
|
+
}
|
|
259
|
+
const H = Math.max(y, AXIS + ROW);
|
|
260
|
+
svg.setAttribute("width", String(W));
|
|
261
|
+
svg.setAttribute("height", String(H));
|
|
262
|
+
svg.setAttribute("viewBox", `0 0 ${W} ${H}`);
|
|
263
|
+
const top = scroller.scrollTop - 200, bottom = scroller.scrollTop + (scroller.clientHeight || 600) + 200;
|
|
264
|
+
const kids = [];
|
|
265
|
+
const x = scale.x;
|
|
266
|
+
kids.push(svgEl("rect", { class: "tlx-axis", x: 0, y: 0, width: W, height: AXIS }));
|
|
267
|
+
const kept = (result?.retention ?? []).map((r) => ({ r, from: md.kind === "binned" ? r.keptFrom.rollups[md.bin] ?? r.keptFrom.events : r.keptFrom.events, days: md.kind === "binned" ? r.rollups[md.bin] : r.events }));
|
|
268
|
+
const held = kept.filter((k) => k.from !== void 0);
|
|
269
|
+
if (held.length) {
|
|
270
|
+
const first = Math.min(...held.map((k) => k.from));
|
|
271
|
+
if (first > view.t0) kids.push(svgEl(
|
|
272
|
+
"rect",
|
|
273
|
+
{ class: "tlx-notkept", x: Math.max(0, x(view.t0)), y: AXIS, width: Math.max(0, x(first) - Math.max(0, x(view.t0))), height: H - AXIS },
|
|
274
|
+
`Nothing kept before ${fmtTime(first, tz)}: ${held.map((k) => `${k.r.source} ${k.days === null ? "kept until deleted" : `kept ${k.days} days`}`).join(", ")}`
|
|
275
|
+
));
|
|
276
|
+
}
|
|
277
|
+
const now = nowT();
|
|
278
|
+
if (now < view.t1) kids.push(svgEl("rect", { class: "tlx-future", x: x(now), y: AXIS, width: W - x(now), height: H - AXIS }));
|
|
279
|
+
for (const tk of ticks(scale, tz, 90)) {
|
|
280
|
+
kids.push(svgEl("line", { class: `tlx-tick${tk.major ? " major" : ""}`, x1: tk.x, x2: tk.x, y1: AXIS - 6, y2: H }));
|
|
281
|
+
const lab = svgEl("text", { class: "tlx-ticklabel", x: tk.x + 3, y: 16 });
|
|
282
|
+
lab.textContent = tk.label;
|
|
283
|
+
kids.push(lab);
|
|
284
|
+
}
|
|
285
|
+
if (brush) kids.push(svgEl("rect", { class: "tlx-brush", x: x(brush.from), y: 0, width: Math.max(1, x(brush.to) - x(brush.from)), height: H }));
|
|
286
|
+
const spans = md.kind === "single" ? (result?.events ?? []).filter((e) => e.dur !== void 0 || e.open) : result?.spans ?? [];
|
|
287
|
+
const marks = md.kind === "single" ? (result?.events ?? []).filter((e) => e.dur === void 0 && !e.open) : [];
|
|
288
|
+
const rowIndex = /* @__PURE__ */ new Map();
|
|
289
|
+
L.forEach((l, i) => {
|
|
290
|
+
if (l.kind === "row") rowIndex.set(l.row.scope, i);
|
|
291
|
+
});
|
|
292
|
+
const rowOfScope = (s) => {
|
|
293
|
+
const lvl = levelOf(scope) + depth;
|
|
294
|
+
const r = levelOf(s) >= lvl ? prefixAt(s, lvl) : s;
|
|
295
|
+
return rowIndex.get(r);
|
|
296
|
+
};
|
|
297
|
+
const visible = (i) => ys[i] + lineH(L[i]) >= top && ys[i] <= bottom;
|
|
298
|
+
L.forEach((l, i) => {
|
|
299
|
+
if (visible(i)) kids.push(svgEl("rect", { class: `tlx-lane${i % 2 ? " odd" : ""}${l.kind === "metric" ? " metric" : ""}`, x: 0, y: ys[i], width: W, height: lineH(l) }));
|
|
300
|
+
});
|
|
301
|
+
if (md.kind === "binned") {
|
|
302
|
+
const max = /* @__PURE__ */ new Map();
|
|
303
|
+
for (const b of result?.bins ?? []) {
|
|
304
|
+
const i = rowOfScope(b.scope);
|
|
305
|
+
if (i !== void 0) max.set(i, Math.max(max.get(i) ?? 0, b.count));
|
|
306
|
+
}
|
|
307
|
+
for (const b of result?.bins ?? []) {
|
|
308
|
+
const i = rowOfScope(b.scope);
|
|
309
|
+
if (i === void 0 || !visible(i)) continue;
|
|
310
|
+
const a = x(b.t), z = x(b.t + BIN_MS[b.bin]);
|
|
311
|
+
if (z < 0 || a > W) continue;
|
|
312
|
+
const worst = [...SEVERITIES].reverse().find((s) => (b.severity[s] ?? 0) > 0) ?? "info";
|
|
313
|
+
const hgt = Math.max(2, (ROW - 8) * Math.sqrt(b.count) / Math.sqrt(max.get(i) || 1));
|
|
314
|
+
kids.push(svgEl(
|
|
315
|
+
"rect",
|
|
316
|
+
{ class: "tlx-countbar", x: a, y: ys[i] + ROW - 3 - hgt, width: Math.max(1, z - a - 0.5), height: hgt, "data-t": b.t },
|
|
317
|
+
`${fmtTime(b.t, tz)}: ${b.count} event${b.count === 1 ? "" : "s"}${worst !== "info" && worst !== "debug" ? `, the worst ${worst}` : ""}`
|
|
318
|
+
));
|
|
319
|
+
if (worst === "warning" || worst === "error") kids.push(svgEl("rect", { class: `tlx-heat sev-${worst}`, x: a, y: ys[i] + ROW - (worst === "error" ? 4 : 3), width: Math.max(1, z - a - 0.5), height: worst === "error" ? 3 : 2 }));
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
for (const e of spans) {
|
|
323
|
+
const i = rowOfScope(e.scope);
|
|
324
|
+
if (i === void 0 || !visible(i)) continue;
|
|
325
|
+
const end = e.open ? now : e.t + (e.dur ?? 0);
|
|
326
|
+
const a = x(e.t), z = x(end);
|
|
327
|
+
if (z < -2 || a > W + 2) continue;
|
|
328
|
+
const cls = `tlx-span sev-${e.severity}${e.open ? " open" : ""}${selected?.id === e.id ? " selected" : ""}`;
|
|
329
|
+
const label = `${e.summary} \xB7 ${fmtTime(e.t, tz)}${e.open ? ", still going" : `, ${fmtDur(end - e.t)}`}`;
|
|
330
|
+
const sy = ys[i] + 5, sh = md.kind === "binned" ? 4 : 8;
|
|
331
|
+
let pa = a;
|
|
332
|
+
for (const c of scale.cuts) {
|
|
333
|
+
if (c.weight >= 1 || c.x1 <= a || c.x0 >= z) continue;
|
|
334
|
+
if (c.x0 > pa) kids.push(svgEl("rect", { class: cls, x: pa, y: sy, width: Math.max(1, c.x0 - pa), height: sh, rx: 2, "data-id": e.id }, label));
|
|
335
|
+
kids.push(svgEl("path", { class: `${cls} through`, d: `M${c.x0} ${sy + sh / 2} H${c.x1}`, "data-id": e.id }, `${label} (lasted through the break)`));
|
|
336
|
+
pa = c.x1;
|
|
337
|
+
}
|
|
338
|
+
if (z > pa) kids.push(svgEl("rect", { class: cls, x: Math.max(-2, pa), y: sy, width: Math.max(2, Math.min(W + 2, z) - Math.max(-2, pa)), height: sh, rx: 2, "data-id": e.id }, label));
|
|
339
|
+
}
|
|
340
|
+
const lastX = /* @__PURE__ */ new Map();
|
|
341
|
+
for (const e of marks) {
|
|
342
|
+
const i = rowOfScope(e.scope);
|
|
343
|
+
if (i === void 0 || !visible(i)) continue;
|
|
344
|
+
const px = x(e.t);
|
|
345
|
+
if (px < -6 || px > W + 6 || px - (lastX.get(i) ?? -Infinity) < 3) continue;
|
|
346
|
+
lastX.set(i, px);
|
|
347
|
+
const cy = ys[i] + ROW / 2 + 2, r = 4;
|
|
348
|
+
const shape = SHAPE[e.severity];
|
|
349
|
+
const d = shape === "diamond" ? `M${px} ${cy - r - 1} l${r + 1} ${r + 1} l${-r - 1} ${r + 1} l${-r - 1} ${-r - 1} z` : shape === "triangle" ? `M${px} ${cy - r - 1} l${r + 1} ${2 * r + 1} h${-2 * r - 2} z` : shape === "square" ? `M${px - r + 0.5} ${cy - r + 0.5} h${2 * r - 1} v${2 * r - 1} h${-2 * r + 1} z` : "";
|
|
350
|
+
const title = `${fmtTime(e.t, tz)} \xB7 ${e.summary}`;
|
|
351
|
+
const cls = `tlx-mark sev-${e.severity}${selected?.id === e.id ? " selected" : ""}${hitAt >= 0 && hits[hitAt]?.id === e.id ? " hit" : ""}`;
|
|
352
|
+
kids.push(d ? svgEl("path", { class: cls, d, "data-id": e.id }, title) : svgEl("circle", { class: cls, cx: px, cy, r: shape === "dot" ? 2.5 : r, "data-id": e.id }, title));
|
|
353
|
+
}
|
|
354
|
+
L.forEach((l, i) => {
|
|
355
|
+
if (l.kind !== "metric" || !visible(i)) return;
|
|
356
|
+
const pts = /* @__PURE__ */ new Map();
|
|
357
|
+
for (const m of result?.metrics ?? []) {
|
|
358
|
+
if (m.series !== l.series) continue;
|
|
359
|
+
const f = "value" in m ? { min: m.value, max: m.value, sum: m.value, count: 1 } : { min: m.min, max: m.max, sum: m.sum, count: m.count };
|
|
360
|
+
const p = pts.get(m.t);
|
|
361
|
+
if (p) {
|
|
362
|
+
p.min = Math.min(p.min, f.min);
|
|
363
|
+
p.max = Math.max(p.max, f.max);
|
|
364
|
+
p.sum += f.sum;
|
|
365
|
+
p.count += f.count;
|
|
366
|
+
} else pts.set(m.t, { ...f });
|
|
367
|
+
}
|
|
368
|
+
const series = [...pts].sort((a, b) => a[0] - b[0]);
|
|
369
|
+
if (!series.length) return;
|
|
370
|
+
const w = md.kind === "binned" ? BIN_MS[md.bin] : MIN;
|
|
371
|
+
const val = (p) => l.type === "gauge" ? p.sum / Math.max(1, p.count) : p.sum;
|
|
372
|
+
const peak = Math.max(1e-9, ...series.map(([, p]) => l.type === "gauge" ? p.max : val(p)));
|
|
373
|
+
const base = ys[i] + MROW - 4, hh = MROW - 10, yv = (v) => base - v / peak * hh;
|
|
374
|
+
if (l.type === "gauge") {
|
|
375
|
+
const band = series.map(([t, p]) => `${x(t)},${yv(p.max)}`).join(" ") + " " + [...series].reverse().map(([t, p]) => `${x(t)},${yv(p.min)}`).join(" ");
|
|
376
|
+
kids.push(svgEl("polygon", { class: "tlx-band", points: band }));
|
|
377
|
+
kids.push(svgEl("polyline", { class: "tlx-line", points: series.map(([t, p]) => `${x(t + w / 2)},${yv(val(p))}`).join(" ") }));
|
|
378
|
+
} else {
|
|
379
|
+
let d = "", prevEnd = -Infinity;
|
|
380
|
+
for (const [t, p] of series) {
|
|
381
|
+
const a = x(t), z = x(t + w), v = yv(val(p));
|
|
382
|
+
d += t > prevEnd ? `M${a} ${base} V${v} H${z}` : ` V${v} H${z}`;
|
|
383
|
+
prevEnd = t + w;
|
|
384
|
+
const nxt = series.find(([t2]) => t2 > t);
|
|
385
|
+
if (!nxt || nxt[0] > prevEnd) d += ` V${base} Z`;
|
|
386
|
+
}
|
|
387
|
+
kids.push(svgEl("path", { class: "tlx-area", d }));
|
|
388
|
+
}
|
|
389
|
+
const lab = svgEl("text", { class: "tlx-peak", x: 4, y: ys[i] + 11 });
|
|
390
|
+
lab.textContent = `peak ${fmtNum(peak, l.unit)}${l.type === "counter" ? ` per ${md.kind === "binned" ? md.bin : "1m"}` : ""}`;
|
|
391
|
+
kids.push(lab);
|
|
392
|
+
});
|
|
393
|
+
for (const c of scale.cuts) {
|
|
394
|
+
if (c.weight >= 1) continue;
|
|
395
|
+
const teeth = (xx) => {
|
|
396
|
+
let d = `M${xx} 0`;
|
|
397
|
+
for (let yy = 0; yy < H; yy += 8) d += ` L${xx + (yy / 8 % 2 ? -3 : 3)} ${yy + 8}`;
|
|
398
|
+
return d;
|
|
399
|
+
};
|
|
400
|
+
const g = svgEl(
|
|
401
|
+
"g",
|
|
402
|
+
{ class: "tlx-cut", tabindex: 0, role: "button", "data-from": c.from, "data-to": c.to, "aria-label": `A break of ${gapLabel(c.to - c.from)} with nothing shown, from ${fmtTime(c.from, tz)} to ${fmtTime(c.to, tz)}: press to open it` },
|
|
403
|
+
`${gapLabel(c.to - c.from)} with nothing here: ${fmtTime(c.from, tz)} to ${fmtTime(c.to, tz)} (click to open)`
|
|
404
|
+
);
|
|
405
|
+
g.append(svgEl("rect", { class: "tlx-cut-bg", x: c.x0, y: 0, width: c.x1 - c.x0, height: H }));
|
|
406
|
+
g.append(svgEl("path", { class: "tlx-cut-edge", d: teeth(c.x0 + 3) }), svgEl("path", { class: "tlx-cut-edge", d: teeth(c.x1 - 3) }));
|
|
407
|
+
const t = svgEl("text", { class: "tlx-cut-label", x: (c.x0 + c.x1) / 2, y: 15, "text-anchor": "middle" });
|
|
408
|
+
t.textContent = gapLabel(c.to - c.from);
|
|
409
|
+
g.append(t);
|
|
410
|
+
kids.push(g);
|
|
411
|
+
}
|
|
412
|
+
if (playhead !== void 0) {
|
|
413
|
+
const px = x(playhead);
|
|
414
|
+
kids.push(svgEl("line", { class: "tlx-playhead", x1: px, x2: px, y1: 0, y2: H }));
|
|
415
|
+
kids.push(svgEl("path", { class: "tlx-handle", d: `M${px - 6} 0 h12 v8 l-6 7 l-6 -7 z` }, `the playhead: ${fmtTime(playhead, tz)}`));
|
|
416
|
+
}
|
|
417
|
+
svg.replaceChildren(...kids);
|
|
418
|
+
labels.replaceChildren(
|
|
419
|
+
h("div", { class: "tlx-labelhead", style: `height:${AXIS}px` }, mode().kind === "single" ? "single events" : `per ${mode().kind === "binned" ? mode().bin : ""}`),
|
|
420
|
+
...L.map((l) => {
|
|
421
|
+
if (l.kind === "metric") return h("div", { class: "tlx-rowlabel metric", style: `height:${MROW}px`, title: `${l.title} (${l.type === "counter" ? "sums" : "min, max and mean"})` }, l.title);
|
|
422
|
+
const r = l.row;
|
|
423
|
+
const lab = h(
|
|
424
|
+
"div",
|
|
425
|
+
{ class: `tlx-rowlabel${r.own ? " own" : ""}`, style: `height:${ROW}px`, "data-scope": r.scope, title: `${r.scope || "all hosts"} \xB7 ${r.count} event${r.count === 1 ? "" : "s"}` },
|
|
426
|
+
h("span", { class: "tlx-kind" }, o.catalog.flags.find((f) => r[f]) ?? r.kind),
|
|
427
|
+
h("span", { class: "tlx-name" }, r.own ? `${r.label} (itself)` : r.label),
|
|
428
|
+
h("span", { class: "tlx-count" }, String(r.count))
|
|
429
|
+
);
|
|
430
|
+
if (!r.own && r.scope !== scope) {
|
|
431
|
+
const b = h("button", { type: "button", class: "tlx-drill", title: r.children ? `Into ${r.label}: its ${r.children} part${r.children === 1 ? "" : "s"}` : `Into ${r.label}`, "aria-label": `Into ${r.label}` }, "\u203A");
|
|
432
|
+
b.addEventListener("click", () => drill(r.scope));
|
|
433
|
+
lab.append(b);
|
|
434
|
+
}
|
|
435
|
+
return lab;
|
|
436
|
+
})
|
|
437
|
+
);
|
|
438
|
+
labels.style.width = `${LABELS}px`;
|
|
439
|
+
paintChrome();
|
|
440
|
+
}
|
|
441
|
+
function paintChrome() {
|
|
442
|
+
crumbsEl.replaceChildren(...crumbs(scope).flatMap((c, i, all) => {
|
|
443
|
+
const b = h("button", { type: "button", class: `tlx-crumb${i === all.length - 1 ? " current" : ""}`, "aria-current": i === all.length - 1 ? "location" : void 0 }, labelOf(c.scope, c.label));
|
|
444
|
+
b.addEventListener("click", () => {
|
|
445
|
+
if (c.scope !== scope) {
|
|
446
|
+
scope = c.scope;
|
|
447
|
+
depth = 1;
|
|
448
|
+
void refresh(true);
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
return i ? [h("span", { class: "tlx-sep", "aria-hidden": "true" }, "/"), b] : [b];
|
|
452
|
+
}));
|
|
453
|
+
liveBtn.setAttribute("aria-pressed", String(live));
|
|
454
|
+
liveBtn.classList.toggle("on", live);
|
|
455
|
+
nowBtn.hidden = !live || follow;
|
|
456
|
+
const md = mode();
|
|
457
|
+
const total = result?.total ?? 0;
|
|
458
|
+
const kept = (result?.retention ?? []).filter((r) => r.events !== null).map((r) => `${r.source} kept ${r.events} d`);
|
|
459
|
+
status.textContent = `${fmtTime(view.t0, tz)} \u2013 ${fmtTime(view.t1, tz)} \xB7 ${md.kind === "single" ? "single events" : `bins of ${md.bin}`} \xB7 ${total} event${total === 1 ? "" : "s"}${gaps.length ? ` \xB7 ${gaps.length} break${gaps.length === 1 ? "" : "s"}` : ""}${kept.length ? ` \xB7 ${kept.slice(0, 3).join(", ")}` : ""}`;
|
|
460
|
+
warnEl.hidden = !warnings.length;
|
|
461
|
+
warnEl.textContent = warnings.join(" \xB7 ");
|
|
462
|
+
hitsEl.textContent = q ? hits.length ? `${hitAt + 1 > 0 ? `${hitAt + 1} of ` : ""}${hits.length}${hits.length >= 2e3 ? "+" : ""} hit${hits.length === 1 ? "" : "s"}` : `${total ? `${total} hit${total === 1 ? "" : "s"}` : "no hits"}` : "";
|
|
463
|
+
for (const b of quick.querySelectorAll(".seg")) b.classList.remove("on");
|
|
464
|
+
canvasNote.textContent = playhead === void 0 ? "" : playState ? (() => {
|
|
465
|
+
const st = o.stamp?.(playState) ?? {};
|
|
466
|
+
return `Canvas: the state recorded at ${fmtTime(Date.parse(st.at ?? "") || playhead, tz)}${st.tag ? ` (${st.tag})` : ""}`;
|
|
467
|
+
})() : "No state recorded here";
|
|
468
|
+
canvasNote.classList.toggle("none", playhead !== void 0 && !playState);
|
|
469
|
+
}
|
|
470
|
+
function paintFacets() {
|
|
471
|
+
facets.replaceChildren();
|
|
472
|
+
for (const s of catalog?.sources ?? []) {
|
|
473
|
+
const on = !filters.source?.length || filters.source.includes(s.name);
|
|
474
|
+
const b = h("button", {
|
|
475
|
+
type: "button",
|
|
476
|
+
class: `tlx-chip${on ? " on" : ""}${s.status === "not-yet" ? " notyet" : ""}`,
|
|
477
|
+
"aria-pressed": String(on && s.status !== "not-yet"),
|
|
478
|
+
disabled: s.status === "not-yet",
|
|
479
|
+
title: s.status === "not-yet" ? `${s.title}: not kept yet` : `${s.title}${retentionText(s)}`
|
|
480
|
+
}, s.name);
|
|
481
|
+
if (s.status !== "not-yet") b.addEventListener("click", () => toggleSource(s.name));
|
|
482
|
+
facets.append(b);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
const retentionText = (s) => {
|
|
486
|
+
const r = catalog?.retention.find((x) => x.source === s.name);
|
|
487
|
+
return r ? ` (kept ${r.events === null ? "until deleted" : `${r.events} days`})` : "";
|
|
488
|
+
};
|
|
489
|
+
function toggleSource(name) {
|
|
490
|
+
const all = (catalog?.sources ?? []).filter((s) => s.status === "kept").map((s) => s.name);
|
|
491
|
+
let cur = filters.source?.length ? [...filters.source] : [...all];
|
|
492
|
+
cur = cur.includes(name) ? cur.filter((x) => x !== name) : [...cur, name];
|
|
493
|
+
filters = { ...filters, ...cur.length === all.length ? { source: void 0 } : { source: cur } };
|
|
494
|
+
if (!filters.source) delete filters.source;
|
|
495
|
+
paintFacets();
|
|
496
|
+
void refresh(true);
|
|
497
|
+
void findHits();
|
|
498
|
+
}
|
|
499
|
+
let typing = 0;
|
|
500
|
+
search.addEventListener("input", () => {
|
|
501
|
+
clearTimeout(typing);
|
|
502
|
+
typing = setTimeout(() => {
|
|
503
|
+
q = search.value.trim();
|
|
504
|
+
hitAt = -1;
|
|
505
|
+
void refresh(true);
|
|
506
|
+
void findHits();
|
|
507
|
+
}, 250);
|
|
508
|
+
});
|
|
509
|
+
search.addEventListener("keydown", (e) => {
|
|
510
|
+
if (e.key === "Enter") {
|
|
511
|
+
e.preventDefault();
|
|
512
|
+
clearTimeout(typing);
|
|
513
|
+
q = search.value.trim();
|
|
514
|
+
void refresh(true).then(() => findHits()).then(() => stepHit(e.shiftKey ? -1 : 1));
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
async function findHits() {
|
|
518
|
+
if (!q) {
|
|
519
|
+
hits = [];
|
|
520
|
+
hitAt = -1;
|
|
521
|
+
paintChrome();
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
const span = view.t1 - view.t0;
|
|
525
|
+
const r = await o.source.query(query(view.t0 - span * 4, Math.max(view.t1 + span * 4, nowT()), { kind: "single" }, { limit: 2e3 }));
|
|
526
|
+
hits = r.events ?? [];
|
|
527
|
+
hitAt = Math.min(hitAt, hits.length - 1);
|
|
528
|
+
paintChrome();
|
|
529
|
+
}
|
|
530
|
+
function stepHit(dir) {
|
|
531
|
+
if (!hits.length) return;
|
|
532
|
+
const center = (view.t0 + view.t1) / 2;
|
|
533
|
+
if (hitAt < 0) hitAt = dir > 0 ? Math.max(0, hits.findIndex((e2) => e2.t >= center)) : Math.max(0, hits.length - 1 - [...hits].reverse().findIndex((e2) => e2.t <= center));
|
|
534
|
+
else hitAt = (hitAt + dir + hits.length) % hits.length;
|
|
535
|
+
const e = hits[hitAt];
|
|
536
|
+
const span = Math.min(view.t1 - view.t0, 2 * HOUR);
|
|
537
|
+
view = { t0: e.t - span / 2, t1: e.t + span / 2 };
|
|
538
|
+
follow = false;
|
|
539
|
+
select(e);
|
|
540
|
+
void refresh();
|
|
541
|
+
}
|
|
542
|
+
prevBtn.addEventListener("click", () => stepHit(-1));
|
|
543
|
+
nextBtn.addEventListener("click", () => stepHit(1));
|
|
544
|
+
sevSel.addEventListener("change", () => {
|
|
545
|
+
const v = sevSel.value;
|
|
546
|
+
filters = { ...filters, ...v ? { severity: SEVERITIES.filter((s) => SEV_RANK(s) >= SEV_RANK(v)) } : {} };
|
|
547
|
+
if (!v) delete filters.severity;
|
|
548
|
+
void refresh(true);
|
|
549
|
+
void findHits();
|
|
550
|
+
});
|
|
551
|
+
async function setQuick(k, go = true) {
|
|
552
|
+
const now = nowT();
|
|
553
|
+
if (k === "run") {
|
|
554
|
+
const r = await o.source.query({ timeline: 1, type: "query", scope, depth: 0, from: now - 30 * DAY, to: now + 1, filters: { kind: ["run"] }, limit: 1e4 }).catch(() => void 0);
|
|
555
|
+
const run = r?.events?.[r.events.length - 1];
|
|
556
|
+
view = run ? { t0: run.t - (run.dur ?? HOUR) * 0.02, t1: (run.open ? now : run.t + (run.dur ?? HOUR)) + (run.dur ?? HOUR) * 0.04 } : { t0: now - DAY, t1: now + DAY * 0.02 };
|
|
557
|
+
} else view = { t0: now - QUICK[k], t1: now + QUICK[k] * 0.02 };
|
|
558
|
+
follow = true;
|
|
559
|
+
expanded.clear();
|
|
560
|
+
weights.clear();
|
|
561
|
+
if (go) void refresh();
|
|
562
|
+
}
|
|
563
|
+
function setLive(on, go = true) {
|
|
564
|
+
live = on;
|
|
565
|
+
unsub?.();
|
|
566
|
+
unsub = void 0;
|
|
567
|
+
if (on && o.source.subscribe) {
|
|
568
|
+
let last = 0, wait = 0;
|
|
569
|
+
unsub = o.source.subscribe(query(nowT() - HOUR, nowT() + 365 * DAY, { kind: "single" }), (b) => {
|
|
570
|
+
if (catalog) catalog.now = Math.max(catalog.now, b.now);
|
|
571
|
+
if (follow) {
|
|
572
|
+
const span = view.t1 - view.t0;
|
|
573
|
+
view = { t0: b.now - span * 0.98, t1: b.now + span * 0.02 };
|
|
574
|
+
}
|
|
575
|
+
const t = Date.now();
|
|
576
|
+
if (t - last > 500) {
|
|
577
|
+
last = t;
|
|
578
|
+
void refresh(true);
|
|
579
|
+
} else if (!wait) wait = setTimeout(() => {
|
|
580
|
+
wait = 0;
|
|
581
|
+
last = Date.now();
|
|
582
|
+
void refresh(true);
|
|
583
|
+
}, 500);
|
|
584
|
+
});
|
|
585
|
+
follow = true;
|
|
586
|
+
}
|
|
587
|
+
if (go) {
|
|
588
|
+
paintChrome();
|
|
589
|
+
writeUrl();
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
liveBtn.addEventListener("click", () => setLive(!live));
|
|
593
|
+
nowBtn.addEventListener("click", () => {
|
|
594
|
+
follow = true;
|
|
595
|
+
const span = view.t1 - view.t0, now = nowT();
|
|
596
|
+
view = { t0: now - span * 0.98, t1: now + span * 0.02 };
|
|
597
|
+
void refresh();
|
|
598
|
+
});
|
|
599
|
+
fitBtn.addEventListener("click", () => void fit());
|
|
600
|
+
gapsBox.addEventListener("change", () => {
|
|
601
|
+
collapse = gapsBox.checked;
|
|
602
|
+
expanded.clear();
|
|
603
|
+
weights.clear();
|
|
604
|
+
later();
|
|
605
|
+
writeUrl();
|
|
606
|
+
});
|
|
607
|
+
quietBox.addEventListener("change", () => {
|
|
608
|
+
hideQuiet = quietBox.checked;
|
|
609
|
+
later();
|
|
610
|
+
writeUrl();
|
|
611
|
+
});
|
|
612
|
+
function drill(s) {
|
|
613
|
+
const row = result?.rows.find((r) => r.scope === s);
|
|
614
|
+
scope = s;
|
|
615
|
+
depth = row && row.children === 0 ? 0 : 1;
|
|
616
|
+
brush = void 0;
|
|
617
|
+
table.hidden = true;
|
|
618
|
+
void refresh(true);
|
|
619
|
+
}
|
|
620
|
+
async function fit() {
|
|
621
|
+
const now = nowT();
|
|
622
|
+
const r = await o.source.query({ timeline: 1, type: "query", scope, depth: 0, from: now - 400 * DAY, to: now + 1, bin: "1d", tz }).catch(() => void 0);
|
|
623
|
+
const ts = (r?.bins ?? []).map((b) => b.t);
|
|
624
|
+
const t0 = ts.length ? Math.min(...ts) : now - 7 * DAY;
|
|
625
|
+
view = { t0, t1: now + (now - t0) * 0.02 };
|
|
626
|
+
follow = true;
|
|
627
|
+
void refresh();
|
|
628
|
+
}
|
|
629
|
+
let stateReq = 0;
|
|
630
|
+
async function setPlayhead(t) {
|
|
631
|
+
playhead = t;
|
|
632
|
+
later();
|
|
633
|
+
if (t === void 0) {
|
|
634
|
+
playState = void 0;
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
const mine = ++stateReq;
|
|
638
|
+
const s = o.source.stateAt ? await o.source.stateAt(scope, t).catch(() => void 0) : void 0;
|
|
639
|
+
if (mine !== stateReq) return;
|
|
640
|
+
playState = s;
|
|
641
|
+
o.onPlayhead?.(t, s);
|
|
642
|
+
paintChrome();
|
|
643
|
+
}
|
|
644
|
+
async function showTable(from, to) {
|
|
645
|
+
brush = { from: Math.min(from, to), to: Math.max(from, to) };
|
|
646
|
+
later();
|
|
647
|
+
const page = await o.source.query(query(brush.from, brush.to, { kind: "single" }, { limit: 500 }));
|
|
648
|
+
const p = parseSearch(q);
|
|
649
|
+
const mark = (s) => {
|
|
650
|
+
const out = [];
|
|
651
|
+
let at = 0;
|
|
652
|
+
for (const [a, b] of highlights(p, s)) {
|
|
653
|
+
out.push(s.slice(at, a), h("mark", null, s.slice(a, b)));
|
|
654
|
+
at = b;
|
|
655
|
+
}
|
|
656
|
+
out.push(s.slice(at));
|
|
657
|
+
return out;
|
|
658
|
+
};
|
|
659
|
+
const rows = (page.events ?? []).map((e) => {
|
|
660
|
+
const tr = h("tr", { "data-id": e.id, tabindex: "0" }, h("td", null, fmtTime(e.t, tz)), h("td", null, e.dur !== void 0 ? fmtDur(e.dur) : e.open ? "still going" : ""), h("td", null, e.source), h("td", null, e.kind), h("td", { class: `sev-${e.severity}` }, e.severity), h("td", { class: "tlx-sum" }, ...mark(e.summary)), h("td", { class: "tlx-scope" }, e.scope));
|
|
661
|
+
tr.addEventListener("click", () => select(e));
|
|
662
|
+
tr.addEventListener("keydown", (ev) => {
|
|
663
|
+
if (ev.key === "Enter") select(e);
|
|
664
|
+
});
|
|
665
|
+
return tr;
|
|
666
|
+
});
|
|
667
|
+
const close = h("button", { type: "button", class: "btn sm quiet", "aria-label": "Close the table" }, "Close");
|
|
668
|
+
close.addEventListener("click", () => {
|
|
669
|
+
brush = void 0;
|
|
670
|
+
table.hidden = true;
|
|
671
|
+
later();
|
|
672
|
+
});
|
|
673
|
+
const exp = (kind) => {
|
|
674
|
+
const b = h("button", { type: "button", class: "btn sm", "data-export": kind }, kind.toUpperCase());
|
|
675
|
+
b.addEventListener("click", () => void exportRange(kind));
|
|
676
|
+
return b;
|
|
677
|
+
};
|
|
678
|
+
table.replaceChildren(
|
|
679
|
+
h("div", { class: "tlx-table-head" }, h("strong", null, `${page.total} event${page.total === 1 ? "" : "s"}`), h("span", null, ` ${fmtTime(brush.from, tz)} \u2013 ${fmtTime(brush.to, tz)}${page.total > 500 ? " (the first 500 shown; the export has them all)" : ""}`), h("span", { class: "spacer" }), h("span", null, "Export: "), exp("json"), exp("csv"), close),
|
|
680
|
+
h("div", { class: "tlx-table-wrap" }, h("table", null, h("thead", null, h("tr", null, ...["When", "Long", "Source", "Kind", "Severity", "What", "Scope"].map((c) => h("th", { scope: "col" }, c)))), h("tbody", null, ...rows)))
|
|
681
|
+
);
|
|
682
|
+
table.hidden = false;
|
|
683
|
+
}
|
|
684
|
+
async function rangeEvents() {
|
|
685
|
+
if (!brush) return [];
|
|
686
|
+
const out = [];
|
|
687
|
+
let cursor;
|
|
688
|
+
do {
|
|
689
|
+
const r = await o.source.query(query(brush.from, brush.to, { kind: "single" }, { limit: 1e4, ...cursor ? { cursor } : {} }));
|
|
690
|
+
out.push(...r.events ?? []);
|
|
691
|
+
cursor = r.next;
|
|
692
|
+
} while (cursor && out.length < 2e5);
|
|
693
|
+
return out;
|
|
694
|
+
}
|
|
695
|
+
async function exportRange(kind) {
|
|
696
|
+
const es = await rangeEvents();
|
|
697
|
+
const text = kind === "json" ? toJSON(es, sensitive) : toCSV(es, sensitive);
|
|
698
|
+
const name = `timeline-${new Date(brush.from).toISOString().slice(0, 16).replace(/:/g, "")}.${kind}`;
|
|
699
|
+
const type = kind === "json" ? "application/json" : "text/csv";
|
|
700
|
+
if (o.onExport) {
|
|
701
|
+
o.onExport(name, text, type);
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
const a = h("a", { href: `data:${type};charset=utf-8,${encodeURIComponent(text)}`, download: name });
|
|
705
|
+
document.body.append(a);
|
|
706
|
+
a.click();
|
|
707
|
+
a.remove();
|
|
708
|
+
}
|
|
709
|
+
function select(e) {
|
|
710
|
+
selected = e;
|
|
711
|
+
later();
|
|
712
|
+
if (!e) {
|
|
713
|
+
detail.hidden = true;
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
const src = catalog?.sources.find((s) => s.name === e.source);
|
|
717
|
+
const sens = new Set(src?.sensitive ?? []);
|
|
718
|
+
const p = parseSearch(q);
|
|
719
|
+
const mark = (s) => {
|
|
720
|
+
const out = [];
|
|
721
|
+
let at = 0;
|
|
722
|
+
for (const [a, b] of highlights(p, s)) {
|
|
723
|
+
out.push(s.slice(at, a), h("mark", null, s.slice(a, b)));
|
|
724
|
+
at = b;
|
|
725
|
+
}
|
|
726
|
+
out.push(s.slice(at));
|
|
727
|
+
return out;
|
|
728
|
+
};
|
|
729
|
+
const link = (label, fn) => {
|
|
730
|
+
if (!fn) return null;
|
|
731
|
+
const b = h("button", { type: "button", class: "btn sm" }, label);
|
|
732
|
+
b.addEventListener("click", fn);
|
|
733
|
+
return b;
|
|
734
|
+
};
|
|
735
|
+
const attrRows = Object.entries(e.attrs).map(([k, v]) => {
|
|
736
|
+
if (!sens.has(k)) return h("tr", null, h("th", { scope: "row" }, k), h("td", null, ...mark(String(v))));
|
|
737
|
+
const show = h("button", { type: "button", class: "btn sm quiet", title: "This can name a remote host, a folder or free text" }, "Show");
|
|
738
|
+
const td = h("td", { class: "tlx-sensitive" }, "hidden ", show);
|
|
739
|
+
show.addEventListener("click", () => td.replaceChildren(String(v)));
|
|
740
|
+
return h("tr", null, h("th", { scope: "row" }, k), td);
|
|
741
|
+
});
|
|
742
|
+
const close = h("button", { type: "button", class: "btn sm quiet tlx-close", "aria-label": "Close" }, "\xD7");
|
|
743
|
+
close.addEventListener("click", () => select(void 0));
|
|
744
|
+
const scopeCrumbs = crumbs(e.scope).slice(1).map((c) => {
|
|
745
|
+
const b = h("button", { type: "button", class: "tlx-crumb" }, labelOf(c.scope, c.label));
|
|
746
|
+
b.addEventListener("click", () => drill(c.scope));
|
|
747
|
+
return b;
|
|
748
|
+
});
|
|
749
|
+
detail.replaceChildren(
|
|
750
|
+
h("div", { class: "tlx-detail-head" }, h("strong", null, e.kind), close),
|
|
751
|
+
h("p", { class: `tlx-sev sev-${e.severity}` }, `${e.severity} \xB7 ${src?.title ?? e.source}`),
|
|
752
|
+
h("p", { class: "tlx-sum" }, ...mark(e.summary)),
|
|
753
|
+
h("p", null, fmtTime(e.t, tz), e.dur !== void 0 ? ` \xB7 ${fmtDur(e.dur)}${e.open ? " so far" : ""}` : e.open ? " \xB7 still going" : ""),
|
|
754
|
+
h("p", { class: "tlx-crumbs small" }, ...scopeCrumbs),
|
|
755
|
+
...attrRows.length ? [h("table", { class: "tlx-attrs" }, h("tbody", null, ...attrRows))] : [],
|
|
756
|
+
h("div", { class: "tlx-links" }, ...(o.actions?.(e) ?? []).map(([label, fn]) => link(label, fn)))
|
|
757
|
+
);
|
|
758
|
+
detail.hidden = false;
|
|
759
|
+
}
|
|
760
|
+
function openCut(from, to) {
|
|
761
|
+
const key = gapKey({ from, to });
|
|
762
|
+
const g = gaps.find((x) => x.from === from && x.to === to);
|
|
763
|
+
if (!g) return;
|
|
764
|
+
expanded.add(key);
|
|
765
|
+
if (!motion) {
|
|
766
|
+
weights.set(key, 1);
|
|
767
|
+
later();
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
const t0 = performance.now();
|
|
771
|
+
const step = (now) => {
|
|
772
|
+
const k = Math.min(1, (now - t0) / 260);
|
|
773
|
+
weights.set(key, 1 - (1 - k) ** 3);
|
|
774
|
+
paint();
|
|
775
|
+
if (k < 1) requestAnimationFrame(step);
|
|
776
|
+
};
|
|
777
|
+
requestAnimationFrame(step);
|
|
778
|
+
}
|
|
779
|
+
let drag;
|
|
780
|
+
const pxOf = (e) => e.clientX - svg.getBoundingClientRect().left;
|
|
781
|
+
svg.addEventListener("pointerdown", (e) => {
|
|
782
|
+
const px = pxOf(e), py = e.clientY - svg.getBoundingClientRect().top;
|
|
783
|
+
const cut = e.target.closest?.(".tlx-cut");
|
|
784
|
+
if (cut) {
|
|
785
|
+
e.preventDefault();
|
|
786
|
+
openCut(Number(cut.getAttribute("data-from")), Number(cut.getAttribute("data-to")));
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
svg.setPointerCapture(e.pointerId);
|
|
790
|
+
const kind = py < AXIS ? "brush" : e.shiftKey ? "brush" : e.target.classList.contains("tlx-handle") ? "scrub" : "pan";
|
|
791
|
+
drag = { kind, x0: px, t0: scale.t(px), v0: view, moved: false };
|
|
792
|
+
e.preventDefault();
|
|
793
|
+
lanes.focus({ preventScroll: true });
|
|
794
|
+
});
|
|
795
|
+
svg.addEventListener("pointermove", (e) => {
|
|
796
|
+
if (!drag) return;
|
|
797
|
+
const px = pxOf(e);
|
|
798
|
+
if (Math.abs(px - drag.x0) > 3) drag.moved = true;
|
|
799
|
+
if (!drag.moved) return;
|
|
800
|
+
if (drag.kind === "pan") {
|
|
801
|
+
const dt = (drag.x0 - px) * scale.msPerPx;
|
|
802
|
+
view = { t0: drag.v0.t0 + dt, t1: drag.v0.t1 + dt };
|
|
803
|
+
follow = false;
|
|
804
|
+
void refresh();
|
|
805
|
+
} else if (drag.kind === "scrub") void setPlayhead(scale.t(px));
|
|
806
|
+
else {
|
|
807
|
+
brush = { from: Math.min(drag.t0, scale.t(px)), to: Math.max(drag.t0, scale.t(px)) };
|
|
808
|
+
later();
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
svg.addEventListener("pointerup", (e) => {
|
|
812
|
+
const d = drag;
|
|
813
|
+
drag = void 0;
|
|
814
|
+
if (!d) return;
|
|
815
|
+
const px = pxOf(e);
|
|
816
|
+
if (d.kind === "brush" && d.moved) {
|
|
817
|
+
void showTable(d.t0, scale.t(px));
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
if (d.kind === "brush" && !d.moved) {
|
|
821
|
+
void setPlayhead(scale.t(px));
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
if (d.kind === "pan" && !d.moved) {
|
|
825
|
+
const id = e.target.closest?.("[data-id]")?.getAttribute("data-id");
|
|
826
|
+
const ev = id ? [...result?.events ?? [], ...result?.spans ?? []].find((x) => x.id === id) : void 0;
|
|
827
|
+
if (ev) {
|
|
828
|
+
select(ev);
|
|
829
|
+
void setPlayhead(ev.t);
|
|
830
|
+
} else void setPlayhead(scale.t(px));
|
|
831
|
+
}
|
|
832
|
+
});
|
|
833
|
+
svg.addEventListener("keydown", (e) => {
|
|
834
|
+
const cut = e.target.closest?.(".tlx-cut");
|
|
835
|
+
if (cut && (e.key === "Enter" || e.key === " ")) {
|
|
836
|
+
e.preventDefault();
|
|
837
|
+
openCut(Number(cut.getAttribute("data-from")), Number(cut.getAttribute("data-to")));
|
|
838
|
+
}
|
|
839
|
+
});
|
|
840
|
+
svg.addEventListener("wheel", (e) => {
|
|
841
|
+
e.preventDefault();
|
|
842
|
+
const px = pxOf(e);
|
|
843
|
+
if (e.shiftKey || Math.abs(e.deltaX) > Math.abs(e.deltaY)) {
|
|
844
|
+
const dt = (e.shiftKey ? e.deltaY : e.deltaX) * scale.msPerPx;
|
|
845
|
+
view = { t0: view.t0 + dt, t1: view.t1 + dt };
|
|
846
|
+
follow = false;
|
|
847
|
+
} else zoomAt(scale.t(px), Math.exp(e.deltaY * 15e-4), px / width());
|
|
848
|
+
void refresh();
|
|
849
|
+
}, { passive: false });
|
|
850
|
+
function zoomAt(at, f, frac = 0.5) {
|
|
851
|
+
const span = Math.min(400 * DAY, Math.max(1e4, (view.t1 - view.t0) * f));
|
|
852
|
+
view = { t0: at - frac * span, t1: at + (1 - frac) * span };
|
|
853
|
+
expanded.clear();
|
|
854
|
+
weights.clear();
|
|
855
|
+
if (f < 1) follow = live && view.t1 >= nowT();
|
|
856
|
+
}
|
|
857
|
+
lanes.addEventListener("keydown", (e) => {
|
|
858
|
+
const span = view.t1 - view.t0;
|
|
859
|
+
if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
|
|
860
|
+
const dt = span * 0.15 * (e.key === "ArrowLeft" ? -1 : 1);
|
|
861
|
+
view = { t0: view.t0 + dt, t1: view.t1 + dt };
|
|
862
|
+
follow = false;
|
|
863
|
+
} else if (e.key === "+" || e.key === "=") zoomAt((view.t0 + view.t1) / 2, 0.6);
|
|
864
|
+
else if (e.key === "-" || e.key === "_") zoomAt((view.t0 + view.t1) / 2, 1 / 0.6);
|
|
865
|
+
else if (e.key === "n" || e.key === "N") {
|
|
866
|
+
stepHit(e.shiftKey ? -1 : 1);
|
|
867
|
+
e.preventDefault();
|
|
868
|
+
return;
|
|
869
|
+
} else if (e.key === "Escape") {
|
|
870
|
+
select(void 0);
|
|
871
|
+
brush = void 0;
|
|
872
|
+
table.hidden = true;
|
|
873
|
+
} else return;
|
|
874
|
+
e.preventDefault();
|
|
875
|
+
void refresh();
|
|
876
|
+
});
|
|
877
|
+
el.addEventListener("keydown", (e) => {
|
|
878
|
+
if (e.key === "/" && document.activeElement !== search && !e.target.closest("input, select, textarea")) {
|
|
879
|
+
e.preventDefault();
|
|
880
|
+
search.focus();
|
|
881
|
+
}
|
|
882
|
+
});
|
|
883
|
+
scroller.addEventListener("scroll", () => later(), { passive: true });
|
|
884
|
+
saveBtn.addEventListener("click", async () => {
|
|
885
|
+
const name = `${crumbs(scope).slice(-1)[0].label}${q ? `: ${q}` : ""}`.slice(0, 80);
|
|
886
|
+
await o.saveView?.({ ...currentView(), name });
|
|
887
|
+
await loadViews();
|
|
888
|
+
});
|
|
889
|
+
let saved = [];
|
|
890
|
+
async function loadViews() {
|
|
891
|
+
if (!o.views) return;
|
|
892
|
+
saved = await o.views();
|
|
893
|
+
viewsSel.replaceChildren(h("option", { value: "" }, "Saved views\u2026"), ...saved.map((v, i) => h("option", { value: String(i) }, v.name)));
|
|
894
|
+
}
|
|
895
|
+
viewsSel.addEventListener("change", () => {
|
|
896
|
+
const v = saved[Number(viewsSel.value)];
|
|
897
|
+
if (v) {
|
|
898
|
+
applyView(v);
|
|
899
|
+
paintFacets();
|
|
900
|
+
void refresh(true);
|
|
901
|
+
}
|
|
902
|
+
viewsSel.value = "";
|
|
903
|
+
});
|
|
904
|
+
const ro = typeof ResizeObserver === "function" ? new ResizeObserver(() => later()) : void 0;
|
|
905
|
+
ro?.observe(lanes);
|
|
906
|
+
const ready = (async () => {
|
|
907
|
+
catalog = await o.source.catalog();
|
|
908
|
+
sensitive = catalog.sources.flatMap((s) => (s.sensitive ?? []).map((a) => `${s.name}.${a}`));
|
|
909
|
+
for (const s of catalog.sources) for (const x of s.series) seriesInfo.set(x.name, { unit: x.unit, type: x.type, title: x.title, source: s.name });
|
|
910
|
+
const firstHost = catalog.hosts.length === 1 ? `host:${catalog.hosts[0].replace(/[%/:\s]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`)}` : "";
|
|
911
|
+
scope = firstHost;
|
|
912
|
+
const now = catalog.now;
|
|
913
|
+
view = { t0: now - DAY, t1: now + DAY * 0.02 };
|
|
914
|
+
const v = readUrl() ?? o.view;
|
|
915
|
+
if (v) applyView(v);
|
|
916
|
+
paintFacets();
|
|
917
|
+
await loadViews();
|
|
918
|
+
await refresh(true);
|
|
919
|
+
if (q) await findHits();
|
|
920
|
+
})();
|
|
921
|
+
return {
|
|
922
|
+
el,
|
|
923
|
+
ready,
|
|
924
|
+
get view() {
|
|
925
|
+
return currentView();
|
|
926
|
+
},
|
|
927
|
+
setView(v) {
|
|
928
|
+
applyView(v);
|
|
929
|
+
paintFacets();
|
|
930
|
+
return refresh(true);
|
|
931
|
+
},
|
|
932
|
+
setRange(t0, t1) {
|
|
933
|
+
view = { t0, t1 };
|
|
934
|
+
follow = false;
|
|
935
|
+
return refresh();
|
|
936
|
+
},
|
|
937
|
+
setPlayhead,
|
|
938
|
+
setLive,
|
|
939
|
+
setTheme,
|
|
940
|
+
refresh: () => refresh(true),
|
|
941
|
+
/** for tests and hosts: what is drawn, and the mapping */
|
|
942
|
+
internal: {
|
|
943
|
+
get result() {
|
|
944
|
+
return result;
|
|
945
|
+
},
|
|
946
|
+
get mode() {
|
|
947
|
+
return mode();
|
|
948
|
+
},
|
|
949
|
+
get scale() {
|
|
950
|
+
return scale;
|
|
951
|
+
},
|
|
952
|
+
get gaps() {
|
|
953
|
+
return gaps;
|
|
954
|
+
},
|
|
955
|
+
get playState() {
|
|
956
|
+
return playState;
|
|
957
|
+
},
|
|
958
|
+
get hits() {
|
|
959
|
+
return hits;
|
|
960
|
+
},
|
|
961
|
+
get selected() {
|
|
962
|
+
return selected;
|
|
963
|
+
},
|
|
964
|
+
get follow() {
|
|
965
|
+
return follow;
|
|
966
|
+
},
|
|
967
|
+
openCut,
|
|
968
|
+
showTable,
|
|
969
|
+
rangeEvents,
|
|
970
|
+
exportRange,
|
|
971
|
+
select,
|
|
972
|
+
stepHit,
|
|
973
|
+
drill,
|
|
974
|
+
findHits,
|
|
975
|
+
paint,
|
|
976
|
+
lines
|
|
977
|
+
},
|
|
978
|
+
dispose() {
|
|
979
|
+
unsub?.();
|
|
980
|
+
ro?.disconnect();
|
|
981
|
+
if (frame) cancelAnimationFrame(frame);
|
|
982
|
+
el.replaceChildren();
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
export {
|
|
987
|
+
activityOf,
|
|
988
|
+
modeFor,
|
|
989
|
+
mountTimeline
|
|
990
|
+
};
|