1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00

Fixed some corner case min/max graph values issue

This commit is contained in:
Martin Tůma 2018-10-26 09:15:23 +02:00
parent f05ff372e7
commit 9f3129f899
14 changed files with 71 additions and 27 deletions

View File

@ -7,9 +7,14 @@ CadenceGraphItem::CadenceGraphItem(const Graph &graph, GraphType type,
QGraphicsItem *parent) : GraphItem(graph, type, parent) QGraphicsItem *parent) : GraphItem(graph, type, parent)
{ {
qreal sum = 0; qreal sum = 0;
_max = graph.first().y();
for (int j = 1; j < graph.size(); j++) for (int i = 1; i < graph.size(); i++) {
sum += graph.at(j).y() * (graph.at(j).s() - graph.at(j-1).s()); qreal y = graph.at(i).y();
sum += y * (graph.at(i).s() - graph.at(i-1).s());
if (y > _max)
_max = y;
}
_avg = sum/graph.last().s(); _avg = sum/graph.last().s();
setToolTip(toolTip()); setToolTip(toolTip());

View File

@ -11,13 +11,13 @@ public:
CadenceGraphItem(const Graph &graph, GraphType type, CadenceGraphItem(const Graph &graph, GraphType type,
QGraphicsItem *parent = 0); QGraphicsItem *parent = 0);
qreal max() const {return -bounds().top();} qreal max() const {return _max;}
qreal avg() const {return _avg;} qreal avg() const {return _avg;}
private: private:
QString toolTip() const; QString toolTip() const;
qreal _avg; qreal _avg, _max;
}; };
#endif // CADENCEGRAPHITEM_H #endif // CADENCEGRAPHITEM_H

View File

@ -7,6 +7,7 @@ ElevationGraphItem::ElevationGraphItem(const Graph &graph, GraphType type,
QGraphicsItem *parent) : GraphItem(graph, type, parent) QGraphicsItem *parent) : GraphItem(graph, type, parent)
{ {
_ascent = _descent = 0; _ascent = _descent = 0;
_min = _max = graph.first().y();
for (int j = 1; j < graph.size(); j++) { for (int j = 1; j < graph.size(); j++) {
qreal cur = graph.at(j).y(); qreal cur = graph.at(j).y();
@ -16,6 +17,11 @@ ElevationGraphItem::ElevationGraphItem(const Graph &graph, GraphType type,
_ascent += cur - prev; _ascent += cur - prev;
if (cur < prev) if (cur < prev)
_descent += prev - cur; _descent += prev - cur;
if (cur < _min)
_min = cur;
if (cur > _max)
_max = cur;
} }
setToolTip(toolTip(Metric)); setToolTip(toolTip(Metric));

View File

@ -13,15 +13,15 @@ public:
qreal ascent() const {return _ascent;} qreal ascent() const {return _ascent;}
qreal descent() const {return _descent;} qreal descent() const {return _descent;}
qreal min() const {return -bounds().bottom();} qreal min() const {return _min;}
qreal max() const {return -bounds().top();} qreal max() const {return _max;}
void setUnits(Units units); void setUnits(Units units);
private: private:
QString toolTip(Units units) const; QString toolTip(Units units) const;
qreal _ascent, _descent; qreal _ascent, _descent, _min, _max;
}; };
#endif // ELEVATIONGRAPHITEM_H #endif // ELEVATIONGRAPHITEM_H

View File

@ -8,11 +8,18 @@ GearRatioGraphItem::GearRatioGraphItem(const Graph &graph, GraphType type,
QGraphicsItem *parent) : GraphItem(graph, type, parent), _top(NAN) QGraphicsItem *parent) : GraphItem(graph, type, parent), _top(NAN)
{ {
qreal val = NAN; qreal val = NAN;
_min = _max = graph.first().y();
for (int i = 1; i < graph.size(); i++) {
const GraphPoint &p = graph.at(i);
for (int j = 1; j < graph.size(); j++) {
const GraphPoint &p = graph.at(j);
qreal val = _map.value(p.y()); qreal val = _map.value(p.y());
_map.insert(p.y(), val + (p.s() - graph.at(j-1).s())); _map.insert(p.y(), val + (p.s() - graph.at(i-1).s()));
if (p.y() < _min)
_min = p.y();
if (p.y() > _max)
_max = p.y();
} }
for (QMap<qreal, qreal>::const_iterator it = _map.constBegin(); for (QMap<qreal, qreal>::const_iterator it = _map.constBegin();

View File

@ -12,8 +12,8 @@ public:
GearRatioGraphItem(const Graph &graph, GraphType type, GearRatioGraphItem(const Graph &graph, GraphType type,
QGraphicsItem *parent = 0); QGraphicsItem *parent = 0);
qreal min() const {return -bounds().bottom();} qreal min() const {return _min;}
qreal max() const {return -bounds().top();} qreal max() const {return _max;}
qreal top() const {return _top;} qreal top() const {return _top;}
const QMap<qreal, qreal> &map() const {return _map;} const QMap<qreal, qreal> &map() const {return _map;}
@ -22,7 +22,7 @@ private:
QString toolTip() const; QString toolTip() const;
QMap<qreal, qreal> _map; QMap<qreal, qreal> _map;
qreal _top; qreal _top, _min, _max;
}; };
#endif // GEARRATIOGRAPHITEM_H #endif // GEARRATIOGRAPHITEM_H

View File

@ -7,9 +7,14 @@ HeartRateGraphItem::HeartRateGraphItem(const Graph &graph, GraphType type,
QGraphicsItem *parent) : GraphItem(graph, type, parent) QGraphicsItem *parent) : GraphItem(graph, type, parent)
{ {
qreal sum = 0; qreal sum = 0;
_max = graph.first().y();
for (int j = 1; j < graph.size(); j++) for (int i = 1; i < graph.size(); i++) {
sum += graph.at(j).y() * (graph.at(j).s() - graph.at(j-1).s()); qreal y = graph.at(i).y();
sum += y * (graph.at(i).s() - graph.at(i-1).s());
if (y > _max)
_max = y;
}
_avg = sum/graph.last().s(); _avg = sum/graph.last().s();
setToolTip(toolTip()); setToolTip(toolTip());

View File

@ -11,13 +11,13 @@ public:
HeartRateGraphItem(const Graph &graph, GraphType type, HeartRateGraphItem(const Graph &graph, GraphType type,
QGraphicsItem *parent = 0); QGraphicsItem *parent = 0);
qreal max() const {return -bounds().top();} qreal max() const {return _max;}
qreal avg() const {return _avg;} qreal avg() const {return _avg;}
private: private:
QString toolTip() const; QString toolTip() const;
qreal _avg; qreal _avg, _max;
}; };
#endif // HEARTRATEGRAPHITEM_H #endif // HEARTRATEGRAPHITEM_H

View File

@ -7,9 +7,14 @@ PowerGraphItem::PowerGraphItem(const Graph &graph, GraphType type,
QGraphicsItem *parent) : GraphItem(graph, type, parent) QGraphicsItem *parent) : GraphItem(graph, type, parent)
{ {
qreal sum = 0; qreal sum = 0;
_max = graph.first().y();
for (int j = 1; j < graph.size(); j++) for (int i = 1; i < graph.size(); i++) {
sum += graph.at(j).y() * (graph.at(j).s() - graph.at(j-1).s()); qreal y = graph.at(i).y();
sum += y * (graph.at(i).s() - graph.at(i-1).s());
if (y > _max)
_max = y;
}
_avg = sum/graph.last().s(); _avg = sum/graph.last().s();
setToolTip(toolTip()); setToolTip(toolTip());

View File

@ -11,13 +11,13 @@ public:
PowerGraphItem(const Graph &graph, GraphType type, PowerGraphItem(const Graph &graph, GraphType type,
QGraphicsItem *parent = 0); QGraphicsItem *parent = 0);
qreal max() const {return -bounds().top();} qreal max() const {return _max;}
qreal avg() const {return _avg;} qreal avg() const {return _avg;}
private: private:
QString toolTip() const; QString toolTip() const;
qreal _avg; qreal _avg, _max;
}; };
#endif // POWERGRAPHITEM_H #endif // POWERGRAPHITEM_H

View File

@ -13,6 +13,13 @@ SpeedGraphItem::SpeedGraphItem(const Graph &graph, GraphType type,
_avg = graph.last().s() / graph.last().t(); _avg = graph.last().s() / graph.last().t();
_mavg = graph.last().s() / movingTime; _mavg = graph.last().s() / movingTime;
_max = graph.first().y();
for (int i = 1; i < graph.size(); i++) {
qreal y = graph.at(i).y();
if (y > _max)
_max = y;
}
setToolTip(toolTip()); setToolTip(toolTip());
} }

View File

@ -12,7 +12,7 @@ public:
SpeedGraphItem(const Graph &graph, GraphType type, qreal movingTime, SpeedGraphItem(const Graph &graph, GraphType type, qreal movingTime,
QGraphicsItem *parent = 0); QGraphicsItem *parent = 0);
qreal max() const {return -bounds().top();} qreal max() const {return _max;}
qreal avg() const {return _avg;} qreal avg() const {return _avg;}
qreal mavg() const {return _mavg;} qreal mavg() const {return _mavg;}
@ -22,7 +22,7 @@ public:
private: private:
QString toolTip() const; QString toolTip() const;
qreal _avg, _mavg; qreal _avg, _mavg, _max;
Units _units; Units _units;
TimeType _timeType; TimeType _timeType;

View File

@ -7,9 +7,18 @@ TemperatureGraphItem::TemperatureGraphItem(const Graph &graph, GraphType type,
QGraphicsItem *parent) : GraphItem(graph, type, parent) QGraphicsItem *parent) : GraphItem(graph, type, parent)
{ {
qreal sum = 0; qreal sum = 0;
_min = _max = graph.first().y();
for (int j = 1; j < graph.size(); j++) {
qreal y = graph.at(j).y();
for (int j = 1; j < graph.size(); j++)
sum += graph.at(j).y() * (graph.at(j).s() - graph.at(j-1).s()); sum += graph.at(j).y() * (graph.at(j).s() - graph.at(j-1).s());
if (y > _max)
_max = y;
if (y < _min)
_min = y;
}
_avg = sum/graph.last().s(); _avg = sum/graph.last().s();
setToolTip(toolTip(Metric)); setToolTip(toolTip(Metric));

View File

@ -11,8 +11,8 @@ public:
TemperatureGraphItem(const Graph &graph, GraphType type, TemperatureGraphItem(const Graph &graph, GraphType type,
QGraphicsItem *parent = 0); QGraphicsItem *parent = 0);
qreal max() const {return -bounds().top();} qreal max() const {return _max;}
qreal min() const {return -bounds().bottom();} qreal min() const {return _min;}
qreal avg() const {return _avg;} qreal avg() const {return _avg;}
void setUnits(Units units); void setUnits(Units units);
@ -20,7 +20,7 @@ public:
private: private:
QString toolTip(Units units) const; QString toolTip(Units units) const;
qreal _avg; qreal _avg, _min, _max;
}; };
#endif // TEMPERATUREGRAPHITEM_H #endif // TEMPERATUREGRAPHITEM_H