legend.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 LEGEND_HPP
44 #define LEGEND_HPP 1
45 
46 
47 #include <vector>
48 #include <string>
49 #include "graph.hpp"
50 #include "label.hpp"
51 #include "colormap.hpp"
52 
53 
62 
66 
70 };
71 
72 
73 #define LEGEND_POS_VERTICAL_MASK 12
74 #define LEGEND_POS_HORIZONTAL_MASK 3
75 
76 #define LEGEND_POS_BOTTOM 0
77 #define LEGEND_POS_MIDDLE 4
78 #define LEGEND_POS_TOP 8
79 
80 #define LEGEND_POS_LEFT 0
81 #define LEGEND_POS_CENTER 1
82 #define LEGEND_POS_RIGHT 2
83 
84 
93 class LegendEntry {
94 
95  Graph &_graph;
96  Label _label;
98 public:
99 
102  LegendEntry( Graph &graph, const std::string &label )
103  : _graph(graph), _label(label) {}
104 
107  LegendEntry( const LegendEntry &le )
108  : _graph(le._graph), _label(le._label) {}
109 
113 
117  _graph = le._graph;
118  _label = le._label;
119  return( *this );
120  }
121 
126  void plot( cairo_t *cairo, double x, double y );
127 
130  void get_size( cairo_t *cairo, double &width, double &height ) const;
131 
134  void set_font_size( double fontsize );
135 };
136 
137 
149 class Legend {
150 
151 public:
152 
155  Legend() {}
156 
159  virtual ~Legend() {}
160 
165  virtual void plot( cairo_t *cairo, double x, double y ) = 0;
166 
169  virtual void get_size( cairo_t *cairo, double &width, double &height ) const = 0;
170 };
171 
172 
176 
177  double _fontsize;
178  std::vector<LegendEntry *> _entry;
180 public:
181 
185 
188  virtual ~MultiEntryLegend() {}
189 
194  virtual void plot( cairo_t *cairo, double x, double y );
195 
198  virtual void get_size( cairo_t *cairo, double &width, double &height ) const;
199 
202  void set_font_size( double fontsize );
203 
206  void add_entry( LegendEntry *entry );
207 
210  void clear_entries( void );
211 };
212 
213 
217 
218  double _height;
219  Colormap &_colormap;
220 
221 
222 public:
223 
226  ColormapLegend( Colormap &colormap ) : _height(0.0), _colormap(colormap) {}
227 
230  virtual ~ColormapLegend() {}
231 
236  virtual void plot( cairo_t *cairo, double x, double y );
237 
240  virtual void get_size( cairo_t *cairo, double &width, double &height ) const;
241 
244  void set_height( double height );
245 };
246 
247 
248 #endif
249 
LegendEntry(Graph &graph, const std::string &label)
Contructor for legend entry.
Definition: legend.hpp:102
Definition: legend.hpp:65
void get_size(cairo_t *cairo, double &width, double &height) const
Get size of legend entry.
Definition: legend.hpp:68
LegendEntry(const LegendEntry &le)
Copy constructor.
Definition: legend.hpp:107
Abstract base class for drawable plots.
Definition: graph.hpp:56
~LegendEntry()
Destructor.
Definition: legend.hpp:112
Definition: legend.hpp:64
Base for plottable graphs.
Plot labels.
virtual void plot(cairo_t *cairo, double x, double y)
Plot legend at (x,y).
Legend()
Default constructor for legend.
Definition: legend.hpp:155
MultiEntryLegend()
Default constructor for legend.
virtual void get_size(cairo_t *cairo, double &width, double &height) const
Get size of legend.
virtual void plot(cairo_t *cairo, double x, double y)=0
Plot legend at (x,y).
virtual ~MultiEntryLegend()
Virtual destructor.
Definition: legend.hpp:188
Definition: legend.hpp:61
void plot(cairo_t *cairo, double x, double y)
Plot legend entry at (x,y).
Class for labels in plots.
Definition: label.hpp:57
Definition: legend.hpp:67
Class for colormap type plots.
Definition: colormap.hpp:74
void set_height(double height)
Set height of legend.
virtual void plot(cairo_t *cairo, double x, double y)
Plot legend at (x,y).
void add_entry(LegendEntry *entry)
Add entry to legend.
virtual void get_size(cairo_t *cairo, double &width, double &height) const =0
Get size of legend.
Definition: legend.hpp:63
Class for legend entry.
Definition: legend.hpp:93
void set_font_size(double fontsize)
Set font size for legend labels.
virtual ~ColormapLegend()
Virtual destructor.
Definition: legend.hpp:230
Base class for legend definition.
Definition: legend.hpp:149
Colormap graph for plotting
virtual ~Legend()
Virtual destructor.
Definition: legend.hpp:159
legend_position_e
Legend position.
Definition: legend.hpp:58
virtual void get_size(cairo_t *cairo, double &width, double &height) const
Get size of legend.
Legend for presenting colormap key.
Definition: legend.hpp:216
ColormapLegend(Colormap &colormap)
Default constructor for legend.
Definition: legend.hpp:226
Definition: legend.hpp:59
LegendEntry & operator=(const LegendEntry &le)
Assignment operator.
Definition: legend.hpp:116
void clear_entries(void)
Clear legend entries.
void set_font_size(double fontsize)
Set font size for legend labels.
Definition: legend.hpp:69
Legend for presenting plot styles.
Definition: legend.hpp:175
Definition: legend.hpp:60