Public
Edited
Aug 7, 2023
1 fork
Importers
Insert cell
Insert cell
Insert cell
Insert cell
{
const x = d3.scaleBand().domain(d3.range(0, arr)).range([0, 600]);
const height = 300;
const y = d3
.scaleLinear()
.domain([0, Math.max(...groupped.map((g) => g.length / data.length)) * 1.1])
.range([0, height]);
const svg = d3.create("svg");
svg.attr("height", height + 100).attr("width", 700);

const graph = svg.append("g").attr("transform", "translate(50,50)");
const r = graph.selectAll("rect").data(groupped);
r.enter()
.append("rect")
.call((e) => e.append("title").text((d) => d.length))
.merge(r)
.attr("x", (d, i) => x(i))
.attr("y", (d) => height - y(d.length / data.length))
.attr("width", x.bandwidth())
.attr("height", (d) => y(d.length / data.length));
graph.append("g").call(d3.axisLeft(y));
graph
.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x));
return svg.node();
}
Insert cell
Insert cell
Insert cell
Insert cell
distributor = (fn, nbVal = 20) => {
let weights = d3.range(nbVal).map((d) => fn(d / nbVal));
var totalWeight = 0;
totalWeight += weights.reduce((acc, v) => acc + v);
var random = Math.random() * totalWeight;
for (var i = 0; i < nbVal; i++) {
random -= weights[i];
if (random < 0) {
return i / nbVal;
}
}
}
Insert cell
groupped = data.reduce(
(a, b) => {
let idx = Math.floor(b * arr);
a[idx] = [...a[idx], b];
return a;
},
d3.range(0, arr).map((w) => [])
)
Insert cell
data = d3.range(0, samples).map((x) => distributor(distribution, possibleVal))
Insert cell
import { chartEditor, Keyframe } from "@nhogs/easing-graphs-editor"
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