Browse Source

Switched ids on the graph to use usernames instead because of inconsistencies of the id property in github API.

performance-improvements
jrtechs 5 years ago
parent
commit
61849949b8
3 changed files with 23 additions and 26 deletions
  1. +3
    -2
      public/js/createOrgRepoGraph.js
  2. +16
    -20
      public/js/friendsGraph.js
  3. +4
    -4
      routes/api.js

+ 3
- 2
public/js/createOrgRepoGraph.js View File

@ -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));
}
});

+ 16
- 20
public/js/friendsGraph.js View File

@ -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));
}
});
});

+ 4
- 4
routes/api.js View File

@ -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
});
}
}

Loading…
Cancel
Save