You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
2.7 KiB

window.onload = async function(){
const charts = document.getElementsByClassName("progress-chart");
for (const chart of charts) {
let puuid = chart.id.split("-");
puuid.splice(0,2);
puuid = puuid.join("-");
fetch(`get.php?puuid=${puuid}`, {
method: "GET",
})
.then(res => res.json())
.then(entries => {
let xValues = [];
let yValues = [];
for (const entriesKey in entries) {
let points = rank_to_points(entries[entriesKey]["tier"], entries[entriesKey]["rank"], entries[entriesKey]["points"]);
xValues.push(entriesKey);
yValues.push(points);
}
new Chart(`progress-chart-${puuid}`, {
type: "line",
data: {
labels: xValues,
datasets: [{
fill: false,
borderColor: "rgba(150,150,175)",
backgroundColor: "rgba(150,150,175)",
data: yValues
}]
},
options: {
plugins: {
legend: {display: false},
tooltip: {
callbacks: {
label: function(context) {
return format_rank(entries[context.label]["tier"],entries[context.label]["rank"],entries[context.label]["points"])
}
}
}
},
scales: {
y: {
display: true,
stepSize: 100,
ticks: {
callback: (value) => {
return points_to_rankstring(value,false);
}
}
},
},
}
});
})
.catch(e => console.error(e))
}
};
function rank_to_points(tier,rank,lp) {
const apex_tiers = (tier === "MASTER" || tier === "GRANDMASTER" || tier === "CHALLENGER");
const tiers = {
"DIAMOND": 2400,
"EMERALD": 2000,
"PLATINUM": 1600,
"GOLD": 1200,
"SILVER": 800,
"BRONZE": 400,
"IRON": 0,
};
const ranks = {
"I": 300,
"II": 200,
"III": 100,
"IV": 0,
};
if (apex_tiers) {
return 2800 + lp;
} else {
return tiers[tier] + ranks[rank] + lp;
}
}
function points_to_rankstring(points, include_LP = true) {
const apex_tiers = (points >= 2800);
let lp = (apex_tiers) ? points - 2800 : points%100
let rank = (points-lp)%400;
let tier = (points-lp-rank);
const tiers = {
2400: "Diamond",
2000: "Emerald",
1600: "Platinum",
1200: "Gold",
800: "Silver",
400: "Bronze",
0: "Iron",
};
const ranks = {
300: "I",
200: "II",
100: "III",
0: "IV",
};
let rank_string = (apex_tiers) ? "Master" : tiers[tier];
if (!apex_tiers) rank_string += ` ${ranks[rank]}`;
if (include_LP || apex_tiers) rank_string += ` ${lp} LP`;
return rank_string;
}
function format_rank(tier,rank,lp) {
tier = tier.charAt(0).toUpperCase()+tier.slice(1).toLowerCase();
const apex_tiers = (tier === "Master" || tier === "Grandmaster" || tier === "Challenger");
let rank_string = tier;
if (!apex_tiers) rank_string += ` ${rank}`;
rank_string += ` ${lp} LP`;
return rank_string;
}