diff --git a/scripts/pi-hole/js/db_graph.js b/scripts/pi-hole/js/db_graph.js index 112440ca0..031283741 100644 --- a/scripts/pi-hole/js/db_graph.js +++ b/scripts/pi-hole/js/db_graph.js @@ -15,6 +15,12 @@ var interval = 0; var dateformat = "MMMM Do YYYY, HH:mm"; +// get the database min timestamp +var mintimestamp; +$.getJSON("api_db.php?getMinTimestamp", function (ts) { + mintimestamp = ts.mintimestamp * 1000 || 0; // return the timestamp in milliseconds or zero (in case of NaN) +}); + $(function () { $("#querytime").daterangepicker( { @@ -24,6 +30,8 @@ $(function () { locale: { format: dateformat }, startDate: start__, endDate: end__, + minDate: moment(mintimestamp), // Use the oldest timestamp found in database as initial date + maxDate: moment(), // Use now as maximum date ranges: { Today: [moment().startOf("day"), moment()], Yesterday: [ @@ -69,19 +77,21 @@ function updateQueriesOverTime() { // Default displaying axis scaling timeLineChart.options.scales.xAxes[0].time.unit = "hour"; - if (num * interval >= 6 * 29 * 24 * 60 * 60) { - // If the requested data is more than 3 months, set ticks interval to quarterly + // Xaxis scaling based on selected daterange + if (num * interval >= 5 * 365 * 24 * 60 * 60) { + // If the requested data is more than 5 years, set ticks interval to year + timeLineChart.options.scales.xAxes[0].time.unit = "year"; + } else if (num * interval >= 366 * 24 * 60 * 60) { + // If the requested data is more than 1 year, set ticks interval to quarter timeLineChart.options.scales.xAxes[0].time.unit = "quarter"; - } else if (num * interval >= 3 * 29 * 24 * 60 * 60) { + } else if (num * interval >= 92 * 24 * 60 * 60) { // If the requested data is more than 3 months, set ticks interval to months timeLineChart.options.scales.xAxes[0].time.unit = "month"; - } - - if (num * interval >= 29 * 24 * 60 * 60) { - // If the requested data is more than 1 month, set ticks interval to weeks + } else if (num * interval >= 31 * 24 * 60 * 60) { + // If the requested data is 1 month or more, set ticks interval to weeks timeLineChart.options.scales.xAxes[0].time.unit = "week"; - } else if (num * interval >= 6 * 24 * 60 * 60) { - // If the requested data is more than 1 week, set ticks interval to days + } else if (num * interval > 3 * 24 * 60 * 60) { + // If the requested data is more than 3 days (72 hours), set ticks interval to days timeLineChart.options.scales.xAxes[0].time.unit = "day"; }