mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-27 21:24:47 +01:00
Fixed graph display issues on constant graphs
Fixed elevation graph data handling
This commit is contained in:
parent
56f15da550
commit
ee3a6adf2b
@ -16,6 +16,7 @@ ElevationGraph::ElevationGraph(QWidget *parent) : GraphView(parent)
|
||||
GraphView::setXUnits(tr("km"));
|
||||
GraphView::setYUnits(tr("m"));
|
||||
GraphView::setXScale(M2KM);
|
||||
GraphView::setMinRange(50.0);
|
||||
}
|
||||
|
||||
void ElevationGraph::addInfo()
|
||||
|
@ -53,6 +53,7 @@ GraphView::GraphView(QWidget *parent)
|
||||
_yScale = 1;
|
||||
|
||||
_precision = 0;
|
||||
_minRange = 0.01;
|
||||
}
|
||||
|
||||
GraphView::~GraphView()
|
||||
@ -166,8 +167,9 @@ void GraphView::resize(const QSizeF &size)
|
||||
{
|
||||
QRectF r;
|
||||
QSizeF mx, my;
|
||||
QPointF rx, ry;
|
||||
QTransform transform;
|
||||
qreal xs, ys;
|
||||
qreal xs, ys, diff;
|
||||
|
||||
|
||||
if (_xAxis->scene() == _scene)
|
||||
@ -182,11 +184,21 @@ void GraphView::resize(const QSizeF &size)
|
||||
for (int i = 0; i < _graphs.size(); i++)
|
||||
_graphs.at(i)->resetTransform();
|
||||
|
||||
_xAxis->setRange(QPointF(_xMin * _xScale, _xMax * _xScale));
|
||||
_yAxis->setRange(QPointF(_yMin * _yScale, _yMax * _yScale));
|
||||
rx = QPointF(_xMin * _xScale, _xMax * _xScale);
|
||||
ry = QPointF(_yMin * _yScale, _yMax * _yScale);
|
||||
if ((diff = ry.y() - ry.x()) < _minRange)
|
||||
ry = QPointF(ry.x() - (_minRange/2 - diff/2),
|
||||
ry.y() + (_minRange/2 - diff/2));
|
||||
_xAxis->setRange(rx);
|
||||
_yAxis->setRange(ry);
|
||||
mx = _xAxis->margin();
|
||||
my = _yAxis->margin();
|
||||
|
||||
r = _scene->itemsBoundingRect();
|
||||
if (r.height() < _minRange)
|
||||
r.adjust(0, -(_minRange/2 - r.height()/2), 0,
|
||||
_minRange/2 - r.height()/2);
|
||||
|
||||
xs = (size.width() - (my.width() + mx.width())) / r.width();
|
||||
ys = (size.height() - (mx.height() + my.height())
|
||||
- _info->boundingRect().height()) / r.height();
|
||||
@ -196,6 +208,10 @@ void GraphView::resize(const QSizeF &size)
|
||||
_graphs.at(i)->setTransform(transform);
|
||||
|
||||
r = _scene->itemsBoundingRect();
|
||||
if (r.height() < _minRange * ys)
|
||||
r.adjust(0, -(_minRange/2 * ys - r.height()/2), 0,
|
||||
(_minRange/2) * ys - r.height()/2);
|
||||
|
||||
_xAxis->setSize(r.width());
|
||||
_yAxis->setSize(r.height());
|
||||
_xAxis->setPos(r.bottomLeft());
|
||||
@ -280,9 +296,12 @@ void GraphView::emitSliderPositionChanged(const QPointF &pos)
|
||||
emit sliderPositionChanged(val);
|
||||
|
||||
const QPainterPath &path = _graphs.at(0)->path();
|
||||
QRectF br = path.boundingRect();
|
||||
if (br.height() < _minRange)
|
||||
br.adjust(0, -(_minRange/2 - br.height()/2), 0,
|
||||
_minRange/2 - br.height()/2);
|
||||
QPointF p = path.pointAtPercent(val);
|
||||
qreal r = (p.y() - path.boundingRect().bottom())
|
||||
/ path.boundingRect().height();
|
||||
qreal r = (p.y() - br.bottom()) / br.height();
|
||||
_sliderInfo->setPos(QPointF(0, _slider->boundingRect().height() * r));
|
||||
_sliderInfo->setText(QString::number(-p.y() * _yScale, 'f', _precision));
|
||||
}
|
||||
|
@ -41,7 +41,8 @@ public:
|
||||
void setYUnits(const QString &units);
|
||||
void setXScale(qreal scale);
|
||||
void setYScale(qreal scale);
|
||||
void setPrecision(int p) {_precision = p;}
|
||||
void setPrecision(int precision) {_precision = precision;}
|
||||
void setMinRange(qreal range) {_minRange = range;}
|
||||
|
||||
void redraw();
|
||||
|
||||
@ -64,6 +65,7 @@ protected:
|
||||
QString _xUnits, _yUnits;
|
||||
QString _xLabel, _yLabel;
|
||||
int _precision;
|
||||
qreal _minRange;
|
||||
|
||||
private slots:
|
||||
void emitSliderPositionChanged(const QPointF &pos);
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
SliderInfoItem::SliderInfoItem(QGraphicsItem *parent) : QGraphicsItem(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SliderInfoItem::updateBoundingRect()
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include <cmath>
|
||||
#include "ll.h"
|
||||
#include "track.h"
|
||||
|
||||
|
||||
#define WINDOW_EF 3
|
||||
#define WINDOW_SE 11
|
||||
#define WINDOW_SF 11
|
||||
@ -84,9 +86,13 @@ void Track::elevationGraph(QVector<QPointF> &graph) const
|
||||
if (!_data.size())
|
||||
return;
|
||||
|
||||
if (isnan(_data.at(0).elevation))
|
||||
return;
|
||||
raw.append(QPointF(0, _data.at(0).elevation));
|
||||
for (int i = 1; i < _data.size(); i++) {
|
||||
dist += llDistance(_data.at(i).coordinates, _data.at(i-1).coordinates);
|
||||
if (isnan(_data.at(i).elevation))
|
||||
return;
|
||||
raw.append(QPointF(dist, _data.at(i).elevation
|
||||
- _data.at(i).geoidheight));
|
||||
}
|
||||
@ -108,7 +114,7 @@ void Track::speedGraph(QVector<QPointF> &graph) const
|
||||
dt = _data.at(i-1).timestamp.msecsTo(_data.at(i).timestamp) / 1000.0;
|
||||
dist += ds;
|
||||
|
||||
if (_data.at(i).speed < 0) {
|
||||
if (isnan(_data.at(i).speed)) {
|
||||
if (dt == 0)
|
||||
continue;
|
||||
v = ds / dt;
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <QPointF>
|
||||
#include <QDateTime>
|
||||
#include <cmath>
|
||||
|
||||
struct Trackpoint
|
||||
{
|
||||
@ -12,7 +13,7 @@ struct Trackpoint
|
||||
qreal geoidheight;
|
||||
qreal speed;
|
||||
|
||||
Trackpoint() {elevation = 0; geoidheight = 0; speed = -1;}
|
||||
Trackpoint() {elevation = NAN; geoidheight = 0; speed = NAN;}
|
||||
};
|
||||
|
||||
#endif // TRACKPOINT_H
|
||||
|
Loading…
Reference in New Issue
Block a user