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.

58 lines
1.7 KiB

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