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, options) {
  2. var edges = [];
  3. var nodes = [];
  4. this.options = {
  5. edges: {
  6. inheritColor: true
  7. },
  8. nodes: {
  9. allowedToMove: false,
  10. parseColor: false
  11. }
  12. };
  13. if (options !== undefined) {
  14. this.options.nodes['allowedToMove'] = options.allowedToMove | false;
  15. this.options.nodes['parseColor'] = options.parseColor | false;
  16. this.options.edges['inheritColor'] = 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 : this.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['x'] = gNode.x;
  39. node['y'] = gNode.y;
  40. node['label'] = gNode.label;
  41. if (this.options.nodes.parseColor == true) {
  42. node['color'] = gNode.color;
  43. }
  44. else {
  45. node['color'] = gNode.color !== undefined ? {background:gNode.color, border:gNode.color} : undefined;
  46. }
  47. node['radius'] = gNode.size;
  48. node['allowedToMoveX'] = this.options.nodes.allowedToMove;
  49. node['allowedToMoveY'] = this.options.nodes.allowedToMove;
  50. nodes.push(node);
  51. }
  52. return {nodes:nodes, edges:edges};
  53. }
  54. exports.parseGephi = parseGephi;