Coder Social home page Coder Social logo

yqrashawn / neo4j-3d-force-graph Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jexp/neo4j-3d-force-graph

0.0 2.0 0.0 1.13 MB

Experiments with Neo4j & 3d-force-graph https://github.com/vasturiano/3d-force-graph

Home Page: https://rawgit.com/jexp/neo4j-3d-force-graph/master/index.html

HTML 100.00%

neo4j-3d-force-graph's Introduction

Some experiments using Data in Neo4j to render 3d graphs using three-js via 3d-force-graph which is a really cool repository.

These pages use the Neo4j javascript driver to query the graph for some basic data and render it in the 3d-graph.

Please note that the JS driver uses a custom Number object, which we have to turn into JS integers with value.toNumber().

The pages load 5000 relationships from your graph at bolt://localhost, you might need to set auth (default is user: neo4j, password: test)

Basic Loading

basic loading: just using the id’s (fastest)

MATCH (n)-->(m) RETURN id(n) as source, id(m) as target LIMIT $limit
ForceGraph3D()(document.getElementById('3d-graph')).graphData(gData)
basic

Incremental Loading

Incremental loading: each row from the driver result is added to the graph incrementally

result.records.forEach(r => {
   const { nodes, links } = Graph.graphData();
   const link={source:r.get('source').toNumber(), target:r.get('target').toNumber()}
   Graph.graphData({
        nodes: [...nodes, { id:link.source }, { id: link.target}],
        links: [...links, link]
    });
});

Color and Caption

color by label and text caption on hover

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
const Graph = ForceGraph3D()(elem)
              .graphData(gData)
              .nodeAutoColorBy('label')
              .nodeLabel(node => `${node.label}: ${node.caption}`)
              .onNodeHover(node => elem.style.cursor = node ? 'pointer' : null);
labels info
Figure 1. Color and Caption on Paradise Papers

Weights for Node and Relationship Sizes

Use weight on node (e.g. pagerank) and on relationship to render different sizes. Also color relationships by type. We use log(weight) for relationships as they would groth too thick otherwise.

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
const Graph = ForceGraph3D()(elem)
              .graphData(gData)
              .nodeAutoColorBy('label')
              .nodeVal('size')
              .linkAutoColorBy('type')
              .linkWidth('weight')
              .nodeLabel(node => `${node.label}: ${node.caption}`)
              .onNodeHover(node => elem.style.cursor = node ? 'pointer' : null);
weights got
Figure 2. Weights on Game Of Thrones

Particles & Cluster Coloring

Color nodes and relationships by community/cluster id. Use particles for relationships to render their weight, here we use the original weight as it represents the number of particles traveling.

MATCH (n)-[r]->(m)
RETURN { id: id(n), label:head(labels(n)), community:n.louvain, caption:n.name, size:n.pagerank } as source,
       { id: id(m), label:head(labels(m)), community:n.louvain, caption:m.name, size:m.pagerank } as target,
       { weight:r.weight, type:type(r), community:case when n.community < m.community then n.community else m.community end} as rel
LIMIT $limit
const Graph = ForceGraph3D()(elem)
              .graphData(gData)
              .nodeAutoColorBy('community')
              .nodeVal('size')
              .linkAutoColorBy('community')
              .linkWidth(0)
              .linkDirectionalParticles('weight') // number of particles
              .linkDirectionalParticleSpeed(0.001) // slow down
              .nodeLabel(node => `${node.label}: ${node.caption}`)
              .onNodeHover(node => elem.style.cursor = node ? 'pointer' : null);
particles got
Figure 3. Particles and Clusters on Game Of Thrones

neo4j-3d-force-graph's People

Contributors

jexp avatar yqrashawn avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.