vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

61 lines
1.8 KiB

function parseGephi(gephiJSON, optionsObj) {
var edges = [];
var nodes = [];
var options = {
edges: {
inheritColor: false
},
nodes: {
fixed: false,
parseColor: false
}
};
if (options !== undefined) {
options.nodes['fixed'] = optionsObj.fixed !== undefined ? options.fixed : true;
options.nodes['parseColor'] = optionsObj.parseColor !== undefined ? options.parseColor : false;
options.edges['inheritColor'] = optionsObj.inheritColor !== undefined ? options.inheritColor : false;
}
var gEdges = gephiJSON.edges;
var gNodes = gephiJSON.nodes;
for (var i = 0; i < gEdges.length; i++) {
var edge = {};
var gEdge = gEdges[i];
edge['id'] = gEdge.id;
edge['from'] = gEdge.source;
edge['to'] = gEdge.target;
edge['attributes'] = gEdge.attributes;
// edge['value'] = gEdge.attributes !== undefined ? gEdge.attributes.Weight : undefined;
// edge['width'] = edge['value'] !== undefined ? undefined : edgegEdge.size;
if (gEdge.color && options.inheritColor === false) {
edge['color'] = gEdge.color;
}
edges.push(edge);
}
for (var i = 0; i < gNodes.length; i++) {
var node = {};
var gNode = gNodes[i];
node['id'] = gNode.id;
node['attributes'] = gNode.attributes;
node['title'] = gNode.title;
node['x'] = gNode.x;
node['y'] = gNode.y;
node['label'] = gNode.label;
if (options.nodes.parseColor === true) {
node['color'] = gNode.color;
}
else {
node['color'] = gNode.color !== undefined ? {background:gNode.color, border:gNode.color} : undefined;
}
node['size'] = gNode.size;
node['fixed'] = options.nodes.fixed && gNode.x !== undefined && gNode.y !== undefined;
nodes.push(node);
}
return {nodes:nodes, edges:edges};
}
exports.parseGephi = parseGephi;