diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-01-05 13:04:53 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-01-06 12:31:22 -0800 |
commit | 8dfa3f6db3eda8bce432afb7407efe2d8822ebbd (patch) | |
tree | 2a1c6f629fc161c33da6e7515c42fad138a0d6de /stats/statsaxis.h | |
parent | 4ab9f1c6b06204285267e79b5ed993514e0213e2 (diff) | |
download | subsurface-8dfa3f6db3eda8bce432afb7407efe2d8822ebbd.tar.gz |
statistics: draw title of axes
Easy enough to implement, but one weirdness:
To get the height of the rotated text, one has to access the
width() member of the boundingRect. I'm not sure if that makes
sense, but so be it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'stats/statsaxis.h')
-rw-r--r-- | stats/statsaxis.h | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/stats/statsaxis.h b/stats/statsaxis.h index c9619a124..c25ffe692 100644 --- a/stats/statsaxis.h +++ b/stats/statsaxis.h @@ -31,7 +31,7 @@ public: double toScreen(double) const; double toValue(double) const; protected: - StatsAxis(QtCharts::QChart *chart, bool horizontal, bool labelsBetweenTicks); + StatsAxis(QtCharts::QChart *chart, const QString &title, bool horizontal, bool labelsBetweenTicks); QtCharts::QChart *chart; struct Label { @@ -56,14 +56,18 @@ protected: bool labelsBetweenTicks; // When labels are between ticks, they can be moved closer to the axis QFont labelFont, titleFont; + std::unique_ptr<QGraphicsSimpleTextItem> title; double size; // width for horizontal, height for vertical double zeroOnScreen; double min, max; + double labelWidth; // Maximum width of labels +private: + double titleSpace() const; // Space needed for title }; class ValueAxis : public StatsAxis { public: - ValueAxis(QtCharts::QChart *chart, double min, double max, int decimals, bool horizontal); + ValueAxis(QtCharts::QChart *chart, const QString &title, double min, double max, int decimals, bool horizontal); private: double min, max; int decimals; @@ -72,7 +76,7 @@ private: class CountAxis : public ValueAxis { public: - CountAxis(QtCharts::QChart *chart, int count, bool horizontal); + CountAxis(QtCharts::QChart *chart, const QString &title, int count, bool horizontal); private: int count; void updateLabels() override; @@ -80,7 +84,7 @@ private: class CategoryAxis : public StatsAxis { public: - CategoryAxis(QtCharts::QChart *chart, const std::vector<QString> &labels, bool horizontal); + CategoryAxis(QtCharts::QChart *chart, const QString &title, const std::vector<QString> &labels, bool horizontal); private: void updateLabels(); }; @@ -93,7 +97,7 @@ struct HistogramAxisEntry { class HistogramAxis : public StatsAxis { public: - HistogramAxis(QtCharts::QChart *chart, std::vector<HistogramAxisEntry> bin_values, bool horizontal); + HistogramAxis(QtCharts::QChart *chart, const QString &title, std::vector<HistogramAxisEntry> bin_values, bool horizontal); private: void updateLabels() override; std::vector<HistogramAxisEntry> bin_values; @@ -102,7 +106,7 @@ private: class DateAxis : public HistogramAxis { public: - DateAxis(QtCharts::QChart *chart, double from, double to, bool horizontal); + DateAxis(QtCharts::QChart *chart, const QString &title, double from, double to, bool horizontal); }; #endif |