Public
Edited
Insert cell
Insert cell
value = (x,y) => Math.sin(x + y) * Math.sin(x - y);
Insert cell
chart ={
const context = DOM.context2d(width, height);
const path = d3.geoPath(null, context);
context.scale(width / (grid.n - 10), width / (grid.n - 10));
while(true){
const dv = (Date.now() % 1000) / 1000 * 0.2;
for (const v of thresholds){
context.beginPath();
path(contours.contour(grid, v + dv));
context.fillStyle = color(v + dv);
context.fill();
}
yield context.canvas;
}
}
Insert cell
color = d3.scaleSequential([-1, 1], d3.interpolateSpectral)
Insert cell
thresholds = Array.from({length: 11}, (_,i) => (i - 6)/ 5)
Insert cell
grid = {
const x0 = -q / 2, x1 = width + q;
const y0 = -q / 2, y1 = height + q;
const n = Math.ceil((x1 - x0) / q);
const m = Math.ceil((y1 - y0) / q);
const grid = new Array(n * m);
for(let j = 0; j < m; ++j){
for (let i = 0; i < n; ++i){
grid[j * n + i] = value(i * q* scale, j * q * scale);
}
}
grid.n = n;
grid.m = m;
return grid;
}
Insert cell
contours = d3.contours().size([grid.n, grid.m])
Insert cell
q = 6// The level of detail, e.g., sample every 4 pixels in x and y.
Insert cell
scale = 1/ 80
Insert cell
height= 600
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more