diff --git a/commands/player-stats.js b/commands/player-stats.js index 83c75e7..b6f9b4d 100644 --- a/commands/player-stats.js +++ b/commands/player-stats.js @@ -170,7 +170,7 @@ module.exports = { }; const encodedChart = encodeURIComponent(JSON.stringify(chart)); - const chartURL = `https://quickchart.io/chart?c=${encodedChart}`; + const chartURL = `https://quickchart.io/chart?bkg=${encodeURIComponent("#ded8d7")}&c=${encodedChart}}`; statsEmbed.setImage(chartURL); @@ -199,31 +199,45 @@ module.exports = { }; const encodedChart = encodeURIComponent(JSON.stringify(chart)); - const chartURL = `https://quickchart.io/chart?c=${encodedChart}`; + const chartURL = `https://quickchart.io/chart?bkg=${encodeURIComponent("#ded8d7")}&c=${encodedChart}}`; statsEmbed.setImage(chartURL); } else if (category == 'combatRating') { + let data = query.combatRatingHistory; + statsEmbed.addFields({ name: 'Combat Rating', value: `${query.combatRating}`, inline: true }); - if (query.combatRatingHistory.length == 1) query.combatRatingHistory.push(query.combatRating) // Make array 2 long for a straight line in the graph + if (data.length == 1) data.push(query.combatRating) // Make array 2 long for a straight line in the graph const chart = { type: 'line', data: { - labels: new Array(query.combatRatingHistory.length).fill(' ', 0, query.combatRating.length), + labels: new Array(data.length).fill(' ', 0, data.length), datasets: [{ - data: query.combatRatingHistory, + data: data, label: 'Combat Rating Over Time', }], }, options: { + scales: { + // Gives comfortable margin to the top of the y-axis + yAxes: [{ + ticks: { + min: 0, + max: Math.round(Math.max(...data)/100)*100 + (Math.round(Math.max(...data)/100)*100 % 200 == 0 ? 400 : 500), // Keeps the max y-axis as a step of 200 + step: 200, + }, + }] + }, + // Gives a margin to the right of the whole graph layout: { padding: { right: 40, }, }, + // Labels points on the graph to show evolution of combat rating plugins: { datalabels: { display: true, @@ -247,10 +261,10 @@ module.exports = { }, }, }, - } + }; const encodedChart = encodeURIComponent(JSON.stringify(chart)); - const chartURL = `https://quickchart.io/chart?c=${encodedChart}`; + const chartURL = `https://quickchart.io/chart?bkg=${encodeURIComponent("#ded8d7")}&c=${encodedChart}}`; statsEmbed.setImage(chartURL); diff --git a/commands/weapon-stats.js b/commands/weapon-stats.js index 5dbefed..4d90464 100644 --- a/commands/weapon-stats.js +++ b/commands/weapon-stats.js @@ -141,7 +141,7 @@ module.exports = { }; const encodedChart = encodeURIComponent(JSON.stringify(chart)); - const chartURL = `https://quickchart.io/chart?c=${encodedChart}`; + const chartURL = `https://quickchart.io/chart?bkg=${encodeURIComponent("#ded8d7")}&c=${encodedChart}}`; stats.setImage(chartURL); diff --git a/package.json b/package.json index 2f8025b..3f4bb1d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dayzr-bot", - "version": "12.2.11", + "version": "12.2.12", "description": "A General Purpose Discord Bot for DayZ Nitrado Servers.", "main": "index.js", "nodemonConfig": { diff --git a/util/KillfeedHandler.js b/util/KillfeedHandler.js index b9d35e7..1739b1e 100644 --- a/util/KillfeedHandler.js +++ b/util/KillfeedHandler.js @@ -191,6 +191,10 @@ module.exports = { let victimOldRating = victimStat.combatRating; killerStat.combatRating = calculateNewCombatRating(killerStat.combatRating, victimStat.combatRating, 1); victimStat.combatRating = calculateNewCombatRating(victimStat.combatRating, killerStat.combatRating, 0); + if (killerStat.combatRatingHistory.length == 8) killerStat.combatRatingHistory = killerStat.combatRatingHistory.slice(1); // Remove first element (limits history to length 8) + if (victimStat.combatRatingHistory.length == 8) victimStat.combatRatingHistory = victimStat.combatRatingHistory.slice(1); // Remove first element (limits history to length 8) + killerStat.combatRatingHistory.push(killerStat.combatRating); + victimStat.combatRatingHistory.push(victimStat.combatRating); let kdiff = killerStat.combatRating - killerOldRating; let vdiff = victimStat.combatRating - victimOldRating;