Elicit.js

Face (emotion)

face() encodes a row's fields as a face. Drag a feature to write its field back: pull the mouth into a smile, widen an eye, tilt a brow. It is a preset that returns a composite in box mode: a point head, two ellipse eyes, two tickY brows and a curveY mouth, placed in the glyph's local units. Each parameter is a channel on one part, editable once you bind it to a field.

API reference

face(options)

Import plot from elicitjs. A preset, not a mark: it returns a composite in box mode — a head point, two ellipse eyes, two tickY brows and a curveY mouth — each placed in the glyph’s own local units. So every feature is its own drag target, and every parameter takes the universal edits. Its centre is placed by the x/y channels when present, else parked at the plot centre.

face({ channels, size, ink, edits, id }) → Mark[]
Options
OptionType · defaultDescription
channels
FaceChannelsdefaultemotion preset
The channel map. The six face params are channels — bind a field with mouthCurve: { field: 'joy', edit: slide({ axis: 'y' }) }, or pin a constant with { value: 0.8 } (a fraction of that param’s travel). Bind none and you get the emotion preset (mouthCurve ← valence, eyeScale ← arousal); binding any one replaces it.
size
number | ChannelSpecdefaultband slot, else min(w,h)·0.35
The box's half-size, which the head is drawn at — so every feature scales with it. Set it when drawing many faces so they don't overlap.
ink
stringdefault'#1f2937'
The colour of the drawn features (eyes, brows, mouth).
channels.x / .y
ChannelSpec
Optional: place the face centre in a plot (small-multiples, or an emotion-space scatter). An edit here rides on the box, which covers the whole glyph — so move() picks the face up from anywhere on it.
fill, stroke
styledefault'#FFD666' / '#B7791F'
The head's colour.
edits
Edit[]
Mark-level edits. They go on the face’s box, which covers the whole glyph, so a whole-dataset edit (create) fires once per gesture.
Channels
ChannelTypeDescription
mouthCurve
→ mouth curvature
Deep frown ∩ ↔ deep smile ∪. Natural edit: slide({ axis: 'y', increase: 'up' }). (Preset: ← valence.)
mouthAsym
→ mouth angle
Centred ↔ smirk. Natural edit: rotate({ pivot: 'mark', pick: 'direct' }).
eyeScale
→ eye rx
Pinpricks ↔ wide. Natural edit: slide({ axis: 'x', increase: 'right' }). (Preset: ← arousal.)
eyeSquint
→ eye ry
Round ↔ flat. Natural edit: slide({ axis: 'y', increase: 'down' }). Unbound, the eyes stay round as they widen.
browHeight
→ brow y
Slammed down ↔ high arch. Natural edit: slide({ axis: 'y', increase: 'up' }).
browTilt
→ brow angle
Sad (outer-down) ↔ angry (inner-down); the two brows mirror each other. Natural edit: rotate({ pivot: 'mark', pick: 'direct' }).
x, y
→ box x, y
Face centre; omitted parks it at the plot centre. move() on either picks the whole face up.
size
→ box size
The box's half-size, drawn as the head. resize() on it scales the whole glyph.
Returns / emits

An array of marks (Elicit flattens it): the composite’s box — which draws one invisible hit circle per row, so move() / resize() on x/y/size picks the whole face up — then head, eyes, brows and mouth.

One face — drag to feel

The emotion preset binds mouthCurve to valence and eyeScale to arousal. Binding any parameter yourself drops the preset. Pull the mouth up to smile, or drag an eye to widen it. Each gesture inverts through the field's scale, and the whole face re-derives.

Face edits are ordinary edits on its parts' channels: a slide on the mouth's curvature, a slide on an eye's radius.

Valence × arousal

The two-field emotion preset. The mouth and eyes are the drag targets themselves.

const chart = Elicit({
width: 320, height: 320,
margins: { top: 12, right: 12, bottom: 12, left: 12 },
data: [ { valence: 0.3, arousal: 0.1 } ],
schema: {
valence: { type: "quantitative", domain: [-1, 1] },
arousal: { type: "quantitative", domain: [-1, 1] },
},
marks: [
// A face draws its features but writes nothing until an edit says so. The
// emotion preset binds mouthCurve ← valence and eyeScale ← arousal; declaring
// them here is what makes those two columns editable — and says which they are.
// Each param is a channel on a real part, so it takes the ordinary edits.
face({
channels: {
mouthCurve: { field: "valence", edit: slide({ axis: "y", increase: "up" }) },
eyeScale: { field: "arousal", edit: slide({ axis: "x", increase: "right" }) },
},
}),
],
});
mount(chart.dom());
Try: Drag the mouth up/down (valence) or drag an eye sideways (arousal).

Turn on more expressions

Bind any subset of the six params in channels, each a { field } with the edit you want. Unbound params stay neutral. Here every param is live: the mouth (↕ curve, ↔ smirk), the eyes (↔ aperture, ↕ squint), and the brows (↕ height, ↔ tilt).

Two params on one part share one gesture. Drag an eye sideways to open it, or down to squint it: rx and ry are two channels on one ellipse. Two edits on one part must read different components of the drag, one on axis: "x" and one on axis: "y".

A brow's tilt drives an angle but uses slide, not rotate. You grab a brow at its own pivot, so rotate would swing through most of a half-turn in a few pixels.

Full Chernoff face

All six parameters bound to fields; grab any feature to sculpt the expression.

const chart = Elicit({
width: 340, height: 340,
margins: { top: 12, right: 12, bottom: 12, left: 12 },
data: [ {
curve: 0.7, smirk: 0.5,
aperture: 0.6, squint: 0.2, browH: 0.5, browT: 0.4,
} ],
schema: {
curve: { type: "quantitative", domain: [0, 1] },
smirk: { type: "quantitative", domain: [0, 1] },
aperture: { type: "quantitative", domain: [0, 1] },
squint: { type: "quantitative", domain: [0, 1] },
browH: { type: "quantitative", domain: [0, 1] },
browT: { type: "quantitative", domain: [0, 1] },
},
marks: [
face({
channels: {
// The mouth is one part, so one drag drives both of its params: the
// vertical component bends it, the horizontal one tilts it into a smirk.
mouthCurve: { field: "curve", edit: slide({ axis: "y", increase: "up" }) },
mouthAsym: { field: "smirk", edit: slide({ axis: "x", increase: "right" }) },
// Each eye is one ellipse: rx opens it, ry squints it. Horizontal and
// vertical drag, so one gesture on an eye reads as reshaping it.
eyeScale: { field: "aperture", edit: slide({ axis: "x", increase: "right" }) },
eyeSquint: { field: "squint", edit: slide({ axis: "y", increase: "down" }) },
// Each brow is one tick: height is where it SITS — a positional channel in
// the face's frame, so `move()` inverts straight back through it — and tilt
// is a magnitude, so it slides.
browHeight: { field: "browH", edit: move({ channels: ["y"] }) },
browTilt: { field: "browT", edit: slide({ axis: "x", increase: "right" }) },
},
}),
],
});
mount(chart.dom());
Try: Drag the mouth, an eye, or a brow — each is a separate mark.

Many faces in a plot

Give the face an x (or y) channel and it is placed like a point: one editable face per row, each with its own frame. Set x: { field: 'valence' }, y: { field: 'arousal' } and the faces form an emotion-space scatter that moves as you edit them.

A mood per person

Faces positioned along a categorical x; drag each one's mouth or eyes to set that person's emotion.

