{
const svg = d3.create("svg").style("border", "1px solid black");
const sWidth = 300;
const sHeight = 300;
const padding = 30;
svg.attr("height", sHeight).attr("width", sWidth);
const xScale = d3
.scaleLog()
.domain(d3.extent(near_earth, (d) => parseFloat(d.q_au_1)))
.range([padding, sWidth - padding]);
const yScale = d3
.scaleLog()
.domain(d3.extent(near_earth, (d) => parseFloat(d.q_au_2)))
.range([sHeight - padding, padding]);
yield svg.node();
var myCircles = svg
.append("g")
.attr("id", "circleGroup")
.selectAll("circle")
.data(near_earth)
.enter()
.append("circle")
.attr("cx", (d, i) => xScale(parseFloat(d.q_au_1)))
.attr("cy", (d, i) => yScale(parseFloat(d.q_au_2)))
.attr("r", 5)
.style("fill", "blue");
svg
.append("g")
.call(d3.axisBottom(xScale))
.attr("transform", "translate(0, " + (sHeight - padding) + ")");
svg
.append("g")
.call(d3.axisLeft(yScale))
.attr("transform", "translate(" + padding + ",0)");
var brush = d3
.brush()
.extent([
[padding, padding],
[sWidth - padding, sHeight - padding]
])
.on("brush", (event) => {
const newBoundsX = [
xScale.invert(event.selection[0][0]),
xScale.invert(event.selection[1][0])
];
const newBoundsY = [
yScale.invert(event.selection[1][1]),
yScale.invert(event.selection[0][1])
];
myCircles.style("fill", "blue");
myCircles
.filter(
(d) =>
parseFloat(d.q_au_1) >= newBoundsX[0] &&
parseFloat(d.q_au_1) <= newBoundsX[1] &&
parseFloat(d.q_au_2) >= newBoundsY[0] &&
parseFloat(d.q_au_2) <= newBoundsY[1]
)
.transition()
.duration(0)
.style("fill", "black");
});
svg.append("g").attr("class", "brush").call(brush);
}