Skip to content

Commit

Permalink
Trends view perspective filter
Browse files Browse the repository at this point in the history
.. applies to all charts in the perspective, so you can create
   a perspective called "Running" and set the filter to "isRun"
   and all charts in the perspective will only show data from
   runs.

.. updated charts on Trends view to honor the perspective
   filter, as below:

   * Overview
   * Trends
   * User Chart
   * Treemap
   * Critical Power
   * R Chart
   * Python Chart
   * Histogram - for metrics
   * Summary - no change as deprecating shortly

.. renamed the HomeView to TrendsView in line with some of the
   other recent name changes. The class names were set over 10
   years ago and no longer reflect the UI concepts.

.. New signal: GcWindow::perspectiveChanged(Perspective *)

   When the chart is moved from one perspective to another, likely does
   not need to do anything on Analysis view, but on Trends view its
   quite likely the filter has changed, so refresh is needed.

.. New signal: GcWindow::perspectiveFilterChanged(QString)

   When the perspective filter is updated this signal is called but
   only on trends view since it doesn't really matter on Analysis
   from the charts point of view.
  • Loading branch information
liversedge committed Jul 8, 2021
1 parent 3bc1391 commit b738038
Show file tree
Hide file tree
Showing 41 changed files with 315 additions and 100 deletions.
27 changes: 26 additions & 1 deletion src/Charts/CPPlot.cpp
Expand Up @@ -53,6 +53,7 @@
#include "LTMCanvasPicker.h"
#include "TimeUtils.h"
#include "Units.h"
#include "Perspective.h"

#include "LTMTrend.h"

Expand Down Expand Up @@ -1074,6 +1075,7 @@ CPPlot::plotTests(RideItem *rideitem)
fs.addFilter(parent->searchBox->isFiltered(), SearchFilterBox::matches(context, parent->searchBox->filter())); // chart settings
fs.addFilter(context->isfiltered, context->filters);
fs.addFilter(context->ishomefiltered, context->homeFilters);
fs.addFilter(parent->myPerspective->isFiltered(), parent->myPerspective->filterlist(DateRange(startDate,endDate)));
Specification spec;
spec.setFilterSet(fs);
spec.setDateRange(DateRange(startDate, endDate));
Expand Down Expand Up @@ -1198,7 +1200,18 @@ CPPlot::plotBests(RideItem *rideItem)

// do we need to get the cache ?
if (bestsCache == NULL) {
bestsCache = new RideFileCache(context, startDate, endDate, isFiltered, files, rangemode, rideItem);
// isFiltered and files are filters from CriticalPowerWindow's filter setting
// we also need to take into account the perspective filter if on trends so
// its easier to just aggregate the filter list here (bit hacky but works ok)
// but only if rangemode (aka on trends)
if (rangemode) {
bestsCache = new RideFileCache(context, startDate, endDate,
isFiltered||parent->myPerspective->isFiltered(),
files + (parent->myPerspective->isFiltered() ? parent->myPerspective->filterlist(DateRange(startDate,endDate)) : QStringList()),
rangemode, rideItem);
} else {
bestsCache = new RideFileCache(context, startDate, endDate, isFiltered, files, rangemode, rideItem);
}
}

// how much we got ?
Expand Down Expand Up @@ -1758,6 +1771,7 @@ CPPlot::plotEfforts()
FilterSet fs; // apply filters when selecting intervals
fs.addFilter(context->isfiltered, context->filters);
fs.addFilter(context->ishomefiltered, context->homeFilters);
fs.addFilter(parent->myPerspective->isFiltered(), parent->myPerspective->filterlist(DateRange(startDate,endDate)));
Specification spec;
spec.setFilterSet(fs);
spec.setDateRange(DateRange(startDate, endDate));
Expand Down Expand Up @@ -2265,6 +2279,17 @@ CPPlot::exportBests(QString filename)
f.close();
}

// perspective filter changed, we need to replot with new bests
void
CPPlot::perspectiveFilterChanged()
{
if (bestsCache) {
delete bestsCache;
bestsCache = NULL;
}
clearCurves();
}

// no filter
void
CPPlot::clearFilter()
Expand Down
1 change: 1 addition & 0 deletions src/Charts/CPPlot.h
Expand Up @@ -112,6 +112,7 @@ class CPPlot : public QwtPlot
void pointHover(QwtPlotCurve *curve, int index);

// filter being applied
void perspectiveFilterChanged();
void clearFilter();
void setFilter(QStringList);

Expand Down
14 changes: 14 additions & 0 deletions src/Charts/CriticalPowerWindow.cpp
Expand Up @@ -518,6 +518,10 @@ CriticalPowerWindow::CriticalPowerWindow(Context *context, bool rangemode) :
// Compare
connect(context, SIGNAL(compareDateRangesStateChanged(bool)), SLOT(forceReplot()));
connect(context, SIGNAL(compareDateRangesChanged()), SLOT(forceReplot()));

connect(this, SIGNAL(perspectiveFilterChanged(QString)), this, SLOT(perspectiveFilterChanged()));
connect(this, SIGNAL(perspectiveChanged(Perspective*)), this, SLOT(perspectiveFilterChanged()));

} else {
// when working on a ride we can select intervals!
connect(cComboSeason, SIGNAL(currentIndexChanged(int)), this, SLOT(seasonSelected(int)));
Expand All @@ -528,6 +532,7 @@ CriticalPowerWindow::CriticalPowerWindow(Context *context, bool rangemode) :
// Compare
connect(context, SIGNAL(compareIntervalsStateChanged(bool)), SLOT(forceReplot()));
connect(context, SIGNAL(compareIntervalsChanged()), SLOT(forceReplot()));

}

connect(seriesCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setSeries(int)));
Expand Down Expand Up @@ -1752,6 +1757,7 @@ CriticalPowerWindow::dateRangeChanged(DateRange dateRange)
fs.addFilter(searchBox->isFiltered(), SearchFilterBox::matches(context, filter()));
fs.addFilter(context->isfiltered, context->filters);
fs.addFilter(context->ishomefiltered, context->homeFilters);
fs.addFilter(myPerspective->isFiltered(), myPerspective->filterlist(dateRange));
int nActivities, nRides, nRuns, nSwims;
QString sport;
context->athlete->rideCache->getRideTypeCounts(
Expand Down Expand Up @@ -1809,6 +1815,14 @@ void CriticalPowerWindow::seasonSelected(int iSeason)
cpPlot->setRide(currentRide);
}

void CriticalPowerWindow::perspectiveFilterChanged()
{
if (rangemode) {
cpPlot->perspectiveFilterChanged();
forceReplot();
}
}

