Elicit.js

Hierarchy

A hierarchy is nodes that sit inside each other, declared with structure: "hierarchy": one table of nodes, and a nesting table with one row per containment. constraints.contain governs which rows can hold others, layout rules size containers and arrange their contents (layout.hierarchy.contain, layout.dodge, layout.row, layout.column, layout.grid, layout.pack), and edit.hierarchy.nest drops a node into a container or out of one. A mark's contains option is a shorthand for container eligibility and fitting on that mark.

API reference

structure: "hierarchy"

Three tables: nodes, nesting and an optional links. One nesting row says one node is inside another.

schema: { structure: "hierarchy", tables: { nodes, nesting, links? } }
Options
OptionType · defaultDescription
nodes
tabledefaultrequired
One row per node. Needs a key: true column. Named anything with role: "nodes".
nesting
tabledefaultrequired
A field map like any other table, named anything with role: "nesting". Its first two ref columns are the contained node, then its container. A node has at most one container. Further columns take a type, domain and default as usual.
links
tabledefaultnone
As in a network: link() draws it and edit.network.* edits it.

constraints.contain(options)

Pure-data membership rule over a hierarchy’s nesting table. It guards every edit and ds.set. Rows in the seed or setData that break it are kept, and one warning names them. An edit is refused only for a break it adds.

constraints.contain({ parent?, child?, maxDepth?, maxChildren?, table? }) → Constraint
Options
OptionType · defaultDescription
table
stringdefault'nesting'
The nesting table, by role or by name.
parent
(d, i, rows) => booleandefaultany node
Which rows of the nodes table may hold other nodes.
child
(d, i, rows) => booleandefaultany node
Which rows of the nodes table may sit inside a container.
maxDepth
numberdefault∞
Maximum nesting depth (top-level nodes are depth 0).
maxChildren
numberdefault∞
Maximum direct children per container.

mark.contains

Shorthand option on any shape mark in a hierarchy. Scopes container eligibility to rows boxed by that mark and configures their padding and fit. Equivalent to constraints.contain plus layout.hierarchy.contain for that mark.

contains: true | ((d, i, rows) => boolean) | { where?, padding?, fit? }
Options
OptionType · defaultDescription
where
(d, i, rows) => booleandefaultevery row the mark boxes
Predicate picking which of the mark’s rows can hold other nodes.
padding
number | { top, right, bottom, left }default10
Room in px between a container’s edge and its contents.
fit
boolean | 'x' | 'y'defaultfalse
Size the container to enclose its contents on both axes (true), width only ("x"), height only ("y"), or keep its given size (false).

edit.hierarchy.nest(options)

Drop a node into the container under the pointer, or out of one. Put it on the mark you drag, beside a move.

edit.hierarchy.nest({ defaults, when }) → Edit
Options
OptionType · defaultDescription
defaults
objectdefault{}
Values for any further columns of the nesting row it writes.

Declaring the structure

structure: "hierarchy" gives the dataset a nodes table and a nesting table. A links table is optional.

schema: {
structure: "hierarchy",
tables: {
nodes: {
id: { type: "categorical", key: true, open: true },
kind: { type: "categorical", domain: ["group", "note"] },
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
w: { type: "quantitative", domain: [0, 600], default: 130 },
h: { type: "quantitative", domain: [0, 400], default: 80 },
},
nesting: {
child: { type: "ref" },
parent: { type: "ref" },
},
},
}

getData(), onChange and setData use one array per table. A table you leave out of data starts empty.

Groups and notes

constraints.contain picks the rows that hold others; layout.hierarchy.contain({ fit: true }) sizes them to their contents.

const chart = Elicit({
width: 520, height: 340,
margins: { top: 16, right: 16, bottom: 16, left: 16 },
axes: false,
schema: {
structure: "hierarchy",
tables: {
nodes: {
id: { type: "categorical", key: true, open: true },
label: { type: "categorical", open: true },
kind: { type: "categorical", domain: ["group", "note"] },
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
w: { type: "quantitative", domain: [0, 600], default: 130 },
h: { type: "quantitative", domain: [0, 400], default: 80 },
},
nesting: {
child: { type: "ref" },
parent: { type: "ref" },
},
},
},
data: {
nodes: [
{ id: "g1", label: "Research", kind: "group", x: 25, y: 60, w: 130, h: 80 },
],
nesting: [
{ child: "n1", parent: "g1" },
],
},
constraints: [
// Only groups hold other nodes.
constraints.contain({ parent: (d) => d.kind === "group" }),
],
layout: [
// A group's size follows its contents; a note keeps its own.
layout.hierarchy.contain({ padding: 12, fit: true }),
layout.dodge(),
],
marks: [
rect({
cornerRadius: 6,
stroke: "#46596B",
edits: [
move({ channels: ["x", "y"], mode: "relative" }),
edit.hierarchy.nest(),
],
channels: {
x: { field: "x" },
y: { field: "y" },
width: { field: "w", scale: null },
height: { field: "h", scale: null },
fill: { fn: (d) => (d.kind === "group" ? "#EDF7F8" : "#EBD6AD") },
},
}),
text({
fontSize: 11,
fill: "#20555A",
channels: {
x: { field: "x" },
y: { field: "y" },
text: { field: "label" },
// A group's name sits above its box, which is as tall as its `h` column.
dy: { fn: (d) => (d.kind === "group" ? -d.h / 2 - 8 : 0) },
},
}),
],
});
mount(chart.dom());
Try: Drag a note into a group or out of one. Drag a group to move it with its contents. Watch nesting and the group’s w/h in the data.

