Skip to content

Instantly share code, notes, and snippets.

@tingletech
Created February 19, 2011 21:43
Show Gist options
  • Select an option

  • Save tingletech/835395 to your computer and use it in GitHub Desktop.

Select an option

Save tingletech/835395 to your computer and use it in GitHub Desktop.
graphdracula rexster example
//Show UCLA CS class dependencies (not complete)
// derived from classes.js example that ships with http://www.graphdracula.net/
$(document).ready(function() {
var rexsterAPI = "http://localhost:8182/";
var width = $(document).width();
var height = $(document).height();
var g = new Graph();
g.edgeFactory.template.style.directed = true;
indicesUrl = rexsterAPI + 'snac/indices/name-idx?key=identity&value=';
identity = "Sierra Club."
// identity = "Eisenhower, Dwight D. (Dwight David), 1890-1969."
// look up node id
var nodeId;
$.ajax({
url: indicesUrl + encodeURIComponent(identity),
async: false,
dataType: "json",
success: function (data) {
nodeId = data.results[0]._id
}
});
var edges = [];
$.ajax({
url: rexsterAPI + "snac/vertices/" + nodeId + '/inE',
async: false,
dataType: "json",
success: function (data) {
arr = data.results // loop through rexster results array
for(var i=0,len=arr.length; value=arr[i], i<len; i++) {
// g.addEdge(value.from_name, value.to_name, { arcrole: value._label })
edges.push( [ value.from_name, value.to_name, value._label ] );
}
}
});
for(var i=0,len=edges.length; value=edges[i], i<len; i++) {
g.addEdge(edges[i][0], edges[i][1]);
console.log(edges[i][0], edges[i][1]);
}
var layouter = new Graph.Layout.Ordered(g, topological_sort(g));
layouter.layout();
var renderer = new Graph.Renderer.Raphael('canvas', g, width, height);
renderer.draw();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment