diff --git a/scripts/pi-hole/js/index.js b/scripts/pi-hole/js/index.js
index fde72372..3442f342 100644
--- a/scripts/pi-hole/js/index.js
+++ b/scripts/pi-hole/js/index.js
@@ -319,24 +319,71 @@ function updateQueryTypesPie() {
queryTypePieChart.update();
// Don't use rotation animation for further updates
queryTypePieChart.options.animation.duration = 0;
+ queryTypePieChart.options.legendCallback = customLegend;
+
// Generate legend in separate div
$("#query-types-legend").html(queryTypePieChart.generateLegend());
- $("#query-types-legend > ul > li").prepend(createEyeConElement());
$("#query-types-legend > ul > li").click(function (e) {
- if (isEyeCon(e.target)) {
+ if (iscolorBox(e.target)) {
return false;
}
window.location.href = "queries.php?querytype=" + querytypeids[$(this).index()];
});
+ $("#query-types-legend .colorBoxWrapper").click(function (e) {
+ hidePieSlice(e);
+ });
}).done(function () {
// Reload graph after minute
setTimeout(updateQueryTypesPie, 60000);
});
}
+function customLegend(chart) {
+ var text = [];
+ var data = chart.data;
+ var datasets = data.datasets;
+ var labels = data.labels;
+
+ text.push('
');
+
+ if (datasets.length > 0) {
+ for (var i = 0; i < datasets[0].data.length; ++i) {
+ var color = datasets[0].backgroundColor[i];
+
+ var txt = "";
+
+ // legend box icon
+ txt =
+ '' +
+ '' +
+ "";
+
+ // color block
+ txt += '';
+
+ // label
+ if (labels[i]) {
+ txt +=
+ '' +
+ labels[i] +
+ "";
+ }
+
+ text.push("- " + txt + "
");
+ }
+ }
+
+ text.push("
");
+ return text.join("");
+}
+
function hidePieSlice(event) {
- toggleEyeCon(event.target);
+ togglecolorBox(event.target);
var legendID = $(event.target).closest(".chart-legend").attr("id");
var ci =
@@ -360,19 +407,19 @@ function hidePieSlice(event) {
ci.update();
}
-function toggleEyeCon(target) {
+function togglecolorBox(target) {
var parentListItem = $(target).closest("li");
- var eyeCon = $(parentListItem).find(".fa-eye, .fa-eye-slash");
+ var colorBox = $(parentListItem).find(".fa-check-square, .fa-square");
- if (eyeCon) {
- $(eyeCon).toggleClass("fa-eye");
- $(eyeCon).toggleClass("fa-eye-slash");
+ if (colorBox) {
+ $(colorBox).toggleClass("fa-check-square");
+ $(colorBox).toggleClass("fa-square");
}
}
-function isEyeCon(target) {
- // See if click happened on eyeConWrapper or child SVG
- if ($(target).closest(".eyeConWrapper")[0]) {
+function iscolorBox(target) {
+ // See if click happened on colorBoxWrapper or child SVG
+ if ($(target).closest(".colorBoxWrapper")[0]) {
return true;
}
@@ -468,16 +515,6 @@ function updateClientsOverTime() {
});
}
-function createEyeConElement() {
- var eyeConWrapper = $("")
- .addClass("eyeConWrapper")
- .click(function (e) {
- hidePieSlice(e);
- });
- eyeConWrapper.append($(""));
- return eyeConWrapper;
-}
-
function updateForwardDestinationsPie() {
$.getJSON("api.php?getForwardDestinations", function (data) {
if ("FTLnotrunning" in data) {
@@ -519,11 +556,12 @@ function updateForwardDestinationsPie() {
forwardDestinationPieChart.update();
// Don't use rotation animation for further updates
forwardDestinationPieChart.options.animation.duration = 0;
+ forwardDestinationPieChart.options.legendCallback = customLegend;
+
// Generate legend in separate div
$("#forward-destinations-legend").html(forwardDestinationPieChart.generateLegend());
- $("#forward-destinations-legend > ul > li").prepend(createEyeConElement());
$("#forward-destinations-legend > ul > li").click(function (e) {
- if (isEyeCon(e.target)) {
+ if (iscolorBox(e.target)) {
return false;
}
@@ -532,6 +570,9 @@ function updateForwardDestinationsPie() {
window.location.href = "queries.php?forwarddest=" + obj;
}
});
+ $("#forward-destinations-legend .colorBoxWrapper").click(function (e) {
+ hidePieSlice(e);
+ });
}).done(function () {
// Reload graph after one minute
setTimeout(updateForwardDestinationsPie, 60000);
@@ -795,7 +836,7 @@ function updateSummaryData(runOnce) {
function doughnutTooltip(tooltipItems, data) {
var dataset = data.datasets[tooltipItems.datasetIndex];
- var label = data.labels[tooltipItems.index];
+ var label = " " + data.labels[tooltipItems.index];
// Compute share of total and of displayed
var scale = 0,
total = 0;
@@ -813,9 +854,9 @@ function doughnutTooltip(tooltipItems, data) {
return label + ": " + dataset.data[tooltipItems.index].toFixed(1) + "%";
return (
label +
- ":
- " +
+ ":
• " +
dataset.data[tooltipItems.index].toFixed(1) +
- "% of all queries
- " +
+ "% of all queries
• " +
((dataset.data[tooltipItems.index] * 100) / (total - scale)).toFixed(1) +
"% of shown items"
);
diff --git a/style/pi-hole.css b/style/pi-hole.css
index f17b5d73..25ce570f 100644
--- a/style/pi-hole.css
+++ b/style/pi-hole.css
@@ -215,21 +215,54 @@
.chart-legend ul {
list-style-type: none;
+ padding-left: 45px;
}
.chart-legend li {
cursor: pointer;
- word-break: break-all;
+ position: relative;
+ line-height: 1;
+ margin: 0 0 6px;
}
.chart-legend li span {
display: inline-block;
- width: 20px;
height: 12px;
+}
+
+.colorBoxWrapper {
+ font-size: 14px;
+}
+
+.colorBoxWrapper:hover {
+ transform: scale(1.15);
+}
+
+.chart-legend li .colorBoxWrapper {
+ position: absolute;
+ width: 20px;
+ left: -20px;
+ top: 0;
+ line-height: 1;
+}
+
+.chart-legend li .legend-color-box {
+ display: none;
+ width: 12px;
margin-right: 5px;
}
-.strike {
+.chart-legend li .legend-label-text {
+ line-height: 1;
+ word-break: break-word;
+}
+
+.chart-legend li .legend-label-text:hover {
+ text-decoration: underline;
+}
+
+.strike,
+.strike span {
text-decoration: line-through !important;
}
@@ -551,10 +584,6 @@ td.details-control {
height: 50px;
}
-.eyeConWrapper {
- font-size: 14px;
-}
-
#apiTokenIframe {
width: 100%;
border: 0;