Skip to content

Instantly share code, notes, and snippets.

@DavidChouinard
Last active August 29, 2015 14:09
Show Gist options
  • Save DavidChouinard/7ac05be11c384d45e0d5 to your computer and use it in GitHub Desktop.
Save DavidChouinard/7ac05be11c384d45e0d5 to your computer and use it in GitHub Desktop.
Act I: DOM Manipulation
// You'll generally need a local server for requests to work. Run:
// python -m SimpleHTTPServer
var width = 700,
height = 500;
var svg = d3.select("svg")
.attr("width", width)
.attr("height", height);
// The code aboves sets up the basic SVG element required for
// drawing vector graphics in the browser. Real code starts below.
var circle = svg.append("circle");
circle
.attr("cx", 200)
.attr("cy", 200)
.attr("r", 40)
.attr("fill", "steelblue")
.attr("fill-opacity", 0.5);
var circle2 = svg.append("circle");
circle2
.attr("cx", 300)
.attr("cy", 200)
.attr("r", 40)
.attr("fill", "steelblue")
.attr("fill-opacity", 0.5);
circle2.remove();
circle
.transition()
.attr("cx", function() {
return Math.random() * width;
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Data Visualization and D3</title>
<meta content="David Chouinard" name="author" />
<style type="text/css">
html, body {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<svg></svg>
</body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="demo.js"></script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment