Skip to content

Focus Indication ​

A focus indicator shows where someone is in a chart. Keyboard users, switch users, people using voice or gestures, and sighted screen reader users all rely on it. The figures below are static and show common shapes for indicators, with the geometry helper that builds each one.

Guidelines ​

  • Make it visible. Focus must be visible (WCAG 2.4.7). Aim for an outline at least 2px thick with 3:1 contrast against what it sits on (WCAG 2.4.13, 1.4.11).
  • Match the shape of what is focused. A box for a bar, an outline around each segment of a series, a band for a line, a hull for a group of points.
  • Leave a gap. Pad the indicator outward so it doesn't cover the mark or change how big it looks.
  • Keep it on top. Draw the focused mark above other marks so nothing covers it (WCAG 2.4.11).
  • Contrast with the marks and the background. Marks come in many colors. The figures here draw the indicator twice: a wide stroke in the background color, then a narrower stroke in the text color on top. This keeps it visible on any mark.
  • Don't rely on color alone. A change in fill or opacity is easy to miss. An outline adds shape.

Chartability covers these and related checks in more depth.

How Data Navigator draws them ​

Data Navigator renders one element at a time over your chart, sized by spatialProperties (x, y, width, height). When you add spatialProperties.path, it draws that SVG path as the element's outline. The geometry helpers return these paths from the shapes you already have.

js
import {
    boundingRectPath,
    unionOfRectPaths,
    convexHullOfRects,
    convexHullOfCircles,
    offsetLinePath
} from 'data-navigator';

node.spatialProperties = { x, y, width, height, path: boundingRectPath([bar], 3) };

Charts drawn on a <canvas> have no elements to measure, so you may need to draw the indicator yourself. See Trouble with Focus Indication.

A single bar ​

boundingRectPath draws one box around one or more rects. The second argument is the padding.

js
const path = boundingRectPath([bars[2]], 3);

A column of a stacked bar ​

The same helper, given every segment in the column, draws one box around all of them.

js
const column = segments.filter(d => d.c === 0);
const path = boundingRectPath(column, 4);

A series across columns ​

A series is spread out, so one box would cover marks that aren't part of it. unionOfRectPaths outlines each rect on its own, in one path.

js
const series = segments.filter(d => d.s === 0);
const path = unionOfRectPaths(series, 3);

A cluster of uneven bars ​

convexHullOfRects wraps a group of rects tightly, following the tops of bars with different heights.

js
const cluster = bars.filter(d => d.group === 1);
const path = convexHullOfRects(cluster, 4);

A group of points ​

convexHullOfCircles wraps a set of circles, including their radius and the padding.

js
const group = points.filter(d => d.group === 0);
const path = convexHullOfCircles(group, 4);

A scatterplot split into ranges ​

When a scatterplot bins each axis into numerical ranges, a range covers a whole strip of the plot, not just the points in it. So its indicator is a band from edge to edge. Skeleton and the Bokeh wrapper both draw scatterplots this way.

Build one rect per range from your scales. Each division node keeps its range in numericalExtents.

js
const extents = [
    [0, 25],
    [25, 50],
    [50, 75],
    [75, 100]
];
const columns = extents.map(([lo, hi]) => ({
    x: x(lo),
    y: y(100),
    width: x(hi) - x(lo),
    height: y(0) - y(100)
}));
const rows = extents.map(([lo, hi]) => ({
    x: x(0),
    y: y(hi),
    width: x(100) - x(0),
    height: y(lo) - y(hi)
}));

The whole chart ​

At the top of the chart, outline every range on both axes. Together they show the grid someone can move through.

js
const path = unionOfRectPaths([...columns, ...rows]);

One axis ​

On an axis, like the x dimension, outline every range on that axis.

js
const path = unionOfRectPaths(columns);

One range ​

A single range gets a single band. An x range is a column, and a y range is a row. No padding, so neighboring bands line up.

js
const path = boundingRectPath([columns[1]]);
js
const path = boundingRectPath([rows[2]]);

One point ​

A point gets a ring just outside its edge.

js
const path = convexHullOfCircles([points[4]], 3);

A line ​

offsetLinePath draws a band that follows a polyline. The second argument is half the band's width.

js
const path = offsetLinePath(lines[0], 7);

The pink line was drawn after the focused line, so it crosses over it inside the band.

Keep the focused mark on top ​

When marks overlap, draw the focused one last. In SVG, move its element to the end of its parent. On a canvas or in WebGL, redraw the focused mark after everything else. A static image can't be redrawn, so the indicator has to do the work alone.

js
const focused = marks.nodes()[0];
focused.parentNode.appendChild(focused);

A legend or axis ​

Grouping nodes, like a dimension, can point to the guide that names them. A box around the legend works well.

js
const box = legend.node().getBBox();
const path = boundingRectPath([box], 6);

See them in use ​

  • The patterns each include a focus indicator table for their charts.
  • The Many Ways demo uses boxes, a series outline, and a legend box on one stacked bar chart.
  • Bespoke Visualization uses custom paths for marks that aren't rectangles.

Released under the MIT License.