87 const vector < AxisTick > &
99 return ( (
double)abs( x - y ) <= 2.0 * ( y * FLT_EPSILON + FLT_MIN ) );
104 static float goodTicks[] = { 5.0, 4.0, 2.0, 1.0 };
108 double rangeLength = range.
length();
111 rangeLength *= scale_factor;
112 const int MIN_TICKS = 3;
115 double rmag = floor( log10( rangeLength ) );
122 if( rangeLength / pow( 10.0, rmag ) < MIN_TICKS ) {
128 double scalelow = range.
low() * scale_factor;
129 double scalehigh = range.
high() * scale_factor;
132 double pmag = max( floor( log10( abs ( scalehigh ) ) ),
133 floor( log10( abs ( scalelow ) ) ) );
138 if( pow( 10.0, pmag ) == scalehigh ||
139 pow( 10.0, pmag ) == scalelow ) pmag--;
151 double tick_step = 0;
154 ( tick_step = goodTicks[tickIndex] * pow( 10.0, rmag ) )
165 double low = range.
low();
172 axis.
setFirstTick( ceil( low / tick_step ) * tick_step );
178 const vector < AxisTick > &
182 double y = 0.0, ylabel;
199 bool use_pmag = abs ( pmag ) > 3.0;
217 decimals =
static_cast<int>( pmag - rmag );
220 if( !decimals ) decimals++;
237 decimals =
static_cast<int>( abs( rmag ) );
249 sprintf( pstr,
"%%1.%df", decimals );
253 double range_high = range.
high();
254 range_high *= scale_factor;
255 range_high += 100. * DBL_EPSILON;
258 while( y <= range_high ) {
260 if( num_ticks >= max_ticks ) {
273 double value = floor( y / pow( 10.0, rmag ) + 0.5 ) *
279 if ( use_pmag ) ylabel = value / pow( 10.0, pmag );
282 value /= scale_factor;
283 sprintf( labl, pstr, ylabel );
295 const Range & limit )
300 double mylow, myhigh;
304 double step, magnitude;
306 const int N_NICE = 6;
310 float nice[N_NICE] = { 1.0, 1.5, 2.0,
314 double low = init_range.
low ();
315 double high = init_range.
high ();
317 if ( ( high - low ) < 10.* DBL_MIN ) {
318 if ( low > 0.0 ) low *= 0.95;
322 high = low + 1000. * FLT_EPSILON;
325 if ( high > 0.) high *= 1.05;
338 mylow = low - 0.05*(high-low);
339 myhigh = high + 0.05*(high-low);
341 range_length = myhigh - mylow;
349 if( low >= 0.0 && high > 22 * low ) {
350 Range range ( 0.0, range_length );
354 if( high <= 0.0 && low < 22 * high ) {
355 Range range ( -range_length, 0.0 );
361 magnitude = floor(log10(abs(range_length)));
362 float norm = range_length / pow(10., magnitude);
365 float r_previous = 10;
366 for (i = 0; i < N_NICE; i++) {
367 r = abs(norm / nice[i] - 1);
368 if (r < r_previous) {
375 step = 0.2 * x * pow(10, magnitude - 1);
376 mylow = floor(mylow / step) * step;
377 myhigh = ceil(myhigh / step) * step;
379 Range range ( mylow, myhigh, init_range.
pos() );
std::vector< AxisTick > m_ticks
The ticks generated by this transform.
virtual const std::vector< AxisTick > & setTicks(AxisModelBase &axis)
Sets the vector of ticks along the axis to which this Linear transform is applied.
double high() const
Returns the maximum of the range object.
A class to maintain tick coordinates and string values.
virtual ~LinearTransform()
The virtual destructor.
A transform on one axis whose output is equal to the input.
A transform that transforms coordinates from one coordinate system to another.
LinearTransform class interface.
void setFirstTick(const double &first_tick)
Sets the value for first tick step.
double getMaxTicks() const
Returns the value for maximum number of ticks.
LinearTransform()
The default constructor.
virtual const Range & adjustValues(AxisModelBase &axis, const Range &limit)
Sets the range of given axis to be a new "nice" within the limits given.
const std::vector< AxisTick > & genTicks(AxisModelBase &)
virtual void inverseTransform(double &x) const
Inverse transforms the coordinate x.
virtual void transform(double &x) const
Transforms the coordinate @ x.
void setRange(double low, double high, double pos)
Sets the Range to the low and high values.
void setFirstTick(AxisModelBase &)
double FLT_EQUAL(double x, double y)
void setPMag(const double &pmag)
Sets the magnitude of the power of ten for the tick labels.
The AxisModelBase class maintains the Range and scaling of an axis.
double length() const
Returns the length of the range object.
double getScaleFactor() const
Returns the scale factor.
double norm(const std::vector< double > &a)
Computes the two norm of the vector.
std::string m_name
Name of the Transform.
hippodraw::AxisModelBase class interface
double getRMag() const
Sets the magnitude of the range.
double getPMag() const
Returns the magnitude of the power of ten for the tick labels.
const Range & getRange(bool scaled) const
Returns the range represented by this AxisModel.
A transform that transforms coordinates in one dimension from one coordinate system to another...
void setRMag(const double &rmag)
Sets the magnitude of the range.
double low() const
Returns the minimum of the range object.
void setTickStep(AxisModelBase &)
void setTickStep(const double &t_step)
Sets the tick step.
Expresses a range of values.
virtual void setUsePMag(const bool &use_p_mag)
Use to set the value of the member variable m_use_pmag.
void setIntersectRange(const Range &, const Range &)
Sets the Range to overlap of the two ranges.
double getFirstTick() const
Returns the value for the first tick step.
virtual void validate(Range &) const
The following function validates the range.
virtual LinearTransform * clone() const
Creates a new Transform object by copying an existing one.
double pos() const
Returns the first positive element in range.
AxisTick class interface.
double getTickStep() const
Returns the tick step in the true coordinate system.