Skip to content

Commit

Permalink
Merge pull request #1708 from pi-hole/release/v5.3.1
Browse files Browse the repository at this point in the history
Pi-hole AdminLTE v5.3.1
  • Loading branch information
PromoFaux authored Jan 19, 2021
2 parents 3ff33a3 + 5baa16e commit 704e5d4
Showing 1 changed file with 49 additions and 21 deletions.
70 changes: 49 additions & 21 deletions scripts/pi-hole/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,14 @@ function updateQueryTypesPie() {
$(this).toggleClass("strike");
var index = $(this).index();
var ci = e.view.queryTypePieChart;
var meta = ci.data.datasets[0]._meta;
for (var i in meta) {
if (Object.prototype.hasOwnProperty.call(meta, i)) {
var curr = meta[i].data[index];
curr.hidden = !curr.hidden;
}
}
var mobj = ci.data.datasets[0]._meta;
var metas = Object.keys(mobj).map(function (e) {
return mobj[e];
});
metas.forEach(function (meta) {
var curr = meta.data[index];
curr.hidden = !curr.hidden;
});

ci.update();
} else if (e.which === 1) {
Expand Down Expand Up @@ -485,19 +486,22 @@ function updateForwardDestinationsPie() {
$(this).toggleClass("strike");
var index = $(this).index();
var ci = e.view.forwardDestinationPieChart;
var meta = ci.data.datasets[0]._meta;
for (var i in meta) {
if (Object.prototype.hasOwnProperty.call(meta, i)) {
var curr = meta[i].data[index];
curr.hidden = !curr.hidden;
}
}
var mobj = ci.data.datasets[0]._meta;
var metas = Object.keys(mobj).map(function (e) {
return mobj[e];
});
metas.forEach(function (meta) {
var curr = meta.data[index];
curr.hidden = !curr.hidden;
});

ci.update();
} else if (e.which === 1) {
// which == 1 is left mouse button
var obj = encodeURIComponent(e.target.textContent);
window.open("queries.php?forwarddest=" + obj, "_self");
if (obj.length > 0) {
window.open("queries.php?forwarddest=" + obj, "_self");
}
}
});
}).done(function () {
Expand Down Expand Up @@ -785,6 +789,34 @@ 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)
// 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"
);
}

$(function () {
// Pull in data via AJAX
updateSummaryData();
Expand Down Expand Up @@ -1035,9 +1067,7 @@ $(function () {
return "Query types";
},
label: function (tooltipItems, data) {
var dataset = data.datasets[tooltipItems.datasetIndex];
var label = data.labels[tooltipItems.index];
return label + ": " + dataset.data[tooltipItems.index].toFixed(1) + "%";
return doughnutTooltip(tooltipItems, data);
}
}
},
Expand Down Expand Up @@ -1077,9 +1107,7 @@ $(function () {
return "Forward destinations";
},
label: function (tooltipItems, data) {
var dataset = data.datasets[tooltipItems.datasetIndex];
var label = data.labels[tooltipItems.index];
return label + ": " + dataset.data[tooltipItems.index].toFixed(1) + "%";
return doughnutTooltip(tooltipItems, data);
}
}
},
Expand Down

0 comments on commit 704e5d4

Please sign in to comment.