{
root.sum(function (d) {
return +d.strength_before;
});
d3.treemap().size([width, height]).padding(0)(root);
svg.selectAll("rect").remove();
svg
.selectAll("rect")
.data(root.leaves())
.enter()
.append("rect")
.attr("x", function (d) {
return d.x0;
})
.attr("y", function (d) {
return d.y0;
})
.attr("width", function (d) {
return d.x1 - d.x0;
})
.attr("height", function (d) {
return d.y1 - d.y0;
})
.style("fill", (d) => {
let h = (Math.random() - 0.5) * 80;
let s = (Math.random() - 0.5) * 30;
let l = (Math.random() - 0.5) * 30;
return `hsl(${200 + h}, ${20 + s}%, ${50 + l}%)`;
})
.style("stroke", (d) => {
if (d.id == unit) {
return "#ffffff";
} else {
return false;
}
})
.on("mouseover", function (el, d) {
console.log(d.id);
});
}