StackLayout
extends Layout
The StackLayout class represents a layout that positions objects by stacking them. To create a StackLayout object and apply it to a collection, use the layout function:
let sl = msc.layout("stack", {orientation: "vertical"});
collection.layout = sl;
Stacking along a path
With the "path" orientation, a stack layout lays paths end to end along a guide path, in the order of the collection’s children, with gap pixels of empty path between neighbors. The guide is given as SVG path data (d, the same format a path mark accepts) or as points (path: [[x, y], ...]). This is the layout of the collection returned by dividing a path; it can also be applied to repeated paths:
let piece = scene.mark("path", {d: "M 100 100 H 150", strokeWidth: 26});
let states = msc.repeat(piece, table, {attribute: "State", layout: msc.layout("stack", {
orientation: "path", gap: 1,
d: "M 108 245 V 336 a 21 21 0 0 0 42 0 V 160 a 21 21 0 0 1 42 0 V 355"
})});
msc.encode(piece, "length", "EV");
The layout replaces each path’s geometry with its stretch of the guide, so the template path’s own shape does not matter. Each path takes its pathLength of the guide: until lengths are set or encoded, the paths share the guide equally; with a "length" encoding, the values fill the guide minus the gaps. The layout can be set before or after the encoding. Paths past the end of the guide are clamped to it, and the guide moves with the collection when it is translated.
Properties
| property | explanation | type | default value |
|---|---|---|---|
| baseline | the baseline of stacking | String | |
| d | for the "path" orientation: the guide path as SVG path data (a constructor argument; read the result from path) | String | |
| gap | the space in pixels between neighboring children: along the stacking direction, or along the guide path for the "path" orientation; set with msc.update(layout, {gap: 2}) | Number | 0 |
group ![]() | the group that uses this layout | Group | |
| horzCellAlignment | the horizontal alignment of item in each cell | String | “left” |
| orientation | the orientation of stacking: "horizontal", "vertical", "angular" or "radial" (for arcs), or "path" (along a guide path) | String | undefined |
| path | for the "path" orientation: the guide path the children are laid along, as points | Array of [x, y] | |
type ![]() | the type of the layout | String | “stack” |
| vertCellAlignment | the vertical alignment of item in each cell | String | “bottom” |
Methods inherited from Layout
| method | explanation | return type |
|---|---|---|
clone() ![]() | returns a copy of this layout | void |
run() ![]() | apply this layout | void |

