File: plot.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 (134 lines) | stat: -rw-r--r-- 3,905 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#ifndef PLOT_H
#define PLOT_H

#include <unistd.h>

#include <stdexcept>
#include <string>
#include <vector>

class Plot {
 public:
  //[[ deprecated("Superceded by plot2d class") ]]
  explicit Plot(const std::string& pdfFile);
  ~Plot();
  void StartLine() { StartLine(""); }
  void StartLine(const std::string& lineTitle);
  void StartScatter() { StartScatter(""); }
  void StartScatter(const std::string& lineTitle);
  void StartBoxes() { StartScatter(""); }
  void StartBoxes(const std::string& lineTitle);
  void StartGrid() { StartGrid(""); }
  void StartGrid(const std::string& gridTitle);
  void PushDataPoint(long double x, long double y);
  void PushDataPoint(long double x, long double y, long double z);
  void PushUnknownDataPoint(long double x, long double y);
  void PushDataBlockEnd();
  void Close();
  void AddRectangle(long double x1, double y1, double x2, double y2);
  void SetTitle(const std::string& title) throw() { _title = title; }
  void SetXAxisText(const std::string& text) throw() { _xAxisText = text; }
  void SetYAxisText(const std::string& text) throw() { _yAxisText = text; }
  void SetZAxisText(const std::string& text) throw() { _zAxisText = text; }
  void SetXRange(long double min, long double max) throw() {
    _xRangeHasMin = true;
    _xRangeHasMax = true;
    _xRangeMin = min;
    _xRangeMax = max;
  }
  void SetXRangeAutoMax(long double min) throw() {
    _xRangeHasMin = true;
    _xRangeHasMax = false;
    _xRangeMin = min;
  }
  void SetXRangeAutoMin(long double max) throw() {
    _xRangeHasMin = false;
    _xRangeHasMax = true;
    _xRangeMax = max;
  }
  void SetXRangeAuto() throw() {
    _xRangeHasMin = false;
    _xRangeHasMax = false;
  }
  void SetYRange(long double min, long double max) throw() {
    if (_yRangeHasMin) {
      if (min < _yRangeMin) _yRangeMin = min;
    } else {
      _yRangeHasMin = true;
      _yRangeMin = min;
    }
    if (_yRangeHasMax) {
      if (max > _yRangeMax) _yRangeMax = max;
    } else {
      _yRangeHasMax = true;
      _yRangeMax = max;
    }
  }
  void SetYRangeAutoMax(long double min) throw() {
    _yRangeHasMin = true;
    _yRangeHasMax = false;
    _yRangeMin = min;
  }
  void SetYRangeAutoMin(long double max) throw() {
    _yRangeHasMin = false;
    _yRangeHasMax = true;
    _yRangeMax = max;
  }
  void SetYRangeAuto() throw() {
    _yRangeHasMin = false;
    _yRangeHasMax = false;
  }
  void SetZRange(long double min, long double max) throw() {
    _zRangeHasMin = true;
    _zRangeHasMax = true;
    _zRangeMin = min;
    _zRangeMax = max;
  }
  void SetCBRange(long double min, long double max) throw() {
    _cbRangeHasMin = true;
    _cbRangeHasMax = true;
    _cbRangeMin = min;
    _cbRangeMax = max;
  }
  void SetLogScale(bool x, bool y, bool z = false) {
    _logX = x;
    _logY = y;
    _logZ = z;
  }
  void SetFontSize(size_t newSize) { _fontSize = newSize; }
  void Show();

 private:
  enum Type { Line, Scatter, Boxes, Grid } _curType;
  void RunGnuplot();
  char _tmpPlotFile[16];
  void Write(int fd, const std::string& str) {
    if (write(fd, str.c_str(), str.length()) != (int)str.length())
      throw std::runtime_error("write() reported an error");
  }
  void CloseCurFd();
  void ExecuteCmd(const std::string& cmd) const;
  std::vector<std::string> _lineFiles, _lineTitles;
  std::vector<Type> _lineTypes;

  int _curLineFd;
  const std::string _pdfFile;
  bool _open;
  std::string _title, _xAxisText, _yAxisText, _zAxisText;
  bool _xRangeHasMin, _xRangeHasMax;
  bool _yRangeHasMin, _yRangeHasMax;
  bool _zRangeHasMin, _zRangeHasMax;
  bool _cbRangeHasMin, _cbRangeHasMax;
  long double _xRangeMin, _xRangeMax;
  long double _yRangeMin, _yRangeMax;
  long double _zRangeMin, _zRangeMax;
  long double _cbRangeMin, _cbRangeMax;
  bool _clipZ;
  std::vector<std::string> _extraHeaders;

  bool _logX, _logY, _logZ;
  bool _hasBoxes;
  size_t _fontSize;
};

#endif