For Dashboard Designers Examples Query with network ouput and and context menus
Wednesday, May 22, 2019 11:04 AMExample: Query with network output and context menus
Label: :Example_2
This example illustrates how you can send the output from a query to a NetworkView. When you right-click in the NetworkView (on a node, a relationship or the canvas), a context menu opens with the following options:
- Return a list of neighbouring nodes (node context menu)
- Return the count of similar relationships (relationship context menu)
- Return the number of selected and visible nodes and relationships (canvas context menu)
The Cypher statement below creates the example.
CREATE (_180138:IA_Function:IA_Neo4jQuery:Example_2 {`process`:'true', `cypher`:'MATCH (n:IA_Function)-[r]->(m) RETURN n,m LIMIT 5', `name`:'Get sample graph'})
CREATE (_180140:IA_Function:IA_NetworkView:Example_2 {`$container.height`:800, `$autoComplete`:'true', `$name`:'', `$container.width`:800, `$area`:'content'})
CREATE (_180143:IA_Function:IA_Neo4jQuery:Example_2 {`cypher`:'MATCH (n)--(m)
WHERE id(n)={id}
RETURN
id(m) AS node_id,
labels(m) AS node_labels,
m.name AS node_name', `name`:'Get neighbours'})
CREATE (_180145:IA_Function:IA_TableView:IA_Function:Example_2 {`$name`:''})
CREATE (_180148:IA_Function:IA_Neo4jQuery:Example_2 {`process`:'true', `cypher`:'MATCH (n)-[r]->(m)
WHERE type(r)={type}
RETURN r LIMIT 20
', `name`:'Extract similar'})
CREATE (_180152:IA_Function:IA_Neo4jQuery:Example_2 {`cypher`:'RETURN
SIZE({visibleIds}) as visible,
SIZE({selectedIds}) as selected', `name`:'Get count of visible / selected nodes'})
CREATE (_180138)-[_546668:TRIGGER {`$name`:'Sample graph', `#relations`:'(%).processed.relations', `#nodes`:'(%).processed.nodes', `type`:'success', `$container.id`:'samplecontainer'}]->(_180140)
CREATE (_180140)-[_546674:TRIGGER {`#params.visibleIds`:'(%)._function.state.visible.nodes[#].id', `type`:'context', `menu`:'canvas', `action`:'Get selected and visible', `#params.selectedIds`:'(%)._function.state.selected.nodes[#].id'}]->(_180152)
CREATE (_180148)-[_546672:TRIGGER {`$name`:'Similar relation', `#relations`:'(%).processed.relations', `#nodes`:'(%).processed.nodes', `type`:'success', `$container.id`:'similarcontainer'}]->(_180140)
CREATE (_180140)-[_546671:TRIGGER {`$params.type`:'(%).target.type', `action`:'Get similar', `menu`:'relation', `type`:'context'}]->(_180148)
CREATE (_180140)-[_546669:TRIGGER {`$params.id`:'(%).target.id', `menu`:'node', `action`:'Get neighbours', `type`:'context'}]->(_180143)
CREATE (_180143)-[_546670:TRIGGER {`$name`:'Neighbours', `$container.id`:'neighbours', `type`:'success', `#data`:'(%).data'}]->(_180145)
CREATE (_180152)-[_546675:TRIGGER {`type`:'success', `$name`:'Counts of visible/selected', `$container.id`:'visibleselected', `#data`:'(%).data'}]->(_180145)
CREATE (_180148)-[_546673:TRIGGER {`$container.id`:'similarrel', `type`:'success', `#data`:'(%).data', `$name`:'Similar relations'}]->(_180145)
WITH COUNT(*) AS foo
MATCH (n:Example_2) RETURN n
Copy the statement to the Cypher panel in InterActor, as described in the first example, and click the [Execute] button. InterActor will process the Cypher and return the interaction diagram.
The diagram contains 4 :IA_Neo4jQuery
nodes, 1 :IA_NetworkView
node and 1 :IA_TableView
node. To view the properties of a node or relationship, select it and see how the properties are displayed in the KeysView panel at the top right.
The node to start the interaction is the :IA_Neo4jQuery
node (blue circle) "Get sample graph". It has a cypher
property, containing
MATCH (n:IA_Function)-[r]->(m) RETURN n,m LIMIT 5
This statement will be executed once the :IA_Neo4jQuery
node is activated.
The :IA_Neo4jQuery
node has a process property set to true, to ensure that the Cypher results are available as nodes and relations to the outgoing trigger to the :IA_NetworkView
.
The trigger with type:success
(only executes when the Cypher executes successfully) carries two arrays #nodes
and #relations
to the :IA_NetworkView
node.
The :IA_NetworkView
node has three outgoing triggers of type:context
. With menu:canvas
, menu:relation
and menu:node
you can define in which contextmenu the option is included. Each of these triggers carries a parameter that is used as an input for the subsequent :IA_Neo4jQuery
node.
All three queries that can be activated from the context-menus send their output to a :IA_TableView
. Note that the :IA_Neo4jQuery
"Extract similar" also sends output to the :IA_NetworkView
. By setting a $container.id
property, we can define whether we want to use a specific container. If the container with that name does not exist yet, it will be created. If this property is omitted, InterActor will create new containers every time the function is triggered.
To run the example, select the "Get sample graph" :IA_Neo4jQuery
node (blue circle) and click the [Execute query] button in the KeysView panel. The Cypher in the :IA_Neo4jQuery
node is executed and the results are returned in a NetworkView.
When you right-click in the "Sample graph" NetworkView on a node , relationship or the canvas, there will be a context-menu. Note that the contextmenu of the canvas also contains two built-in options.
You may also wonder why, when you select nodes in the "Sample graph" NetworkView, their properties do not appear in the KeysView panel, while when selecting nodes in the "Main NetworkView (application)" NetworkView, they do appear.
The reason is that the required interaction between the "Sample graph" :IA_NetworkView
node and the KeysView panel, which is a :IA_HtmlView node
, does not yet exist in your instance. The next example illustrates how you can create such an interaction in an efficient way.