A series of related examples:
- Canvas geometric zooming
- Canvas semantic zooming
- SVG geometric zooming
- SVG semantic zooming
Using newer version of d3 and measuring fps (disabled since inaccurate).
A series of related examples:
Using newer version of d3 and measuring fps (disabled since inaccurate).
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<title>Zoom + Pan</title> | |
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> | |
<script src="http://graspingmath.com/libs/css-fpsmeter.js"></script> | |
<style> | |
.overlay { | |
fill: none; | |
pointer-events: all; | |
} | |
</style> | |
<body> | |
<!--<div id="fps"></div>--> | |
<script> | |
//// measure fps using css transitions | |
//var fps_el = document.getElementById("fps"); | |
//document.addEventListener('fps', function(evt) { fps_el.innerHTML = evt.fps + " fps"}, false); | |
//FPSMeter.run(0.5); | |
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> |