Skip to content

Instantly share code, notes, and snippets.

@elisedeux
elisedeux / Linkurious_SDK_Ex1.js
Last active April 4, 2017 08:37
Querying the Linkurious Graph API and displaying the result as a graph visualization with Ogma.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="./lib/ogma.min.js"></script>
<script src="./lib/jquery-3.1.1.min.js"></script>
<style>
#graph-container {
width: 300px;
@elisedeux
elisedeux / Linkurious_SDK_Ex2.js
Last active April 4, 2017 08:38
A query to find and display the shortest path between two nodes using Linkurious REST API.
// Use the REST API to get the shortest path between two customers and render in Ogma
function shortestPath(customer1, customer2) {
// Configure and send the Ajax query asynchronously.
$.ajax({
type: "GET",
// Define the authentication information.
headers: {
"Content-Type": "application/json",
"Authorization": "Basic " + btoa('root@root.com:6160b54b872459ce1c06c1a8ccdd9019')
@elisedeux
elisedeux / Linkurious_SDK_Ex3.js
Last active April 4, 2017 08:38
Retrieving nodes list and displaying the result
// Use the REST API to search for a term
function searchCustomer(term) {
// Configure and send the Ajax query asynchronously.
$.ajax({
type: "GET",
// REST method url
url: "http://localhost:3000/api/1cf9e65b/search/nodes/full",
// Define the authentication information.
headers: {
// Create the class with a low opacity value
ogma.createClass('faded', {
nodeAttributes: { opacity: 0.2 },
edgeAttributes: { opacity: 0.2 }
});
// Select the nodes and edges that must be faded
const nodesToFade = ogma.getNodes().filter(node => node.getData('type') === 'INVESTOR');
const edgesToFade = nodesToFade.getAdjacentEdges();
MATCH (c1:Customer)-[r*1..4]-(c2:Customer)
WHERE ID(c1) = {{"customer":node:"Customer"}}
return c1, r, c2
@elisedeux
elisedeux / Query template used to expand a person's bank account node and its ten highest associated transactions.
Last active May 8, 2018 07:57
Query template used to expand a person's bank account node and its ten highest associated transactions.
MATCH (c:PERSON)-[e1:HAS_BANK_ACCOUNT]->(cc:BANK_ACCOUNT)-[e2:HAS_RECEIVED]->(t:TRANSACTION)
WHERE ID(c) = {{"PERSON":node:"PERSON"}}
RETURN c, e1, cc, e2, t
ORDER BY t.amount DESC
LIMIT 10
@elisedeux
elisedeux / Guest Mode URL Parameters
Created November 9, 2018 13:19
Guest Mode URL Parameters
# Load a node by node ID
/guest?populate=nodeId&item_id=123&key=a1b1c1
# Load an edge and its source and target nodes by edge ID
/guest?populate=edgeId&item_id=123&key=a1b1c1
# Load a node and its neighbors by node ID
/guest?populate=expandNodeId&item_id=123&key=a1b1c1
# Load nodes (by search query)
// 1) match all disputed transactions
match (p:person)-[b:HAS_BOUGHT_AT {status: "Disputed"}]->(m:merchant)
with
collect(p) as disputer, // list of persons with disputed transactions
collect(b) as disputed, // list disputed transactions
collect(m) as merchants // list merchants with disputed transactions
// 2) match all undisputed transactions
match (p:person)-[b:HAS_BOUGHT_AT {status: "Undisputed"}]->(m:merchant)
where p in disputer // keep only transactions where the buyer is a disputer
with // group undisputed transactions by merchant
MATCH p=(a:Company)-[rs:SELLS_TO*]->(c:Company)
WHERE a.country <> c.country
WITH p, a, c, rs, nodes(p) AS ns
WITH p, a, c, rs, filter(n IN ns WHERE n.epoch - 1383123473 < (90*60*60*24)) AS bs
WITH p, a, c, rs, head(bs) AS b
WHERE NOT b IS NULL
WITH p, a, b, c, head(rs) AS r1, last(rs) AS rn
WITH p, a, b, c, r1, rn, rn.epoch - r1.epoch AS d
WHERE d < (15*60*60*24)
RETURN a, b, c, d, r1, rn
MATCH (b:BANK_ACCOUNT)-[e:HAS_TRANSFERED]->(a)
WHERE id(a) = {{"Bank":node:"BANK_ACCOUNT"}} and e.amount > {{"Amount":number:{"min":0}}} and e.date >= {{"Start date":date:"iso"}} and e.date < {{"End date":date:"iso"}}
return a, e, b