Elicit.js

Composite

A composite is a glyph: a group of ordinary marks, its parts, over the same rows of the dataset. Each part encodes some fields, and a part whose channel carries an edit is a handle. Give a part a frame: channel and the composite becomes a box that its parts sit inside.

API reference

composite(options)

A glyph: a group of marks over the shared dataset. Import plot from elicitjs. Returns an array of marks, which Elicit flattens into its marks list. In box mode — switched on by a part stating a frame: channel — the composite’s own x / y / size place and size a per-row box, and the parts are placed inside it.

composite({ parts, channels, edits, discreteScale, id }) → Mark[]
Options
OptionType · defaultDescription
parts
Mark[]default[]
The sub-marks, in z-order (later parts paint on top — visual parts first, handles last). Each part is an ordinary mark with its own channels / style shorthands (arm geometry, per-part stroke, a tip’s size). A part with an edit is a handle; a part without one is inert and the engine makes it pointerEvents:"none" so it can’t swallow a sibling’s drag.
channels
objectdefault{}
Shared channel map merged into every part. Use it for glyph-wide bindings (x/y/angle/fill). A part’s own channel for the same name wins (shallow replace). Inherited edits land on the last part only. In box mode x / y / size are withheld — they define the box, not each part’s position — and everything else still trickles.
fill, angle, …
shorthand
Constant shorthands desugared into composite channels (shared by every part unless a part overrides). Parts keep their own shorthands too — e.g. a composite angle, per-part stroke.
edits
Edit[]
Mark-level edits. They ride the last part — one dataset, so a whole-dataset edit declared on every part would fire once per part. In box mode they ride the box, whose channel map holds the glyph’s placement columns.
discreteScale
'band' | 'point'default'band'
Stamped onto any part that doesn’t declare its own. A glyph usually sits in a band slot.
id
stringdefault'composite'
Prefix for the parts’ generated ids (id/0, id/1, …), so each part keeps a stable identity across renders.
Channels
ChannelTypeDescription
frame: -0.4 (on x / y)
local position
Local range [-1, 1] from the box’s centre, y up — so { frame: -0.4 } is 40% of the way to the left edge. A local part that states no x/y sits at the origin, so parts never repeat the composite’s own position. Long form: { datum: -0.4, scale: "frame" }.
frame: 1 (on size / rx / ry / strokeWidth)
local magnitude
Local range [0, 1]: a fraction of the box’s half-size, so the part scales with the glyph.
frame: [lo, hi] (with a field)
field → box
Maps the field’s schema domain onto that slice of the box. The range is on the channel, the domain on the schema — the same division as everywhere else. Long form: scale: { type: "frame", range: […] }.
frame: [lo, hi] (with a categorical field)
categories → stops
A categorical or ordinal field spreads its categories evenly from lo to hi, the first category at lo. An edit on the channel snaps to the nearest category.
{ fn, frame: true }
derived local
fn(d) returns local units, the same units as { frame: -0.4 }. Use it to place a part where another part’s value puts it: a forearm at the end of an upper arm. It writes nothing, so it carries no edit.
frame on angle / curvature
private scale
No local box — the units are the channel’s own (degrees, half-chords). The scale is still per part, which is how two mirrored parts get opposite ranges without colliding on a global axis.
Returns / emits

An array of marks — the parts, with ids assigned, composite channels merged in. In box mode the array is led by the box, which carries the composite’s x/y/size and covers the whole glyph — so a move() / resize() on those channels picks the glyph up from anywhere on it. Nothing about the glyph reaches the engine: it sees ordinary marks reading the one dataset.

Lollipop

A lollipop is a stem plus a draggable tip. The stem is a ruleX spanning the baseline to the value. It carries no edit, so it is inert. The tip is a point that edits value. Drag a tip and its stem re-derives, because both marks read the same row.

One editable field (the tip)

The stem is a span ruleX (baseline → value); the tip point edits value.

const chart = Elicit({
width: 380, height: 260,
margins: { top: 14, right: 14, bottom: 26, left: 30 },
data: [
{ g: "A", value: 40 }, { g: "B", value: 62 },
{ g: "C", value: 48 }, { g: "D", value: 75 },
],
schema: {
g: { type: "categorical" },
value: { type: "quantitative", domain: [0, 100] },
},
marks: [
composite({
id: "lollipop",
parts: [
ruleX({
stroke: "#94A5B3", strokeWidth: 2,
channels: { x: { field: "g" }, y2: { field: "value" } },
}),
point({
fill: "#50AEB7", size: 7,
channels: {
x: { field: "g" },
y: { field: "value", edit: move() },
},
}),
],
}),
],
});
mount(chart.dom());
Try: Drag a lollipop tip up or down.

