From b55aa67496bd31c323927f45ef14e52d31747c9f Mon Sep 17 00:00:00 2001 From: Peter L Jones Date: Fri, 20 Mar 2020 23:03:56 +0000 Subject: [PATCH] Enhance historygraph to allow size based on date Due to the increasing number of connections, the *number* of history entries is no longer a good way to size the width of the graph. In addition to adding a much larger FIFO, I have chosen to add a date constraint. This means I do not have to keep making the FIFO bigger daily and, when numbers fall, the graph will not change shape. --- src/historygraph.cpp | 9 ++++++++- src/historygraph.h | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/historygraph.cpp b/src/historygraph.cpp index 9c3522f3..5b958e0c 100644 --- a/src/historygraph.cpp +++ b/src/historygraph.cpp @@ -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] ); } diff --git a/src/historygraph.h b/src/historygraph.h index 47038599..86c42221 100644 --- a/src/historygraph.h +++ b/src/historygraph.h @@ -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 ******************************************************************/