// SPDX-License-Identifier: GPL-2.0 // Supported chart axes #ifndef STATS_AXIS_H #define STATS_AXIS_H #include #include #include #include namespace QtCharts { class QChart; } class StatsAxis { public: virtual ~StatsAxis(); virtual void updateLabels(const QtCharts::QChart *chart) = 0; virtual QtCharts::QAbstractAxis *qaxis() = 0; // Returns minimum and maximum of shown range, not of data points. virtual std::pair minMax() const; protected: StatsAxis(bool horizontal); int guessNumTicks(const QtCharts::QChart *chart, const QtCharts::QAbstractAxis *axis, const std::vector &strings) const; bool horizontal; }; // Small template that derives from a QChart-axis and defines // the corresponding virtual axis() accessor. template class StatsAxisTemplate : public StatsAxis, public QAxis { using StatsAxis::StatsAxis; QtCharts::QAbstractAxis *qaxis() override final { return this; } }; class ValueAxis : public StatsAxisTemplate { public: ValueAxis(double min, double max, int decimals, bool horizontal); private: double min, max; int decimals; void updateLabels(const QtCharts::QChart *chart) override; std::pair minMax() const override; }; class CountAxis : public ValueAxis { public: CountAxis(int count, bool horizontal); private: int count; void updateLabels(const QtCharts::QChart *chart) override; }; class CategoryAxis : public StatsAxisTemplate { public: CategoryAxis(const std::vector &labels, bool horizontal); private: void updateLabels(const QtCharts::QChart *chart); }; struct HistogramAxisEntry { QString name; double value; bool recommended; }; class HistogramAxis : public StatsAxisTemplate { public: HistogramAxis(std::vector bin_values, bool horizontal); private: void updateLabels(const QtCharts::QChart *chart) override; std::pair minMax() const override; std::vector bin_values; int preferred_step; }; class DateAxis : public HistogramAxis { public: DateAxis(double from, double to, bool horizontal); }; #endif