Last active
June 7, 2018 06:59
-
-
Save nicmcd/6bdd0aef5880964bd37c7603b1e55fc0 to your computer and use it in GitHub Desktop.
D3 zoom problem (NOT fixed)
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> | |
body, html { | |
width: 100%; | |
height: 100%; | |
margin: 0; | |
} | |
svg { | |
position: absolute; | |
top: 0; | |
left: 0; | |
} | |
</style> | |
<script type="text/javascript" src="http://d3js.org/d3.v5.js"></script> | |
<script type="text/javascript"> | |
function load() { | |
var svg = d3.select("body") | |
.append("svg") | |
.attr("width", "100%") | |
.attr("height", "100%"); | |
var zoom = d3.zoom().on("zoom", function() { | |
d3.select("#vis").attr("transform", d3.event.transform); | |
}); | |
var vis = svg.call(zoom).append("g").attr("id", "vis"); | |
d3.select("body").on("keypress", function() { | |
if (d3.event.shiftKey) { | |
if (d3.event.key == "R") { | |
vis.transition().duration(500).call(zoom.transform, d3.zoomIdentity); | |
} | |
} | |
}); | |
vis.append("rect") | |
.attr("x", 10) | |
.attr("y", 10) | |
.attr("width", 100) | |
.attr("height", 100); | |
} | |
</script> | |
</head> | |
<body onload="load()"> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment