mirror of
https://github.com/pi-hole/web.git
synced 2025-12-23 20:28:28 +00:00
Modify how we add data to the stacked bar charts on the dashboard.
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
@@ -227,8 +227,26 @@ function updateQueriesOverTime() {
|
|||||||
data.ads_over_time[0].splice(-1, 1);
|
data.ads_over_time[0].splice(-1, 1);
|
||||||
// Remove possibly already existing data
|
// Remove possibly already existing data
|
||||||
timeLineChart.data.labels = [];
|
timeLineChart.data.labels = [];
|
||||||
timeLineChart.data.datasets[0].data = [];
|
timeLineChart.data.datasets = [];
|
||||||
timeLineChart.data.datasets[1].data = [];
|
|
||||||
|
var labels = ["Blocked DNS Queries", "Permitted DNS Queries"];
|
||||||
|
var blockedColor = $(".queries-blocked").css("background-color");
|
||||||
|
var permittedColor = $(".queries-permitted").css("background-color");
|
||||||
|
var colors = [blockedColor, permittedColor];
|
||||||
|
|
||||||
|
// Collect values and colors, and labels
|
||||||
|
for (var i = 0; i < labels.length; i++) {
|
||||||
|
timeLineChart.data.datasets.push({
|
||||||
|
data: [],
|
||||||
|
// If we ran out of colors, make a random one
|
||||||
|
backgroundColor: colors[i],
|
||||||
|
pointRadius: 0,
|
||||||
|
pointHitRadius: 5,
|
||||||
|
pointHoverRadius: 5,
|
||||||
|
label: labels[i],
|
||||||
|
cubicInterpolationMode: "monotone"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Add data for each hour that is available
|
// Add data for each hour that is available
|
||||||
for (var hour in data.ads_over_time[0]) {
|
for (var hour in data.ads_over_time[0]) {
|
||||||
@@ -351,7 +369,7 @@ function updateClientsOverTime() {
|
|||||||
var timestamps = data.over_time[0];
|
var timestamps = data.over_time[0];
|
||||||
var plotdata = data.over_time[1];
|
var plotdata = data.over_time[1];
|
||||||
var labels = [];
|
var labels = [];
|
||||||
var key, i, j;
|
var key;
|
||||||
|
|
||||||
for (key in data.clients) {
|
for (key in data.clients) {
|
||||||
if (Object.prototype.hasOwnProperty.call(data.clients, key)) {
|
if (Object.prototype.hasOwnProperty.call(data.clients, key)) {
|
||||||
@@ -362,19 +380,15 @@ function updateClientsOverTime() {
|
|||||||
|
|
||||||
// Remove possibly already existing data
|
// Remove possibly already existing data
|
||||||
clientsChart.data.labels = [];
|
clientsChart.data.labels = [];
|
||||||
clientsChart.data.datasets[0].data = [];
|
clientsChart.data.datasets = [];
|
||||||
for (i = 1; i < clientsChart.data.datasets.length; i++) {
|
|
||||||
clientsChart.data.datasets[i].data = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect values and colors, and labels
|
// Collect values and colors, and labels
|
||||||
clientsChart.data.datasets[0].backgroundColor = THEME_COLORS[0];
|
var numClients = 0;
|
||||||
clientsChart.data.datasets[0].pointRadius = 0;
|
if (plotdata.length > 0) {
|
||||||
clientsChart.data.datasets[0].pointHitRadius = 5;
|
numClients = plotdata[0].length;
|
||||||
clientsChart.data.datasets[0].pointHoverRadius = 5;
|
}
|
||||||
clientsChart.data.datasets[0].label = labels[0];
|
|
||||||
|
|
||||||
for (i = clientsChart.data.datasets.length; plotdata.length && i < plotdata[0].length; i++) {
|
for (var i = 0; i < numClients; i++) {
|
||||||
clientsChart.data.datasets.push({
|
clientsChart.data.datasets.push({
|
||||||
data: [],
|
data: [],
|
||||||
// If we ran out of colors, make a random one
|
// If we ran out of colors, make a random one
|
||||||
@@ -391,7 +405,7 @@ function updateClientsOverTime() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add data for each dataset that is available
|
// Add data for each dataset that is available
|
||||||
for (j in timestamps) {
|
for (var j in timestamps) {
|
||||||
if (!Object.prototype.hasOwnProperty.call(timestamps, j)) {
|
if (!Object.prototype.hasOwnProperty.call(timestamps, j)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -407,7 +421,6 @@ function updateClientsOverTime() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$("#clients .overlay").hide();
|
$("#clients .overlay").hide();
|
||||||
clientsChart.options.animation = false;
|
|
||||||
clientsChart.update();
|
clientsChart.update();
|
||||||
})
|
})
|
||||||
.done(function () {
|
.done(function () {
|
||||||
@@ -778,8 +791,6 @@ $(function () {
|
|||||||
// Pull in data via AJAX
|
// Pull in data via AJAX
|
||||||
updateSummaryData();
|
updateSummaryData();
|
||||||
|
|
||||||
var blockedColor = $(".queries-blocked").css("background-color");
|
|
||||||
var permittedColor = $(".queries-permitted").css("background-color");
|
|
||||||
var gridColor = $(".graphs-grid").css("background-color");
|
var gridColor = $(".graphs-grid").css("background-color");
|
||||||
var ticksColor = $(".graphs-ticks").css("color");
|
var ticksColor = $(".graphs-ticks").css("color");
|
||||||
var ctx = document.getElementById("queryOverTimeChart").getContext("2d");
|
var ctx = document.getElementById("queryOverTimeChart").getContext("2d");
|
||||||
@@ -787,33 +798,9 @@ $(function () {
|
|||||||
type: utils.getGraphType(),
|
type: utils.getGraphType(),
|
||||||
data: {
|
data: {
|
||||||
labels: [],
|
labels: [],
|
||||||
datasets: [
|
datasets: [{ data: [] }]
|
||||||
{
|
|
||||||
label: "Blocked DNS Queries",
|
|
||||||
fill: true,
|
|
||||||
backgroundColor: blockedColor,
|
|
||||||
borderColor: blockedColor,
|
|
||||||
pointBorderColor: blockedColor,
|
|
||||||
pointRadius: 1,
|
|
||||||
pointHoverRadius: 5,
|
|
||||||
data: [],
|
|
||||||
pointHitRadius: 5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Permitted DNS Queries",
|
|
||||||
fill: true,
|
|
||||||
backgroundColor: permittedColor,
|
|
||||||
borderColor: permittedColor,
|
|
||||||
pointBorderColor: permittedColor,
|
|
||||||
pointRadius: 1,
|
|
||||||
pointHoverRadius: 5,
|
|
||||||
data: [],
|
|
||||||
pointHitRadius: 5
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
animation: false,
|
|
||||||
tooltips: {
|
tooltips: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
mode: "x-axis",
|
mode: "x-axis",
|
||||||
|
|||||||
Reference in New Issue
Block a user