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-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>
|
|
|
|
#include <QBarCategoryAxis>
|
|
|
|
#include <QCategoryAxis>
|
2021-01-05 11:11:46 +00:00
|
|
|
#include <QFont>
|
|
|
|
#include <QGraphicsSimpleTextItem>
|
|
|
|
#include <QGraphicsLineItem>
|
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 <QValueAxis>
|
|
|
|
|
|
|
|
namespace QtCharts {
|
|
|
|
class QChart;
|
|
|
|
}
|
|
|
|
|
2021-01-05 11:11:46 +00:00
|
|
|
class StatsAxis : QGraphicsLineItem {
|
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;
|
|
|
|
|
|
|
|
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;
|
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-05 11:11:46 +00:00
|
|
|
StatsAxis(QtCharts::QChart *chart, bool horizontal, bool labelsBetweenTicks);
|
2021-01-04 16:16:13 +00:00
|
|
|
QtCharts::QChart *chart;
|
2021-01-05 11:11:46 +00:00
|
|
|
|
|
|
|
struct Label {
|
|
|
|
std::unique_ptr<QGraphicsSimpleTextItem> label;
|
|
|
|
double pos;
|
|
|
|
Label(const QString &name, double pos, QtCharts::QChart *chart, const QFont &font);
|
|
|
|
};
|
|
|
|
std::vector<Label> labels;
|
|
|
|
void addLabel(const QString &label, double pos);
|
|
|
|
virtual void updateLabels() = 0;
|
|
|
|
|
|
|
|
struct Tick {
|
|
|
|
std::unique_ptr<QGraphicsLineItem> item;
|
|
|
|
double pos;
|
|
|
|
Tick(double pos, QtCharts::QChart *chart);
|
|
|
|
};
|
|
|
|
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;
|
|
|
|
double min, max;
|
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-04 16:16:13 +00:00
|
|
|
ValueAxis(QtCharts::QChart *chart, 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;
|
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-04 16:16:13 +00:00
|
|
|
CountAxis(QtCharts::QChart *chart, 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;
|
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-04 16:16:13 +00:00
|
|
|
CategoryAxis(QtCharts::QChart *chart, 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:
|
2021-01-04 16:16:13 +00:00
|
|
|
void updateLabels();
|
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-04 16:16:13 +00:00
|
|
|
HistogramAxis(QtCharts::QChart *chart, 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;
|
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-04 16:16:13 +00:00
|
|
|
DateAxis(QtCharts::QChart *chart, 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
|