-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
129 lines (115 loc) · 3.69 KB
/
index.html
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
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
</head>
<body>
<style>
#curve_chart{
margin: auto;
}
.flex{
display: flex;
flex-direction: row;
justify-content: center;
}
.input{
border: 1px solid #ccc;
padding: 5px;
border-radius: 4px;
}
.button{
background: #F44336;
color: #fff;
border: 1px solid #e91313;
border-radius: 3px;
padding: 7px;
margin-left: 5px;
}
</style>
<div id="form" class="flex">
<input type="text" class="input" id="repovalue" placeholder=":owner/:repo_name" />
<button class="button" id="mapgen">Generate</button>
</div>
<div id="curve_chart" style="width: 900px; height: 500px"></div>
<script>
var Generate = {
repoAddress : "https://api.github.com/repos/tensorflow/tensorflow/stats/commit_activity",
monthsNames : ['Jan','Feb','March','April','May', 'June', 'July', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
commitsByMonth : {},
lastDate: (function(){
var now = new Date();
return new Date(now.setMonth(now.getMonth() - 11));
}()),
drawChart : function(){
console.log(this.repoAddress);
$.get(this.repoAddress, (response)=> {
this.convertToMonthWise(response);
this.generateGraph(this.commitsByMonth);
}).fail(function() {
alert( "No repository found!" );
});
},
setRepoAddr: function(addr){
this.repoAddress = `https://api.github.com/repos/${addr}/stats/commit_activity`;
},
daysInMonth : function(month,year) {
return new Date(year, month, 0).getDate();
},
convertToMonthWise : function(response){
console.log(response);
let prevMonth = 0;
for(let i =0; i < response.length; i++){
let week = response[i];
let tmpDate = new Date(week.week*1000);
let month = tmpDate.getMonth();
let noOfDays = this.daysInMonth(month, tmpDate.getFullYear());
for(let i=0;i<7;i++){
tmpDate.setDate(tmpDate.getDate()+1);
if(tmpDate<this.lastDate){
continue;
}
month = this.monthsNames[tmpDate.getMonth()];
if(this.commitsByMonth[month]){
this.commitsByMonth[month] = this.commitsByMonth[month] + (week.days[i]);
}else{
this.commitsByMonth[month] = (week.days[i]);
}
}
}
console.log(this.commitsByMonth);
},
generateGraph : function (argument) {
var data = new google.visualization.DataTable();
// Declare columns
data.addColumn('string', 'Month');
data.addColumn('number', 'Commits');
var rows = [];
for(prop in argument){
rows.push([ prop , argument[prop] ])
}
data.addRows(rows);
var options = {
title: 'Commit history',
legend: { position: 'bottom' },
pointSize: 8
};
var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
chart.draw(data, options);
},
clearcommitsByMonth : function(){
this.commitsByMonth = {};
}
}
$(function(){
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(Generate.drawChart.bind(Generate));
$("#mapgen").click(()=>{
Generate.clearcommitsByMonth();
Generate.setRepoAddr($("#repovalue").val());
Generate.drawChart();
})
});
</script>
</body>
</html>