Public
Edited
Feb 10, 2021
1 fork
28 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
mutable transform = d3.zoomIdentity
Insert cell
zoom = d3.zoom().scaleExtent([1, 150])
Insert cell
zoomed = ({ transform }) => {
mutable transform = transform;
let chart = viewof chart.value;
chart.density
.xDomain(transform.rescaleX(xScale).domain())
.yDomain(transform.rescaleY(yScale).domain());
chart.update(xs);
}
Insert cell
{
// Set up the initial zoom transform without triggering the zoom event
chart.canvas.__zoom = mutable transform;

// Attach the zoom transform to the canvas element
d3.select(viewof chart.value.canvas).call(zoom.on("zoom.zoomed", zoomed));

invalidation.then(() => zoom.on("zoom.zoomed", null));
}
Insert cell
xScale = d3.scaleLinear(xDomain, [0, size])
Insert cell
yScale = d3.scaleLinear(yDomain, [size, 0])
Insert cell
// cacheInterpolator speeds up colorization by returning cached {r, g, b} objects
interpolator = cacheInterpolator(d3.interpolateBlues)
Insert cell
size = Math.min(width, 500)
Insert cell
xDomain = [-2.5, 2.5]
Insert cell
yDomain = [-2.5, 2.5]
Insert cell
xs = X.subarray(0, numPoints)
Insert cell
ys = Y.subarray(0, numPoints)
Insert cell
X = Float64Array.from({ length: maxPoints }, rand)
Insert cell
Y = Float64Array.from({ length: maxPoints }, rand)
Insert cell
maxPoints = 1e6
Insert cell
rand = d3.randomNormal(0, 0.75) // Sample coordinates from a normal distribution
Insert cell
d3 = require('d3@6')
Insert cell
comma = d3.format(',')
Insert cell
import { slider } from '@jashkenas/inputs'
Insert cell
import { legend } from '@d3/color-legend'
Insert cell
import {
densityPlot,
pointDensity,
cacheInterpolator
} from '@twitter/density-plot@4159'
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