Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

# QwtAutoScale Class Reference

Collaboration diagram for QwtAutoScale:

[legend]
List of all members.

## Detailed Description

The Qwt Auto-Scaler.

This class can be used to generate a scale which may span multiple ranges of values. A scale consists of a lower boundary, an upper boundary, a vector of major scale ticks and a vector of minor scale ticks which divide it into subintervals. A quick look at the example below will give you an idea of how the auto-scaler works.

The auto-scaler produces "reasonable" major and minor step sizes. For linear scales, the major step size will fit into the pattern , where n is an integer. In logarithmic mode (setOptions()) the step size is measured in *decades* and the major step size will be adjusted to fit the pattern , where n is a natural number including zero.

The step size can be manipulated indirectly using setMaxMajor(). The layout of the scale can be varied with setOptions().

The auto-scaling algorithm can be partly or completely disabled (even temporarily) if a user-defined scale is desired. This can be done with the setScale() function. It can be switched off again with setAutoScale().

The two adjust() members are used to extend the scale if necessary in order to include another range or array of values. The resulting scale division can be obtained with scaleDiv(). reset() resets the scale to zero.

Example

    #include <qwt_autoscl.h>
    #include <iostream.h>

    double x1[100];
    double x2[200];
    double range_min, range_max;

    QwtAutoScale as;

    // ... determine x1 and x1, range_min and range_max here ...

    as.reset();                           // clear it
    as.adjust(range_min, range_max);      // include a range
    as.adjust(x1,100);                    // include an array
    as.adjust(x2,200);                    // include another array

    for (i=0;i<as.scaleDiv().majCnt(); i++)
    {
      cout << "Scale tick " << i
      << " at " << as.scaleDiv().majMark(i) << "\n";
    }

Warning:
  For logarithmic scales, the step size as well as the margins are measured in *decades*.

Definition at line 78 of file qwt_autoscl.h.

## Public Types
enum | { None = 0, IncludeRef = 1, Symmetric = 2, Floating = 4, Logarithmic = 8, Inverted = 16 }
## Public Member Functions
| QwtAutoScale ()
| ~QwtAutoScale ()
void | setAutoScale ()
bool | autoScale () const
void | setAutoRebuild (bool)
bool | autoRebuild () const
void | changeOptions (int opt, bool tf)
void | setOptions (int opt)
bool | option (int opt) const
int | options () const
void | setMaxMajor (int n)
int | maxMajor () const
void | setMaxMinor (int n)
int | maxMinor () const
void | setReference (double r)
double | reference () const
void | setMargins (double m1, double m2)
double | loMargin () const
double | hiMargin () const
void | setScale (double xmin, double xmax, double step=0.0)
const QwtScaleDiv & | scaleDiv () const
void | adjust (double *arr, int n, int reset=0)
void | adjust (const QwtArray< double > &x, int reset=0)
void | adjust (double x1, double x2, int reset=0)
void | build ()
void | reset ()
## Protected Member Functions
void | buildLinScale ()
void | buildLogScale ()
void | setRange (double x1, double x2)

## Constructor & Destructor Documentation

QwtAutoScale::QwtAutoScale | ( |  | ) |

| Ctor. Definition at line 17 of file qwt_autoscl.cpp.

QwtAutoScale::~QwtAutoScale | ( |  | ) |

| Dtor. Definition at line 37 of file qwt_autoscl.cpp.

## Member Function Documentation

void QwtAutoScale::adjust | ( | double | vmin,
|  | double | vmax,
|  | int | reset = `0`
| ) |

  | Adjust the scale to include a specified interval. This member function extends the boundaries of the scale and re-calculates the step size if necessary in order to include a specified interval. If the reset parameter has nonzero value, the previous state will be cleared. Parameters:
  | vmin | lower border of the specified interval
  | vmax | upper border of the specified interval
  | reset | if nonzero, reset the scale. Defaults to 0.
Definition at line 150 of file qwt_autoscl.cpp. References build().

