1+ const themes = {
2+ default : {
3+ backgroundColor : [
4+ 'rgba(54, 162, 235, 0.2)' ,
5+ 'rgba(255, 206, 86, 0.2)'
6+ ] ,
7+ borderColor : [
8+ 'rgba(54, 162, 235, 1)' ,
9+ 'rgba(255, 206, 86, 1)'
10+ ]
11+ } ,
12+ dark : {
13+ backgroundColor : [
14+ 'rgba(54, 54, 54, 0.2)' ,
15+ 'rgba(77, 77, 77, 0.2)'
16+ ] ,
17+ borderColor : [
18+ 'rgba(54, 54, 54, 1)' ,
19+ 'rgba(77, 77, 77, 1)'
20+ ]
21+ } ,
22+ light : {
23+ backgroundColor : [
24+ 'rgba(200, 200, 200, 0.2)' ,
25+ 'rgba(220, 220, 220, 0.2)'
26+ ] ,
27+ borderColor : [
28+ 'rgba(200, 200, 200, 1)' ,
29+ 'rgba(220, 220, 220, 1)'
30+ ]
31+ } ,
32+ colorful : {
33+ backgroundColor : [
34+ 'rgba(255, 99, 132, 0.2)' ,
35+ 'rgba(75, 192, 192, 0.2)'
36+ ] ,
37+ borderColor : [
38+ 'rgba(255, 99, 132, 1)' ,
39+ 'rgba(75, 192, 192, 1)'
40+ ]
41+ }
42+ } ;
43+
144document . getElementById ( 'repoForm' ) . addEventListener ( 'submit' , function ( event ) {
245 event . preventDefault ( ) ;
346 const username = document . getElementById ( 'username' ) . value ;
447 const repository = document . getElementById ( 'repository' ) . value ;
48+ const theme = document . getElementById ( 'theme' ) . value ;
549
650 fetch ( `https://api.github.com/repos/${ username } /${ repository } ` )
751 . then ( response => response . json ( ) )
852 . then ( data => {
953 const forks = data . forks_count ;
1054 const stars = data . stargazers_count ;
55+ const themeColors = themes [ theme ] ;
1156
1257 const ctx = document . getElementById ( 'forksStarsChart' ) . getContext ( '2d' ) ;
1358 if ( window . forksStarsChart instanceof Chart ) {
@@ -20,19 +65,14 @@ document.getElementById('repoForm').addEventListener('submit', function(event) {
2065 datasets : [ {
2166 label : 'Count' ,
2267 data : [ forks , stars ] ,
23- backgroundColor : [
24- 'rgba(54, 162, 235, 0.2)' ,
25- 'rgba(255, 206, 86, 0.2)'
26- ] ,
27- borderColor : [
28- 'rgba(54, 162, 235, 1)' ,
29- 'rgba(255, 206, 86, 1)'
30- ] ,
68+ backgroundColor : themeColors . backgroundColor ,
69+ borderColor : themeColors . borderColor ,
3170 borderWidth : 1
3271 } ]
3372 } ,
3473 options : {
3574 responsive : true ,
75+ maintainAspectRatio : false ,
3676 scales : {
3777 y : {
3878 beginAtZero : true ,
@@ -44,7 +84,7 @@ document.getElementById('repoForm').addEventListener('submit', function(event) {
4484 x : {
4585 title : {
4686 display : true ,
47- text : 'Metric'
87+ text : repository
4888 }
4989 }
5090 }
@@ -61,4 +101,4 @@ document.getElementById('downloadButton').addEventListener('click', function() {
61101 link . href = window . forksStarsChart . toBase64Image ( ) ;
62102 link . download = 'forks-stars-chart.png' ;
63103 link . click ( ) ;
64- } ) ;
104+ } ) ;
0 commit comments