The nesting table

The nesting table is declared like any other table: a field map, with a type for every column.

It needs two ref columns. The first names the contained node and the second names its container. Both point at the nodes table's key: true column, so their values are node identities. The column names are yours.

nesting: {
child: { type: "ref" }, // the contained node
parent: { type: "ref" }, // its container
}

One row is one membership. A node with no row is at the top level. A node has at most one container, and cannot contain itself or any node inside it. A row from data or setData that breaks either rule is dropped with a warning, and so is a row that names a missing node.

Add any other columns you want to record about a membership. They take a type, a domain and a default like columns anywhere else. A row made by a drop takes each column's default, or the value you pass in edit.hierarchy.nest({ defaults }).

nesting: {
child: { type: "ref" },
parent: { type: "ref" },
coder: { type: "categorical", domain: ["seed", "participant"], default: "participant" },
}

Deleting a node removes the nesting rows that name it. Its contents move to the top level.

Naming the tables

Name the tables for your data and give each a role: "nodes", "nesting" or "links". A table named after its role needs no role, which is the short form used above.

tables: {
topics: { role: "nodes", fields: { … } },
memberships: { role: "nesting", fields: { … } },
}

data, getData() and setData are then keyed topics and memberships. Marks, constraints, layouts and edits find each table by its role.

Named tables, and a column on the membership

topics and memberships, by role. A dropped quote's row takes coder's default.

const chart = Elicit({
width: 520, height: 320,
margins: { top: 20, right: 16, bottom: 16, left: 16 },
axes: false,
schema: {
structure: "hierarchy",
tables: {
// Named for the data; `role` says which table each one is.
topics: {
role: "nodes",
fields: {
name: { type: "categorical", key: true, open: true },
kind: { type: "categorical", domain: ["theme", "quote"] },
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
w: { type: "quantitative", domain: [0, 600], default: 130 },
h: { type: "quantitative", domain: [0, 400], default: 80 },
},
},
memberships: {
role: "nesting",
fields: {
// The first ref is the contained node, the second its container.
quote: { type: "ref" },
theme: { type: "ref" },
// A column of its own: every membership row carries one.
coder: { type: "categorical", domain: ["seed", "participant"], default: "participant" },
},
},
},
},
data: {
topics: [
{ name: "Trust", kind: "theme", x: 25, y: 58, w: 130, h: 80 },
],
memberships: [
{ quote: "\u201cIt just works\u201d", theme: "Trust", coder: "seed" },
{ quote: "\u201cToo pricey\u201d", theme: "Cost", coder: "seed" },
],
},
constraints: [
constraints.contain({ parent: (d) => d.kind === "theme" }),
],
layout: [
layout.hierarchy.contain({ padding: 12, fit: true }),
layout.dodge(),
],
marks: [
rect({
cornerRadius: 6,
stroke: "#46596B",
edits: [
move({ channels: ["x", "y"], mode: "relative" }),
edit.hierarchy.nest(),
],
channels: {
x: { field: "x" },
y: { field: "y" },
width: { field: "w", scale: null },
height: { field: "h", scale: null },
fill: { fn: (d) => (d.kind === "theme" ? "#EDF7F8" : "#EBD6AD") },
},
}),
text({
fontSize: 11,
fill: "#20555A",
channels: {
x: { field: "x" },
y: { field: "y" },
text: { field: "name" },
dy: { fn: (d) => (d.kind === "theme" ? -d.h / 2 - 8 : 0) },
},
}),
],
});
mount(chart.dom());
Try: Drag the loose quote into a theme and read its memberships row: coder is participant, where the seeded rows say seed.

Containers

Containment splits cleanly into two pieces: eligibility (a pure-data invariant) and geometry (a pixel-space layout rule).

  • constraints.contain({ parent, child, maxDepth, maxChildren }) decides which rows may hold others, which may sit inside a container, and how deep or full a container may get. It guards every edit and ds.set. Rows in the seed or setData that break it are kept, and one warning names them; an edit is refused only for a break it adds.
  • layout.hierarchy.contain({ where, padding, fit }) sets the room between a container's edge and its contents, and whether the container sizes itself to fit them (fit: true, "x", "y", or false). where picks the containers that take this padding and fit. Which rows may take a drop is still constraints.contain or a mark's contains.
constraints: [
constraints.contain({ parent: (d) => d.kind === "group" }),
],
layout: [
layout.hierarchy.contain({ padding: 12, fit: true }),
],

When a chart draws different kinds of node with separate marks, or when one mark owns its own containers, the mark option contains is a shorthand for both:

rect({
contains: { where: (d) => d.kind === "group", padding: 12, fit: true },
channels: {
x: { field: "x" },
y: { field: "y" },
width: { field: "w", scale: null },
height: { field: "h", scale: null },
},
})

contains: true lets every row drawn by that mark hold others, and contains: (d) => … picks rows with default padding. scale: null reads w and h as pixels.

A fitted container writes its size back to the mark's size fields (width/height, size, rx/ry, or x1/x2/y1/y2), so a resize edit leaves those fitted columns alone while an empty container stays editable. When a container loses its last child, it returns to each fitted column's schema default and keeps its top-left corner. Declare a default for every fitted column; without one, the container shrinks to its padding and logs a warning.

w: { type: "quantitative", domain: [0, 600], default: 130 },

The fitted size is in the data, so other channels can read it. The examples here place a group's name from its h column.

Groups inside groups

A container is fitted after its contents, at any depth.

const chart = Elicit({
width: 560, height: 380,
margins: { top: 20, right: 16, bottom: 16, left: 16 },
axes: false,
schema: {
structure: "hierarchy",
tables: {
nodes: {
id: { type: "categorical", key: true, open: true },
label: { type: "categorical", open: true },
kind: { type: "categorical", domain: ["group", "person"] },
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
w: { type: "quantitative", domain: [0, 600], default: 100 },
h: { type: "quantitative", domain: [0, 400], default: 60 },
},
nesting: {
child: { type: "ref" },
parent: { type: "ref" },
},
},
},
data: {
nodes: [
{ id: "org", label: "Company", kind: "group", x: 40, y: 55, w: 100, h: 60 },
],
nesting: [
{ child: "eng", parent: "org" },
],
},
layout: [layout.dodge()],
marks: [
rect({
cornerRadius: 6,
stroke: "#46596B",
// Shorthand on the mark: groups hold others and fit round their contents.
contains: { where: (d) => d.kind === "group", padding: 18, fit: true },
edits: [
move({ channels: ["x", "y"], mode: "relative" }),
edit.hierarchy.nest(),
],
channels: {
x: { field: "x" },
y: { field: "y" },
width: { field: "w", scale: null },
height: { field: "h", scale: null },
fill: { fn: (d) => (d.kind === "group" ? "#2B5D87" : "#ffffff") },
fillOpacity: { fn: (d) => (d.kind === "group" ? 0.12 : 1) },
},
}),
text({
fontSize: 11,
fill: "#20555A",
channels: {
x: { field: "x" },
y: { field: "y" },
text: { field: "label" },
// Inside the top padding, so nested groups' names do not collide.
dy: { fn: (d) => (d.kind === "group" ? -d.h / 2 + 10 : 0) },
dx: { fn: (d) => (d.kind === "group" ? -d.w / 2 + 10 : 0) },
textAnchor: { fn: (d) => (d.kind === "group" ? "start" : "middle") },
},
}),
],
});
mount(chart.dom());
Try: Drag a person between teams. Drag the Web team out of Engineering and into Design. Every group it leaves or joins re-fits.

Any node can hold others

contains: { padding: 14, fit: true } — drop one node on another to make a group.

const chart = Elicit({
width: 480, height: 320,
margins: { top: 20, right: 16, bottom: 16, left: 16 },
axes: false,
schema: {
structure: "hierarchy",
tables: {
nodes: {
id: { type: "categorical", key: true, open: true },
label: { type: "categorical", open: true },
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
w: { type: "quantitative", domain: [0, 600], default: 80 },
h: { type: "quantitative", domain: [0, 400], default: 28 },
},
nesting: {
child: { type: "ref" },
parent: { type: "ref" },
},
},
},
data: {
nodes: [
{ id: "a", label: "Fruit", x: 25, y: 70, w: 80, h: 28 },
],
nesting: [],
},
layout: [layout.dodge()],
marks: [
rect({
cornerRadius: 6,
fill: "#E3F1DF",
stroke: "#5C9A4B",
// Every node may hold others: drop one on another to make a group.
contains: { padding: 14, fit: true },
edits: [
move({ channels: ["x", "y"], mode: "relative" }),
edit.hierarchy.nest(),
create({ defaults: { label: "New", w: 80, h: 28 } }),
remove({ when: when.alt }),
],
channels: {
x: { field: "x" },
y: { field: "y" },
width: { field: "w", scale: null },
height: { field: "h", scale: null },
},
}),
text({
fontSize: 11,
fill: "#3A6630",
channels: {
x: { field: "x" },
y: { field: "y" },
text: { field: "label" },
// A node that has grown past a single line is a group: name it above.
dy: { fn: (d) => (d.h > 30 ? -d.h / 2 - 8 : 0) },
},
}),
],
});
mount(chart.dom());
Try: Drag Apple onto Fruit. Click empty space to add a node and Alt-click one to delete it. Deleting a group releases its contents.

Padding and spacing

Every container keeps padding between its edge and its contents. The default is 10px. Give one number, or a side each; a side you leave out takes the default.

layout: [
layout.hierarchy.contain({ padding: { top: 30, right: 12, bottom: 12, left: 12 }, fit: true }),
layout.dodge({ gap: 10 }),
]

A fitted container is sized to leave that room. A container with a size of its own moves its contents inside it.

Add layout.dodge({ gap, where, in }) to push overlapping siblings apart. gap defaults to 8px, where picks the rows that take part, and in scopes it to "all" (default), "roots", "containers", or a container predicate. Round nodes keep the gap edge to edge. A composite dodges as a whole, with every part, its label included.

Nodes dodge their siblings: the contents of one container dodge each other, and top-level nodes dodge each other. When two overlap, the node you just dropped stays put and the other moves the shortest distance that clears it. When that leaves no room, the contents pack in reading order from the top-left. A container that grows pushes its neighbours the same way, and they take their contents along. A pushed node stays inside its container's padding, or inside the plot at the top level.

Nodes are pushed apart on release, and when data arrives through setData. While you drag, they are drawn where the release will put them. Seeded data is spaced once, at the start.

Room for a name, and no overlaps

padding by side; layout.dodge({ gap: 10 }) pushes overlapping siblings apart on release.

const chart = Elicit({
width: 520, height: 340,
margins: { top: 16, right: 16, bottom: 16, left: 16 },
axes: false,
schema: {
structure: "hierarchy",
tables: {
nodes: {
id: { type: "categorical", key: true, open: true },
label: { type: "categorical", open: true },
kind: { type: "categorical", domain: ["group", "note"] },
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
w: { type: "quantitative", domain: [0, 600], default: 130 },
h: { type: "quantitative", domain: [0, 400], default: 80 },
},
nesting: {
child: { type: "ref" },
parent: { type: "ref" },
},
},
},
data: {
nodes: [
{ id: "g1", label: "Research", kind: "group", x: 25, y: 60, w: 130, h: 80 },
],
nesting: [
{ child: "n1", parent: "g1" },
],
},
constraints: [
// Only groups hold other nodes.
constraints.contain({ parent: (d) => d.kind === "group" }),
],
layout: [
// The top side leaves room for the name.
layout.hierarchy.contain({
padding: { top: 30, right: 12, bottom: 12, left: 12 },
fit: true,
}),
// Overlapping siblings are pushed 10px apart when a drag ends.
layout.dodge({ gap: 10 }),
],
marks: [
rect({
cornerRadius: 6,
stroke: "#46596B",
edits: [
move({ channels: ["x", "y"], mode: "relative" }),
edit.hierarchy.nest(),
],
channels: {
x: { field: "x" },
y: { field: "y" },
width: { field: "w", scale: null },
height: { field: "h", scale: null },
fill: { fn: (d) => (d.kind === "group" ? "#EDF7F8" : "#EBD6AD") },
},
}),
text({
fontSize: 11,
fill: "#20555A",
channels: {
x: { field: "x" },
y: { field: "y" },
text: { field: "label" },
// A group's name sits in its top padding.
dy: { fn: (d) => (d.kind === "group" ? -d.h / 2 + 15 : 0) },
},
}),
],
});
mount(chart.dom());
Try: Drop the loose note on top of Interviews: Interviews and Survey make room. Drag Research onto Build and let go.

Arranging contents

Add an arrangement rule to layout to place contents in slots or packed clusters. See Layout for the full vocabulary, including flat tables and networks.

| Rule | Contents | | --- | --- | | layout.dodge({ gap, where, in }) | Where you drop them, pushed apart when they overlap. | | layout.row({ gap, in }) | Left to right from the top-left. A row with a fixed width wraps at it. | | layout.column({ gap, in }) | Top to bottom from the top-left. A column with a fixed height wraps at it. | | layout.grid({ columns, gap, in }) | Equal cells, the size of the largest node, columns to a row. | | layout.pack({ gap, keep, in }) | Drawn together where you drop them, touching. |

In a hierarchy, row, column, grid and pack default to in: "containers". Pass in: "roots" to arrange top-level nodes, in: "all" for both, or in: (d) => … to arrange different container kinds differently — for example layout.row({ in: "roots" }) beside layout.column({ in: (d) => d.kind === "lane" }).

In a row, column or grid, the order of the contents is the answer. Drag a node within its container to reorder it. Drop one into a container and it takes the nearest slot. While you drag, the other nodes open a space where it will land. On release, every node snaps to its slot.

A pack has no order. A node you drop there moves in to touch the others, and the others stay where they are. Nothing in a pack moves until you let go, so the node you aim at holds still. Round nodes pack as circles. Boxes pack as boxes, so they meet edge to edge.

keep sets how a dropped node moves in:

| keep | The node moves | | --- | --- | | "distance" | To the free spot nearest where you let go. The default. | | "angle" | Straight towards the node in the middle of the pack, or away from it, until it touches. Its direction from the middle stays the same. |

Use "angle" when where a node sits around the middle is the answer.

gap is the space between slots, 8px by default. columns sets a grid's cells to a row. Without it, a grid fills a fixed width, or makes a square.

layout: [
layout.hierarchy.contain({ padding: { top: 30, right: 10, bottom: 10, left: 10 }, fit: true }),
layout.column({ gap: 6 }),
]

The order is read from the x and y columns, which hold each node's slot. A fitted container keeps its top-left corner and grows right and down. A pack is fitted round its contents.

A board that grows

layout.column({ gap: 6 }) — each lane stacks its cards and fits round them.

const chart = Elicit({
width: 560, height: 360,
margins: { top: 16, right: 16, bottom: 16, left: 16 },
axes: false,
schema: {
structure: "hierarchy",
tables: {
nodes: {
id: { type: "categorical", key: true, open: true },
label: { type: "categorical", open: true },
kind: { type: "categorical", domain: ["lane", "card"] },
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
// An empty lane returns to this size.
w: { type: "quantitative", domain: [0, 600], default: 140 },
h: { type: "quantitative", domain: [0, 600], default: 70 },
},
nesting: {
child: { type: "ref" },
parent: { type: "ref" },
},
},
},
data: {
nodes: [
{ id: "todo", label: "To do", kind: "lane", x: 18, y: 80, w: 140, h: 70 },
],
nesting: [
{ child: "a", parent: "todo" },
],
},
constraints: [
constraints.contain({ parent: (d) => d.kind === "lane", child: (d) => d.kind === "card" }),
],
layout: [
// A lane grows down as cards join it, leaving room at the top for its name.
layout.hierarchy.contain({
padding: { top: 30, right: 10, bottom: 10, left: 10 },
fit: true,
}),
// Cards stack top to bottom, in order, inside each lane.
layout.column({ gap: 6 }),
],
marks: [
rect({
cornerRadius: 6,
stroke: "#46596B",
edits: [
move({ channels: ["x", "y"], mode: "relative" }),
edit.hierarchy.nest(),
],
channels: {
x: { field: "x" },
y: { field: "y" },
width: { field: "w", scale: null },
height: { field: "h", scale: null },
fill: { fn: (d) => (d.kind === "lane" ? "#EDF7F8" : "#FFFFFF") },
},
}),
text({
fontSize: 11,
fill: "#20555A",
channels: {
x: { field: "x" },
y: { field: "y" },
text: { field: "label" },
dy: { fn: (d) => (d.kind === "lane" ? -d.h / 2 + 15 : 0) },
},
}),
],
});
mount(chart.dom());
Try: Drag Pilot study above Write survey. Drag Ethics form into Done, between the cards there. Doing returns to its default size.

Rows inside rows

layout.row({ gap: 6 }) — rows hold tiles and other rows, at any depth.

const chart = Elicit({
width: 560, height: 300,
margins: { top: 16, right: 16, bottom: 16, left: 16 },
axes: false,
schema: {
structure: "hierarchy",
tables: {
nodes: {
id: { type: "categorical", key: true, open: true },
kind: { type: "categorical", domain: ["row", "tile"] },
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
// An empty row returns to this size.
w: { type: "quantitative", domain: [0, 600], default: 60 },
h: { type: "quantitative", domain: [0, 400], default: 50 },
},
nesting: {
child: { type: "ref" },
parent: { type: "ref" },
},
},
},
data: {
nodes: [
{ id: "outer", kind: "row", x: 10, y: 75, w: 60, h: 50 },
],
nesting: [
{ child: "A1", parent: "outer" },
],
},
constraints: [
constraints.contain({ parent: (d) => d.kind === "row" }),
],
layout: [
// Rows hold tiles and other rows, left to right, and fit round them.
layout.hierarchy.contain({ padding: 8, fit: true }),
layout.row({ gap: 6 }),
layout.dodge({ in: "roots" }),
],
marks: [
rect({
cornerRadius: 5,
stroke: "#46596B",
edits: [
move({ channels: ["x", "y"], mode: "relative" }),
edit.hierarchy.nest(),
],
channels: {
x: { field: "x" },
y: { field: "y" },
width: { field: "w", scale: null },
height: { field: "h", scale: null },
fill: { fn: (d) => (d.kind === "row" ? "#EDF7F8" : "#FFFFFF") },
},
}),
text({
fontSize: 11,
fill: "#20555A",
channels: {
x: { field: "x" },
y: { field: "y" },
text: { fn: (d) => (d.kind === "tile" ? d.id : "") },
},
}),
],
});
mount(chart.dom());
Try: Drag A2 into any row. Drag a whole row into another one.

A grid

layout.grid({ columns: 3, gap: 8 }) — fixed boards that fill in reading order.

const chart = Elicit({
width: 560, height: 320,
margins: { top: 16, right: 16, bottom: 16, left: 16 },
axes: false,
// The two boards are the question, so they stay where they are.
lock: (d, i, table) => table === "nodes" && d.kind === "board",
schema: {
structure: "hierarchy",
tables: {
nodes: {
id: { type: "categorical", key: true, open: true },
label: { type: "categorical", open: true },
kind: { type: "categorical", domain: ["board", "item"] },
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
w: { type: "quantitative", domain: [0, 600] },
h: { type: "quantitative", domain: [0, 400] },
},
nesting: {
child: { type: "ref" },
parent: { type: "ref" },
},
},
},
data: {
nodes: [
{ id: "keep", label: "Keep", kind: "board", x: 27, y: 50, w: 220, h: 250 },
],
nesting: ["i0", "i1", "i2", "i3", "i4", "i5", "i6", "i7"].map((child) => ({ child, parent: "keep" })),
},
constraints: [
constraints.contain({ parent: (d) => d.kind === "board", child: (d) => d.kind === "item" }),
],
layout: [
// No `fit`: a board keeps its size. Items fill three cells to a row under its name.
layout.hierarchy.contain({ padding: { top: 30, right: 14, bottom: 14, left: 14 } }),
layout.grid({ columns: 3, gap: 8 }),
],
marks: [
rect({
cornerRadius: 6,
stroke: "#46596B",
edits: [
move({ channels: ["x", "y"], mode: "relative" }),
edit.hierarchy.nest(),
],
channels: {
x: { field: "x" },
y: { field: "y" },
width: { field: "w", scale: null },
height: { field: "h", scale: null },
fill: { fn: (d) => (d.kind === "board" ? "#EDF7F8" : "#FFFFFF") },
},
}),
text({
fill: "#20555A",
channels: {
x: { field: "x" },
y: { field: "y" },
text: { field: "label" },
fontSize: { fn: (d) => (d.kind === "board" ? 11 : 24) },
dy: { fn: (d) => (d.kind === "board" ? -d.h / 2 + 15 : 0) },
},
}),
],
});
mount(chart.dom());
Try: Drag items onto Drop. Drag an item between two others to reorder.

