Last active
September 30, 2019 22:59
-
-
Save awoodruff/9166290 to your computer and use it in GitHub Desktop.
State lines
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> | |
<style type="text/css"> | |
#states path { | |
fill: none; | |
} | |
</style> | |
<script src="http://d3js.org/d3.v2.js"></script> | |
<title>Go lines go!</title> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
var projection = d3.geo.azimuthal() | |
.mode("equidistant") | |
.origin([-98, 38]) | |
.scale(1000) | |
.translate([400, 250]); | |
var path = d3.geo.path() | |
.projection(projection); | |
var svg = d3.select("body").append("svg") | |
.attr("width", 900) | |
.attr("height", 500); | |
var states = svg.append("svg:g") | |
.attr("id", "states"); | |
d3.json("/awoodruff/raw/9166290/us-states.json", function(collection) { | |
states.selectAll("path") | |
.data(collection.features) | |
.enter().append("svg:path") | |
.attr("d", path) | |
.attr("stroke",function(){ return "rgb(" + parseInt(Math.random()*255) + "," + parseInt(Math.random()*255) + "," + parseInt(Math.random()*255) + ")"; }) | |
.attr("stroke-dasharray",function(){ return this.getTotalLength() + " " + this.getTotalLength(); }) | |
.each(animate); | |
}); | |
function animate() | |
{ | |
d3.select(this) | |
.attr("stroke-dashoffset",function(){return this.getTotalLength();}) | |
.transition() | |
.ease("linear") | |
.duration(function(){return this.getTotalLength()*10;}) | |
.attr("stroke-dashoffset",function(){return 3*this.getTotalLength();}) | |
.each("end",animate); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment