Published
Edited
Apr 28, 2022
2 stars
Insert cell
Insert cell
canvas = {
const context = DOM.context2d(width, height)
context.fillStyle = 'hsl(216deg 100% 13%)'
context.fillRect(0, 0, width, height)

context.globalCompositeOperation = 'lighter'
const minY = 0
const maxY = 300

const binPxSize = 2
const binSize = binPxSize / width * data.length
for (let i = 0; i < width; i += 1) {
const start = Math.floor(binSize * i)
const end = Math.floor(binSize * (i + 1))
const vals = data.slice(start, end)
vals.sort((a, b) => a - b)
while (vals.length > 1) {
const bottom = vals.shift()
const top = vals.pop()
const x1 = i * binPxSize
const y1 = lerp(bottom, minY, maxY, height, 0)
const y2 = lerp(top, minY, maxY, height, 0)
context.fillStyle = 'rgba(255, 255, 255, 0.03)'
context.fillRect(x1, y1, binPxSize, y2 - y1)
}
}
return context.canvas
}
Insert cell
height = 200
Insert cell
width = 400
Insert cell
Insert cell
Insert cell
Insert cell
import {octave, perlin2} from "@mbostock/perlin-noise"
Insert cell
noise = octave(perlin2, 3)
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