Flat Tables That Just Work: Better Array Ingest for Specialized CanvasXpress Charts
CanvasXpress has always been generous about input. Hand it a flat, two-dimensional array — a header row, then one row per observation — and it figures out which columns are variables, which are samples, and which are annotations. For the bread-and-butter chart types, Scatter, Bar, Box, and friends, that generic heuristic does the right thing. You never think about it.
But a few specialized chart types need the data oriented a particular way, and the generic heuristic did not know their quirks. Manhattan plots, Miami plots, copy-number Manhattan variants, and Clustree diagrams all expect their row identifiers and their measurement columns in specific roles. A Pie chart wants a real measure, not a count. When those expectations were not met, the result was a blank render or a single uniform slice — frustrating, because the data was fine; only its orientation was wrong.
That gap is now closed. The ingest layer builds the correct orientation for these specialized renderers, and uses a real measure for Pie, so the exact same flat array that works everywhere else works for them too.
What was going wrong
When the engine saw a records array without an obvious variable/sample split, it fell back to synthesizing a value column of all ones and pushing the real numeric columns off into the annotation slot. For a generic chart that is harmless. For the specialized types it was fatal:
- Manhattan / Miami / copy-number Manhattan resolve their points by looking marker names up among the samples and reading chromosome, position, and significance from the variable columns. If those columns never reached the right slot, the renderer had nothing to draw.
- Clustree expects a cells-by-resolution-levels matrix, with cluster-membership labels in the cells. The generic path stranded the levels in the wrong place.
- Pie showed a single "counts" slice of value one for every category, instead of slices proportional to your actual numbers.
The fix, from a user's point of view
Nothing in how you call CanvasXpress changes. You still pass a flat array and a config. What changed is that the engine now recognizes these cases and reshapes accordingly:
For the specialized scatter types, it builds a labeled-matrix orientation — row identifiers (the SNPs or the cells) as the variables, and the field or resolution columns as the samples — which is exactly what those renderers read.
For Pie, when your table has exactly one text column and exactly one numeric column, the engine uses the text column's values as the slice labels and the numeric column as the slice sizes. No more phantom count-of-one slices.
A concrete example
Here is a market-share Pie from a plain two-column array:
var data = [
["Company", "Share"],
["Acme", 34],
["Globex", 27],
["Initech", 19],
["Umbrella", 12],
["Soylent", 8]
];
new CanvasXpress("chart", data, { graphType: "Pie" });
You get five slices sized 34, 27, 19, 12, and 8 — proportional to the real shares — instead of five identical wedges. The engine reads Share as the measure because it is the single numeric column, and Company as the labels because it is the single text column.
A Manhattan plot works the same way. Hand it a table whose first column is marker names and whose remaining columns are chromosome, position, and significance, set the appropriate scatter type, and the points land across the chromosomes the way they should — no manual pivot into the engine's internal object form.
Why it stays safe
The careful part of this work is that it only kicks in for the narrow situations that need it. The Pie measure rule fires only when the table is exactly one text column plus one numeric column; multi-numeric matrices and the other Pie input shapes that already worked keep routing through their existing path, untouched. The specialized-matrix branch fires only when you have actually asked for one of those scatter types. Every chart that rendered correctly before renders identically now — the dozens of general chart types are completely unaffected.
That is the design principle throughout CanvasXpress ingest: make the hard cases work without making the easy cases any different. The specialized renderers were always capable of producing these plots; they just needed the data handed to them in the right orientation, and now the engine does that handoff for you.
The takeaway
If you have ever built a Manhattan or Miami plot, a Clustree, or a simple Pie and gotten a blank canvas or a meaningless uniform chart from a perfectly good table, the cause was almost certainly orientation, and it is fixed. Pass your flat array as you always would. The engine now meets the specialized types where they live, so one input format really does cover the whole gallery.