Skip to content

Instantly share code, notes, and snippets.

@paulusm
Created April 18, 2016 14:28
Show Gist options
  • Save paulusm/886d9f2dbf126760c83f3f43bee16f08 to your computer and use it in GitHub Desktop.
Save paulusm/886d9f2dbf126760c83f3f43bee16f08 to your computer and use it in GitHub Desktop.
// The user list
var nodes=[
{id:"Bob", label:"Bob", url:"http://www.example.org/~bob"},
{id:"Alice", label:"Alice", url:"http://www.example.org/~alice"},
{id:"Fred", label:"Fred", url:"http://www.example.org/~fred"},
];
var edges = [];
$().ready(function(){
$("#content").append("<img src=\"img/ajax-loader2.gif\" style=\"position:absolute; top:300px; left:300px;\">");
//loop through
for(var i=0; i<nodes.length; i++){
xfnScan(nodes[i]);
}
});
$(document).ajaxStop(function() {
$("#content").empty();
console.log("Ajax stop");
// create a network
var container = document.getElementById('viz');
options = {
stabilize: false,
edges: {
width: 2,
style: 'arrow',
color: 'gray'
}
}
var data = {
nodes: nodes,
edges: edges
};
var network = new vis.Network(container, data, options);
});
function xfnScan(node){
//console.log(node);
$.ajax({
url: node.url,
cache: false,
accepts: "text/html"
})
.done(function(data) {
$(data).find("a[rel]").each(function(){
console.log(node.id, this.rel, getNodeFromLink(this.href));
edges.push({from:node.id, to: getNodeFromLink(this.href)});
});
});
}
function getNodeFromLink(theLink){
for(var i=0; i<nodes.length; i++){
if(theLink === nodes[i].url || theLink.substring(0, theLink.length - 1) === nodes[i].url ){
return nodes[i].id;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment