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.

59 lines
1.8 KiB

  1. function parseGephi(gephiJSON, optionsObj) {
  2. var edges = [];
  3. var nodes = [];
  4. var options = {
  5. edges: {
  6. inheritColor: true
  7. },
  8. nodes: {
  9. fixed: false,
  10. parseColor: false
  11. }
  12. };
  13. if (options !== undefined) {
  14. options.nodes['fixed'] = optionsObj.fixed !== undefined ? options.fixed : false;
  15. options.nodes['parseColor'] = optionsObj.parseColor !== undefined ? options.parseColor : false;
  16. options.edges['inheritColor'] = optionsObj.inheritColor !== undefined ? options.inheritColor : true;
  17. }
  18. var gEdges = gephiJSON.edges;
  19. var gNodes = gephiJSON.nodes;
  20. for (var i = 0; i < gEdges.length; i++) {
  21. var edge = {};
  22. var gEdge = gEdges[i];
  23. edge['id'] = gEdge.id;
  24. edge['from'] = gEdge.source;
  25. edge['to'] = gEdge.target;
  26. edge['attributes'] = gEdge.attributes;
  27. // edge['value'] = gEdge.attributes !== undefined ? gEdge.attributes.Weight : undefined;
  28. // edge['width'] = edge['value'] !== undefined ? undefined : edgegEdge.size;
  29. edge['color'] = gEdge.color;
  30. edge['inheritColor'] = edge['color'] !== undefined ? false : options.inheritColor;
  31. edges.push(edge);
  32. }
  33. for (var i = 0; i < gNodes.length; i++) {
  34. var node = {};
  35. var gNode = gNodes[i];
  36. node['id'] = gNode.id;
  37. node['attributes'] = gNode.attributes;
  38. node['title'] = gNode.title;
  39. node['x'] = gNode.x;
  40. node['y'] = gNode.y;
  41. node['label'] = gNode.label;
  42. if (options.nodes.parseColor === true) {
  43. node['color'] = gNode.color;
  44. }
  45. else {
  46. node['color'] = gNode.color !== undefined ? {background:gNode.color, border:gNode.color} : undefined;
  47. }
  48. node['size'] = gNode.size;
  49. node['fixed'] = options.nodes.fixed && gNode.x !== undefined && gNode.y !== undefined;
  50. nodes.push(node);
  51. }
  52. return {nodes:nodes, edges:edges};
  53. }
  54. exports.parseGephi = parseGephi;