{
const svg = d3
.create("svg")
.attr("width", figWidth)
.attr("viewBox", [0, 0, figWidth, figHeight]);
const g = svg
.append("g")
.attr("transform", `translate(${margin.left}, ${margin.top})`);
svg
.append("text")
.text("Footballers' sizes, preferred foot, & overall rating.")
.attr("transform", `translate(${iwidth / 2}, 15)`)
.attr("text-anchor", "middle")
.style("font-size", "1.2em")
.style("font-weight", "bold");
const minisData = [
{ row: 0, col: 0, data: players90, title: "Rating 90-100" },
{ row: 0, col: 1, data: players80, title: "Rating 80-89" },
{ row: 1, col: 0, data: players70, title: "Rating 70-79" },
{ row: 1, col: 1, data: players60, title: "Rating 60-69" },
{ row: 2, col: 0, data: playersOther, title: "Rating 0-59" }
];
const minis = g
.selectAll("g.chart")
.data(minisData)
.join("g")
.attr("class", "chart")
.attr(
"transform",
(d) => `translate(${chartCol(d.col)}, ${chartRow(d.row)})`
);
minis
.append("rect")
.attr("fill", "#eee")
.attr("width", chartCol.bandwidth())
.attr("height", chartRow.bandwidth());
minis
.append("text")
.text((g) => g.title)
.attr("transform", (g) => `translate(${chartCol.bandwidth() / 2}, -5)`)
.style("font-weight", "bold")
.style("text-anchor", "middle")
.style("font-size", "10pt");
minis
.selectAll("circle")
.data((g) => g.data)
.join("circle")
.attr("cx", (p) => x(p.height_cm))
.attr("cy", (p) => y(p.weight_kg))
.attr("r", 2)
.attr("fill", (p) => color(p.preferred_foot));
g.select("g.chart")
.append("text")
.text("↑ Height (cm)")
.attr("transform", `translate(-25, -10)`)
.attr("text-anchor", "start")
.style("font-weight", "bold")
.style("font-size", "8pt");
g.select("g.chart")
.append("text")
.text("Weight (kg) →")
.attr(
"transform",
`translate(${chartCol.bandwidth()}, ${chartRow.bandwidth() + 30})`
)
.attr("text-anchor", "end")
.style("font-weight", "bold")
.style("font-size", "8pt");
minis
.append("g")
.attr("class", "x-axis")
.attr("transform", `translate(0, ${chartRow.bandwidth()})`)
.call(d3.axisBottom(x));
minis.append("g").attr("class", "y-axis").call(d3.axisLeft(y));
return svg.node();
}