Website for visualizing a persons github network.
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.

124 lines
2.4 KiB

  1. var nodes;
  2. var edges;
  3. const options = {
  4. nodes: {
  5. borderWidth:4,
  6. size:30,
  7. color: {
  8. border: '#222222',
  9. background: '#666666'
  10. },
  11. font:{color:'#eeeeee'}
  12. },
  13. edges: {
  14. color: 'lightgray'
  15. }
  16. };
  17. function alreadyInGraph(userID)
  18. {
  19. for(var i = 0; i < nodes.length; i++)
  20. {
  21. if(nodes[i].id === userID)
  22. {
  23. return true;
  24. }
  25. }
  26. return false;
  27. }
  28. function addPersonToGraph(profileData)
  29. {
  30. nodes.push(
  31. {
  32. id:profileData.id,
  33. shape: 'circularImage',
  34. image:profileData.avatar_url
  35. });
  36. }
  37. function addFriends(username, apiPath)
  38. {
  39. return new Promise(function(resolve, reject)
  40. {
  41. queryAPIByUser(apiPath, username, function(data)
  42. {
  43. for(var i = 0; i < data.length; i++)
  44. {
  45. if(!alreadyInGraph(data[i].id))
  46. {
  47. addPersonToGraph(data[i]);
  48. }
  49. }
  50. resolve();
  51. },
  52. function(error)
  53. {
  54. reject(error);
  55. })
  56. });
  57. }
  58. function createConnections()
  59. {
  60. return new Promise(function(resolve, reject)
  61. {
  62. resolve();
  63. });
  64. }
  65. function addSelfToGraph(username)
  66. {
  67. return new Promise(function(resolve, reject)
  68. {
  69. queryAPIByUser("", username, function(data)
  70. {
  71. addPersonToGraph(data);
  72. resolve();
  73. },
  74. function(error)
  75. {
  76. reject(error);
  77. });
  78. });
  79. }
  80. function createFriendsGraph(username, containerName, graphsTitle)
  81. {
  82. nodes = [];
  83. edges = [];
  84. addSelfToGraph(username).then(function()
  85. {
  86. addFriends(username, API_FOLLOWERS).then(function()
  87. {
  88. addFriends(username, API_FOLLOWING).then(function()
  89. {
  90. createConnections().then(function()
  91. {
  92. var container = document.getElementById(containerName);
  93. var data =
  94. {
  95. nodes: nodes,
  96. edges: edges
  97. };
  98. var network = new vis.Network(container, data, options);
  99. });
  100. });
  101. })
  102. }).catch(function(error)
  103. {
  104. console.log(error);
  105. $("#" + graphsTitle).html("Error Fetching Data From API");
  106. });
  107. }