@@ -48,31 +48,33 @@ export default async function graph(interaction: AnySelectMenuInteraction) {
48
48
] ,
49
49
type : "line" ,
50
50
data : {
51
- datasets : interaction . users . map ( ( user ) => {
52
- const data = recentXp
53
- . filter ( ( gain ) => gain . time < maxDate && gain . user === user . id )
54
- . reduce < { x : number ; y : number } [ ] > ( ( acc , xp ) => {
55
- const previous = acc . at ( - 1 ) ?? { y : 0 , x : recentXp [ 0 ] ?. time ?? 0 } ;
56
- return [
57
- ...acc ,
58
- ...Array . from (
59
- { length : Math . floor ( ( xp . time - previous . x ) / 3_600_000 ) } ,
60
- ( _ , index ) => ( {
61
- y : previous . y ,
62
- x : previous . x + 3_600_000 * index ,
63
- } ) ,
64
- ) ,
65
- { x : xp . time , y : xp . xp + previous ?. y } ,
66
- ] ;
67
- } , [ ] ) ;
68
- return {
69
- label : user . username ,
70
- data : [
71
- ...( data . length ? data : [ { y : 0 , x : recentXp [ 0 ] ?. time ?? 0 } ] ) ,
72
- { x : maxDate , y : data . at ( - 1 ) ?. y ?? 0 } ,
73
- ] ,
74
- } ;
75
- } ) ,
51
+ datasets : interaction . users
52
+ . map ( ( user ) => {
53
+ const data = recentXp
54
+ . filter ( ( gain ) => gain . time < maxDate && gain . user === user . id )
55
+ . reduce < { x : number ; y : number } [ ] > ( ( acc , xp ) => {
56
+ const previous = acc . at ( - 1 ) ?? { y : 0 , x : recentXp [ 0 ] ?. time ?? 0 } ;
57
+ return [
58
+ ...acc ,
59
+ ...Array . from (
60
+ { length : Math . floor ( ( xp . time - previous . x ) / 3_600_000 ) } ,
61
+ ( _ , index ) => ( {
62
+ y : previous . y ,
63
+ x : previous . x + 3_600_000 * index ,
64
+ } ) ,
65
+ ) ,
66
+ { x : xp . time , y : xp . xp + previous ?. y } ,
67
+ ] ;
68
+ } , [ ] ) ;
69
+ return {
70
+ label : user . username ,
71
+ data : [
72
+ ...( data . length ? data : [ { y : 0 , x : recentXp [ 0 ] ?. time ?? 0 } ] ) ,
73
+ { x : maxDate , y : data . at ( - 1 ) ?. y ?? 0 } ,
74
+ ] ,
75
+ } ;
76
+ } )
77
+ . sort ( ( one , two ) => ( two . data . at ( - 1 ) ?. y ?? 0 ) - ( one . data . at ( - 1 ) ?. y ?? 0 ) ) ,
76
78
} ,
77
79
} ) ;
78
80
0 commit comments