{
const width = 800;
const height = 600;
const margin = {top: 40, right: 40, bottom: 40, left: 40};
const colors = ["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b"];
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height)
.attr("viewBox", [0, 0, width, height]);
const gridCols = 3;
const cellWidth = (width - margin.left - margin.right) / gridCols;
const cellHeight = 200;
svg.selectAll("rect")
.data(data)
.join("rect")
.attr("x", (d, i) => margin.left + (i % gridCols) * cellWidth)
.attr("y", (d, i) => margin.top + Math.floor(i / gridCols) * cellHeight)
.attr("width", d => d.footprint * 150)
.attr("height", d => d.footprint * 150)
.attr("fill", (d, i) => colors[i])
.attr("stroke", "#333")
.attr("stroke-width", 1);
svg.selectAll(".title")
.data(data)
.join("text")
.attr("class", "title")
.attr("x", (d, i) => margin.left + (i % gridCols) * cellWidth + d.footprint * 150 - 10)
.attr("y", (d, i) => margin.top + Math.floor(i / gridCols) * cellHeight + 25)
.attr("text-anchor", "end")
.text(d => d.fname.toUpperCase())
.attr("font-size", "12px")
.attr("font-weight", "bold");
svg.selectAll(".value")
.data(data)
.join("text")
.attr("class", "value")
.attr("x", (d, i) => margin.left + (i % gridCols) * cellWidth + d.footprint * 150 - 10)
.attr("y", (d, i) => margin.top + Math.floor(i / gridCols) * cellHeight + 45)
.attr("text-anchor", "end")
.text(d => `${d.footprint} hectares`)
.attr("font-size", "10px");
return svg.node();
}