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() );