Numerous graph fixes

This commit is contained in:
Cryptkeeper
2015-12-18 21:23:24 -06:00
parent 76a4cd1f95
commit 454627b2a9
6 changed files with 82 additions and 22 deletions

View File

@ -231,6 +231,8 @@ $(document).ready(function() {
var mojangServicesUpdater;
var sortServersTask;
var graphDuration;
socket.on('connect', function() {
$('#tagline-text').text('Loading...');
@ -262,6 +264,10 @@ $(document).ready(function() {
$('#big-graph-controls').css('display', 'none');
});
socket.on('setGraphDuration', function(value) {
graphDuration = value;
});
socket.on('historyGraph', function(rawData) {
displayedGraphData = rawData;
@ -295,23 +301,25 @@ $(document).ready(function() {
});
socket.on('updateHistoryGraph', function(rawData) {
var targetGraphData = displayedGraphData[rawData.ip];
// If it's not in our display group, push it to the hidden group instead so it can be restored and still be up to date.
if (!targetGraphData) {
targetGraphData = hiddenGraphData[rawData.ip];
// Prevent race conditions.
if (!graphDuration) {
return;
}
if (targetGraphData.length > 24 * 60) {
targetGraphData.shift();
// If it's not in our display group, use the hidden group instead.
var targetGraphData = displayedGraphData[rawData.ip] ? displayedGraphData : hiddenGraphData;
trimOldPings(targetGraphData, graphDuration);
targetGraphData[rawData.ip].push([rawData.timestamp, rawData.players]);
// Redraw if we need to.
if (displayedGraphData[rawData.ip]) {
historyPlot.setData(convertGraphData(displayedGraphData));
historyPlot.setupGrid();
historyPlot.draw();
}
targetGraphData.push([rawData.timestamp, rawData.players]);
historyPlot.setData(convertGraphData(displayedGraphData));
historyPlot.setupGrid();
historyPlot.draw();
});
socket.on('add', function(servers) {