viewof chart = {
replay;
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
.attr("font-size", "1.5em");
const brush = d3.brush()
.extent([[margin.left, margin.top], [width - margin.right, height - margin.bottom]])
.on("start brush end", brushed);
const circle = svg.append("g")
.selectAll("circle")
.data(data)
.join("circle")
.attr("transform", d => `translate(${x(d[0])},${y(d[1])})`)
.attr("r", 2);
svg.append("g")
.call(yAxis);
svg.append("g")
.call(xAxis);
svg.append("text")
.attr("text-anchor", "start")
.attr("font-family", "sans-serif")
.attr("font-size", ".75em")
.attr("x", margin.left)
.attr("y", margin.top)
.attr("dx", "2em")
.attr("dy", ".5em")
.text("magnitude")
svg.append("text")
.attr("text-anchor", "start")
.attr("font-family", "sans-serif")
.attr("font-size", ".75em")
.attr("x", width - margin.right)
.attr("y", height - margin.bottom)
.attr("dx", "-4em")
.attr("dy", "-.5em")
.text("depth (km)")
svg.append("g")
.call(brush)
.call(brush.move, [[x0 - dx / 2, y1], [x0 + dx / 2, y0]])
.call(g => g.select(".overlay")
.datum({type: "selection"})
.on("mousedown touchstart", beforebrushstarted))
.transition()
.ease(d3.easeLinear)
.delay(500)
.duration(5000)
.call(brush.move, [[x1, y1], [x1 + dx, y0]])
function beforebrushstarted(event) {
d3.select(this.parentNode).call(brush.clear)
svg.node().value = [null, null, data];
svg.node().dispatchEvent(new CustomEvent("input"));
}
function brushed(event) {
const selection = event.selection;
if (selection === null) {
} else {
const [[a0, b0], [a1, b1]] = selection;
const [x0, x1] = [a0, a1].map(x.invert);
const [y0, y1] = [b0, b1].map(y.invert);
circle.attr("stroke", d => x0 <= d[0] && d[0] <= x1 && d[1] <= y0 && y1 <= d[1] ? "red" : null);
let a = circle
.filter(d => x0 <= d[0] && d[0] <= x1 && d[1] <= y0 && y1 <= d[1])
.attr("stroke", "red")
.data()
.map(d => d[2]);
svg.node().value = [[x0, y0], [x1, y1], a];
svg.node().dispatchEvent(new CustomEvent("input"));
}
}
return svg.node();
}