Skip to content

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

Label chart bars with values and pie slices with value and share

tt-a1i031c816d3ffc
diff --git a/archify/explainer/charts.mjs b/archify/explainer/charts.mjs
index 8a2d7283..e93c682f 100644
--- a/archify/explainer/charts.mjs
+++ b/archify/explainer/charts.mjs
@@ -10,12 +10,22 @@ register(pie, xychart, quadrantChart, sankey, radar, venn);
const NATIVE = { flowchart: 'workflow or architecture', sequence: 'sequence', class: 'class', er: 'erd', state: 'lifecycle', timeline: 'timeline', gantt: 'timeline or waterfall', mindmap: 'tree', treeview: 'tree' };
+// A pie legend reads "Label · value (share%)" rather than Pele's "Label [value]". The labels are
+// rewritten before rendering so the legend is laid out for their real width.
+function pieLegend(text) {
+ if (!/^\s*pie\b/u.test(text)) return text;
+ const slice = /^(\s*)"((?:[^"\\]|\\.)*)"\s*:\s*(-?\d+(?:\.\d+)?)\s*$/gmu;
+ const total = [...text.matchAll(slice)].reduce((sum, match) => sum + Number(match[3]), 0);
+ if (!(total > 0)) return text;
+ return text.replace(/^(\s*pie)\s+showData\b/u, '$1').replace(slice, (_, indent, label, value) => { const share = Math.round(Number(value) / total * 100); return `${indent}"${label} · ${value}${/\p{Script=Han}/u.test(label) ? `(${share}%)` : ` (${share}%)`}" : ${value}`; });
+}
+
/** Render a Mermaid chart to static SVG, or return a located diagnostic reason. */
export function compileExplainerChart(text) {
const type = detectType(text);
if (type && NATIVE[type]) return { error: `Mermaid ${type} is drawn with the native ${NATIVE[type]} shorthand, which Archify validates and lets readers explore.`, example: `@${NATIVE[type].split(' ')[0]} id=...` };
try {
- const result = render(text, { padding: 8, fontSize: 14, links: false, images: false, config: { xyChart: { width: 520, height: 280 }, quadrantChart: { chartWidth: 420, chartHeight: 420 } } });
+ const result = render(pieLegend(text), { padding: 8, fontSize: 13, links: false, images: false, config: { xyChart: { width: 480, height: 260, showDataLabel: true }, quadrantChart: { chartWidth: 400, chartHeight: 400 } } });
// A rotated CJK axis title lies on its side; vertical writing keeps the characters upright.
const svg = result.svg.replace(/<g transform="translate\(([\d.-]+),([\d.-]+)\) rotate\(-90\)"><text x="0" y="[\d.-]+" text-anchor="middle">([^<]*\p{Script=Han}[^<]*)<\/text><\/g>/gu, (_, x, y, label) => `<text x="${x}" y="${y}" text-anchor="middle" writing-mode="vertical-rl">${label}</text>`);
return { svg, width: result.width, height: result.height, type: result.type };
diff --git a/archify/explainer/reader.css b/archify/explainer/reader.css
index 6d7ba976..9452db93 100644
--- a/archify/explainer/reader.css
+++ b/archify/explainer/reader.css
@@ -174,7 +174,8 @@ meter{width:100%;height:8px;accent-color:var(--accent)}
/* Code and diff */
.chart{margin:0;display:flex;flex-direction:column;--pele-bg:transparent;--pele-fg:var(--ink);--pele-muted:var(--muted);--pele-line:var(--rule-strong);--pele-surface:var(--sunk);--pele-surface-alt:var(--zebra);--pele-border:var(--rule-strong);--pele-accent:var(--accent);--pele-font:var(--sans);--pele-font-mono:var(--mono);--pele-series-1:var(--accent);--pele-series-2:var(--caution);--pele-series-3:var(--good);--pele-series-4:var(--violet);--pele-series-5:var(--bad);--pele-series-6:var(--accent-ink);--pele-series-7:var(--muted);--pele-series-8:var(--faint)}
-.chart>svg{display:block;width:min(100%,calc(var(--native-width,100vw) * 1.25));height:auto;max-height:380px;margin-inline:auto}
+/* Charts never scale above their native size, so their text stays at the page's small-text size. */
+.chart>svg{display:block;width:min(100%,var(--native-width,100vw));height:auto;margin-inline:auto}
.chart figcaption{font-size:12px;color:var(--muted);margin-top:8px;padding:0 4px}
.snippet{border:1px solid var(--rule);border-radius:8px;background:var(--code);overflow:hidden}
.snippet figcaption{display:flex;justify-content:space-between;align-items:center;gap:12px;padding:6px 12px;border-bottom:1px solid var(--rule);font-size:12px;color:var(--muted);background:var(--panel)}
diff --git a/archify/references/explainer-authoring.md b/archify/references/explainer-authoring.md
index 48761b17..4e872c46 100644
--- a/archify/references/explainer-authoring.md
+++ b/archify/references/explainer-authoring.md
@@ -200,6 +200,8 @@ xychart-beta
```
````
+Bars show their values, and a pie legend shows each value with its share. Use `xychart-beta horizontal` for ranked items or long category names. Put the contrast the reader must see in one chart, such as P50 beside P99.
+
Chart only numbers the reader can trust: values from the user, a source or a measurement. Mark illustrative values in scope. Quote every label that contains spaces or non-ASCII text. Flowcharts, sequences, class, ER, state, timeline and mind-map Mermaid use the native shorthand above, which Archify validates and lets readers explore.
## Directive reference
diff --git a/test/explainer-charts.test.mjs b/test/explainer-charts.test.mjs
index a88b2de2..eb83a21b 100644
--- a/test/explainer-charts.test.mjs
+++ b/test/explainer-charts.test.mjs
@@ -42,3 +42,12 @@ test('explainer chart CJK axis titles stand upright and task lists become checkl
const mixed = finalize(t, 'pie\n "A" : 1\n```\n\n- [ ] Task\n- Plain\n\n```text\nx');
assert.ok(mixed.receipt.diagnostics.some(d => d.code === 'explainer/parse-list' && /checklist/.test(d.message)));
});
+
+test('explainer charts label bar values and give pie slices their value and share', t => {
+ const bars = finalize(t, 'xychart-beta\n x-axis ["Before", "After"]\n bar [80, 600]');
+ assert.match(bars.html, /<text[^>]*>600<\/text>/, 'bars carry their value');
+ const pie = finalize(t, 'pie showData\n "Viewer" : 0.8\n "字体" : 0.2');
+ assert.match(pie.html, /Viewer · 0\.8 \(80%\)/);
+ assert.match(pie.html, /字体 · 0\.2(20%)/);
+ assert.doesNotMatch(pie.html, /\[0\.8\]/);
+});