fix: NVD3 1.8.1 API compat, null guards, missing brace
- Removed useInteractiveGuideline (not in NVD3 1.8.1 on CDN) - Added null guards in updateData + updateCharts for navigation-away - Fixed missing closing brace in updateCharts if block Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+30
-5
@@ -50,7 +50,6 @@ function ServerInfoPage(params, container) {
|
|||||||
var perfChart = nv.models.multiChart()
|
var perfChart = nv.models.multiChart()
|
||||||
.margin({ top: 30, right: 75, bottom: 40, left: 75 })
|
.margin({ top: 30, right: 75, bottom: 40, left: 75 })
|
||||||
.color(['darkred', 'yellowgreen'])
|
.color(['darkred', 'yellowgreen'])
|
||||||
.useInteractiveGuideline(true)
|
|
||||||
.duration(0);
|
.duration(0);
|
||||||
perfChart.yAxis1.axisLabel('Framerate').tickFormat(d3.format(',d'));
|
perfChart.yAxis1.axisLabel('Framerate').tickFormat(d3.format(',d'));
|
||||||
perfChart.yAxis2.axisLabel('Entities').tickFormat(d3.format(',d'));
|
perfChart.yAxis2.axisLabel('Entities').tickFormat(d3.format(',d'));
|
||||||
@@ -69,7 +68,6 @@ function ServerInfoPage(params, container) {
|
|||||||
nv.addGraph(function () {
|
nv.addGraph(function () {
|
||||||
var netChart = nv.models.stackedAreaChart()
|
var netChart = nv.models.stackedAreaChart()
|
||||||
.margin({ top: 0, right: 75, bottom: 40, left: 75 })
|
.margin({ top: 0, right: 75, bottom: 40, left: 75 })
|
||||||
.useInteractiveGuideline(true)
|
|
||||||
.duration(0);
|
.duration(0);
|
||||||
netChart.yAxis.axisLabel('Network').tickFormat(function (bytes) {
|
netChart.yAxis.axisLabel('Network').tickFormat(function (bytes) {
|
||||||
var fmt = d3.format('.0f');
|
var fmt = d3.format('.0f');
|
||||||
@@ -87,6 +85,22 @@ function ServerInfoPage(params, container) {
|
|||||||
|
|
||||||
window._netChart = netChart;
|
window._netChart = netChart;
|
||||||
});
|
});
|
||||||
|
netChart.yAxis.axisLabel('Network').tickFormat(function (bytes) {
|
||||||
|
var fmt = d3.format('.0f');
|
||||||
|
if (bytes < 1024) return fmt(bytes) + 'B';
|
||||||
|
if (bytes < 1048576) return fmt(bytes / 1024) + 'kB';
|
||||||
|
if (bytes < 1073741824) return fmt(bytes / 1048576) + 'MB';
|
||||||
|
return fmt(bytes / 1073741824) + 'GB';
|
||||||
|
});
|
||||||
|
netChart.xAxis.axisLabel('Time').tickFormat(function (d) { return d3.time.format('%H:%M:%S')(new Date(d)); });
|
||||||
|
|
||||||
|
d3.select('#chart-network').datum([
|
||||||
|
{ key: 'IN', values: [] },
|
||||||
|
{ key: 'OUT', values: [] }
|
||||||
|
]).call(netChart);
|
||||||
|
|
||||||
|
window._netChart = netChart;
|
||||||
|
});
|
||||||
|
|
||||||
nv.addGraph(function () {
|
nv.addGraph(function () {
|
||||||
var playersChart = nv.models.pieChart()
|
var playersChart = nv.models.pieChart()
|
||||||
@@ -115,6 +129,10 @@ function ServerInfoPage(params, container) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateData(data) {
|
function updateData(data) {
|
||||||
|
// Guard: element may be gone if navigated away
|
||||||
|
var fieldsEl = document.getElementById('si-fields');
|
||||||
|
if (!fieldsEl) return;
|
||||||
|
|
||||||
// Update text fields
|
// Update text fields
|
||||||
var fieldsHtml = '';
|
var fieldsHtml = '';
|
||||||
for (var key in data) {
|
for (var key in data) {
|
||||||
@@ -124,8 +142,11 @@ function ServerInfoPage(params, container) {
|
|||||||
fieldsHtml += '<div class="col-sm-4"><p><span class="text-white-50">' + key + ':</span> <span>' + val + '</span></p></div>';
|
fieldsHtml += '<div class="col-sm-4"><p><span class="text-white-50">' + key + ':</span> <span>' + val + '</span></p></div>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
document.getElementById('si-fields').innerHTML = fieldsHtml;
|
fieldsEl.innerHTML = fieldsHtml;
|
||||||
if (data.Hostname) document.getElementById('si-hostname').textContent = data.Hostname;
|
if (data.Hostname) {
|
||||||
|
var hn = document.getElementById('si-hostname');
|
||||||
|
if (hn) hn.textContent = data.Hostname;
|
||||||
|
}
|
||||||
|
|
||||||
// Collect chart data
|
// Collect chart data
|
||||||
recordedData.push({ ts: Date.now(), data: data });
|
recordedData.push({ ts: Date.now(), data: data });
|
||||||
@@ -136,15 +157,19 @@ function ServerInfoPage(params, container) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateCharts(data) {
|
function updateCharts(data) {
|
||||||
|
// Guard: SVG elements may be gone if navigated away
|
||||||
// Players pie chart
|
// Players pie chart
|
||||||
if (window._playersChart) {
|
if (window._playersChart) {
|
||||||
d3.select('#chart-players').datum([
|
var pc = d3.select('#chart-players');
|
||||||
|
if (!pc.empty()) {
|
||||||
|
pc.datum([
|
||||||
{ key: 'Queued', y: data.Queued || 0 },
|
{ key: 'Queued', y: data.Queued || 0 },
|
||||||
{ key: 'Joining', y: data.Joining || 0 },
|
{ key: 'Joining', y: data.Joining || 0 },
|
||||||
{ key: 'Players', y: data.Players || 0 },
|
{ key: 'Players', y: data.Players || 0 },
|
||||||
{ key: 'Free', y: (data.MaxPlayers || 0) - ((data.Joining || 0) + (data.Players || 0)) }
|
{ key: 'Free', y: (data.MaxPlayers || 0) - ((data.Joining || 0) + (data.Players || 0)) }
|
||||||
]).call(window._playersChart);
|
]).call(window._playersChart);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Performance chart
|
// Performance chart
|
||||||
var fpsVals = [], entVals = [], netInVals = [], netOutVals = [];
|
var fpsVals = [], entVals = [], netInVals = [], netOutVals = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user