void QwtAutoScale::adjust | ( | const QwtArray< double > & | x,
|  | int | reset = `0`
| ) |

  | Adjust the scale to include a given array of input values. This member function extends the boundaries of the scale and re-calculates the step size if necessary in order to include all values in the array. If the reset parameter has nonzero value, the previous state will be cleared. Parameters:
  | x | QwtArray<double> of input values
  | reset | If != 0 reset the scale's contents
Definition at line 131 of file qwt_autoscl.cpp. References adjust().

void QwtAutoScale::adjust | ( | double * | x,
|  | int | num,
|  | int | reset = `0`
| ) |

  | Adjust the scale to include a given array of input values. This member function extends the boundaries of the scale and re-calculates the step size if necessary in order to include all values in the array. If the reset parameter has nonzero value, the previous state will be cleared. Parameters:
  | x | Array of input values
  | num | Array size
  | reset | If != 0 reset the scale's contents
Definition at line 100 of file qwt_autoscl.cpp. References build(). Referenced by adjust(), and QwtPlot::updateAxes().

bool QwtAutoScale::autoRebuild | ( |  | ) | const

| Returns: If true, rebuild scale automatically with call to 'adjust' See also: QwtAutoScale::setAutoRebuild() Definition at line 739 of file qwt_autoscl.cpp.

bool QwtAutoScale::autoScale | ( |  | ) | const

| Returns: `TRUE` if auto-scaling is active See also: QwtAutoScale::setAutoScale() Definition at line 45 of file qwt_autoscl.cpp. Referenced by QwtPlot::axisAutoScale(), and QwtPlot::updateAxes().

void QwtAutoScale::build | ( |  | ) |

| Re-build the scale. Definition at line 176 of file qwt_autoscl.cpp. References buildLinScale(), buildLogScale(), and QwtScaleDiv::rebuild(). Referenced by adjust(), changeOptions(), setAutoScale(), setMargins(), setMaxMajor(), setMaxMinor(), setOptions(), setReference(), and setScale().

void QwtAutoScale::buildLinScale | ( |  | ) | `[protected]`

| Build a linear scale. Definition at line 213 of file qwt_autoscl.cpp. References QwtScaleDiv::rebuild(), and setRange(). Referenced by build().

void QwtAutoScale::buildLogScale | ( |  | ) | `[protected]`

| build a logarithmic scale Definition at line 300 of file qwt_autoscl.cpp. References QwtScaleDiv::rebuild(), and setRange(). Referenced by build().

void QwtAutoScale::changeOptions | ( | int | opt,
|  | bool | tf
| ) |

  | Set or reset specified scale options. Parameters:
  | opt | or-combined scale options
  | tf | If `TRUE`, set the specified options. If `FALSE`, reset these options.
See also: QwtAutoScale::setOptions() Definition at line 391 of file qwt_autoscl.cpp. References build(). Referenced by QwtPlot::changeAxisOptions().

double QwtAutoScale::hiMargin | ( |  | ) | const

| Returns: the margin at the upper end of the scale See also: QwtAutoScale::setMargins() Definition at line 63 of file qwt_autoscl.cpp.

double QwtAutoScale::loMargin | ( |  | ) | const

| Returns: the margin at the lower end of the scale See also: QwtAutoScale::setMargins() Definition at line 54 of file qwt_autoscl.cpp. Referenced by QwtPlot::axisMargins().

int QwtAutoScale::maxMajor | ( |  | ) | const

| Returns: the maximum number of major tickmarks See also: QwtAutoScale::setMaxMajor() Definition at line 72 of file qwt_autoscl.cpp. Referenced by QwtPlot::axisMaxMajor().

int QwtAutoScale::maxMinor | ( |  | ) | const

| Returns: the maximum number of minor scale ticks See also: QwtAutoScale::setMaxMinor() Definition at line 81 of file qwt_autoscl.cpp. Referenced by QwtPlot::axisMaxMinor().

bool QwtAutoScale::option | ( | int | opt | ) | const

  | Returns TRUE if the specified option is set. Parameters:
  | opt | Option
See also: QwtAutoScale::setOptions() Definition at line 697 of file qwt_autoscl.cpp.

