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): let the repaired canvas hold a wrapped legend

tt-a1if73e6c5e750a
diff --git a/archify.zip b/archify.zip
index e5abe607..f2826305 100644
Binary files a/archify.zip and b/archify.zip differ
diff --git a/archify/renderers/sequence/README.md b/archify/renderers/sequence/README.md
index 9aca2196..22feffa5 100644
--- a/archify/renderers/sequence/README.md
+++ b/archify/renderers/sequence/README.md
@@ -74,7 +74,7 @@ muted text color.
| Message spacing | ≥28px vertical between messages that share horizontal space |
| Arrow span | ≥60px horizontal between the two participants |
| Segments | y pixel ranges with `to > from`, inside `[72, lifeline bottom + 20]` |
-| Legend row | y = height − 54 |
+| Legend | last row baseline at height − 54; extra rows wrap upward and stay 12px below the timeline content |
`segments[].from/to` and `activations[].from/to` are y pixel coordinates, not
participant ids; activations also require `to > from`.
diff --git a/archify/renderers/sequence/render-sequence.mjs b/archify/renderers/sequence/render-sequence.mjs
index 3e25db99..b2db98f8 100644
--- a/archify/renderers/sequence/render-sequence.mjs
+++ b/archify/renderers/sequence/render-sequence.mjs
@@ -461,7 +461,9 @@ function legendLayout() {
x: 40,
baselineY: layout.legendY,
width: viewBox[0] - 80,
- minTitleY: Math.max(layout.legendY - 30, contentBottom + LEGEND_CONTENT_GAP),
+ // The same content-based budget as legendRequiredHeight(): a wrapped
+ // legend may use any rows it needs as long as it stays below the content.
+ minTitleY: Math.max(layout.lifelineTop, contentBottom + LEGEND_CONTENT_GAP),
unfit: sequence.meta?.legend === undefined ? 'hide' : 'error',
diagramType: 'sequence',
};
diff --git a/archify/test/edge-label-color.test.mjs b/archify/test/edge-label-color.test.mjs
index 31763e41..1e60867c 100644
--- a/archify/test/edge-label-color.test.mjs
+++ b/archify/test/edge-label-color.test.mjs
@@ -170,6 +170,39 @@ test('sequence legend stays below a late message with a note', () => {
assert.ok(Number(fs.readFileSync(automatic.output, 'utf8').match(/<svg viewBox="0 0 920 (\d+)"/)[1]) > 760);
});
+test('sequence repair height also holds a wrapped legend', () => {
+ // A narrow canvas with all five variants wraps the legend to two rows; the
+ // suggested height must make that legend actually render below the content.
+ const variants = ['emphasis', 'return', 'security', 'dashed', 'default'];
+ const doc = (height) => ({
+ schema_version: 1, diagram_type: 'sequence',
+ meta: { title: 'Wrapped legend', output: 'wrapped.html', quality_profile: 'showcase', viewBox: [480, height] },
+ participants: [{ id: 'a', type: 'frontend', label: 'Client' }, { id: 'b', type: 'backend', label: 'Server' }],
+ messages: variants.map((variant, index) => ({
+ from: index % 2 ? 'b' : 'a', to: index % 2 ? 'a' : 'b', y: 180 + index * 60, label: variant, variant,
+ })).concat([{ from: 'a', to: 'b', y: 477, label: 'late', note: 'completed' }]),
+ });
+ const write = (name, source) => {
+ const input = path.join(tmp, `${name}.json`);
+ fs.writeFileSync(input, JSON.stringify(source));
+ return input;
+ };
+ const failed = spawnSync(process.execPath, [cli, 'validate', 'sequence', write('wrapped-short', doc(560)), '--json'], { cwd: skillRoot, encoding: 'utf8' });
+ assert.notEqual(failed.status, 0);
+ const height = Number(failed.stdout.match(/set meta\.viewBox\[1\] to at least (\d+)/)?.[1]);
+ assert.ok(height > 560, failed.stdout);
+ const output = path.join(tmp, 'wrapped-repaired.html');
+ const repaired = spawnSync(process.execPath, [cli, 'render', 'sequence', write('wrapped-repaired', doc(height)), output], { cwd: skillRoot, encoding: 'utf8' });
+ assert.equal(repaired.status, 0, repaired.stderr);
+ const html = fs.readFileSync(output, 'utf8');
+ const baselines = new Set([...html.matchAll(/data-legend-semantic-kind="[^"]+"[^>]*data-legend-baseline="([\d.]+)"/g)].map((match) => match[1]));
+ assert.equal([...html.matchAll(/data-legend-semantic-kind="/g)].length, variants.length, 'every variant appears in the repaired legend');
+ assert.ok(baselines.size >= 2, 'the fixture must exercise a wrapped legend');
+ const legendTitle = Number(html.match(/<text x="[\d.]+" y="([\d.]+)"[^>]*>Legend<\/text>/)[1]);
+ const noteY = Number(html.match(/<text data-detail="fine"[^>]*>completed<\/text>/)[0].match(/ y="([\d.]+)"/)[1]);
+ assert.ok(noteY + 2 < legendTitle - 12, `note at ${noteY}, legend title at ${legendTitle}`);
+});
+
test('edge path and label classes resolve to the same theme token', () => {
const template = fs.readFileSync(path.join(skillRoot, 'assets/template.html'), 'utf8');
for (const variant of VARIANTS) {