Skip to content

Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.

fix(waterfall): retain narrow-axis endpoint labels and merge dev

cyanseek9b7427b12fb8
diff --cc archify.zip
index 071631e9,776666e0..3676ad8a
Binary files differ
diff --cc archify/renderers/waterfall/render-waterfall.mjs
index f43458f5,826d6403..2ce70834
--- a/archify/renderers/waterfall/render-waterfall.mjs
+++ b/archify/renderers/waterfall/render-waterfall.mjs
@@@ -236,21 -226,6 +236,34 @@@ const legendEntries =
const contentBottom = rowsTop + placed.length * layout.rowH + 8;
const labelRoom = Math.ceil(Math.max(...placed.map((row) => row.x1 + LABEL_GAP + row.labelWidth)) - axisX1);
const width = Math.ceil(axisX1 + Math.max(24, labelRoom) + layout.margin);
+const axisLabels = ticks.map(tick => {
+ const text = `${timeNumber(tick.t)} ${unitLabel}`;
+ const halfWidth = (textUnits(text) * 10.5 * ADVANCE + 4) / 2;
+ const x = Math.max(layout.margin + halfWidth, Math.min(tick.x, width - layout.margin - halfWidth));
+ return { text, x, left: x - halfWidth, right: x + halfWidth };
+});
+// Keep the endpoints readable; omit intermediate labels that cannot fit. The
+// ticks and the proportional time geometry remain unchanged.
++if (axisLabels.length > 1) {
++ const first = axisLabels[0];
++ const last = axisLabels.at(-1);
++ const overlap = Math.max(0, first.right + 8 - last.left);
++ const leftShift = Math.min(overlap, first.left - layout.margin);
++ first.x -= leftShift;
++ first.left -= leftShift;
++ first.right -= leftShift;
++ const rightShift = Math.min(overlap - leftShift, width - layout.margin - last.right);
++ last.x += rightShift;
++ last.left += rightShift;
++ last.right += rightShift;
++}
+let previousLabelRight = -Infinity;
+for (const [index, label] of axisLabels.entries()) {
+ const last = axisLabels.at(-1);
+ if (label.left < previousLabelRight + 8 || (index > 0 && index < axisLabels.length - 1 && label.right + 8 > last.left)) continue;
+ label.visible = true;
+ previousLabelRight = label.right;
+}
const footprint = legendFootprint(legendEntries, { width: width - layout.margin * 2, fontSize: 11 });
const height = Math.ceil(contentBottom + layout.margin + (legendEntries.length ? 34 + footprint.extraHeight : 0));
const viewBox = [width, height];
diff --cc test/desktop-reader-browser.test.mjs
index 909be87e,9a7b23fe..54e25573
--- a/test/desktop-reader-browser.test.mjs
+++ b/test/desktop-reader-browser.test.mjs
@@@ -16,48 -16,6 +16,50 @@@ const packagedHtmlExamples = fs.readdir
.filter((name) => name.endsWith('.html') && !name.endsWith('.visual-check.html'))
.sort();
+test('waterfall axis labels stay distinct and inside the SVG at nonzero origins', {
+ skip: chromePath ? false : 'Set ARCHIFY_CHROME to run the real browser regression.',
+}, async (t) => {
+ const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-axis-labels-'));
+ t.after(() => fs.rmSync(directory, { recursive: true, force: true }));
+ const browser = new ChromeVisualBrowser(chromePath);
+ try {
- for (const span of [
- { id: 'request', name: 'Request', start: 0.0091, duration: 0.000004 },
- { id: 'request', name: 'Request', start: 1e16, end: 1e16 + 2 },
++ for (const [timing, layout] of [
++ [{ start: 0.0091, duration: 0.000004 }],
++ [{ start: 1e16, end: 1e16 + 2 }],
++ [{ start: 100000000000, end: 100000000000.00005 }, { width: 360 }],
+ ]) {
+ const input = path.join(directory, 'input.json');
+ const artifactPath = path.join(directory, 'output.html');
+ fs.writeFileSync(input, JSON.stringify({ schema_version: 1, diagram_type: 'waterfall',
- meta: { title: 'Recorded range', evidence: 'illustrative', unit: 'ms' }, spans: [span] }));
++ meta: { title: 'Recorded range', evidence: 'illustrative', unit: 'ms' }, layout,
++ spans: [{ id: 'request', name: 'Request', ...timing }] }));
+ execFileSync(process.execPath, [path.join(skillRoot, 'renderers/waterfall/render-waterfall.mjs'), input, artifactPath]);
+ for (const theme of ['light', 'dark']) {
+ await browser.inspect({ artifactPath, width: 1280, height: 900, theme });
+ const session = await browser.sessionPromise;
+ const response = await browser.cdp.send('Runtime.evaluate', { returnByValue: true, expression: `(() => {
+ const svg = document.querySelector('svg[data-waterfall-ui]');
+ const bounds = svg.getBoundingClientRect();
+ return { left: bounds.left, right: bounds.right,
+ labels: [...svg.querySelectorAll('text.wf-num[text-anchor="middle"]')].map(text => {
+ const rect = text.getBoundingClientRect();
+ return { text: text.textContent, left: rect.left, right: rect.right };
+ }) };
+ })()` }, session);
+ const { left, right, labels } = response.result.value;
+ assert.ok(labels.length >= 2);
+ assert.equal(new Set(labels.map(label => label.text)).size, labels.length);
+ for (const [index, label] of labels.entries()) {
+ assert.ok(label.left >= left - 0.5 && label.right <= right + 0.5, JSON.stringify(label));
+ if (index) assert.ok(label.left >= labels[index - 1].right, JSON.stringify(labels));
+ }
+ }
+ }
+ } finally {
+ await browser.close();
+ }
+});
+
test('all packaged HTML examples pass the real visual-check desktop gate', {
skip: chromePath ? false : 'Set ARCHIFY_CHROME to run the real browser regression.',
}, async () => {