-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithubapi1.js
132 lines (121 loc) · 3.74 KB
/
githubapi1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
const axios = window.axios;
console.log(
"The GitHub data you're now seeing is loaded at the instant you visit my website. I'm working on a stable server setup for this."
);
var reponames = [];
var commitlengths = [];
var divId = 1;
var languages = [];
var commitDates = [];
const url = "https://api.github.com/users/karthik4423/repos";
axios.get(url, {}).then(function (datas) {
//console.log(datas.data);
for (var i = 0; i < datas.data.length; i++) {
if (JSON.stringify(datas.data[i].fork) == "false") {
reponames.push([
datas.data[i].updated_at,
datas.data[i].name,
datas.data[i].language,
datas.data[i].description,
datas.data[i].languages_url,
]);
}
}
setTimeout(dateFormatter, 100);
setTimeout(addElement, 1200);
});
function dateFormatter() {
for (i = 0; i < reponames.length; i++) {
reponames[i][0] = new Date(reponames[i][0]);
}
reponames.sort(function (a, b) {
return b[0] - a[0];
});
// console.log(reponames);
getLanguages();
}
function getLanguages() {
for (i = 0; i < 4; i++) {
// console.log("entered for");
// console.log(reponames[i][1]);
axios.get(reponames[i][4], {}).then(function (datas) {
// console.log("yo : ", datas.data);
languages.push(Object.entries(datas.data));
});
}
}
function addElement() {
for (var i = 0; i < 4; i++) {
reponames[i][0] = reponames[i][0].toString().slice(0, 16);
reponames[i][1] = reponames[i][1].replace(/-/g, " ");
reponames[i][1] = reponames[i][1].replace(/_/g, " ");
reponames[i][0] = reponames[i][0].replace(" ", ", ");
newElem = document.createElement("div");
newElem.setAttribute("id", divId);
newElem.setAttribute("class", "card col-8 card-style");
innerElem = document.createElement("div");
innerElem.setAttribute("id", divId + "in");
innerElem.setAttribute("class", "card-body");
innerElem.innerHTML =
"<div>" +
'<h5 class="card-title text-center"> Repo Name : ' +
reponames[i][1] +
"</h5>" +
'<hr class="red"/>' +
"<p><b> Description : </b>" +
reponames[i][3] +
"</p>" +
"<p><b> Languages : </b>" +
reponames[i][2] +
"</p>" +
"<p><b> Last Updated : </b>" +
reponames[i][0] +
"</p>" +
"</div>" +
'<div style="height:inherit;width:auto">' +
'<div id="chart' +
divId +
'" >' +
//style="width: 75%; height: 50%"
//Object.entries(languages[i]) +
"</div>" +
"</div>";
// setTimeout(drawPieChart(divId, i), 200);
newElem.appendChild(innerElem);
document.getElementById("repos").appendChild(newElem);
// console.log(newElem);
// console.log(languages);
divId += 1;
}
for (i = 0; i < 4; i++) {
drawPieChart(languages[i], i + 1, i);
//console.log(reponames[i][1], languages[i]);
}
}
function drawPieChart(langarray, id, i) {
id = "chart" + id;
//console.log(id);
//langarray = [];
google.charts.load("current", { packages: ["corechart"] });
google.charts.setOnLoadCallback(drawChart);
// langarray = Object.entries(languages[i]);
//langarray = languages[i];
langarray.unshift(["Language", "lines"]);
//console.log(langarray);
// Draw the chart and set the chart values
function drawChart() {
let data = google.visualization.arrayToDataTable(langarray);
//console.log(data);
// Optional; add a title and set the width and height of the chart
let options = {
title: "Language Split",
pieHole: 0.4,
height: 50 + "%",
width: 75 + "%",
};
// Display the chart inside the <div> element with id="piechart"
var chart = new google.visualization.PieChart(document.getElementById(id));
chart.draw(data, options);
//chart.draw(data, options);
}
}