chart = {
const marginTop = 20;
const marginRight = 30;
const marginBottom = 30;
const marginLeft = 40;
const { gap, strokeWidth } = form;
const aspectRatio = width / height;
const numCols = Math.sqrt(totalBricks * aspectRatio);
const numRows = totalBricks / numCols;
const brickWidth = width / numCols;
const brickHeight = height / numRows;
const svg = d3
.create("svg")
.attr("viewBox", [0, 0, width, height])
.attr("width", width)
.attr("height", height)
.attr("style", "max-width: 100%; height: auto;");
const colorScale = d3
.scaleThreshold()
.domain([0, 200, 400, 600])
.range(colorRange);
const rc = rough.svg(svg.node());
for (let i = 0; i < numRows; i++) {
for (let j = 0; j < numCols; j++) {
const xOffset = i % 2 === 0 ? brickWidth / 2 : 0;
if (i % 2 === 0 && j === numCols - 1) {
continue;
}
const node = rc.rectangle(
j * (brickWidth + gap) + xOffset,
i * (brickHeight + gap),
brickWidth,
brickHeight,
{
fill: colorScale(i * numCols + j),
roughness,
hachureAngle: -41,
hachureGap,
strokeWidth,
strokeColor,
fillStyle,
fillWeight
}
);
svg.node().appendChild(node);
}
}
return svg.node();
}