const chart = Elicit({
width: 540, height: 260,
margins: { top: 16, right: 20, bottom: 34, left: 20 },
axes: { x: {}, y: false },
data: [
{ who: "Ana", valence: 0.6, arousal: 0.4 },
],
schema: {
who: { type: "categorical", domain: ["Ana", "Ben", "Cy"] },
valence: { type: "quantitative", domain: [-1, 1] },
arousal: { type: "quantitative", domain: [-1, 1] },
},
marks: [
face({
size: 46,
channels: {
x: { field: "who" },
// Declared, not implied: these are the two columns a drag on this face
// writes. (The emotion preset would DRAW the same binding, but a mark is
// inert until an edit names the column it touches.) Every face's parts are
// separate features, so a drag on Ana's mouth cannot reach Ben's.
mouthCurve: { field: "valence", edit: slide({ axis: "y", increase: "up" }) },
eyeScale: { field: "arousal", edit: slide({ axis: "x", increase: "right" }) },
},
}),
],
});
mount(chart.dom());
Try: Drag any face's mouth or an eye.

Showing a handle's track

A positional channel in the frame has a real scale, so move() on it travels exactly the range the scale spans. guide: { track: true } draws that range as a dashed segment. It is off by default.

A handle's travel range

The dashed segment is exactly the range the edit maps the pointer onto — drag past either end and the value stops.

const chart = Elicit({
width: 320, height: 300,
margins: { top: 12, right: 12, bottom: 12, left: 12 },
data: [ { brow: 0.5 } ],
schema: {
brow: { type: "quantitative", domain: [0, 1] },
},
marks: [
face({
channels: {
// A brow's height is a POSITIONAL channel in the face's local frame, so
// `move()` inverts the pointer straight back through the very scale that
// placed it — and the frame scale's pixel range IS the travel range.
// `guide: { track: true }` draws that range, so what you see is the mapping.
browHeight: {
field: "brow",
edit: move({ channels: ["y"], guide: { track: true } }),
},
},
}),
],
});
mount(chart.dom());
Try: Drag a brow up and down along its dashed track.

One face per day — click to add

A face is creatable like a point. A plane click inverts the pointer through the x and y scales to mint a datum, and every part draws from it. Mark-level edits go on the face's box, so create fires once per click.

Here the week starts with three days filled. Click an empty day to add its face. The click's height sets the mood, which also drives the smile. unique({ field: "day" }) makes the day the identity, so each day holds at most one face.

Click an empty day to add a face

create() on an ordinal x (days) × numeric y (mood); unique({ field: "day" }) caps each day at one face. mouthCurve reads the same mood field, so a created face's smile matches where you clicked.

const chart = Elicit({
width: 560, height: 300,
margins: { top: 16, right: 20, bottom: 32, left: 34 },
axes: { x: {}, y: {} },
data: [
{ day: "Mon", mood: 0.7 },
],
schema: {
// Ordinal x: the week runs Mon → Sun in this order (a band axis).
day: { type: "ordinal", domain: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] },
// Numeric y in [0, 1]: how good the day felt. It also drives the smile.
mood: { type: "quantitative", domain: [0, 1] },
},
constraints: [ unique({ field: "day" }) ],
marks: [
face({
size: 24,
channels: {
x: { field: "day" },
y: { field: "mood" },
// Bind the smile to the SAME field as y: click higher → happier face,
// and a created face's expression derives from the mood create mints —
// no extra field to seed. The edit makes pulling the mouth write `mood`
// too, so the smile and the y position stay two views of one column.
mouthCurve: { field: "mood", edit: slide({ axis: "y", increase: "up" }) },
},
// A click on an empty day's column inverts the pointer to (day, mood) and
// mints one face there. Mark-level edits ride on the HEAD part, so the
// create fires once per click, not once per facial feature. A click that
// lands ON a face carries a node, so it never fires the plane create — and
// a click in a day that's already taken is rejected by `unique`.
edits: [ create({ channels: ["x", "y"] }) ],
}),
],
});
mount(chart.dom());
Try: Click an empty day to add its face · drag a mouth to adjust the mood.

It's just a composite

face() is built from public marks, so you can assemble one yourself. As a composite, it can also draw a network's nodes; see Faces as nodes. Below is a smaller face written out in full: a point head, two ellipse eyes, two tickY brows and a curveY mouth, each placed in the composite's box.

frame: marks a number as being in the glyph's own coordinates: x and y in [-1, 1] from the centre with y up, and radii as a fraction of the half-size. A part with no position sits at the centre, where the head goes. A field-bound channel maps the field's declared domain onto a slice of the box (frame: [0.05, 0.19]), and the edit inverts back through it.

Each brow is a tickY spanning a chord, with worry driving its height and tilt. The tilt ranges are mirrored, [45, -45] on the left and [-45, 45] on the right, so a rising worry tilts both brows into the same expression. Each part has its own frame: scale, so the two ranges stay independent.

A face, written out

The same construction face() performs, spelled out with composite + point + ellipse + tick + curve.

const chart = Elicit({
width: 320, height: 300,
margins: { top: 12, right: 12, bottom: 12, left: 12 },
data: [ { openness: 0.7, mood: 0.8, worry: 0.35 } ],
schema: {
openness: { type: "quantitative", domain: [0, 1] },
mood: { type: "quantitative", domain: [0, 1] },
worry: { type: "quantitative", domain: [0, 1] },
},
marks: [
// This is what `face()` returns. A part stating a `frame:` channel turns the
// composite into a BOX: its x / y / size say where the box is and how big,
// and a `frame:` channel is placed inside it — x and y in [-1, 1] from the
// centre with y UP, radii as a fraction of the half-size.
composite({
id: "myface",
channels: { size: { value: 92 } },
parts: [
// The head IS the box: radius 1 in local units, and no position at all —
// inside a box, saying nothing means "here, at the glyph".
point({ channels: {
size: { frame: 1 },
fill: { value: "#FFD666" },
stroke: { value: "#B7791F" },
} }),
// Two eyes. `rx` maps the field's domain onto a slice of the box, so the
// same drag means the same thing however big the head is.
ellipse({ channels: {
x: { frame: -0.4 },
y: { frame: 0.16 },
rx: { field: "openness", frame: [0.05, 0.19],
edit: slide({ axis: "x", increase: "right" }) },
ry: { frame: 0.12 },
fill: { value: "#1f2937" },
} }),
ellipse({ channels: {
x: { frame: 0.4 },
y: { frame: 0.16 },
rx: { field: "openness", frame: [0.05, 0.19],
edit: slide({ axis: "x", increase: "right" }) },
ry: { frame: 0.12 },
fill: { value: "#1f2937" },
} }),
// Two brows, each a tickY spanning a chord in the box. `worry` drives
// BOTH the height (a slide on y) and the tilt — and the two tilt ranges
// are MIRRORED, so one rising field tilts them into the same expression
// rather than the same direction. That only works because each part's
// frame scale is PRIVATE: a single global angle scale could not hold
// [45, -45] and [-45, 45] at once.
tickY({ channels: {
x1: { frame: -0.14 }, x2: { frame: -0.50 },
y: { field: "worry", frame: [0.57, 0.23],
edit: slide({ axis: "y", increase: "down" }) },
angle: { field: "worry", frame: [45, -45] },
stroke: { value: "#1f2937" },
strokeWidth: { frame: 0.055 },
} }),
tickY({ channels: {
x1: { frame: 0.14 }, x2: { frame: 0.50 },
y: { field: "worry", frame: [0.57, 0.23],
edit: slide({ axis: "y", increase: "down" }) },
angle: { field: "worry", frame: [-45, 45] },
stroke: { value: "#1f2937" },
strokeWidth: { frame: 0.055 },
} }),
// The mouth is a `curve`: a chord in the box plus a curvature. Positive
// bows up, so a descending range turns a rising mood into a deeper smile.
curveY({ channels: {
x1: { frame: -0.36 },
x2: { frame: 0.36 },
y: { frame: -0.34 },
curvature: { field: "mood", frame: [0.6, -0.6],
edit: slide({ axis: "y", increase: "up" }) },
stroke: { value: "#1f2937" },
strokeWidth: { frame: 0.055 },
} }),
],
}),
],
});
mount(chart.dom());
Try: Drag an eye sideways · drag a brow down to worry it · drag the mouth up and down.