Skip to content

Instantly share code, notes, and snippets.

@valex
Created November 6, 2017 16:16
Show Gist options
  • Save valex/2a9e70cc6f8de5de860b8f80d2acbe9a to your computer and use it in GitHub Desktop.
Save valex/2a9e70cc6f8de5de860b8f80d2acbe9a to your computer and use it in GitHub Desktop.
Tweening interpolator, d3.js version 4
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script src="http://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/d3-selection-multi.v1.min.js"></script>
<script>
var svg = d3.select('body')
.append('svg')
.attrs({
width: 500,
height: 200
});
svg.append('text')
.attrs({ x: 100, y: 50, fill:'black' })
.transition()
.duration(10000)
.tween("mytween", function (d, i) {
var node = this;
return function (t) {
node.textContent = d3.interpolateRound(0, 10)(t);
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment