2019-10-14 10:31:29 +00:00
|
|
|
// Link quality gauge for ChartJS
|
|
|
|
|
2020-03-06 18:57:16 +00:00
|
|
|
// Support for dark theme
|
2019-10-20 17:29:32 +00:00
|
|
|
theme = getCookie('theme');
|
2020-03-06 18:57:16 +00:00
|
|
|
if (theme == 'lightsout.css') {
|
|
|
|
var borderColor = 'rgba(37, 153, 63, 1)';
|
|
|
|
var labelColor = 'rgba(37, 153, 63, 1)';
|
2023-08-30 07:52:59 +00:00
|
|
|
} else if (theme == 'material-light.php') {
|
|
|
|
var borderColor = '#f2f2fb';
|
|
|
|
var labelColor = '#f2f2fb';
|
|
|
|
} else if (theme == 'material-dark.php') {
|
|
|
|
var borderColor = '#f2f2fb';
|
|
|
|
var labelColor = '#f2f2fb';
|
2019-10-20 17:29:32 +00:00
|
|
|
} else {
|
2020-02-02 13:40:41 +00:00
|
|
|
var borderColor = 'rgba(147, 210, 162, 1)';
|
|
|
|
var labelColor = 'rgba(130, 130, 130, 1)';
|
2019-10-20 17:29:32 +00:00
|
|
|
}
|
|
|
|
|
2019-10-14 10:31:29 +00:00
|
|
|
let data1 = {
|
2020-02-02 13:40:41 +00:00
|
|
|
datasets: [{
|
|
|
|
data: [linkQ, 100-linkQ],
|
2023-09-10 08:09:23 +00:00
|
|
|
backgroundColor: 'transparent',
|
2020-02-02 13:40:41 +00:00
|
|
|
borderColor: borderColor,
|
|
|
|
}],
|
2019-10-14 10:31:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let config = {
|
2020-02-02 13:40:41 +00:00
|
|
|
type: 'doughnut',
|
|
|
|
data: data1,
|
|
|
|
options: {
|
|
|
|
aspectRatio: 2,
|
|
|
|
responsive: true,
|
|
|
|
maintainAspectRatio: false,
|
|
|
|
tooltips: {enabled: false},
|
|
|
|
hover: {mode: null},
|
|
|
|
legend: {
|
|
|
|
display: false,
|
|
|
|
},
|
|
|
|
rotation: (2/3)*Math.PI,//2+(1/3),
|
|
|
|
circumference: (1+(2/3)) * Math.PI, // * Math.PI,
|
|
|
|
cutoutPercentage: 80,
|
|
|
|
animation: {
|
|
|
|
animateScale: false,
|
|
|
|
animateRotate: true
|
|
|
|
},
|
|
|
|
tooltips: {
|
|
|
|
enabled: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
centerText: {
|
|
|
|
display: true,
|
|
|
|
text: linkQ + "%"
|
|
|
|
},
|
|
|
|
plugins: [{
|
|
|
|
beforeDraw: function(chart) {
|
|
|
|
if (chart.config.centerText.display !== null &&
|
|
|
|
typeof chart.config.centerText.display !== 'undefined' &&
|
|
|
|
chart.config.centerText.display) {
|
|
|
|
drawLinkQ(chart);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}]
|
2019-10-14 10:31:29 +00:00
|
|
|
};
|
|
|
|
|
2019-10-19 21:56:26 +00:00
|
|
|
function drawLinkQ(chart) {
|
2019-10-14 10:31:29 +00:00
|
|
|
|
2020-02-02 13:40:41 +00:00
|
|
|
let width = chart.chart.width;
|
|
|
|
let height = chart.chart.height;
|
|
|
|
let ctx = chart.chart.ctx;
|
2019-10-14 10:31:29 +00:00
|
|
|
|
2020-02-02 13:40:41 +00:00
|
|
|
ctx.restore();
|
|
|
|
let fontSize = (height / 100).toFixed(2);
|
|
|
|
ctx.font = fontSize + "em sans-serif";
|
|
|
|
ctx.fillStyle = labelColor;
|
|
|
|
ctx.textBaseline = "middle";
|
2019-10-14 10:31:29 +00:00
|
|
|
|
2020-02-02 13:40:41 +00:00
|
|
|
let text = chart.config.centerText.text;
|
|
|
|
let textX = Math.round((width - ctx.measureText(text).width) * 0.5);
|
|
|
|
let textY = height / 2;
|
|
|
|
ctx.fillText(text, textX, textY);
|
|
|
|
ctx.save();
|
2019-10-14 10:31:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
window.onload = function() {
|
2020-02-02 13:40:41 +00:00
|
|
|
let ctx = document.getElementById("divChartLinkQ").getContext("2d");
|
|
|
|
var chart = new Chart(ctx, config);
|
2019-10-14 10:31:29 +00:00
|
|
|
};
|
|
|
|
|