Browse Source

Merge branch 'master' of https://github.com/jrtechs/github-graphs

pull/11/head
CetaceanNation 5 years ago
parent
commit
f9baece4fb
4 changed files with 83 additions and 21 deletions
  1. +1
    -0
      public/FriendsGraph.html
  2. +20
    -0
      public/js/friendsGraph.js
  3. +62
    -21
      public/js/profileGen.js
  4. +0
    -0
      public/js/repoGen.js

+ 1
- 0
public/FriendsGraph.html View File

@ -64,6 +64,7 @@
<div class="col-md-10 col-12"> <div class="col-md-10 col-12">
<h2 id="graphLabel"></h2> <h2 id="graphLabel"></h2>
<div id="myGraph" class="w-100"></div> <div id="myGraph" class="w-100"></div>
<pre id="eventSpan"></pre>
</div> </div>
<div class="col-md-2 col-12 w-100"> <div class="col-md-2 col-12 w-100">
<div id="profileGen"></div> <div id="profileGen"></div>

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

@ -223,6 +223,17 @@ function addSelfToGraph(username)
} }
function bringUpProfileView(id)
{
for(var i = 0; i < nodes.length; i++)
{
if(nodes[i].id === id)
{
profileGen(nodes[i].name, "profileGen");
}
}
}
/** /**
* Creates a graph * Creates a graph
* @param username * @param username
@ -248,6 +259,15 @@ function createFriendsGraph(username, containerName, graphsTitle)
edges: edges edges: edges
}; };
var network = new vis.Network(container, data, options); var network = new vis.Network(container, data, options);
network.on("click", function (params) {
params.event = "[original event]";
document.getElementById('eventSpan').innerHTML = '<h2>Click event:</h2>' + JSON.stringify(params, null, 4);
if(Number(this.getNodeAt(params.pointer.DOM)) !== NaN)
{
bringUpProfileView(Number(this.getNodeAt(params.pointer.DOM)));
}
});
}); });
}); });
}) })

+ 62
- 21
public/js/profileGen.js View File

@ -1,27 +1,68 @@
function profileGen(username, container) { function profileGen(username, container) {
queryAPIByUser("", username, (data) => {
console.log(data);
html =
"<div> \
<img src=\""+data.avatar_url+"\"></img> \
<h1>"+data.name+"</h1> \
<h2>"+data.login+"</h2> \
<p>Followers: "+data.followers+"</p> \
<p>Following: "+data.following+"</p> \
<p>"+(data.bio != null ? "Bio: "+data.bio : "")+"</p> \
<p>"+(data.location != null ? "Location: "+data.location : "")+"</p> \
<p>"+(data.email != null ? "Email: "+data.email : "")+"</p> \
<p>"+(data.blog != null ? "Site: "+data.blog : "")+"</p> \
<p>"+(data.company != null ? "Company: "+data.company : "")+"</p> \
<a href=\""+data.html_url+"\">"+data.html_url+"</h2> \
<h2></h2> \
</div>"
$("#"+container).html(html);
queryAPIByUser("", username, (user) => {
parseOrgs(user.login).then(function(orgsReturn) {
let html =
"<div> \
<img src=\""+user.avatar_url+"\"></img> \
<h1>"+user.name+"</h1> \
<h2>"+user.login+"</h2> \
<p>Followers: "+user.followers+"</p> \
<p>Following: "+user.following+"</p> \
<p>"+(user.bio != null ? "Bio: "+user.bio : "")+"</p> \
<p>"+(user.location != null ? "Location: "+user.location : "")+"</p> \
<p>"+(user.email != null ? "Email: "+user.email : "")+"</p> \
<p>"+(user.blog != null ? "Site: "+user.blog : "")+"</p> \
<p>"+(user.company != null ? "Company: "+user.company : "")+"</p> \
<p>"+(user.organizations_url != null ? "Organizations: "+orgsReturn: "")+"</p> \
<a href=\""+user.html_url+"\">"+user.html_url+"</h2> \
<h2></h2> \
</div>"
$("#"+container).html(html);
})
}, () => { }, () => {
console.log("error");
console.error("error getting user info");
}); });
} }
function parseOrgs(oranization_url) {
async function parseOrgs(name) {
const urlpath = `api/users/${name}/orgs`;
let orgs_final = [];
await queryUrl(urlpath, async (orgs) => {
orgs.map(org => {
return new Promise(function (res, rej) {
url = org.url;
queryUrl(url, (orgData) => {
orgs_final.push("<a href=\"" + orgData.html_url + "\"><img src=\"" + orgData.avatar_url + "\"></img></a>");
//console.log(orgs_final);
res();
}, () => {
console.error("error getting org info");
});
});
});
console.log(orgs);
await Promise.all(orgs);
}, () => {
console.error("error getting orgs");
});
console.log(orgs_final);
console.log(orgs_final.length);
console.log(orgs_final[0]);
return orgs_final.join(" ");
}
function queryUrl(url, successCallBack, errorCallBack) {
console.log(url);
$.ajax({
type:'GET',
url: url,
crossDomain: true,
dataType: "json",
success: successCallBack,
error:errorCallBack
});
} }

+ 0
- 0
public/js/repoGen.js View File


Loading…
Cancel
Save