From d4233c07b83b4e7332a3e65af0119d80cc700b4e Mon Sep 17 00:00:00 2001 From: "Lang, Simon" Date: Tue, 11 Jun 2024 23:31:42 +0200 Subject: [PATCH] removed unnecessary fetch-requests --- public/elotracker/chart-integration.js | 97 ++++++++++++-------------- 1 file changed, 44 insertions(+), 53 deletions(-) diff --git a/public/elotracker/chart-integration.js b/public/elotracker/chart-integration.js index d45567e..a96c8b2 100644 --- a/public/elotracker/chart-integration.js +++ b/public/elotracker/chart-integration.js @@ -90,61 +90,52 @@ window.onload = async function(){ let puuid = chart.id.split("-"); puuid.splice(0,2); puuid = puuid.join("-"); - fetch(`get.php?puuid=${puuid}`, { - method: "GET", - }) - .then(res => res.json()) - .then(result => { - let entries = result["entries"]; - let account = result["accounts"]; - 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: [{ - label: `${account["gameName"]}#${account["tagLine"]}`, - 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"]) - }, - beforeTitle: function (context) { - return context[0].dataset.label; - }, - } - } - }, - scales: { - y: { - display: true, - stepSize: 100, - ticks: { - callback: (value) => { - return points_to_rankstring(value,false); - } - } + let xValues = []; + let yValues = []; + for (const entriesKey in player_entries[puuid]) { + let points = rank_to_points(player_entries[puuid][entriesKey]["tier"], player_entries[puuid][entriesKey]["rank"], player_entries[puuid][entriesKey]["points"]); + xValues.push(entriesKey); + yValues.push(points); + } + new Chart(`progress-chart-${puuid}`, { + type: "line", + data: { + labels: xValues, + datasets: [{ + label: `${player_accounts[puuid]["gameName"]}#${player_accounts[puuid]["tagLine"]}`, + 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(player_entries[puuid][context.label]["tier"],player_entries[puuid][context.label]["rank"],player_entries[puuid][context.label]["points"]) }, - }, + beforeTitle: function (context) { + return context[0].dataset.label; + }, + } } - }); - }) - .catch(e => console.error(e)) + }, + scales: { + y: { + display: true, + stepSize: 100, + ticks: { + callback: (value) => { + return points_to_rankstring(value,false); + } + } + }, + }, + } + }); } };