Skip to content

Instantly share code, notes, and snippets.

@tomshanley
Last active January 30, 2020 01:45
Show Gist options
  • Save tomshanley/4683d21075d1d1015b7d2833b4154139 to your computer and use it in GitHub Desktop.
Save tomshanley/4683d21075d1d1015b7d2833b4154139 to your computer and use it in GitHub Desktop.
ease delay
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()
function delayEase(t, e) {
// the polyInOut function from d3.ease
// https://github.com/d3/d3-ease/blob/master/src/poly.js
return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
}
let exp = 0.5 // see https://github.com/d3/d3-ease/blob/master/src/poly.js#L27
let arr = [0,1,2,3,4,5,6,7]
let len = arr.length
let svg = d3.select("body").append("svg")
.attr("width", 1000)
.attr("height", 500)
let circles = svg.selectAll("circle")
.data(arr)
.enter()
.append("circle")
.attr("cx", d => (d * 40) + 40)
.attr("cy", 50)
.attr("r", 10)
.style("fill", "black")
circles.transition()
.duration(5000)
.delay(function(d,i) {
let delay = 5000 * (delayEase((i/len), exp))
console.log(delay)
return delay
})
.attr("cy", 450)
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment