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:
Mark Liversedge
2013-12-17 13:35:58 +00:00
parent 2ea02dbfd3
commit 8aee630180
3 changed files with 13 additions and 2 deletions

View File

@@ -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);

View File

@@ -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];

View File

@@ -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;