Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long-term graph changes #1969

Merged
merged 5 commits into from
Nov 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions scripts/pi-hole/js/db_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand All @@ -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: [
Expand Down Expand Up @@ -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";
}

Expand Down