chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
let previousS0, previousS1;
const brush = d3
.brushX()
.extent([
[margin.left, margin.top],
[width - margin.right, height - margin.bottom]
])
.on("start brush end", brushed);
const circle = svg
.append("g")
.attr("fill-opacity", 0.2)
.selectAll("circle")
.data(Float64Array.from({ length: 800 }, Math.random))
.join("circle")
.attr("transform", (d) => `translate(${x(d)},${y()})`)
.attr("r", 3.5);
svg.append("g").call(xAxis);
let brushGroup = svg
.append("g")
.call(brush)
.call(brush.move, [0.3, 0.5].map(x));
function brushed({ selection }) {
if (selection === null) {
circle.attr("stroke", null);
} else {
const sx = selection.map(x.invert);
}
var s = selection || x.range();
if (((s[1] - s[0]) / width) * 100 > 50) {
console.log("run");
brushGroup.call(brush.move, [previousS0, previousS1]);
return;
}
previousS0 = s[0];
previousS1 = s[1];
}
return svg.node();
}