A series of related examples:
- Canvas geometric zooming
- Canvas semantic zooming
- SVG geometric zooming
- SVG semantic zooming
license: gpl-3.0 |
A series of related examples:
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<svg width="960" height="500"></svg> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script> | |
var svg = d3.select("svg"), | |
width = +svg.attr("width"), | |
height = +svg.attr("height"); | |
var randomX = d3.randomNormal(width / 2, 80), | |
randomY = d3.randomNormal(height / 2, 80), | |
data = d3.range(2000).map(function() { return [randomX(), randomY()]; }); | |
var g = svg.append("g"); | |
var circle = g.selectAll("circle") | |
.data(data) | |
.enter().append("circle") | |
.attr("r", 2.5) | |
.attr("transform", function(d) { return "translate(" + d + ")"; }); | |
svg.append("rect") | |
.attr("fill", "none") | |
.attr("pointer-events", "all") | |
.attr("width", width) | |
.attr("height", height) | |
.call(d3.zoom() | |
.scaleExtent([1, 8]) | |
.on("zoom", zoom)); | |
function zoom() { | |
g.attr("transform", d3.event.transform); | |
} | |
</script> |