Moved graph loading functions to network-values.js

This commit is contained in:
Risto Lahtela 2021-02-11 11:49:25 +02:00
parent 691ebc1ed4
commit 4d46102a98
2 changed files with 128 additions and 123 deletions

View File

@ -308,4 +308,105 @@ function onViewserver(i, servers) {
quickView.querySelector('#data_downtime').innerText = server.downtime;
}, 0);
}
}
function loadPlayersOnlineGraph(json, error) {
if (json) {
const series = {
playersOnline: {
name: s.name.playersOnline, type: s.type.areaSpline, tooltip: s.tooltip.zeroDecimals,
data: json.playersOnline, color: v.colors.playersOnline, yAxis: 0
}
};
playersChart('playersOnlineChart', series.playersOnline, 2);
} else if (error) {
document.getElementById('playersOnlineChart').innerText = `Failed to load graph data: ${error}`;
}
}
function loadUniqueAndNewGraph(json, error) {
if (json) {
const uniquePlayers = {
name: s.name.uniquePlayers, type: s.type.spline, tooltip: s.tooltip.zeroDecimals,
data: json.uniquePlayers, color: v.colors.playersOnline
};
const newPlayers = {
name: s.name.newPlayers, type: s.type.spline, tooltip: s.tooltip.zeroDecimals,
data: json.newPlayers, color: v.colors.newPlayers
};
dayByDay('uniqueChart', [uniquePlayers, newPlayers]);
} else if (error) {
document.getElementById('uniqueChart').innerText = `Failed to load graph data: ${error}`;
}
}
function loadHourlyUniqueAndNewGraph(json, error) {
if (json) {
const uniquePlayers = {
name: s.name.uniquePlayers, type: s.type.spline, tooltip: s.tooltip.zeroDecimals,
data: json.uniquePlayers, color: v.colors.playersOnline
};
const newPlayers = {
name: s.name.newPlayers, type: s.type.spline, tooltip: s.tooltip.zeroDecimals,
data: json.newPlayers, color: v.colors.newPlayers
};
dayByDay('hourlyUniqueChart', [uniquePlayers, newPlayers]);
} else if (error) {
document.getElementById('uniqueChart').innerText = `Failed to load graph data: ${error}`;
}
}
function loadServerPie(json, error) {
if (json) {
serverPieSeries = {
name: 'Server Playtime',
colorByPoint: true,
colors: json.server_pie_colors,
data: json.server_pie_series_30d
};
serverPie('serverPie', serverPieSeries);
} else if (error) {
document.getElementById('serverPie').innerText = `Failed to load graph data: ${error}`;
}
}
function loadActivityGraphs(json, error) {
if (json) {
activityPie('activityPie', {
name: s.name.unit_players, colorByPoint: true, data: json.activity_pie_series
});
stackChart('activityStackGraph', json.activity_labels, json.activity_series, s.name.unit_players);
} else if (error) {
const errorMessage = `Failed to load graph data: ${error}`;
document.getElementById('activityPie').innerText = errorMessage;
document.getElementById('activityStackGraph').innerText = errorMessage;
}
}
function loadGeolocationGraph(json, error) {
if (json) {
const geolocationSeries = {
name: s.name.unit_players,
type: 'map',
mapData: Highcharts.maps['custom/world'],
data: json.geolocation_series,
joinBy: ['iso-a3', 'code']
};
const geolocationBarSeries = {
color: json.colors.bars,
name: s.name.unit_players,
data: json.geolocation_bar_series.map(function (bar) {
return bar.value
})
};
const geolocationBarCategories = json.geolocation_bar_series.map(function (bar) {
return bar.label
});
worldMap('worldMap', json.colors.low, json.colors.high, geolocationSeries);
horizontalBarChart('countryBarChart', geolocationBarCategories, [geolocationBarSeries], s.name.unit_players);
} else if (error) {
const errorMessage = `Failed to load graph data: ${error}`;
document.getElementById('worldMap').innerText = errorMessage;
document.getElementById('countryBarChart').innerText = errorMessage;
}
}

View File

