Skip to content

Instantly share code, notes, and snippets.

@curran
Last active February 21, 2017 11:01
Show Gist options
  • Save curran/d406e6f18ceb49f47c9376605f85be74 to your computer and use it in GitHub Desktop.
Save curran/d406e6f18ceb49f47c9376605f85be74 to your computer and use it in GitHub Desktop.
[UNLISTED] Using Merge
license: mit
<!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