@ -9,6 +9,9 @@ import {
PointElement ,
LineElement ,
Filler ,
type ChartOptions ,
type ChartData ,
type Plugin ,
} from 'chart.js' ;
import { GET } from '../modules/fetch.ts' ;
import zoomPlugin from 'chartjs-plugin-zoom' ;
@ -22,8 +25,9 @@ import {chartJsColors} from '../utils/color.ts';
import { sleep } from '../utils.ts' ;
import 'chartjs-adapter-dayjs-4/dist/chartjs-adapter-dayjs-4.esm' ;
import { fomanticQuery } from '../modules/fomantic/base.ts' ;
import type { Entries } from 'type-fest' ;
const customEventListener = {
const customEventListener : Plugin = {
id : 'customEventListener' ,
afterEvent : ( chart , args , opts ) => {
/ / e v e n t w i l l b e r e p l a y e d f r o m c h a r t . u p d a t e w h e n r e s e t z o o m ,
@ -65,10 +69,10 @@ export default {
data : ( ) => ( {
isLoading : false ,
errorText : '' ,
totalStats : { } ,
sortedContributors : { } ,
totalStats : { } as Record < string , any > ,
sortedContributors : { } as Record < string , any > ,
type : 'commits' ,
contributorsStats : [ ] ,
contributorsStats : { } as Record < string , any > ,
xAxisStart : null ,
xAxisEnd : null ,
xAxisMin : null ,
@ -99,7 +103,7 @@ export default {
async fetchGraphData ( ) {
this . isLoading = true ;
try {
let response ;
let response : Response ;
do {
response = await GET ( ` ${ this . repoLink } /activity/contributors/data ` ) ;
if ( response . status === 202 ) {
@ -112,7 +116,7 @@ export default {
/ / b e l o w l i n e m i g h t b e d e l e t e d i f w e a r e s u r e g o p r o d u c e s m a p a l w a y s s o r t e d b y k e y s
total . weeks = Object . fromEntries ( Object . entries ( total . weeks ) . sort ( ) ) ;
const weekValues = Object . values ( total . weeks ) ;
const weekValues = Object . values ( total . weeks ) as any ;
this . xAxisStart = weekValues [ 0 ] . week ;
this . xAxisEnd = firstStartDateAfterDate ( new Date ( ) ) ;
const startDays = startDaysBetween ( this . xAxisStart , this . xAxisEnd ) ;
@ -120,7 +124,7 @@ export default {
this . xAxisMin = this . xAxisStart ;
this . xAxisMax = this . xAxisEnd ;
this . contributorsStats = { } ;
for ( const [ email , user ] of Object . entries ( rest ) ) {
for ( const [ email , user ] of Object . entries ( rest ) as Entries < Record < string , Record < string , any > >> ) {
user . weeks = fillEmptyStartDaysWithZeroes ( startDays , user . weeks ) ;
this . contributorsStats [ email ] = user ;
}
@ -146,7 +150,7 @@ export default {
user . total _additions = 0 ;
user . total _deletions = 0 ;
user . max _contribution _type = 0 ;
const filteredWeeks = user . weeks . filter ( ( week ) => {
const filteredWeeks = user . weeks . filter ( ( week : Record < string , number > ) => {
const oneWeek = 7 * 24 * 60 * 60 * 1000 ;
if ( week . week >= this . xAxisMin - oneWeek && week . week <= this . xAxisMax + oneWeek ) {
user . total _commits += week . commits ;
@ -195,7 +199,7 @@ export default {
return ( 1 - ( coefficient % 1 ) ) * 10 * * exp + maxValue ;
} ,
toGraphData ( data ) {
toGraphData ( data : Array < Record < string , any > > ) : ChartData < 'line' > {
return {
datasets : [
{
@ -211,9 +215,9 @@ export default {
} ;
} ,
updateOtherCharts ( event , reset ) {
const minVal = event . chart . options . scales . x . min ;
const maxVal = event . chart . options . scales . x . max ;
updateOtherCharts ( { chart } : { chart : Chart } , reset ? : boolean = false ) {
const minVal = chart . options . scales . x . min ;
const maxVal = chart . options . scales . x . max ;
if ( reset ) {
this . xAxisMin = this . xAxisStart ;
this . xAxisMax = this . xAxisEnd ;
@ -225,7 +229,7 @@ export default {
}
} ,
getOptions ( type ) {
getOptions ( type : string ) : ChartOptions < 'line' > {
return {
responsive : true ,
maintainAspectRatio : false ,
@ -238,6 +242,7 @@ export default {
position : 'top' ,
align : 'center' ,
} ,
/ / @ t s - e x p e c t - e r r o r : b u g i n c h a r t . j s t y p e s
customEventListener : {
chartType : type ,
instance : this ,