Skip to content

Commit

Permalink
Plot Formula in AllPlot - Part 4 of 4
Browse files Browse the repository at this point in the history
.. compare mode now works with user data
   series on AllPlot.

.. probably a few minor nits to clean up
   and maybe some refinements will come.

One thing is for sure, AllPlot and AllPlotWindow
have reached the limit of maintainability and we
should think carefully about how they move forward.
  • Loading branch information
liversedge committed Aug 31, 2015
1 parent 601b720 commit 84c4d52
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 14 deletions.
35 changes: 31 additions & 4 deletions src/AllPlot.cpp
Expand Up @@ -4177,6 +4177,7 @@ AllPlot::setDataFromPlots(QList<AllPlot *> plots)
curveColors->saveState();

// remove all curves from the plot
for(int k=0; k<standard->U.count(); k++) standard->U[k].curve->detach();
standard->wCurve->detach();
standard->mCurve->detach();
standard->wattsCurve->detach();
Expand Down Expand Up @@ -4221,6 +4222,7 @@ AllPlot::setDataFromPlots(QList<AllPlot *> plots)
standard->lpppCurve->detach();
standard->rpppCurve->detach();

for(int k=0; k<standard->U.count(); k++) standard->U[k].curve->setVisible(false);
standard->wCurve->setVisible(false);
standard->mCurve->setVisible(false);
standard->wattsCurve->setVisible(false);
Expand Down Expand Up @@ -4672,6 +4674,14 @@ AllPlot::setDataFromPlots(QList<AllPlot *> plots)
break;

default:
if (scope > RideFile::none) {

// user defined series
int index = scope - (RideFile::none+1);
ourCurve = static_cast<QwtPlotCurve*>(new QwtPlotGappedCurve(referencePlot->standard->U[index].name, 3));
thereCurve = referencePlot->standard->U[index].curve;
title = referencePlot->standard->U[index].name;
}
case RideFile::interval:
case RideFile::vam:
case RideFile::wattsKg:
Expand Down Expand Up @@ -4701,18 +4711,21 @@ AllPlot::setDataFromPlots(QList<AllPlot *> plots)
ourCurve->attach(this);

// lets clone the data
QVector<QPointF> array;
for (size_t i=0; i<thereCurve->data()->size(); i++) array << thereCurve->data()->sample(i);
QVector<double> x,y;
for (size_t i=0; i<thereCurve->data()->size(); i++) {
x << thereCurve->data()->sample(i).x();
y << thereCurve->data()->sample(i).y();
}

ourCurve->setSamples(array);
ourCurve->setSamples(x,y);
ourCurve->setYAxis(yLeft);
ourCurve->setBaseline(thereCurve->baseline());

if (ourCurve->maxYValue() > MAXY) MAXY = ourCurve->maxYValue();
if (ourCurve->minYValue() < MINY) MINY = ourCurve->minYValue();

// symbol when zoomed in super close
if (array.size() < 150) {
if (x.size() < 150) {
QwtSymbol *sym = new QwtSymbol;
sym->setPen(QPen(GColor(CPLOTMARKER)));
sym->setStyle(QwtSymbol::Ellipse);
Expand Down Expand Up @@ -4886,6 +4899,7 @@ AllPlot::setDataFromObject(AllPlotObject *object, AllPlot *reference)
bydist = reference->bydist;

// remove all curves from the plot
for(int k=0; k<standard->U.count(); k++) standard->U[k].curve->detach();
standard->wCurve->detach();
standard->mCurve->detach();
standard->wattsCurve->detach();
Expand Down Expand Up @@ -4926,6 +4940,7 @@ AllPlot::setDataFromObject(AllPlotObject *object, AllPlot *reference)
standard->intervalHighlighterCurve->detach();
standard->intervalHoverCurve->detach();

for(int k=0; k<standard->U.count(); k++) standard->U[k].curve->setVisible(false);
standard->wCurve->setVisible(false);
standard->mCurve->setVisible(false);
standard->wattsCurve->setVisible(false);
Expand Down Expand Up @@ -4979,6 +4994,17 @@ AllPlot::setDataFromObject(AllPlotObject *object, AllPlot *reference)
setMatchLabels(standard);
}

// show user data curves
for(int k=0; k< standard->U.count() && k<object->U.count(); k++) {

if (!object->U[k].smooth.empty()) {

standard->U[k].curve->setSamples(xaxis.data(), object->U[k].smooth.data(), totalPoints);
standard->U[k].curve->attach(this);
standard->U[k].curve->setVisible(true);
}
}

if (!object->wattsArray.empty()) {
standard->wattsCurve->setSamples(xaxis.data(), object->smoothWatts.data(), totalPoints);
standard->wattsCurve->attach(this);
Expand Down Expand Up @@ -5616,6 +5642,7 @@ AllPlot::setDataFromRideFile(RideFile *ride, AllPlotObject *here, QList<UserData
++arrayLength;
}
recalc(here);

}
else {
//setTitle("no data");
Expand Down
69 changes: 59 additions & 10 deletions src/AllPlotWindow.cpp
Expand Up @@ -1238,12 +1238,30 @@ AllPlotWindow::compareChanged()
foreach(AllPlotObject *p, compareIntervalCurves) delete p;
compareIntervalCurves.clear();

// clean away old compare user data
foreach(QList<UserData*>user, compareUserDataSeries) {
foreach(UserData *p, user)
delete p;
}
compareUserDataSeries.clear();

// new ones ..
if (context->isCompareIntervals) {

// generate the user data series for each interval
foreach(CompareInterval ci, context->compareIntervals) {
QList<UserData*> list;
foreach(UserData *u, userDataSeries) {
UserData *p = new UserData(u->name, u->units, u->formula, ci.color); // use context for interval
p->setRideItem(ci.rideItem);
list << p;
}
compareUserDataSeries << list;
}

// first, lets init fullPlot, just in case its never
// been set (ie, switched to us before ever plotting a ride
if (myRideItem) fullPlot->setDataFromRide(myRideItem, QList<UserData*>()); //XXX
if (myRideItem) fullPlot->setDataFromRide(myRideItem, QList<UserData*>());

// and even if the current ride is blank, we're not
// going to be blank !!
Expand All @@ -1262,10 +1280,11 @@ AllPlotWindow::compareChanged()

fullPlot->standard->setVisible(false);
if (fullPlot->smooth < 1) fullPlot->smooth = 1;
int k=0;
foreach(CompareInterval ci, context->compareIntervals) {

AllPlotObject *po = new AllPlotObject(fullPlot, QList<UserData*>()); //XXX
if (ci.isChecked()) fullPlot->setDataFromRideFile(ci.data, po, QList<UserData*>()); //XXX
AllPlotObject *po = new AllPlotObject(fullPlot, compareUserDataSeries[k]);
if (ci.isChecked()) fullPlot->setDataFromRideFile(ci.data, po, compareUserDataSeries[k]);

// what was the maximum x value?
if (po->maxKM > maxKM) maxKM = po->maxKM;
Expand All @@ -1277,17 +1296,22 @@ AllPlotWindow::compareChanged()

// remember
compareIntervalCurves << po;

// next
k++;
}

// what is the longest compareInterval?
if (fullPlot->bydist) fullPlot->setAxisScale(QwtPlot::xBottom, 0, maxKM);
else fullPlot->setAxisScale(QwtPlot::xBottom, 0, maxSECS/60);

// now set it it in all the compare objects so they all get set
// to the same time / duration
// to the same time / duration and all the data is set too
k=0;
foreach (AllPlotObject *po, compareIntervalCurves) {
po->maxKM = maxKM;
po->maxSECS = maxSECS;
k++;
}

if (fullPlot->bydist == false) {
Expand Down Expand Up @@ -1325,6 +1349,8 @@ AllPlotWindow::compareChanged()
AllPlot *ap = new AllPlot(this, this, context);
ap->bydist = fullPlot->bydist;
ap->setShadeZones(showPower->currentIndex() == 0);

// user data series needs setting up
ap->setDataFromObject(compareIntervalCurves[i], fullPlot);

// simpler to keep the indexes aligned
Expand Down Expand Up @@ -1407,6 +1433,13 @@ AllPlotWindow::compareChanged()
if (showAP->isChecked()) { s.one = RideFile::aPower; s.two = RideFile::none; wanted << s;};
if (showBalance->isChecked()) { s.one = RideFile::lrbalance; s.two = RideFile::none; wanted << s;};

// and the user series
for(int k=0; k<userDataSeries.count(); k++) {
s.one = static_cast<RideFile::SeriesType>(RideFile::none + 1 + k);
s.two = RideFile::none;
wanted << s;
}

/*
if (showTE->isChecked()) {
s.one = RideFile::lte; s.two = RideFile::none; wanted << s;
Expand Down Expand Up @@ -1474,18 +1507,34 @@ AllPlotWindow::compareChanged()
sd->enableComponent(QwtScaleDraw::Ticks, false);
sd->enableComponent(QwtScaleDraw::Backbone, false);
plot->setAxisScaleDraw(QwtPlot::yLeft, sd);


// default paletter override below if needed
QPalette pal;
pal.setColor(QPalette::WindowText, RideFile::colorFor(x.one));
pal.setColor(QPalette::Text, RideFile::colorFor(x.one));

// y-axis title and colour
if (x.one == RideFile::alt && x.two == RideFile::slope) {

// alt/slope special case
plot->setAxisTitle(QwtPlot::yLeft, tr("Alt/Slope"));
plot->showAltSlopeState = allPlot->showAltSlopeState;
plot->setAltSlopePlotStyle(allPlot->standard->altSlopeCurve);
} else {
plot->setAxisTitle(QwtPlot::yLeft, RideFile::seriesName(x.one));

} else {

// user defined series
if (x.one > RideFile::none) {
int index = (int)(x.one) - (RideFile::none + 1);
plot->setAxisTitle(QwtPlot::yLeft, userDataSeries[index]->name);
pal.setColor(QPalette::WindowText, userDataSeries[index]->color);
pal.setColor(QPalette::Text, userDataSeries[index]->color);
} else {
// everything else
plot->setAxisTitle(QwtPlot::yLeft, RideFile::seriesName(x.one));
}
}
QPalette pal;
pal.setColor(QPalette::WindowText, RideFile::colorFor(x.one));
pal.setColor(QPalette::Text, RideFile::colorFor(x.one));

plot->axisWidget(QwtPlot::yLeft)->setPalette(pal);

// remember them
Expand Down
1 change: 1 addition & 0 deletions src/AllPlotWindow.h
Expand Up @@ -385,6 +385,7 @@ class AllPlotWindow : public GcChartWindow

// user data series widgets
QList<UserData*> userDataSeries;
QList<QList<UserData*> > compareUserDataSeries;

// comparing
QList<AllPlotObject*> compareIntervalCurves; // one per compareInterval
Expand Down

0 comments on commit 84c4d52

Please sign in to comment.