X-Git-Url: http://iramuteq.org/git?p=iramuteq;a=blobdiff_plain;f=webexport%2Fjs%2Fsigma.parseGexf.js;fp=webexport%2Fjs%2Fsigma.parseGexf.js;h=59945a8bb4ecaf962b16dfb2ed367fe7b2af32d1;hp=0000000000000000000000000000000000000000;hb=a81391287af1ad5ff4f7b69d96d5e0a80fb285a3;hpb=4f2dc8e6823ac5886f758a6ad3f1ae6acb01916c;ds=sidebyside diff --git a/webexport/js/sigma.parseGexf.js b/webexport/js/sigma.parseGexf.js new file mode 100755 index 0000000..59945a8 --- /dev/null +++ b/webexport/js/sigma.parseGexf.js @@ -0,0 +1,160 @@ +// Mathieu Jacomy @ Sciences Po Médialab & WebAtlas +// (requires sigma.js to be loaded) +sigma.publicPrototype.parseGexf = function(gexfPath) { + // Load XML file: + var gexfhttp, gexf; + var sigmaInstance = this; + gexfhttp = window.XMLHttpRequest ? + new XMLHttpRequest() : + new ActiveXObject('Microsoft.XMLHTTP'); + + gexfhttp.overrideMimeType('text/xml'); + gexfhttp.open('GET', gexfPath, false); + gexfhttp.send(); + gexf = gexfhttp.responseXML; + + var viz='http://www.gexf.net/1.2draft/viz'; // Vis namespace + var i, j, k; + + // Parse Attributes + // This is confusing, so I'll comment heavily + var nodesAttributes = []; // The list of attributes of the nodes of the graph that we build in json + var edgesAttributes = []; // The list of attributes of the edges of the graph that we build in json + var attributesNodes = gexf.getElementsByTagName('attributes'); // In the gexf (that is an xml), the list of xml nodes 'attributes' (note the plural 's') + + + for(i = 0; i0){ + sizeNode = sizeNodes[0]; + size = parseFloat(sizeNode.getAttribute('value')); + } + + var positionNodes = nodeNode.getElementsByTagName('position'); + positionNodes = positionNodes.length ? + positionNodes : + nodeNode.getElementsByTagNameNS('*','position'); + if(positionNodes.length>0){ + var positionNode = positionNodes[0]; + x = parseFloat(positionNode.getAttribute('x')); + y = parseFloat(positionNode.getAttribute('y')); + } + + var colorNodes = nodeNode.getElementsByTagName('color'); + colorNodes = colorNodes.length ? + colorNodes : + nodeNode.getElementsByTagNameNS('*','color'); + if(colorNodes.length>0){ + colorNode = colorNodes[0]; + color = '#'+sigma.tools.rgbToHex(parseFloat(colorNode.getAttribute('r')), + parseFloat(colorNode.getAttribute('g')), + parseFloat(colorNode.getAttribute('b'))); + } + + // Create Node + var node = {label:label, size:size, x:x, y:y, attributes:[], color:color}; // The graph node + + // Attribute values + var attvalueNodes = nodeNode.getElementsByTagName('attvalue'); + for(k=0; k