Skip to content

Instantly share code, notes, and snippets.

@alfmoh
Last active May 13, 2019 18:04
Show Gist options
  • Select an option

  • Save alfmoh/fb673f4b02227e37fcedd2aa26b1ea51 to your computer and use it in GitHub Desktop.

Select an option

Save alfmoh/fb673f4b02227e37fcedd2aa26b1ea51 to your computer and use it in GitHub Desktop.
circles
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<script>
console.clear();
// Feel free to change or delete any of the code you see in this editor!
var svg = d3.select("body").append("svg")
.attr("width", 960)
.attr("height", 500)
const dataset = [1,2,3,9,5,15];
const scale = d3.scaleLinear()
.domain(dataset)
.range([10,50]);
const colorScale = d3.scaleQuantile()
.domain(dataset)
.range(["red","blue"])
svg.selectAll("circle")
.data(dataset)
.enter()
.append("circle")
.attr("r",1)
.attr("cy",500)
.attr("cx",(d,i)=>scale(d))
.transition()
.delay(d=>d*200)
.duration(1000)
.attr("r",(d,i)=>d)
.attr("cx",(d,i)=>scale(d))
.attr("cy",(d,i)=>i*50)
.style("fill",d=>colorScale(d))
.transition()
// .delay(d=>d*20)
.duration(1000)
.attr("r",(d,i)=>d*5)
.style("fill","pink")
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment