feat: NET图表改为DualLineChart (上下行双线)
This commit is contained in:
@@ -98,7 +98,7 @@
|
|||||||
var btn = document.getElementById("btn-layout");
|
var btn = document.getElementById("btn-layout");
|
||||||
var grid = document.getElementById("sentinel-grid");
|
var grid = document.getElementById("sentinel-grid");
|
||||||
// 销毁旧图表
|
// 销毁旧图表
|
||||||
try { Object.keys(_chartInstances).forEach(function(k){ if(_chartInstances[k]) _chartInstances[k].forEach(function(c){ if(c.destroy)c.destroy(); }); }); } catch(e) {}
|
try { Object.keys(_chartInstances).forEach(function(k){ var chs = _chartInstances[k]; if(chs) { Object.values(chs).forEach(function(c){ if(c&&c.destroy)c.destroy(); }); } }); } catch(e) {}
|
||||||
_chartInstances = {};
|
_chartInstances = {};
|
||||||
_cardCache = {};
|
_cardCache = {};
|
||||||
_firstRender = true;
|
_firstRender = true;
|
||||||
@@ -150,7 +150,7 @@
|
|||||||
var grid = document.getElementById("sentinel-grid");
|
var grid = document.getElementById("sentinel-grid");
|
||||||
if (!nodes.length) {
|
if (!nodes.length) {
|
||||||
grid.innerHTML = '<div class="card" style="text-align:center;padding:24px;color:var(--text-dim)">暂无节点 — 切换到节点管理添加</div>';
|
grid.innerHTML = '<div class="card" style="text-align:center;padding:24px;color:var(--text-dim)">暂无节点 — 切换到节点管理添加</div>';
|
||||||
try { Object.keys(_chartInstances).forEach(function(k){ if(_chartInstances[k]) _chartInstances[k].forEach(function(c){ if(c.destroy)c.destroy(); }); }); } catch(e) {}
|
try { Object.keys(_chartInstances).forEach(function(k){ var chs = _chartInstances[k]; if(chs) { Object.values(chs).forEach(function(c){ if(c&&c.destroy)c.destroy(); }); } }); } catch(e) {}
|
||||||
_chartInstances = {};
|
_chartInstances = {};
|
||||||
_cardCache = {};
|
_cardCache = {};
|
||||||
_firstRender = true;
|
_firstRender = true;
|
||||||
@@ -205,13 +205,16 @@
|
|||||||
}
|
}
|
||||||
grid.appendChild(card);
|
grid.appendChild(card);
|
||||||
_cardCache[id] = card;
|
_cardCache[id] = card;
|
||||||
if (isRow && typeof MiniChart !== 'undefined' && !_chartInstances[id]) {
|
if (isRow && !_chartInstances[id]) {
|
||||||
try {
|
try {
|
||||||
_chartInstances[id] = [
|
_chartInstances[id] = { cpu: null, mem: null, net: null };
|
||||||
new MiniChart(id+'-cpu', '#7aa2f7'),
|
if (typeof MiniChart !== 'undefined') {
|
||||||
new MiniChart(id+'-mem', '#9ece6a'),
|
_chartInstances[id].cpu = new MiniChart(id+'-cpu', '#7aa2f7');
|
||||||
new MiniChart(id+'-net', '#e0af68'),
|
_chartInstances[id].mem = new MiniChart(id+'-mem', '#9ece6a');
|
||||||
];
|
}
|
||||||
|
if (typeof DualLineChart !== 'undefined') {
|
||||||
|
_chartInstances[id].net = new DualLineChart(id+'-net', '#bb9af7', '#c0a8f0');
|
||||||
|
}
|
||||||
} catch(e) {}
|
} catch(e) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -250,8 +253,12 @@
|
|||||||
if (netUp) netUp.textContent = '↑' + fmtSpeed(net.tx_bytes_sec||0);
|
if (netUp) netUp.textContent = '↑' + fmtSpeed(net.tx_bytes_sec||0);
|
||||||
if (mrd) mrd.textContent = (mem.used_gb||0).toFixed(1)+'/'+(mem.total_gb||0).toFixed(1)+' GB';
|
if (mrd) mrd.textContent = (mem.used_gb||0).toFixed(1)+'/'+(mem.total_gb||0).toFixed(1)+' GB';
|
||||||
var charts = _chartInstances[id];
|
var charts = _chartInstances[id];
|
||||||
if (charts && charts[0]) {
|
if (charts) {
|
||||||
try { charts[0].update(cpuVal); charts[1].update(memVal); charts[2].update(net.rx_bytes_sec||0); } catch(e) {}
|
try {
|
||||||
|
if (charts.cpu) charts.cpu.update(cpuVal);
|
||||||
|
if (charts.mem) charts.mem.update(memVal);
|
||||||
|
if (charts.net) charts.net.update(net.rx_bytes_sec||0, net.tx_bytes_sec||0);
|
||||||
|
} catch(e) {}
|
||||||
}
|
}
|
||||||
var infoR = card.querySelector('.col-info');
|
var infoR = card.querySelector('.col-info');
|
||||||
if (infoR) infoR.textContent = (n.last_seen ? new Date(n.last_seen*1000).toLocaleTimeString() : '—');
|
if (infoR) infoR.textContent = (n.last_seen ? new Date(n.last_seen*1000).toLocaleTimeString() : '—');
|
||||||
|
|||||||
Reference in New Issue
Block a user