Declarative, Saveable Data Selections in CanvasXpress
Every CanvasXpress chart lives on top of one matrix: samples × variables, with annotations riding along on each axis. Slicing that matrix down to the rows and columns you actually want to look at — "just the Control samples," "only these five pathways," "samples where expression clears a threshold" — is one of the most common things a user does before a chart becomes useful. Until now, doing that meant clicking through the Data Filters panel by hand, every time, for every chart.
We've shipped two focused improvements that make this workflow faster and, more importantly, repeatable: a declarative dataSelection config option that lets you author a filter as a plain object (and save/reload it with the chart), and a live visible/total count summary right in the Data Filters panel so you always know how much of your data survived the cut.
The problem with filtering by hand
The Data Filters panel has always let you narrow a chart by annotation — check a box, drag a numeric range, and the chart redraws against the visible subset. That's great for one-off exploration. But it has two gaps if you want to operationalize a selection:
- There was no way to describe a filter as data. You couldn't hand a colleague (or an LLM building a chart on your behalf) a compact spec that says "these samples, this condition." You had to click.
- Once you did filter something, you had no simple way to see how much of your matrix was still visible without eyeballing the chart itself.
Both of those are now solved without adding a new tool to learn — they extend the panel and the config you already use.
Declarative selections: dataSelection
dataSelection is an opt-in config option. Instead of manually toggling checkboxes, you describe the slice of the matrix you want directly in the chart's configuration, using the same annotations that already live on your samples and variables:
var cx = new CanvasXpress("myChart", data, {
graphType: "Heatmap",
dataSelection: {
samples: {
any: [
{ annotation: "Treatment", op: "exact", value: ["Control"] },
{ annotation: "Site", op: "exact", value: ["Site3"] }
]
},
variables: {
all: [
{ annotation: "Pathway", op: "like", value: ["glyco"] }
]
}
}
});
A few things are worth calling out:
anyandallread the way you'd expect.anybehaves like OR,allbehaves like AND, and you can nest one level of grouping to express more nuanced logic — for example "(Control OR Site3) AND Dose ≥ 10."- Selections apply to samples, variables, or both, using the same annotation names already present in your data — there's nothing new to learn about your own dataset.
anyis strongest within a single annotation — picking multiple acceptable values for one field, likeTreatment in [Control, TreatmentA]. When you need to combine conditions across different annotations,all(AND) is the reliable path today; for anything more elaborate, named selections (below) give you a clean way to define and switch between several fully-resolved slices instead of composing one large mixed expression.
Because dataSelection de-sugars into the same filtering engine that already powers the Data Filters panel, brush selections, and the legend, there's no separate code path to trust — you're describing the same subset the UI would have produced, just without the clicking.
Named selections you can switch between
You're not limited to one selection. dataSelection also accepts an array of named blocks, so you can define several meaningful cohorts up front and flip between them:
dataSelection: [
{ name: "Controls", active: true, samples: { all: [
{ annotation: "Treatment", op: "exact", value: ["Control"] }
]}},
{ name: "Site 3 cohort", samples: { all: [
{ annotation: "Site", op: "exact", value: ["Site3"] }
]}}
]
The active flag marks which one is applied when the chart renders; you can switch selections at runtime and the chart redraws against the newly resolved subset. This is a genuinely useful pattern for dashboards or notebooks where you want to compare "Cohort A" and "Cohort B" views of the same chart without duplicating configuration.
It round-trips — for free
Because dataSelection is a first-class config option, it comes along for the ride wherever your configuration does. Calling:
var config = cx.getConfig();
returns your selection back in the same authored shape you wrote — not an internal, hard-to-read filter structure. That means a chart's selection survives the normal save/load cycle: use the toolbar's Save as JSON to persist the chart (selection included), and dropping that saved .json file back onto the chart container reloads it, selection intact. If you use the Reproduce action to replay how a chart was built, the selection is part of that replay too. For teams building charts programmatically — including LLM-assisted workflows — this turns "the filter I clicked through" into "the filter I can read, write, and hand off."
If you'd rather update a selection without touching the rest of the chart's configuration, that works the normal way too:
cx.updateConfig({ dataSelection: { samples: { all: [
{ annotation: "Age", op: "between", value: [40, 65] }
]}}}, true);
Always know how much survived
The second piece is smaller but solves a real everyday annoyance: the Data Filters panel now shows a live visible/total count as you filter — for example, "142 / 500 samples" — updating immediately as you check boxes or drag a numeric range. Whether you got there by clicking through the panel or by loading a dataSelection spec, you get instant, honest feedback on how much of your matrix is actually feeding the chart. No more guessing from the plot alone whether your filter did what you intended.
Why this matters
CanvasXpress has always been deliberately narrow about what a "dataset" is: one matrix, one worksheet, with annotations on each axis. That constraint is a feature — it keeps charts predictable and reproducible. dataSelection extends that same paradigm rather than working around it: it's just a friendlier, saveable way to describe the subset of your existing matrix you want to see, using the engine that was already trustworthy. Combined with live counts in the panel, selecting the right slice of your data — and knowing you got it right — is now a config detail instead of a repeated manual chore.