{
const target = html`<svg id="target" viewBox="0 0 ${width} ${height}">
</svg>`;
const margin = { left: 50, right: 20, top: 20, bottom: 50 },
iwidth = width - margin.left - margin.right,
iheight = height - margin.top - margin.bottom;
const svg = d3.select(target);
const gDrawing = svg
.append("g")
.attr("transform", `translate(${margin.left}, ${margin.top})`);
gDrawing
.append("rect")
.attr("width", iwidth)
.attr("height", iheight)
.attr("fill", "#eee");
const x = d3
.scaleLinear()
.domain([0, d3.max(data, (d) => d.skill_fk_accuracy * 10)])
.range([0, iwidth])
.nice();
const y = d3
.scaleLinear()
.domain([0, d3.max(data, (d) => d.skill_ball_control * 5)])
.range([iheight, 0])
.nice();
const color = d3.scaleOrdinal(d3.schemeAccent);
gDrawing
.append("g")
.attr("class", "x--axis")
.attr("transform", `translate(0, ${iheight})`)
.call(d3.axisBottom(x));
gDrawing.append("g").attr("class", "y--axis").call(d3.axisLeft(y));
const circles = gDrawing
.selectAll("circle")
.data(data)
.join("circle")
.attr("cx", (d) => x(d.skill_fk_accuracy * 10))
.attr("cy", (d) => y(d.skill_ball_control * 5))
.attr("r", 5)
.attr("fill", (d) => color(d.body_type));
gDrawing
.append("text")
.attr("x", iwidth / 2)
.attr("y", iheight + 40)
.attr("text-anchor", "middle")
.text("FK Accuracy");
gDrawing
.append("text")
.attr("x", -(iheight / 2))
.attr("y", -35)
.attr("text-anchor", "middle")
.attr("transform", "rotate(-90)")
.text("Ball Control");
const legend = svg
.append("g")
.attr("class", "legend")
.attr(
"transform",
`translate(${iwidth + margin.left - 100}, ${iheight / 2})`
);
const legendData = Array.from(new Set(data.map((d) => d.body_type)));
legend.append("text").attr("x", 0).attr("y", 0).text("Body Type");
legend
.selectAll("legend-item")
.data(legendData)
.join("g")
.attr("class", "legend-item")
.attr("transform", (d, i) => `translate(0, ${20 * (i + 1)})`)
.each(function (d) {
const g = d3.select(this);
g.append("circle")
.attr("r", 5)
.attr("cx", 0)
.attr("cy", -5)
.attr("fill", color(d));
g.append("text").attr("x", 10).attr("y", 0).attr("dy", "0.32em").text(d);
});
return target;
}