{
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
const lastname = function(d) {
const split = d.toLowerCase().split(' ');
return split[split.length - 1]
}
svg
.selectAll("anything")
.data(students)
.enter()
.append("clipPath")
.attr("id", d => lastname(d.name))
.append("circle")
.attr("id", d => d.name)
.attr("r", 20)
.attr("cx", d => x(d.var1))
.attr("cy", d => y(d.var2));
svg
.append("g")
.selectAll('image')
.data(students)
.join('image')
.attr('href', d => d.img)
.attr("x", d => x(d.var1) - 25)
.attr('y', d => y(d.var2) - 25)
.attr('width', 50)
.attr('height', 50)
.attr(
'clip-path',
d =>
`url(#${lastname(d.name)})`
)
.attr('preserveAspectRatio', "xMidYMin slice");
svg
.append("g")
.selectAll("text")
.data(students)
.join("text")
.attr("dy", "0.35em")
.attr("x", d => x(d.var1))
.attr("y", d => y(d.var2) - 28)
.attr("font-family", "sans-serif")
.attr("font-size", 12)
.attr("font-weight", "bold")
.attr("text-anchor", "middle")
.text(d => d.name.split(' ')[0]);
svg.append("g").call(xAxis);
svg.append("g").call(yAxis);
return svg.node();
}