mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
statistics: consider overhang of horizontal axes
The old code didn't consider that labels can peak out of horizontal axes if labels are under ticks. This commit takes this into account. However, it must be noted that this is only heuristics: Before setting the size of the axes, the actual minimum and maximum label are not known, because we round to "nice" numbers. But the size of the axis can only be set after knowing the overhang, leading to a circular dependency. Therefore, the code currently simply uses the minimum and maximum value of the data, hoping that the "nice" values will not format to something significantly larger. We could do a multi-pass scheme, but let's not for now. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
0ff1145fd8
commit
bdecd98ef5
3 changed files with 63 additions and 11 deletions
|
|
@ -16,6 +16,7 @@ public:
|
|||
// Returns minimum and maximum of shown range, not of data points.
|
||||
std::pair<double, double> minMax() const;
|
||||
std::pair<double, double> minMaxScreen() const; // minimum and maximum in screen coordinates
|
||||
std::pair<double, double> horizontalOverhang() const; // space that labels peak out in horizontal axes
|
||||
|
||||
double width() const; // Only supported by vertical axes. Only valid after setSize().
|
||||
double height() const; // Only supported for horizontal axes. Always valid.
|
||||
|
|
@ -39,6 +40,7 @@ protected:
|
|||
std::vector<Label> labels;
|
||||
void addLabel(const QString &label, double pos);
|
||||
virtual void updateLabels() = 0;
|
||||
virtual std::pair<QString, QString> getFirstLastLabel() const = 0;
|
||||
|
||||
struct Tick {
|
||||
std::unique_ptr<QGraphicsLineItem> item;
|
||||
|
|
@ -69,6 +71,7 @@ private:
|
|||
double min, max;
|
||||
int decimals;
|
||||
void updateLabels() override;
|
||||
std::pair<QString, QString> getFirstLastLabel() const override;
|
||||
};
|
||||
|
||||
class CountAxis : public ValueAxis {
|
||||
|
|
@ -77,6 +80,7 @@ public:
|
|||
private:
|
||||
int count;
|
||||
void updateLabels() override;
|
||||
std::pair<QString, QString> getFirstLastLabel() const override;
|
||||
};
|
||||
|
||||
class CategoryAxis : public StatsAxis {
|
||||
|
|
@ -85,6 +89,7 @@ public:
|
|||
private:
|
||||
std::vector<QString> labelsText;
|
||||
void updateLabels();
|
||||
std::pair<QString, QString> getFirstLastLabel() const override;
|
||||
};
|
||||
|
||||
struct HistogramAxisEntry {
|
||||
|
|
@ -98,6 +103,7 @@ public:
|
|||
HistogramAxis(const QString &title, std::vector<HistogramAxisEntry> bin_values, bool horizontal);
|
||||
private:
|
||||
void updateLabels() override;
|
||||
std::pair<QString, QString> getFirstLastLabel() const override;
|
||||
std::vector<HistogramAxisEntry> bin_values;
|
||||
int preferred_step;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue