|  |  | @ -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 = []; | 
			
		
	
	
		
			
				
					|  |  |  |