Relationships are not showing in the graph by using neovis.js

cypher
neovis

(Babu Ganesh0708) #1

Hi All,

I am trying to show the top 10 node in the graph and below is the query I tried in neo4j browser,

MATCH (p1:Username)-[r:sent]->(p2:Username) 
RETURN p1, count(*) AS count 
ORDER BY count DESC LIMIT 10

As below image shows the top 10 nodes with their relationship

Similarly I am trying to show the graph using neovis.js and I can able to show the top 10 nodes in the visualization but not sure why the relationships are not showing in the graph.

Below is the response,

neovis javascript function,

function draw() {
            var config = {
                container_id: "viz",
                server_url: "bolt://localhost:7687",
				arrows: true,
                labels: {
                    "Username": {
                        "caption": "mail_id",
						"size": "pagerank",
                        "community": "partition"
                    }
                },
                relationships: {
					"sent": {
                        "thickness": "count",
                        "caption": false
                    }
                },
				initial_cypher: "MATCH (p1:Username)-[r:sent]->(p2:Username) RETURN p1, count(*) AS count ORDER BY count DESC LIMIT 10"
            };

            viz = new NeoVis.default(config);
            viz.render();
        }

Please correct me If am doing anything wrong in the query and let me know your thoughts.

Regards,
Ganeshbabu R


(Michael Hunger) #2

You also have to return the relationships.

e.g.

MATCH (p1:Username)
with p1, size((p1)-[r:sent]->()) as count
order by count desc limit 10
match (p1)-[r]->()
RETURN p1, r


(Babu Ganesh0708) #3

Thanks @michael.hunger

Yes it solved the problem..

Also similar problem I am facing now and we have two nodes (Username & Topics) and I am trying to show the top topics which discussed among the users and below is the query to load the data to neo4j

LOAD CSV WITH HEADERS FROM "file:///data_email.csv" AS row
WITH row WHERE row.message_subject <> 'none' AND row.keywords <> 'none'
MERGE (p1:Username {mail_id: row.sender_address}) ON CREATE SET p1.timestamp = row.date_time 
MERGE (p2:Username {mail_id: row.recipient_address})
MERGE (p3:Topic {topic: row.keywords})
WITH p1, p2, p3, row, COUNT(*) AS count
MERGE (p1)-[r1:sent]->(p2) ON CREATE SET r1.time = row.date_time, r1.count = count
MERGE (p1)-[r2:sender_interest]->(p3)<-[r3:receiver_interest]-(p2) ON CREATE SET r2.sentcount = count, r3.receivecount = count

After I loaded the data to neo4j below is the query I tried to show the top 10 topics with the users in neo4j browser,

MATCH (p1:Username)-[r2:sender_interest]->(t:Topic)
WITH p1, t, count(r2) as count
RETURN p1.mail_id as sender, t.topic as topics, count
ORDER BY count DESC
LIMIT 10

Response of the query,

Now I am trying to show the top 10 topics using neovis.js but don't know why the data is not showing up and I wanted to show the thickness based on the relationship count.

**Below is the neovis javascript function,
**

var config = {
                container_id: "viz",
				server_url: "bolt://localhost:7687",
				arrows: true,
                labels: {
                    "Username": {
                        "caption": "mail_id",
						"size": "pagerank",
                        "community": "partition"
                    },
					"Topic": {
					    "caption": "topic"
					}
                },
                relationships: {
					"sender_interest": {
					    "thickness": "sentcount",
						"caption": false
					}
                },
                initial_cypher: "MATCH (p1:Username),(p3:Topic) with p1, p3, size((p1:Username)-[:senderinterest]-(p3:Topic)) as count order by count desc limit 10 MATCH (p1)-[r:senderinterest]->(p3) RETURN p1, p3, r"
            };

Also I am having less confident of the way I have set the count value for interest relationship.
Please correct me If I am doing anything wrong.

Regards,
Ganeshbabu R


(Michael Hunger) #4

To test it I recommend running these in neo4j browser and work step by step in your query.

Are you actually looking for users that have sent a lot or topics that got a lot
or the same topic and user that had most interactions?
You can simplify this:

