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): give services that share a colour one legend entry

tt-a1ib608c0e60e23
diff --git a/archify/renderers/waterfall/README.md b/archify/renderers/waterfall/README.md
index 49cdee67..410f9bf6 100644
--- a/archify/renderers/waterfall/README.md
+++ b/archify/renderers/waterfall/README.md
@@ -53,7 +53,10 @@ span that does the work itself is a solid bar, so the paint separates inclusive
summaries from leaf work. Colour states the `service`: each service gets its own
palette family in order of first appearance (a span without one inherits its
parent's; unowned spans are neutral), with a dot in the name column and a legend
-entry when more than one service appears. Red is reserved for `status: "error"`.
+entry when more than one service appears. There are five service colours; past
+five services they repeat, and services sharing a colour share one legend entry
+(`gateway · inventory`), so the key never ties a colour to a single service it
+does not own. Red is reserved for `status: "error"`.
Each bar carries its exact duration just after its end; the canvas reserves
room past the axis for the widest label, so short operations stay labelled. The
diff --git a/archify/renderers/waterfall/render-waterfall.mjs b/archify/renderers/waterfall/render-waterfall.mjs
index e6db3728..54d334d2 100644
--- a/archify/renderers/waterfall/render-waterfall.mjs
+++ b/archify/renderers/waterfall/render-waterfall.mjs
@@ -193,8 +193,15 @@ const placed = rows.map((row, index) => {
// that changes a bar's paint; a single-service trace with only ok spans needs
// no key.
const presentStatuses = new Set(placed.map((row) => row.status));
+// Past five services the palette repeats. Services that share a colour share
+// one entry, so the key never claims a colour belongs to a single service.
+const serviceLegendEntries = [...services.reduce((byTone, service) => {
+ const tone = serviceTone(service);
+ byTone.set(tone, [...(byTone.get(tone) || []), service]);
+ return byTone;
+}, new Map())].map(([tone, owners]) => ({ kind: `service:${owners[0]}`, label: owners.join(' · '), tone, interactive: false }));
const legendEntries = [
- ...(services.length > 1 ? services.map((service) => ({ kind: `service:${service}`, label: service, tone: serviceTone(service), interactive: false })) : []),
+ ...(services.length > 1 ? serviceLegendEntries : []),
...resolveLegend(undefined, ['error', 'cancelled', 'incomplete'].map((kind) => ({ kind, label: i18nText(locale, `legend.waterfall.${kind}`), tone: STATUS_TONE[kind] ?? 'external', interactive: false })), presentStatuses),
];
const contentBottom = rowsTop + placed.length * layout.rowH + 8;
diff --git a/test/waterfall-rendering.test.mjs b/test/waterfall-rendering.test.mjs
index efe988e0..d7c3340f 100644
--- a/test/waterfall-rendering.test.mjs
+++ b/test/waterfall-rendering.test.mjs
@@ -99,3 +99,20 @@ test('waterfall: invalid timing and parent cycles are refused', () => {
assert.match(failure((d) => { d.spans[1].parent = 'missing'; }), /waterfall\/missing-parent/);
assert.match(failure((d) => { d.spans[0].parent = 'auth'; }), /waterfall\/cycle/);
});
+
+test('waterfall: services past the five colours share a legend entry instead of a duplicated colour', () => {
+ const services = ['gateway', 'auth', 'cart', 'pricing', 'tax', 'inventory', 'postgres'];
+ const diagram = clone(small);
+ diagram.spans = [
+ { id: 'root', name: 'POST /checkout', service: services[0], start: 0, duration: 700 },
+ ...services.slice(1).map((service, index) => ({ id: `s${index}`, name: `${service} call`, service, parent: 'root', start: index * 100, duration: 80 })),
+ ];
+ const result = run(diagram);
+ assert.equal(result.status, 0, result.stderr);
+ const html = fs.readFileSync(result.output, 'utf8');
+ const labels = [...html.matchAll(/data-legend-semantic-kind="service:[^"]*"[\s\S]*?<text[^>]*>([^<]+)<\/text>/g)].map((match) => match[1]);
+ assert.equal(labels.length, 5, labels.join(' | '));
+ assert.ok(labels.includes('gateway · inventory'), labels.join(' | '));
+ assert.ok(labels.includes('auth · postgres'), labels.join(' | '));
+ assert.ok(labels.includes('cart'), labels.join(' | '));
+});