Public
Edited
Aug 3, 2023
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = scaledSimplex(n, seed, smoothness)
Insert cell
data2 = scaledSimplex(
n,
seed,
smoothness,
bias,
0,
20,
new Date(2022, 6, 24),
new Date(2023, 7, 31)
)
Insert cell
convertValuesToDates = (values, start, end) => {
const timeScale = d3
.scaleTime()
.range(d3.extent(values))
.domain([start, end]);
return values.map((d) => timeScale.invert(d));
}
Insert cell
scaledSimplex = (
n,
seed,
smoothness,
bias = -1,
minY = -1,
maxY = 1,
minX,
maxX
) => {
const noise = makeSimplex1D(seed, smoothness);
const f = (y) => Math.max(noise(y), bias);
let ys = d3.range(n).map((d) => f(d));
let xs = d3.range(n);
if (minX instanceof Date && minX > 0 && maxX instanceof Date && maxX > 0) {
xs = convertValuesToDates(xs, minX, maxX);
}
const linScale = d3.scaleLinear().domain(d3.extent(ys)).range([minY, maxY]);
ys = ys.map((d) => linScale(d));
return ys.map((y, i) => ({ x: xs[i], y: y }));
}
Insert cell
Insert cell
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