Published
Edited
May 30, 2021
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
palette = getRandomPalette()
Insert cell
d3 = require("d3@6")
Insert cell
Insert cell
//https://observablehq.com/@karlsluis/rotating-polygons
toRadians = (angle) => {
return angle * (Math.PI / 180);
}
Insert cell
// // helper method to make translating easier, via https://observablehq.com/@sjengle/zillow-affordability-heatmap
translate = function(x, y) {
return "translate(" + x + "," + y + ")";
};
Insert cell
array = n => new Array(n).fill(0).map((d, i) => i)
Insert cell
random = (a, b) => {
if(Array.isArray(a)) return a[Math.random() * a.length | 0]
if(!a && a !== 0) return Math.random()
if(!b && b !== 0) return Math.random() * a

if(a > b) [a, b] = [b, a] // swap values
return a + Math.random() * (b - a)
}
Insert cell
randInt = (a, b) => ~~random(a, b)
Insert cell
shuffle = arr => {
let copy = [...arr] // create a copy of original array
for (let i = copy.length - 1; i; i --) {
let randomIndex = randInt(i + 1);
[copy[i], copy[randomIndex]] = [copy[randomIndex], copy[i]] // swap
}
return copy
}
Insert cell
range = (start, end, step = 1) => array(Math.ceil((end - start + 1) / step)).map((d, i) => start + i * step)
Insert cell
import { palettes, scales, getRandomPalette } from '@makio135/give-me-colors'
Insert cell
import {slider} from "@jashkenas/inputs"
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