Error bar

One row holds three editable fields: mean (the dot), lo and hi (the caps). Each is its own mark with an edit on a plain y channel, so dragging a cap moves only that end. The whisker is a ruleX spanning lo to hi, and follows the caps because it reads the same rows.

Independent handles per field

Each handle is its own mark. The whisker spans lo..hi and follows the caps.

const chart = Elicit({
width: 380, height: 280,
margins: { top: 14, right: 14, bottom: 26, left: 30 },
data: [
{ g: "A", mean: 50, lo: 35, hi: 65 },
],
// lo, mean and hi all land on the y axis. The axis spans the UNION of their
// declared domains, so no chart-level y scale is needed.
schema: {
g: { type: "categorical", domain: ["A", "B", "C"] },
lo: { type: "quantitative", domain: [0, 60] },
mean: { type: "quantitative", domain: [0, 80] },
hi: { type: "quantitative", domain: [20, 100] },
},
marks: [
composite({
id: "errorbar",
parts: [
// Inert visual: no edit, so the engine makes it pointer-transparent.
ruleX({
stroke: "#6F8294", strokeWidth: 1.5,
channels: { x: { field: "g" }, y1: { field: "lo" }, y2: { field: "hi" } },
}),
point({
fill: "#50AEB7", size: 6,
channels: {
x: { field: "g" },
y: { field: "mean", edit: move() },
},
}),
tick({
stroke: "#20555A", strokeWidth: 2,
channels: { x: { field: "g" }, y: { field: "lo", edit: move() } },
}),
tick({
stroke: "#20555A", strokeWidth: 2,
channels: { x: { field: "g" }, y: { field: "hi", edit: move() } },
}),
],
}),
],
});
mount(chart.dom());
Try: Drag the centre dot to move the mean, or a cap to move an end.

Coupled move, centre within ends

The dot's edit.custom sets mean from the pointer and shifts lo and hi by the same amount, so the whole bar moves. A constraint declared once on the spec keeps the centre within the ends. It applies to every part's edits, so a cap stops at the centre whichever handle you drag.

const chart = Elicit({
width: 380, height: 280,
margins: { top: 14, right: 14, bottom: 26, left: 30 },
data: [
{ g: "A", mean: 50, lo: 35, hi: 65 },
{ g: "B", mean: 62, lo: 55, hi: 72 },
],
schema: {
g: { type: "categorical", domain: ["A", "B"] },
lo: { type: "quantitative", domain: [0, 100] },
mean: { type: "quantitative", domain: [0, 100] },
hi: { type: "quantitative", domain: [0, 100] },
},
// Invariant on the DATA: the centre stays within the ends. A cap drag and a dot
// drag are different marks, but one rule gates both — which is exactly why a
// constraint is declared here, on the spec, and not inside either mark.
constraints: [
constraints.custom(({ active }) => active
? { hi: Math.max(active.hi, active.mean), lo: Math.min(active.lo, active.mean) }
: undefined),
],
marks: [
composite({
id: "errorbar",
parts: [
ruleX({
stroke: "#6F8294", strokeWidth: 1.5,
channels: { x: { field: "g" }, y1: { field: "lo" }, y2: { field: "hi" } },
}),
point({
fill: "#50AEB7", size: 6,
channels: {
x: { field: "g" },
// Coupled move: the dot shifts lo/hi by the mean's delta.
y: { field: "mean",
edit: edit.custom((ctx) => {
const d = ctx.datum;
const s = ctx.channels[0].scale;
const mean = s.invertValue(ctx.pointer.y);
const delta = mean - d.mean;
return { ...d, mean, lo: d.lo + delta, hi: d.hi + delta };
}) },
},
}),
tick({
stroke: "#20555A", strokeWidth: 2,
channels: { x: { field: "g" }, y: { field: "lo", edit: move() } },
}),
tick({
stroke: "#20555A", strokeWidth: 2,
channels: { x: { field: "g" }, y: { field: "hi", edit: move() } },
}),
],
}),
],
});
mount(chart.dom());
Try: Drag the dot — the whole bar travels. Drag a cap past the dot — it stops at the centre.

Composite channels + per-part channels

Channels bind at two levels. The composite's channels (here x, y, angle) pass down to every part, so the glyph shares one position and one orientation. Each part still declares its own channels and shorthands: arm length, stroke colour, a hub's fill and size. A part's key wins on conflict. Inherited edits attach to the last part only, so one rotate() spins the whole glyph once.

Shared x/y/angle; per-part stroke on crossing ticks

A + made of tickY (horizontal) and tickX (vertical). Composite channels bind position and angle once; each tick keeps its own stroke and length. The last part holds the inherited rotate() edit.

const chart = Elicit({
width: 380, height: 280,
margins: { top: 14, right: 14, bottom: 26, left: 30 },
data: [
{ x: 25, y: 35, theta: -15 },
],
schema: {
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
theta: { type: "quantitative", domain: [-180, 180] },
},
marks: [
composite({
id: "plus",
discreteScale: "point",
// Glyph-wide: every part inherits these (unless it overrides).
channels: {
x: { field: "x" },
y: { field: "y" },
angle: {
field: "theta",
scale: { range: [-180, 180] },
edit: rotate({ pivot: "mark", fold: false, pick: "direct" }),
},
},
parts: [
// Horizontal arm — own stroke/length; inherits x/y/angle (edit stripped).
tickY({ length: 28, stroke: "#B7DEE1", strokeWidth: 5 }),
// Vertical arm — own stroke; last part keeps the inherited rotate().
tickX({ length: 28, stroke: "#50AEB7", strokeWidth: 5 }),
],
}),
],
});
mount(chart.dom());
Try: Drag the darker (vertical) arm of a + to spin it.

Same composite angle; hub point with its own fill/size

A square hub is the third part. It inherits x/y/angle from the composite and sets its own shape, fill and size; part channels win for those names. rotate() is still on the last part.

const chart = Elicit({
width: 380, height: 280,
margins: { top: 14, right: 14, bottom: 26, left: 30 },
data: [
{ x: 30, y: 40, theta: 20 },
],
schema: {
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
theta: { type: "quantitative", domain: [-180, 180] },
},
marks: [
composite({
id: "crosshair",
discreteScale: "point",
channels: {
x: { field: "x" },
y: { field: "y" },
angle: {
field: "theta",
scale: { range: [-180, 180] },
edit: rotate({ pivot: "mark", fold: false, pick: "direct" }),
},
},
parts: [
tickY({ length: 32, stroke: "#94A5B3", strokeWidth: 3 }),
tickX({ length: 32, stroke: "#94A5B3", strokeWidth: 3 }),
// Hub: own shape/fill/size; inherits x/y/angle; keeps rotate() (last).
point({
shape: "square",
size: 6,
fill: "#F2B94B",
}),
],
}),
],
});
mount(chart.dom());
Try: Drag the hub (last part) to spin the whole glyph.

Creating a whole glyph at once

A create gesture mints one row, and every part of the glyph encodes it, so one click adds a whole composite. See what can be created. Put create on one part only (here the tip). A click then appends one row, not one per part. The inert stem re-derives from the same row, so the stem and tip appear together.

Double-click to add a lollipop

create() is on the tip only; the stem (an inert ruleX from baseline → value) re-derives from the same new row. One row in, one whole glyph out. count({ max }) caps the dataset.

const chart = Elicit({
width: 380, height: 260,
margins: { top: 14, right: 14, bottom: 26, left: 30 },
data: [
{ x: 20, value: 45 },
],
schema: {
x: { type: "quantitative", domain: [0, 100] },
value: { type: "quantitative", domain: [0, 100] },
},
constraints: [ count({ max: 8 }) ],
marks: [
composite({
id: "lollipop",
parts: [
// The stem: inert, so it stays pointer-transparent and carries no create.
ruleX({
stroke: "#94A5B3", strokeWidth: 2,
channels: { x: { field: "x" }, y2: { field: "value" } },
}),
// The tip: the ONE part that owns the create. A plane gesture fans to every
// feature, so declaring create on a single part appends exactly one row —
// and because both parts read that row, a whole lollipop (stem + tip) appears.
// dblclick, since a move-drag also lives on this handle.
point({
fill: "#50AEB7", size: 7,
channels: {
x: { field: "x" },
y: { field: "value", edit: move() },
},
edits: [ create({ gesture: "dblclick", channels: ["x", "y"] }) ],
}),
],
}),
],
});
mount(chart.dom());
Try: Double-click empty space to add a lollipop · drag a tip to move it.

A glyph with its own units

The parts above sit on the chart's axes. Some glyphs need their own units: a face's eye sits 16% of the way up the face, not at y = 0.16 in the data.

Give a part a frame: channel and the composite becomes a box. The composite's x / y / size set each row's box centre and half-size, and frame: values are read inside that box:

  • x / y: [-1, 1] from the centre, y up. { frame: -0.4 } is 40% of the way to the left edge.
  • size / rx / ry / strokeWidth: [0, 1], a fraction of the half-size.
  • angle / curvature: the channel's own units. Each part has its own scale, so two parts can take opposite ranges.
  • { field: "f", frame: [lo, hi] } maps the field's schema domain onto that slice of the box. The domain stays on the schema.
  • A categorical field spreads its categories evenly over [lo, hi], and an edit snaps to the nearest one.
  • { fn: (d) => …, frame: true } is derived in local units. Use it to place a part where another part's value puts it, such as a forearm at the end of an upper arm.

x / y / size describe the box, so they stay off the parts. A part that states no position sits at the centre. { value } is in pixels, so use frame: for anything that should scale with the glyph.

For a single knob with a ring fill and a needle, see Needle → Ableton-style knob.

A dial per row

The composite's x and size place a box. The dial states no position, so it sits at the centre at the box's full half-size; the needle spans it in local units and rotates through its own angle scale.

const chart = Elicit({
width: 480, height: 300,
margins: { top: 20, right: 24, bottom: 40, left: 44 },
axes: { x: {}, y: {} },
data: [
{ site: "North", capacity: 30, load: 0.7 },
{ site: "South", capacity: 72, load: 0.3 },
],
schema: {
site: { type: "categorical", domain: ["North", "South"] },
capacity: { type: "quantitative", domain: [0, 100] },
load: { type: "quantitative", domain: [0, 1] },
},
marks: [
// One part states a channel in LOCAL units (`frame:`), so the composite
// becomes a BOX: its x / y / size place and size one per row. Inside it,
// x and y run [-1, 1] from the centre with y UP, and magnitudes are a
// fraction of the half-size.
composite({
id: "gauge",
channels: {
x: { field: "capacity" },
y: { value: 150 },
size: { value: 46 },
},
parts: [
// The dial: exactly the box's half-size. It states no position at all —
// inside a box, saying nothing means "here, at the glyph".
point({ channels: {
size: { frame: 1 },
fill: { value: "#EDF7F8" }, stroke: { value: "#6F8294" },
} }),
// The needle: a tick spanning the box's full width, rotated by `load`.
// The angle is a PRIVATE frame scale, so this glyph's degrees can't
// collide with another mark's — and the rotate inverts back through it.
tickY({ channels: {
x1: { frame: -0.85 },
x2: { frame: 0.85 },
angle: { field: "load", frame: [-80, 80],
edit: rotate({ pivot: "mark", pick: "direct" }) },
stroke: { value: "#EE7B5E" },
strokeWidth: { frame: 0.09 },
} }),
],
}),
],
});
mount(chart.dom());
Try: Drag a needle around its own centre.

Why they're real scales

A frame: channel is a real scale, built once per row, so the ordinary edits work inside a box. move, slide, rotate and resize invert a gesture through the same mapping that placed the part, and .accepts() reports the field's real range to an external control.

The chart's axes ignore frame: channels. An eye at { frame: -0.4 } leaves the x domain and the axes unchanged.

Everything scales together

A part's geometry is a fraction of the box, so resizing the glyph resizes its contents. An edit on an inner part still writes its own field on its own domain.

An edit on the composite's own x / y / size moves or resizes the whole glyph. The box covers the glyph, so you can grab it anywhere, including between the parts. A part with its own edit takes the drag first.

Resize the glyph, the contents follow

The outer disc is the box's half-size; the inner one is 0..0.8 of it. resize() is on the composite, so dragging the outer ring grows the whole glyph and the share stays put.

const chart = Elicit({
width: 480, height: 300,
margins: { top: 20, right: 24, bottom: 40, left: 44 },
axes: { x: {}, y: false },
data: [
{ town: "Ayr", weight: 26, share: 0.7 },
],
schema: {
town: { type: "categorical", domain: ["Ayr", "Bede", "Cara"] },
weight: { type: "quantitative", domain: [10, 70] },
share: { type: "quantitative", domain: [0, 1] },
},
marks: [
composite({
id: "pip",
channels: {
x: { field: "town" },
// `size` is the box's HALF-SIZE, so resizing the glyph resizes everything
// placed in it. The edit lives here, on the glyph itself: the box is a
// real grab target covering the whole pip, so this picks it up bodily.
size: { field: "weight", scale: { range: [18, 54] }, edit: resize() },
},
parts: [
// The outer disc IS the box — full half-size, at the origin. It carries
// no edit of its own, so it is pointer-transparent and a drag on it
// reaches the box underneath.
point({ channels: {
size: { frame: 1 },
fill: { value: "#EDF7F8" }, stroke: { value: "#6F8294" },
} }),
// The inner disc is 0..0.8 of the half-size — a FRACTION, so it grows with
// the glyph and its edit still writes `share` on the same [0, 1] domain.
point({ channels: {
size: { field: "share", frame: [0, 0.8],
edit: slide({ axis: "y", increase: "up" }) },
fill: { value: "#50AEB7" },
} }),
],
}),
],
});
mount(chart.dom());
Try: Drag the inner disc up to raise its share · drag the outer ring outward to grow the glyph.

