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