Published
Edited
Nov 12, 2020
2 stars
Insert cell
Insert cell
Insert cell
{
const context = DOM.context2d(500, 500);
const line = d3
.line()
.x(d => 100 + 300 * d[0])
.y(d => 400 - 300 * d[1])
.context(context);

context.beginPath();
line(d3.zip(d3.quantize(t => t, 200), d3.quantize(scalek, 200)));
context.stroke();

return context.canvas;
}
Insert cell
// f(k) is its own inverse
f = k => x => Math.pow(1 - Math.pow(x, k), 1 / k)
Insert cell
fk = f(k)
Insert cell
scalek = d3.piecewise((a, b) => t => b + (a - b) * fk(t), [0, 1])
Insert cell
scalek(0.5)
Insert cell
d3.quantize(scalek, 20)
Insert cell
d3.quantize(t => t, 20)
Insert cell
piecewiseNumber = d3.piecewise(d3.interpolateRound, [0, 1, 10, 100, 1000])
Insert cell
d3.interpolateRound(1, 4500)(0.4)
Insert cell
d3.quantize(piecewiseNumber, 20)
Insert cell
d3 = require("d3@6")
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