What box mode returns

Box mode returns the box first, then the parts, all as plain marks. The box carries the composite's x / y / size, so those fields still build the chart's axes. Without an edit on them, the box is inert.

Two limits apply to a part placed in the box:

  • A { fn } channel is called once per row, as (d, 0, [d]), so it sees only its own row. Read the field instead. Its result is in pixels; add frame: true to return local units.
  • A line-family mark inside a box is built one row at a time, so it cannot join rows into a series, and it logs a warning. To connect rows, position it on the global scales, or move it out of the composite.

A part with no frame: channel keeps the global scales, so one part of a glyph can still span to a data value.

Build a face with one brow

face() is a composite in box mode: a point head, two ellipse eyes, two tickY brows and a curveY mouth. It is a preset, so you can build a different face from the same parts. Here it has one brow instead of two.

The brow and the mouth are both curve marks. curvature is the apex's offset from the chord, as a fraction of the half-chord, so it scales with the glyph. Positive curvature bows to the left of the curve's direction, which arches a rightward chord upward. A descending frame: range reverses that, so a rising grump dips the brow and a rising mood deepens the smile.

The face page builds the preset's own parts the same way.

One brow, two curves

Head, eyes, brow and mouth, all placed in the glyph's local units. The brow and the mouth are the same mark with opposite frame ranges.

const chart = Elicit({
width: 520, height: 300,
margins: { top: 20, right: 24, bottom: 40, left: 24 },
axes: { x: {}, y: false },
data: [
{ who: "Ada", grump: 0.15, mood: 0.85 },
],
schema: {
who: { type: "categorical", domain: ["Ada", "Brun", "Cyd"] },
grump: { type: "quantitative", domain: [0, 1] },
mood: { type: "quantitative", domain: [0, 1] },
},
marks: [
// A face is nothing but a composite in box mode — so if you want a face with
// ONE brow, you just use one part. Two `curveY`s do all the expression here:
// a unibrow across both eyes and a mouth under them.
composite({
id: "unibrow",
// Where the glyph goes and how big it is. Nothing inside restates this.
channels: { x: { field: "who" }, size: { value: 56 } },
parts: [
// Head: the box itself, at the origin.
point({ channels: {
size: { frame: 1 },
fill: { value: "#F2B94B" }, stroke: { value: "#C99128" },
} }),
// Eyes: pinned local positions, radius a fraction of the half-size.
point({ channels: {
x: { frame: -0.34 }, y: { frame: 0.12 }, size: { frame: 0.11 },
fill: { value: "#20555A" },
} }),
point({ channels: {
x: { frame: 0.34 }, y: { frame: 0.12 }, size: { frame: 0.11 },
fill: { value: "#20555A" },
} }),
// THE UNIBROW. `curvature` is the apex's offset from the chord as a
// fraction of the half-chord, and positive bows to the LEFT of travel —
// so on this rightward chord positive arches UP. The descending range
// turns a rising `grump` into a brow that dips toward the nose.
curveY({ channels: {
x1: { frame: -0.60 }, x2: { frame: 0.60 },
y: { frame: 0.46 },
curvature: { field: "grump", frame: [0.45, -0.35],
edit: slide({ axis: "y", increase: "down" }) },
stroke: { value: "#20555A" },
strokeWidth: { frame: 0.10 },
} }),
// The mouth, same mark and the same trick with the sign reversed.
curveY({ channels: {
x1: { frame: -0.34 }, x2: { frame: 0.34 },
y: { frame: -0.36 },
curvature: { field: "mood", frame: [0.6, -0.6],
edit: slide({ axis: "y", increase: "up" }) },
stroke: { value: "#20555A" },
strokeWidth: { frame: 0.06 },
} }),
],
}),
],
});
mount(chart.dom());
Try: Drag the unibrow down to make a face grumpier · drag a mouth up to cheer it up.