-
-
Save mbostock/580de8199ea3b85f822a to your computer and use it in GitHub Desktop.
Point Reordering Bug
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> | |
<meta charset="utf-8"> | |
<style> | |
path { | |
fill: none; | |
stroke: #777; | |
marker: url(#marker); | |
} | |
</style> | |
<body> | |
<button type="button" id="change">Change</button> | |
<script src="//d3js.org/d3.v3.min.js"></script> | |
<script src="//d3js.org/topojson.v1.min.js"></script> | |
<script> | |
var width = 960, | |
height = 500; | |
var projection0 = d3.geo.mercator() | |
.center([-97, 37]) | |
.scale(4000 / 2 / Math.PI) | |
.translate([width / 2, height / 2]) | |
.precision(0); | |
var projection1 = d3.geo.albers() | |
.precision(0); | |
var path = d3.geo.path() | |
.projection(projection0); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
svg.append("defs").append("marker") | |
.attr("id", "marker") | |
.attr("viewBox", "0 0 10 10") | |
.attr("refX", 5) | |
.attr("refY", 5) | |
.attr("markerUnits", "strokeWidth") | |
.attr("markerWidth", 10) | |
.attr("markerHeight", 10) | |
.append("circle") | |
.style("fill", "#ccc") | |
.style("stroke", "#333") | |
.style("stroke-opacity", .5) | |
.attr("cx", 5) | |
.attr("cy", 5) | |
.attr("r", 3); | |
d3.json("/mbostock/raw/4090846/us.json", function(error, us) { | |
if (error) throw error; | |
var states = svg.append("path") | |
.datum(topojson.feature(us, us.objects.states).features[6]) | |
.attr("d", path); | |
d3.select("#change").on("click", function() { | |
states.transition() | |
.duration(1000) | |
.attr("d", path.projection(path.projection() === projection1 ? projection0 : projection1)); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment