Public
Edited
Oct 24, 2023
5 forks
Importers
61 stars
Insert cell
Insert cell
p = d3.line()([[10, 60], [40, 90], [60, 10], [190, 10]])
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
walk = {
replay;
const data = [];
for (let i = 0, v = 2; i < 50; ++i) {
v += Math.random() - 0.5;
v = Math.max(Math.min(v, 4), 0);
data.push({step: i, value: v});
yield data;
}
}
Insert cell
walkX = d3.scaleLinear()
.domain([0, 49])
.range([10, width - 10])
Insert cell
walkY = d3.scaleLinear()
.domain([0, 4])
.range([200 - 10, 10])
Insert cell
line = d3.line()
.x(d => walkX(d.step))
.y(d => walkY(d.value))
Insert cell
line(walk)
Insert cell
Insert cell
Insert cell
Insert cell
// Using d3.shuffle to simulate unordered data
svg`<svg width=${width} height=200>
<path d="${line(d3.shuffle(walk.slice()))}"
stroke="black" stroke-width="0.3" fill="none">
</svg>`
Insert cell
Insert cell
ball = {
replay2;
// Start at the center of the field.
let vx = width / 2, vy = 250;
const data = [];
for (let i = 0; i < 1000; i++) {
// Random walk with large or small steps.
const l = Math.random() < 0.05 ? 100 : 10;
data.push({
step: i,
x: vx += l * (Math.random() - 0.5),
y: vy += l * (Math.random() - 0.5)
});
yield data;
}
}
Insert cell
// The x and y accessors retrieve the corresponding attributes
// shorthand equivalent to d3.line().x(d => d.x).y(d => d.y)
footballLine = d3.line(d => d.x, d => d.y)
Insert cell
footballLine(ball)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
badwalk = walk.map(d => ({
step: d.step,
value: Math.random() < 0.2 ? null : d.value,
real: d.value
}))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
lc = d3.line()
.curve(d3[curve])
.x(d => walkX(d.step))
.y(d => walkY(d.value))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more