mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
Fix LTM trend line
.. broken on All Dates selections. It must be time to introduce a polynomial fit or somesuch as the linear regress is a little simplistic for most cases.
This commit is contained in:
@@ -536,8 +536,8 @@ LTMPlot::setData(LTMSettings *set)
|
||||
|
||||
// cosmetics
|
||||
QPen cpen = QPen(metricDetail.penColor.darker(200));
|
||||
cpen.setWidth(width*2); // double thickness for trend lines
|
||||
cpen.setStyle(Qt::DotLine);
|
||||
cpen.setWidth(2); // double thickness for trend lines
|
||||
cpen.setStyle(Qt::SolidLine);
|
||||
trend->setPen(cpen);
|
||||
if (appsettings->value(this, GC_ANTIALIAS, false).toBool()==true)
|
||||
trend->setRenderHint(QwtPlotItem::RenderAntialiased);
|
||||
@@ -547,6 +547,11 @@ LTMPlot::setData(LTMSettings *set)
|
||||
|
||||
// perform linear regression
|
||||
LTMTrend regress(xdata.data(), ydata.data(), count);
|
||||
|
||||
// override class variable as doing it temporarily for trend line only
|
||||
double maxX = 0.5 + groupForDate(settings->end.date(), settings->groupBy) -
|
||||
groupForDate(settings->start.date(), settings->groupBy);
|
||||
|
||||
double xtrend[2], ytrend[2];
|
||||
xtrend[0] = 0.0;
|
||||
ytrend[0] = regress.getYforX(0.0);
|
||||
|
||||
@@ -29,6 +29,10 @@ LTMTrend::LTMTrend(double *xdata, double *ydata, int count) :
|
||||
if (count <= 2) return;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
|
||||
// ignore zero points
|
||||
if (ydata[i] == 0.00) continue;
|
||||
|
||||
points++;
|
||||
sumX += xdata[i];
|
||||
sumY += ydata[i];
|
||||
|
||||
@@ -26,6 +26,8 @@ class LTMTrend
|
||||
// Constructor using arrays of x values and y values
|
||||
LTMTrend(double *, double *, int);
|
||||
double getYforX(double x) const { return (a + b * x); }
|
||||
double intercept() { return a; }
|
||||
double slope() { return b; }
|
||||
|
||||
protected:
|
||||
long points;
|
||||
|
||||
Reference in New Issue
Block a user