UNPKG

sigma-react

Version:

A JavaScript library dedicated to graph drawing.

1 lines 1.99 kB
(function(a){"use strict";if("undefined"==typeof sigma)throw"sigma is not declared";sigma.utils.pkg("sigma.neo4j"),sigma.utils.pkg("sigma.utils"),sigma.neo4j.send=function(a,b,c,d,e){var f,g,h,i=sigma.utils.xhr();if(f=a,"object"==typeof a&&(f=a.url,g=a.user,h=a.password),!i)throw"XMLHttpRequest not supported, cannot load the file.";f+=b,i.open(c,f,!0),g&&h&&i.setRequestHeader("Authorization","Basic "+btoa(g+":"+h)),i.setRequestHeader("Accept","application/json"),i.setRequestHeader("Content-type","application/json; charset=utf-8"),i.onreadystatechange=function(){4===i.readyState&&e(JSON.parse(i.responseText))},i.send(d)},sigma.neo4j.cypher_parse=function(a,b){var c,d={nodes:[],edges:[]},e={},f={};a.results[0].data.forEach(function(a){a.graph.nodes.forEach(function(a){var c=b.node(a);c.id in e||(e[c.id]=c)}),a.graph.relationships.forEach(function(a){var c=b.edge(a);c.id in f||(f[c.id]=c)})});for(c in e)d.nodes.push(e[c]);for(c in f)d.edges.push(f[c]);return d},sigma.neo4j.cypher=function(a,b,c,d,e){var f,g,h="/db/data/transaction/commit";e||(e=sigma.neo4j.defaultProducers),f=JSON.stringify({statements:[{statement:b,resultDataContents:["graph"],includeStats:!1}]}),g=function(a){return function(b){var d={nodes:[],edges:[]};d=sigma.neo4j.cypher_parse(b,e),c instanceof sigma?(c.graph.clear(),c.graph.read(d)):"object"==typeof c?(c=new sigma(c),c.graph.read(d),c.refresh()):"function"==typeof c&&(a=c,c=null),a&&a(c||d)}},sigma.neo4j.send(a,h,"POST",f,g(d))},sigma.neo4j.getLabels=function(a,b){sigma.neo4j.send(a,"/db/data/labels","GET",null,b)},sigma.neo4j.getTypes=function(a,b){sigma.neo4j.send(a,"/db/data/relationship/types","GET",null,b)},sigma.neo4j.defaultProducers={node:function(a){return{id:a.id,label:a.id,x:Math.random(),y:Math.random(),size:1,color:"#666666",neo4j_labels:a.labels,neo4j_data:a.properties}},edge:function(a){return{id:a.id,label:a.type,source:a.startNode,target:a.endNode,color:"#7D7C8E",neo4j_type:a.type,neo4j_data:a.properties}}}}).call(window);