Public
Edited
Dec 28, 2023
1 fork
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";

context.drawImage(image, 0, 0, width, height);
context.beginPath();

path(contours.contour(values, 0.01));

context.stroke();
return context.canvas;
}
Insert cell
3 << 2
Insert cell
contours.contour(values, 0.01)
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);

console.log("data", data);

let colors = {};

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 values;

return d3.blur2({ data: values, width: n }, 1).data;
}
Insert cell
contours = d3.contours().size([n, m]).smooth(true).thresholds(20)
Insert cell
m = image.naturalHeight
Insert cell
n = image.naturalWidth
Insert cell
image = Object.assign(
await FileAttachment("20230926_18_F30_wafs_300_wspd_m.png").image(),
{ style: "max-height: 33px; display: block;" }
)
Insert cell
height = 600
Insert cell
width=900
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