mirror of
https://github.com/pi-hole/web.git
synced 2024-12-06 19:36:21 +01:00
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:
@@ -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">
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user