drawXpPieChart

Tracks and estimates hourly XP rate in Nitro Type races

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/501962/1418071/drawXpPieChart.js

  1. // ==UserScript==
  2. // @name drawXpPieChart
  3. // @version 3.5
  4. // @description Tracks and estimates hourly XP rate in Nitro Type races
  5. // @author TensorFlow - Dvorak
  6. // @match *://*.nitrotype.com/race
  7. // @match *://*.nitrotype.com/race/*
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11. function drawXpPieChart() {
  12. const canvas = document.getElementById('xpPieChart');
  13. const ctx = canvas.getContext('2d');
  14.  
  15. const data = [
  16. { label: 'Placement', value: xpCategories.placement, cumulative: cumulativeXpCategories.placement, color: '#ff6384' },
  17. { label: 'Accuracy', value: xpCategories.accuracy, cumulative: cumulativeXpCategories.accuracy, color: '#36a2eb' },
  18. { label: 'Wampus', value: xpCategories.wampus, cumulative: cumulativeXpCategories.wampus, color: '#cc65fe' },
  19. { label: 'Friends', value: xpCategories.friends, cumulative: cumulativeXpCategories.friends, color: '#4caf50' },
  20. { label: 'Gold Bonus', value: xpCategories.goldBonus, cumulative: cumulativeXpCategories.goldBonus, color: '#ffeb3b' },
  21. { label: 'Speed', value: xpCategories.speed, cumulative: cumulativeXpCategories.speed, color: '#f44336' },
  22. { label: 'Other', value: xpCategories.other, cumulative: cumulativeXpCategories.other, color: '#ffce56' }
  23. ].filter(category => category.value > 0); // Filter out categories with value 0
  24.  
  25. const total = data.reduce((acc, category) => acc + category.value, 0);
  26.  
  27. ctx.clearRect(0, 0, canvas.width, canvas.height);
  28.  
  29. let startAngle = 0;
  30. data.forEach(category => {
  31. const sliceAngle = (category.value / total) * 2 * Math.PI;
  32. ctx.beginPath();
  33. ctx.moveTo(150, 150); // Adjusted for smaller canvas
  34. ctx.arc(150, 150, 150, startAngle, startAngle + sliceAngle); // Adjusted for smaller canvas
  35. ctx.closePath();
  36. ctx.fillStyle = category.color;
  37. ctx.fill();
  38.  
  39. // Draw labels centered within the slice and as far away from the center as possible
  40. const midAngle = startAngle + sliceAngle / 2;
  41. const labelX = 150 + (150 - 20) * Math.cos(midAngle); // Adjusted for smaller canvas
  42. const labelY = 150 + (150 - 20) * Math.sin(midAngle); // Adjusted for smaller canvas
  43. ctx.fillStyle = "#fff";
  44. ctx.textAlign = "center";
  45. ctx.font = "bold 12px Arial";
  46. ctx.fillText(`${category.label} (${formatNumber(category.cumulative)})`, labelX, labelY);
  47.  
  48. startAngle += sliceAngle;
  49. });
  50. }
  51.