Track
track() draws a value as a length along a route: a bar that wraps, coils or curls round a circle. The route is the path option, an SVG path. The length channel is how much of it is drawn, and move() on length drags the end of the bar along the route.
API reference
track(options)
A value drawn as a length along a route. The route is the path option, and the length channel is the fraction of it drawn. Each row draws its route as an invisible grab area, then its bar.
track({ path, join, channels, edits, id, table, tip }) → Mark| Option | Type · default | Description |
|---|---|---|
path | string | | The route: an SVG path, or a function of the row returning one. Each M starts a lane, and only lanes hold value. In plot pixels, or in unit form when x, y or size is bound. A path that can’t be read draws nothing and logs a warning. |
join | 'round' | default'none' | What connects one lane to the next. It holds no value. 'round' leaves along one lane and arrives along the next. |
channels | objectdefault{} | Channel map — see Channels. |
edits | Edit[] | Mark-level edits. move() on length drags the end of the bar along the route; slide() adds to it along one axis. |
stroke, | styledefaultstroke: theme ink, | Shorthands for constant channels. The bar is a stroke and is never filled. |
| Channel | Type | Description |
|---|---|---|
length | linear | How much of the route is drawn. Its range is [0, 1], so the schema’s domain spans the whole route. Omitted, the whole route is drawn. Pair with move(). |
x / y | linear | | Where a unit-form path is centred. Binding either one places the path. |
size | linear | The radius of the box a unit-form path fits, in px (default 6). |
angle | linear | Rotation of a unit-form path in degrees, counter-clockwise from east. |
stroke / strokeWidth / strokeDash / opacity | const | | The bar's paint. |
A route for every row
The schema's domain spans the whole route: the domain's maximum draws all of it, and half of it draws half. Rows read on one scale when every row's route is the same length.
path is in plot pixels. A function of the row, (d, i, data) => string, gives each row its own route. When x, y or size is bound, the path is in unit form and placed the way shape places one: centred at x/y, fitted to a box of radius size, turned by angle. One path then draws a route for every row.
move() puts the end of the bar at the point of the route nearest the pointer. You can press anywhere on the route, even where no bar is drawn, so a bar at zero can still be grabbed. During a drag the end follows the route from where it was, so it doesn't jump to a part of the route that only passes close by. slide() on length also works: it adds to the value as you drag along one axis.
Project progress
One circular path, placed per row by x and size. move() on length writes done.
// How far along is each project? Drag the end of a ring round its circle.// One route for every row: a circle from the top, clockwise, in unit form.// x, y and size place it, so each row draws its own ring.const ring = "M0,-1 A1,1 0 1 1 -0.001,-1";const chart = Elicit({width: 460, height: 200,margins: { top: 10, right: 10, bottom: 40, left: 10 },axes: false,schema: {project: { type: "categorical" },done: { type: "quantitative", domain: [0, 100] },},data: [{ project: "Survey", done: 80 },],constraints: [snap({ step: 1 })],marks: [// The full circle, faint, under each ring.track({path: ring,channels: {x: { field: "project" }, size: { value: 50 }, y: { value: 75 },stroke: { value: "#dddddd" }, strokeWidth: { value: 12 },},}),track({path: ring,channels: {x: { field: "project" }, size: { value: 50 }, y: { value: 75 },length: { field: "done", edit: move() },stroke: { value: "#50AEB7" }, strokeWidth: { value: 12 },},}),text({ channels: {x: { field: "project" }, y: { value: 75 },text: { fn: (d) => `${d.done}%` }, fontSize: { value: 16 },} }),text({ channels: {x: { field: "project" }, y: { value: 160 },text: { field: "project" }, fontSize: { value: 12 }, fill: { value: "#555555" },} }),],});mount(chart.dom());
Lanes and joins
Each M in the path starts a lane. Only lanes hold value, so the gap from one lane to the next adds nothing to the length. join draws what connects them: "round" turns through a curve that leaves along one lane and arrives along the next, so two lanes running opposite ways get a half circle. "straight" draws a line across the gap. "none" (the default) leaves it empty. A join is drawn once the bar reaches the next lane.
A route with one lane, such as a coil with square corners, needs no join: every pixel of it holds value.
Du Bois's wrapped bars builds wrapped bars with track, and his coil and spiral draw a coil and a spiral with it.
Three joins
Three charts over one dataset. Each draws the same value along the same three lanes, with a different join.
// One value, drawn three ways. Each chart takes the same route, three lanes// with one `M` each, and a different `join` for what connects them.const route = "M110,20L410,20 M410,42L110,42 M110,64L410,64";const ds = Elicit.dataset({schema: { value: { type: "quantitative", domain: [0, 90] } },data: [{ value: 50 }],constraints: [snap({ step: 1 })],});for (const join of ["round", "straight", "none"]) {const chart = ds.chart({width: 460, height: 90,margins: { top: 0, right: 0, bottom: 0, left: 0 },axes: false,marks: [track({path: route,join,channels: {length: { field: "value", edit: move() },stroke: { value: "#50AEB7" }, strokeWidth: { value: 8 },},}),text({ channels: {x: { value: 20 }, y: { value: 42 },text: { value: `join: "${join}"` }, textAnchor: { value: "start" }, fontSize: { value: 12 },} }),],});mount(chart.dom());}