Every word after the first is placed by walking outward from the canvas center and
taking the first spot that doesn't collide with anything already placed. The
spiral option decides what "outward" means — and that single choice is what
makes a cloud look like a disk or like a filled box.
mode picks the packing strategy
(pretty / balanced / fast);
spiral picks the search path. Ordering, collision testing and cost are
identical either way, so you can change the silhouette without giving up placement quality.
spiral | Path | Resulting look |
|---|---|---|
"archimedean"default |
The classic curve r = b·θ — radius grows smoothly with angle. |
A round, organic cloud. The canvas corners stay empty because the search reaches them last, if at all. |
"rectangular" |
Growing axis-aligned square rings, each one step further out than the last. | A box-filled cloud: words reach the corners, and edges read as straight lines. This is d3-cloud's other spiral. |
spiral alongside modeOne extra option. Everything else — the items, the placements you get back, the way you render them — is unchanged, so you can flip between the two at runtime and re-draw.
import { layout } from "./js/index.js"; const placements = await layout(items, { mode: "pretty", // packing strategy — unchanged spiral: "rectangular", // search path: fill a box, not a disk width: 960, height: 600, });
Omit spiral and you get "archimedean" — the same clouds this
library has always produced. Anything else throws a RangeError.
fast ignores it. Shelf packing never searches outward,
so there is no path to choose.padding, the font-size range, or a bigger canvas first.
The same words, the same mode, the same seed — laid out with each path so you can compare the round cloud against the boxy one.
Watch the corners. The round cloud tapers away from them; the boxy one runs words straight into them. On the wide canvas above you can also see the square path's trade-off — it grows by equal steps on both axes, so it runs out of vertical room before it reaches the far left and right edges. Fullscreen lays out against the viewport so you can inspect either path alone.