From e1dae514adf81f9acffbd129c441962e33bc12f7 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 23 Nov 2016 18:33:11 +0100 Subject: [PATCH 1/3] Fixes the main diagram --- js/pihole/index.js | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/js/pihole/index.js b/js/pihole/index.js index 5d22efdd..872a6420 100644 --- a/js/pihole/index.js +++ b/js/pihole/index.js @@ -63,9 +63,10 @@ $(document).ready(function() { mode: "x-axis", callbacks: { title(tooltipItem, data) { - var idx = tooltipItem[0].index; - var h = Math.floor(idx/6); - var m = 10*(idx%6); + var label = tooltipItem[0].xLabel; + var time = label.match(/(\d?\d):?(\d?\d?)/); + var h = parseInt(time[1], 10); + var m = parseInt(time[2], 10) || 0; var from = padNumber(h)+":"+padNumber(m)+":00"; var to = padNumber(h)+":"+padNumber(m+9)+":59"; return "Queries from "+from+" to "+to; @@ -147,6 +148,23 @@ $(document).ready(function() { updateTopLists(); }); +// Helper function needed for converting the Objects to Arrays + +function objectToArray(p){ + console.log(p); + var keys = Object.keys(p); + keys.sort(function(a, b) { + return a - b; + }); + + var arr = [], idx = []; + for (var i = 0; i < keys.length; i++) { + arr.push(p[keys[i]]); + idx.push(keys[i]); + } + return [idx,arr]; +} + // Functions to update data in page function updateSummaryData(runOnce) { @@ -179,18 +197,22 @@ function updateSummaryData(runOnce) { } });; } - +var iff; function updateQueriesOverTime() { $.getJSON("api.php?overTimeData10mins", function(data) { // Add data for each hour that is available // remove last data point since it not representative - data.ads_over_time.splice(-1,1); - for (var hour in data.ads_over_time) { + data.domains_over_time = objectToArray(data.domains_over_time); + data.ads_over_time = objectToArray(data.ads_over_time); + data.ads_over_time[0].splice(-1,1); + iff = data.ads_over_time; + for (var hour in data.ads_over_time[0]) { var d = new Date(); - d.setHours(Math.floor(hour/6),10*(hour%6),0,0); + var h = parseInt(data.domains_over_time[0][hour]); + d.setHours(Math.floor(h/6),10*(h%6),0,0); timeLineChart.data.labels.push(d); - timeLineChart.data.datasets[0].data.push(data.domains_over_time[hour]); - timeLineChart.data.datasets[1].data.push(data.ads_over_time[hour]); + timeLineChart.data.datasets[0].data.push(data.domains_over_time[1][hour]); + timeLineChart.data.datasets[1].data.push(data.ads_over_time[1][hour]); } $('#queries-over-time .overlay').remove(); timeLineChart.update(); From 69336891fc31d69028fd6822e2a6eacf77286f50 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 23 Nov 2016 18:43:54 +0100 Subject: [PATCH 2/3] Remove debug statement --- js/pihole/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/pihole/index.js b/js/pihole/index.js index 97fd031b..dbf3fcbf 100644 --- a/js/pihole/index.js +++ b/js/pihole/index.js @@ -166,7 +166,6 @@ $(document).ready(function() { // Helper function needed for converting the Objects to Arrays function objectToArray(p){ - console.log(p); var keys = Object.keys(p); keys.sort(function(a, b) { return a - b; From d8644c2999809ebb3192f1d0f41e0d8458c6bf4b Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 23 Nov 2016 18:53:04 +0100 Subject: [PATCH 3/3] Removed an unused variable; --- js/pihole/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/pihole/index.js b/js/pihole/index.js index dbf3fcbf..f583fbbb 100644 --- a/js/pihole/index.js +++ b/js/pihole/index.js @@ -213,7 +213,7 @@ function updateSummaryData(runOnce) { } });; } -var iff; + function updateQueriesOverTime() { $.getJSON("api.php?overTimeData10mins", function(data) { // Add data for each hour that is available