99 PointElement ,
1010 LineElement ,
1111 Filler ,
12+ type ChartOptions ,
13+ type ChartData ,
14+ type Plugin ,
1215} from ' chart.js' ;
1316import {GET } from ' ../modules/fetch.ts' ;
1417import zoomPlugin from ' chartjs-plugin-zoom' ;
@@ -22,8 +25,9 @@ import {chartJsColors} from '../utils/color.ts';
2225import {sleep } from ' ../utils.ts' ;
2326import ' chartjs-adapter-dayjs-4/dist/chartjs-adapter-dayjs-4.esm' ;
2427import {fomanticQuery } from ' ../modules/fomantic/base.ts' ;
28+ import type {Entries } from ' type-fest' ;
2529
26- const customEventListener = {
30+ const customEventListener: Plugin = {
2731 id: ' customEventListener' ,
2832 afterEvent : (chart , args , opts ) => {
2933 // event will be replayed from chart.update when reset zoom,
@@ -65,10 +69,10 @@ export default {
6569 data : () => ({
6670 isLoading: false ,
6771 errorText: ' ' ,
68- totalStats: {},
69- sortedContributors: {},
72+ totalStats: {} as Record < string , any > ,
73+ sortedContributors: {} as Record < string , any > ,
7074 type: ' commits' ,
71- contributorsStats: [] ,
75+ contributorsStats: {} as Record < string , any > ,
7276 xAxisStart: null ,
7377 xAxisEnd: null ,
7478 xAxisMin: null ,
@@ -99,7 +103,7 @@ export default {
99103 async fetchGraphData() {
100104 this .isLoading = true ;
101105 try {
102- let response;
106+ let response: Response ;
103107 do {
104108 response = await GET (` ${this .repoLink }/activity/contributors/data ` );
105109 if (response .status === 202 ) {
@@ -112,15 +116,15 @@ export default {
112116 // below line might be deleted if we are sure go produces map always sorted by keys
113117 total .weeks = Object .fromEntries (Object .entries (total .weeks ).sort ());
114118
115- const weekValues = Object .values (total .weeks );
119+ const weekValues = Object .values (total .weeks ) as any ;
116120 this .xAxisStart = weekValues [0 ].week ;
117121 this .xAxisEnd = firstStartDateAfterDate (new Date ());
118122 const startDays = startDaysBetween (this .xAxisStart , this .xAxisEnd );
119123 total .weeks = fillEmptyStartDaysWithZeroes (startDays , total .weeks );
120124 this .xAxisMin = this .xAxisStart ;
121125 this .xAxisMax = this .xAxisEnd ;
122126 this .contributorsStats = {};
123- for (const [email, user] of Object .entries (rest )) {
127+ for (const [email, user] of Object .entries (rest ) as Entries < Record < string , Record < string , any >>> ) {
124128 user .weeks = fillEmptyStartDaysWithZeroes (startDays , user .weeks );
125129 this .contributorsStats [email ] = user ;
126130 }
@@ -146,7 +150,7 @@ export default {
146150 user .total_additions = 0 ;
147151 user .total_deletions = 0 ;
148152 user .max_contribution_type = 0 ;
149- const filteredWeeks = user .weeks .filter ((week ) => {
153+ const filteredWeeks = user .weeks .filter ((week : Record < string , number > ) => {
150154 const oneWeek = 7 * 24 * 60 * 60 * 1000 ;
151155 if (week .week >= this .xAxisMin - oneWeek && week .week <= this .xAxisMax + oneWeek ) {
152156 user .total_commits += week .commits ;
@@ -195,7 +199,7 @@ export default {
195199 return (1 - (coefficient % 1 )) * 10 ** exp + maxValue ;
196200 },
197201
198- toGraphData(data ) {
202+ toGraphData(data : Array < Record < string , any >>) : ChartData < ' line ' > {
199203 return {
200204 datasets: [
201205 {
@@ -211,9 +215,9 @@ export default {
211215 };
212216 },
213217
214- updateOtherCharts(event , reset ) {
215- const minVal = event . chart .options .scales .x .min ;
216- const maxVal = event . chart .options .scales .x .max ;
218+ updateOtherCharts({ chart } : {chart : Chart } , reset ? : boolean = false ) {
219+ const minVal = chart .options .scales .x .min ;
220+ const maxVal = chart .options .scales .x .max ;
217221 if (reset ) {
218222 this .xAxisMin = this .xAxisStart ;
219223 this .xAxisMax = this .xAxisEnd ;
@@ -225,7 +229,7 @@ export default {
225229 }
226230 },
227231
228- getOptions(type ) {
232+ getOptions(type : string ) : ChartOptions < ' line ' > {
229233 return {
230234 responsive: true ,
231235 maintainAspectRatio: false ,
@@ -238,6 +242,7 @@ export default {
238242 position: ' top' ,
239243 align: ' center' ,
240244 },
245+ // @ts-expect-error: bug in chart.js types
241246 customEventListener: {
242247 chartType: type ,
243248 instance: this ,
0 commit comments