1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00

build: Chart.js 4.5.1

This commit is contained in:
catborise 2026-10-17 12:54:51 +03:00
parent 53d900fd57
commit f5ec757d1a
9 changed files with 164 additions and 404 deletions

View file

@ -380,7 +380,8 @@
});
});
</script>
<script src="{% static 'js/Chart.bundle.min.js' %}"></script>
<script src="{% static 'js/chart.umd.min.js' %}"></script>
<script src="{% static 'js/charts.js' %}"></script>
<script src="{% static 'js/poll.js' %}"></script>
<script>
{% trans "average over" as average_over %}
@ -399,222 +400,21 @@
stats_poll.start();
return;
}
var cpu_ctx = $("#cpuChart").get(0).getContext("2d");
var cpuChart = new Chart(cpu_ctx, {
type: 'line',
data: {
datasets : [{
backgroundColor: "rgba(44,127,184,0.5)",
label: "Usage"
}]
var cpuChart = lineChart(document.getElementById("cpuChart"), "%", ["Usage"], {
max: 100,
tooltip: function (context, text) {
var span = cpuWindows[context.dataIndex];
return span ? text + ' ({{ average_over|escapejs }} ' + span + ' s)' : text;
},
options: {
responsive: true,
legend: {
display: false
},
scales: {
xAxes:[{
offset: false,
ticks: {
beginAtZero: false,
autoSkip: true,
maxTicksLimit: 10,
maxRotation: 0,
minRotation: 0,
stepSize: 10,
},
}],
yAxes: [{
ticks: {
suggestedMax: 100,
suggestedMin: 0,
stepSize: 20,
callback: function(value, index, values) {
return value + ' %';
}
},
}],
},
tooltips: {
callbacks: {
label: function (tooltipItem, chart) {
var label = chart.datasets[tooltipItem.datasetIndex].label || '';
if (label) {
label += ': ';
}
label += tooltipItem.yLabel + ' %';
var span = cpuWindows[tooltipItem.index];
return span ? label + ' ({{ average_over|escapejs }} ' + span + ' s)' : label;
}
}
}
}
});
var mem_ctx = $("#memChart").get(0).getContext("2d");
var memChart = new Chart(mem_ctx, {
type: 'line',
data: {
datasets : [{
label: "Usage"
}]
},
options: {
responsive: true,
legend: {
display: false
},
scales: {
xAxes:[{
offset: false,
ticks: {
beginAtZero: false,
autoSkip: true,
maxTicksLimit: 10,
maxRotation: 0,
minRotation: 0,
stepSize: 10,
},
}],
yAxes: [{
ticks: {
suggestedMax: 100,
suggestedMin: 0,
stepSize: 20,
callback: function(value, index, values) {
return value + ' MB';
}
},
}],
},
tooltips: {
callbacks: {
label: function (tooltipItem, chart) {
var label = chart.datasets[tooltipItem.datasetIndex].label || '';
if (label) {
label += '(RSS): ';
}
return label += tooltipItem.yLabel + ' MB';
}
}
}
}
});
var memChart = lineChart(document.getElementById("memChart"), "MB", ["Usage (RSS)"]);
var diskChart = {};
{% for disk in instance.disks %}
var disk_ctx_{{ disk.dev }} = $("#blk{{ disk.dev }}Chart").get(0).getContext("2d");
diskChart['{{ disk.dev }}'] = new Chart(disk_ctx_{{ disk.dev }}, {
type: 'line',
data: {
datasets : [{
backgroundColor: "rgba(127,205,187,0.5)",
label: "Read"
},
{
backgroundColor: "rgba(44,127,184,0.5)",
label: "Write"
}]
},
options: {
responsive: true,
legend: {
display: false
},
scales: {
xAxes:[{
offset: false,
ticks: {
beginAtZero: false,
autoSkip: true,
maxTicksLimit: 10,
maxRotation: 0,
minRotation: 0,
stepSize: 10,
},
}],
yAxes: [{
ticks: {
suggestedmax: 100,
suggestedMin: 0,
callback: function(value, index, values) {
return value + ' MB/s';
}
},
}],
},
tooltips: {
callbacks: {
label: function (tooltipItem, chart) {
var label = chart.datasets[tooltipItem.datasetIndex].label || '';
if (label) {
label += ': ';
}
return label += tooltipItem.yLabel + ' MB/s';
}
}
}
}
});
diskChart['{{ disk.dev|escapejs }}'] = lineChart(document.getElementById("blk{{ disk.dev|escapejs }}Chart"), "MB/s", ["Read", "Write"]);
{% endfor %}
var netChart = {};
{% for net in instance.networks %}
var net_ctx_{{ forloop.counter0 }} = $("#netEth{{ forloop.counter0 }}Chart").get(0).getContext("2d");
netChart[{{ forloop.counter0 }}] = new Chart(net_ctx_{{ forloop.counter0 }}, {
type: 'line',
data: {
datasets : [
{
backgroundColor: "rgba(127,205,187,0.5)",
label: "Inbound"
},
{
backgroundColor: "rgba(44,127,184,0.5)",
label: "Outbound"
}]
},
options: {
responsive: true,
legend: {
display: false
},
scales: {
xAxes:[{
offset: false,
ticks: {
beginAtZero: false,
autoSkip: true,
maxTicksLimit: 10,
maxRotation: 0,
minRotation: 0,
stepSize: 10,
},
}],
yAxes: [{
ticks: {
suggestedMax: 100,
suggestedMin: 0,
callback: function(value, index, values) {
return value + ' Mbps';
}
},
}],
},
tooltips: {
callbacks: {
label: function (tooltipItem, chart) {
var label = chart.datasets[tooltipItem.datasetIndex].label || '';
if (label) {
label += ': ';
}
return label += tooltipItem.yLabel + ' Mbps';
}
}
}
}
});
netChart[{{ forloop.counter0 }}] = lineChart(document.getElementById("netEth{{ forloop.counter0 }}Chart"), "Mbit/s", ["Inbound", "Outbound"]);
{% endfor %}
// the first point at once, then every 5 s like the host graph
@ -625,40 +425,23 @@
});
}, function graph_usage(data) {
statsSample = data.sample || null;
cpuChart.data.labels.push(data.timeline);
cpuChart.data.datasets[0].data.push(data.cpudata);
cpuWindows.push(data.window);
if (cpuChart.data.datasets[0].data.length > 10){
cpuChart.data.labels.shift();
cpuChart.data.datasets[0].data.shift();
if (cpuWindows.length > CHART_POINTS) {
cpuWindows.shift();
}
cpuChart.update();
memChart.data.labels.push(data.timeline);
memChart.options.scales.yAxes[0].ticks.max = parseInt(data.memdata.total / 1024);
memChart.options.scales.yAxes[0].ticks.stepSize = parseInt(data.memdata.total / (1024 * 5));
memChart.data.datasets[0].data.push(data.memdata.used / 1024);
if (memChart.data.datasets[0].data.length > 10){
memChart.data.labels.shift();
memChart.data.datasets[0].data.shift();
addPoint(cpuChart, data.timeline, [data.cpudata]);
// a VM whose memory could not be read gives total 0: a gap, same axis
if (data.memdata.total) {
memChart.options.scales.y.max = Math.round(data.memdata.total / 1024);
addPoint(memChart, data.timeline, [Math.round(data.memdata.used / 1024)]);
} else {
addPoint(memChart, data.timeline, [null]);
}
memChart.update();
// a disk or NIC added after the page loaded has no chart until a reload
function push(chart, values) {
if (!chart) {
return;
if (chart) {
addPoint(chart, data.timeline, values);
}
chart.data.labels.push(data.timeline);
chart.data.datasets[0].data.push(values[0]);
chart.data.datasets[1].data.push(values[1]);
if (chart.data.datasets[0].data.length > 10){
chart.data.labels.shift();
chart.data.datasets[0].data.shift();
chart.data.datasets[1].data.shift();
}
chart.update();
}
data.blkdata.forEach(function (disk) { push(diskChart[disk.dev], disk.data); });
data.netdata.forEach(function (nic) { push(netChart[nic.dev], nic.data); });