2017-05-26 18:49:27 -04:00
|
|
|
<script>
|
2017-10-04 19:01:04 -04:00
|
|
|
function getPlayerHistoryChart(playerHistory, i) {
|
|
|
|
///////////////////////////////////////
|
2017-10-15 21:40:27 -04:00
|
|
|
|
|
|
|
// thanks to cnavas js :(
|
|
|
|
playerHistory.forEach(function(item, i) {
|
|
|
|
playerHistory[i].x = new Date(playerHistory[i].x);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-10-04 19:01:04 -04:00
|
|
|
return new CanvasJS.Chart(`graph-player-history-${i}`, {
|
|
|
|
backgroundColor: "#191919",
|
|
|
|
height: 100,
|
|
|
|
animationEnabled: true,
|
2017-09-27 16:07:43 -04:00
|
|
|
|
2017-10-04 19:01:04 -04:00
|
|
|
toolTip: {
|
|
|
|
contentFormatter: function (e) {
|
2017-10-15 21:40:27 -04:00
|
|
|
var date = new Date(e.entries[0].dataPoint.x);
|
2017-10-04 19:01:04 -04:00
|
|
|
return date.toLocaleTimeString('en-US', { timeZone: 'America/New_York', hour12: true }) + " - " + e.entries[0].dataPoint.y + " players";
|
|
|
|
}
|
|
|
|
},
|
2017-09-27 16:07:43 -04:00
|
|
|
|
2017-10-04 19:01:04 -04:00
|
|
|
axisX: {
|
|
|
|
interval: 1,
|
|
|
|
gridThickness: 0,
|
|
|
|
lineThickness: 0,
|
|
|
|
tickThickness: 0,
|
|
|
|
margin: 0,
|
|
|
|
valueFormatString: " ",
|
|
|
|
},
|
2017-09-27 16:07:43 -04:00
|
|
|
|
2017-10-04 19:01:04 -04:00
|
|
|
axisY: {
|
|
|
|
gridThickness: 0,
|
|
|
|
lineThickness: 0,
|
|
|
|
tickThickness: 0,
|
|
|
|
minimum: 0,
|
|
|
|
margin: 0,
|
|
|
|
valueFormatString: " ",
|
|
|
|
labelMaxWidth: 0,
|
|
|
|
},
|
2017-09-27 16:07:43 -04:00
|
|
|
|
2017-10-04 19:01:04 -04:00
|
|
|
legend: {
|
|
|
|
maxWidth: 0,
|
|
|
|
maxHeight: 0,
|
|
|
|
dockInsidePlotArea: true,
|
|
|
|
},
|
2017-09-27 16:07:43 -04:00
|
|
|
|
2017-10-04 19:01:04 -04:00
|
|
|
data: [{
|
|
|
|
showInLegend: false,
|
|
|
|
type: "splineArea",
|
|
|
|
color: "rgba(0, 122, 204, 0.432)",
|
|
|
|
markerSize: 0,
|
|
|
|
dataPoints: playerHistory,
|
|
|
|
}]
|
2017-09-27 16:07:43 -04:00
|
|
|
});
|
2017-10-04 19:01:04 -04:00
|
|
|
//////////////////////////////////////
|
2017-09-27 16:07:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function getServers() {
|
|
|
|
$.getJSON("/_servers", function (result) {
|
2017-10-04 19:01:04 -04:00
|
|
|
|
2017-09-27 16:07:43 -04:00
|
|
|
$.each(result, function (i, server) {
|
2017-10-04 19:01:04 -04:00
|
|
|
var selectedServer = $(`#server-${i}`);
|
2017-09-27 16:07:43 -04:00
|
|
|
|
2017-10-04 19:01:04 -04:00
|
|
|
if (selectedServer.length < 1) {
|
|
|
|
$('#serverList').append(`<div id="server-${i}"><div class="serverContainer"></div></div>`);
|
|
|
|
selectedServer = $(`#server-${i}`);
|
|
|
|
selectedServer.append(`<div class="player-history" id="graph-player-history-${i}"></div><hr/><br/><br/>`)
|
|
|
|
}
|
2017-09-27 16:07:43 -04:00
|
|
|
|
|
|
|
|
2017-10-04 19:01:04 -04:00
|
|
|
var template =
|
|
|
|
`
|
|
|
|
<div class ="serverInfo table">
|
|
|
|
<div class ="serverTitle tableCell">${server.serverName}</div>
|
|
|
|
<div class ="serverMap tableCell">${server.mapName}</div>
|
|
|
|
<div class ="serverPlayers tableCell">${server.currentPlayers}/${server.maxPlayers}</div>
|
|
|
|
</div>
|
|
|
|
<div class ="serverChatList table">${formatMessages(server.chatHistory)}</div>
|
|
|
|
<div class ="serverPlayerList table">${formatPlayers(server.players)}</div>
|
|
|
|
<div style="clear:both;"></div>
|
|
|
|
<hr/>`;
|
|
|
|
|
|
|
|
selectedServer.find('.serverContainer').html(template);
|
|
|
|
|
|
|
|
if (!selectedServer.find(`#graph-player-history-${i}`).children().length) {
|
|
|
|
var historyGraph = getPlayerHistoryChart(server.PlayerHistory, i);
|
|
|
|
$(document).trigger("graphready", [historyGraph]);
|
|
|
|
}
|
2017-09-27 16:07:43 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
getServers();
|
2017-10-04 19:01:04 -04:00
|
|
|
setInterval(getServers, 1000);
|
2017-09-27 16:07:43 -04:00
|
|
|
});
|
2017-10-04 19:01:04 -04:00
|
|
|
|
|
|
|
$(document).on("graphready", function (e, graph) {
|
|
|
|
// why is this so slow I have to call it async?
|
|
|
|
setTimeout(graph.render, 1);
|
|
|
|
})
|
2017-05-26 18:49:27 -04:00
|
|
|
</script>
|
2017-10-04 19:01:04 -04:00
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
<div id="serverList">
|
|
|
|
</div>
|