Elicit.js

Sticker

sticker() draws a rounded box with text inside and sizes the box to the text. A long note wraps at maxWidth and grows taller. Add editText({ multiline: true }) to double-click and type into it. It is a preset over composite, made of a rect and a text, so every channel, scale, edit and constraint works as on other marks.

API reference

sticker(options)

Import plot from elicitjs. A rounded box with text inside, sized by the text. A preset over composite, so it desugars into an ordinary rect and text.

sticker({ channels, padding, cornerRadius, maxWidth, minWidth, minHeight, lineHeight, fontFamily, format, table, edits, id }) → Mark[]
Options
OptionType · defaultDescription
channels
objectdefault{}
x/y place the box and are shared by both parts. text is the string it holds. Label channels (fontSize, textAnchor, dx, dy) go to the text; every other channel (fill, stroke, opacity, angle) goes to the box. width and height pin a dimension and turn auto-sizing off for that axis; a pinned width is also the width the text wraps at, so a note resized narrower re-flows and grows taller.
padding
numberdefault10
Space between the text and the box’s edge, in px.
cornerRadius
numberdefault6
Corner radius in px. Set 0 for square corners.
maxWidth
numberdefault160
The box stops growing here and the text wraps instead. Also the wrap width, so a long note gets taller rather than wider. A width channel replaces it on both counts.
minWidth
numberdefault60
Keeps an empty or one-word note from collapsing to nothing.
minHeight
numberdefault0
A floor for the box’s height, in px.
lineHeight
numberdefault1.35 × fontSize
Baseline step between wrapped lines, in px.
fontSize
numberdefault13
Used to measure as well as to draw, so the box matches what is painted. A fontSize channel still reaches the label, but the box is measured at this value.
fontFamily
stringdefaultthe theme’s font
Measured with, when your page font differs from the theme’s.
format
string | fndefaultString
Display formatter for the text channel: a d3-format string, or (v) => string. Display-only — the column stays raw, so editText still writes the real value.
Returns / emits

Carries no edits of its own, like every mark. Put move({ channels: ["x", "y"], mode: "relative" }) on x and editText({ multiline: true }) in edits. Both land on the box: you drag and double-click the note, not its letters. Prefer mode: "relative" — an absolute move puts the box’s centre at the pointer, which snaps a note you grabbed by its corner.

editText(options)

Write a typed string back into the text channel’s field. Double-click opens an editor over the mark; Enter or clicking away commits, Escape cancels.

editText({ multiline, channels, when, stage }) → Edit
Options
OptionType · defaultDescription
multiline
booleandefaultfalse
Use a textarea, in which Enter inserts a newline and Cmd/Ctrl+Enter commits. Pair it with sticker, whose text wraps.
channels
string[]default["text"]
Which channel’s field to write. The default is right almost always.

Sizing

The box is measured from the text channel string, at the fontSize and fontFamily it is drawn in, plus padding on every side.

maxWidth is both the ceiling and the wrap width. A longer note breaks onto more lines and the box gets taller. minWidth keeps a one-word note from collapsing.

State a width or height channel to pin that dimension instead:

sticker({ channels: { width: { value: 120 }, text: { field: "note" } } })

Auto-sizing stops for that axis only, so a pinned width still lets height follow the wrapped text. Size from the row with { fn }, or read a column of pixel widths with { field: "w", scale: null }.

A pinned width is also the wrap width, in place of maxWidth. Narrow a note and the text re-flows; with height still auto-sized, the box grows taller to fit.

Resizing

Bind width to a field and give it an edit to make a resize handle. The channel is in pixels, so give it a range that matches the field's domain. The column then holds the box's width directly:

width: {
field: "w",
scale: { range: [70, 260] },
edit: slide({ axis: "x", increase: "right", extent: 95, when: when.shift }),
}

slide changes the value by how far you drag, so the box stays put when you press it. extent is the drag distance that sweeps the whole domain. The box grows about its centre, so an extent of half the domain's span (95 for a 190-wide domain) keeps the dragged edge under the pointer.

For grips on the note's sides, attach ui.handles() to the chart. A grip moves its own side and holds the other still, and the width channel needs no edit.

A move on x and a slide on width both read horizontal travel. Gate them with when.shift and when.noShift so each gets its own gesture.

