Last active
December 19, 2015 14:09
-
-
Save justinjhendrick/5967126 to your computer and use it in GitHub Desktop.
translate0 is null 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"> | |
<title>Zoom + Pan</title> | |
<script src="http://d3js.org/d3.v3.js"></script> | |
<style> | |
.overlay { | |
fill: none; | |
pointer-events: all; | |
} | |
</style> | |
<body> | |
<script> | |
//copied from http://bl.ocks.org/mbostock/3680999. changed the reference to the current version of d3. | |
var width = 960, | |
height = 500; | |
var randomX = d3.random.normal(width / 2, 80), | |
randomY = d3.random.normal(height / 2, 80); | |
var data = d3.range(2000).map(function() { | |
return [ | |
randomX(), | |
randomY() | |
]; | |
}); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height) | |
.append("g") | |
.call(d3.behavior.zoom().scaleExtent([1, 8]).on("zoom", zoom)) | |
.append("g"); | |
svg.append("rect") | |
.attr("class", "overlay") | |
.attr("width", width) | |
.attr("height", height); | |
svg.selectAll("circle") | |
.data(data) | |
.enter().append("circle") | |
.attr("r", 2.5) | |
.attr("transform", function(d) { return "translate(" + d + ")"; }); | |
function zoom() { | |
svg.attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")"); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment