Built with blockbuilder.org
Last active
February 21, 2017 11:01
-
-
Save curran/d406e6f18ceb49f47c9376605f85be74 to your computer and use it in GitHub Desktop.
[UNLISTED] Using Merge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Using Merge</title> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
</head> | |
<body> | |
<svg width="960" height="500"></svg> | |
<script> | |
var svg = d3.select("svg"); | |
function render(data){ | |
var circles = svg | |
.selectAll("circle").data(data); | |
circles | |
.enter().append("circle") | |
.attr("cy", 250) | |
.attr("r", 100) | |
.merge(circles) | |
.attr("cx", function (d){ return d; }); | |
circles.exit().remove(); | |
} | |
setTimeout(function (){ render([300, 500, 700]); }, 1000); | |
setTimeout(function (){ render([350, 600]); }, 2000); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment