-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithubapi.js
116 lines (105 loc) · 3.07 KB
/
githubapi.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
const axios = window.axios;
var datas;
const url = "https://157.245.109.70:8000/";
axios
.get(url, {})
.then((datas) => {
//console.log(datas);
addData(datas);
})
.catch((err) => {
console.log("oops. server down.");
});
p = 0;
q = 1;
reponames = [];
languages = [];
var divId = 1;
function addData(datas) {
len = datas.data.length / 2;
for (var i = 0; i < len; i++) {
// console.log("inloop");
// console.log(datas.data[p], p, q);
reponames.push(datas.data[p]);
languages.push(datas.data[q]);
p += 2;
q += 2;
}
//console.log(reponames, languages);
setTimeout(addElement, 120);
}
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>" +
new Date(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);
}
}