Skip to content

Instantly share code, notes, and snippets.

@awoodruff
Last active September 30, 2019 22:59
Show Gist options
  • Save awoodruff/9166290 to your computer and use it in GitHub Desktop.
Save awoodruff/9166290 to your computer and use it in GitHub Desktop.
State lines
<!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>
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment