Merge pull request #30 from pi-hole/fix/remove-forward-over-time

Remove forwarded over time and hide query types over time graphs
This commit is contained in:
Mark Drobnak
2018-06-04 20:36:03 -04:00
committed by GitHub
3 changed files with 0 additions and 175 deletions
-168
View File
@@ -1,168 +0,0 @@
/* Pi-hole: A black hole for Internet advertisements
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* Web Interface
* Forward Destinations Over Time component
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
import React, { Component } from 'react';
import { Line } from 'react-chartjs-2';
import { padNumber, api, makeCancelable, ignoreCancel } from '../utils';
export default class ForwardDestOverTime extends Component {
state = {
loading: true,
data: {
labels: [],
datasets: []
},
options: {
tooltips: {
enabled: true,
mode: "x-axis",
callbacks: {
title: tooltipItem => {
const label = tooltipItem[0].xLabel;
const time = label.match(/(\d?\d):?(\d?\d?)/);
const h = parseInt(time[1], 10);
const m = parseInt(time[2], 10) || 0;
const from = padNumber(h)+":"+padNumber(m-5)+":00";
const to = padNumber(h)+":"+padNumber(m+4)+":59";
return "Forward destinations from "+from+" to "+to;
},
label: (tooltipItems, data) => {
return data.datasets[tooltipItems.datasetIndex].label + ": " + (100.0*tooltipItems.yLabel).toFixed(1) + "%";
}
}
},
legend: {
display: false
},
scales: {
xAxes: [{
type: "time",
time: {
unit: "hour",
displayFormats: {
hour: "HH:mm"
},
tooltipFormat: "HH:mm"
}
}],
yAxes: [{
ticks: {
mix: 0.0,
max: 1.0,
beginAtZero: true,
callback: (value, index, values) => Math.round(value*100) + "%"
},
stacked: true
}]
},
maintainAspectRatio: true
}
};
constructor(props) {
super(props);
this.updateGraph = this.updateGraph.bind(this);
}
updateGraph() {
this.updateHandler = makeCancelable(
api.getForwardDestOverTime(),
{ repeat: this.updateGraph, interval: 10 * 60 * 1000 }
);
this.updateHandler.promise.then(res => {
// Remove last data point as it's not yet finished
res.over_time.splice(-1, 1);
const labels = [];
const destinations = res.forward_destinations;
const datasets = [];
const colors = [
"#20a8d8",
"#f86c6b",
"#4dbd74",
"#f8cb00",
"#263238",
"#63c2de",
"#b0bec5"
];
// Fill in destination information
let i = 0;
for(let destination of destinations) {
datasets.push({
label: destination.split("|")[0],
// If we ran out of colors, make a random one
backgroundColor: i < colors.length
? colors[i]
: '#' + parseInt("" + Math.random() * 0xffffff, 10).toString(16),
pointRadius: 0,
pointHitRadius: 5,
pointHoverRadius: 5,
data: []
});
i++;
}
// Fill in data & labels
for(let step of res.over_time) {
const date = new Date(1000 * step.timestamp);
const sum = step.data.reduce((a, b) => a + b);
if (sum > 0) {
for(let destination in datasets) {
if(datasets.hasOwnProperty(destination))
datasets[destination].data.push(step.data[destination] / sum);
}
}
labels.push(date);
}
const data = this.state.data;
data.labels = labels;
data.datasets = datasets;
this.setState({ data, loading: false });
}).catch(ignoreCancel);
}
componentDidMount() {
this.updateGraph();
}
componentWillUnmount() {
this.updateHandler.cancel();
}
render() {
return (
<div className="col-md-12 col-lg-6">
<div className="card">
<div className="card-header">
Forward Destinations Over Time
</div>
<div className="card-block">
<Line width={400} height={150} data={this.state.data} options={this.state.options}/>
</div>
{
this.state.loading
?
<div className="card-img-overlay" style={{background: "rgba(255,255,255,0.7)"}}>
<i className="fa fa-refresh fa-spin" style={{position: "absolute", top: "50%", left: "50%", fontSize: "30px"}}/>
</div>
:
null
}
</div>
</div>
);
}
}
-3
View File
@@ -75,9 +75,6 @@ export const api = {
getQueryTypesOverTime() {
return api.get("stats/overTime/query_types");
},
getForwardDestOverTime() {
return api.get("stats/overTime/forward_destinations");
},
getTopDomains() {
return api.get("stats/top_domains");
},
-4
View File
@@ -11,8 +11,6 @@
import React, { Fragment } from 'react';
import SummaryStats from '../components/SummaryStats';
import QueriesGraph from '../components/QueriesGraph';
import QueryTypesOverTime from '../components/QueryTypesOverTime';
import ForwardDestOverTime from '../components/ForwardDestOverTime';
import TopDomains from '../components/TopDomains';
import TopBlocked from '../components/TopBlocked';
import TopClients from '../components/TopClients';
@@ -26,8 +24,6 @@ export default () => (
api.loggedIn ?
<Fragment>
<div className="row">
<QueryTypesOverTime/>
<ForwardDestOverTime/>
</div>
<div className="row">
<TopDomains/>