Skip to content

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

Reject blank data-chart values instead of drawing them as zero

tt-a1i67c6d68253eb
diff --git a/archify.zip b/archify.zip
index 19f5a053..51a39e95 100644
Binary files a/archify.zip and b/archify.zip differ
diff --git a/archify/explainer/charts.mjs b/archify/explainer/charts.mjs
index 98a669af..8b03886e 100644
--- a/archify/explainer/charts.mjs
+++ b/archify/explainer/charts.mjs
@@ -56,8 +56,15 @@ export function chartFromData(bytes, filePath, { kind, x, y, unit }) {
if (missing) return { error: `The data file has no column "${missing}". Columns: ${[...columns].join(', ')}.` };
if (rows.length > (kind === 'pie' ? 12 : 60)) return { error: `A ${kind} chart takes at most ${kind === 'pie' ? 12 : 60} rows; this file has ${rows.length}.` };
const quote = value => `"${String(value).replace(/["\\]/gu, '')}"`;
- const numbers = column => rows.map(row => Number(String(row[column]).replace(/,/gu, '')));
- for (const column of y) { const bad = numbers(column).findIndex(value => !Number.isFinite(value)); if (bad >= 0) return { error: `Column "${column}" has a non-numeric value in data row ${bad + 1}: ${rows[bad][column]}.` }; }
- if (kind === 'pie') return { text: `pie\n${rows.map(row => ` ${quote(row[x])} : ${Number(String(row[y[0]]).replace(/,/gu, ''))}`).join('\n')}` };
+ // A blank cell is missing data, not zero: Number('') is 0, so blanks are rejected before conversion.
+ const blank = value => value === undefined || value === null || String(value).trim() === '';
+ const numbers = column => rows.map(row => blank(row[column]) ? NaN : Number(String(row[column]).replace(/,/gu, '')));
+ for (const column of y) {
+ const bad = numbers(column).findIndex(value => !Number.isFinite(value));
+ if (bad < 0) continue;
+ if (blank(rows[bad][column])) return { error: `Column "${column}" is empty in data row ${bad + 1}. A blank is missing data, not zero: fill in the value, or leave the row out and say so in the caption.` };
+ return { error: `Column "${column}" has a non-numeric value in data row ${bad + 1}: ${rows[bad][column]}.` };
+ }
+ if (kind === 'pie') { const values = numbers(y[0]); return { text: `pie\n${rows.map((row, i) => ` ${quote(row[x])} : ${values[i]}`).join('\n')}` }; }
return { text: `xychart-beta\n x-axis [${rows.map(row => quote(row[x])).join(', ')}]\n${unit ? ` y-axis ${quote(unit)}\n` : ''}${y.map(column => ` ${kind} ${quote(column)} [${numbers(column).join(', ')}]`).join('\n')}` };
}
diff --git a/archify/references/explainer-authoring.md b/archify/references/explainer-authoring.md
index 2f6eebeb..814f76f1 100644
--- a/archify/references/explainer-authoring.md
+++ b/archify/references/explainer-authoring.md
@@ -205,7 +205,7 @@ xychart-beta
Name each series (`bar "Before" [...]`) so the chart gets a legend. 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. When numbers carry the point, such as one value jumping while others stay flat, a before/after or a share, chart them so the contrast is seen at a glance; a table under the chart adds only the words each number needs. Put the contrast in one chart, such as mean, P50 and P99 before and after.
-When the numbers are in a CSV or JSON file next to the draft, chart the file instead of copying its values: `@chart type=bar|line|pie data=latency.csv x=day y=p50,p99 unit=ms title="..."`. `x` names the label column and `y` one value column per series (a pie uses the first). CSV needs a header row; JSON is an array of objects. The file is read and frozen at delivery, up to 60 rows (12 for a pie).
+When the numbers are in a CSV or JSON file next to the draft, chart the file instead of copying its values: `@chart type=bar|line|pie data=latency.csv x=day y=p50,p99 unit=ms title="..."`. `x` names the label column and `y` one value column per series (a pie uses the first). CSV needs a header row; JSON is an array of objects. The file is read and frozen at delivery, up to 60 rows (12 for a pie). A blank value is an error, not zero: fill it in, or leave the row out and say so in the caption.
A chart states where its numbers come from the same way text does: measured, from a source, estimated or illustrative, in its caption or 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.
diff --git a/test/explainer-charts.test.mjs b/test/explainer-charts.test.mjs
index 05a27717..d25855f1 100644
--- a/test/explainer-charts.test.mjs
+++ b/test/explainer-charts.test.mjs
@@ -67,3 +67,13 @@ test('a data chart reads its CSV next to the draft, freezes it, and names a miss
assert.notEqual(missing.status, 0);
assert.ok(missing.receipt.diagnostics.some(d => /no column "p95"/.test(d.message)));
});
+
+test('a blank data cell is missing data, never drawn as zero', async () => {
+ const { chartFromData } = await import('../archify/explainer/charts.mjs');
+ for (const [file, bytes] of [['a.csv', 'day,p99\nMon,80\nTue,\n'], ['a.json', '[{"day":"Mon","p99":80},{"day":"Tue","p99":null}]'], ['b.json', '[{"day":"Mon","p99":80},{"day":"Tue"}]']]) {
+ const result = chartFromData(Buffer.from(bytes), file, { kind: 'bar', x: 'day', y: ['p99'] });
+ assert.equal(result.text, undefined, file);
+ assert.match(result.error, /empty in data row 2/, file);
+ }
+ assert.match(chartFromData(Buffer.from('k,v\nA,60\nB,40\n'), 'a.csv', { kind: 'pie', x: 'k', y: ['v'] }).text, /"A" : 60\n {2}"B" : 40/);
+});