image_chart = {
let svg, xAxis, yAxis, title;
if (!this) {
svg = d3
.create("svg")
.attr("width", width)
.attr("height", height);
xAxis = svg.append("g").attr("class", "xaxis");
yAxis = svg.append("g").attr("class", "yaxis");
title = svg
.append("text")
.attr("class", "chart_title")
.attr("transform", `translate(${width / 2},15)`)
.style("text-anchor", "middle");
}
else {
svg = d3.select(this);
xAxis = svg.select(".xaxis");
yAxis = svg.select(".yaxis");
title = svg.select(".chart_title");
}
xAxis.call(xAxisFn);
yAxis.call(yAxisFn);
title.text("Chart title");
const unselected_artists = chart_data.filter(d => d.artist !== artist);
const circles = svg.selectAll("image").data(unselected_artists, d => d.id);
circles
.join("image")
.attr(
"xlink:href",
"https://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/12in-Vinyl-LP-Record-Angle.jpg/440px-12in-Vinyl-LP-Record-Angle.jpg"
)
.attr("width", 10)
.attr("height", 10)
.attr("transform", d => `translate(${x(d.x)}, ${y(d.y)})`);
const selected_artist_data = chart_data.filter(d => d.artist == artist);
const rects = svg.selectAll("rect").data(selected_artist_data);
rects
.join("rect")
.attr("x", d => x(d.x) - size / 2)
.attr("y", d => y(d.y) - size / 2)
.transition()
.duration(500)
.attr("width", size)
.attr("height", size);
return svg.node();
}