Skip to content

Commit c226c18

Browse files
committed
sort
Signed-off-by: RedGuy12 <paul@reid-family.org>
1 parent 9a32b1f commit c226c18

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

modules/xp/graph.ts

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,33 @@ export default async function graph(interaction: AnySelectMenuInteraction) {
4848
],
4949
type: "line",
5050
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)),
7678
},
7779
});
7880

0 commit comments

Comments
 (0)