Skip to content

Instantly share code, notes, and snippets.

@ntzyz
Created March 2, 2018 12:07
Show Gist options
  • Save ntzyz/c2dc3fc6b145336df3c7a60f812b02bd to your computer and use it in GitHub Desktop.
Save ntzyz/c2dc3fc6b145336df3c7a60f812b02bd to your computer and use it in GitHub Desktop.
diff --git a/js/app.js b/js/app.js
index cb7221c..72ec32f 100644
--- a/js/app.js
+++ b/js/app.js
@@ -74,6 +74,11 @@ var graph = new vis.Network(container, {nodes, edges}, {
shapeProperties: {
useBorderWithImage: true
}
+ },
+ edges: {
+ arrows: {
+ to: { enabled: true}
+ }
}
});
@@ -95,31 +100,40 @@ var addNode = function(id, name, image, dst) {
}
var addEdge = function(n1, n2, dst) {
- if(!dst.get().filter(e => (e.from == n1 && e.to == n2) || (e.from == n2 && e.to == n1)).length)
+ if(!dst.get().filter(e => (e.from == n1 && e.to == n2)).length)
dst.add({from: n1, to: n2});
}
+async function fetchJson (url) {
+ const response = await fetch(url);
+ return await response.json();
+}
+
async function drawRel(id) {
if(visited.includes(id)) return;
working.className = '';
+ let info, foing, foers;
try {
- var info = (await getInfoByIds([id]))[0];
- if (info.communityvisibilitystate != 3) {
- alert(`Error procressing id ${id}: Profile is not public.`);
- working.className = 'hide';
- return;
- }
- var friends = await getFriends(id);
+ [info, foing, foers] = await Promise.all([
+ fetchJson(`https://api.github.com/users/${id}`),
+ fetchJson(`https://api.github.com/users/${id}/following`),
+ fetchJson(`https://api.github.com/users/${id}/followers`),
+ ]);
} catch (e) {
+ console.error(e);
alert(`Error procressing id ${id}: ${e}. Is the ID correct? (use SteamID64, not profile name or custom URL)`);
working.className = 'hide';
return;
}
- addNode(id, info.personaname, info.avatarfull, nodes);
- friends.forEach(f => {
- if (f.communityvisibilitystate != 3) visited.push(f.steamid);
- addNode(f.steamid, f.personaname, f.avatarfull, nodes);
- addEdge(id, f.steamid, edges);
+ addNode(id, info.login, info.avatar_url, nodes);
+
+ foing.forEach(f => {
+ addNode(f.login, f.login, f.avatar_url, nodes);
+ addEdge(id, f.login, edges);
+ });
+ foers.forEach(f => {
+ addNode(f.login, f.login, f.avatar_url, nodes);
+ addEdge(f.login, id, edges);
});
working.className = 'hide';
visited.push(id);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment