svg = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
const g = svg
.append("g")
.attr("class", "gDrawing")
.attr("transform", `translate(${margin.left}, ${margin.top})`);
g.append("g")
.attr("class", "x--axis")
.attr("transform", `translate(0, ${iheight})`)
.call(d3.axisBottom(x))
.call((axis) =>
axis
.append("text")
.text(xAttr)
.style("fill", "black")
.attr("transform", `translate(${iwidth}, -10)`)
.style("text-anchor", "end")
);
g.append("g")
.attr("class", "y--axis")
.call(d3.axisLeft(y))
.call((axis) =>
axis
.append("text")
.text(yAttr)
.style("fill", "black")
.style("text-anchor", "middle")
.attr("y", -15)
);
const legendValues = d3.ticks(
d3.min(playerArray, (d) => d.avgAge),
d3.max(playerArray, (d) => d.avgAge),
5
);
const legend = svg
.append("g")
.attr("transform", `translate(${iwidth + margin.right}, ${margin.top})`);
const legendSizes = [20, 30, 40];
legend
.selectAll("legendCircles")
.data(legendValues)
.join("circle")
.attr("cx", 30)
.attr("cy", (d, i) => i * 30)
.attr("r", 10)
.attr("fill", (d) => colorScale(d))
.attr("stroke", "black")
.attr("opacity", 0.7);
legend
.selectAll("legendLabels")
.data(legendValues)
.join("text")
.attr("x", -55)
.attr("y", (d, i) => i * 30)
.text((d) => `Avg Age: ${Math.round(d)}`)
.style("fill", "black")
.style("font-size", "14px")
.attr("alignment-baseline", "middle");
svg
.append("text")
.attr("x", width / 2)
.attr("y", 20)
.attr("text-anchor", "middle")
.style("font-size", "20px")
.style("font-weight", "bold")
.text("Scatter Plot of Player Data (Size by Avg Age)");
return svg.node();
}