Public
Edited
Oct 30, 2024
8 forks
53 stars
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
groupingForce = forceInABox()
.size([width, height-100]) // Size of the chart
.template(template) // Either treemap or force
.groupBy("group") // Nodes' attribute to group
.strength(forceInABoxStrength) // Strength to foci
.links(graph.links) // The graph links. Must be called after setting the grouping attribute (Force template only)
.enableGrouping(useGroupInABox)
.linkStrengthInterCluster(linkStrengthInterCluster) // linkStrength between nodes of different clusters
.linkStrengthIntraCluster(linkStrengthIntraCluster) // linkStrength between nodes of the same cluster
.forceLinkDistance(forceLinkDistance) // linkDistance between meta-nodes on the template (Force template only)
.forceLinkStrength(forceLinkStrength) // linkStrength between meta-nodes of the template (Force template only)
.forceCharge(-forceCharge) // Charge between the meta-nodes (Force template only)
.forceNodeSize(forceNodeSize) // Used to compute the template force nodes size (Force template only)

Insert cell
Insert cell
simulation = d3.forceSimulation()
.nodes(graph.nodes)
.force("group", groupingForce)
// .force("collide", d3.forceCollide(nodeSize+1))
.force("charge", d3.forceManyBody().strength(-4))
.force("link",
d3.forceLink(graph.links)
.distance(2)
.strength(groupingForce.getLinkStrength)
)
.force("center", useGroupInABox ? null : d3.forceCenter(width/2, height/2));
// .force("x", useGroupInABox ? null : d3.forceX(width/2) )
// .force("y", useGroupInABox ? null : d3.forceY(height/2) );

Insert cell
width = 800
Insert cell
Insert cell
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