Skip to content

Commit

Permalink
Adjust d3 forces #15
Browse files Browse the repository at this point in the history
  • Loading branch information
Scobiform committed Apr 20, 2024
1 parent d325ac2 commit 7e2e92e
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions templates/graph.html
Original file line number Diff line number Diff line change
Expand Up @@ -275,31 +275,16 @@

// # Add forces to the graph
// Dynamic collision radius based on node type
Graph.d3Force('collide', d3.forceCollide().radius(node => {
if (node.type === 'instance') {
return instanceSizeMultiplier + 7 * Math.sqrt(node.connectionCount);
} else {
return avatarSizeMultiplier + (Math.log(node.followerCount + 1) * 63);
}
}))
Graph.d3Force('collide', d3.forceCollide().radius(node => node.type === 'instance' ? 60 : 42))
// Increased repulsive force
.d3Force('charge', d3.forceManyBody().strength(-42000))
// Centering forces
// Increased distance and adjusted strength for links
.d3Force('link', d3.forceLink().id(d => d.id).distance(200).strength(0.5))
.d3Force('x', d3.forceX(container.clientWidth / 2).strength(0.05))
.d3Force('y', d3.forceY(container.clientHeight / 2).strength(0.05))
.d3Force('center', d3.forceCenter(container.clientWidth / 2, container.clientHeight / 2))
// Link forces with conditional distance based on link type and node attributes
.d3Force('link', d3.forceLink()
.id(d => d.id)
.distance(link => {
// Optionally adjust link distances based on node attributes if required
if (link.type === 'instance') return 4200 + 5 * Math.sqrt(link.source.connectionCount);
else if (link.type === 'user') return 14000 + 2 * Math.sqrt(link.source.followerCount);
else if (link.type === 'followers') return 2100 + 2 * Math.sqrt(link.source.followerCount);
else if (link.type === 'followings') return 1400 + 2 * Math.sqrt(link.source.followerCount);
else return 10000; // Default distance for other or undefined types
})
.strength(0.5));
// Link distance based on type
.d3Force('link', d3.forceLink().distance(link => link.type === 'instance' ? 200 : 100).strength(0.5));

return Graph;
}
Expand Down

0 comments on commit 7e2e92e

Please sign in to comment.