2022-07-10 18:06:46 -04:00
|
|
|
|
function getClosestMultiple(baseValue, value) {
|
|
|
|
|
return Math.round(value / baseValue) * baseValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getStatsChart(id) {
|
2018-05-30 21:50:20 -04:00
|
|
|
|
const data = $('#' + id).data('history');
|
2022-07-10 18:06:46 -04:00
|
|
|
|
|
2021-03-22 12:09:25 -04:00
|
|
|
|
if (data === undefined) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-07-10 18:06:46 -04:00
|
|
|
|
if (data.length <= 1) {
|
|
|
|
|
// only 0 perf
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const labels = [];
|
|
|
|
|
const values = [];
|
|
|
|
|
|
2018-05-30 21:50:20 -04:00
|
|
|
|
data.forEach(function (item, i) {
|
2022-07-10 18:06:46 -04:00
|
|
|
|
labels.push(item.OccurredAt);
|
|
|
|
|
values.push(item.Performance)
|
2018-05-30 21:50:20 -04:00
|
|
|
|
});
|
2022-07-10 18:06:46 -04:00
|
|
|
|
|
2018-05-30 21:50:20 -04:00
|
|
|
|
|
2022-07-10 18:06:46 -04:00
|
|
|
|
const padding = 4;
|
|
|
|
|
let dataMin = Math.min(...values);
|
|
|
|
|
const dataMax = Math.max(...values);
|
2018-06-01 20:55:26 -04:00
|
|
|
|
|
|
|
|
|
if (dataMax - dataMin === 0) {
|
|
|
|
|
dataMin = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-10 18:06:46 -04:00
|
|
|
|
dataMin = Math.max(0, dataMin);
|
2018-06-01 20:55:26 -04:00
|
|
|
|
|
2022-07-10 18:06:46 -04:00
|
|
|
|
const min = getClosestMultiple(padding, dataMin - padding);
|
|
|
|
|
const max = getClosestMultiple(padding, dataMax + padding);
|
2018-06-01 20:55:26 -04:00
|
|
|
|
|
2022-07-10 18:06:46 -04:00
|
|
|
|
const chartData = {
|
|
|
|
|
labels: labels,
|
|
|
|
|
datasets: [{
|
|
|
|
|
data: values,
|
|
|
|
|
pointBackgroundColor: 'rgba(255, 255, 255, 0)',
|
|
|
|
|
pointBorderColor: 'rgba(255, 255, 255, 0)',
|
|
|
|
|
pointHoverRadius: 5,
|
|
|
|
|
pointHoverBackgroundColor: 'rgba(255, 255, 255, 1)',
|
|
|
|
|
}]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
|
defaultFontFamily: '-apple-system, BlinkMacSystemFont, "Open Sans", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"',
|
|
|
|
|
responsive: true,
|
|
|
|
|
maintainAspectRatio: false,
|
|
|
|
|
legend: false,
|
|
|
|
|
tooltips: {
|
|
|
|
|
callbacks: {
|
|
|
|
|
label: context => moment.utc(context.label).local().calendar(),
|
|
|
|
|
title: items => Math.round(items[0].yLabel) + ' ' + _localization['WEBFRONT_ADV_STATS_RANKING_METRIC']
|
|
|
|
|
},
|
|
|
|
|
mode: 'nearest',
|
|
|
|
|
intersect: false,
|
|
|
|
|
animationDuration: 0,
|
|
|
|
|
cornerRadius: 0,
|
|
|
|
|
displayColors: false
|
2018-05-30 21:50:20 -04:00
|
|
|
|
},
|
2022-07-10 18:06:46 -04:00
|
|
|
|
hover: {
|
|
|
|
|
mode: 'nearest',
|
|
|
|
|
intersect: false
|
2018-06-01 20:55:26 -04:00
|
|
|
|
},
|
2022-07-10 18:06:46 -04:00
|
|
|
|
elements: {
|
|
|
|
|
line: {
|
|
|
|
|
fill: false,
|
|
|
|
|
borderColor: halfmoon.getPreferredMode() === "light-mode" ? 'rgba(0, 0, 0, 0.85)' : 'rgba(255, 255, 255, 0.75)',
|
|
|
|
|
borderWidth: 2
|
|
|
|
|
},
|
|
|
|
|
point: {
|
|
|
|
|
radius: 5
|
|
|
|
|
}
|
2018-05-30 21:50:20 -04:00
|
|
|
|
},
|
2022-07-10 18:06:46 -04:00
|
|
|
|
scales: {
|
|
|
|
|
xAxes: [{
|
|
|
|
|
display: false,
|
|
|
|
|
}],
|
|
|
|
|
yAxes: [{
|
|
|
|
|
gridLines: {
|
|
|
|
|
display: false
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
position: 'right',
|
|
|
|
|
ticks: {
|
|
|
|
|
callback: function (value, index, values) {
|
|
|
|
|
if (index === values.length - 1) {
|
|
|
|
|
return min;
|
|
|
|
|
} else if (index === 0) {
|
|
|
|
|
return max;
|
|
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
fontColor: 'rgba(255, 255, 255, 0.25)'
|
|
|
|
|
}
|
|
|
|
|
}]
|
2018-05-30 21:50:20 -04:00
|
|
|
|
},
|
2022-07-10 18:06:46 -04:00
|
|
|
|
layout: {
|
|
|
|
|
padding: {
|
|
|
|
|
left: 15
|
|
|
|
|
}
|
2018-05-30 21:50:20 -04:00
|
|
|
|
},
|
2022-07-10 18:06:46 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
new Chart(id, {
|
|
|
|
|
type: 'line',
|
|
|
|
|
data: chartData,
|
|
|
|
|
options: options
|
|
|
|
|
});
|
2018-05-30 21:50:20 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
|
$('.client-rating-graph').each(function (i, element) {
|
2022-07-10 18:06:46 -04:00
|
|
|
|
getStatsChart($(element).children('canvas').attr('id'));
|
2018-05-30 21:50:20 -04:00
|
|
|
|
});
|
2019-02-26 22:25:27 -05:00
|
|
|
|
|
2022-07-10 18:06:46 -04:00
|
|
|
|
|
2019-02-26 22:25:27 -05:00
|
|
|
|
$('.top-players-link').click(function (event) {
|
2019-02-27 21:13:15 -05:00
|
|
|
|
$($(this).attr('href')).html('');
|
|
|
|
|
initLoader('/Stats/GetTopPlayersAsync?serverId=' + $(this).data('serverid'), $(this).attr('href'), 10, 0);
|
|
|
|
|
loadMoreItems();
|
2019-02-26 22:25:27 -05:00
|
|
|
|
});
|
2018-05-30 21:50:20 -04:00
|
|
|
|
});
|
2018-05-31 20:17:52 -04:00
|
|
|
|
|
|
|
|
|
$(document).on("loaderFinished", function (event, response) {
|
|
|
|
|
const ids = $.map($(response).find('.client-rating-graph'), function (elem) { return $(elem).attr('id'); });
|
|
|
|
|
ids.forEach(function (item, index) {
|
2022-07-10 18:06:46 -04:00
|
|
|
|
getStatsChart($(item).children('canvas').attr('id'));
|
2018-05-31 20:17:52 -04:00
|
|
|
|
});
|
|
|
|
|
});
|