Skip to content

SquarifyItem

Defined in: perf/layout/squarify.ts:26

Squarified treemap layout (Bruls, Huijsen & van Wijk, 2000).

Produces axis-aligned rectangles whose areas are proportional to the input values, optimising the per-rectangle aspect ratio so cells stay close to square.

Implementation notes (this file used to be O(n²)):

  • The input array is not copied or sliced. We walk it with an index cursor (start), so we never reallocate the tail of the array.
  • remainingTotal is maintained as a running counter; we subtract rowSum after each row instead of re-summing the leftover items.
  • The “would adding this candidate worsen the worst aspect ratio?” test never builds a [...row, candidate] array. worstAspect accepts the candidate as an extra parameter and folds it into the loop, so the inner per-iteration work allocates nothing.

Worst-case complexity is now O(Σ row.length) for the aspect-ratio checks (each item is visited once per row it sits in, plus once when the row is committed) — i.e. close to linear for typical inputs and never worse than O(n × maxRowLength) which is bounded by the number of items per row.

Extended by

Properties

label

label: string

Defined in: perf/layout/squarify.ts:27


value

value: number

Defined in: perf/layout/squarify.ts:28