void CriticalPowerWindow::filterChanged()
{
cpPlot->setRide(currentRide);
Expand Down
4 changes: 3 additions & 1 deletion src/Charts/CriticalPowerWindow.h
Expand Up @@ -26,6 +26,7 @@
#include "Season.h"
#include "RideFile.h"
#include "SearchFilterBox.h"
#include "Perspective.h"

#include "qxtstringspinbox.h"
#include <QtGui>
Expand Down Expand Up @@ -124,7 +125,7 @@ class CriticalPowerWindow : public GcChartWindow
void setVariant(int x);

// filter
bool isFiltered() const { return (searchBox->isFiltered() || context->ishomefiltered || context->isfiltered); }
bool isFiltered() const { return (searchBox->isFiltered() || myPerspective->isFiltered() || context->ishomefiltered || context->isfiltered); }
QString filter() const { return searchBox->filter(); }
void setFilter(QString x) { searchBox->setFilter(x); }

Expand Down Expand Up @@ -262,6 +263,7 @@ class CriticalPowerWindow : public GcChartWindow
void resetSeasons();
void filterChanged();
void dateRangeChanged(DateRange);
void perspectiveFilterChanged();

void useCustomRange(DateRange);
void useStandardRange();
Expand Down
8 changes: 8 additions & 0 deletions src/Charts/GoldenCheetah.h
Expand Up @@ -20,12 +20,14 @@
#define _GC_GoldenCheetah_h
class GcWindow;
class Context;
class Perspective;

#define G_OBJECT
//#define G_OBJECT Q_PROPERTY(QString instanceName READ instanceName WRITE setInstanceName)
//#define setInstanceName(x) setProperty("instanceName", x)
#define myRideItem property("ride").value<RideItem*>()
#define myDateRange property("dateRange").value<DateRange>()
#define myPerspective property("perspective").value<Perspective*>()

#include <QString>
#include <QMenu>
Expand All @@ -45,6 +47,7 @@ class Context;

class RideItem;
class GcOverlayWidget;
class Perspective;


class GcWindow : public QFrame
Expand Down Expand Up @@ -122,6 +125,8 @@ public slots:
void widthFactorChanged(double);
void colorChanged(QColor);
void dateRangeChanged(DateRange);
void perspectiveFilterChanged(QString);
void perspectiveChanged(Perspective*);
void resizing(GcWindow*);
void moving(GcWindow*);
void resized(GcWindow*); // finished resizing
Expand Down Expand Up @@ -159,6 +164,9 @@ public slots:
void setDateRange(DateRange);
DateRange dateRange() const;

void notifyPerspectiveFilterChanged(QString x) { emit perspectiveFilterChanged(x); }
void notifyPerspectiveChanged(Perspective *x) { emit perspectiveChanged(x); }

void setWidthFactor(double);
double widthFactor() const;

Expand Down
20 changes: 19 additions & 1 deletion src/Charts/HistogramWindow.cpp
Expand Up @@ -21,6 +21,7 @@
#include "Specification.h"
#include "HelpWhatsThis.h"
#include "Utils.h"
#include "Perspective.h"

// predefined deltas for each series
static const double wattsDelta = 1.0;
Expand Down Expand Up @@ -314,6 +315,10 @@ HistogramWindow::HistogramWindow(Context *context, bool rangemode) : GcChartWind
connect(distMetricTree, SIGNAL(itemSelectionChanged()), this, SLOT(treeSelectionChanged()));
connect(totalMetricTree, SIGNAL(itemSelectionChanged()), this, SLOT(treeSelectionChanged()));

// perspective filter changed
connect(this, SIGNAL(perspectiveFilterChanged(QString)), this, SLOT(perspectiveFilterChanged()));
connect(this, SIGNAL(perspectiveChanged(Perspective*)), this, SLOT(perspectiveFilterChanged()));

// replot when background refresh is progressing
connect(context, SIGNAL(refreshUpdate(QDate)), this, SLOT(refreshUpdate(QDate)));

Expand Down Expand Up @@ -1008,7 +1013,11 @@ HistogramWindow::updateChart()

// plotting a data series, so refresh the ridefilecache

source = new RideFileCache(context, use.from, use.to, isfiltered, files, rangemode);
if (rangemode) {
source = new RideFileCache(context, use.from, use.to, isfiltered||myPerspective->isFiltered(),
files + myPerspective->filterlist(use), rangemode);
} else source = new RideFileCache(context, use.from, use.to, isfiltered, files, rangemode);

cfrom = use.from;
cto = use.to;
stale = false;
Expand Down Expand Up @@ -1043,6 +1052,7 @@ HistogramWindow::updateChart()
fs.addFilter(isfiltered, files);
fs.addFilter(context->isfiltered, context->filters);
fs.addFilter(context->ishomefiltered, context->homeFilters);
fs.addFilter(myPerspective->isFiltered(), myPerspective->filterlist(use));

// setData using the summary metrics -- always reset since filters may
// have changed, or perhaps the bin width...
Expand Down Expand Up @@ -1085,6 +1095,14 @@ HistogramWindow::updateChart()
} // if stale
}

