AxisModelBase.cxx
Go to the documentation of this file.
1 
12 // for dll interface warning
13 #ifdef _MSC_VER
14 #include "msdevstudio/MSconfig.h"
15 #endif
16 
17 #include "AxisModelBase.h"
18 #include "AxisTick.h"
19 
20 #include <algorithm>
21 
22 #include <cassert>
23 
24 using std::string;
25 using std::vector;
26 
27 namespace hippodraw {
28 
30  : m_range( 0.0, 1.0 ),
31  m_start_range ( -1.0, 1.0 ),
32  m_is_dragging ( false ),
33  m_auto_range ( true ),
34  m_empty( true ),
35  m_scale_factor ( 1.0 ),
36  m_scaling_on ( false ),
37  m_first_tick( 0.0 ),
38  m_max_ticks( 20 ),
39  m_num_minor_ticks( 0 ),
40  m_label_location( label ),
41  m_scale_location( scale ),
42  m_pmag( 0.0 ),
43  m_use_pmag( false ),
44  m_ticks( m_max_ticks ),
45  m_ticks_in_range(m_max_ticks),
46  m_auto_ticks ( true )
47 {
48 }
49 
51  : m_range( axis_model.m_range ),
52  m_start_range ( 0.0, 1.0 ),
53  m_is_dragging ( false ),
54  m_auto_range( axis_model.m_auto_range ),
55  m_empty( axis_model.m_empty ),
56  m_scale_factor( axis_model.m_scale_factor ),
57  m_scaling_on ( axis_model.m_scaling_on ),
58  m_first_tick( axis_model.m_first_tick ),
59  m_tick_step( axis_model.m_tick_step ),
60  m_max_ticks( 20 ),
61  m_num_minor_ticks( axis_model.m_num_minor_ticks ),
62  m_label_location( axis_model.m_label_location ),
63  m_scale_location( axis_model.m_scale_location ),
64  m_pmag( axis_model.m_pmag ),
65  m_use_pmag( axis_model.m_use_pmag ),
66  m_ticks( axis_model.m_ticks ),
67  m_ticks_in_range( axis_model.m_ticks_in_range),
68  m_auto_ticks ( axis_model.m_auto_ticks )
69 {
70 }
71 
73 {
74 }
75 
76 void AxisModelBase::setTickStep( const double & t_step )
77 {
78  m_tick_step = t_step;
79 }
80 
82 {
83  return m_tick_step;
84 }
85 
86 void AxisModelBase::setFirstTick( const double & first_tick )
87 {
88  m_first_tick = first_tick;
89 }
90 
92 {
93  return m_first_tick;
94 }
95 
97 {
98  return m_max_ticks;
99 }
100 
101 void AxisModelBase::setRMag( const double & rmag )
102 {
103  m_rmag = rmag;
104 }
105 
107 {
108  return m_rmag;
109 }
110 
111 void AxisModelBase::setPMag( const double & pmag )
112 {
113  m_pmag = pmag;
114 }
115 
117 {
118  return m_pmag;
119 }
120 
122 {
123  return m_use_pmag;
124 }
125 
126 void AxisModelBase::setUsePMag( const bool & use_p_mag )
127 {
128  m_use_pmag = use_p_mag;
129 }
130 
132 {
133  return m_label_location;
134 }
135 
137 {
138  return m_scale_location;
139 }
140 
141 void
143 setAutoTicks ( bool yes )
144 {
145  m_auto_ticks = yes;
146  if (!m_auto_ticks) adjustTicks();
147 }
148 
149 bool
151 isAutoTicks ( ) const
152 {
153  return m_auto_ticks;
154 }
155 
156 void
158 setTicks ( const std::vector < AxisTick > & ticks)
159 {
160  m_ticks = ticks;
161  if (!m_auto_ticks) adjustTicks();
162 }
163 
164 const vector<AxisTick> &
166 {
167  if ( m_auto_ticks ) return m_ticks;
168  else return m_ticks_in_range;
169 
170 }
171 
172 void
175 {
176  /* Need pre-processing to keep ticks in range. */
177  m_ticks_in_range.clear();
178 
179  /* Only ticks within the range are useful. */
180  unsigned int size = m_ticks.size();
181  double range_high = m_range.high();
182  double range_low = m_range.low();
183  for ( unsigned int i = 0; i<size; i++ ) {
184  if (( m_ticks[i].value()< range_high ) &&
185  ( m_ticks[i].value()> range_low ))
186  m_ticks_in_range.push_back(m_ticks[i]);
187  }
188 }
189 
190 
191 void AxisModelBase::setRange ( double low, double high, double pos )
192 {
193  if ( low > high ) std::swap ( low, high );
194  m_range.setRange ( low, high, pos );
195 
196  if (!m_auto_ticks) adjustTicks();
197 }
198 
199 void AxisModelBase::setRange( const Range & range, bool scaled )
200 {
201  /* Comment out this for now to enable very small range ( range < 1e-16 );
202 
203  if ( range.length () < DBL_EPSILON ) {
204  return;
205  }
206 
207  */
208  Range myrange = range;
209  if( scaled ){
210  Range newrange( range.low() / m_scale_factor,
211  range.high() / m_scale_factor,
212  range.pos() );
213  myrange = newrange;
214  }
215 
216  m_range = myrange;
217 
218  // I could just call adjustLogValues() without a check, since linear
219  // does nothing in that function. However, this assures that the
220  // graph actually has content, which may or may not be important in
221  // adjustLogValues(), so I'm playing it on the safe side.
222  // Note that this causes problems in binned axes, because this has
223  // already bypassed the binner's dialogue. Therefore, this is only a
224  // secondary backup, as adjustLogValues() would have already been
225  // called for binned axes through the projector.
226  if( isLog() ) adjustLogValues();
227 
228  m_empty = false;
229 
230  if (!m_auto_ticks) adjustTicks();
231 
232 }
233 
234 void AxisModelBase::setIntersectRange ( const Range & r1, const Range & r2 )
235 {
236  m_range = r1;
237  m_range.setIntersect ( r2 );
238 }
239 
240 void
242 setRangePos ( double pos )
243 {
244  assert( pos > 0.0 );
245  m_range.setPos( pos );
246 }
247 
248 void AxisModelBase::setUnionRange ( const Range & range )
249 {
250  if( m_empty ) {
251  m_range = range;
252  m_range.setEmpty ( false );
253  m_empty = false;
254  }
255  else {
256  m_range.setUnion( range );
257  }
258 }
259 
261 {
262  m_empty = true;
263 }
264 
265 const Range & AxisModelBase::getRange(bool scaled) const
266 {
267 
268  if(!scaled)
269  return m_range;
270 
271  double low = m_range.low() * m_scale_factor;
272  double high = m_range.high() * m_scale_factor;
273 
274  Range range ( low, high );
275  m_scaled_range = range;
276 
277  return m_scaled_range;
278 }
279 
281 {
282  m_auto_range = flag;
283 }
284 
286 {
287  return m_auto_range;
288 }
289 
291 {
292  m_scale_factor = sf;
293  m_scaling_on = true;
294 }
295 
297 {
298  if ( m_scaling_on == false ) return 1.0;
299  // else
300  return m_scale_factor;
301 }
302 
304 {
305  return m_scaling_on;
306 }
307 
309 {
310  m_scaling_on = on;
311  if ( on == false ) m_scale_factor = 1.0;
312 }
313 
314 void AxisModelBase::startDragging ( bool dragging )
315 {
316  if ( m_is_dragging == false ) {
318  }
319  m_is_dragging = dragging;
320 }
321 
322 } // namespace hippodraw
double pos() const
Returns the first positive element in range.
Definition: Range.cxx:113
Range m_start_range
The starting range before start of dragging events.
Definition: AxisModelBase.h:46
void setRangePos(double)
The function which changes the pos member of m_range.
double m_rmag
The value of the power of ten of the range to be used to determine how many decimal places are needed...
Definition: AxisModelBase.h:97
virtual ~AxisModelBase()
The virtual destructor.
hippodraw::AxisModelBase class interface
virtual bool needPMag() const
The following functions are used by the AxisRepBase * object.
double high() const
Returns the maximum of the range object.
Definition: Range.cxx:100
void setAutoTicks(bool yes)
Sets flag to determine if tick positions should be automatically generated or not.
Expresses a range of values.
Definition: Range.h:33
Range m_range
The current range of the axis.
Definition: AxisModelBase.h:38
void adjustTicks()
Adjust ticks in non_auto_tick mode.
void setRMag(const double &rmag)
Sets the magnitude of the range.
void setEmpty()
Sets the range to empty.
const std::vector< AxisTick > & getTicks() const
Returns a reference of generated ticks.
double m_scale_factor
The scale factor.
Definition: AxisModelBase.h:62
const Range & getRange(bool scaled) const
Returns the range represented by this AxisModel.
void startDragging(bool dragging)
Sets the member m_start_dragging to the current range if dragging is starting.
double m_pmag
The value of the power of ten to be used to multiply the tick labels.
Definition: AxisModelBase.h:88
bool m_use_pmag
A flag to indicate that one will using scientific notation.
Definition: AxisModelBase.h:93
double m_first_tick
The position of the first tick.
Definition: AxisModelBase.h:70
AxisTick class interface.
void setIntersectRange(const Range &, const Range &)
Sets the Range to overlap of the two ranges.
std::vector< AxisTick > m_ticks
The list of generated ticks.
double getMaxTicks() const
Returns the value for maximum number of ticks.
void setTicks(const std::vector< AxisTick > &ticks)
Sets the ticks for plotting.
void setUnionRange(const Range &range)
Sets the range to be the union of the existing range and range.
void setScaleFactor(double)
Sets the value of the scale factor.
virtual void setUsePMag(const bool &use_p_mag)
Use to set the value of the member variable m_use_pmag.
double getRMag() const
Sets the magnitude of the range.
bool isScaling() const
Returns true if the axis is being scaled.
void setFirstTick(const double &first_tick)
Sets the value for first tick step.
void setScaling(bool on=true)
Sets axis scaling on if on is true.
void setPos(double x)
Sets the first positive element in range.
Definition: Range.cxx:119
bool isAutoRanging() const
Returns true if auto-ranging is enabled; otherwise, returns false.
bool isAutoTicks() const
Returns true if position of the ticks should be automatically generated.
const int m_max_ticks
The maximum number of ticks.
Definition: AxisModelBase.h:77
AxisLoc getScaleLocation() const
bool m_auto_ticks
A flag set to true if ticks are being automatically generated.
bool m_auto_range
The auto-range flag.
Definition: AxisModelBase.h:53
void setTickStep(const double &t_step)
Sets the tick step.
void setRange(double low, double high, double pos)
Changes the current Range.
Definition: Range.cxx:126
AxisLoc
The base class for the binner hierarchy.
Definition: AxisLoc.h:17
intp size(numeric::array arr)
Definition: num_util.cpp:296
void setRange(double low, double high, double pos)
Sets the Range to the low and high values.
double getScaleFactor() const
Returns the scale factor.
bool m_empty
A flag to indicate whether the range is empty.
Definition: AxisModelBase.h:56
void setPMag(const double &pmag)
Sets the magnitude of the power of ten for the tick labels.
void setAutoRanging(bool flag)
Sets the auto-ranging flag to flag.
void setEmpty(bool yes=true)
Sets the range to empty.
Definition: Range.cxx:165
double m_tick_step
The distance between two consecutive ticks.
Definition: AxisModelBase.h:74
AxisModelBase(AxisLoc label, AxisLoc scale)
The constructor sets the location of the ticks, labels, and scale.
bool m_scaling_on
If true, the axis is being scaled.
Definition: AxisModelBase.h:65
double getTickStep() const
Returns the tick step in the true coordinate system.
void setIntersect(const Range &range)
Forms the intersect with the range in the argument.
Definition: Range.cxx:188
virtual bool isLog() const =0
Returns a boolean describing the type of the scale of the axis.
double low() const
Returns the minimum of the range object.
Definition: Range.cxx:87
Range m_scaled_range
The scaled range.
Definition: AxisModelBase.h:41
void setUnion(const Range &range)
Forms the union with the range range.
Definition: Range.cxx:170
std::vector< AxisTick > m_ticks_in_range
Only work for non auto_ticks.
double getFirstTick() const
Returns the value for the first tick step.
The AxisModelBase class maintains the Range and scaling of an axis.
Definition: AxisModelBase.h:33
virtual const Range & adjustLogValues()=0
Adjust the range for nice logging.
bool m_is_dragging
The current dragging state.
Definition: AxisModelBase.h:49
double getPMag() const
Returns the magnitude of the power of ten for the tick labels.
AxisLoc getLabelLocation() const

Generated for HippoDraw Class Library by doxygen