Skip to content

Instantly share code, notes, and snippets.

@clementbat
Last active April 8, 2020 23:03
Show Gist options
  • Save clementbat/9d810a2ca9cdbfd86a5acd0b23e28ce3 to your computer and use it in GitHub Desktop.
Save clementbat/9d810a2ca9cdbfd86a5acd0b23e28ce3 to your computer and use it in GitHub Desktop.
function squarify (children, row, width) {
if (children.length === 1) {
layoutLastRow(row, children, width)
return
}
const rowWithChild = [...row, children[0]]
if (row.length === 0 || worst(row, width) >= worst(rowWithChild, width)) {
children.shift()
squarify(children, rowWithChild, width)
} else {
layoutRow(row, width)
squarify(children, [], getMinWidth().width)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment