mirror of
https://github.com/pi-hole/web.git
synced 2025-12-24 04:38:28 +00:00
Fix doughnut tooltip and legend
Signed-off-by: Christian König <ckoenig@posteo.de>
This commit is contained in:
@@ -323,7 +323,7 @@ function updateQueryTypesPie() {
|
||||
queryTypePieChart.options.legendCallback = customLegend;
|
||||
|
||||
// Generate legend in separate div
|
||||
$("#query-types-legend").html(queryTypePieChart.generateLegend());
|
||||
// $("#query-types-legend").html(queryTypePieChart.generateLegend());
|
||||
$("#query-types-legend > ul > li").click(function (e) {
|
||||
if (iscolorBox(e.target)) {
|
||||
return false;
|
||||
@@ -568,7 +568,7 @@ function updateForwardDestinationsPie() {
|
||||
forwardDestinationPieChart.options.legendCallback = customLegend;
|
||||
|
||||
// Generate legend in separate div
|
||||
$("#forward-destinations-legend").html(forwardDestinationPieChart.generateLegend());
|
||||
// $("#forward-destinations-legend").html(forwardDestinationPieChart.generateLegend());
|
||||
$("#forward-destinations-legend > ul > li").click(function (e) {
|
||||
if (iscolorBox(e.target)) {
|
||||
return false;
|
||||
@@ -839,32 +839,23 @@ function updateSummaryData(runOnce) {
|
||||
});
|
||||
}
|
||||
|
||||
function doughnutTooltip(tooltipItems, data) {
|
||||
var dataset = data.datasets[tooltipItems.datasetIndex];
|
||||
var label = " " + data.labels[tooltipItems.index];
|
||||
// Compute share of total and of displayed
|
||||
var scale = 0,
|
||||
total = 0;
|
||||
var metas = Object.keys(dataset._meta).map(function (e) {
|
||||
return dataset._meta[e];
|
||||
});
|
||||
metas.forEach(function (meta) {
|
||||
meta.data.forEach(function (val, i) {
|
||||
if (val.hidden) scale += dataset.data[i];
|
||||
total += dataset.data[i];
|
||||
});
|
||||
});
|
||||
if (scale === 0)
|
||||
function doughnutTooltip(tooltipLabel) {
|
||||
var percentageTotalShown = tooltipLabel.chart._metasets[0].total;
|
||||
var label = " " + tooltipLabel.label;
|
||||
|
||||
if (percentageTotalShown >= 100) {
|
||||
// All items shown
|
||||
return label + ": " + dataset.data[tooltipItems.index].toFixed(1) + "%";
|
||||
return (
|
||||
label +
|
||||
":<br>• " +
|
||||
dataset.data[tooltipItems.index].toFixed(1) +
|
||||
"% of all queries<br>• " +
|
||||
((dataset.data[tooltipItems.index] * 100) / (total - scale)).toFixed(1) +
|
||||
"% of shown items"
|
||||
);
|
||||
return label + ": " + tooltipLabel.parsed.toFixed(1) + "%";
|
||||
} else {
|
||||
return (
|
||||
label +
|
||||
":<br>• " +
|
||||
tooltipLabel.parsed.toFixed(1) +
|
||||
"% of all queries<br>• " +
|
||||
((tooltipLabel.parsed * 100) / percentageTotalShown).toFixed(1) +
|
||||
"% of shown items"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
var maxlogage = "24";
|
||||
@@ -1096,7 +1087,12 @@ $(function () {
|
||||
}
|
||||
|
||||
$("#queryOverTimeChart").click(function (evt) {
|
||||
var activePoints = timeLineChart.getElementsAtEventForMode(evt, 'nearest', { intersect: true }, false);
|
||||
var activePoints = timeLineChart.getElementsAtEventForMode(
|
||||
evt,
|
||||
"nearest",
|
||||
{ intersect: true },
|
||||
false
|
||||
);
|
||||
if (activePoints.length > 0) {
|
||||
//get the internal index
|
||||
var clickedElementindex = activePoints[0].index;
|
||||
@@ -1113,7 +1109,12 @@ $(function () {
|
||||
});
|
||||
|
||||
$("#clientsChart").click(function (evt) {
|
||||
var activePoints = clientsChart.getElementsAtEventForMode(evt, 'nearest', { intersect: true }, false);
|
||||
var activePoints = clientsChart.getElementsAtEventForMode(
|
||||
evt,
|
||||
"nearest",
|
||||
{ intersect: true },
|
||||
false
|
||||
);
|
||||
if (activePoints.length > 0) {
|
||||
//get the internal index
|
||||
var clickedElementindex = activePoints[0].index;
|
||||
@@ -1148,18 +1149,23 @@ $(function () {
|
||||
},
|
||||
plugins: {
|
||||
legend: {
|
||||
display: false,
|
||||
display: true,
|
||||
position: "right",
|
||||
align: "start",
|
||||
labels: {
|
||||
boxWidth: 13,
|
||||
color: ticksColor,
|
||||
},
|
||||
},
|
||||
tooltip: {
|
||||
// Disable the on-canvas tooltip
|
||||
enabled: false,
|
||||
custom: customTooltips,
|
||||
external: customTooltips,
|
||||
callbacks: {
|
||||
title: function () {
|
||||
return "Query types";
|
||||
},
|
||||
label: function (tooltipItems, data) {
|
||||
return doughnutTooltip(tooltipItems, data);
|
||||
return "Query type";
|
||||
},
|
||||
label: doughnutTooltip,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1192,18 +1198,23 @@ $(function () {
|
||||
},
|
||||
plugins: {
|
||||
legend: {
|
||||
display: false,
|
||||
display: true,
|
||||
position: "right",
|
||||
align: "start",
|
||||
labels: {
|
||||
boxWidth: 13,
|
||||
color: ticksColor,
|
||||
},
|
||||
},
|
||||
tooltip: {
|
||||
// Disable the on-canvas tooltip
|
||||
enabled: false,
|
||||
custom: customTooltips,
|
||||
external: customTooltips,
|
||||
callbacks: {
|
||||
title: function () {
|
||||
return "Forward destinations";
|
||||
},
|
||||
label: function (tooltipItems, data) {
|
||||
return doughnutTooltip(tooltipItems, data);
|
||||
return "Upstream server";
|
||||
},
|
||||
label: doughnutTooltip,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user