@ -836,6 +836,26 @@
<script src="./js/network-values.js"></script>
<script id="mainScript">
// HighCharts Series
const s = {
name: {
playersOnline: 'Players Online',
uniquePlayers: 'Unique Players',
newPlayers: 'New Players',
maxPing: 'Worst Ping',
minPing: 'Best Ping',
avgPing: 'Average Ping',
unit_players: 'Players'
},
tooltip: {
twoDecimals: {valueDecimals: 2},
zeroDecimals: {valueDecimals: 0}
},
type: {
areaSpline: 'areaspline',
spline: 'spline'
}
};
try {
refreshBarrierMs = ${refreshBarrier};
@ -868,128 +888,12 @@
time: {timezoneOffset: v.values.timezoneOffset * 60}
});
// HighCharts Series
const s = {
name: {
playersOnline: 'Players Online',
uniquePlayers: 'Unique Players',
newPlayers: 'New Players',
maxPing: 'Worst Ping',
minPing: 'Best Ping',
avgPing: 'Average Ping'
},
tooltip: {
twoDecimals: {
valueDecimals: 2
},
zeroDecimals: {
valueDecimals: 0
}
},
type: {
areaSpline: 'areaspline',
spline: 'spline'
}
};
refreshingJsonRequest("./v1/graph?type=playersOnline&server=${serverUUID}", function (json, error) {
if (json) {
const series = {
playersOnline: {
name: s.name.playersOnline, type: s.type.areaSpline, tooltip: s.tooltip.zeroDecimals,
data: json.playersOnline, color: v.colors.playersOnline, yAxis: 0
}
};
playersChart('playersOnlineChart', series.playersOnline, 2);
} else if (error) {
$('#playersOnlineChart').text("Failed to load graph data: " + error);
}
}, 'network-overview');
refreshingJsonRequest("./v1/graph?type=uniqueAndNew", function (json, error) {
if (json) {
const uniquePlayers = {
name: s.name.uniquePlayers, type: s.type.spline, tooltip: s.tooltip.zeroDecimals,
data: json.uniquePlayers, color: v.colors.playersOnline
};
const newPlayers = {
name: s.name.newPlayers, type: s.type.spline, tooltip: s.tooltip.zeroDecimals,
data: json.newPlayers, color: v.colors.newPlayers
};
dayByDay('uniqueChart', [uniquePlayers, newPlayers]);
} else if (error) {
$('#uniqueChart').text("Failed to load graph data: " + error)
}
}, 'network-overview');
refreshingJsonRequest("./v1/graph?type=hourlyUniqueAndNew", function (json, error) {
if (json) {
const uniquePlayers = {
name: s.name.uniquePlayers, type: s.type.spline, tooltip: s.tooltip.zeroDecimals,
data: json.uniquePlayers, color: v.colors.playersOnline
};
const newPlayers = {
name: s.name.newPlayers, type: s.type.spline, tooltip: s.tooltip.zeroDecimals,
data: json.newPlayers, color: v.colors.newPlayers
};
dayByDay('hourlyUniqueChart', [uniquePlayers, newPlayers]);
} else if (error) {
$('#uniqueChart').text("Failed to load graph data: " + error)
}
}, 'network-overview');
refreshingJsonRequest("./v1/graph?type=serverPie", function (json, error) {
if (json) {
serverPieSeries = {
name: 'Server Playtime',
colorByPoint: true,
colors: json.server_pie_colors,
data: json.server_pie_series_30d
};
serverPie('serverPie', serverPieSeries);
} else if (error) {
$('#serverPie').text("Failed to load graph data: " + error)
}
}, 'sessions-overview');
refreshingJsonRequest("./v1/graph?type=activity", function (json, error) {
if (json) {
activityPie('activityPie', {
name: 'Players', colorByPoint: true, data: json.activity_pie_series
});
stackChart('activityStackGraph', json.activity_labels, json.activity_series, 'Players');
} else if (error) {
$('#activityPie').text("Failed to load graph data: " + error);
$('#activityStackGraph').text("Failed to load graph data: " + error);
}
}, 'playerbase-overview');
refreshingJsonRequest("./v1/graph?type=geolocation", function (json, error) {
if (json) {
const geolocationSeries = {
name: 'Players',
type: 'map',
mapData: Highcharts.maps['custom/world'],
data: json.geolocation_series,
joinBy: ['iso-a3', 'code']
};
const geolocationBarSeries = {
color: json.colors.bars,
name: 'Players',
data: json.geolocation_bar_series.map(function (bar) {
return bar.value
})
};
const geolocationBarCategories = json.geolocation_bar_series.map(function (bar) {
return bar.label
});
worldMap('worldMap', json.colors.low, json.colors.high, geolocationSeries);
horizontalBarChart('countryBarChart', geolocationBarCategories, [geolocationBarSeries], 'Players');
} else if (error) {
$('#worldMap').text("Failed to load graph data: " + error);
$('#countryBarChart').text("Failed to load graph data: " + error);
}
}, 'geolocations');
refreshingJsonRequest("./v1/graph?type=playersOnline&server=${serverUUID}", loadPlayersOnlineGraph, 'network-overview');
refreshingJsonRequest("./v1/graph?type=uniqueAndNew", loadUniqueAndNewGraph, 'network-overview');
refreshingJsonRequest("./v1/graph?type=hourlyUniqueAndNew", loadHourlyUniqueAndNewGraph, 'network-overview');
refreshingJsonRequest("./v1/graph?type=serverPie", loadServerPie, 'sessions-overview');
refreshingJsonRequest("./v1/graph?type=activity", loadActivityGraphs, 'playerbase-overview');
refreshingJsonRequest("./v1/graph?type=geolocation", loadGeolocationGraph, 'geolocations');
setLoadingText('Sorting out plugin tables..');
@ -1015,7 +919,7 @@
}
function setLoadingText(text) {
$('.loader-text').text(text);
document.querySelector('.loader-text').innerText = text;
}
</script>