Public
Edited
Oct 26, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
nodes = {
let system;
let gen = DiscSampler(width, 300, 20);
let points = [];
let pointsHash = [];
let finished = false;
let obj = {
points,
pointsHash,
}
for (let i = 0; i < totalPoints / 20; i++) {
if (finished) break;
finished = genPoints(points, 20);
yield obj
}

function genPoints(container, num = 20) {
let result;
for (let i = 0; i < num; i++) {
result = gen.next();
if (result.done) {
break;
}
if (container) {
container.push(result.value);
pointsHash[container.length - 1] =
hash(result.value[0], result.value[1]);
}
}
return result.done;
}
}
Insert cell
{
hide
map.update(nodes, ratio)
}
Insert cell
map = {

const svg = d3.create('svg')
.attr("width", width)
.attr("height", 300)
.attr("viewBox", [0, 0, width, 300])
.attr(
"style",
"max-width: 100%; height: auto; height: intrinsic;border: solid 1px"
)
const circles = svg.append('g')
.attr('stroke', 200)
.attr('stroke-width', 2)
.attr('fill', 'gray')

function update(result, ratio){
circles.selectAll('circle')
.data(result.points)
.join('circle')
.attr('cx', d=>d[0])
.attr('cy', d=>d[1])
.attr('r', 5)
.style('opacity', (_, i) => result.pointsHash[i] > ratio ? '25%' : '100%' )
}

return {
svg,
update,
}
}
Insert cell
svgCircle = (p5, x, y)=>{
return d3.create('circle')
.attr('stroke', 200)
.attr('stroke-width', 2)
.attr('fill')
.attr('cx', x)
.attr('cy', y)
.attr('r', 5)
}
Insert cell
hash = (x, y) => {
const arr = new Float64Array([x, y])
return xxhash.h32(new Uint8Array(arr)) / 0xFFFFFFFF
}
Insert cell
xxhash = (await require('xxhash-wasm@1.0.2/umd/xxhash-wasm.js'))()
Insert cell
import { DiscSampler } from "@fil/2d-point-distributions"
Insert cell
import {p5, ParticleSystem} from "@tmcw/p5"
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