Curve
curve draws a segment bowed off its chord. The bend is the curvature channel, so how much it bends, and which way, is an elicited number. curveY spans x and sits on y, curveX spans y and sits on x, and curve reads the channels you declare.
API reference
curve(options) · curveX · curveY
Import plot from elicitjs. A segment that bends. A tick draws a straight line between two points; a curve draws the same span bowed off its chord by an amount that is itself a channel — so “how much does this bend, and which way” becomes an elicited number. curveY spans x and sits on y; curveX spans y and sits on x; bare curve reads the declared channels.
curve({ channels, orientation, length, edits, id }) → Mark
curveY(options) → Mark // value on y (chord along x)
curveX(options) → Mark // value on x (chord along y)| Option | Type · default | Description |
|---|---|---|
channels | Channelsdefault{} | The chord endpoints (x1/x2 or y1/y2; with one end given, the other is the baseline), the position on the other axis, curvature, angle, plus the standard style channels. |
orientation | 'vertical' | defaultauto | Which axis the value runs along ( 'vertical' = y). Inferred from the declared chord pair, a band scale or the lone bound channel; curveY / curveX pin it. |
length | numberdefaultmin(w, | Chord length in px, centred on the span axis' own channel. Used only when no endpoint pair is declared. |
| Channel | Type | Description |
|---|---|---|
curvature | linear | How far the apex sits off the chord, as a fraction of the HALF-chord: 0 is a straight segment, ±1 bows out by half the span’s length. Positive bows to the left of travel (a rightward chord bows up). It scales with the chord, so a glyph’s curve stays proportional when the glyph resizes. Natural edit: slide({ axis: 'y' }). |
x1, | linear | | The chord's two ends. Without them the chord is `length` px centred on the `x` channel. |
y (curveY) | linear | Where the chord sits. curveX swaps the two families: y1/y2 span, x positions. |
angle | linear | Tilt about the chord midpoint, in math degrees. Baked into the geometry (neither renderer rotates a path node), so it works everywhere. Natural edit: rotate({ pivot: 'mark', pick: 'direct' }). |
A mark emitting two path nodes per datum: the visible curve, and a fat transparent hit path over it so a few-pixel stroke is actually grabbable. The hit path leaves pointerEvents unset, so an inert curve is silenced by the engine and can’t swallow a neighbour’s drag.
One number: how much it bends
curvature is the apex's offset from the chord as a fraction of the half-chord. 0 is a straight segment, and ±1 bows out by half the span's length. The shape stays proportional when the span changes, so a face's mouth keeps its expression when the head is resized.
Positive curvature bows to the left of travel, from the first endpoint to the second, so a rightward chord bows up. Set the direction on the scale: a descending range turns a rising field into a deepening cup.
How does value grow between the ends?
The chord is fixed and only the shape between its ends is elicited: one number.
const chart = Elicit({width: 480, height: 300,margins: { top: 20, right: 24, bottom: 40, left: 44 },axes: { x: {}, y: false },data: [{ option: "A", convexity: 0.6 },],schema: {option: { type: "categorical", domain: ["A", "B", "C"] },convexity: { type: "quantitative", domain: [-1, 1] },},marks: [// "How does value grow between the two ends?" — a straight line means steadily,// a bow means front- or back-loaded. The chord is fixed (both ends are agreed);// only the SHAPE between them is elicited, which is exactly one number.curveY({length: 110,channels: {x: { field: "option" },// No y scale here, so the height is a visual constant: `{ value }` is in// pixels, and skips the scale by definition.y: { value: 150 },// Positive curvature bows to the LEFT of travel — up, for a chord that runs// left to right. So an ascending range plus increase:"up" makes dragging up// arch it and dragging down cup it.curvature: { field: "convexity", scale: { range: [-0.8, 0.8] },edit: slide({ axis: "y", increase: "up" }) },stroke: { value: "#50AEB7" },strokeWidth: { value: 3 },},}),],});mount(chart.dom());
Bend and tilt
angle tilts the whole curve about its chord midpoint.
Both edits work on the same mark because they read different components of one drag: slide({ axis: "y" }) on curvature and slide({ axis: "x" }) on angle. Two edits that read the same component conflict, unless when gates one of them (see Shape). Use slide, not rotate, on angle: you grab the curve at its own pivot, so a few pixels of travel swing rotate through most of a half-turn and pin the value to an extreme.
An explicit chord, bent and leaning
x1 → x2 states the chord outright; curvature bends it and angle leans it.
const chart = Elicit({width: 420, height: 300,margins: { top: 20, right: 30, bottom: 40, left: 44 },axes: { x: {}, y: {} },data: [ { from: 15, to: 85, at: 55, bow: 0.5, lean: 12 } ],schema: {from: { type: "quantitative", domain: [0, 100] },to: { type: "quantitative", domain: [0, 100] },at: { type: "quantitative", domain: [0, 100] },bow: { type: "quantitative", domain: [-1, 1] },lean: { type: "quantitative", domain: [-45, 45] },},marks: [// An explicit endpoint PAIR states the chord: x1 → x2 at height y. Both edits// sit on one mark, so ONE drag drives both: its vertical component bends the// curve, its horizontal one tilts it. Reading two components of a gesture is// what lets two params share a mark without fighting — an angular edit here// would fire off both, since you are standing on the pivot.curveY({channels: {x1: { field: "from" },x2: { field: "to" },y: { field: "at" },curvature: { field: "bow", scale: { range: [-0.8, 0.8] },edit: slide({ axis: "y", increase: "up" }) },angle: { field: "lean", scale: { range: [-45, 45] },edit: slide({ axis: "x", increase: "right" }) },stroke: { value: "#EE7B5E" },strokeWidth: { value: 3 },},}),],});mount(chart.dom());
Grabbing a curve
A curve carries a wide transparent hit area along its stroke, so a drag near the line catches it, on both SVG and canvas. Edits measure from the chord midpoint. A curve with no edit lets drags pass through to the marks beneath it.