MATCH (p1:Username)
with p1, size((p1)-[:senderinterest]->()) as count 
order by count desc limit 10 
MATCH (p1)-[r:senderinterest]->(p3) RETURN p1, p3, r

(Ameyasoft) #5

Hi,

Try this query to get topic and total number of users discussed.

MATCH (t:Topic)-[:sender_interest]-(p)
WITH t, count(distinct p) as Cnt
MATCH (t)-[:receiver_interest]-(q)
WITH t, count(distinct q) + Cnt as Tot
RETURN t.topic, Tot;

Here is the result with your previously published data with one topic:
bganesh3

-Kamal


(Sucheta) #6

Hey babu

I want to know how do you get the similar color for the nodes .

I ran this code -

  CALL algo.labelPropagation(null,null,'OUTGOING',{write:true, partitionProperty:'partition',  
   weightProperty:'count'})

And this is my Neovis.js code. Please help.

I tried using the community label everywhere in my config variable but still no change in nodes

    var config = {
         container_id: "viz",
         server_url: "bolt://localhost:11001/",
         server_user: "neo4j",
         server_password: "781",
         labels: {
            
             "ngoconnectionserviceimplhttpsoap11endpoint": {
                "thickness": "weight",
                "caption": true,
               "community": "partition",
                "sizeCypher": "MATCH (n) WHERE id(n) = {id} MATCH (n)-[r]-() RETURN sum(r.weight) AS c"
            },
            "ngoconnectionserviceimplhttpsoap12endpoint": {
               "thickness": "weight",
               "caption": true,
               "community": "partition",
               "sizeCypher": "MATCH (n) WHERE id(n) = {id} MATCH (n)-[r]-() RETURN sum(r.weight) AS c"
           },
           "connparams_2": {
            "thickness": "weight",
            "caption": true,
           "community": "partition",
            "sizeCypher": "MATCH (n) WHERE id(n) = {id} MATCH (n)-[r]-() RETURN sum(r.weight) AS c"
        },

        "connparams": {
            "thickness": "weight",
            "caption": true,
           "community": "partition",
            "sizeCypher": "MATCH (n) WHERE id(n) = {id} MATCH (n)-[r]-() RETURN sum(r.weight) AS c"
        },            
        
       
             
         },
         relationships: {
             "Parameter": {
                 "thickness": "weight",
                 "caption": true,
                 "community": "partition",
                '
             },
             "Method": {
                "thickness": "weight",
                "caption": true,
                "community": "partition"
              
            },
          
            "Department": {
                "thickness": "weight",
                "caption": true,
                "community": "partition",
                
            },
         
         },

         cluster_labels: {
            "Parameter": "community"
          },
       
         initial_cypher:cypherQuery ,        
        arrows: true,
        hierarchical_layout:true,
        hierarchical_sort_method:"directed",
        
     };

Please help. I ain't getting any clustered uniform color.

Output -


(William Lyon) #7

@sucheta- can you verify that running label propagation identified several distinct communities or reasonable size (and not just that you end with many communities with few nodes in each)? For example, if you run

MATCH (n:connparams)
WITH COLLECT(id(n)) AS community, n.partition AS partition
RETURN partition, SIZE(community) AS num ORDER BY num DESC LIMIT 25

this will show you the size of the 25 largest communities.


(Sucheta) #8

@William_Lyon
Thanks for the reply.
I got this result -

How does it affect the color of my nodes in Neovis.js.
Does it mean that there are 21 nodes connected to connparams that have same color ?

Also ,

Is this definition correct -

 "connparams": {
            "thickness": "weight",
            "caption": true,
           "community": "partition",
            "sizeCypher": "MATCH (n) WHERE id(n) = {id} MATCH (n)-[r]-() RETURN sum(r.weight) AS c"
        },   

Kindly guide so that i get same color for a set of nodes.


(Michael Hunger) #9

you only have one community with size 1

your label propagation algorithm didn't run correctly.


(Sucheta) #10

Hi michael,

I ran the above query . Can you please point out what is wrong with it. I saw this query on the video of -

Graph Visualization With Neo4j Using Neovis.js


(Michael Hunger) #11

If it ran correctly you should see many more partitions.
Or at most a partition with size > 1


(Sucheta) #12

