Hermes2D  3.0
graph.h
1 // This file is part of Hermes2D.
2 //
3 // Hermes2D is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // Hermes2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Hermes2D. If not, see <http://www.gnu.org/licenses/>.
15 
16 #ifndef __H2D_GRAPH_H
17 #define __H2D_GRAPH_H
18 
19 #include "global.h"
20 namespace Hermes
21 {
22  namespace Hermes2D
23  {
32  class HERMES_API Graph : public Hermes::Mixins::Loggable
33  {
34  public:
35 
36  Graph(const char* title = nullptr, const char* x_axis_name = nullptr, const char* y_axis_name = nullptr);
37 
38  void set_captions(const char* title = nullptr, const char* x_axis_name = nullptr, const char* y_axis_name = nullptr);
39 
40  void set_log_x(bool log = true);
41  void set_log_y(bool log = true);
42 
43  void show_legend(bool show = true);
44  void show_grid(bool show = true);
45 
46  int add_row(const char* name = nullptr, const char* color = "k", const char* line = "-", const char* marker = "");
47  void set_row_style(int row, const char* color = "k", const char* line = "-", const char* marker = "");
48 
49  void add_values(int row, double x, double y);
50  // same as previous but uses row = 0
51  void add_values(double x, double y);
52  void add_values(int row, int n, double* x, double* y);
53  void add_values(int row, int n, double2* xy);
54 
55  virtual void save(const char* filename) = 0;
56  void save_numbered(const char* filename, int number);
57 
58  protected:
59 
60  std::string title, xname, yname;
61  bool logx, logy, legend, grid;
62 
63  struct Values
64  {
65  double x, y;
66  };
67 
68  struct Row
69  {
70  std::string name, color, line, marker;
71  std::vector<Values> data;
72  };
73 
74  std::vector<Row> rows;
75  };
76 
79  class HERMES_API SimpleGraph : public Graph
80  {
81  public:
82 
83  SimpleGraph(const char* title = nullptr, const char* x_axis_name = nullptr, const char* y_axis_name = nullptr)
84  : Graph(title, x_axis_name, y_axis_name) {}
85 
86  virtual void save(const char* filename);
87  };
88 
91  class HERMES_API MatlabGraph : public Graph
92  {
93  public:
94 
95  MatlabGraph(const char* title = nullptr, const char* x_axis_name = nullptr, const char* y_axis_name = nullptr)
96  : Graph(title, x_axis_name, y_axis_name) {}
97 
98  virtual void save(const char* filename);
99  };
100 
103 
104  static const char* default_terminal = "set terminal postscript eps enhanced\n";
105 
106  class HERMES_API GnuplotGraph : public Graph
107  {
108  public:
109 
110  GnuplotGraph(const char* title = nullptr, const char* x_axis_name = nullptr, const
111  char* y_axis_name = nullptr, double lines_width = 1.0, const
112  std::string& terminal_str = default_terminal) :
113  Graph(title, x_axis_name, y_axis_name),
114  legend_pos(),
115  terminal_str(terminal_str),
116  lw(lines_width) {
117  }
118 
119  virtual void save(const char* filename);
120 
123  void set_legend_pos(const char* posspec);
124 
125  protected:
130 
134 
137  double lw;
138  };
139 
142  class HERMES_API PNGGraph : public GnuplotGraph
143  {
144  public:
145 
146  PNGGraph(const char* title = nullptr, const char* x_axis_name = nullptr, const char* y_axis_name = nullptr,
147  double lines_width = 1.0, double plot_width = 800, double plot_height = 600);
148  };
149  }
150 }
151 #endif
Definition: adapt.h:24
Common definitions for Hermes2D.
::xsd::cxx::tree::name< char, token > name
C++ type corresponding to the Name XML Schema built-in type.
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.