void
HistogramWindow::perspectiveFilterChanged()
{
stale = true;
updateChart();
repaint();
}

void
HistogramWindow::clearFilter()
{
Expand Down
1 change: 1 addition & 0 deletions src/Charts/HistogramWindow.h
Expand Up @@ -153,6 +153,7 @@ class HistogramWindow : public GcChartWindow
void zonesChanged();
void clearFilter();
void setFilter(QStringList files);
void perspectiveFilterChanged();

// date settings
void useCustomRange(DateRange);
Expand Down
5 changes: 5 additions & 0 deletions src/Charts/LTMWindow.cpp
Expand Up @@ -302,6 +302,8 @@ LTMWindow::LTMWindow(Context *context) :
connect(this, SIGNAL(dateRangeChanged(DateRange)), this, SLOT(dateRangeChanged(DateRange)));
connect(this, SIGNAL(styleChanged(int)), this, SLOT(styleChanged(int)));
connect(ltmTool, SIGNAL(filterChanged()), this, SLOT(filterChanged()));
connect(this, SIGNAL(perspectiveFilterChanged(QString)), this, SLOT(filterChanged()));
connect(this, SIGNAL(perspectiveChanged(Perspective*)), this, SLOT(filterChanged()));
connect(context, SIGNAL(homeFilterChanged()), this, SLOT(filterChanged()));
connect(ltmTool->groupBy, SIGNAL(currentIndexChanged(int)), this, SLOT(groupBySelected(int)));
connect(rGroupBy, SIGNAL(valueChanged(int)), this, SLOT(rGroupBySelected(int)));
Expand Down Expand Up @@ -635,6 +637,7 @@ LTMWindow::presetSelected(int index)
fs.addFilter(context->isfiltered, context->filters);
fs.addFilter(context->ishomefiltered, context->homeFilters);
fs.addFilter(ltmTool->isFiltered(), ltmTool->filters());
fs.addFilter(myPerspective->isFiltered(), myPerspective->filterlist(myDateRange));
settings.specification.setFilterSet(fs);
settings.specification.setDateRange(DateRange(settings.start.date(), settings.end.date()));

Expand Down Expand Up @@ -1072,6 +1075,7 @@ LTMWindow::filterChanged()
fs.addFilter(context->isfiltered, context->filters);
fs.addFilter(context->ishomefiltered, context->homeFilters);
fs.addFilter(ltmTool->isFiltered(), ltmTool->filters());
fs.addFilter(myPerspective->isFiltered(), myPerspective->filterlist(myDateRange));
settings.specification.setFilterSet(fs);
settings.specification.setDateRange(DateRange(settings.start.date(), settings.end.date()));

Expand Down Expand Up @@ -1198,6 +1202,7 @@ LTMWindow::applyClicked()
fs.addFilter(context->isfiltered, context->filters);
fs.addFilter(context->ishomefiltered, context->homeFilters);
fs.addFilter(ltmTool->isFiltered(), ltmTool->filters());
fs.addFilter(myPerspective->isFiltered(), myPerspective->filterlist(myDateRange));
settings.specification.setFilterSet(fs);
settings.specification.setDateRange(DateRange(settings.start.date(), settings.end.date()));

Expand Down
4 changes: 3 additions & 1 deletion src/Charts/Overview.cpp
Expand Up @@ -40,7 +40,7 @@ OverviewWindow::OverviewWindow(Context *context, int scope) : GcChartWindow(cont
main->setSpacing(0);
main->setContentsMargins(0,0,0,0);

space = new ChartSpace(context, scope);
space = new ChartSpace(context, scope, this);
main->addWidget(space);

HelpWhatsThis *help = new HelpWhatsThis(space);
Expand All @@ -59,7 +59,9 @@ OverviewWindow::OverviewWindow(Context *context, int scope) : GcChartWindow(cont
connect(this, SIGNAL(dateRangeChanged(DateRange)), space, SLOT(dateRangeChanged(DateRange)));
connect(context, SIGNAL(filterChanged()), space, SLOT(filterChanged()));
connect(context, SIGNAL(homeFilterChanged()), space, SLOT(filterChanged()));
connect(this, SIGNAL(perspectiveFilterChanged(QString)), space, SLOT(filterChanged()));
}
connect(this, SIGNAL(perspectiveChanged(Perspective*)), space, SLOT(refresh()));
connect(context, SIGNAL(refreshEnd()), space, SLOT(refresh()));
connect(context, SIGNAL(estimatesRefreshed()), space, SLOT(refresh()));

Expand Down
11 changes: 10 additions & 1 deletion src/Charts/OverviewItems.cpp
Expand Up @@ -78,6 +78,11 @@ static void setFilter(ChartSpaceItem *item, Specification &spec)
fs.addFilter(item->parent->context->isfiltered, item->parent->context->filters);
fs.addFilter(item->parent->context->ishomefiltered, item->parent->context->homeFilters);

// property gets set after chartspace is initialised, so when we start up its not
// available, but comes later...
if (item->parent->window->property("perspective").isValid())
fs.addFilter(item->parent->window->myPerspective->isFiltered(), item->parent->window->myPerspective->filterlist(item->parent->myDateRange));

// local filter
fs.addFilter(item->datafilter != "", SearchFilterBox::matches(item->parent->context, item->datafilter));
spec.setFilterSet(fs);
Expand Down Expand Up @@ -466,9 +471,13 @@ KPIOverviewItem::setData(RideItem *item)
void
KPIOverviewItem::setDateRange(DateRange dr)
{
Specification spec;
spec.setDateRange(dr);
setFilter(this, spec);

// calculate the value...
DataFilter parser(this, parent->context, program);
Result res = parser.evaluate(dr, datafilter);
Result res = parser.evaluate(spec, dr);

// set to zero for daft values
value = res.string();
Expand Down
2 changes: 2 additions & 0 deletions src/Charts/PythonChart.cpp
Expand Up @@ -191,6 +191,7 @@ void PythonConsole::keyPressEvent(QKeyEvent *e)
if (pythonHost->chart()) {
python->canvas = pythonHost->chart()->canvas;
python->chart = pythonHost->chart();
python->perspective = myPerspective;
}

try {
Expand Down Expand Up @@ -228,6 +229,7 @@ void PythonConsole::keyPressEvent(QKeyEvent *e)

// clear context
python->canvas = NULL;
python->perspective = NULL;
python->chart = NULL;
}

Expand Down
6 changes: 6 additions & 0 deletions src/Charts/RChart.cpp
Expand Up @@ -384,6 +384,10 @@ RChart::RChart(Context *context, bool ridesummary) : GcChartWindow(context), con
// refresh when comparing
connect(context, SIGNAL(compareDateRangesStateChanged(bool)), this, SLOT(runScript()));
connect(context, SIGNAL(compareDateRangesChanged()), this, SLOT(runScript()));

// perspective or perspective filter changed
connect(this, SIGNAL(perspectiveFilterChanged(QString)), this, SLOT(runScript()));
connect(this, SIGNAL(perspectiveChanged(Perspective *)), this, SLOT(runScript()));
}

// we apply BOTH filters, so update when either change
Expand Down Expand Up @@ -537,6 +541,7 @@ RChart::runScript()
// run it !!
rtool->context = context;
rtool->canvas = canvas;
rtool->perspective = myPerspective;
rtool->chart = this;

// set default page size
Expand Down Expand Up @@ -601,6 +606,7 @@ RChart::runScript()
// clear context
rtool->context = NULL;
rtool->canvas = NULL;
rtool->perspective = NULL;
rtool->chart = NULL;
}
}

0 comments on commit b738038

Please sign in to comment.