Skip to content

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

fix(sequence): wrap message notes within their lane (#676)

yarrbakrbfbb02b9122c
diff --git a/archify/renderers/sequence/README.md b/archify/renderers/sequence/README.md
index 8a25f1ec..bc8599ec 100644
--- a/archify/renderers/sequence/README.md
+++ b/archify/renderers/sequence/README.md
@@ -73,6 +73,7 @@ muted text color.
| Message `y` range | `[160, height − 83]` |
| Message spacing | ≥28px vertical between messages that share horizontal space |
| Arrow span | ≥60px horizontal between the two participants |
+| Message notes | 7px fine-detail text under the arrow, wrapped at 11px line spacing inside one gap between neighbouring lifelines (the widest gap the message spans, nearest the sender on a tie), clear of activation bars; long unbroken text breaks after `/ . - ? & = # _`, otherwise at any character, so the full note is kept in every export. In `showcase`, a note that reaches a later message fails with the `y` that message needs |
| Segments | y pixel ranges with `to > from`, inside `[72, lifeline bottom + 20]` |
| Legend | last row baseline at height − 54; extra rows wrap upward and stay 12px below the timeline content |
diff --git a/archify/renderers/sequence/render-sequence.mjs b/archify/renderers/sequence/render-sequence.mjs
index 808db62f..3c02d084 100644
--- a/archify/renderers/sequence/render-sequence.mjs
+++ b/archify/renderers/sequence/render-sequence.mjs
@@ -46,9 +46,136 @@ function legendEntries() {
// needs LEGEND_BLOCK_HEIGHT (title glyphs, row, and the 54px baseline inset).
const LEGEND_CONTENT_GAP = 12;
const LEGEND_BLOCK_HEIGHT = 86;
+
+// Column geometry depends only on the canvas width, which is known before the
+// automatic height is: notes wrap inside lane gaps, and their wrapped height
+// feeds that automatic height.
+// `column_fit: "spread"` widens the lanes with the viewBox instead of keeping
+// the fixed 108px gap, so a wide canvas gains column distance and label room
+// rather than dead space on the right. The default stays "fixed" so existing
+// diagrams keep their coordinates.
+const canvasWidth = sequence.meta?.viewBox?.[0] ?? 920;
+const columnFit = sequence.meta?.column_fit === 'spread' ? 'spread' : 'fixed';
+const participantCount = Math.max(1, asArray(sequence.participants).length);
+const sideMargin = 62;
+const participantW = columnFit === 'spread'
+ ? Math.max(86, Math.min(190, Math.round((canvasWidth - sideMargin * 2) / participantCount) - 24))
+ : 86;
+const colGap = columnFit === 'spread' && participantCount > 1
+ ? Math.max(108, (canvasWidth - 40 - sideMargin - participantW) / (participantCount - 1))
+ : 108;
+const leftX = columnFit === 'spread' ? sideMargin + participantW / 2 : sideMargin;
+const participantIndexById = new Map(asArray(sequence.participants).map((participant, index) => [participant.id, index]));
+
+function participantX(index) {
+ return leftX + index * colGap;
+}
+
+// A note wraps inside one gap between neighbouring lifelines, so it never
+// crosses an unrelated lifeline or activation bar (#676). Every character
+// stays visible, including in image exports: long unbroken text (a URL or
+// path) breaks after its punctuation, otherwise at any character.
+const NOTE_FONT_SIZE = 7;
+const NOTE_LINE_HEIGHT = NOTE_FONT_SIZE + 4;
+// The first line keeps its original position: 12px past the arrow start,
+// which sits 7px from the lifeline.
+const NOTE_ARROW_INSET = 7;
+const NOTE_TEXT_INSET = 12;
+// Activation bars reach 5px past a lifeline; keep 6px of air beyond them.
+const NOTE_LIFELINE_CLEARANCE = 11;
+const NOTE_BREAK_AFTER = new Set(['/', '.', '-', '?', '&', '=', '#', '_']);
+const noteSegmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
+const noteLayouts = new Map();
+
+function noteTextWidth(text) {
+ return minimumNodeTextWidth(text, NOTE_FONT_SIZE);
+}
+
+// Index after the last punctuation break in `piece`, or its full length.
+function noteBreakIndex(piece) {
+ for (let index = piece.length - 1; index > 0; index -= 1) {
+ if (NOTE_BREAK_AFTER.has(piece[index - 1])) return index;
+ }
+ return piece.length;
+}
+
+function wrapNoteText(text, width) {
+ const lines = [];
+ let line = '';
+ const flush = () => {
+ const trimmed = line.trimEnd();
+ if (trimmed) lines.push(trimmed);
+ line = '';
+ };
+ for (const word of String(text).match(/\s+|\S+/gu) || []) {
+ if (/^\s+$/u.test(word)) {
+ if (line) line += ' ';
+ continue;
+ }
+ if (noteTextWidth(line + word) <= width) {
+ line += word;
+ continue;
+ }
+ flush();
+ let piece = '';
+ for (const { segment } of noteSegmenter.segment(word)) {
+ while (piece && noteTextWidth(piece + segment) > width) {
+ const cut = noteBreakIndex(piece);
+ lines.push(piece.slice(0, cut));
+ piece = piece.slice(cut);
+ }
+ piece += segment;
+ }
+ line = piece;
+ }
+ flush();
+ return lines;
+}
+
+// The widest gap the message spans; equal gaps resolve toward the sender.
+function noteGapIndex(fromIndex, toIndex) {
+ const low = Math.min(fromIndex, toIndex);
+ const high = Math.max(fromIndex, toIndex);
+ let best = null;
+ for (let gap = low; gap < high; gap += 1) {
+ const width = participantX(gap + 1) - participantX(gap);
+ const senderDistance = Math.abs((fromIndex < toIndex ? gap : gap + 1) - fromIndex);
+ if (!best || width > best.width || (width === best.width && senderDistance < best.senderDistance)) {
+ best = { gap, width, senderDistance };
+ }
+ }
+ return best?.gap ?? null;
+}
+
+function noteLayout(message) {
+ if (noteLayouts.has(message)) return noteLayouts.get(message);
+ let result = null;
+ const fromIndex = participantIndexById.get(message.from);
+ const toIndex = participantIndexById.get(message.to);
+ if (message.note && typeof message.y === 'number' && fromIndex !== undefined && toIndex !== undefined && fromIndex !== toIndex) {
+ const gap = noteGapIndex(fromIndex, toIndex);
+ const x = participantX(gap) + NOTE_ARROW_INSET + NOTE_TEXT_INSET;
+ const maxWidth = Math.max(1, participantX(gap + 1) - NOTE_LIFELINE_CLEARANCE - x);
+ const lines = noteTextWidth(message.note) <= maxWidth ? [message.note] : wrapNoteText(message.note, maxWidth);
+ const baseline = message.y + 18;
+ result = {
+ x,
+ baseline,
+ lines,
+ width: Math.max(...lines.map(noteTextWidth)),
+ top: baseline - NOTE_FONT_SIZE,
+ bottom: message.y + 22 + (lines.length - 1) * NOTE_LINE_HEIGHT,
+ };
+ }
+ noteLayouts.set(message, result);
+ return result;
+}
+
const contentBottom = Math.max(
0,
- ...asArray(sequence.messages).map((message) => message.y + (message.note ? 22 : 6)),
+ ...asArray(sequence.messages).map((message) => (message.note
+ ? noteLayout(message)?.bottom ?? message.y + 22
+ : message.y + 6)),
...asArray(sequence.activations).map((activation) => activation.to),
...asArray(sequence.segments).map((segment) => segment.to),
);
@@ -63,19 +190,6 @@ function legendRequiredHeight(width) {
const viewBox = sequence.meta?.viewBox || [920, Math.max(760, legendRequiredHeight(920))];
// The timeline scales with viewBox height: a taller viewBox gains message room,
// a shorter one shrinks the readable band (validated below) instead of clipping.
-// `column_fit: "spread"` widens the lanes with the viewBox instead of keeping
-// the fixed 108px gap, so a wide canvas gains column distance and label room
-// rather than dead space on the right. The default stays "fixed" so existing
-// diagrams keep their coordinates.
-const columnFit = sequence.meta?.column_fit === 'spread' ? 'spread' : 'fixed';
-const participantCount = Math.max(1, asArray(sequence.participants).length);
-const sideMargin = 62;
-const participantW = columnFit === 'spread'
- ? Math.max(86, Math.min(190, Math.round((viewBox[0] - sideMargin * 2) / participantCount) - 24))
- : 86;
-const colGap = columnFit === 'spread' && participantCount > 1
- ? Math.max(108, (viewBox[0] - 40 - sideMargin - participantW) / (participantCount - 1))
- : 108;
// Showcase is the fast-authoring default; standard retains legacy label geometry.
const readableMessages = sequence.meta?.quality_profile === 'showcase';
@@ -92,7 +206,7 @@ const layout = {
lifelineTop: 142,
lifelineBottom: viewBox[1] - 65,
legendY: viewBox[1] - 54,
- leftX: columnFit === 'spread' ? sideMargin + participantW / 2 : sideMargin,
+ leftX,
colGap,
labelH: readableMessages ? 18 : 16
};
@@ -106,10 +220,6 @@ const arrowClass = {
return: ['a-default', 'arrowhead']
};
-function participantX(index) {
- return layout.leftX + index * layout.colGap;
-}
-
const participants = new Map(asArray(sequence.participants).map((participant, index) => [
participant.id,
{
@@ -331,6 +441,35 @@ function validateSequence() {
routeHint: 'shorten the label, reorder participants, or enlarge meta.viewBox',
}));
+ // A wrapped note keeps every character (#676), so a note that still reaches a
+ // later message needs that message moved; authored y values stay as written.
+ // Showcase only, so standard keeps accepting existing diagrams.
+ if (readableMessages) {
+ const messages = asArray(sequence.messages);
+ messages.forEach((message, messageIndex) => {
+ const note = noteLayout(message);
+ if (!note) return;
+ const noteRect = { x: note.x, y: note.top, width: note.width, height: note.bottom - note.top };
+ const blocker = messages
+ .map((other, otherIndex) => {
+ if (otherIndex === messageIndex || typeof other.y !== 'number' || other.y <= message.y) return null;
+ const otherNote = noteLayout(other);
+ const rects = [
+ messageLabelBox(other),
+ messageRouteBox(other),
+ otherNote && { x: otherNote.x, y: otherNote.top, width: otherNote.width, height: otherNote.bottom - otherNote.top },
+ ].filter(Boolean);
+ return rects.some((rect) => rectsOverlap(noteRect, rect, 2)) ? other : null;
+ })
+ .filter(Boolean)
+ .sort((a, b) => a.y - b.y)[0];
+ if (!blocker) return;
+ const lines = note.lines.length === 1 ? '1 line' : `${note.lines.length} lines`;
+ const requiredY = Math.ceil(note.bottom + 22);
+ problems.push(`Note on message "${message.label}" wraps to ${lines} (down to y=${Math.ceil(note.bottom)}) and reaches message "${blocker.label}" at y=${blocker.y} — move "${blocker.label}" and later messages down so it sits at y=${requiredY} or below, or shorten the note.`);
+ });
+ }
+
for (const segment of asArray(sequence.segments)) {
if (segment.to <= segment.from) {
problems.push(`Segment "${segment.label}" has invalid y range (from ${segment.from} to ${segment.to}) — "to" must be greater than "from".`);
@@ -446,8 +585,12 @@ function renderMessage(message, index) {
const [cls, marker] = arrowClass[message.variant || 'default'] || arrowClass.default;
const strokeWidth = message.variant === 'emphasis' ? 1.8 : 1.4;
const dash = message.variant === 'return' ? ' stroke-dasharray="3,5"' : '';
- const note = message.note
- ? `\n <text data-detail="fine" x="${Math.min(start, end) + 12}" y="${message.y + 18}" class="t-dim" font-size="7">${esc(message.note)}</text>`
+ const noteBox = noteLayout(message);
+ const noteContent = noteBox?.lines.length > 1
+ ? noteBox.lines.map((line, lineIndex) => `<tspan x="${noteBox.x}" dy="${lineIndex ? NOTE_LINE_HEIGHT : 0}">${esc(line)}</tspan>`).join('')
+ : esc(message.note);
+ const note = noteBox
+ ? `\n <text data-detail="fine" x="${noteBox.x}" y="${noteBox.baseline}" class="t-dim" font-size="${NOTE_FONT_SIZE}">${noteContent}</text>`
: '';
return ` <g ${focusEdgeAttrs(message.from, message.to, message.label, index, message.id)}>
<path data-composition-edge-from="${esc(message.from)}" data-composition-edge-to="${esc(message.to)}"${message.id ? ` data-composition-edge-id="${esc(message.id)}"` : ''} data-composition-points="${routePointsValue([[start, message.y], [end, message.y]])}" d="M ${start} ${message.y} L ${end} ${message.y}" class="${cls}"${animateAttr(sequence.meta, 'edge', index)} stroke-width="${strokeWidth}"${dash} marker-end="url(#${marker})"/>
diff --git a/archify/scripts/check-render-output.mjs b/archify/scripts/check-render-output.mjs
index ae6e741a..a6dd23c3 100644
--- a/archify/scripts/check-render-output.mjs
+++ b/archify/scripts/check-render-output.mjs
@@ -796,7 +796,7 @@ function collectSequenceColumnSpace({ svgAttrs, fragment, nodeRects, arrows }) {
const columnFit = svgAttrs['data-sequence-column-fit'];
if (!['fixed', 'spread'].includes(columnFit)) return null;
const evidence = { measured: false, reviewSuggested: false, columnFit };
- if (svgAttrs.transform || /<tspan\b/i.test(fragment)) return evidence;
+ if (svgAttrs.transform) return evidence;
// Brand badges stay inside their participant box. Ignore only that subtree's
// transforms, including the preset path or nested fallback icon's scale.
const brandGroups = [];
@@ -832,9 +832,19 @@ function collectSequenceColumnSpace({ svgAttrs, fragment, nodeRects, arrows }) {
rightEdges.push(numberAttr(attrs, 'x') + numberAttr(attrs, 'width'));
}
for (const match of fragment.matchAll(/<text\b([^>]*)>([\s\S]*?)<\/text>/gi)) {
- const box = textBox(parseAttrs(match[1]), stripTags(match[2]).trim());
- if (!box) return evidence;
- rightEdges.push(box.x2);
+ const attrs = parseAttrs(match[1]);
+ // A wrapped note places each line in a <tspan> with its own x. Any other
+ // line offset is not measured here.
+ const lines = /<tspan\b/i.test(match[2])
+ ? [...match[2].matchAll(/<tspan\b([^>]*)>([\s\S]*?)<\/tspan>/gi)]
+ .map((line) => ({ attrs: { ...attrs, ...parseAttrs(line[1]) }, text: stripTags(line[2]).trim() }))
+ : [{ attrs, text: stripTags(match[2]).trim() }];
+ if (!lines.length || lines.some((line) => line.attrs.dx !== undefined)) return evidence;
+ for (const line of lines) {
+ const box = textBox(line.attrs, line.text);
+ if (!box) return evidence;
+ rightEdges.push(box.x2);
+ }
}
if (!rightEdges.every(Number.isFinite)) return evidence;
const occupiedRight = Math.max(...rightEdges);
diff --git a/archify/test/sequence-note-wrap.test.mjs b/archify/test/sequence-note-wrap.test.mjs
new file mode 100644
index 00000000..28ed6cd3
--- /dev/null
+++ b/archify/test/sequence-note-wrap.test.mjs
@@ -0,0 +1,180 @@
+import { test } from 'node:test';
+import assert from 'node:assert/strict';
+import { spawnSync } from 'node:child_process';
+import fs from 'node:fs';
+import os from 'node:os';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { minimumNodeTextWidth } from '../renderers/shared/text-fit.mjs';
+
+// Sequence message notes wrap inside one gap between neighbouring lifelines and
+// keep every character (#676).
+const skillRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
+const cli = path.join(skillRoot, 'bin/archify.mjs');
+const LONG_NOTE = 'this note explains the whole retry and backoff policy in a lot of detail so it is very long';
+const URL_NOTE = 'see https://api.example.com/v2/users/profile/settings/notifications/email-preferences';
+
+function sequence({ messages, participants = ['client', 'api', 'db'], quality = 'showcase', activations } = {}) {
+ return {
+ schema_version: 1,
+ diagram_type: 'sequence',
+ meta: { title: 'Note wrap', output: 'note.html', quality_profile: quality, column_fit: 'spread' },
+ participants: participants.map((id) => ({ id, type: 'backend', label: id.toUpperCase() })),
+ messages,
+ ...(activations ? { activations } : {}),
+ };
+}
+
+function run(t, command, spec) {
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-sequence-note-'));
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
+ const input = path.join(dir, 'candidate.json');
+ const output = path.join(dir, 'note.html');
+ fs.writeFileSync(input, JSON.stringify(spec));
+ const args = command === 'render'
+ ? [cli, 'render', 'sequence', input, output]
+ : [cli, 'validate', 'sequence', input, '--json'];
+ const result = spawnSync(process.execPath, args, { cwd: skillRoot, encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 });
+ return { result, html: command === 'render' && result.status === 0 ? fs.readFileSync(output, 'utf8') : '' };
+}
+
+function render(t, spec) {
+ const { result, html } = run(t, 'render', spec);
+ assert.equal(result.status, 0, result.stdout + result.stderr);
+ return html;
+}
+
+function lifelines(html) {
+ return [...html.matchAll(/<path d="M ([\d.]+) 142 L \1 [\d.]+" class="a-default" stroke-width="0.8" stroke-dasharray="3,7"\/>/g)]
+ .map((match) => Number(match[1]));
+}
+
+function notes(html) {
+ return [...html.matchAll(/<text data-detail="fine" x="([\d.]+)" y="([\d.]+)" class="t-dim" font-size="7">([\s\S]*?)<\/text>/g)]
+ .map((match) => {
+ const tspans = [...match[3].matchAll(/<tspan x="([\d.]+)" dy="([\d.]+)">([^<]*)<\/tspan>/g)];
+ return {
+ x: Number(match[1]),
+ y: Number(match[2]),
+ raw: match[3],
+ lines: tspans.length ? tspans.map((line) => line[3]) : [match[3]],
+ tspanX: tspans.map((line) => Number(line[1])),
+ dy: tspans.map((line) => Number(line[2])),
+ };
+ });
+}
+
+function decode(text) {
+ return text.replaceAll('&amp;', '&');
+}
+
+test('the reported long note wraps inside its own lane and keeps every word', (t) => {
+ const html = render(t, sequence({
+ messages: [
+ { id: 'request', from: 'client', to: 'api', y: 200, label: 'request', note: LONG_NOTE },
+ { id: 'reply', from: 'api', to: 'client', y: 380, label: 'reply', variant: 'return' },
+ ],
+ activations: [{ participant: 'api', from: 190, to: 390 }],
+ }));
+ const [client, api] = lifelines(html);
+ const [note] = notes(html);
+ assert.ok(note.lines.length > 1, 'the long note wraps');
+ assert.equal(note.lines.join(' '), LONG_NOTE, 'no word is dropped or shortened');
+ assert.equal(note.x, client + 19, 'the first line keeps its original position');
+ assert.deepEqual(note.dy, note.lines.map((_, index) => (index ? 11 : 0)));
+ for (const line of note.lines) {
+ assert.ok(note.x + minimumNodeTextWidth(line, 7) <= api - 11, `"${line}" stays clear of the API activation bar`);
+ }
+});
+
+test('long unbroken text breaks after URL punctuation and keeps every character', (t) => {
+ const html = render(t, sequence({
+ participants: ['client', 'api', 'db', 'cache', 'queue'],
+ messages: [{ id: 'link', from: 'client', to: 'api', y: 200, label: 'docs', note: URL_NOTE }],
+ }));
+ const [client, api] = lifelines(html);
+ const [note] = notes(html);
+ assert.ok(note.lines.length > 2, 'the address spans several lines');
+ assert.equal(note.lines[0], 'see');
+ assert.equal(note.lines.slice(1).join(''), URL_NOTE.slice('see '.length), 'every character of the address is kept');
+ for (const line of note.lines.slice(1, -1)) {
+ assert.match(line, /[/.\-?&=#_]$/, `"${line}" breaks after punctuation`);
+ }
+ for (const line of note.lines) {
+ assert.ok(client + 19 + minimumNodeTextWidth(line, 7) <= api - 11, `"${line}" fits its lane`);
+ }
+});
+
+test('text without any punctuation breaks at a character boundary', (t) => {
+ const token = 'x'.repeat(160);
+ const html = render(t, sequence({ messages: [{ from: 'client', to: 'api', y: 200, label: 'token', note: token }] }));
+ const [note] = notes(html);
+ assert.ok(note.lines.length > 1);
+ assert.equal(note.lines.join(''), token);
+});
+
+test('a short note keeps its original single-line markup', (t) => {
+ const html = render(t, sequence({ messages: [{ from: 'api', to: 'client', y: 200, label: 'reply', note: 'cached for 5 minutes' }] }));
+ const [client] = lifelines(html);
+ assert.match(html, new RegExp(`<text data-detail="fine" x="${client + 19}" y="218" class="t-dim" font-size="7">cached for 5 minutes</text>`));
+ assert.doesNotMatch(html, /<tspan/);
+});
+
+test('a note on a message that skips participants uses the gap beside the sender', (t) => {
+ const forward = render(t, sequence({ messages: [{ from: 'client', to: 'db', y: 200, label: 'lookup', note: LONG_NOTE }] }));
+ const [client, api, db] = lifelines(forward);
+ const [forwardNote] = notes(forward);
+ assert.equal(forwardNote.x, client + 19);
+ for (const line of forwardNote.lines) assert.ok(forwardNote.x + minimumNodeTextWidth(line, 7) <= api - 11, 'clear of the skipped API lifeline');
+
+ const backward = render(t, sequence({ messages: [{ from: 'db', to: 'client', y: 200, label: 'result', note: LONG_NOTE }] }));
+ const [backwardNote] = notes(backward);
+ assert.equal(backwardNote.x, api + 19, 'the gap between API and DB sits beside the sender');
+ for (const line of backwardNote.lines) assert.ok(backwardNote.x + minimumNodeTextWidth(line, 7) <= db - 11);
+});
+
+test('a wrapped note that reaches the next message names the message and the y it needs', (t) => {
+ const crowded = (replyY) => sequence({
+ participants: ['client', 'api', 'db', 'cache', 'queue'],
+ messages: [
+ { id: 'request', from: 'client', to: 'api', y: 200, label: 'request', note: LONG_NOTE },
+ { id: 'reply', from: 'api', to: 'client', y: replyY, label: 'reply', variant: 'return' },
+ ],
+ });
+ const failed = run(t, 'validate', crowded(230)).result;
+ assert.notEqual(failed.status, 0);
+ const receipt = JSON.parse(failed.stdout);
+ const message = receipt.diagnostics.map((entry) => entry.message).join('\n');
+ assert.match(message, /Note on message "request" wraps to \d+ lines/);
+ const requiredY = Number(message.match(/move "reply" and later messages down so it sits at y=(\d+) or below/)?.[1]);
+ assert.ok(requiredY > 230, message);
+
+ const repaired = run(t, 'validate', crowded(requiredY)).result;
+ assert.equal(repaired.status, 0, repaired.stdout);
+ const html = render(t, crowded(requiredY));
+ assert.equal(decode(notes(html)[0].lines.join(' ')), LONG_NOTE);
+});
+
+test('standard keeps accepting a crowded note', (t) => {
+ const spec = sequence({
+ quality: 'standard',
+ messages: [
+ { from: 'client', to: 'api', y: 200, label: 'request', note: LONG_NOTE },
+ { from: 'api', to: 'client', y: 230, label: 'reply', variant: 'return' },
+ ],
+ });
+ assert.equal(run(t, 'validate', spec).result.status, 0);
+});
+
+test('an automatic canvas grows to hold a wrapped note on the last message', (t) => {
+ const html = render(t, sequence({
+ participants: ['client', 'api', 'db', 'cache', 'queue'],
+ messages: [{ from: 'client', to: 'api', y: 700, label: 'late', note: LONG_NOTE.repeat(2) }],
+ }));
+ const height = Number(html.match(/<svg viewBox="0 0 920 (\d+)"/)[1]);
+ const [note] = notes(html);
+ const lastBaseline = note.y + (note.lines.length - 1) * 11;
+ const legendTitle = Number(html.match(/<text x="[\d.]+" y="([\d.]+)"[^>]*>Legend<\/text>/)[1]);
+ assert.ok(lastBaseline + 2 < legendTitle - 12, `last note line ${lastBaseline} stays above the legend title ${legendTitle}`);
+ assert.ok(height > 760);
+});
diff --git a/archify/test/sequence-width-review.test.mjs b/archify/test/sequence-width-review.test.mjs
index 2b29b7cc..fbabf2d6 100644
--- a/archify/test/sequence-width-review.test.mjs
+++ b/archify/test/sequence-width-review.test.mjs
@@ -133,16 +133,25 @@ test('small conversations and a compact fixed canvas are not advised to stretch'
assert.equal(check(render(t, compact).output).report.composition.sequenceColumnSpace.reviewSuggested, false);
});
-test('meaningful CJK message labels and notes occupy the right-hand region', t => {
- for (const field of ['label', 'note']) {
- const spec = sequence();
- spec.messages = [{ from: 'p4', to: 'p5', y: 200, label: '结果', [field]: '这是需要保留的中文说明'.repeat(field === 'label' ? 4 : 3) }];
- const { report } = check(render(t, spec).output);
- const space = report.composition.sequenceColumnSpace;
- assert.equal(space.measured, true);
- assert.ok(space.occupiedRight > 810);
- assert.equal(space.reviewSuggested, false, `${field} reserves the apparent blank area`);
- }
+test('meaningful CJK message labels occupy the right-hand region', t => {
+ const spec = sequence();
+ spec.messages = [{ from: 'p4', to: 'p5', y: 200, label: '这是需要保留的中文说明'.repeat(4) }];
+ const { report } = check(render(t, spec).output);
+ const space = report.composition.sequenceColumnSpace;
+ assert.equal(space.measured, true);
+ assert.ok(space.occupiedRight > 810);
+ assert.equal(space.reviewSuggested, false, 'label reserves the apparent blank area');
+});
+
+test('a long CJK note wraps inside its lane gap, so the unused width stays measurable', t => {
+ const spec = sequence();
+ spec.messages = [{ from: 'p4', to: 'p5', y: 200, label: '结果', note: '这是需要保留的中文说明'.repeat(3) }];
+ const { output, html } = render(t, spec);
+ assert.match(html, /<tspan /, 'the note wraps onto several lines');
+ const space = check(output).report.composition.sequenceColumnSpace;
+ assert.equal(space.measured, true);
+ assert.ok(space.occupiedRight <= 645, `the note stays left of the last column (${space.occupiedRight})`);
+ assert.equal(space.reviewSuggested, true);
});
test('segment frames are structural but their text still reserves width', t => {