statistics: implement axes
Implement five kinds of axes:
- ValueAxis: a standard axis for plotting numerical linear data.
- CountAxis: a ValueAxis for plotting counts of dives.
- CategoryAxis: an axis for plotting discrete variables without
any notion of distance.
- HistogramAxis: an axis for plotting bins with a numeric value.
- DateAxis: a HistogramAxis that formats dates.
The axes derive from a common virtual base class that defines
a small interface, notably, returning the minimum and maximum
displayed value and redrawing the axis.
The mapping and painting is performed by QtCharts' axes. On
the one hand, using QtCharts turned out to be too inflexible.
On the other hand it allowed us to quickly prototype the charts.
Ultimately, we should do our own drawing of the axis.
As a testament to the inflexibility, QtCharts' axes do not
allow for repeated labels is needed for quarter-based date
charts (year, Q2, Q3, Q4, year, Q2, Q3, ...). Therefore the
code disambiguates labels by adding unicode zero-width spaces.
Wonderful.
When omitting labels due to space reasons, the histogram
axis attempts to show "preferred" labels. In the quarter
example above, it tries to show full years.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01 20:35:56 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#ifndef STATS_AXIS_H
|
|
|
|
#define STATS_AXIS_H
|
|
|
|
|
2021-01-14 22:22:24 +00:00
|
|
|
#include "chartitem.h"
|
|
|
|
|
2021-01-05 11:11:46 +00:00
|
|
|
#include <memory>
|
statistics: implement axes
Implement five kinds of axes:
- ValueAxis: a standard axis for plotting numerical linear data.
- CountAxis: a ValueAxis for plotting counts of dives.
- CategoryAxis: an axis for plotting discrete variables without
any notion of distance.
- HistogramAxis: an axis for plotting bins with a numeric value.
- DateAxis: a HistogramAxis that formats dates.
The axes derive from a common virtual base class that defines
a small interface, notably, returning the minimum and maximum
displayed value and redrawing the axis.
The mapping and painting is performed by QtCharts' axes. On
the one hand, using QtCharts turned out to be too inflexible.
On the other hand it allowed us to quickly prototype the charts.
Ultimately, we should do our own drawing of the axis.
As a testament to the inflexibility, QtCharts' axes do not
allow for repeated labels is needed for quarter-based date
charts (year, Q2, Q3, Q4, year, Q2, Q3, ...). Therefore the
code disambiguates labels by adding unicode zero-width spaces.
Wonderful.
When omitting labels due to space reasons, the histogram
axis attempts to show "preferred" labels. In the quarter
example above, it tries to show full years.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01 20:35:56 +00:00
|
|
|
#include <vector>
|
2021-01-05 11:11:46 +00:00
|
|
|
#include <QFont>
|
statistics: implement axes
Implement five kinds of axes:
- ValueAxis: a standard axis for plotting numerical linear data.
- CountAxis: a ValueAxis for plotting counts of dives.
- CategoryAxis: an axis for plotting discrete variables without
any notion of distance.
- HistogramAxis: an axis for plotting bins with a numeric value.
- DateAxis: a HistogramAxis that formats dates.
The axes derive from a common virtual base class that defines
a small interface, notably, returning the minimum and maximum
displayed value and redrawing the axis.
The mapping and painting is performed by QtCharts' axes. On
the one hand, using QtCharts turned out to be too inflexible.
On the other hand it allowed us to quickly prototype the charts.
Ultimately, we should do our own drawing of the axis.
As a testament to the inflexibility, QtCharts' axes do not
allow for repeated labels is needed for quarter-based date
charts (year, Q2, Q3, Q4, year, Q2, Q3, ...). Therefore the
code disambiguates labels by adding unicode zero-width spaces.
Wonderful.
When omitting labels due to space reasons, the histogram
axis attempts to show "preferred" labels. In the quarter
example above, it tries to show full years.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01 20:35:56 +00:00
|
|
|
|
2021-01-14 22:22:24 +00:00
|
|
|
class StatsView;
|
|
|
|
class ChartLineItem;
|
|
|
|
class QFontMetrics;
|
statistics: implement axes
Implement five kinds of axes:
- ValueAxis: a standard axis for plotting numerical linear data.
- CountAxis: a ValueAxis for plotting counts of dives.
- CategoryAxis: an axis for plotting discrete variables without
any notion of distance.
- HistogramAxis: an axis for plotting bins with a numeric value.
- DateAxis: a HistogramAxis that formats dates.
The axes derive from a common virtual base class that defines
a small interface, notably, returning the minimum and maximum
displayed value and redrawing the axis.
The mapping and painting is performed by QtCharts' axes. On
the one hand, using QtCharts turned out to be too inflexible.
On the other hand it allowed us to quickly prototype the charts.
Ultimately, we should do our own drawing of the axis.
As a testament to the inflexibility, QtCharts' axes do not
allow for repeated labels is needed for quarter-based date
charts (year, Q2, Q3, Q4, year, Q2, Q3, ...). Therefore the
code disambiguates labels by adding unicode zero-width spaces.
Wonderful.
When omitting labels due to space reasons, the histogram
axis attempts to show "preferred" labels. In the quarter
example above, it tries to show full years.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01 20:35:56 +00:00
|
|
|
|
2021-01-14 22:22:24 +00:00
|
|
|
// The labels and the title of the axis are rendered into a pixmap.
|
|
|
|
// The ticks and the baseline are realized as individual ChartLineItems.
|
|
|
|
class StatsAxis : public ChartPixmapItem {
|
statistics: implement axes
Implement five kinds of axes:
- ValueAxis: a standard axis for plotting numerical linear data.
- CountAxis: a ValueAxis for plotting counts of dives.
- CategoryAxis: an axis for plotting discrete variables without
any notion of distance.
- HistogramAxis: an axis for plotting bins with a numeric value.
- DateAxis: a HistogramAxis that formats dates.
The axes derive from a common virtual base class that defines
a small interface, notably, returning the minimum and maximum
displayed value and redrawing the axis.
The mapping and painting is performed by QtCharts' axes. On
the one hand, using QtCharts turned out to be too inflexible.
On the other hand it allowed us to quickly prototype the charts.
Ultimately, we should do our own drawing of the axis.
As a testament to the inflexibility, QtCharts' axes do not
allow for repeated labels is needed for quarter-based date
charts (year, Q2, Q3, Q4, year, Q2, Q3, ...). Therefore the
code disambiguates labels by adding unicode zero-width spaces.
Wonderful.
When omitting labels due to space reasons, the histogram
axis attempts to show "preferred" labels. In the quarter
example above, it tries to show full years.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01 20:35:56 +00:00
|
|
|
public:
|
|
|
|
virtual ~StatsAxis();
|
|
|
|
// Returns minimum and maximum of shown range, not of data points.
|
2021-01-05 11:11:46 +00:00
|
|
|
std::pair<double, double> minMax() const;
|
2021-01-06 13:17:51 +00:00
|
|
|
std::pair<double, double> minMaxScreen() const; // minimum and maximum in screen coordinates
|
2021-01-11 11:59:17 +00:00
|
|
|
std::pair<double, double> horizontalOverhang() const; // space that labels peak out in horizontal axes
|
2021-01-05 11:11:46 +00:00
|
|
|
|
|
|
|
double width() const; // Only supported by vertical axes. Only valid after setSize().
|
|
|
|
double height() const; // Only supported for horizontal axes. Always valid.
|
|
|
|
void setSize(double size); // Width for horizontal and height for vertical.
|
|
|
|
void setPos(QPointF pos); // Must be called after setSize().
|
|
|
|
void setRange(double, double);
|
|
|
|
|
|
|
|
// Map x (horizontal) or y (vertical) coordinate to or from screen coordinate
|
|
|
|
double toScreen(double) const;
|
|
|
|
double toValue(double) const;
|
2021-01-05 12:51:39 +00:00
|
|
|
|
|
|
|
std::vector<double> ticksPositions() const; // Positions in screen coordinates
|
statistics: implement axes
Implement five kinds of axes:
- ValueAxis: a standard axis for plotting numerical linear data.
- CountAxis: a ValueAxis for plotting counts of dives.
- CategoryAxis: an axis for plotting discrete variables without
any notion of distance.
- HistogramAxis: an axis for plotting bins with a numeric value.
- DateAxis: a HistogramAxis that formats dates.
The axes derive from a common virtual base class that defines
a small interface, notably, returning the minimum and maximum
displayed value and redrawing the axis.
The mapping and painting is performed by QtCharts' axes. On
the one hand, using QtCharts turned out to be too inflexible.
On the other hand it allowed us to quickly prototype the charts.
Ultimately, we should do our own drawing of the axis.
As a testament to the inflexibility, QtCharts' axes do not
allow for repeated labels is needed for quarter-based date
charts (year, Q2, Q3, Q4, year, Q2, Q3, ...). Therefore the
code disambiguates labels by adding unicode zero-width spaces.
Wonderful.
When omitting labels due to space reasons, the histogram
axis attempts to show "preferred" labels. In the quarter
example above, it tries to show full years.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01 20:35:56 +00:00
|
|
|
protected:
|
2021-01-14 22:22:24 +00:00
|
|
|
StatsAxis(StatsView &view, const QString &title, bool horizontal, bool labelsBetweenTicks);
|
|
|
|
|
|
|
|
std::unique_ptr<ChartLineItem> line;
|
|
|
|
QString title;
|
|
|
|
double titleWidth;
|
2021-01-05 11:11:46 +00:00
|
|
|
|
|
|
|
struct Label {
|
2021-01-14 22:22:24 +00:00
|
|
|
QString label;
|
|
|
|
int width;
|
2021-01-05 11:11:46 +00:00
|
|
|
double pos;
|
|
|
|
};
|
|
|
|
std::vector<Label> labels;
|
2021-01-14 22:22:24 +00:00
|
|
|
void addLabel(const QFontMetrics &fm, const QString &label, double pos);
|
2021-01-05 11:11:46 +00:00
|
|
|
virtual void updateLabels() = 0;
|
2021-01-11 11:59:17 +00:00
|
|
|
virtual std::pair<QString, QString> getFirstLastLabel() const = 0;
|
2021-01-05 11:11:46 +00:00
|
|
|
|
|
|
|
struct Tick {
|
2021-01-14 22:22:24 +00:00
|
|
|
std::unique_ptr<ChartLineItem> item;
|
2021-01-05 11:11:46 +00:00
|
|
|
double pos;
|
|
|
|
};
|
|
|
|
std::vector<Tick> ticks;
|
|
|
|
void addTick(double pos);
|
|
|
|
|
|
|
|
int guessNumTicks(const std::vector<QString> &strings) const;
|
statistics: implement axes
Implement five kinds of axes:
- ValueAxis: a standard axis for plotting numerical linear data.
- CountAxis: a ValueAxis for plotting counts of dives.
- CategoryAxis: an axis for plotting discrete variables without
any notion of distance.
- HistogramAxis: an axis for plotting bins with a numeric value.
- DateAxis: a HistogramAxis that formats dates.
The axes derive from a common virtual base class that defines
a small interface, notably, returning the minimum and maximum
displayed value and redrawing the axis.
The mapping and painting is performed by QtCharts' axes. On
the one hand, using QtCharts turned out to be too inflexible.
On the other hand it allowed us to quickly prototype the charts.
Ultimately, we should do our own drawing of the axis.
As a testament to the inflexibility, QtCharts' axes do not
allow for repeated labels is needed for quarter-based date
charts (year, Q2, Q3, Q4, year, Q2, Q3, ...). Therefore the
code disambiguates labels by adding unicode zero-width spaces.
Wonderful.
When omitting labels due to space reasons, the histogram
axis attempts to show "preferred" labels. In the quarter
example above, it tries to show full years.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01 20:35:56 +00:00
|
|
|
bool horizontal;
|
2021-01-05 11:11:46 +00:00
|
|
|
bool labelsBetweenTicks; // When labels are between ticks, they can be moved closer to the axis
|
statistics: implement axes
Implement five kinds of axes:
- ValueAxis: a standard axis for plotting numerical linear data.
- CountAxis: a ValueAxis for plotting counts of dives.
- CategoryAxis: an axis for plotting discrete variables without
any notion of distance.
- HistogramAxis: an axis for plotting bins with a numeric value.
- DateAxis: a HistogramAxis that formats dates.
The axes derive from a common virtual base class that defines
a small interface, notably, returning the minimum and maximum
displayed value and redrawing the axis.
The mapping and painting is performed by QtCharts' axes. On
the one hand, using QtCharts turned out to be too inflexible.
On the other hand it allowed us to quickly prototype the charts.
Ultimately, we should do our own drawing of the axis.
As a testament to the inflexibility, QtCharts' axes do not
allow for repeated labels is needed for quarter-based date
charts (year, Q2, Q3, Q4, year, Q2, Q3, ...). Therefore the
code disambiguates labels by adding unicode zero-width spaces.
Wonderful.
When omitting labels due to space reasons, the histogram
axis attempts to show "preferred" labels. In the quarter
example above, it tries to show full years.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01 20:35:56 +00:00
|
|
|
|
2021-01-05 11:11:46 +00:00
|
|
|
QFont labelFont, titleFont;
|
|
|
|
double size; // width for horizontal, height for vertical
|
|
|
|
double zeroOnScreen;
|
2021-01-14 22:22:24 +00:00
|
|
|
QPointF offset; // Offset of the label and title pixmap with respect to the (0,0) position.
|
2021-01-05 11:11:46 +00:00
|
|
|
double min, max;
|
2021-01-05 12:04:53 +00:00
|
|
|
double labelWidth; // Maximum width of labels
|
|
|
|
private:
|
|
|
|
double titleSpace() const; // Space needed for title
|
statistics: implement axes
Implement five kinds of axes:
- ValueAxis: a standard axis for plotting numerical linear data.
- CountAxis: a ValueAxis for plotting counts of dives.
- CategoryAxis: an axis for plotting discrete variables without
any notion of distance.
- HistogramAxis: an axis for plotting bins with a numeric value.
- DateAxis: a HistogramAxis that formats dates.
The axes derive from a common virtual base class that defines
a small interface, notably, returning the minimum and maximum
displayed value and redrawing the axis.
The mapping and painting is performed by QtCharts' axes. On
the one hand, using QtCharts turned out to be too inflexible.
On the other hand it allowed us to quickly prototype the charts.
Ultimately, we should do our own drawing of the axis.
As a testament to the inflexibility, QtCharts' axes do not
allow for repeated labels is needed for quarter-based date
charts (year, Q2, Q3, Q4, year, Q2, Q3, ...). Therefore the
code disambiguates labels by adding unicode zero-width spaces.
Wonderful.
When omitting labels due to space reasons, the histogram
axis attempts to show "preferred" labels. In the quarter
example above, it tries to show full years.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01 20:35:56 +00:00
|
|
|
};
|
|
|
|
|
2021-01-05 11:11:46 +00:00
|
|
|
class ValueAxis : public StatsAxis {
|
statistics: implement axes
Implement five kinds of axes:
- ValueAxis: a standard axis for plotting numerical linear data.
- CountAxis: a ValueAxis for plotting counts of dives.
- CategoryAxis: an axis for plotting discrete variables without
any notion of distance.
- HistogramAxis: an axis for plotting bins with a numeric value.
- DateAxis: a HistogramAxis that formats dates.
The axes derive from a common virtual base class that defines
a small interface, notably, returning the minimum and maximum
displayed value and redrawing the axis.
The mapping and painting is performed by QtCharts' axes. On
the one hand, using QtCharts turned out to be too inflexible.
On the other hand it allowed us to quickly prototype the charts.
Ultimately, we should do our own drawing of the axis.
As a testament to the inflexibility, QtCharts' axes do not
allow for repeated labels is needed for quarter-based date
charts (year, Q2, Q3, Q4, year, Q2, Q3, ...). Therefore the
code disambiguates labels by adding unicode zero-width spaces.
Wonderful.
When omitting labels due to space reasons, the histogram
axis attempts to show "preferred" labels. In the quarter
example above, it tries to show full years.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01 20:35:56 +00:00
|
|
|
public:
|
2021-01-14 22:22:24 +00:00
|
|
|
ValueAxis(StatsView &view, const QString &title, double min, double max, int decimals, bool horizontal);
|
statistics: implement axes
Implement five kinds of axes:
- ValueAxis: a standard axis for plotting numerical linear data.
- CountAxis: a ValueAxis for plotting counts of dives.
- CategoryAxis: an axis for plotting discrete variables without
any notion of distance.
- HistogramAxis: an axis for plotting bins with a numeric value.
- DateAxis: a HistogramAxis that formats dates.
The axes derive from a common virtual base class that defines
a small interface, notably, returning the minimum and maximum
displayed value and redrawing the axis.
The mapping and painting is performed by QtCharts' axes. On
the one hand, using QtCharts turned out to be too inflexible.
On the other hand it allowed us to quickly prototype the charts.
Ultimately, we should do our own drawing of the axis.
As a testament to the inflexibility, QtCharts' axes do not
allow for repeated labels is needed for quarter-based date
charts (year, Q2, Q3, Q4, year, Q2, Q3, ...). Therefore the
code disambiguates labels by adding unicode zero-width spaces.
Wonderful.
When omitting labels due to space reasons, the histogram
axis attempts to show "preferred" labels. In the quarter
example above, it tries to show full years.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01 20:35:56 +00:00
|
|
|
private:
|
|
|
|
double min, max;
|
|
|
|
int decimals;
|
2021-01-04 16:16:13 +00:00
|
|
|
void updateLabels() override;
|
2021-01-11 11:59:17 +00:00
|
|
|
std::pair<QString, QString> getFirstLastLabel() const override;
|
statistics: implement axes
Implement five kinds of axes:
- ValueAxis: a standard axis for plotting numerical linear data.
- CountAxis: a ValueAxis for plotting counts of dives.
- CategoryAxis: an axis for plotting discrete variables without
any notion of distance.
- HistogramAxis: an axis for plotting bins with a numeric value.
- DateAxis: a HistogramAxis that formats dates.
The axes derive from a common virtual base class that defines
a small interface, notably, returning the minimum and maximum
displayed value and redrawing the axis.
The mapping and painting is performed by QtCharts' axes. On
the one hand, using QtCharts turned out to be too inflexible.
On the other hand it allowed us to quickly prototype the charts.
Ultimately, we should do our own drawing of the axis.
As a testament to the inflexibility, QtCharts' axes do not
allow for repeated labels is needed for quarter-based date
charts (year, Q2, Q3, Q4, year, Q2, Q3, ...). Therefore the
code disambiguates labels by adding unicode zero-width spaces.
Wonderful.
When omitting labels due to space reasons, the histogram
axis attempts to show "preferred" labels. In the quarter
example above, it tries to show full years.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01 20:35:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CountAxis : public ValueAxis {
|
|
|
|
public:
|
2021-01-14 22:22:24 +00:00
|
|
|
CountAxis(StatsView &view, const QString &title, int count, bool horizontal);
|
statistics: implement axes
Implement five kinds of axes:
- ValueAxis: a standard axis for plotting numerical linear data.
- CountAxis: a ValueAxis for plotting counts of dives.
- CategoryAxis: an axis for plotting discrete variables without
any notion of distance.
- HistogramAxis: an axis for plotting bins with a numeric value.
- DateAxis: a HistogramAxis that formats dates.
The axes derive from a common virtual base class that defines
a small interface, notably, returning the minimum and maximum
displayed value and redrawing the axis.
The mapping and painting is performed by QtCharts' axes. On
the one hand, using QtCharts turned out to be too inflexible.
On the other hand it allowed us to quickly prototype the charts.
Ultimately, we should do our own drawing of the axis.
As a testament to the inflexibility, QtCharts' axes do not
allow for repeated labels is needed for quarter-based date
charts (year, Q2, Q3, Q4, year, Q2, Q3, ...). Therefore the
code disambiguates labels by adding unicode zero-width spaces.
Wonderful.
When omitting labels due to space reasons, the histogram
axis attempts to show "preferred" labels. In the quarter
example above, it tries to show full years.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01 20:35:56 +00:00
|
|
|
private:
|
|
|
|
int count;
|
2021-01-04 16:16:13 +00:00
|
|
|
void updateLabels() override;
|
2021-01-11 11:59:17 +00:00
|
|
|
std::pair<QString, QString> getFirstLastLabel() const override;
|
statistics: implement axes
Implement five kinds of axes:
- ValueAxis: a standard axis for plotting numerical linear data.
- CountAxis: a ValueAxis for plotting counts of dives.
- CategoryAxis: an axis for plotting discrete variables without
any notion of distance.
- HistogramAxis: an axis for plotting bins with a numeric value.
- DateAxis: a HistogramAxis that formats dates.
The axes derive from a common virtual base class that defines
a small interface, notably, returning the minimum and maximum
displayed value and redrawing the axis.
The mapping and painting is performed by QtCharts' axes. On
the one hand, using QtCharts turned out to be too inflexible.
On the other hand it allowed us to quickly prototype the charts.
Ultimately, we should do our own drawing of the axis.
As a testament to the inflexibility, QtCharts' axes do not
allow for repeated labels is needed for quarter-based date
charts (year, Q2, Q3, Q4, year, Q2, Q3, ...). Therefore the
code disambiguates labels by adding unicode zero-width spaces.
Wonderful.
When omitting labels due to space reasons, the histogram
axis attempts to show "preferred" labels. In the quarter
example above, it tries to show full years.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01 20:35:56 +00:00
|
|
|
};
|
|
|
|
|
2021-01-05 11:11:46 +00:00
|
|
|
class CategoryAxis : public StatsAxis {
|
statistics: implement axes
Implement five kinds of axes:
- ValueAxis: a standard axis for plotting numerical linear data.
- CountAxis: a ValueAxis for plotting counts of dives.
- CategoryAxis: an axis for plotting discrete variables without
any notion of distance.
- HistogramAxis: an axis for plotting bins with a numeric value.
- DateAxis: a HistogramAxis that formats dates.
The axes derive from a common virtual base class that defines
a small interface, notably, returning the minimum and maximum
displayed value and redrawing the axis.
The mapping and painting is performed by QtCharts' axes. On
the one hand, using QtCharts turned out to be too inflexible.
On the other hand it allowed us to quickly prototype the charts.
Ultimately, we should do our own drawing of the axis.
As a testament to the inflexibility, QtCharts' axes do not
allow for repeated labels is needed for quarter-based date
charts (year, Q2, Q3, Q4, year, Q2, Q3, ...). Therefore the
code disambiguates labels by adding unicode zero-width spaces.
Wonderful.
When omitting labels due to space reasons, the histogram
axis attempts to show "preferred" labels. In the quarter
example above, it tries to show full years.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01 20:35:56 +00:00
|
|
|
public:
|
2021-01-14 22:22:24 +00:00
|
|
|
CategoryAxis(StatsView &view, const QString &title, const std::vector<QString> &labels, bool horizontal);
|
statistics: implement axes
Implement five kinds of axes:
- ValueAxis: a standard axis for plotting numerical linear data.
- CountAxis: a ValueAxis for plotting counts of dives.
- CategoryAxis: an axis for plotting discrete variables without
any notion of distance.
- HistogramAxis: an axis for plotting bins with a numeric value.
- DateAxis: a HistogramAxis that formats dates.
The axes derive from a common virtual base class that defines
a small interface, notably, returning the minimum and maximum
displayed value and redrawing the axis.
The mapping and painting is performed by QtCharts' axes. On
the one hand, using QtCharts turned out to be too inflexible.
On the other hand it allowed us to quickly prototype the charts.
Ultimately, we should do our own drawing of the axis.
As a testament to the inflexibility, QtCharts' axes do not
allow for repeated labels is needed for quarter-based date
charts (year, Q2, Q3, Q4, year, Q2, Q3, ...). Therefore the
code disambiguates labels by adding unicode zero-width spaces.
Wonderful.
When omitting labels due to space reasons, the histogram
axis attempts to show "preferred" labels. In the quarter
example above, it tries to show full years.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01 20:35:56 +00:00
|
|
|
private:
|
statistics: convert chart to QQuickItem
It turns out that the wrong base class was used for the chart.
QQuickWidget can only be used on desktop, not in a mobile UI.
Therefore, turn this into a QQuickItem and move the container
QQuickWidget into desktop-only code.
Currently, this code is insane: The chart is rendered onto a
QGraphicsScene (as it was before), which is then rendered into
a QImage, which is transformed into a QSGTexture, which is then
projected onto the device. This is performed on every mouse
move event, since these events in general change the position
of the info-box.
The plan is to slowly convert elements such as the info-box into
QQuickItems. Browsing the QtQuick documentation, this will
not be much fun.
Also note that the rendering currently tears, flickers and has
antialiasing artifacts, most likely owing to integer (QImage)
to floating point (QGraphicsScene, QQuickItem) conversion
problems. The data flow is
QGraphicsScene (float) -> QImage (int) -> QQuickItem (float).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-07 13:38:37 +00:00
|
|
|
std::vector<QString> labelsText;
|
2021-01-04 16:16:13 +00:00
|
|
|
void updateLabels();
|
2021-01-11 11:59:17 +00:00
|
|
|
std::pair<QString, QString> getFirstLastLabel() const override;
|
statistics: implement axes
Implement five kinds of axes:
- ValueAxis: a standard axis for plotting numerical linear data.
- CountAxis: a ValueAxis for plotting counts of dives.
- CategoryAxis: an axis for plotting discrete variables without
any notion of distance.
- HistogramAxis: an axis for plotting bins with a numeric value.
- DateAxis: a HistogramAxis that formats dates.
The axes derive from a common virtual base class that defines
a small interface, notably, returning the minimum and maximum
displayed value and redrawing the axis.
The mapping and painting is performed by QtCharts' axes. On
the one hand, using QtCharts turned out to be too inflexible.
On the other hand it allowed us to quickly prototype the charts.
Ultimately, we should do our own drawing of the axis.
As a testament to the inflexibility, QtCharts' axes do not
allow for repeated labels is needed for quarter-based date
charts (year, Q2, Q3, Q4, year, Q2, Q3, ...). Therefore the
code disambiguates labels by adding unicode zero-width spaces.
Wonderful.
When omitting labels due to space reasons, the histogram
axis attempts to show "preferred" labels. In the quarter
example above, it tries to show full years.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01 20:35:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct HistogramAxisEntry {
|
|
|
|
QString name;
|
|
|
|
double value;
|
|
|
|
bool recommended;
|
|
|
|
};
|
|
|
|
|
2021-01-05 11:11:46 +00:00
|
|
|
class HistogramAxis : public StatsAxis {
|
statistics: implement axes
Implement five kinds of axes:
- ValueAxis: a standard axis for plotting numerical linear data.
- CountAxis: a ValueAxis for plotting counts of dives.
- CategoryAxis: an axis for plotting discrete variables without
any notion of distance.
- HistogramAxis: an axis for plotting bins with a numeric value.
- DateAxis: a HistogramAxis that formats dates.
The axes derive from a common virtual base class that defines
a small interface, notably, returning the minimum and maximum
displayed value and redrawing the axis.
The mapping and painting is performed by QtCharts' axes. On
the one hand, using QtCharts turned out to be too inflexible.
On the other hand it allowed us to quickly prototype the charts.
Ultimately, we should do our own drawing of the axis.
As a testament to the inflexibility, QtCharts' axes do not
allow for repeated labels is needed for quarter-based date
charts (year, Q2, Q3, Q4, year, Q2, Q3, ...). Therefore the
code disambiguates labels by adding unicode zero-width spaces.
Wonderful.
When omitting labels due to space reasons, the histogram
axis attempts to show "preferred" labels. In the quarter
example above, it tries to show full years.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01 20:35:56 +00:00
|
|
|
public:
|
2021-01-14 22:22:24 +00:00
|
|
|
HistogramAxis(StatsView &view, const QString &title, std::vector<HistogramAxisEntry> bin_values, bool horizontal);
|
statistics: implement axes
Implement five kinds of axes:
- ValueAxis: a standard axis for plotting numerical linear data.
- CountAxis: a ValueAxis for plotting counts of dives.
- CategoryAxis: an axis for plotting discrete variables without
any notion of distance.
- HistogramAxis: an axis for plotting bins with a numeric value.
- DateAxis: a HistogramAxis that formats dates.
The axes derive from a common virtual base class that defines
a small interface, notably, returning the minimum and maximum
displayed value and redrawing the axis.
The mapping and painting is performed by QtCharts' axes. On
the one hand, using QtCharts turned out to be too inflexible.
On the other hand it allowed us to quickly prototype the charts.
Ultimately, we should do our own drawing of the axis.
As a testament to the inflexibility, QtCharts' axes do not
allow for repeated labels is needed for quarter-based date
charts (year, Q2, Q3, Q4, year, Q2, Q3, ...). Therefore the
code disambiguates labels by adding unicode zero-width spaces.
Wonderful.
When omitting labels due to space reasons, the histogram
axis attempts to show "preferred" labels. In the quarter
example above, it tries to show full years.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01 20:35:56 +00:00
|
|
|
private:
|
2021-01-04 16:16:13 +00:00
|
|
|
void updateLabels() override;
|
2021-01-11 11:59:17 +00:00
|
|
|
std::pair<QString, QString> getFirstLastLabel() const override;
|
statistics: implement axes
Implement five kinds of axes:
- ValueAxis: a standard axis for plotting numerical linear data.
- CountAxis: a ValueAxis for plotting counts of dives.
- CategoryAxis: an axis for plotting discrete variables without
any notion of distance.
- HistogramAxis: an axis for plotting bins with a numeric value.
- DateAxis: a HistogramAxis that formats dates.
The axes derive from a common virtual base class that defines
a small interface, notably, returning the minimum and maximum
displayed value and redrawing the axis.
The mapping and painting is performed by QtCharts' axes. On
the one hand, using QtCharts turned out to be too inflexible.
On the other hand it allowed us to quickly prototype the charts.
Ultimately, we should do our own drawing of the axis.
As a testament to the inflexibility, QtCharts' axes do not
allow for repeated labels is needed for quarter-based date
charts (year, Q2, Q3, Q4, year, Q2, Q3, ...). Therefore the
code disambiguates labels by adding unicode zero-width spaces.
Wonderful.
When omitting labels due to space reasons, the histogram
axis attempts to show "preferred" labels. In the quarter
example above, it tries to show full years.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01 20:35:56 +00:00
|
|
|
std::vector<HistogramAxisEntry> bin_values;
|
|
|
|
int preferred_step;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DateAxis : public HistogramAxis {
|
|
|
|
public:
|
2021-01-14 22:22:24 +00:00
|
|
|
DateAxis(StatsView &view, const QString &title, double from, double to, bool horizontal);
|
statistics: implement axes
Implement five kinds of axes:
- ValueAxis: a standard axis for plotting numerical linear data.
- CountAxis: a ValueAxis for plotting counts of dives.
- CategoryAxis: an axis for plotting discrete variables without
any notion of distance.
- HistogramAxis: an axis for plotting bins with a numeric value.
- DateAxis: a HistogramAxis that formats dates.
The axes derive from a common virtual base class that defines
a small interface, notably, returning the minimum and maximum
displayed value and redrawing the axis.
The mapping and painting is performed by QtCharts' axes. On
the one hand, using QtCharts turned out to be too inflexible.
On the other hand it allowed us to quickly prototype the charts.
Ultimately, we should do our own drawing of the axis.
As a testament to the inflexibility, QtCharts' axes do not
allow for repeated labels is needed for quarter-based date
charts (year, Q2, Q3, Q4, year, Q2, Q3, ...). Therefore the
code disambiguates labels by adding unicode zero-width spaces.
Wonderful.
When omitting labels due to space reasons, the histogram
axis attempts to show "preferred" labels. In the quarter
example above, it tries to show full years.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01 20:35:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|