Skip to content

Instantly share code, notes, and snippets.

@bellentuck
Last active November 9, 2017 21:12
Show Gist options
  • Save bellentuck/c97444761caad7d0156894c1f663f692 to your computer and use it in GitHub Desktop.
Save bellentuck/c97444761caad7d0156894c1f663f692 to your computer and use it in GitHub Desktop.
copyright: mit
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Enter and Exit, Transitions</title>
<script type="text/javascript" src="http://d3js.org/d3.v2.min.js"></script>
</head>
<body>
<h1>Meet Your First Primes!</h1>
<script type="text/javascript" src="index.js"></script>
</body>
</html>
let primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97];
// 1) Update
var p = d3.select("body")
.selectAll("p") // these don't yet exist
.data(primes)
.text(function(d) { return d; });
// 2) Enter
p.enter().append("p")
.text(function(d) { return d; });
// 3) Exit
p.exit().remove();
// d3.select("body")
// .selectAll("p")
// .data([2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97])
// .enter().append("p")
// .text(function(d) { return "I'm the number " + d + ", yay!"; });
d3.select("body").transition()
.duration(7500)
.style("background-color", "blue");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment