Skip to content

Instantly share code, notes, and snippets.

@russelllim22
Created September 4, 2021 22:23
Show Gist options
  • Save russelllim22/28efccb175c20d71bbc3fabd2e387a07 to your computer and use it in GitHub Desktop.
Save russelllim22/28efccb175c20d71bbc3fabd2e387a07 to your computer and use it in GitHub Desktop.
let xVar = document.getElementById("select-x-var").value;
document.getElementById("select-x-var").addEventListener("change", (e)=>{
// update the x-variable based on the user selection
xVar = e.target.value
// rescale the x-axis
xScale = d3.scaleLinear()
.domain([0, d3.max(articleData, d => d[xVar]) ])
.range([0, 600]);
// redraw the x-axis
svg.select("#xAxis")
.call(d3.axisBottom(xScale))
// transition each circle element
svg.selectAll(".bubble")
.transition()
.duration(1000)
.attr("cx", (d) => xScale(d[xVar]) )
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment