Skip to content

Commit

Permalink
Weights and Sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
jexp committed Mar 30, 2018
1 parent c09e2e6 commit b2e3278
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ The pages load 5000 relationships from your graph at bolt://localhost, you might
* link:{base}/index.html[basic loading^] just using the id's (fastest) link:index.html[index.html]
* link:{base}/incremental.html[incremental loading^] each row from the driver result is added to the graph incrementally link:incremental.html[incremental.html]
* link:{base}/color.html[color by label and caption on hover^] loads `{ id: id(n), label:head(labels(n)), caption:n.name }` per node link:color.html[color.html]
* link:{base}/weights.html[node size and rel-weight^] loads `{ id: id(m), label:head(labels(m)), caption:m.name, size:m.pagerank }` as node, `{weight:log(r.weight), type:type(r)}` as relationships link:weights.html[weights.html]
.Color and Caption on Paradise Papers
image::labels-info.jpg[width=600]

.Weights on Game Of Thrones
image::weights-got.jpg[width=600]
Binary file added weights-got.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions weights.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<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)-[r]->(m) RETURN { id: id(n), label:head(labels(n)), caption:n.name, size:n.pagerank } as source, { id: id(m), label:head(labels(m)), caption:m.name, size:m.pagerank } as target, {weight:log(r.weight), type:type(r)} as rel LIMIT $limit', {limit: 5000})
.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;
var rel = r.get('rel');
return Object.assign({source:source.id,target:target.id}, rel);
});
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')
.nodeVal('size')
.linkAutoColorBy('type')
.linkWidth('weight')
// .linkDirectionalParticles(10)
.nodeLabel(node => `${node.label}: ${node.caption}`)
.onNodeHover(node => elem.style.cursor = node ? 'pointer' : null);
})
.catch(function (error) {
console.log(error);
});
</script>
</body>

0 comments on commit b2e3278

Please sign in to comment.