Browse Source

Got the base graph functionality working.

pull/11/head
Jeffery Russell 5 years ago
parent
commit
78cf78a13f
5 changed files with 103 additions and 28 deletions
  1. BIN
      public/img/graphExample.png
  2. +91
    -11
      public/js/friendsGraph.js
  3. +0
    -1
      public/js/githubAPI.js
  4. +12
    -13
      routes/api.js
  5. +0
    -3
      server.js

BIN
public/img/graphExample.png View File

Before After
Width: 1292  |  Height: 1418  |  Size: 765 KiB

+ 91
- 11
public/js/friendsGraph.js View File

@ -19,6 +19,13 @@ const options = {
}
};
/**
* Checks if a user is a node in the graph
*
* @param userID
* @returns {boolean}
*/
function alreadyInGraph(userID)
{
for(var i = 0; i < nodes.length; i++)
@ -32,6 +39,11 @@ function alreadyInGraph(userID)
}
/**
* adds a person to the nodes list
*
* @param profileData
*/
function addPersonToGraph(profileData)
{
nodes.push(
@ -43,6 +55,15 @@ function addPersonToGraph(profileData)
});
}
/**
* Adds the followers/following of a person
* to the graph
*
* @param username
* @param apiPath
* @returns {Promise<any>}
*/
function addFriends(username, apiPath)
{
return new Promise(function(resolve, reject)
@ -66,34 +87,75 @@ function addFriends(username, apiPath)
}
/**
* Greedy function which checks to see if a edge is in the graphs
*
* @param id1
* @param id2
* @returns {boolean}
*/
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)
{
return true;
}
}
return false;
}
/**
* Adds a connection to the graph
*
* @param person1
* @param person2
*/
function addConnection(person1, person2)
{
edges.push(
if(person1.id !== person2.id)
{
if(alreadyInGraph(person2.id) && !edgeInGraph(person1.id, person2.id))
{
from: person1.id,
to: person2.id
});
edges.push(
{
from: person1.id,
to: person2.id
});
}
}
}
function processUserConnections(userName)
/**
* Processes all the connections of a user and adds them to the graph
*
* @param user has .id and .name
* @returns {Promise<any>}
*/
function processUserConnections(user)
{
return new Promise(function(resolve, reject)
{
queryAPIByUser(API_FOLLOWING, userName,
queryAPIByUser(API_FOLLOWING, user.name,
function(data)
{
for(var i = 0; i < data.length; i++)
{
addConnection(user, data[i])
}
queryAPIByUser(API_FOLLOWERS, userName, function(data2)
queryAPIByUser(API_FOLLOWERS, user.name, function(data2)
{
for(var i = 0; i < data2.length; i++)
{
addConnection(user, data2[i]);
}
resolve();
},
@ -109,6 +171,13 @@ function processUserConnections(userName)
});
}
/**
* Creates connections between all the nodes in
* the graph.
*
* @returns {Promise<any>}
*/
function createConnections()
{
return new Promise(function(resolve, reject)
@ -116,7 +185,7 @@ function createConnections()
var prom = [];
for(var i = 0; i < nodes.length; i++)
{
prom.push(processUserConnections(nodes[i].name));
prom.push(processUserConnections(nodes[i]));
}
Promise.all(prom).then(function()
@ -130,6 +199,12 @@ function createConnections()
}
/**
* Adds the base person to the graph.
*
* @param username
* @returns {Promise<any>}
*/
function addSelfToGraph(username)
{
return new Promise(function(resolve, reject)
@ -148,7 +223,12 @@ function addSelfToGraph(username)
}
/**
* Creates a graph
* @param username
* @param containerName
* @param graphsTitle
*/
function createFriendsGraph(username, containerName, graphsTitle)
{
nodes = [];

+ 0
- 1
public/js/githubAPI.js View File

@ -32,7 +32,6 @@ const API_ORGANIZATIONS = "/orgs";
*/
function queryAPIByUser(apiPath, user, successCallBack, errorCallBack) {
const urlpath = APIROOT + API_USER_PATH + user + apiPath;
console.log(urlpath);
$.ajax({
type:'GET',
url: urlpath,

+ 12
- 13
routes/api.js View File

@ -25,18 +25,17 @@ function queryGitHubAPI(requestURL)
{
if(apiData == null)
{
const queryRUL = GITHUB_API + requestURL + authenticate;
got(queryRUL, { json: true }).then(response =>
{
resolve(response.body);
cache.put(requestURL, response.body);
}).catch(error =>
{
resolve(response.body);
cache.put(requestURL, response.body);
});
const queryRUL = GITHUB_API + requestURL + authenticate;
got(queryRUL, { json: true }).then(response =>
{
resolve(response.body);
cache.put(requestURL, response.body);
}).catch(error =>
{
resolve(response.body);
cache.put(requestURL, response.body);
});
}
else
@ -47,11 +46,11 @@ function queryGitHubAPI(requestURL)
}
routes.get('/*', (request, result) =>
{
const gitHubAPIURL = request.url;
result.setHeader('Content-Type', 'application/json');
queryGitHubAPI(gitHubAPIURL).then(function(data)
{
result.write(JSON.stringify(data));

+ 0
- 3
server.js View File

@ -25,9 +25,6 @@ const routes = require('./routes');
app.use('/', routes);
app.listen(configLoader.getConfiguration().port, () =>
console.log(`App listening on port ${configLoader.getPort()}!`)
);

Loading…
Cancel
Save