Skip to content

Instantly share code, notes, and snippets.

@strictlymomo
Created January 12, 2018 17:29
Show Gist options
  • Save strictlymomo/b4843955c2854e19594ba6b45ce5a58d to your computer and use it in GitHub Desktop.
Save strictlymomo/b4843955c2854e19594ba6b45ce5a58d to your computer and use it in GitHub Desktop.
2D Force + WebGL

This block implements a 2D graph structure in three dimensional space using 3d-force-graph.

<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