Skip to content

Commit 80dbfb4

Browse files
authored
Merge pull request #73 from Balatro-Multiplayer/64-add-command-argument-to-display-the-graph-with-individual-points
Dots to each point optional argument
2 parents 5c02129 + 1f0ab92 commit 80dbfb4

4 files changed

Lines changed: 30 additions & 2 deletions

File tree

src/commands/queues/statsQueue.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ export default {
1515
const targetUser = interaction.options.getUser('user') || interaction.user
1616
const byDate =
1717
interaction.options.getString('by-date') === 'yes' ? true : false
18+
const showDots =
19+
interaction.options.getString('dots') === 'yes' ? true : false
1820
const queueId = await getQueueIdFromName(queueName)
1921
const playerStats = await getStatsCanvasUserData(targetUser.id, queueId)
2022
const statFile = await drawPlayerStatsCanvas(
2123
queueName,
2224
playerStats,
2325
byDate,
26+
showDots,
2427
)
2528
const viewStatsButtons = setupViewStatsButtons(queueName)
2629

src/commands/superCommands/stats.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ export default {
3333
.setDescription('Sort the stats by date')
3434
.addChoices([{ name: 'yes', value: 'yes' }])
3535
.setRequired(false),
36+
)
37+
.addStringOption((option) =>
38+
option
39+
.setName('dots')
40+
.setDescription('Show dots for each individual game on the graph')
41+
.addChoices([{ name: 'yes', value: 'yes' }])
42+
.setRequired(false),
3643
),
3744
),
3845
async execute(interaction: ChatInputCommandInteraction) {

src/utils/canvasHelpers.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ function createGraph(
421421
xlen: number,
422422
ylen: number,
423423
byDate: boolean = false,
424+
showDots: boolean = false,
424425
) {
425426
/**
426427
* Draws normalizedPoints to ctx. The top left of the graph is at x,y, and the graph should be xlen across and ylen down
@@ -668,6 +669,22 @@ function createGraph(
668669

669670
ctx.restore()
670671

672+
// Draw dots at each data point if enabled
673+
if (showDots) {
674+
for (let i = 0; i < normalizedPoints.length; i++) {
675+
const p = normalizedPoints[i]
676+
const x = graphX + ((p.xVar - minX) / xRange) * graphXLen
677+
const y = convertToCanvasSpace(p.rating)
678+
const color = getColor(p.rating)
679+
680+
// Draw dot
681+
ctx.beginPath()
682+
ctx.arc(x, y, 4, 0, Math.PI * 2)
683+
ctx.fillStyle = color
684+
ctx.fill()
685+
}
686+
}
687+
671688
// Add y level labels
672689

673690
guideRatings.forEach((r) => {
@@ -1103,6 +1120,7 @@ export async function drawPlayerStatsCanvas(
11031120
queueName: string,
11041121
playerData: StatsCanvasPlayerData,
11051122
byDate: boolean,
1123+
showDots: boolean = false,
11061124
) {
11071125
// Render at higher resolution for sharper text (2x, 4x, etc.)
11081126
// Higher scale = more anti-aliasing but larger file size
@@ -1156,7 +1174,7 @@ export async function drawPlayerStatsCanvas(
11561174

11571175
//graph
11581176
await addBlackBox(ctx, 270, 170, 470, 370)
1159-
createGraph(ctx, playerData, queueName, 280, 180, 450, 350, byDate)
1177+
createGraph(ctx, playerData, queueName, 280, 180, 450, 350, byDate, showDots)
11601178

11611179
// Export with high quality settings
11621180
return await canvas.toBuffer('png', {

src/utils/matchHelpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ export async function endMatch(
855855
try {
856856
// build results embed
857857
const resultsEmbed = new EmbedBuilder()
858-
.setTitle(`🏆 ${queueSettings.queue_name} Match #${matchId} 🏆`)
858+
.setTitle(`${queueSettings.queue_name} Match #${matchId} 🏆`)
859859
.setColor(queueSettings.color as any)
860860

861861
const guild =

0 commit comments

Comments
 (0)