in src/heatmap.ts [182:207]
private updateCircles(container, points: Example2D[]) {
// Keep only points that are inside the bounds.
let xDomain = this.xScale.domain();
let yDomain = this.yScale.domain();
points = points.filter(p => {
return p.x >= xDomain[0] && p.x <= xDomain[1]
&& p.y >= yDomain[0] && p.y <= yDomain[1];
});
// Attach data to initially empty selection.
let selection = container.selectAll("circle").data(points);
// Insert elements to match length of points array.
selection.enter().append("circle").attr("r", 3);
// Update points to be in the correct position.
selection
.attr({
cx: (d: Example2D) => this.xScale(d.x),
cy: (d: Example2D) => this.yScale(d.y),
})
.style("fill", d => this.color(d.label));
// Remove points if the length has gone down.
selection.exit().remove();
}