Published
Edited
Jul 7, 2022
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
polarfunction = (r,theta) => r**2 * Math.cos(2 * theta) * Math.sin(2 * theta)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
grid = {
const q = .25; // The level of detail, e.g., sample every 4 pixels in x and y.
const x0 = -q / 2, x1 = width + q; //The coordinates corresponding to the Math. q is the step.
const y0 = -q / 2, y1 = height + q; //The coordinates cooresponding to the Math. q is the step.
const n = Math.ceil((x1 - x0) / q); //Number of grid points in the x axis
const m = Math.ceil((y1 - y0) / q); // Number of points in the y axis
const grid = new Array(n * m); // An array that fits the total number of points.
for (let j = 0; j < m; ++j) {
for (let i = 0; i < n; ++i) {
let ivalue = xscale.invert(i * q + x0) //xscale must be set to the range of values you want the xscale to traverse
let jvalue = yscale.invert(j * q + y0) //yscale must be set to the range of value you want the yscale to go 0,2pi
grid[j * n + i] = cart(jvalue,ivalue,polarfunction,radius); //Takes the grid point and
}
}
grid.x = -q;
grid.y = -q;
grid.k = q;
grid.n = n;
grid.m = m;
return grid;
}
Insert cell
Insert cell
contours = d3.contours()
.size([grid.n, grid.m])
.thresholds(thresholds)
(grid)
.map(transform)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import {Legend} from "@d3/color-legend"
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