Skip to content

Instantly share code, notes, and snippets.

@jexp
Created March 29, 2018 19:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jexp/ebcf16bc607bb62b458e3e8b10c26e1c to your computer and use it in GitHub Desktop.
Save jexp/ebcf16bc607bb62b458e3e8b10c26e1c to your computer and use it in GitHub Desktop.
<head>
<style> body { margin: 0; } </style>
<script src="//unpkg.com/3d-force-graph"></script>
<script src="//cdn.rawgit.com/neo4j/neo4j-javascript-driver/1.2/lib/browser/neo4j-web.min.js"></script>
<!--<script src="../../dist/3d-force-graph.js"></script>-->
</head>
<body>
<div id="3d-graph"></div>
<script>
const driver = neo4j.v1.driver("bolt://localhost", neo4j.v1.auth.basic("neo4j", "test"));
const session = driver.session();
const start = new Date()
session
.run('MATCH (n) WITH n MATCH (n)-->(m) RETURN id(n) as source, id(m) as target LIMIT $limit', {limit: 5000})
.then(function (result) {
const links = result.records.map(r => { return {source:r.get('source').toNumber(), target:r.get('target').toNumber()}});
session.close();
console.log(links.length+" links loaded in "+(new Date()-start)+" ms.")
const ids = new Set()
links.forEach(l => {ids.add(l.source);ids.add(l.target);});
const gData = { nodes: Array.from(ids).map(id => {return {id:id}}), links: links}
const Graph = ForceGraph3D()(document.getElementById('3d-graph')).graphData(gData);
})
.catch(function (error) {
console.log(error);
});
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment