Published
Edited
Mar 30, 2020
Fork of Zoom (SVG)
1 fork
Insert cell
Insert cell
chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);

const g = svg.append("g");

g.append("image").attr("xlink:href","https://chriszrc.static.observableusercontent.com/files/639090a84b8c9f0ea239a78cf06646af7fcc61573b4527b0598825ab135a83696036383f9d13318b012536d88f27711b5401352552cc667ec38f0da7d3ee03c0?response-content-disposition=attachment%3Bfilename*%3DUTF-8%27%27london.png&Expires=1585656000000&Key-Pair-Id=APKAJCHFJLLLU4Y2WVSQ&Signature=ctkvd2jSCc6nQxlJ0Zg2TDqQ3EdOK-yPiPI0mxWvC0UY~5SxC-r2yLpGru-OIjWPD-DFYL5RbzAy6etv9q64dYX1JhXQkiHFUT-wwxCdrWacxiCaYsrPyFWnRuCWYinA9s139WvU3gD55hw8wZlzdVW7AO~YttvNgFapQrO7GN6YGCTfjWGkaxDHDR2OR6uasqeLkHHEe2kR~kBaN6Njo6eYr97uahika10RpkFIW-dMk~C2V2rciZ11gqV83olDFL185poTGUAr92gi10ALnolS5OL2Ext4WADaGM2hUtPeRevFPnE2Tm0hwm9Hv-f2EQt7EzM9Tvjs05cRoNpAdg__")
.attr("height",height)
.attr("width",width)
;

svg.call(d3.zoom()
.extent([[0, 0], [width, height]])
.scaleExtent([1, 8])
.on("zoom", zoomed));

function zoomed() {
g.attr("transform", d3.event.transform);
}

return svg.node();
}
Insert cell
height = 600
Insert cell
data = {
const randomX = d3.randomNormal(width / 2, 80);
const randomY = d3.randomNormal(height / 2, 80);
return Array.from({length: 2000}, () => [randomX(), randomY()]);
}
Insert cell
d3 = require("d3@5")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more