class Geometry · Computations
Pack
Packs circles tightly, e.g. as packed bubbles, or places them along a curve around a map (necklace maps).
circlesAround packs the circles around a point with their sizes kept, circlesInCircle scales
the packing so that it fits into a circle; the circlesAlong… functions place each circle on a
curve near where it belongs, all scaled by one factor. The functions compute once and are not
reactive. For circles that follow data, call them in Reactive.do with what the circles are
computed from as senders, and pass the same result every time so that visuals made from it
follow. circlesAround and circlesInCircle use only the radii of the input circles and pack
from scratch on each call, so when values change a circle may take a different place; animate
towards the result (e.g. Animate.shape.followAll) for smooth motion. Their packing is dense and
the same for the same input, but not the densest possible. The circlesAlong… functions also use
the centers (where each circle belongs) and can keep the last order with previous.
Static methods
circlesAlongArcstatic
static circlesAlongArc(circles: Circle[], arc: Arc | ShapeLike, options?: PackCirclesAlongCurveOptions | null, result?: Circle[] | null): Circle[]Places circles on an arc around a map, each near where it belongs, all scaled by the largest
common factor at which none overlap: a necklace map on part of a circle. E.g.
Pack.circlesAlongArc(symbols, arc, { padding: 2 }, onArc).
The input circles' centers are where each circle belongs (e.g. the center of its region),
their radii the relative sizes (e.g. from Values.sqrtScale). Each home is projected to the
closest point of the arc; the circles keep the order of these points along it and move along
it as little as possible so that none overlap (with padding between them), all between the
arc's ends. All radii are multiplied by the same factor, the largest at which they fit the
arc's length (up to maxScale), so the sizes stay comparable. Where the arc bends,
neighbours get more room along it; only neighbours are checked, so a curve that comes back
close to itself can still let circles overlap. The result is the same for the same input and
changes smoothly when the homes move, as long as their order along the arc stays; when it
changes, circles swap places: animate towards the result (e.g. Animate.shape.followAll), or
pass the last result as previous to keep the order (e.g. while dragging); order: "given"
keeps the order of the list. A circle whose center or radius is not a finite number (or whose
radius is 0 or negative) is returned unchanged and left out; an arc that is not finite
returns all circles unchanged.
circles- The circles at their homes; they are not changed (unless they are also
result). arc- The necklace.
optionsoptional- The padding, largest scale, order and last layout (see
PackCirclesAlongCurveOptions). resultoptional- Optional list to store the result in: one circle per input circle, in the same order; its circles are reused and written to, and circles are added or removed at the end to match the number of input circles.
Returns The circles on the necklace.
circlesAlongCirclestatic
static circlesAlongCircle(circles: Circle[], circle: Circle | ShapeLike, options?: PackCirclesAlongCurveOptions | null, result?: Circle[] | null): Circle[]Places circles on a circle around a map, each near where it belongs, all scaled by the
largest common factor at which none overlap: a necklace map. E.g.
Pack.circlesAlongCircle(symbols, ring, { padding: 2 }, onRing).
The input circles' centers are where each circle belongs (e.g. the center of its region),
their radii the relative sizes (e.g. from Values.sqrtScale). Each home is projected to the
closest point of the circle; the circles keep the order of these points along it and move
along it as little as possible so that none overlap (with padding between them). All radii
are multiplied by the same factor, the largest at which they fit the circle's length (up to
maxScale), so the sizes stay comparable. Where the circle bends, neighbours get more room
along it; only neighbours are checked, so a curve that comes back close to itself can still
let circles overlap. The result is the same for the same input and changes smoothly when the
homes move, as long as their order along the circle stays; when it changes, circles swap
places: animate towards the result (e.g. Animate.shape.followAll), or pass the last result
as previous to keep the order (e.g. while dragging); order: "given" keeps the order of
the list. A circle whose center or radius is not a finite number (or whose radius is 0 or
negative) is returned unchanged and left out; a necklace circle that is not finite returns
all circles unchanged.
circles- The circles at their homes; they are not changed (unless they are also
result). circle- The necklace.
optionsoptional- The padding, largest scale, order and last layout (see
PackCirclesAlongCurveOptions). resultoptional- Optional list to store the result in: one circle per input circle, in the same order; its circles are reused and written to, and circles are added or removed at the end to match the number of input circles.
Returns The circles on the necklace.
circlesAlongPolygonstatic
static circlesAlongPolygon(circles: Circle[], polygon: Polygon | ShapeLike, options?: PackCirclesAlongCurveOptions | null, result?: Circle[] | null): Circle[]Places circles on a polygon around a map, each near where it belongs, all scaled by the
largest common factor at which none overlap: a necklace map. E.g. around the map's outline
grown outward: Pack.circlesAlongPolygon(symbols, Offsets.convexContour(points, 20, 4), { padding: 2 }, placed).
The input circles' centers are where each circle belongs (e.g. the center of its region),
their radii the relative sizes (e.g. from Values.sqrtScale). Each home is projected to the
closest point of the polygon; the circles keep the order of these points along it and move
along it as little as possible so that none overlap (with padding between them). All radii
are multiplied by the same factor, the largest at which they fit the polygon's length (up to
maxScale), so the sizes stay comparable. Where the polygon bends, neighbours get more room
along it; only neighbours are checked, so a curve that comes back close to itself can still
let circles overlap. The result is the same for the same input and changes smoothly when the
homes move, as long as their order along the polygon stays; when it changes, circles swap
places: animate towards the result (e.g. Animate.shape.followAll), or pass the last result
as previous to keep the order (e.g. while dragging); order: "given" keeps the order of
the list. A circle whose center or radius is not a finite number (or whose radius is 0 or
negative) is returned unchanged and left out; a polygon without length returns all circles
unchanged.
circles- The circles at their homes; they are not changed (unless they are also
result). polygon- The necklace, e.g. the convex hull of the map grown outward (
Offsets.convexContour). optionsoptional- The padding, largest scale, order and last layout (see
PackCirclesAlongCurveOptions). resultoptional- Optional list to store the result in: one circle per input circle, in the same order; its circles are reused and written to, and circles are added or removed at the end to match the number of input circles.
Returns The circles on the necklace.
circlesAlongPolylinestatic
static circlesAlongPolyline(circles: Circle[], polyline: Polyline | ShapeLike, options?: PackCirclesAlongCurveOptions | null, result?: Circle[] | null): Circle[]Places circles on a polyline beside a map, each near where it belongs, all scaled by the
largest common factor at which none overlap: a necklace map along an open curve. E.g.
Pack.circlesAlongPolyline(symbols, coast, { padding: 2 }, placed).
The input circles' centers are where each circle belongs (e.g. the center of its region),
their radii the relative sizes (e.g. from Values.sqrtScale). Each home is projected to the
closest point of the polyline; the circles keep the order of these points along it and move
along it as little as possible so that none overlap (with padding between them), all
between the polyline's ends. All radii are multiplied by the same factor, the largest at
which they fit the polyline's length (up to maxScale), so the sizes stay comparable. Where
the polyline bends, neighbours get more room along it; only neighbours are checked, so a
curve that comes back close to itself can still let circles overlap. The result is the same
for the same input and changes smoothly when the homes move, as long as their order along the
polyline stays; when it changes, circles swap places: animate towards the result (e.g.
Animate.shape.followAll), or pass the last result as previous to keep the order (e.g.
while dragging); order: "given" keeps the order of the list. A circle whose center or
radius is not a finite number (or whose radius is 0 or negative) is returned unchanged and
left out; a polyline without length returns all circles unchanged.
circles- The circles at their homes; they are not changed (unless they are also
result). polyline- The necklace, an open curve.
optionsoptional- The padding, largest scale, order and last layout (see
PackCirclesAlongCurveOptions). resultoptional- Optional list to store the result in: one circle per input circle, in the same order; its circles are reused and written to, and circles are added or removed at the end to match the number of input circles.
Returns The circles on the necklace.
circlesAroundstatic
static circlesAround(circles: Circle[], center: Point | VectorLike, options?: PackCirclesAroundOptions | null, result?: Circle[] | null): Circle[]Packs circles tightly around a point, without overlap; the radii stay as they are, e.g. a
packed bubble chart: Pack.circlesAround(circles, [400, 300], { padding: 1 }, bubbles).
The packing is placed so that its smallest enclosing circle (Circles.enclosing) is centered
on center. With order: "size" (default) the large circles are packed first and end up in
the middle. With groups, circles with the same key form a cluster and the clusters are
packed with each other, kept groupPadding apart. A circle whose radius is not a finite
number (or negative) is returned unchanged and left out; a center that is not finite returns
all circles unchanged.
circles- The circles; only their radii are used. They are not changed (unless they are also
result). center- The center of the packing.
optionsoptional- The padding, order and groups (see
PackCirclesAroundOptions). resultoptional- Optional list to store the result in: one circle per input circle, in the same order; its circles are reused and written to, and circles are added or removed at the end to match the number of input circles.
Returns The packed circles.
circlesInCirclestatic
static circlesInCircle(circles: Circle[], circle: Circle | ShapeLike, options?: PackCirclesInCircleOptions | null, result?: Circle[] | null): Circle[]Packs circles and scales the whole packing, positions and radii, so that it fits into a
circle: the circles change size. E.g. bubbles in a round frame:
Pack.circlesInCircle(circles, frame, { padding: 1 }, bubbles).
The packing is centered on the circle's center and scaled down or up by the largest factor at
which it fits; the radii in the result are the input radii times that factor (the same for
all). The padding is scaled as well, so it is given in the units of the input radii. The
arrangement depends only on the radii, the padding and the order, so resizing the circle
scales the packing evenly. If circle has radius 0, the circles get radius 0 at its center;
if it is not finite, the circles are returned unchanged. order works as in circlesAround.
circles- The circles; only their radii are used. They are not changed (unless they are also
result). circle- The circle to fit the packing into.
optionsoptional- The padding and order (see
PackCirclesInCircleOptions). resultoptional- Optional list to store the result in: one circle per input circle, in the same order; its circles are reused and written to, and circles are added or removed at the end to match the number of input circles.
Returns The packed and scaled circles.
