-
-
Save DGaffney/1c2f1c3c6a9501320e94 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
sigma.publicPrototype.parseJSON = function(jsonPath,callback) { | |
var sigmaInstance = this; | |
jQuery.getJSON(jsonPath, function(data) { | |
for (i=0; i<data.nodes.length; i++){ | |
var nodeNode = data.nodes[i]; | |
var id = nodeNode.id; | |
var label = nodeNode.label; | |
var color = '#'+sigma.tools.rgbToHex(parseFloat(nodeNode.color.r), parseFloat(nodeNode.color.g), parseFloat(nodeNode.color.b)) | |
var x = parseFloat(nodeNode.position.x); | |
var y = parseFloat(nodeNode.position.y); | |
var size = parseFloat(nodeNode.size); | |
var clean_node = {id:id, label:label, color:color, x:x, y:y, attributes:[], size:size}; | |
for (j=0; j < nodeNode.attributes.length; j++){ | |
var raw_attribute = nodeNode.attributes[j]; | |
var attr = raw_attribute.for; | |
var val = raw_attribute.value; | |
clean_node.attributes.push({attr:attr, val:val}); | |
} | |
sigmaInstance.addNode(id, clean_node); | |
}; | |
for(i=0; i<data.edges.length; i++){ | |
var edgeNode = data.edges[i]; | |
var edge = { | |
id: i, | |
sourceID: edgeNode.source, | |
targetID: edgeNode.target, | |
label: edgeNode.label, | |
weight: parseFloat(edgeNode.weight), | |
displaySize: parseFloat(edgeNode.weight), | |
attributes: [] | |
}; | |
for (j=0; j < edgeNode.attributes.length; j++){ | |
var raw_attribute = edgeNode.attributes[j]; | |
var attr = raw_attribute.for; | |
var val = raw_attribute.value; | |
edge.attributes.push({attr:attr, val:val}); | |
} | |
sigmaInstance.addEdge(i, edgeNode.source, edgeNode.target, edge); | |
}; | |
if (callback) callback.call(this); | |
}); | |
}; |
Jeez! Didn't see these messages. Expect a response in a few days from me.
https://gist.github.com/DGaffney/c98d2430b5052630e9a6/raw/5c02bb3198132b1e0ee528141208b4cdc58a6b29/data.json
That is a json file for you!
Hi,
I'm trying to display a graph with sigma.js from data in JSON format. I started from the "parse GEXF" example, converted the "les_miserables.gexf" file with the provided python script, changed the html code to load the sigma.parseJson.js. The graph doesn't show up, I have the following error message in the browser console: "TypeError: 'undefined' is not an object (evaluating 'data.nodes.length') in sigma.parseJson.js". Any idea? Would you have a working example that I could start from instead?
Thanks in advance.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a working example located somewhere that we can explore? Thanks! :)