pack
Places its children so that their enclosing circles touch and do not overlap. This is circle packing. With a by, pack makes one child per group. Without a by, it makes one child per row, from the one-row group [row] (see spread). Two pack operators in a row give a nested packing.
gf.chart(seafood)
.flow(gf.pack({ by: "lake" }), gf.pack())
.mark(gf.circle({ r: 12, fill: "species" }))
.render(root, { w: 420, h: 420 });Signature
pack({ by?, spacing? })
pack({ spacing? }, marks)Combinator form
Given a list of marks, pack packs those marks instead of rows of data. It returns a mark, so a pack can hold another pack.
gf.pack({}, [
gf.circle({ r: 60 }),
gf.ellipse({ w: 90, h: 44 }),
gf.pack({}, [
gf.circle({ r: 26 }),
gf.circle({ r: 18 }),
gf.circle({ r: 14 }),
]),
]).render(root, { w: 420, h: 420 });Parameters
Circle packing: place the flow's groups (or rows) so their enclosing circles touch without overlapping, with d3's front-chain algorithm. Children keep their pixel size; the pack does not fit itself to the available space yet (#967).
| Option | Type | Default | Description |
|---|---|---|---|
by | string | FieldAccessor | ChunkKey | Field to partition rows by (like spread/scatter); also accepts a field(...) accessor carrying domain ops (sort/reverse/bin/dropNulls), or chunk(size) to group consecutive rows. Without by, each row is its own group. | |
spacing | number | 0 | Gap between sibling circles, in pixels: each child's enclosing circle is packed as if its radius were spacing / 2 larger. |
Packing
pack packs each child's enclosing circle with d3's front-chain algorithm (packSiblings). It has no option to choose another way to pack, because there is no other way yet.
Each child is packed by its enclosing circle, which depends on its shape.
- A circle is its own enclosing circle.
- An ellipse uses the circle of its larger radius.
- A polygon uses the smallest circle through its vertices.
- A rect or text uses the circle through the corners of its box.
- A nested
packuses the smallest circle around its own children. - An
enclosearound fresh children uses the smallest circle around its outline, stroke included.
spacing adds half of itself to each child's circle before packing, so it is the gap in pixels between two touching siblings.
Limits
- Children keep the pixel size they are laid out at. The pack does not scale itself to fit the space it is given, and it cannot yet size a child from data. So give each child a size in pixels, e.g.,
circle({ r: 12 }), notcircle({ r: "count" }). See #967.
