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.

178 lines
3.6 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. name:profileData.login,
  34. shape: 'circularImage',
  35. image:profileData.avatar_url
  36. });
  37. }
  38. function addFriends(username, apiPath)
  39. {
  40. return new Promise(function(resolve, reject)
  41. {
  42. queryAPIByUser(apiPath, username, function(data)
  43. {
  44. for(var i = 0; i < data.length; i++)
  45. {
  46. if(!alreadyInGraph(data[i].id))
  47. {
  48. addPersonToGraph(data[i]);
  49. }
  50. }
  51. resolve();
  52. },
  53. function(error)
  54. {
  55. reject(error);
  56. })
  57. });
  58. }
  59. function addConnection(person1, person2)
  60. {
  61. edges.push(
  62. {
  63. from: person1.id,
  64. to: person2.id
  65. });
  66. }
  67. function processUserConnections(userName)
  68. {
  69. return new Promise(function(resolve, reject)
  70. {
  71. queryAPIByUser(API_FOLLOWING, userName,
  72. function(data)
  73. {
  74. for(var i = 0; i < data.length; i++)
  75. {
  76. }
  77. queryAPIByUser(API_FOLLOWERS, userName, function(data2)
  78. {
  79. for(var i = 0; i < data2.length; i++)
  80. {
  81. }
  82. resolve();
  83. },
  84. function(error)
  85. {
  86. reject(error);
  87. });
  88. },
  89. function(error)
  90. {
  91. reject(error);
  92. })
  93. });
  94. }
  95. function createConnections()
  96. {
  97. return new Promise(function(resolve, reject)
  98. {
  99. var prom = [];
  100. for(var i = 0; i < nodes.length; i++)
  101. {
  102. prom.push(processUserConnections(nodes[i].name));
  103. }
  104. Promise.all(prom).then(function()
  105. {
  106. resolve();
  107. }).catch(function(error)
  108. {
  109. reject(error);
  110. });
  111. });
  112. }
  113. function addSelfToGraph(username)
  114. {
  115. return new Promise(function(resolve, reject)
  116. {
  117. queryAPIByUser("", username, function(data)
  118. {
  119. addPersonToGraph(data);
  120. resolve();
  121. },
  122. function(error)
  123. {
  124. reject(error);
  125. });
  126. });
  127. }
  128. function createFriendsGraph(username, containerName, graphsTitle)
  129. {
  130. nodes = [];
  131. edges = [];
  132. addSelfToGraph(username).then(function()
  133. {
  134. addFriends(username, API_FOLLOWERS).then(function()
  135. {
  136. addFriends(username, API_FOLLOWING).then(function()
  137. {
  138. createConnections().then(function()
  139. {
  140. var container = document.getElementById(containerName);
  141. var data =
  142. {
  143. nodes: nodes,
  144. edges: edges
  145. };
  146. var network = new vis.Network(container, data, options);
  147. });
  148. });
  149. })
  150. }).catch(function(error)
  151. {
  152. console.log(error);
  153. $("#" + graphsTitle).html("Error Fetching Data From API");
  154. });
  155. }