File: verticalplotscale.h

package info (click to toggle)
aoflagger 3.4.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,960 kB
  • sloc: cpp: 83,076; python: 10,187; sh: 260; makefile: 178
file content (99 lines) | stat: -rw-r--r-- 2,918 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef VERTICAL_PLOT_SCALE_H
#define VERTICAL_PLOT_SCALE_H

#include "linkable.h"
#include "axis.h"

#include <array>
#include <string>
#include <vector>
#include <memory>

#include <gtkmm/drawingarea.h>

typedef std::pair<double, std::string> Tick;

class VerticalPlotScale : public Linkable<VerticalPlotScale> {
 public:
  VerticalPlotScale();
  ~VerticalPlotScale();

  void SetPlotDimensions(double plotWidth, double plotHeight, double fromTop,
                         bool isSecondAxis) {
    _plotWidth = plotWidth;
    _plotHeight = plotHeight;
    _fromTop = fromTop;
    _isSecondAxis = isSecondAxis;
    _metricsAreInitialized = false;
  }

  void AlignTo(VerticalPlotScale& base) {
    _alignTo = &base;
    _metricsAreInitialized = false;
  }

  double GetWidth(const Cairo::RefPtr<Cairo::Context>& cairo) {
    initializeMetrics(cairo);
    return _width;
  }

  double GetTickTextHeight(const Cairo::RefPtr<Cairo::Context>& cairo);

  void SetDrawWithDescription(bool drawWithDescription) {
    _drawWithDescription = drawWithDescription;
    _metricsAreInitialized = false;
  }
  void SetUnitsCaption(const std::string& caption) {
    _unitsCaption = caption;
    _metricsAreInitialized = false;
  }
  void SetDescriptionFontSize(double fontSize) {
    _tickValuesFontSize = fontSize;
    _metricsAreInitialized = false;
  }
  void SetTickValuesFontSize(double fontSize) {
    _tickValuesFontSize = fontSize;
    _metricsAreInitialized = false;
  }

  void Draw(const Cairo::RefPtr<Cairo::Context>& cairo, double offsetX,
            double offsetY);
  void SetAxisType(AxisType axisType) { _axisType = axisType; }
  void SetTickRange(double min, double max) {
    _tickRange = std::array<double, 2>{min, max};
  }
  double GetTickRangeMin() const { return _tickRange[0]; }
  double GetTickRangeMax() const { return _tickRange[1]; }
  void SetLogarithmic(bool logarithmic) { _isLogarithmic = logarithmic; }
  bool IsLogarithmic() const { return _isLogarithmic; }
  void InitializeTicks();
  double UnitToAxis(double unitValue) const;
  double AxisToUnit(double axisValue) const;

 private:
  void drawDescription(const Cairo::RefPtr<Cairo::Context>& cairo,
                       double offsetX, double offsetY);
  bool ticksFit(const Cairo::RefPtr<Cairo::Context>& cairo);
  void initializeMetrics(const Cairo::RefPtr<Cairo::Context>& cairo);
  double getTickYPosition(const Tick& tick);

  // These are set through SetPlotDimensions()
  double _plotWidth, _plotHeight, _fromTop;
  bool _isSecondAxis;

  // These are calculated by initializeMetrics()
  double _width, _captionSize;

  bool _metricsAreInitialized;
  VerticalPlotScale* _alignTo;
  std::unique_ptr<class TickSet> _tickSet;
  AxisType _axisType;
  std::array<double, 2> _tickRange;
  bool _isLogarithmic;
  bool _drawWithDescription;
  std::string _unitsCaption;
  double _descriptionFontSize;
  double _tickValuesFontSize;
};

#endif