Merge pull request #13 from pljones/feature/covid19-date-limit-on-historygraph

Enhance historygraph to allow size based on date
This commit is contained in:
corrados 2020-03-21 09:34:24 +01:00 committed by GitHub
commit f605c35935
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -135,6 +135,9 @@ void AHistoryGraph::Update ( )
// store current date for reference
curDate = QDate::currentDate();
// set oldest date to draw
QDate minDate = curDate.addDays ( MAX_DAYS_HISTORY * -1 );
// get oldest date in history
QDate oldestDate = curDate.addDays ( 1 ); // one day in the future
const int iNumItemsForHistory = vHistoryDataFifo.Size();
@ -150,6 +153,10 @@ void AHistoryGraph::Update ( )
}
}
}
if (oldestDate < minDate)
{
oldestDate = minDate;
}
const int iNumDaysInHistory = -curDate.daysTo ( oldestDate ) + 1;
// draw frame of the graph
@ -159,7 +166,7 @@ void AHistoryGraph::Update ( )
for ( i = 0; i < iNumItemsForHistory; i++ )
{
// only use valid dates
if ( vHistoryDataFifo[i].DateTime.date().isValid() )
if ( vHistoryDataFifo[i].DateTime.date().isValid() && oldestDate <= vHistoryDataFifo[i].DateTime.date() )
{
AddMarker ( vHistoryDataFifo[i] );
}

View File

@ -44,7 +44,9 @@
/* Definitions ****************************************************************/
// number of history items to store
#define NUM_ITEMS_HISTORY 600
#define NUM_ITEMS_HISTORY 4800
// oldest item to draw
#define MAX_DAYS_HISTORY 60
/* Interface ******************************************************************/