Skip to content

Instantly share code, notes, and snippets.

@ikwattro
Created May 16, 2015 22:14
Show Gist options
  • Save ikwattro/2ed7bb06f65dde909dba to your computer and use it in GitHub Desktop.
Save ikwattro/2ed7bb06f65dde909dba to your computer and use it in GitHub Desktop.
From NeoClient to Vis.js
$q = 'MATCH (n) OPTIONAL MATCH (n)-[r]-() RETURN r,n';
$result = $neoclient->sendCypherQuery($q)->getResult();
$graph = [];
foreach ($result->getNodes() as $node) {
$graph['nodes'][] = [
'id' => $node->getId(),
'label' => $node->getLabels()[0],
'group' => $node->getLabels()[0],
'properties' => $node->getProperties()
];
}
foreach ($result->getRelationships() as $rel) {
$graph['edges'][] = [
'id' => $rel->getId(),
'from' => $rel->getStartNode()->getId(),
'to' => $rel->getEndNode()->getId(),
'label' => $rel->getType()
]
}
return json_encode($graph);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment