Mosaico

Library

Every box keeps its shape, and every gutter comes out exact.

Four ways to pack boxes of any shape, all running live below. Fill a box searches every arrangement of up to six boxes for the one with the least empty space and crop, and steers away from boxes that shrink to slivers. Even weight breaks a list into rows and gives every box the same area, so the wide ones stop dominating. Even grid puts every box in a same-size cell and picks the column count that makes the boxes biggest. Justified fills every row to the edge at one height, as a photo gallery does.

Add
Box
Order
Align

Every box keeps its exact shape, and whatever the container's shape leaves over becomes empty margin, never a crop; Align says where the margin goes. Gap and padding are shares of the box's height here; give the container a width and height and they are pixels. columnGap and rowGap set the two directions apart. Click a box to remove it. Up to six boxes: the search tries every guillotine arrangement. Lattice's collage layout is this strategy.

Five things to try

Each one loads a set into the demo above and shows what the strategy does with it.

Every gutter comes out exact

The Fill a box layout above, as the CSS grid toGrid() hands you. The tracks are fr, so the browser fits the grid to whatever box it has. Each box spans whole tracks and keeps its exact shape, because every width in the tree was solved as a straight line in its height, gutters included.

Try to make it slow

Six boxes is the worst case for tree: every guillotine arrangement of every order. rows takes a list of any length. This runs each 40 times in your browser and reports the median.

First user: Lattice

Two Lattice layouts run on Mosaico, in the command-line export and in the live preview alike.

collage · six photos58 → 9 msMoving the search into Mosaico made it about six times faster.
collage · layouts changed0 of 4,128A golden file pins every layout, byte for byte, to the old packer.
logo-wall · wordmark vs crest3.6× → 2×Beside a crest, wordmarks come down to a badge's area, and no row stands taller.
logo-wall · one shapeunchangedA wall of one mark shape draws exactly as it did.

How it compares

Measured on one machine: median / 95th percentile, in ms. The three solve different jobs, so read each column for what it does.

ItemsMosaico freeMosaico ordereddiorama 2.0.18justified-layout 4.1.0
4 items0.21 / 0.460.04 / 0.270.13 / 0.590.01 / 0.02
6 items8.19 / 12.110.39 / 0.580.43 / 0.980.01 / 0.02
What it doesEvery order, every guillotine arrangement, exact guttersYour order, every arrangement, exact guttersOrdered trees only, no guttersRows only; the height lands wherever it lands

This page runs the real library in your browser. Learn how Mosaico works, and how to use it →