Elicit.js

Network UI

ui.network() is the UI layer for a node-link chart. Beside a port, + adds a linked node and two more icons connect and detach. A link carries icons to reverse it, put a node on it, and remove it. A right-click menu covers the plane, the nodes and the links, and a node that sizes from data gets resize grips. Each piece appears where the spec names the edit behind it.

API reference

ui.network(options?)

The UI a node-link chart needs, built from the edits its spec names. It works on a dataset with structure: "network"; any other logs a warning.

ui.attach(chart, [ui.network()])
ui.network({ links: false, menu: { channel: "stroke" } })
ui.network({ edits: { unlink: "cut" } })
Options
OptionType · defaultDescription
ports
booleandefaulttrue
Icons beside a port: + adds a node on that side, linked from this one; the link icon connects to a node already there; detach shows where a link is docked.
links
booleandefaulttrue
Icons beside a link, where the pointer meets it: reverse, + to put a new node on it there, and remove.
menu
boolean | { channel }defaulttrue
The right-click menu. channel names the node channel its categories come from; the default is a categorical fill.
resize
booleandefaulttrue
Grips on a node mark that binds width or height to a field.
edits
{ connect?, rewire?, reverse?, unlink?, remove?, create? }defaultfound by what each edit does
The edit behind each action, by name. unlink removes a link, remove a node and create adds a node.

A flowchart with its UI

The spec below is an ordinary network of stickers with ports. Every edit the UI drives has a name. ui.attach(chart, [ui.network()]) finds them by what they do.

Notes, links and their icons

Grow the board from a port's +, link and detach with the icons beside it, reverse a link, put a node on it or remove it from its icons, add and recolour notes from the menu, resize a note by its grips.

const chart = Elicit({
width: 540, height: 380,
margins: { top: 28, right: 28, bottom: 28, left: 28 },
axes: false,
schema: {
structure: "network",
tables: {
steps: {
role: "nodes",
fields: {
id: { type: "categorical", key: true, open: true },
label: { type: "categorical", open: true },
kind: { type: "categorical", domain: ["idea", "task", "risk"] },
w: { type: "quantitative", domain: [80, 240] },
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
},
},
flows: {
role: "links",
directed: true,
fields: {
source: { type: "ref" },
target: { type: "ref" },
fromSide: { type: "categorical", domain: ["top", "right", "bottom", "left"] },
toSide: { type: "categorical", domain: ["top", "right", "bottom", "left"] },
},
},
},
},
data: {
steps: [
{ id: "s1", label: "Draft the question", kind: "idea", w: 130, x: 22, y: 80 },
],
flows: [{ source: "s1", target: "s2", fromSide: "right", toSide: "left" }],
},
marks: [
link({
id: "flow",
stroke: "#94A5B3",
strokeWidth: 1.5,
channels: { sourceSide: { field: "fromSide" }, targetSide: { field: "toSide" } },
edits: [
edit.network.rewire({ name: "rewire" }),
// gesture: "commit" is a gesture no pointer makes: only the UI fires these.
edit.network.reverse({ name: "reverse", gesture: "commit" }),
remove({ name: "unlink", gesture: "commit" }),
],
}),
sticker({
id: "note",
stroke: "rgba(70, 89, 107, 0.25)",
cornerRadius: 8,
edits: [
editText({ multiline: true }),
create({ name: "add", gesture: "commit", defaults: { label: "New note", w: 110 } }),
remove({ name: "delete", gesture: "commit" }),
],
channels: {
x: { field: "x", edit: move({ channels: ["x", "y"], mode: "relative" }) },
y: { field: "y" },
text: { field: "label" },
fill: { field: "kind", scale: { range: ["#FBE6B0", "#C9E4F6", "#F8CCC6"] } },
width: { field: "w", scale: { range: [80, 240] } },
ports: { value: true, edit: edit.network.connect({ name: "link" }) },
},
}),
],
});
mount(chart.dom());
ui.attach(chart, [ui.network()]);
Try: Bring the pointer to the edge of a note. Right-click the board, a note or a link.

Add, link and detach at a port

Bring the pointer to a port and up to three icons appear outside the node, on that side. The port they belong to is lit, with the rest of the node's ports.

+ adds a node on that side and links this port to it. The new node takes this node's category and size, and sits one gap out from the side. Where another node is in the way, or the plot ends, it steps along the side to the nearest free spot. The node and its link are one undo step. Drag the + to draw the link yourself: drop it on a node to link to that node, or on empty space to make the new node there.

The link icon connects to a node that is already on the board. Drag it to the node, or click it and then click the node. The link follows the pointer until that second click, and Escape cancels. The icon shows only where a new link could land.

At a port that holds a link, the detach icon takes it off. Drag the icon to re-point that end of the link to another node. Click it to remove the link. With several links at the port, the click lists them and you choose one.

Reaching the icons

Icons stay while the pointer travels to them, and for a moment after it leaves what they belong to. One set shows at a time: near a port, the port's icons replace a link's.

Resize a node

A node mark that binds width or height to a field gets resize grips. A port sits in the middle of each side, so the grips take the corners below it.

What the spec declares

Each action needs one named edit. An action whose edit is missing is left out; an edit that is there with no name logs a warning.

| Action | Edit | Where it goes | | --- | --- | --- | | + beside a port | edit.network.connect({ name }) and create({ name }) | the ports channel; the node mark | | Link icon beside a port | edit.network.connect({ name }) | the node mark's ports channel | | Detach by dragging | edit.network.rewire({ name }) | the link mark | | Detach by clicking, remove a link | remove({ name }) | the link mark | | Reverse a link | edit.network.reverse({ name }) | the link mark | | + on a link | create({ name }), edit.network.connect({ name }) and edit.network.rewire({ name }) | the node mark, its ports channel, the link mark | | Add a node | create({ name }) | the node mark | | Remove a node | remove({ name }) | the node mark | | A node's category | none | a categorical fill on the node mark | | Resize a node | none | a field on width or height |

gesture: "commit" on create, remove and reverse keeps them for the UI, so a plain click on the board adds and removes nothing. ui.network({ edits: { connect, rewire, reverse, unlink, remove, create } }) names an edit yourself where the chart has several of a kind.