From 61849949b820f265daa57b93ca13f00ef38f17ca Mon Sep 17 00:00:00 2001 From: jrtechs Date: Sat, 28 Dec 2019 11:52:24 -0500 Subject: [PATCH] Switched ids on the graph to use usernames instead because of inconsistencies of the id property in github API. --- public/js/createOrgRepoGraph.js | 5 +++-- public/js/friendsGraph.js | 36 +++++++++++++++------------------ routes/api.js | 8 ++++---- 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/public/js/createOrgRepoGraph.js b/public/js/createOrgRepoGraph.js index be50a91..93880d4 100644 --- a/public/js/createOrgRepoGraph.js +++ b/public/js/createOrgRepoGraph.js @@ -62,8 +62,9 @@ function createOrgRepoGraph(orgname, containerName, graphsTitle) var network = new vis.Network(container, data, options); network.on("click", function (params) { params.event = "[original event]"; - if(Number(this.getNodeAt(params.pointer.DOM)) !== NaN) { - bringUpProfileView(Number(this.getNodeAt(params.pointer.DOM))); + if(this.getNodeAt(params.pointer.DOM) !== NaN) + { + bringUpProfileView(this.getNodeAt(params.pointer.DOM)); } }); diff --git a/public/js/friendsGraph.js b/public/js/friendsGraph.js index 794d4fb..570975e 100644 --- a/public/js/friendsGraph.js +++ b/public/js/friendsGraph.js @@ -37,11 +37,11 @@ var options = { * @param userID * @returns {boolean} */ -function alreadyInGraph(userID) +function alreadyInGraph(username) { for(var i = 0; i < nodes.length; i++) { - if(nodes[i].id === userID) + if(nodes[i].id === username) { return true; } @@ -59,8 +59,7 @@ function addPersonToGraph(profileData) { nodes.push( { - id:profileData.id, - name:profileData.login, + id:profileData.login, shape: 'circularImage', image:profileData.avatar_url }); @@ -84,7 +83,7 @@ function addFriends(username) { for(var i = 0; i < data.length; i++) { - if(!alreadyInGraph(data[i].id)) + if(!alreadyInGraph(data[i].login)) { addPersonToGraph(data[i]); } @@ -110,11 +109,8 @@ function edgeInGraph(id1, id2) { for(var i = 0;i < edges.length; i++) { - if(edges[i].from === id1 && edges[i].to === id2) - { - return true; - } - if(edges[i].to === id1 && edges[i].from === id2) + if((edges[i].to === id1 && edges[i].from === id2) || + (edges[i].from === id1 && edges[i].to === id2)) { return true; } @@ -131,14 +127,14 @@ function edgeInGraph(id1, id2) */ function addConnection(person1, person2) { - if(person1.id !== person2.id) + if(person1.login !== person2.login) { - if(alreadyInGraph(person2.id) && !edgeInGraph(person1.id, person2.id)) + if(alreadyInGraph(person2.login) && !edgeInGraph(person1.id, person2.login)) { edges.push( { from: person1.id, - to: person2.id + to: person2.login }); } } @@ -156,7 +152,7 @@ function processUserConnections(user) return new Promise(function(resolve, reject) { updateProgress(); - getFriendsAPI(user.name, + getFriendsAPI(user.id, (data)=> { for(var i = 0; i < data.length; i++) @@ -168,7 +164,7 @@ function processUserConnections(user) { console.log(error); resolve(); - }) + }); }); } @@ -227,7 +223,7 @@ function addSelfToGraph(username) { queryAPIByUser("", username, (data)=> { - baseID = data.id; + baseID = data.login; total = (data.followers + data.following); addPersonToGraph(data); resolve(); @@ -245,13 +241,13 @@ function addSelfToGraph(username) * * @param github id */ -function bringUpProfileView(id) +function bringUpProfileView(uname) { for(var i = 0; i < nodes.length; i++) { - if(nodes[i].id === id) + if(nodes[i].id === uname) { - profileGen(nodes[i].name, "profileGen"); + profileGen(nodes[i].id, "profileGen"); } } } @@ -289,7 +285,7 @@ function createFriendsGraph(username, containerName, progressBarID) { if(Number(this.getNodeAt(params.pointer.DOM)) !== NaN) { - bringUpProfileView(Number(this.getNodeAt(params.pointer.DOM))); + bringUpProfileView(this.getNodeAt(params.pointer.DOM)); } }); }); diff --git a/routes/api.js b/routes/api.js index fe23ef8..393ea85 100644 --- a/routes/api.js +++ b/routes/api.js @@ -78,7 +78,7 @@ const API_FOLLOWERS = "/followers"; const API_USER_PATH = "/users/"; const API_PAGINATION_SIZE = 100; // 100 is the max, 30 is the default // if this is too large, it would be infeasible to make graphs for people following popular people -const API_MAX_PAGES = 3; +const API_MAX_PAGES = 2; const API_PAGINATION = "&per_page=" + API_PAGINATION_SIZE; @@ -118,6 +118,7 @@ function fetchAllUsers(username, apiPath, page, lst) } else { + console.log(data); reject("Malformed data"); } }).catch((err)=> @@ -156,9 +157,8 @@ function minimizeFriends(people) { ids.add(people[i].id); friendLst.push({ - id: people[i].id, - login: people[i].login, - avatar_url: people[i].avatar_url + login: people[i].login, + avatar_url: people[i].avatar_url }); } }