1
1
<template >
2
2
<div >
3
- <Line :data =" mainGraphData" :options =" data. options" />
3
+ <Line :data =" mainGraphData" :options =" options" />
4
4
5
5
<div class =" ui attached segment two column grid" >
6
6
<div
9
9
class =" column stats-table"
10
10
>
11
11
<div class =" ui top attached header gt-df gt-f1" >
12
- <b class =" ui right" >#{{index + 1}}</b >
12
+ <b class =" ui right" >#{{ index + 1 }}</b >
13
13
<a :href =" contributor.home_link" >
14
14
<img
15
15
height =" 40"
34
34
</div >
35
35
</div >
36
36
<div class =" ui attached segment" >
37
- <Line :data =" graph(contributor.weeks)" :options =" data. options" />
37
+ <Line :data =" graph(contributor.weeks)" :options =" options" />
38
38
</div >
39
39
</div >
40
40
</div >
@@ -56,6 +56,7 @@ import {
56
56
LineElement ,
57
57
Filler ,
58
58
} from " chart.js" ;
59
+ import zoomPlugin from " chartjs-plugin-zoom" ;
59
60
import { Bar , Line } from " vue-chartjs" ;
60
61
import " chartjs-adapter-dayjs-4/dist/chartjs-adapter-dayjs-4.esm" ;
61
62
@@ -69,23 +70,55 @@ ChartJS.register(
69
70
Legend,
70
71
PointElement,
71
72
LineElement,
72
- Filler
73
+ Filler,
74
+ zoomPlugin
73
75
);
74
76
75
77
const sfc = {
76
78
components: { Line },
77
79
data : () => ({
78
80
data: {
79
- options: {
81
+ },
82
+
83
+ masterChartData: window .config .pageData .repoContributorsCommitStats || [],
84
+ type: window .config .pageData .contributionType ,
85
+ individualChartsData:
86
+ window .config .pageData .repoContributorsCommitStats || [],
87
+ }),
88
+ computed: {
89
+ options () {
90
+ return {
80
91
responsive: true ,
81
92
plugins: {
82
93
legend: {
83
94
display: false ,
84
- }
95
+ },
96
+ zoom: {
97
+ pan: {
98
+ enabled: true ,
99
+ mode: " x" ,
100
+ threshold: 20 ,
101
+ },
102
+ limits: {
103
+ x: {
104
+ min: " original" ,
105
+ max: " original" ,
106
+ minRange: 1000000000 ,
107
+ },
108
+ },
109
+ zoom: {
110
+ wheel: {
111
+ enabled: true ,
112
+ },
113
+ pinch: {
114
+ enabled: true ,
115
+ },
116
+ mode: " x" ,
117
+ },
118
+ },
85
119
},
86
120
scales: {
87
121
x: {
88
- // min: '2021-11-06',
89
122
type: " time" ,
90
123
time: {
91
124
// unit: 'year'
@@ -94,17 +127,11 @@ const sfc = {
94
127
},
95
128
y: {
96
129
min: 0 ,
130
+ max: this .maxMainGraph (),
97
131
},
98
132
},
99
- },
133
+ }
100
134
},
101
-
102
- masterChartData: window .config .pageData .repoContributorsCommitStats || [],
103
- type: window .config .pageData .contributionType ,
104
- individualChartsData:
105
- window .config .pageData .repoContributorsCommitStats || [],
106
- }),
107
- computed: {
108
135
mainGraphData () {
109
136
return {
110
137
datasets: [
@@ -134,6 +161,14 @@ const sfc = {
134
161
},
135
162
},
136
163
methods: {
164
+ maxMainGraph () {
165
+ const maxValue = Math .max (... this .masterChartData [" " ].weeks .map (o => o[this .type ]))
166
+ const [cooefficient , exp ] = maxValue .toExponential ().split (' e' )
167
+ if (Number (cooefficient) % 1 == 0 ) {
168
+ return maxValue
169
+ }
170
+ return (1 - Number (cooefficient) % 1 ) * 10 ** Number (exp) + maxValue
171
+ },
137
172
additions (data ) {
138
173
return Object .values (data).reduce ((acc , item ) => {
139
174
return acc + item .additions ;
0 commit comments