int QwtAutoScale::options | ( |  | ) | const

| Returns: options See also: QwtAutoScale::setOptions(), QwtAutoScale::option() Definition at line 707 of file qwt_autoscl.cpp. Referenced by QwtPlot::axisOptions().

double QwtAutoScale::reference | ( |  | ) | const

| Returns: the reference value See also: QwtAutoScale::setOptions(), QwtAutoScale::option() Definition at line 686 of file qwt_autoscl.cpp. Referenced by QwtPlot::axisReference().

void QwtAutoScale::reset | ( |  | ) |

| Set the interval boundaries to zero and clear the scale division. This member function resets an AutoScale object to its initial state. It is needed to clean up the scale before or after subsequent adjust() calls. The boundaries of the scale are set to zero and the scale division is cleared. Warning: A reset doesn't affect the margins. Definition at line 413 of file qwt_autoscl.cpp. References QwtScaleDiv::reset(). Referenced by QwtPlot::updateAxes().

const QwtScaleDiv & QwtAutoScale::scaleDiv | ( |  | ) | const

| The scale division consists of two boundary values, an array of major tickmarks and an array of minor tickmarks. Returns: a const reference to the scale division See also: QwtScaleDiv Definition at line 720 of file qwt_autoscl.cpp. Referenced by QwtPlot::axisScale(), QwtPlot::canvasMap(), and QwtPlot::print().

void QwtAutoScale::setAutoRebuild | ( | bool | tf | ) |

| If true, rebuild scale automatically with call to 'adjust' See also: QwtAutoScale::autoRebuild() Definition at line 730 of file qwt_autoscl.cpp.

void QwtAutoScale::setAutoScale | ( |  | ) |

| Enable auto-scaling. This function is used to switch back to auto-scaling mode if the scale has been frozen temporarily (see setScale()). When auto-scaling is reactivated, the scale will be rebuild, which means that if adjust or setMaxIntv have been called in between, the scale will be adjusted to the new conditions. if none of these functions and no reset has been called, the old state will be restored. if only reset has been called in between, nothing will happen. See also: QwtAutoScale::setScale() Definition at line 439 of file qwt_autoscl.cpp. References build(). Referenced by QwtPlot::setAxisAutoScale().

void QwtAutoScale::setMargins | ( | double | mlo,
|  | double | mhi
| ) |

  | Specify margins at the scale's endpoints. Parameters:
  | mlo | minimum distance between the scale's lower boundary and the smallest enclosed value
  | mhi | minimum distance between the scale's upper boundary and the greatest enclosed value
Margins can be used to leave a minimum amount of space between the enclosed intervals and the boundaries of the scale. Warning: With logarithmic scales, the margins are measured in decades. The margins will not be changed by any other member function. You should remember this when you call reset() or change from a linear to a logarithmic scale. Definition at line 461 of file qwt_autoscl.cpp. References build(). Referenced by QwtPlot::setAxisMargins().

void QwtAutoScale::setMaxMajor | ( | int | mx | ) |

  | Specify the maximum number of major intervals. Parameters:
  | mx | maximum number of subintervals
The auto-scaler places the major ticks at reasonable points, such that the number of major tick intervals does not exceed the specified maximum number. Definition at line 477 of file qwt_autoscl.cpp. References build(). Referenced by QwtPlot::setAxisMaxMajor().

void QwtAutoScale::setMaxMinor | ( | int | mx | ) |

  | Specify the maximum number of minor subdivisions within major scale intervals. Parameters:
  | mx | maximum number of minor ticks
Definition at line 489 of file qwt_autoscl.cpp. References build(). Referenced by QwtPlot::setAxisMaxMinor().

void QwtAutoScale::setOptions | ( | int | opt | ) |

  | Reset scale options and set specified options. Parameters:
  | opt | Combined set of options
  The behaviour of the auto-scaling algorithm can be changed with the following options: QwtAutoScale::None Switch all options off. QwtAutoscale::IncludeRef Build a scale which includes the reference value. QwtAutoScale::Symmetric Build a scale which is symmetric to the reference value. QwtAutoScale::Logarithmic Build a logarithmic scale. QwtAutoScale::Floating The endpoints of the scale are supposed to be equal the outmost included values plus the specified margins (see setMargins()). If this option is not* set, the endpoints of the scale will be integer multiples of the step size. QwtAutoScale::Inverted Turn the scale upside down. Warning: If the type of scale division is changed from logarithmic to linear or vice versa, the margins will not be transformed. Note that the margins count in decades if the scale is logarithmic. If a linear scale contains negative values, switching to a logarithmic scale will cut them off and set the lower scale boundary to its lowest possible value of 1.0E-100. This effect is reversible if you switch back to a linear scale. The options have no effect while auto-scaling is turned off (see setScale()) Example:
      #include "../include/qwt_autoscl.h>

      void main()
      {
          QwtAutoScale as;

          // build linear scale with default settings
          as.adjust(17.45, 87344.0);

          //...

          // change to logarithmic scale with floating ends
          as.setOptions(QwtAutoScale::Floating | QwtAutoscale::Logarithmic);

          //...

          // change to linear, zero-symmetric scale
          as.setOptions(QwtAutoScale::ZeroSymmetric);

          //...
      }
See also: QwtAutoScale::changeOptions() for a description of the possible options. Definition at line 649 of file qwt_autoscl.cpp. References build(). Referenced by QwtPlot::setAxisOptions().

void QwtAutoScale::setRange | ( | double | x1,
|  | double | x2
| ) | `[protected]`

  | Specify a user-defined range. Parameters:
  | x1 | user-defined lower boundary
  | x2 | user-defined upper boundary
Warning: if x1 > x2, the lower boundary will be set to x2 and the upper boundary to x1. if x1 == x2, the auto-scaler sets the boundaries to (-0.5, 0.5) for linear scales and to (LOG_MIN, LOG_MAX) for logarithmic scales. See also: QwtAutoScale::setScale(), LOG_MIN, LOG_MAX. Definition at line 510 of file qwt_autoscl.cpp. References LOG_MAX, and LOG_MIN. Referenced by buildLinScale(), buildLogScale(), and setScale().

void QwtAutoScale::setReference | ( | double | r | ) |

  | Specify a reference point. Parameters:
  | r | new reference value
The reference point is needed if the auto-scaler options IncludeRef or Symmetric are active. Its default value is 0 for linear scales and 1 for logarithmic scales. Warning: The reference value for logarithmic scales is limited to ( LOG_MIN / 2 <= reference <= LOG_MAX /2 ). If the specified value is less than LOG_MIN, it will be set to 1.0 for logarithmic scales. See also: LOG_MIN, LOG_MAX. Definition at line 670 of file qwt_autoscl.cpp. References build(), LOG_MAX, and LOG_MIN. Referenced by QwtPlot::setAxisReference().

void QwtAutoScale::setScale | ( | double | xmin,
|  | double | xmax,
|  | double | step = `0.0`
| ) |

  | Specify a user-defined scale and switch off auto-scaling. Parameters:
  | xmin | user-defined lower boundary
  | xmax | user-defined upper boundary
  | step | user-defined fixed major step size
A fixed scale may be used for different purposes, e.g. zooming. If the step argument is left out or less or equal to zero, the auto-scaler will calculate the major step size size according to the maxMajor setting. The fixed-scale mode can switched off using setAutoScale(), which restores the previous values. Warning: if xmin > xmax, the lower boundary will be set to xmax and the upper boundary to xmin. if xmin == xmax, the auto-scaler sets the boundaries to (-0.5, 0.5) for linear scales and to (LOG_MIN, LOG_MAX) for logarithmic scales. Options and margins have no effect while auto-scaling is switched off. See also: QwtAutoScale::setMaxMajor(), QwtAutoScale::setAutoScale(), LOG_MIN, LOG_MAX. Definition at line 576 of file qwt_autoscl.cpp. References build(), and setRange(). Referenced by QwtPlot::setAxisScale().