forked from Ashutosh00710/github-readme-activity-graph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
185 lines (175 loc) · 4.91 KB
/
script.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
let valueToCopy = {
username: '',
bgColor: 'ffcfe9',
color: '9e4c98',
line: '9e4c98',
point: '403d3d',
};
/*-------- For displaying loading animation ---------*/
const loader = document.querySelector('.loader');
const setLoader = () => {
loader.classList.add('active');
};
const reomveLoader = () => {
loader.classList.remove('active');
};
//Get submit button
let submitButton = document.getElementById('submit-button');
//on click event
submitButton.addEventListener('click', (event) => {
//get username
event.preventDefault();
var username = document.getElementById('username').value;
if (username.length > 0) {
valueToCopy.username = username;
setLoader();
} else {
alert('Enter your Username');
return;
}
//get user data
axios({
url: `https://activity-graph.herokuapp.com/data?username=${username}`,
method: 'GET',
})
.then((contributionData) => {
console.log(contributionData.data);
let userData = contributionData.data;
var data = {
labels: [...Array(userData.contributions.length + 1).keys()].slice(1),
series: [{ value: userData.contributions }],
};
const options = {
width: 1000,
height: 380,
axisY: {
title: 'Contributions',
onlyInteger: true,
offset: 70,
labelOffset: {
y: 4.5,
},
},
axisX: {
title: 'Days',
offset: 50,
labelOffset: {
x: -4.5,
},
},
chartPadding: {
top: 80,
right: 50,
bottom: 20,
left: 20,
},
showArea: true,
fullWidth: true,
plugins: [
Chartist.plugins.ctAxisTitle({
axisX: {
axisTitle: 'Days',
axisClass: 'ct-axis-title',
offset: {
x: 0,
y: 50,
},
textAnchor: 'middle',
},
axisY: {
axisTitle: 'Contributions',
axisClass: 'ct-axis-title',
offset: {
x: 0,
y: 50,
},
textAnchor: 'middle',
flipTitle: true,
},
}),
],
};
new Chartist.Line('.ct-chart', data, options);
reomveLoader();
})
.catch((err) => {
console.error(err);
reomveLoader();
alert('Sorry! something went wrong.');
});
});
//Dynamic changes
//Background
let bgInput = document.getElementById('bgColor');
bgInput.addEventListener('input', function () {
valueToCopy.bgColor = bgInput.value;
document.querySelector('.rect').style.backgroundColor = bgInput.value;
console.log(`bgInput`, bgInput.value);
});
//line
function line() {
let theInput = document.getElementById('line');
theInput.addEventListener('input', function () {
valueToCopy.line = theInput.value;
document.querySelector('.ct-line').style.stroke = theInput.value;
});
}
//color
function color() {
let theInput = document.getElementById('color');
theInput.addEventListener('input', function () {
valueToCopy.color = theInput.value;
let allLables = document.querySelectorAll('.ct-label');
var index = 0,
length = allLables.length;
for (; index < length; index++) {
allLables[index].style.fill = theInput.value;
allLables[index].style.color = theInput.value;
}
});
theInput.addEventListener('input', function () {
let allLables = document.querySelectorAll('.ct-axis-title');
var index = 0,
length = allLables.length;
for (; index < length; index++) {
allLables[index].style.fill = theInput.value;
}
});
theInput.addEventListener('input', function () {
let allLables = document.querySelectorAll('.ct-grid');
var index = 0,
length = allLables.length;
for (; index < length; index++) {
allLables[index].style.stroke = theInput.value;
}
});
}
//point
function point() {
let pointInput = document.getElementById('point');
pointInput.addEventListener('input', function () {
valueToCopy.point = pointInput.value;
let allPointLables = document.querySelectorAll('.ct-point');
var idx = 0,
len = allPointLables.length;
for (; idx < len; idx++) {
allPointLables[idx].style.stroke = pointInput.value;
}
});
}
//calling
line();
color();
point();
document.querySelector('.copy').addEventListener('click', copyText);
function copyText() {
var copyText = `[}&color=${valueToCopy.color.slice(
1
)}&line=${valueToCopy.line.slice(1)}&point=${valueToCopy.point.slice(
1
)}&area=true&hide_border=true)](https://github.com/ashutosh00710/github-readme-activity-graph)`;
navigator.clipboard.writeText(copyText);
alert('The copied text is: ' + copyText);
}