Pin height the same way for a fixed-size card. Leave it off and height keeps following the text.

Resizable notes

Drag the width, and the text re-wraps to fit.

const chart = Elicit({
width: 460, height: 300,
margins: { top: 20, right: 20, bottom: 20, left: 20 },
axes: false,
schema: {
note: { type: "categorical", open: true },
w: { type: "quantitative", domain: [70, 260] },
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
},
data: [
{ note: "Shift-drag my edge sideways. The text re-wraps to whatever width I end up.", w: 170, x: 32, y: 62 },
{ note: "Narrow notes get taller.", w: 100, x: 72, y: 28 },
],
marks: [
sticker({
fill: "#EBD6AD",
stroke: "rgba(70, 89, 107, 0.13)",
maxWidth: 260,
edits: [editText({ multiline: true })],
channels: {
x: {
field: "x",
edit: move({ channels: ["x", "y"], mode: "relative", when: when.noShift }),
},
y: { field: "y" },
width: {
field: "w",
scale: { range: [70, 260] },
edit: slide({ axis: "x", increase: "right", extent: 95, when: when.shift }),
},
text: { field: "note" },
},
}),
],
});
mount(chart.dom());
Try: Shift-drag a note sideways to resize it — the text re-wraps and the box gets taller as it narrows. Drag without Shift to move it, and double-click to retype.

Typing

editText() writes what you type back into the text channel's field. Put it in edits:

sticker({
edits: [editText({ multiline: true })],
channels: { x: { field: "x" }, y: { field: "y" }, text: { field: "note" } },
})

Double-click a note to open an editor filling the box. multiline: true makes it a textarea: Enter inserts a newline, and Cmd/Ctrl+Enter or clicking away commits. Escape cancels either way. Without it you get a single-line field where Enter commits.

Drag or double-click anywhere on the box, including the gaps between words.

Typing needs the SVG renderer. Under CanvasRenderer a sticker draws and drags only.

Editing a board

The universal edits do the rest:

  • move({ channels: ["x", "y"], mode: "relative" }) on x drags a note. Use mode: "relative" on anything with area: it moves by how far you drag and keeps the grab point under the pointer. The default "absolute" puts the note's centre at the pointer, so a big box jumps when you press it.
  • create() in edits mints one where you click. Give it defaults so a new note arrives with a colour and a placeholder.
  • remove({ when: when.alt }) deletes the note under the pointer.
  • cycle() on fill steps through the colours in that field's domain.

Sticky notes

Boxes sized by what you type.

const chart = Elicit({
width: 460, height: 300,
margins: { top: 20, right: 20, bottom: 20, left: 20 },
axes: false,
schema: {
note: { type: "categorical", open: true },
tone: { type: "categorical", domain: ["#EBD6AD", "#C2DEBA", "#EDF7F8"] },
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
},
data: [
{ note: "Drag me", tone: "#EBD6AD", x: 25, y: 75 },
],
marks: [
sticker({
stroke: "rgba(70, 89, 107, 0.13)",
maxWidth: 140,
edits: [
editText({ multiline: true }),
create({ defaults: { note: "New note", tone: "#EBD6AD" } }),
remove({ when: when.alt }),
],
channels: {
x: { field: "x", edit: move({ channels: ["x", "y"], mode: "relative" }) },
y: { field: "y" },
text: { field: "note" },
fill: { field: "tone", scale: null, edit: cycle() },
},
}),
],
});
mount(chart.dom());
Try: Drag a note. Double-click one and type — Enter makes a new line, Cmd/Ctrl+Enter commits, and the box resizes. Click a note to recolour it,click empty space to add one, and Alt-click to delete.

Diagram board

A diagram board is a network schema with a sticker over the nodes and a link over the links. List link() first so connectors sit behind the boxes.

With curve: "orthogonal", each connector leaves a box at a right angle from one of its edges. It docks to the sticker's measured box and routes around any note in the way. See where a link meets a node.

Give the sticker a ports channel with edit.network.connect() on it. Hover a box and a port appears on each edge. Drag from one to another box to connect them; drop on a port to pin that end, or on the box to connect at its facing port. The link mark's sourceSide and targetSide channels name the columns the sides are written to — see Ports. Dragging a box's body still moves it.

edit.network.rewire() on the link puts a handle on each end while you hover it: drag one to another box to reconnect, or into space to disconnect. Deleting a box drops its connectors, because a link must name a node that exists.

Flowchart

Boxes you type into, connectors you drag, flip and restyle.

const chart = Elicit({
width: 520, height: 360,
margins: { top: 24, right: 24, bottom: 24, left: 24 },
axes: false,
schema: {
structure: "network",
tables: {
steps: {
role: "nodes",
fields: {
id: { type: "categorical", key: true, open: true },
label: { type: "categorical", open: true },
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
},
},
flows: {
role: "links",
directed: true,
fields: {
source: { type: "ref" },
target: { type: "ref" },
kind: { type: "categorical", domain: ["orthogonal", "bezier"] },
// The edge each end meets, or null to slide along the box.
fromSide: { type: "categorical", domain: ["top", "right", "bottom", "left"] },
toSide: { type: "categorical", domain: ["top", "right", "bottom", "left"] },
},
},
},
},
data: {
steps: [
{ id: "s1", label: "Draft the question", x: 22, y: 82 },
],
flows: [
{ source: "s1", target: "s2", kind: "orthogonal" },
],
},
marks: [
link({
stroke: "#94A5B3",
strokeWidth: 1.5,
channels: {
curve: { field: "kind" },
sourceSide: { field: "fromSide" },
targetSide: { field: "toSide" },
},
edits: [
edit.network.rewire(),
edit.network.reverse({ when: when.alt }),
cycle({ channels: ["curve"], when: when.noAlt }),
],
}),
sticker({
fill: "#F9F4EC",
stroke: "#C99128",
maxWidth: 130,
cornerRadius: 8,
edits: [
editText({ multiline: true }),
create({ defaults: { label: "New step" } }),
remove({ when: when.alt }),
],
channels: {
x: { field: "x", edit: move({ channels: ["x", "y"], mode: "relative" }) },
y: { field: "y" },
text: { field: "label" },
// A dot on each edge, shown when you hover a box: drag from one to connect.
ports: {
value: true,
edit: edit.network.connect({ defaults: { kind: "orthogonal" } }),
},
},
}),
],
});
mount(chart.dom());
Try: Double-click a box and type — Enter makes a new line, Cmd/Ctrl+Enter commits, and the box grows to fit. Hover a box and drag from one of its ports to another box to connect them; drop on a port to pin that end, or on the box to connect at its facing port. Hover a connector and drag its end to reconnect it, or into space to remove it. Drag a box around another and watch its connectors follow. Click a connector to switch it between an elbow and a curve, and Alt-click one to reverse it. Click empty space for a new box, and Alt-click a box to delete it — its connectors go too.

Notes on a scale

A sticker is placed through the same scales as any mark. Point x at a categorical field and the notes sit in columns. move inverts the drag through that band scale, so dropping a note in another column writes the new category into the row.

The lane a note ends in is the answer. getData() returns it as lane. Sort within a lane by pointing y at a quantitative field, as here with rank.

Lanes

A band scale on x, so a drag re-files a card.

const chart = Elicit({
width: 480, height: 320,
margins: { top: 24, right: 16, bottom: 30, left: 16 },
axes: { x: {}, y: false },
schema: {
note: { type: "categorical", open: true },
lane: { type: "categorical", domain: ["Now", "Next", "Later"] },
rank: { type: "quantitative", domain: [0, 100] },
},
data: [
{ note: "Measure the text", lane: "Now", rank: 80 },
],
marks: [
grid({ channel: "x" }),
sticker({
fill: "#ECF3F9",
stroke: "#1D4467",
maxWidth: 120,
edits: [
editText({ multiline: true }),
create({ defaults: { note: "New card" } }),
remove({ when: when.alt }),
],
channels: {
x: { field: "lane", edit: move({ channels: ["x", "y"], mode: "relative" }) },
y: { field: "rank" },
text: { field: "note" },
},
}),
],
});
mount(chart.dom());
Try: Drag a card into another lane — it snaps to the column and the row’s lane changes. Double-click to retype, click empty space to add a card, and Alt-click to delete.