frame.hpp
Go to the documentation of this file.
1 
5 /* Copyright (c) 2005-2011 Taneli Kalvas. All rights reserved.
6  *
7  * You can redistribute this software and/or modify it under the terms
8  * of the GNU General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this library (file "COPYING" included in the package);
19  * if not, write to the Free Software Foundation, Inc., 51 Franklin
20  * Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * If you have questions about your rights to use or distribute this
23  * software, please contact Berkeley Lab's Technology Transfer
24  * Department at TTD@lbl.gov. Other questions, comments and bug
25  * reports should be sent directly to the author via email at
26  * taneli.kalvas@jyu.fi.
27  *
28  * NOTICE. This software was developed under partial funding from the
29  * U.S. Department of Energy. As such, the U.S. Government has been
30  * granted for itself and others acting on its behalf a paid-up,
31  * nonexclusive, irrevocable, worldwide license in the Software to
32  * reproduce, prepare derivative works, and perform publicly and
33  * display publicly. Beginning five (5) years after the date
34  * permission to assert copyright is obtained from the U.S. Department
35  * of Energy, and subject to any subsequent five (5) year renewals,
36  * the U.S. Government is granted for itself and others acting on its
37  * behalf a paid-up, nonexclusive, irrevocable, worldwide license in
38  * the Software to reproduce, prepare derivative works, distribute
39  * copies to the public, perform publicly and display publicly, and to
40  * permit others to do so.
41  */
42 
43 #ifndef FRAME_HPP
44 #define FRAME_HPP 1
45 
46 
47 #include <string>
48 #include <vector>
49 #include <cairo.h>
50 #include "color.hpp"
51 #include "ruler.hpp"
52 #include "coordmapper.hpp"
53 #include "graph.hpp"
54 #include "legend.hpp"
55 
56 
57 
71 };
72 
73 
81 enum PlotAxis {
87 };
88 
89 
90 
107 class Frame {
108 
111  struct DObj {
112  PlotAxis _xaxis;
113  PlotAxis _yaxis;
114  Graph *_graph;
116  DObj( PlotAxis xaxis, PlotAxis yaxis, Graph *graph )
117  : _xaxis(xaxis), _yaxis(yaxis), _graph(graph) {}
118  };
119 
120  Ruler _ruler[4];
121  Coordmapper1D _cm[4];
122  bool _enable[4];
123  bool _fenable[4];
124  bool _autorange[8];
125  double _range_min[4];
126  double _range_max[4];
128  int _offx;
129  int _offy;
131  int _width;
132  int _height;
134  double _fontsize;
135  double _titlespace;
136  Color _bg;
137  Color _fg;
139  std::vector<DObj> _dobj;
141  bool _legend_enable;
142  legend_position_e _legend_pos;
143  MultiEntryLegend _legend;
145  Label _title;
147  PlotFixedMode _fixedaspect;
149  bool _automargin;
150  double _tmargin[4];
158  void draw_legend( cairo_t *cairo );
159  void calculate_autoranging( void );
160  void calculate_ruler_autoenable( void );
161  void calculate_rulers( cairo_t *cairo, bool ruler_tic_bbox_test );
162  void calculate_frame( cairo_t *cairo );
163  void draw_frame( cairo_t *cairo );
164  void mirror_rulers( void );
165  void set_frame_clipping( cairo_t *cairo );
166  void unset_frame_clipping( cairo_t *cairo );
167 
168 public:
169 
172  Frame();
173 
176  ~Frame() {}
177 
185  void set_geometry( int width, int height, int offx, int offy ) {
186  _width = width;
187  _height = height;
188  _offx = offx;
189  _offy = offy;
190  }
191 
194  void set_font_size( double size );
195 
198  double get_font_size( void ) {
199  return( _fontsize );
200  }
201 
204  void set_background( Color &bg ) {
205  _bg = bg;
206  }
207 
210  void set_foreground( Color &fg ) {
211  _fg = fg;
212  }
213 
219  Coordmapper get_coordmapper( PlotAxis xaxis, PlotAxis yaxis ) const;
220 
223  void get_margins( double margin[4] ) const;
224 
230  void get_frame_edges( double edge[4] ) const;
231 
234  void set_title( const std::string &title );
235 
238  void set_axis_label( PlotAxis axis, const std::string &label );
239 
246  void force_enable_ruler( PlotAxis axis, bool force );
247 
254  void ruler_autorange_enable( PlotAxis axis, bool min, bool max );
255 
262  void set_ranges( PlotAxis axis, double min, double max );
263 
269  void get_ranges( PlotAxis axis, double &min, double &max ) const;
270 
282  void set_fixed_aspect( PlotFixedMode mode );
283 
296  void set_automargin( bool enable );
297 
306  void add_graph( PlotAxis xaxis, PlotAxis yaxis,
307  Graph *graph, LegendEntry *legend = NULL );
308 
314  void clear_graphs( void );
315 
318  void enable_legend( bool enable );
319 
323 
337  void draw( cairo_t *cairo );
338 };
339 
340 
341 #endif
342 
void draw(cairo_t *cairo)
Draw frame and plot contents.
void set_automargin(bool enable)
Set automatic margin setting on or off.
Linear 1D coordinate mapper.
Definition: coordmapper.hpp:57
void get_margins(double margin[4]) const
Get margins.
PlotAxis
Axis specification for plots.
Definition: frame.hpp:81
void set_background(Color &bg)
Set background color.
Definition: frame.hpp:204
Definition: frame.hpp:69
Abstract base class for drawable plots.
Definition: graph.hpp:56
Rulers for plot frames.
void get_ranges(PlotAxis axis, double &min, double &max) const
Get coordinate ranges for axis.
Base for plottable graphs.
void set_geometry(int width, int height, int offx, int offy)
Set size of plot.
Definition: frame.hpp:185
Definition: frame.hpp:82
1D and 2D coordinate transformations for plotter.
Definition: frame.hpp:70
Definition: frame.hpp:85
void set_ranges(PlotAxis axis, double min, double max)
Set coordinate ranges for axis.
Colors for plotting.
void clear_graphs(void)
Clear all graphs from frame.
PlotFixedMode
Fixed aspect ratio setting for frame.
Definition: frame.hpp:67
Definition: frame.hpp:84
Class for labels in plots.
Definition: label.hpp:57
Definition: frame.hpp:68
double get_font_size(void)
Get font size used for tics and labels.
Definition: frame.hpp:198
void set_axis_label(PlotAxis axis, const std::string &label)
Set axis label.
Definition: frame.hpp:86
Frame()
Default constructor.
Definition: frame.hpp:83
Class for coordinate axis ruler.
Definition: ruler.hpp:62
Linear-linear 2D coordinate mapper.
Definition: coordmapper.hpp:119
void add_graph(PlotAxis xaxis, PlotAxis yaxis, Graph *graph, LegendEntry *legend=NULL)
Add graph to frame.
Coordmapper get_coordmapper(PlotAxis xaxis, PlotAxis yaxis) const
Get a 2d coordinate mapper for selected axes.
void set_title(const std::string &title)
Set title for plot.
Plot legends.
Class for legend entry.
Definition: legend.hpp:93
void get_frame_edges(double edge[4]) const
Get frame edge locations.
void set_fixed_aspect(PlotFixedMode mode)
Set fixed aspect ratio mode.
void force_enable_ruler(PlotAxis axis, bool force)
Force enable ruler for axis.
void set_foreground(Color &fg)
Set foreground color.
Definition: frame.hpp:210
legend_position_e
Legend position.
Definition: legend.hpp:58
void set_legend_position(legend_position_e pos)
Set legend position.
General purpose plotter frame for cairographics surfaces.
Definition: frame.hpp:107
Color class for plotting.
Definition: color.hpp:53
~Frame()
Destructor.
Definition: frame.hpp:176
void ruler_autorange_enable(PlotAxis axis, bool min, bool max)
Enable/disable ruler autorange.
void enable_legend(bool enable)
Set legend enable/disable.
void set_font_size(double size)
Set font size used for tics and labels.
Legend for presenting plot styles.
Definition: legend.hpp:175