1
1
<template >
2
2
<div >
3
- <Line :data =" toGraphData(totalStats.weeks, 'main')" :options =" getOptions('main')" />
3
+ <Line
4
+ v-if =" Object.keys(totalStats).length !== 0"
5
+ :data =" toGraphData(totalStats.weeks, 'main')"
6
+ :options =" getOptions('main')"
7
+ />
4
8
5
9
<div class =" ui attached segment two column grid" >
6
10
<div
21
25
<div class =" gt-ml-3" >
22
26
<a :href =" contributor.home_link" ><h4 >{{ contributor.name }}</h4 ></a >
23
27
<p class =" gt-font-12" >
24
- <strong >{{ contributor.total_commits.toLocaleString() }} commits </strong >
28
+ <strong >{{ contributor.total_commits.toLocaleString() }} commits
29
+ </strong >
25
30
<strong class =" text green" >{{ additions(contributor.weeks).toLocaleString() }}++
26
31
</strong >
27
32
<strong class =" text red" >
30
35
</div >
31
36
</div >
32
37
<div class =" ui attached segment" >
33
- <Line :data =" toGraphData(contributor.weeks, 'contributor')" :options =" getOptions('contributor')" />
38
+ <Line
39
+ :data =" toGraphData(contributor.weeks, 'contributor')"
40
+ :options =" getOptions('contributor')"
41
+ />
34
42
</div >
35
43
</div >
36
44
</div >
@@ -56,6 +64,8 @@ import zoomPlugin from 'chartjs-plugin-zoom';
56
64
import {Line } from ' vue-chartjs' ;
57
65
import ' chartjs-adapter-dayjs-4/dist/chartjs-adapter-dayjs-4.esm' ;
58
66
67
+ const {pageData } = window .config ;
68
+
59
69
Chart .register (
60
70
TimeScale,
61
71
CategoryScale,
@@ -72,25 +82,51 @@ Chart.register(
72
82
73
83
const sfc = {
74
84
components: {Line},
75
- data : () => ({
76
- totalStats: window .config .pageData .repoTotalStats || [],
77
- type: window .config .pageData .contributionType ,
78
- contributorsStats:
79
- window .config .pageData .repoContributorsStats || [],
80
- }),
85
+ data : () => {
86
+ return {
87
+ isLoading: false ,
88
+ totalStats: {},
89
+ repoLink: pageData .repoLink || [],
90
+ type: pageData .contributionType ,
91
+ contributorsStats: [],
92
+ };
93
+ },
94
+ mounted () {
95
+ this .fetchGraphData ();
96
+ },
81
97
computed: {
82
98
sortedContributors () {
83
99
return Object .values (this .contributorsStats )
84
- .sort ((a , b ) => (a .total_commits > b .total_commits ? - 1 : a .total_commits === b .total_commits ? 0 : 1 ))
100
+ .sort ((a , b ) =>
101
+ a .total_commits > b .total_commits ?
102
+ - 1 :
103
+ a .total_commits === b .total_commits ?
104
+ 0 :
105
+ 1
106
+ )
85
107
.slice (0 , 100 );
86
108
},
87
109
},
88
110
methods: {
111
+ async fetchGraphData () {
112
+ this .isLoading = true ;
113
+ fetch (` /api/v1/repos/${ this .repoLink } /contributors` )
114
+ .then ((response ) => response .json ())
115
+ .then ((data ) => {
116
+ const {Total , ... rest } = data;
117
+ this .contributorsStats = rest;
118
+ this .totalStats = Total;
119
+ this .isLoading = false ;
120
+ });
121
+ },
89
122
maxMainGraph () {
90
123
const maxValue = Math .max (
91
124
... this .totalStats .weeks .map ((o ) => o[this .type ])
92
125
);
93
- const [cooefficient , exp ] = maxValue .toExponential ().split (' e' ).map (Number );
126
+ const [cooefficient , exp ] = maxValue
127
+ .toExponential ()
128
+ .split (' e' )
129
+ .map (Number );
94
130
if (cooefficient % 1 === 0 ) {
95
131
return maxValue;
96
132
}
@@ -117,7 +153,10 @@ const sfc = {
117
153
pointRadius: 0 ,
118
154
pointHitRadius: 0 ,
119
155
fill: ' start' ,
120
- backgroundColor: type === ' main' ? ' rgba(137, 191, 154, 0.6)' : ' rgba(96, 153, 38, 0.7)' ,
156
+ backgroundColor:
157
+ type === ' main' ?
158
+ ' rgba(137, 191, 154, 0.6)' :
159
+ ' rgba(96, 153, 38, 0.7)' ,
121
160
borderWidth: 0 ,
122
161
tension: 0.3 ,
123
162
},
@@ -157,7 +196,7 @@ const sfc = {
157
196
mode: ' x' ,
158
197
threshold: 20 ,
159
198
160
- onPan: this .updateOtherCharts
199
+ onPan: this .updateOtherCharts ,
161
200
},
162
201
limits: {
163
202
x: {
@@ -175,7 +214,7 @@ const sfc = {
175
214
},
176
215
mode: ' x' ,
177
216
178
- onZoomComplete: this .updateOtherCharts
217
+ onZoomComplete: this .updateOtherCharts ,
179
218
},
180
219
},
181
220
},
0 commit comments