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

propertyexplanationtypedefault value
baselinethe baseline of stackingString
dfor the "path" orientation: the guide path as SVG path data (a constructor argument; read the result from path)String
gapthe 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})Number0
group the group that uses this layoutGroup
horzCellAlignmentthe horizontal alignment of item in each cellString“left”
orientationthe orientation of stacking: "horizontal", "vertical", "angular" or "radial" (for arcs), or "path" (along a guide path)Stringundefined
pathfor the "path" orientation: the guide path the children are laid along, as pointsArray of [x, y]
type the type of the layoutString“stack”
vertCellAlignmentthe vertical alignment of item in each cellString“bottom”

Methods inherited from Layout

methodexplanationreturn type
clone() returns a copy of this layoutvoid
run() apply this layoutvoid