Packed circles

layout.pack({ gap: 3 }) — an item lands where you drop it, touching the others.

const chart = Elicit({
width: 560, height: 340,
margins: { top: 24, right: 16, bottom: 16, left: 16 },
axes: false,
schema: {
structure: "hierarchy",
tables: {
nodes: {
id: { type: "categorical", key: true, open: true },
label: { type: "categorical", open: true },
kind: { type: "categorical", domain: ["set", "item"] },
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
// An empty set returns to this radius.
r: { type: "quantitative", domain: [0, 300], default: 30 },
},
nesting: {
child: { type: "ref" },
parent: { type: "ref" },
},
},
},
data: {
nodes: [
{ id: "likely", label: "Likely", kind: "set", x: 28, y: 50, r: 30 },
],
nesting: [
{ child: "a", parent: "likely" },
],
},
constraints: [
constraints.contain({ parent: (d) => d.kind === "set", child: (d) => d.kind === "item" }),
],
layout: [
// Items gather where they are dropped; the set encloses them.
layout.hierarchy.contain({ padding: 6, fit: true }),
layout.pack({ gap: 3 }),
],
marks: [
point({
stroke: "#46596B",
edits: [
move({ channels: ["x", "y"], mode: "relative" }),
edit.hierarchy.nest(),
],
channels: {
x: { field: "x" },
y: { field: "y" },
size: { field: "r", scale: null },
fill: { fn: (d) => (d.kind === "set" ? "#EDF7F8" : "#C3B9DF") },
},
}),
text({
fontSize: 10,
fill: "#20555A",
channels: {
x: { field: "x" },
y: { field: "y" },
text: { field: "label" },
dy: { fn: (d) => (d.kind === "set" ? -d.r - 8 : 0) },
},
}),
],
});
mount(chart.dom());
Try: Drag Rain into Unlikely. Drag every item out of a set and it returns to its default radius.

Packed boxes

layout.pack({ keep: "angle", gap: 6 }) — a card keeps its direction from Price.

const chart = Elicit({
width: 560, height: 340,
margins: { top: 16, right: 16, bottom: 16, left: 16 },
axes: false,
// The board is the question, so it stays where it is.
lock: (d, i, table) => table === "nodes" && d.kind === "board",
schema: {
structure: "hierarchy",
tables: {
nodes: {
id: { type: "categorical", key: true, open: true },
label: { type: "categorical", open: true },
kind: { type: "categorical", domain: ["board", "goal", "item"] },
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
w: { type: "quantitative", domain: [0, 600] },
h: { type: "quantitative", domain: [0, 400] },
},
nesting: {
child: { type: "ref" },
parent: { type: "ref" },
},
},
},
data: {
nodes: [
{ id: "board", label: "What drives the price?", kind: "board", x: 50, y: 50, w: 520, h: 300 },
],
nesting: ["price", "a", "b", "c", "d", "e"].map((child) => ({ child, parent: "board" })),
},
constraints: [
constraints.contain({ parent: (d) => d.kind === "board" }),
],
layout: [
// Each card slides in to touch, keeping its direction from Price.
layout.hierarchy.contain(),
layout.pack({ keep: "angle", gap: 6 }),
],
marks: [
rect({
cornerRadius: 6,
stroke: "#46596B",
edits: [
move({ channels: ["x", "y"], mode: "relative" }),
edit.hierarchy.nest(),
],
channels: {
x: { field: "x" },
y: { field: "y" },
width: { field: "w", scale: null },
height: { field: "h", scale: null },
fill: { fn: (d) => (d.kind === "board" ? "#EDF7F8" : d.kind === "goal" ? "#C3B9DF" : "#FFFFFF") },
},
}),
text({
fontSize: 11,
fill: "#20555A",
channels: {
x: { field: "x" },
y: { field: "y" },
text: { field: "label" },
dy: { fn: (d) => (d.kind === "board" ? -d.h / 2 + 15 : 0) },
},
}),
],
});
mount(chart.dom());
Try: Drag Fuel to the far right of the board. It slides in beside Price on that side.

Fixed containers

Leave fit off layout.hierarchy.contain and a container keeps the size it was given. Use this for regions that are part of the question: buckets, lanes, zones. Lock them with lock so only the cards move. Cards stay inside the bucket's padding, and a locked row stays where it is when nodes dodge. Add layout.dodge() to keep cards from overlapping, or layout.column() / layout.grid() to put them in slots.

The answer is the nesting table: one row per card, naming its bucket.

Sorting cards into buckets

No fit: each bucket keeps its size and its cards inside it; nesting records the sort.

const chart = Elicit({
width: 560, height: 340,
margins: { top: 20, right: 16, bottom: 16, left: 16 },
axes: false,
// The buckets are the question, so they stay where they are.
lock: (d, i, table) => table === "nodes" && d.kind === "bucket",
schema: {
structure: "hierarchy",
tables: {
nodes: {
id: { type: "categorical", key: true, open: true },
label: { type: "categorical", open: true },
kind: { type: "categorical", domain: ["bucket", "card"] },
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
w: { type: "quantitative", domain: [0, 600] },
h: { type: "quantitative", domain: [0, 400] },
},
nesting: {
child: { type: "ref" },
parent: { type: "ref" },
},
},
},
data: {
nodes: [
{ id: "must", label: "Must have", kind: "bucket", x: 18, y: 58, w: 150, h: 210 },
],
nesting: [{ child: "c5", parent: "must" }],
},
constraints: [
constraints.contain({ parent: (d) => d.kind === "bucket", child: (d) => d.kind === "card" }),
],
layout: [
// No `fit`: a bucket keeps the size it was given, and cards stay below its name.
layout.hierarchy.contain({ padding: { top: 26 } }),
layout.dodge(),
],
marks: [
rect({
cornerRadius: 6,
stroke: "#46596B",
edits: [
move({ channels: ["x", "y"], mode: "relative" }),
edit.hierarchy.nest(),
],
channels: {
x: { field: "x" },
y: { field: "y" },
width: { field: "w", scale: null },
height: { field: "h", scale: null },
fill: { fn: (d) => (d.kind === "bucket" ? "#EDF7F8" : "#B7DEE1") },
},
}),
text({
fontSize: 11,
fill: "#20555A",
channels: {
x: { field: "x" },
y: { field: "y" },
text: { field: "label" },
dy: { fn: (d) => (d.kind === "bucket" ? -d.h / 2 + 12 : 0) },
},
}),
],
});
mount(chart.dom());
Try: Drag each card into a bucket. A card released outside every bucket has no nesting row.

Other shapes

point, ellipse, shape and a composite hold other nodes the same way. A round mark fits the circle that encloses its contents. A point writes its fitted radius to size, and an ellipse writes to rx and ry.

Circles

contains: { where, padding: 8, fit: true } — a set's radius encloses its items.

const chart = Elicit({
width: 480, height: 340,
margins: { top: 16, right: 16, bottom: 16, left: 16 },
axes: false,
schema: {
structure: "hierarchy",
tables: {
nodes: {
id: { type: "categorical", key: true, open: true },
label: { type: "categorical", open: true },
kind: { type: "categorical", domain: ["set", "item"] },
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
r: { type: "quantitative", domain: [0, 300], default: 40 },
},
nesting: {
child: { type: "ref" },
parent: { type: "ref" },
},
},
},
data: {
nodes: [
{ id: "s1", label: "Mammals", kind: "set", x: 30, y: 55, r: 40 },
],
nesting: [
{ child: "i1", parent: "s1" },
],
},
layout: [layout.dodge()],
marks: [
point({
stroke: "#46596B",
// A set's radius encloses its items.
contains: { where: (d) => d.kind === "set", padding: 8, fit: true },
edits: [
move({ channels: ["x", "y"], mode: "relative" }),
edit.hierarchy.nest(),
],
channels: {
x: { field: "x" },
y: { field: "y" },
size: { field: "r", scale: null },
fill: { fn: (d) => (d.kind === "set" ? "#EDF7F8" : "#C3B9DF") },
},
}),
text({
fontSize: 10,
fill: "#20555A",
channels: {
x: { field: "x" },
y: { field: "y" },
text: { field: "label" },
dy: { fn: (d) => (d.kind === "set" ? -d.r - 8 : 0) },
},
}),
],
});
mount(chart.dom());
Try: Drag Penguin into Birds. Drag an item towards a set’s edge and the set grows on release.

Dragging in and out

Put edit.hierarchy.nest() on the mark you drag, beside move({ mode: "relative" }). The move carries the node. On release, the node joins the innermost container under the pointer. Released over no container, it leaves the one it was in.

While you drag, the chart shows what a release would do. The container the node would join is outlined and grows to hold it. The container it came from keeps its size while the pointer is inside it, and shrinks once the pointer leaves. Other nodes move out of the way when layout.dodge() or a slot layout is active. The data changes on release. Style the outline with the target state of effects.

A container stays where it is when you drag a node past it or out of it. Released against a container's edge, the node you dropped moves clear of it when layout.dodge() is active.

The layout eases to its new place. Nodes make room first and a container resizes after them. The node you drag stays on the pointer. Set the time with motion: { duration } on the spec, in milliseconds, or motion: false to draw each change at once. Motion is off when the reader's system asks for reduced motion.

The same move moves a container, and its contents travel with it.

Rules about which nodes may go where, maximum depth, or how many children a container may hold belong in constraints.contain(...) (or constraints.custom on table: "nesting"). A drop a rule refuses shows no outline and leaves the data unchanged.

A limit on each container

constraints.contain({ parent, child, maxChildren: 3 }) — three tasks per phase.

const chart = Elicit({
width: 520, height: 340,
margins: { top: 20, right: 16, bottom: 16, left: 16 },
axes: false,
schema: {
structure: "hierarchy",
tables: {
nodes: {
id: { type: "categorical", key: true, open: true },
label: { type: "categorical", open: true },
kind: { type: "categorical", domain: ["phase", "task"] },
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
w: { type: "quantitative", domain: [0, 600], default: 130 },
h: { type: "quantitative", domain: [0, 400], default: 80 },
},
nesting: {
child: { type: "ref" },
parent: { type: "ref" },
},
},
},
data: {
nodes: [
{ id: "p1", label: "Phase 1 (max 3)", kind: "phase", x: 25, y: 58, w: 130, h: 80 },
],
nesting: [
{ child: "t1", parent: "p1" },
],
},
constraints: [
// Only phases hold tasks, and each phase holds at most three.
constraints.contain({
parent: (d) => d.kind === "phase",
child: (d) => d.kind === "task",
maxChildren: 3,
}),
],
layout: [
layout.hierarchy.contain({ padding: 12, fit: true }),
layout.dodge(),
],
marks: [
rect({
cornerRadius: 6,
stroke: "#46596B",
edits: [
move({ channels: ["x", "y"], mode: "relative" }),
edit.hierarchy.nest(),
],
channels: {
x: { field: "x" },
y: { field: "y" },
width: { field: "w", scale: null },
height: { field: "h", scale: null },
fill: { fn: (d) => (d.kind === "phase" ? "#F9EEEC" : "#F6D5CB") },
},
}),
text({
fontSize: 11,
fill: "#9A3E27",
channels: {
x: { field: "x" },
y: { field: "y" },
text: { field: "label" },
dy: { fn: (d) => (d.kind === "phase" ? -d.h / 2 - 8 : 0) },
},
}),
],
});
mount(chart.dom());
Try: Drag Review into Phase 1: it is full, so nothing lights up. Drag it into Phase 2 instead.

Reading and setting from outside

Containment is stored as rows, so your code reads and writes it like any other data. getData() returns the nesting rows and each container's fitted size.

setData takes the same shape. Change the nesting rows and every container re-fits. A node sent with no x and y is placed inside the container it joins, clear of the nodes already there. In an arranged container it takes the last slot.

const data = chart.getData();
chart.setData({ ...data, nesting: [...data.nesting, { child: "n4", parent: "g2" }] });

Set from outside

Each button calls setData with new nesting rows; no sizes are sent.

const el = Elicit({
width: 520, height: 320,
margins: { top: 20, right: 16, bottom: 16, left: 16 },
axes: false,
schema: {
structure: "hierarchy",
tables: {
nodes: {
id: { type: "categorical", key: true, open: true },
label: { type: "categorical", open: true },
kind: { type: "categorical", domain: ["group", "note"] },
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
w: { type: "quantitative", domain: [0, 600], default: 130 },
h: { type: "quantitative", domain: [0, 400], default: 80 },
},
nesting: {
child: { type: "ref" },
parent: { type: "ref" },
},
},
},
data: {
nodes: [
{ id: "g1", label: "Group A", kind: "group", x: 25, y: 55, w: 130, h: 80 },
],
nesting: [
{ child: "n1", parent: "g1" },
{ child: "n2", parent: "g1" },
],
},
constraints: [
constraints.contain({ parent: (d) => d.kind === "group" }),
],
layout: [
layout.hierarchy.contain({ padding: 12, fit: true }),
layout.dodge(),
],
marks: [
rect({
cornerRadius: 6,
stroke: "#46596B",
edits: [
move({ channels: ["x", "y"], mode: "relative" }),
edit.hierarchy.nest(),
],
channels: {
x: { field: "x" },
y: { field: "y" },
width: { field: "w", scale: null },
height: { field: "h", scale: null },
fill: { fn: (d) => (d.kind === "group" ? "#EDF7F8" : "#C2DEBA") },
},
}),
text({
fontSize: 11,
fill: "#20555A",
channels: {
x: { field: "x" },
y: { field: "y" },
text: { field: "label" },
dy: { fn: (d) => (d.kind === "group" ? -d.h / 2 - 8 : 0) },
},
}),
],
});
mount(el.dom());
// What a program (or a model) does: read the tables, write them back.
const button = (label, run) => {
const b = document.createElement("button");
b.textContent = label;
b.style.cssText = "margin: 0 6px 8px 0; padding: 4px 10px; font: 12px system-ui; cursor: pointer;";
b.onclick = run;
return b;
};
const toolbar = document.createElement("div");
let minted = 0;
toolbar.append(
// Re-parent by rewriting the nesting rows. No sizes or positions are sent.
button("Move everything to Group B", () => {
const data = el.getData();
el.setData({
...data,
nesting: data.nodes.filter((d) => d.kind === "note").map((d) => ({ child: d.id, parent: "g2" })),
});
}),
// A new node with no x/y: it is placed inside the group it joins.
button("Add a note to Group A", () => {
const data = el.getData();
const id = "new" + ++minted;
el.setData({
nodes: [...data.nodes, { id, label: "Added " + minted, kind: "note", x: null, y: null, w: 70, h: 26 }],
nesting: [...data.nesting, { child: id, parent: "g1" }],
});
}),
button("Ungroup all", () => el.setData({ ...el.getData(), nesting: [] })),
);
if (el.dom().parentNode) el.dom().parentNode.insertBefore(toolbar, el.dom());
Try: Click the buttons, then drag a note. Both write the same tables.