custom_scatter = {
let svg, x_axis, y_axis, x_label;
if (!this) {
svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
x_axis = svg
.append("g")
.attr("class", "x_axis")
.call(xAxis);
y_axis = svg
.append("g")
.attr("class", "y_axis")
.call(yAxis);
x_label = svg
.append("text")
.attr(
"transform",
`translate(${margin.left +
(x.range()[1] - x.range()[0]) / 2},${height})`
)
.style("text-anchor", "middle")
.text("title");
} else {
svg = d3.select(this);
x_axis = svg.select(".x_axis");
y_axis = svg.select(".y_axis");
}
const chart_data = data.filter(d => d.color < max_color);
const circles = svg
.selectAll("circle")
.data(chart_data, d => d.id)
.join(
enter =>
enter
.append("circle")
.attr("cy", height - margin.bottom)
.attr("cx", d => x(d.x))
.attr("r", 5)
.style("fill", "rgb(73, 141, 201)"),
update => update,
exit =>
exit
.style("fill", "red")
.transition()
.duration(1000)
.delay(d => x(1 - d.x))
.attr("cy", height - margin.bottom)
.remove()
)
.transition()
.duration(1000)
.delay(d => x(d.x))
.attr("cy", d => y(d.y));
return svg.node();
}