This block implements a 2D graph structure in three dimensional space using 3d-force-graph.
Created
January 12, 2018 17:29
-
-
Save strictlymomo/b4843955c2854e19594ba6b45ce5a58d to your computer and use it in GitHub Desktop.
2D Force + WebGL
This file contains 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; } </style> | |
<script src="//unpkg.com/3d-force-graph@1"></script> | |
</head> | |
<body> | |
<div id="3d-graph"></div> | |
<script> | |
// Hierarchy | |
const N = 7500; | |
const gData = { | |
nodes: [...Array(N).keys()].map(i => ({ id: i })), | |
links: [...Array(N).keys()] | |
.filter(id => id) | |
.map(id => ({ | |
source: Math.floor( Math.pow(id,1/1.62) ), | |
target: id + 1 | |
})) | |
} | |
const Graph = ForceGraph3D() | |
(document.getElementById('3d-graph')) | |
.numDimensions(2) | |
.lineOpacity(.2) | |
.forceEngine('ngraph') | |
.graphData(gData); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment