forked from alandefreitas/matplotplusplus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgnuplot.h
140 lines (121 loc) · 5.87 KB
/
gnuplot.h
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
135
136
137
138
139
140
//
// Created by Alan Freitas on 26/08/20.
//
#ifndef MATPLOTPLUSPLUS_BACKEND_GNUPLOT_H
#define MATPLOTPLUSPLUS_BACKEND_GNUPLOT_H
#include <array>
#include <chrono>
#include <matplot/backend/backend_interface.h>
#include <tuple>
namespace matplot::backend {
class gnuplot : public backend_interface {
public:
gnuplot();
virtual ~gnuplot();
bool is_interactive() override;
const std::string &output() override;
const std::string &output_format() override;
bool output(const std::string &filename) override;
bool output(const std::string &filename,
const std::string &file_format) override;
unsigned int width() override;
unsigned int height() override;
unsigned int position_x() override;
unsigned int position_y() override;
void position_x(unsigned int new_position_x) override;
void position_y(unsigned int new_position_y) override;
void width(unsigned int new_width) override;
void height(unsigned int new_height) override;
bool new_frame() override;
bool render_data() override;
bool supports_fonts() override;
public:
bool consumes_gnuplot_commands() override;
void run_command(const std::string &command) override;
void include_comment(const std::string &comment) override;
public /* gnuplot pipe functions */:
/// We "render the data" by flushing the commands
bool flush_commands();
/// Identify the default terminal type in the system
static std::string default_terminal_type();
static bool terminal_is_available(std::string_view);
static std::tuple<int, int, int> gnuplot_version();
static bool terminal_has_title_option(const std::string &t);
static bool terminal_has_size_option(const std::string &t);
static bool terminal_has_position_option(const std::string &t);
static bool terminal_has_enhanced_option(const std::string &t);
static bool terminal_has_color_option(const std::string &t);
static bool terminal_has_font_option(const std::string &t);
public: /* gnuplot pipe constexprs */
// True if the windows persist after closing the program
// False by default because this is VERY annoying in
// some repetitive tasks involving lots of plots
// You can change the default here or run the command
// set terminal "name" persist
static constexpr bool windows_should_persist_by_default = false;
// True if we should wait at least 5 seconds after the last
// flush to close gnuplot
static constexpr bool dont_let_it_close_too_fast = false;
// True if we allow to use the mouse interactively in the window
// Most of the time, this is just annoying when we scroll without
// meaning to It is very very hard to use the mouse properly
// http://www.gnuplot.info/files/gpReadMouseTest.c
static constexpr bool allow_using_mouse = true;
#if defined(TRACE_GNUPLOT_COMMANDS) && \
!defined(MATPLOT_BUILD_FOR_DOCUMENTATION_IMAGES)
static constexpr bool trace_commands = true;
#else
static constexpr bool trace_commands = false;
#endif
static constexpr size_t pipe_capacity_worst_case = BUFSIZ;
/// File formats for figures and properties of terminals
static constexpr std::array<
std::pair<std::string_view, std::string_view>, 33>
extension_terminal() {
return std::array<std::pair<std::string_view, std::string_view>,
33>{
std::pair{".html", "canvas"}, std::pair{".cgm", "cgm"},
std::pair{".txt", "dumb"}, std::pair{".md", "dumb"},
std::pair{".dxf", "dxf"}, std::pair{".emf", "emf"},
// std::pair{".emtex", "emtex"},
std::pair{".eps", "postscript"}, std::pair{".eps", "epscairo"},
std::pair{".eps", "epslatex"}, std::pair{".gif", "gif"},
std::pair{".hpgl", "hpgl"}, std::pair{".jpeg", "jpeg"},
std::pair{".jpg", "jpeg"}, std::pair{".tex", "epslatex"},
std::pair{".mf", "mf"}, std::pair{".mp", "mp"},
std::pair{".pcl5", "pcl5"}, std::pair{".pdf", "pdf"},
std::pair{".pdf", "pdfcairo"}, std::pair{".png", "pngcairo"},
std::pair{".png", "png"}, std::pair{".tex", "pslatex"},
std::pair{".tex", "context"}, std::pair{".tex", "texdraw"},
std::pair{".tex", "tikz"},
// std::pair{".tex", "eepic"},
// std::pair{".tex", "tpic"},
std::pair{".pstex", "pstex"},
std::pair{".pstricks", "pstricks"},
// std::pair{".qms", "qms"},
std::pair{".sixel", "sixelgd"}, std::pair{".svg", "svg"},
std::pair{".tek40xx", "tek40xx"},
std::pair{".tek410x", "tek410x"},
// std::pair{".tgif", "tgif"},
std::pair{".tkcanvas", "tkcanvas"},
// std::pair{".tpic", "tpic"},
std::pair{".vttek", "vttek"}};
}
private:
// Pipe to gnuplot process
FILE *pipe_;
// How many bytes we put in the pipe
size_t bytes_in_pipe_{0};
// Current gnuplot terminal we should
std::string terminal_{"qt"};
// Position and size
std::array<unsigned, 4> position_{680, 558, 560, 420};
// Time we last flush, to avoid flushing results too fast
std::chrono::high_resolution_clock::time_point last_flush_;
// File output, if non-interactive
std::string output_{};
// Whether we should include comments in the commands
bool include_comments_ = trace_commands;
};
} // namespace matplot::backend
#endif // MATPLOTPLUSPLUS_BACKEND_GNUPLOT_H