Giter VIP home page Giter VIP logo

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 latest 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() and wrap int values we send to the server like the limit in neo4j.int.

The example pages load 5000 relationships from the GameOfThrones graph at https://demo.neo4jlabs.com:7473 You might need to change auth and database (default: database/user/password: gameofthrones)

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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

neo4j-3d-force-graph's Issues

Render from database without reload

Hi, I watched your awsome video from youtube. I am just trying to reimplement the react version such that the query from database can be executed without clicking the reload button. I tried something below but it doesnt work. It gives the error TypeError: Cannot read properties of undefined (reading 'filter'). Can you please help? Thanks

componentDidMount() {
var that=this
const driver = neo4j.driver("bolt://demo.neo4jlabs.com", neo4j.auth.basic("gameofthrones", "gameofthrones"),{encrypted: true});
const session = driver.session({database:"gameofthrones"});

session
  .run('MATCH (n)-[r:INTERACTS1]->(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', {limit: neo4j.int(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'); if (rel.weight) { rel.weight = rel.weight.toNumber(); }
       return Object.assign({source:source.id,target:target.id}, rel);
    });
  that.setState({ data: {nodes, links}, loading: false });
})

}

render() {
return(




)
}
}

sample cannot open

beautiful 3d relationship maps , but the all sample can not open , would you help to check why ? it's seems like the datasource was use a local url .

thanks

Color of nodes

Hi Micheal,

Do you know if its possible to define the color of the nodes. For example:
image

I want to make the lightblue nodes, red. This is my code:

const elem = document.getElementById('viz');
const driver = neo4j.v1.driver("bolt://localhost", neo4j.v1.auth.basic("neo4j", "test"),{encrypted: true});
const session = driver.session();
const start = new Date()
session
.run("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: 4000})
.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()
(document.getElementById('viz'))
.graphData(gData)
.nodeLabel(node => <span style="color: black">${node.label}: ${node.caption}</span>)
.nodeAutoColorBy('label')
.linkDirectionalParticles(2)
.linkDirectionalParticleWidth(2)
.linkDirectionalParticleColor(() => 'grey')
.nodeVal(5)
.linkColor('black')
.backgroundColor('#ffffff')
.linkWidth(2)
.nodeResolution(30)
.nodeOpacity(1)
.linkColor(link => link.color ? '#000000' : '#000000' )
.onNodeHover(node => elem.style.cursor = node ? 'pointer' : null)
.onNodeClick(node => {
// Aim at node from outside it
const distance = 160;
const distRatio = 1 + distance/Math.hypot(node.x, node.y, node.z);
Graph.cameraPosition(
{ x: node.x * distRatio, y: node.y * distRatio, z: node.z * distRatio }, // new position
node, // lookAt ({ x, y, z })
30000 // ms transition duration
);
})
});

I cannot find it anywhere if this is even possible.

Thank you in advance

Regarding Relationship Captions

I have tried modifying the code to obtain captions to the relationship arrows, but haven't been able to do so as of now. Could you please help me with the same.

Data caption in node

Hi Michael,

First off i would like to say that i really like this libary in combination with Neo4j :) The visualisation look amazing. That said i was wondering if it's possible to display the data caption, partial in the node in a 2D graph? Like this image:

image

particles, color, incremental, index

Very basic question -

I've connected to a database, and the graph renders as defined in CypherViz.js. However, I can't figure out how to render the html code in particles.html / color.html / incremental.html / index.html. I've tried modifying the address, i.e. http://localhost:3000/particles.html, as it seemed comparable to https://rawgit.com/jexp/neo4j-3d-force-graph/master/particles.html, but clearly this is not the solution.

Sorry, I know that this is a very basic react / javascript question.

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.