Menu

[487b0c]: / src / ruler.hpp  Maximize  Restore  History

Download this file

214 lines (172 with data), 7.2 kB

  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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*! \file ruler.hpp
* \brief Rulers for plot frames
*/
/* Copyright (c) 2005-2009 Taneli Kalvas. All rights reserved.
*
* You can redistribute this software and/or modify it under the terms
* of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library (file "COPYING" included in the package);
* if not, write to the Free Software Foundation, Inc., 51 Franklin
* Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* If you have questions about your rights to use or distribute this
* software, please contact Berkeley Lab's Technology Transfer
* Department at TTD@lbl.gov. Other questions, comments and bug
* reports should be sent directly to the author via email at
* taneli.kalvas@jyu.fi.
*
* NOTICE. This software was developed under partial funding from the
* U.S. Department of Energy. As such, the U.S. Government has been
* granted for itself and others acting on its behalf a paid-up,
* nonexclusive, irrevocable, worldwide license in the Software to
* reproduce, prepare derivative works, and perform publicly and
* display publicly. Beginning five (5) years after the date
* permission to assert copyright is obtained from the U.S. Department
* of Energy, and subject to any subsequent five (5) year renewals,
* the U.S. Government is granted for itself and others acting on its
* behalf a paid-up, nonexclusive, irrevocable, worldwide license in
* the Software to reproduce, prepare derivative works, distribute
* copies to the public, perform publicly and display publicly, and to
* permit others to do so.
*/
#ifndef RULER_HPP
#define RULER_HPP 1
#include <cairo.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <iostream>
#include "color.hpp"
#include "label.hpp"
#include "coordmapper.hpp"
/*! \brief Class for coordinate axis ruler.
*
* Ruler is a class for drawing coordinate axis for frame or palette
* colormap legend for example.
*/
class Ruler {
/*! \brief One coordinate tic with label and location.
*/
struct Tic {
double _x; /*!< \brief Tic coordinate. */
Label _label; /*!< \brief Tic label. */
/*! \brief Constructor for coordinate tic.
*/
Tic( double x, const std::string &label ) : _x(x), _label(label) {}
};
Color _color; /*!< \brief Ruler color. */
double _ticlen_in; /*!< \brief Tic length in. */
double _ticlen_out; /*!< \brief Tic length out. */
double _labelspace; /*!< \brief Space from tic to ticlabel. */
double _range[2]; /*!< \brief Coordinate range. */
bool _autorange[2]; /*!< \brief Autorange enable. */
double _endpt[4]; /*!< \brief Ruler endpoints (x1,y1,x2,y2). */
double _fontsize; /*!< \brief Ruler font size. */
Label _axislabel; /*!< \brief Ruler axislabel. */
bool _label_enabled;
bool _indir; /*!< \brief In direction. True for x1 and y2 axes. */
std::vector<Tic> _tic; /*!< \brief Tics. */
int _cind; /*!< \brief Coordinate index, 0 or 1. */
static bool tic_labels_bbox_crash_x( const double bbox[4], const double obbox[4] );
static bool tic_labels_bbox_crash_y( const double bbox[4], const double obbox[4] );
bool add_tic( double x, cairo_t *cairo, const Coordmapper1D &cm,
bool ruler_tic_bbox_test, double &maxsize, double obbox[4] );
public:
/*! \brief Default contructor.
*/
Ruler();
/*! \brief Contructor for defined coordinate index.
*/
Ruler( int cind );
/*! \brief Copy contructor.
*/
Ruler( const Ruler &ruler );
/*! \brief Assignment operator.
*/
Ruler &operator=( const Ruler &ruler );
/*! \brief Destructor.
*/
~Ruler() {}
/*! \brief Copy tics and from other ruler.
*/
void copy_tics( const Ruler &ruler );
/*! \brief Set font size.
*/
void set_font_size( double size );
/*! \brief Set ruler color.
*/
void set_color( const Color &color );
/*! \brief Set tic lengths
*/
void set_ticlen( double inlen, double outlen );
/*! \brief Set ruler autoranging status
*/
void set_autorange( bool autorange_min, bool autorange_max );
/*! \brief Get ruler autoranging status
*/
void get_autorange( bool &autorange_min, bool &autorange_max ) const;
/*! \brief Set ruler ranges.
*
* Set ruler ranges to finite values. If only one range is either
* infinite or NaN, it is replaced by a number to get a total
* range span of 1. If both numbers are infinite or NaN, the
* minimum will be set to 0.0 and maximum to 1.0.
*/
void set_ranges( double min, double max );
/*! \brief Get current ruler ranges.
*
* Returns finite values used for ruler ranges.
*/
void get_ranges( double &min, double &max ) const;
/*! \brief End points in pixels for ruler.
*/
void set_endpoints( double x1, double y1, double x2, double y2 );
/*! \brief Set axis label.
*/
void set_axis_label( const std::string &label );
/*! \brief Enable axis title and tic labels.
*/
void enable_labels( bool enable );
/*! \brief Set coordinate index.
*
* Set \a cind to 0 for x and 1 for y.
*/
void set_coord_index( int cind );
/*! \brief Set in direction for frame ruler.
*/
void set_indir( bool ccw );
/*! \brief Calculate ruler ranges, set tics and coordmapper.
*
* If ruler_tic_bbox_test is set to true, the bounding boxes of
* the tic labels are tested against overlapping and tics are
* rebuilt with larger tic spacing to prevent this.
*/
void calculate( cairo_t *cairo, Coordmapper1D &cm, bool ruler_tic_bbox_test );
/*! \brief Draw ruler with cairo.
*
* If \a recalculate is false, the ruler will be drawn with it's
* current settings. This is for frame to prevent excess
* recalculation of rulers.
*/
void draw( cairo_t *cairo, Coordmapper1D &cm, bool recalculate = true );
/*! \brief Get bounding box of ruler.
*
* If \a recalculate is false, the ruler bounding box will
* correspond to it's current settings. This is for frame to
* prevent excess recalculation of rulers.
*/
void get_bbox( cairo_t *cairo, double bbox[4], Coordmapper1D &cm, bool recalculate = true );
/*! \brief Debug print to stream.
*/
void debug_print( std::ostream &os ) const ;
};
#endif