Last active
April 22, 2021 23:29
-
-
Save vasturiano/bcfc5baa9e7998fb97b3091d2499fe16 to your computer and use it in GitHub Desktop.
3D Radial Force
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <head> | |
| <style> | |
| body { | |
| margin: 0; | |
| font-family: Sans-serif; | |
| } | |
| </style> | |
| <script src="//unpkg.com/3d-force-graph@1"></script> | |
| <script src="//unpkg.com/d3-octree"></script> | |
| <script src="//unpkg.com/d3-force-3d@1"></script> | |
| </head> | |
| <body> | |
| <div id="3d-graph"></div> | |
| <script> | |
| const N = 700; | |
| const nodes = [...Array(N*4).keys()].map((n) => ({ type: n > N ? 'b' : 'a' })); | |
| ForceGraph3D() | |
| .d3AlphaDecay(0.01) | |
| .d3VelocityDecay(0.1) | |
| .d3Force('charge', null) // Deactivate existing charge | |
| .d3Force('radial', d3.forceRadial(d => d.type === 'a' ? 300 : 600)) | |
| .d3Force('collide', d3.forceCollide(16)) | |
| .nodeRelSize(8) | |
| .nodeColor(d => d.type === 'a' ? 'brown' : 'steelblue') | |
| .graphData({ nodes, links: [] }) | |
| (document.getElementById('3d-graph')); | |
| </script> | |
| </body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment