Created
April 18, 2016 14:28
-
-
Save paulusm/886d9f2dbf126760c83f3f43bee16f08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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