Published
Edited
May 9, 2018
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
getRandomWalk = (n, initial, delta) => d3.range(n - 1)
.map(d => delta())
.reduce(
(acc, cur) => acc.concat([[
acc[acc.length-1][0] + 1,
acc[acc.length-1][1] * (1 + cur)
]]),
[[0, initial]]
)
Insert cell
distort = (data, recurse) => {
// nested only bc Observable's weird w recursion (it appears circular)
return recurser(data, recurse)
// btw i'd appreciate any code review re: how to make this cleaner lol
function recurser(data, recurse) {
if(!recurse) return data
const extent = d3.extent(data)
const warp = (extent[1] - extent[0]) * Math.random()

const cut = Math.floor(data.length / 2)
const cut1 = data.slice(0, cut)
const cut2 = data.slice(cut)

const scale1 = d3.scaleLinear()
.domain(d3.extent(cut1))
.range([extent[0], extent[0] + warp])
const scale2 = d3.scaleLinear()
.domain(d3.extent(cut2))
.range([extent[0] + warp, extent[1]])

return recurser(cut1.map(scale1), recurse - 1)
.concat(recurser(cut2.map(scale2), recurse - 1))
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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