Dual Tree
The dual tree is the most flexible pattern. It fits any chart where each data point belongs to two categories at once: a stacked bar (year and browser), a clustered bar, or a line chart with a discrete x axis (month and city).
It is the structure at the heart of the Data Navigator paper (Elavsky, Nadolskis, and Moritz, IEEE VIS 2023). The Skeleton editor shows it as its schema view.
The idea: two trees, one set of leaves
A plain tree gives each data point one parent. That forces a choice. Do you group the stacked bar by year, or by browser? Either way, one question becomes hard to answer.
The dual tree refuses to choose. It builds both trees over the same data points:
Chart
┌─────────┴─────────┐
Year Browser (dimensions)
┌─────┼─────┐ ┌────┼────┬────┐
2015 2016 2017 Chrome Firefox ... (divisions)
│ │ │ │ │
└─────┴──┬──┴───────┴────┘
62%, Chrome, 2015 12%, Firefox, 2015 ... (shared data points)Every data point has two parents: its year and its browser. The inspector below the chart shows this as a grid. Each column is a year, each row is a browser, and every dot sits where its two parents cross.
Why it works
At a data point, the arrow keys answer two different questions.
- Left and Right answer "how does this browser change over time?" They keep the browser and change the year.
- Up and Down answer "how does this year break down?" They keep the year and change the browser.
This comes from childmostNavigation: 'across'. At the data point level, the sibling keys of each dimension jump to the matching point in the next division instead of the next point in the same division. Left and Right cross the year divisions. Up and Down cross the browser divisions.
Getting out is just as direct. W goes up to the point's year. J goes up to its browser. So you can ask "what about all of 2016?" and "what about Safari overall?" from the same spot.
Walk through it
Using the stacked bar chart:
| You are on | You press | You land on | Why |
|---|---|---|---|
| Chart | Enter | Year | First dimension |
| Year | Enter | 2015 | First year |
| 2015 | Enter | 62%, Chrome, 2015 | First point in 2015 |
| 62%, Chrome, 2015 | → | 63%, Chrome, 2016 | Same browser, next year |
| 63%, Chrome, 2016 | ↑ | 12%, Firefox, 2016 | Same year, the browser above |
| 12%, Firefox, 2016 | J | Firefox | Up to the browser group |
| Firefox | ↓ | Chrome | Next browser group, down the stack |
| Chrome | J | Browser | Up to the dimension |
Try the same path with the keyboard or the text chat. In chat, type enter, drill in, drill in, drill in, right, up, to-browser.
Text chat (works on touch screens)
Inspector (tree view)
Current node: none
How it is built
Two categorical dimensions, both with childmostNavigation: 'across'. The addLevel0 node is the root that holds them.
const topToBottom = [...stacks].reverse();
const firstRow = division => Object.values(division.values)[0];
const structure = dataNavigator.structure({
data: browsers,
idKey: 'id',
dimensions: {
parentOptions: { addLevel0: { id: 'chart', edges: [] } },
values: [
{
dimensionKey: 'year',
nodeId: 'years',
type: 'categorical',
divisionOptions: { divisionNodeIds: (key, value) => `year-${value}` },
behavior: { extents: 'circular', childmostNavigation: 'across' },
navigationRules: { sibling_sibling: ['left', 'right'], parent_child: ['to-year', 'drill-in'] }
},
{
dimensionKey: 'browser',
nodeId: 'browsers',
type: 'categorical',
divisionOptions: { divisionNodeIds: (key, value) => `browser-${value.toLowerCase()}` },
// order browsers top to bottom, so Down moves down the stack
operations: {
sortFunction: (a, b) =>
topToBottom.indexOf(firstRow(a).browser) - topToBottom.indexOf(firstRow(b).browser)
},
behavior: { extents: 'circular', childmostNavigation: 'across' },
navigationRules: { sibling_sibling: ['up', 'down'], parent_child: ['to-browser', 'drill-in'] }
}
]
}
});const structure = dataNavigator.structure({
data: browsers,
idKey: 'id',
dimensions: {
parentOptions: { addLevel0: { id: 'chart', edges: [] } },
values: [
{
dimensionKey: 'year',
nodeId: 'years',
type: 'categorical',
divisionOptions: { divisionNodeIds: (key, value) => `year-${value}` },
behavior: { extents: 'circular', childmostNavigation: 'across' },
// years are far apart in a clustered chart, so they get [ and ]
navigationRules: {
sibling_sibling: ['backward', 'forward'],
parent_child: ['to-year', 'drill-in']
}
},
{
dimensionKey: 'browser',
nodeId: 'browsers',
type: 'categorical',
divisionOptions: { divisionNodeIds: (key, value) => `browser-${value.toLowerCase()}` },
behavior: { extents: 'circular', childmostNavigation: 'across' },
// neighboring bars in a cluster are different browsers, so Left and Right
navigationRules: {
sibling_sibling: ['left', 'right'],
parent_child: ['to-browser', 'drill-in']
}
}
]
},
navigationRules: {
left: { key: 'ArrowLeft', direction: 'source' },
right: { key: 'ArrowRight', direction: 'target' },
backward: { key: 'BracketLeft', direction: 'source' },
forward: { key: 'BracketRight', direction: 'target' },
'drill-in': { key: 'Enter', direction: 'target' },
'drill-out': { key: 'Backspace', direction: 'source' },
'to-year': { key: 'KeyW', direction: 'source' },
'to-browser': { key: 'KeyJ', direction: 'source' }
}
});const structure = dataNavigator.structure({
data: cities,
idKey: 'id',
dimensions: {
parentOptions: { addLevel0: { id: 'chart', edges: [] } },
values: [
{
dimensionKey: 'month',
nodeId: 'months',
type: 'categorical',
divisionOptions: { divisionNodeIds: (key, value) => `month-${value.toLowerCase()}` },
behavior: { extents: 'circular', childmostNavigation: 'across' },
navigationRules: { sibling_sibling: ['left', 'right'], parent_child: ['to-month', 'drill-in'] }
},
{
dimensionKey: 'city',
nodeId: 'cities',
type: 'categorical',
divisionOptions: { divisionNodeIds: (key, value) => `city-${slug(value)}` },
behavior: { extents: 'circular', childmostNavigation: 'across' },
// lines cross, so Up and Down follow the city order
navigationRules: { sibling_sibling: ['up', 'down'], parent_child: ['to-city', 'drill-in'] }
}
]
}
});The three specs are almost the same. Only the keys change to fit the layout.
| Option | What it does |
|---|---|
addLevel0 | Adds the root above both dimensions. |
childmostNavigation: 'across' | Sibling keys at a data point move to the matching point in the next division. |
extents: 'circular' | The last year wraps to the first, and so on. |
sibling_sibling | The key pair for one dimension. Each dimension needs its own pair. |
parent_child | The first name moves up to the parent. Give each dimension its own name (to-year, to-browser) so both parents stay reachable. |
divisionNodeIds | Readable ids like year-2015. Helpful in the inspector and in your code. |
Match keys to the layout
The tree is the same in all three charts. The keys follow what is next to what on screen.
- Stacked bar. Browsers stack vertically, so Up and Down move between them. A
sortFunctionorders the browser divisions top to bottom, so Down really moves down. - Clustered bar. Neighboring bars are browsers, so Left and Right move between them. Years are far apart, so they get
[and]. - Multi-line. Months run left to right. Lines cross each other, so Up and Down follow a fixed city order.
Matching data points
'across' matches points by their position in each division. That works when every division lists its points in the same order, as these datasets do. If your data has gaps, pass a childmostMatching function in behavior to choose the match yourself.
Labels
Lead with the value, then both categories: 62%, Chrome, 2015. A division names itself and summarizes its children: 2015. 5 browsers. Chrome leads with 62%.
const n = structure.nodes;
n.chart.semantics = { label: `${alt} Two groupings: year and browser.` };
n.years.semantics = { label: 'Year. 3 years, 2015 to 2017.' };
n.browsers.semantics = { label: 'Browser. 5 browsers, Chrome to Other.' };
years.forEach(y => {
const top = browsers.filter(d => d.year === y).sort((a, b) => b.share - a.share)[0];
n[`year-${y}`].semantics = { label: `${y}. 5 browsers. ${top.browser} leads with ${top.share}%.` };
});
stacks.forEach(s => {
const rows = browsers.filter(d => d.browser === s);
const lo = Math.min(...rows.map(d => d.share));
const hi = Math.max(...rows.map(d => d.share));
n[`browser-${s.toLowerCase()}`].semantics = {
label: `${s}. 3 years, ${lo === hi ? `${lo}% each year` : `${lo}% to ${hi}%`}.`
};
});
browsers.forEach(d => {
n[d.id].semantics = { label: `${d.share}%, ${d.browser}, ${d.year}` };
});Focus indicators
| Node | Stacked bar | Clustered bar | Multi-line |
|---|---|---|---|
| Data point | Box around the segment | Box around the bar | Circle on the point |
| Year / month | Box around the column | Box around the cluster | Box around the month's points |
| Browser / city | Outline of each segment | Outline of each bar | Band along the line |
| Dimension | Year: plot and x axis. Browser: the browser names. | Year: same. Browser: the names above the first cluster. | Month: x axis. City: the names at the line ends. |
A browser group is spread across the chart, so its indicator is one outline per segment (unionOfRectPaths). A year sits in one place, so one box is enough.
const all = Object.values(bars);
n.chart.spatialProperties = rectSpatial({ x: 6, y: 6, width: width - 12, height: height - 12 }, 0);
n.years.spatialProperties = rectSpatial(unionBox(all, boxes.xAxis), 4);
n.browsers.spatialProperties = rectSpatial(boxes.labels, 4);
years.forEach(y => {
const col = browsers.filter(d => d.year === y).map(d => bars[d.id]);
n[`year-${y}`].spatialProperties = rectSpatial(unionBox(col), 4);
});
stacks.forEach(s => {
const segs = browsers.filter(d => d.browser === s).map(d => bars[d.id]);
n[`browser-${s.toLowerCase()}`].spatialProperties = spatial(unionBox(segs), unionOfRectPaths(segs, 3));
});
browsers.forEach(d => {
n[d.id].spatialProperties = rectSpatial(bars[d.id], 2);
});When to use something else
- Only one category? Use a list or a tree.
- Two numerical axes? Use 2D spatial.
- Two numbers and a category? Use spatial plus. It is a dual tree with a third dimension.