Public
Edited
Jun 19, 2022
5 forks
61 stars
Also listed in…
Graphs
Insert cell
Insert cell
{
const el = html`<div style="width: 100%; height: 600px;"></div>`;
yield el;

ForceGraph3D()(el)
.height(600)
.linkWidth(4)
.linkOpacity(0.5)
.graphData(gData)
.d3Force("radius", forceRadius(gData.nodes, 320));
}
Insert cell
gData = {
// Random tree
const N = 300;
return {
nodes: [...Array(N).keys()].map((i) => ({ id: i })),
links: [...Array(N).keys()]
.filter((id) => id)
.map((id) => ({
source: id,
target: Math.round(Math.random() * (id - 1))
}))
};
}
Insert cell
function forceRadius(nodes, R = 1) {
return () => {
for (const n of nodes) {
const r = Math.hypot(n.x, n.y, n.z);
const u = Math.pow(r ? Math.sqrt(R / r) : 1, 0.05);
n.x *= u;
n.y *= u;
n.z *= u;
}
};
}
Insert cell
ForceGraph3D = require("3d-force-graph")
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