Published
Edited
Jul 4, 2022
5 forks
Importers
18 stars
Also listed in…
d3-geo
Insert cell
Insert cell
canvas = {
const context = DOM.context2d(width, height);
const projection = d3.geoIdentity().scale(width / n);
const path = d3.geoPath(projection, context);
context.lineWidth = 2;
context.lineJoin = "round";
context.strokeStyle = "magenta";
for (let t = 0, T = 240; true; t = (t + 1) % T) {
context.drawImage(image, 0, 0, width, height);
context.beginPath();
path(contours.contour(values, t / T));
context.stroke();
yield context.canvas;
}
}
Insert cell
contours = d3.contours().size([n, m])
Insert cell
m = image.naturalHeight
Insert cell
n = image.naturalWidth
Insert cell
values = {
const canvas = document.createElement("canvas");
canvas.width = n;
canvas.height = m;
const context = canvas.getContext("2d");
context.drawImage(image, 0, 0);
const data = context.getImageData(0, 0, n, m);
const values = new Float64Array(n * m);
for (let j = 0, k = 0; j < m; ++j) {
for (let i = 0; i < n; ++i, ++k) {
values[k] = data.data[k << 2] / 255;
}
}
return d3.blur2({data: values, width: n}, 3).data;
}
Insert cell
image = Object.assign(await FileAttachment("cloud-fraction.png").image(), {style: "max-height: 33px; display: block;"})
Insert cell
height = Math.ceil(width / 2)
Insert cell
d3 = require("d3@7.6.0/dist/d3.min.js") // d3.blur was introduced in d3-array@3.2 and d3@7.6
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