Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aim: transform Neo4j Record to G6 , stuck at how to skip duplicate nodes #192

Closed
scarletfrank opened this issue Aug 19, 2021 · 7 comments
Closed

Comments

@scarletfrank
Copy link

Aim

  • transform Neo4j Records to G6 format
  • can not figure out how neovis.js avoid adding duplicate nodes

Problem

Example Cypher: MATCH (b)-[re]-(c) RETURN b, re, c LIMIT 10

As the case of neovis

  viz.render();
  console.log(viz._edges);
  console.log(viz._nodes);
// ----
{id: 59085, from: 11496, to: 15468, raw: Relationship, title: "",}
{id: 59087, from: 18665, to: 15468, raw: Relationship, title: "", ...}
// ----
{id: 15468, raw: Node, value: 1, label: "  ", group: 2,}
{id: 11496, raw: Node, value: 1, label: "  ", group: 2,}
{id: 18665, raw: Node, value: 1, label: "  ", group: 2,}

I use use-neo4j as a React wrapper to access Neo4j. It returns Neo4jRecord which is actually Record from Neo4j-Driver .

[Record, Record, Record, Record, Record, Record, Record, Record, Record, Record]
Record.toObject()  // = > {n: Node, re: Relationship, b: Node}

Inevitably, I have to skip the duplicate nodes. I know neovis works well. I find a similar implementation at this developer blog, in which it says

Next, we have to convert the returned results from Neo4j which is a list of records into a format that is D3 compatible. 
neovis.js provides a very good guide on how to achieve this and for the most part, we copied their code.
@thebestnom
Copy link
Collaborator

I don't think we actually skip duplicates, if I remember correctly we add everything to vis DataSet by id, so it should just override the last one in case of duplicates (same as using hashmap)

(Neo4j node and relationship comes with unique id)

@scarletfrank
Copy link
Author

Thanks for quick reply.

OMG. I think I find the key to the problem, but I am still a little bit confused.

_addNode(node) {
this._nodes[node.id] = node;
}

Yes, It will override the node with the same id.

As for the developer blog, I am not sure whether Motif inherit the neo4j-driver logic

let nodes: Node[] = []; // Node from `neo4j-driver`
let startNode = buildNode(v.start);
nodes.push(startNode); 

Maybe the last line is equivalent to Node[startNode.identity] = startNode;

@scarletfrank
Copy link
Author

I would complete my neo4j-g6-demo this week.
After that, I will leave the link and close this issue.

@thebestnom
Copy link
Collaborator

Thanks for quick reply.

OMG. I think I find the key to the problem, but I am still a little bit confused.

_addNode(node) {
this._nodes[node.id] = node;
}

Yes, It will override the node with the same id.

As for the developer blog, I am not sure whether Motif inherit the neo4j-driver logic

let nodes: Node[] = []; // Node from `neo4j-driver`
let startNode = buildNode(v.start);
nodes.push(startNode); 

Maybe the last line is equivalent to Node[startNode.identity] = startNode;

Nope 😅 it looks like they have the same problem as you (also the code is a little bit different on 2.0.0 but it does the same thing)

@thebestnom
Copy link
Collaborator

I think that if they use a network library most of them know as well to merge same id

@thebestnom
Copy link
Collaborator

But in their data it most likely have duplicates

@scarletfrank
Copy link
Author

I successfully implement it. The code is here

I also combine it with Graphin in the my react-graphapp.

Although it works fine with my local Neo4j Docker instances , it still needs to be developed for richer customization.

I think the issue is solved. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants