Merge pull request #711 from pi-hole/tweak/pie-chart-legends

Add separate legends for pie charts on the dashboard
This commit is contained in:
Mark Drobnak
2018-04-02 16:44:26 -04:00
committed by GitHub
3 changed files with 74 additions and 8 deletions
+10 -4
View File
@@ -132,8 +132,11 @@ else
<h3 class="box-title">Query Types (integrated)</h3>
</div>
<div class="box-body">
<div class="chart">
<canvas id="queryTypePieChart" width="400" height="150"></canvas>
<div class="float-left" style="width:50%">
<canvas id="queryTypePieChart" width="120" height="120"></canvas>
</div>
<div class="float-left" style="width:50%">
<div id="query-types-legend" class="chart-legend"></div>
</div>
</div>
<div class="overlay">
@@ -148,8 +151,11 @@ else
<h3 class="box-title">Forward Destinations (integrated)</h3>
</div>
<div class="box-body">
<div class="chart">
<canvas id="forwardDestinationPieChart" width="400" height="150"></canvas>
<div class="float-left" style="width:50%">
<canvas id="forwardDestinationPieChart" width="120" height="120"></canvas>
</div>
<div class="float-left" style="width:50%">
<div id="forward-destinations-legend" class="chart-legend"></div>
</div>
</div>
<div class="overlay">
+36 -4
View File
@@ -178,6 +178,23 @@ function updateQueryTypesPie() {
queryTypePieChart.update();
// Don't use rotation animation for further updates
queryTypePieChart.options.animation.duration=0;
// Generate legend in separate div
$("#query-types-legend").html(queryTypePieChart.generateLegend());
$("#query-types-legend > ul > li").on("click",function(e){
$(this).toggleClass("strike");
var index = $(this).index();
var ci = e.view.queryTypePieChart;
var meta = ci.data.datasets[0]._meta;
for(let i in meta)
{
if ({}.hasOwnProperty.call(meta, i))
{
var curr = meta[i].data[index];
curr.hidden = !curr.hidden;
}
}
ci.update();
});
}).done(function() {
// Reload graph after minute
setTimeout(updateQueryTypesPie, 60000);
@@ -392,6 +409,23 @@ function updateForwardDestinationsPie() {
forwardDestinationPieChart.update();
// Don't use rotation animation for further updates
forwardDestinationPieChart.options.animation.duration=0;
// Generate legend in separate div
$("#forward-destinations-legend").html(forwardDestinationPieChart.generateLegend());
$("#forward-destinations-legend > ul > li").on("click",function(e){
$(this).toggleClass("strike");
var index = $(this).index();
var ci = e.view.forwardDestinationPieChart;
var meta = ci.data.datasets[0]._meta;
for(let i in meta)
{
if ({}.hasOwnProperty.call(meta, i))
{
var curr = meta[i].data[index];
curr.hidden = !curr.hidden;
}
}
ci.update();
});
}).done(function() {
// Reload graph after one minute
setTimeout(updateForwardDestinationsPie, 60000);
@@ -960,8 +994,7 @@ $(document).ready(function() {
},
options: {
legend: {
display: true,
position: "right"
display: false
},
tooltips: {
enabled: true,
@@ -998,8 +1031,7 @@ $(document).ready(function() {
},
options: {
legend: {
display: true,
position: "right"
display: false
},
tooltips: {
enabled: true,
+28
View File
@@ -115,3 +115,31 @@ a.lookatme {
-webkit-animation: fa-spin 1s infinite linear;
animation: fa-spin 1s infinite linear;
}
.chart-legend {
height:250px;
overflow:auto;
}
.chart-legend ul {
list-style-type: none;
}
.chart-legend li {
cursor:pointer;
}
.chart-legend li span {
display: inline-block;
width: 20px;
height: 12px;
margin-right: 5px;
}
.strike {
text-decoration: line-through !important;
}
.float-left{
float:left;
}