Thanks Michael. But i don't know where i am going wrong. Please suggest.


(Michael Hunger) #13

what does this output?

CALL algo.labelPropagation.stream(null,null,'OUTGOING')

you should see each node with its partition.


(Michael Hunger) #14

also can you show the tabular output of a

match (n) return n limit 10

in neo4j browser.


(Sucheta) #15

@michael.hunger

The output of this query -

CALL algo.labelPropagation.stream(null,null,'OUTGOING')

Output -

Error -

 Neo.ClientError.Statement.SyntaxError: Type mismatch: expected Map, Node or Relationship but was String (line 1, column 53 (offset: 52))
"CALL algo.labelPropagation.stream(null,null,'OUTGOING')"
                                                                                         ^

And the output of -

match (n) return n limit 10

is -



{
  "name": "abc",
  "partition": 2
}
{
  "name": "def",
  "company": "abc",
  "partition": 46
}
{
  "name": "ghi",
  "company": "abc",
  "partition": 46
}
{
  "name": "NGOConnectionServiceImpl",
  "company": "abc",
  "partition": 52
}
{
  "name": "NGOConnectionServiceImplHttpSoap11Endpoint",
  "company": "abc",
  "partition": 10
}
{
  "name": "disconnectCab",
  "company": "abc",
  "partition": 11
}
{
  "name": "input",
  "company": "abc",
  "partition": 9
}
{
  "name": "disconParams",
  "company": "abc",
  "partition": 9
}
{
  "name": "cabinetName",
  "company": "abc",
  "partition": 8
}
{
  "name": "userDbId",
  "company": "abc",
  "partition": 9
}

(Michael Hunger) #16

what was the cypher query for your neoviz? you did not show it up there.

it seems that some of your nodes have a partition property but not clear if those are the right labels you use in the visualization.

do your nodes have a single label or multiple labels?

match (n) 
where n:ngoconnectionserviceimplhttpsoap11endpoint
or n:connparams
or n:ngoconnectionserviceimplhttpsoap12endpoint
or n:connparams_2
return n, labels(n)
limit 10

(Sucheta) #17

Hi Michael,

The original cypherQuery for my neovis is -

 var cypherQuery = "MATCH (n)-[r]->(m) RETURN n,r,m;";

The output for the query you mentioned is -

var cypherQuery = `match (n) 
         where n:ngoconnectionserviceimplhttpsoap11endpoint
         or n:connparams
         or n:ngoconnectionserviceimplhttpsoap12endpoint
         or n:connparams_2
         return n, labels(n)
         limit 10`

output -

The output for the cypherQuery is -

var cypherQuery = `match (n) -[r]->(m) 
         where n:ngoconnectionserviceimplhttpsoap11endpoint
         or n:connparams
         or n:ngoconnectionserviceimplhttpsoap12endpoint
         or n:connparams_2
         return n,r,m, labels(n)
         limit 50`

output -


(Michael Hunger) #18

As you can see you only have one node for each label.

Did you understand the concept of labels in Neo4j?

They are like types or "tables" or "collections" in other databases.

So you should have hundreds or millions of nodes with the same lable, like "Person" or "Product" or "Location".

And for those labels the configuration in neovis holds the information on how to render them.

So in a real graph you would have a (:Person)-[:KNOWS]-(:Person)

Where people would form clusters/communities.
And you would configure neovis for the "Person" label to use the partition property to color those clusters.


(Sucheta) #19

Hi Michael,

I changed my queries to incorporate the labels. Here are a few query examples -

'Match (cabinet_2:Organization) where cabinet_2.name ="cabinet_2" and cabinet_2.company="cateina"  Create  (privileges_2: Department{name:\'privileges_2\',company:\'cateina\'}), (cabinet_2)-[:Department]->(privileges_2)' ,
 'Match (disconnectcab:Method) where disconnectcab.name ="disconnectcab" and disconnectcab.company="cateina"  Create  (input:Request{name:\'input\',company:\'cateina\'}), (disconnectcab)-[:Request]->(input) ',
