Shape
shape() draws one SVG path per row, centred at its x/y — a named shape, a pictogram, any path you write. The shape comes from the symbol channel. size is the radius of the box it fits, and angle turns it in place. It takes every universal edit, as point does.
API reference
shape(options)
One SVG path per row, centred at x/y. The shape comes from the symbol channel. It takes every universal edit, is picked inside its body, and declares a node box for a network.
shape({ channels, symbol, edits, id, table, tip }) → Mark| Option | Type · default | Description |
|---|---|---|
symbol | string | default'circle' | Shorthand for a constant symbol channel: a shape name, an SVG path, or a function of the row returning either. A string that is neither draws a circle and logs a warning. |
image | string | | 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. |
channels | objectdefault{} | Channel map — see Channels. |
edits | Edit[] | Mark-level edits. move, resize, rotate and the rest work as on point. |
fill, | styledefaultfill: theme ink | Shorthands for constant channels. |
| Channel | Type | Description |
|---|---|---|
x / y | linear | | The shape's centre. Omitted, it sits at the middle of the plot on that axis. |
symbol | ordinal | The shape per row. A field maps onto the named shapes circle, square, triangle, diamond, star, cross, wye by default, or onto scale: { range: [...] } — names or SVG path strings. Default circle. |
size | linear | The radius of the box the shape fits, in px (default 6). Pair with resize() to drag it. |
angle | linear | Rotation in degrees, counter-clockwise from east, about the shape’s centre. Pair with rotate({ pick: 'direct', pivot: 'mark', fold: false }). |
fill / stroke / strokeWidth / strokeDash / opacity | const | | Paint, as on any mark. |
ports | true | | Where links may meet the shape’s box in a network. Pair with edit.network.connect(). |
Named shapes by category
Put a categorical field on symbol and each category takes a named shape: circle, square, triangle, diamond, star, cross, wye, in that order. legends: true keys each category with its shape.
You can grab a shape anywhere inside its outline.
Trees by species
symbol on a categorical field maps each species to a named shape; the legend keys them.
const chart = Elicit({width: 440, height: 280,margins: { top: 16, right: 16, bottom: 32, left: 36 },legends: true,schema: {x: { type: "quantitative", domain: [0, 100] },y: { type: "quantitative", domain: [0, 100] },kind: { type: "categorical", domain: ["oak", "pine", "birch", "maple"] },},data: [{ x: 18, y: 30, kind: "oak" }, { x: 30, y: 72, kind: "pine" },],marks: [shape({size: 9, fill: "#1B3F60",channels: {x: { field: "x" },y: { field: "y" },// Each category takes a named shape: circle, square, triangle, diamond, …symbol: { field: "kind", edit: cycle() },},edits: [move({ channels: ["x", "y"] })],}),],});mount(chart.dom());
Pictograms from SVG paths
Give symbol a scale: { range: [...] } of SVG path strings, and each category draws its own pictogram. A path can use any coordinates. It is fitted to the box of radius size around its row's position.
The elicited value is the category. The path encodes it, as a colour does on fill.
Rank three needs
A path per category on the symbol scale; move() on y sets each priority.
// Hand-written SVG paths, one per category. Any coordinates work:// each path is fitted to a box of radius `size` around its row's x/y.const house = "M0 10 L10 0 L20 10 L17 10 L17 20 L3 20 L3 10 Z";const car = "M1 12 L4 6 L16 6 L19 12 L19 16 L1 16 Z M4 16 A2 2 0 0 0 8 16 Z M12 16 A2 2 0 0 0 16 16 Z";const heart = "M10 18 L2.5 10 A5 5 0 0 1 10 4.5 A5 5 0 0 1 17.5 10 Z";const chart = Elicit({width: 380, height: 260,margins: { top: 20, right: 16, bottom: 32, left: 36 },schema: {need: { type: "categorical", domain: ["housing", "transport", "health"] },priority: { type: "quantitative", domain: [0, 10] },},data: [{ need: "housing", priority: 7 },],marks: [shape({size: 16,channels: {x: { field: "need" },y: { field: "priority", edit: move() },symbol: { field: "need", scale: { range: [house, car, heart] } },fill: { field: "need", scale: { range: ["#4e79a7", "#f28e2b", "#e15759"] } },},}),],});mount(chart.dom());
One path for every row
The symbol shorthand sets one shape for every row: a name, an SVG path, or (d, i, data) => string for a shape chosen per row. It defaults to "circle". A string that is neither a name nor a readable path draws a circle and logs a warning.
angle rotates the shape in degrees, counter-clockwise from east. rotate() on angle turns it about its centre, and resize() on size grows it. Both read the same drag, so when separates them: with when.noShift and when.shift, a plain drag turns an arrow and Shift-drag sets its speed.
Wind arrows
symbol sets one arrow for every row; rotate() writes dir and resize() writes speed.
// Wind at three stations: drag an arrow to turn it, Shift-drag to set its speed.const arrow = "M0 7 L12 7 L12 2 L20 10 L12 18 L12 13 L0 13 Z"; // points right (0°)const chart = Elicit({width: 400, height: 260,margins: { top: 16, right: 16, bottom: 32, left: 36 },schema: {x: { type: "quantitative", domain: [0, 100] },y: { type: "quantitative", domain: [0, 100] },dir: { type: "quantitative", domain: [0, 360] },speed: { type: "quantitative", domain: [0, 30] },},data: [{ x: 22, y: 62, dir: 30, speed: 12 },],constraints: [clamp({ field: "speed", min: 2, max: 30 })],marks: [shape({symbol: arrow,fill: "#50AEB7",channels: {x: { field: "x" },y: { field: "y" },// Degrees, counter-clockwise from east.angle: {field: "dir",scale: { range: [0, 360] },edit: rotate({ pick: "direct", pivot: "mark", fold: false, when: when.noShift }),},size: { field: "speed", scale: { range: [4, 28] } },},edits: [resize({ channel: "size", when: when.shift })],}),],});mount(chart.dom());
Shapes as network nodes
A shape declares its box, so it can be the node mark of a network. Links meet the box's edges, and a ports channel puts connection points on them. On a shape turned by angle, the edges and ports turn with it.
A supply network
Each station is a shape by kind. ports with edit.network.connect() draws new links.
const chart = Elicit({width: 460, height: 280,margins: { top: 24, right: 24, bottom: 24, left: 24 },axes: false,schema: {structure: "network",tables: {stations: {role: "nodes",fields: {id: { type: "categorical", key: true, open: true },kind: { type: "categorical", domain: ["source", "relay", "sink"] },x: { type: "quantitative", domain: [0, 100] },y: { type: "quantitative", domain: [0, 100] },},},feeds: {role: "links",directed: true,fields: { source: { type: "ref" }, target: { type: "ref" } },},},},data: {stations: [{ id: "a", kind: "source", x: 10, y: 50 },],feeds: [{ source: "a", target: "b" },],},marks: [link({ stroke: "#94A5B3", strokeWidth: 1.5, edits: [edit.network.rewire()] }),shape({size: 14,channels: {x: { field: "x", edit: move({ channels: ["x", "y"], mode: "relative" }) },y: { field: "y" },symbol: { field: "kind", scale: { range: ["triangle", "circle", "square"] } },fill: { field: "kind", scale: { range: ["#7DB86B", "#50AEB7", "#EE7B5E"] } },// Drag from a port to another station to link them.ports: { value: true, edit: edit.network.connect() },},}),],});mount(chart.dom());