-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<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 elem = document.getElementById('3d-graph'); | ||
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: id(n), label:head(labels(n)), caption:n.name } as source, { id: id(m), label:head(labels(m)), caption:m.name } as target LIMIT $limit', {limit: 10000}) | ||
.then(function (result) { | ||
const nodes = {} | ||
const links = result.records.map(r => { | ||
var source = r.get('source');source.id = source.id.toNumber(); | ||
nodes[source.id] = source; | ||
var target = r.get('target');target.id = target.id.toNumber(); | ||
nodes[target.id] = target; | ||
return {source:source.id,target:target.id} | ||
}); | ||
session.close(); | ||
console.log(links.length+" links loaded in "+(new Date()-start)+" ms.") | ||
const gData = { nodes: Object.values(nodes), links: links} | ||
const Graph = ForceGraph3D()(elem) | ||
.graphData(gData) | ||
.nodeAutoColorBy('label') | ||
.nodeLabel(node => `${node.label}: ${node.caption}`) | ||
.onNodeHover(node => elem.style.cursor = node ? 'pointer' : null); | ||
}) | ||
.catch(function (error) { | ||
console.log(error); | ||
}); | ||
</script> | ||
</body> |