Elicit.js

Ellipse

ellipse draws a dot with two radii, rx and ry. Each is its own channel, with its own field and its own edit, so one mark elicits two numbers. size sets any radius you leave unset.

API reference

ellipse(options)

Import plot from elicitjs. A dot with two independent radii. point has one size channel because a circle has one radius; splitting it into rx and ry means each can carry its own field and its own edit — two elicited numbers in one shape.

ellipse({ channels, edits, id }) → Mark
Options
OptionType · defaultDescription
channels
Channelsdefault{}
x, y, rx, ry, angle plus the standard style channels.
image
string | (d) => string | ChannelSpec
The shape's background image: a URL painted inside each shape in place of the fill. Takes fit, position and repeat as channel params, as in CSS. See Image.
size
number | ChannelSpecdefault5
The fallback for whichever radius is not otherwise named, so ellipse({ size: 6 }) is a circle.
fill, stroke, …
styledefaulttheme ink
The standard style surface, same as every mark.
Channels
ChannelTypeDescription
x, y
linear | band | point
The centre. A missing channel parks it at the centre of that dimension.
rx
size
Horizontal radius in px (default range [3, 18]). Natural edit: slide({ axis: 'x' }).
ry
size
Vertical radius in px. Natural edit: slide({ axis: 'y' }). Both fall back to size.
angle
linear
Tilt in math degrees about the centre. A rotated ellipse is hit-tested in its own frame, so it stays grabbable where it is drawn.
Returns / emits

A mark emitting one ellipse node per datum.

Two uncertainties, one blob

Use an ellipse for an estimate with per-axis uncertainty. The centre is the estimate, and each radius is the uncertainty along its axis.

Both radius edits are on the same mark, so one diagonal drag reshapes the blob. slide({ axis: 'x' }) and slide({ axis: 'y' }) read different components of the drag, so they work together.

Cost × benefit, with per-axis spread

rx and ry are separate fields; drag a blob sideways to widen it, up or down to flatten it.

const chart = Elicit({
width: 480, height: 320,
margins: { top: 20, right: 24, bottom: 40, left: 44 },
axes: { x: {}, y: {} },
data: [
{ region: "North", cost: 30, benefit: 62, costSd: 8, benefitSd: 16 },
{ region: "South", cost: 66, benefit: 34, costSd: 17, benefitSd: 6 },
],
schema: {
cost: { type: "quantitative", domain: [0, 100] },
benefit: { type: "quantitative", domain: [0, 100] },
costSd: { type: "quantitative", domain: [2, 30] },
benefitSd: { type: "quantitative", domain: [2, 30] },
region: { type: "categorical", domain: ["North", "South"] },
},
marks: [
// One blob per region: the CENTRE is the estimate, the two RADII are two
// separate uncertainties. A circle could only say "how unsure overall"; two
// radii let a reader say they are confident about cost and vague about benefit.
// Both edits sit on one mark, so a single diagonal drag reshapes the blob —
// that is the point of rx and ry being independent channels.
ellipse({
channels: {
x: { field: "cost" },
y: { field: "benefit" },
rx: { field: "costSd", scale: { range: [6, 64] },
edit: slide({ axis: "x", increase: "right" }) },
ry: { field: "benefitSd", scale: { range: [6, 64] },
edit: slide({ axis: "y", increase: "down" }) },
fill: { field: "region" },
fillOpacity: { value: 0.35 },
stroke: { field: "region" },
},
}),
],
});
mount(chart.dom());
Try: Drag a blob sideways (cost spread) or vertically (benefit spread).

Moving it as well

Two edits that read the same component of a drag conflict on one mark: a move() on the centre and a radius slide would both fire. Gate one with when (for example when.shift, as on Shape), or give each its own mark in a composite: an ellipse that resizes, and a point at its centre that moves. Direct pick sends each drag to the mark you touched.

A blob you can move and resize

The ellipse carries the radius edit; a small centre dot carries the move. Two marks, two gestures, one row.

const chart = Elicit({
width: 420, height: 320,
margins: { top: 20, right: 24, bottom: 40, left: 44 },
axes: { x: {}, y: {} },
data: [ { cost: 40, benefit: 55, sd: 14 } ],
schema: {
cost: { type: "quantitative", domain: [0, 100] },
benefit: { type: "quantitative", domain: [0, 100] },
sd: { type: "quantitative", domain: [2, 30] },
},
marks: [
// Two edits that both read a raw drag can't share one mark — one gesture would
// fire both. Give them one mark each: the blob resizes, the dot at its centre
// moves. Direct-pick routes a gesture to the mark you touched, so there is
// nothing to arbitrate.
composite({
id: "blob",
parts: [
ellipse({ channels: {
x: { field: "cost" },
y: { field: "benefit" },
rx: { field: "sd", scale: { range: [6, 64] },
edit: slide({ axis: "x", increase: "right" }) },
ry: { field: "sd", scale: { range: [6, 64] } },
fill: { value: "#50AEB7" }, fillOpacity: { value: 0.28 },
stroke: { value: "#37919B" },
} }),
point({ channels: {
x: { field: "cost", edit: move({ channels: ["x", "y"] }) },
y: { field: "benefit" },
size: { value: 5 },
fill: { value: "#20555A" },
} }),
],
}),
],
});
mount(chart.dom());
Try: Drag the dot to move the blob · drag the blob to resize it.

Inside a glyph

A face draws its eyes with ellipse: an rx that opens and an ry that squints, both set as fractions of the glyph's frame so they scale with the head. See composite for how a mark places itself in a glyph's local coordinates.