Public
Edited
Jan 29, 2024
Insert cell
Insert cell
Insert cell
Insert cell
randomLines = {
const svg = d3.select(DOM.svg(width, height))
.attr("fill", "none")
.attr("stroke", "black")
.attr("stroke-width", 0.5);
for (let i = 0; i < 50; ++i) {
yield svg.node();

svg.append("path")
.attr("d", line(dampenedRandomWalk()))
}
}
Insert cell
function dampenedRandomWalk() {
let target = 0.5 + (Math.random() - 0.5)
let value = Math.random();
let values = [value];
for (let i = 0; i < n; ++i) {
let dec = decay + (Math.random() - 0.5);
console.log(value)
values.push(value += (Math.random() - 0.5) * noise + (target - value) * dec);
}
return values;
}
Insert cell
function strokeNone() {
return `0 ${this.getTotalLength()}`;
}
Insert cell
function strokeIn() {
const l = this.getTotalLength();
return d3.interpolate(`0 ${l}`, `${l} 0`);
}
Insert cell
function strokeOut() {
const l = this.getTotalLength();
return d3.interpolate(`0 0 ${l}`, `0 ${l} 0`);
}
Insert cell
line = d3.line().x((d, i) => i / n * width).y(d => d * height).curve(d3.curveBasis)
Insert cell
n = 10
Insert cell
height = 830

Insert cell
width = 1440

Insert cell
d3 = require("d3@5")
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