Merge pull request #574 from pi-hole/fix/dashboard_percentages

Fixes for the dashboard due to recent FTL changes
This commit is contained in:
DL6ER
2017-09-20 22:41:13 +02:00
committed by GitHub
2 changed files with 36 additions and 26 deletions
+7 -7
View File
@@ -179,11 +179,11 @@ if (isset($_GET['getForwardDestinations']) && $auth)
$tmp = explode(" ",$line);
if(count($tmp) == 4)
{
$forward_dest[$tmp[3]."|".$tmp[2]] = intval($tmp[1]);
$forward_dest[$tmp[3]."|".$tmp[2]] = floatval($tmp[1]);
}
else
{
$forward_dest[$tmp[2]] = intval($tmp[1]);
$forward_dest[$tmp[2]] = floatval($tmp[1]);
}
}
@@ -199,7 +199,7 @@ if (isset($_GET['getQueryTypes']) && $auth)
foreach($return as $ret)
{
$tmp = explode(": ",$ret);
$querytypes[$tmp[0]] = intval($tmp[1]);
$querytypes[$tmp[0]] = floatval($tmp[1]);
}
$result = array('querytypes' => $querytypes);
@@ -257,7 +257,7 @@ if (isset($_GET['overTimeDataForwards']) && $auth)
{
$tmp = explode(" ",$line);
for ($i=0; $i < count($tmp)-1; $i++) {
$over_time[intval($tmp[0])][$i] = intval($tmp[$i+1]);
$over_time[intval($tmp[0])][$i] = floatval($tmp[$i+1]);
}
}
$result = array('over_time' => $over_time);
@@ -274,11 +274,11 @@ if (isset($_GET['getForwardDestinationNames']) && $auth)
$tmp = explode(" ",$line);
if(count($tmp) == 4)
{
$forward_dest[$tmp[3]."|".$tmp[2]] = intval($tmp[1]);
$forward_dest[$tmp[3]."|".$tmp[2]] = floatval($tmp[1]);
}
else
{
$forward_dest[$tmp[2]] = intval($tmp[1]);
$forward_dest[$tmp[2]] = floatval($tmp[1]);
}
}
@@ -296,7 +296,7 @@ if (isset($_GET['overTimeDataQueryTypes']) && $auth)
{
$tmp = explode(" ",$line);
for ($i=0; $i < count($tmp)-1; $i++) {
$over_time[intval($tmp[0])][$i] = intval($tmp[$i+1]);
$over_time[intval($tmp[0])][$i] = floatval($tmp[$i+1]);
}
}
$result = array('over_time' => $over_time);
+29 -19
View File
@@ -118,17 +118,9 @@ function updateQueryTypesOverTime() {
// New style: Get Unix timestamps
d = new Date(1000*h);
var sum = plotdata[j][0] + plotdata[j][1];
var A = 0, AAAA = 0;
if(sum > 0)
{
A = plotdata[j][0]/sum;
AAAA = plotdata[j][1]/sum;
}
queryTypeChart.data.labels.push(d);
queryTypeChart.data.datasets[0].data.push(A);
queryTypeChart.data.datasets[1].data.push(AAAA);
queryTypeChart.data.datasets[0].data.push(1e-2*plotdata[j][0]);
queryTypeChart.data.datasets[1].data.push(1e-2*plotdata[j][1]);
}
}
$("#query-types .overlay").hide();
@@ -243,18 +235,10 @@ function updateForwardedOverTime() {
for (j in timestamps)
{
if (!{}.hasOwnProperty.call(timestamps, j)) continue;
var sum = 0.0;
for (key in plotdata[j])
{
if (!{}.hasOwnProperty.call(plotdata[j], key)) continue;
sum += plotdata[j][key];
}
var dd = [];
for (key in plotdata[j])
{
if (!{}.hasOwnProperty.call(plotdata[j], key)) continue;
var singlepoint = plotdata[j][key];
forwardDestinationChart.data.datasets[key].data.push(singlepoint/sum);
forwardDestinationChart.data.datasets[key].data.push(1e-2*plotdata[j][key]);
}
var d = new Date(1000*parseInt(timestamps[j]));
@@ -822,6 +806,19 @@ $(document).ready(function() {
display: true,
position: "right"
},
tooltips: {
enabled: true,
callbacks: {
title: function(tooltipItem, data) {
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) + "%";
}
}
},
animation: {
duration: 2000
},
@@ -847,6 +844,19 @@ $(document).ready(function() {
display: true,
position: "right"
},
tooltips: {
enabled: true,
callbacks: {
title: function(tooltipItem, data) {
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) + "%";
}
}
},
animation: {
duration: 2000
},