'Create  (lockbyuser_2:Parameter{name:\'lockbyuser_2\',company:\'cateina\'}), (cabinet_2)-[:Parameter]->(lockbyuser_2) ',
  'Match (cabinet_2:Parameter) where cabinet_2.name ="cabinet_2" and cabinet_2.company="cateina"  Create  (loginuserrights_2:Parameter{name:\'loginuserrights_2\',company:\'cateina\'}), (cabinet_2)-[:Parameter]->(loginuserrights_2) ',

...etc.

And then i ran this query ->

CALL algo.labelPropagation(null,null,'OUTGOING',{write:true, partitionProperty:'partition', weightProperty:'count'})

And i configured my neovis.js as -

var config = {
             container_id: "viz",
             server_url: "bolt://localhost:11001/",
             server_user: "neo4j",
             server_password: "Virtuallib1",
             labels: {
                 //"Character": "name",
                
                 "Organization": {
                    "thickness": "weight",
                    "caption": "name",
                    "size": "pagerank",
                   "community": "community",
                    "sizeCypher": "MATCH (n) WHERE id(n) = {id} MATCH (n)-[r]-() RETURN sum(r.weight) AS c"
                },
                "Parameter": {
                   "thickness": "weight",
                   "caption": "name",
                   "size": "pagerank",
                   "community": "community",
                   "sizeCypher": "MATCH (n) WHERE id(n) = {id} MATCH (n)-[r]-() RETURN sum(r.weight) AS c"
               },
               "Department": {
                "thickness": "weight",
                "caption": "name",
                "size": "pagerank",
               "community": "community",
                "sizeCypher": "MATCH (n) WHERE id(n) = {id} MATCH (n)-[r]-() RETURN sum(r.weight) AS c"
            },

            "Request": {
                   "thickness": "weight",
                   "caption": "name",
                   "size": "pagerank",
                   "community": "community",
               },
               "Response": {
                   "thickness": "weight",
                   "caption": "name",
                   "size": "pagerank",
                   "community": "community",
                   
               },
               "Paths": {
                   "thickness": "weight",
                   "caption": "name",
                   "size": "pagerank",
                   "community": "community",
                  
               },
               "API": {
                   "thickness": "weight",
                   "caption": "name",
                   "size": "pagerank",
                   "community": "community",
                  
               },
              
               "System": {
                   "thickness": "weight",
                   "caption": "name",
                   "size": "pagerank",
                   "community": "community",
               },
               "Service": {
                "thickness": "weight",
                "caption": "name",
                "size": "pagerank",
                "community": "community",
            },
            "Operation": {
                "thickness": "weight",
                "caption": "name",
                "size": "pagerank",
                "community": "community",
            },
            "Method": {
                "thickness": "weight",
                "caption": "name",
                "size": "pagerank",
                "community": "community",
            },
                 
             },
             relationships: {
                 "Parameter": {
                     "thickness": "weight",
                     "caption": true,
                     "community": "partition",
                     "color":'red'
                 },
                 "Method": {
                    "thickness": "weight",
                    "caption": true,
                    "community": "Blue",
                   
                },
                "Request": {
                    "thickness": "weight",
                    "caption": true,
                    "community": "partition",
                   
                },
                "Response": {
                    "thickness": "weight",
                    "caption": true,
                    "community": "partition",
                    
                },
                "Paths": {
                    "thickness": "weight",
                    "caption": true,
                    "community": "partition",
                    
                },
                "API": {
                    "thickness": "weight",
                    "caption": true,
                    "community": "partition",
                   
                },
                "Department": {
                    "thickness": "weight",
                    "caption": true,
                    "community": "partition",
                    
                },
                "System": {
                    "thickness": "weight",
                    "caption": true,
                    "community": "partition",
                    
                },
             },

             cluster_labels: {
                "Parameter": "partition"
              },
           
             initial_cypher:cypherQuery ,        
            arrows: true,
            hierarchical_layout:true,
            hierarchical_sort_method:"directed",
            
         };                 
         this.viz = new NeoVis.default(config);  
      
         this.viz.render();
         console.log(this.viz);
}

However, i get the same color for all the labels. Like -

But i want different color for every label. Please help


(Michael Hunger) #20

What are the different communities for your labels now?

match (n)
return head(labels(n)) as lab, n.partition as partition, count(*) as count
order by label, count desc;