Skip to content

Instantly share code, notes, and snippets.

<svg :width="width" :height="height">
<g v-for="rectangle in rectangles" fill="grey">
<rect
:x=rectangle[0]
:y=rectangle[1]
:width=rectangle[2]
:height=rectangle[3]
style="stroke-width:1;stroke:white"/>
<text
:x="rectangle[0] + rectangle[2] / 2"
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)) {
@clementbat
clementbat / treemap-svg.html
Created February 26, 2019 11:28
treemap svg
<svg width="600" height="400">
<rect x="0" y="0" width="300" height="200"/>
<rect x="0" y="200" width="300" height="200"/>
</svg>
@clementbat
clementbat / treemap-algorithm
Created February 26, 2019 11:13
treemap algorithm
procedure squarify(list of real children, list of real row,real w)
begin
real c = head(children);
if worst(row, w) ≤ worst(row++[c], w) then
squarify(tail(children), row++[c], w)
else
layoutrow(row);
squarify(children, [], width());
fi
end