Published
Edited
Nov 27, 2018
Insert cell
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewConfig = ({
focusedNode: root,
zoom: null
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function zoomTo(v) {
var k = diameter / v[2];
viewConfig.zoom = v;
node.attr("transform", function(d) { return "translate(" + (d.x - v[0]) * k + "," + (d.y - v[1]) * k + ")"; });
circle.attr("r", function(d) { return d.r * k; });
}
Insert cell
function zoom(focusedNode) {
viewConfig.focusedNode = focusedNode;

let transition = d3.transition()
.duration(d3.event.altKey ? 7500 : 750)
.tween("zoom", function(d) {
var i = d3.interpolateZoom(viewConfig.zoom, [focusedNode.x, focusedNode.y, focusedNode.r * 2 + viewConfig.margin]);
return function(t) { zoomTo(i(t)); };
});

transition.selectAll("text")
.filter(function(d) { return d.parent === focus || this.style.display === "inline"; })
.style("fill-opacity", function(d) { return d.parent === focus ? 1 : 0; })
.on("start", function(d) { if (d.parent === focus) this.style.display = "inline"; })
.on("end", function(d) { if (d.parent !== focus) this.style.display = "none"; });
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
//zoomTo([root.x, root.y, root.r * 2 + margin])
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