Qwt Programmer's manual

QwtAutoScale


NAME

QwtAutoScale - The Qwt Auto-Scaler

SYNOPSIS

#include <qwt_autoscl.h>

DESCRIPTION

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 {1,2,5}*10^n, where n is an integer. In logarithmic mode (see setOptions) the step size is measured in decades and the major step size will be adjusted to fit the pattern {1,2,3,5}*10^n, 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 (1) 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 scaleDivThe reset resets the scale to zero.

PUBLIC MEMBERS

QwtAutoScale
Constructor
~QwtAutoScale
Destructor
adjust (1)
Adjust the scale in order to include all values in a specified array
adjust (2)
Adjust the scale in order to include a specified range
build
Rebuild the scale
reset
Reset the scale to zero
changeOptions
Change a set of options
setAutoRebuild
Enable automatic update
setAutoScale
Re-enable auto-scaling
setMargins
Specify boundary margins
setMaxMajor
Set maximal number of major subdivisions
setMaxMinor
Set maximum number of minor subdivisions
setOptions
Specify options
setReference
Specify reference point
setScale
Set a fixed scale range and (optionally)
scaleDiv
Return the scale division
autoScale
Check for autoscale mode
loMargin
Return lower margin
hiMargin
Return upper margin
maxMajor
Return max. number of major steps
maxMinor
Return max. number of minor steps
option
Check for specified option
options
Return options
reference
Return reference value
scaleDiv
Return scale divisio

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";
      }      

NOTE

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

MEMBER FUNCTION DESCRIPTION


QwtAutoScale::QwtAutoScale

Construct a QwtAutoScale instance

Syntax

QwtAutoScale::QwtAutoScale()

QwtAutoScale::~QwtAutoScale

Destroy a QwtAutoScale instance

Syntax

QwtAutoScale::~QwtAutoScale()

QwtAutoScale::adjust (1)

Adjust the scale to include a given array of input values.

Syntax

void QwtAutoScale::adjust(double *., int num, int reset)

Parameters

double *x
array of input values
int num
size of x
int reset = 0
if != 0 reset the scale's contents.

Return Value

Description

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.

QwtAutoScale::adjust (2)

Adjust the scale to include a specified interval

Syntax

void QwtAutoScale::adjust(double vmin, double vmax, int reset)

Parameters

double vmin
lower border of the specified interval
double vmax
upper border of the specified interval
int reset
if nonzero, reset the scale. Defaults to 0.

Description

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.

QwtAutoScale::changeOptions

Set or reset specified scale options

Syntax

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

Parameters

int opt
or-combined scale options
bool tf
If TRUE, set the specified options. If FALSE, reset these options.

See also

setOptions

QwtAutoScale::reset

Set the interval boundaries to zero and clear the scale division

Syntax

void QwtAutoScale::reset()

Description

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.

Note

A reset doesn't affect the margins.

QwtAutoScale::setAutoScale

Enable auto-scaling

Syntax

void QwtAutoScale::setAutoScale()

Description

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

See also

setScale

QwtAutoScale::setMargins

Specify margins at the scale's endpoints

Syntax

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

Parameters

double mlo
minimum distance between the scale's lower boundary and the smallest enclosed value
double mhi
minimum distance between the scale's upper boundary and the greatest enclosed value

Description

Margins can be used to leave a minimum amount of space between the enclosed intervals and the boundaries of the scale.

Note


QwtAutoScale::setMaxMajor

Specify the maximum number of major intervals

Syntax

void QwtAutoScale::setMaxMajor(int mx)

Parameters

int mx
maximum number of subintervals

Description

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.

QwtAutoScale::setMaxMinor

Specify the maximum number of minor subdivisions within major scale intervals

Syntax

void QwtAutoScale::setMaxMinor(int mx)

Parameters

int mx
maximum number of minor ticks

QwtAutoScale::setScale

Specify a user-defined scale and switch off auto-scaling

Syntax

void QwtAutoScale::setScale(double xmin, double xmax, double step)

Parameters

double xmin
user-defined lower boundary
double xmax
user-defined upper boundary
double step = 0
user-defined fixed major step size

Description

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 (see setMaxMajor. The fixed-scale mode can switched off using setAutoScale, which restores the previous values.

Note


QwtAutoScale::setOptions

Reset scale options and set specified options

Syntax

void QwtAutoScale::setOptions(int opt)

Parameters

int opt
Combined set of options

Description

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.

Note

Example

      #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

changeOptions for a description of the possible options

QwtAutoScale::setReference

Specify a reference point

Syntax

void QwtAutoScale::setReference(double r)

Parameters

double r
new reference value

Description

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.

Note

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 (defined in qwt_math.h), it will be set to 1.0 for logarithmic scales.

QwtAutoScale::autoScale

Return TRUE if auto-scaling is active

Syntax

bool QwtAutoScale::autoScale()

See Also

setAutoScale

QwtAutoScale::loMargin

Return the margin at the lower end of the scale

Syntax

double QwtAutoScale::loMargin()

See also

setMargins

QwtAutoScale::hiMargin

Return the margin at the upper end of the scale

Syntax

double QwtAutoScale::hiMargin()

See Also

setMargins

QwtAutoScale::maxMajor

Return the maximum number of major tickmarks

Syntax

int QwtAutoScale::maxMajor()

See also

setMaxMajor

QwtAutoScale::maxMinor

Return the maximum number of minor scale ticks

Syntax

int QwtAutoScale::maxMinor()

See Also

setMaxMinor

QwtAutoScale::option

Returns TRUE if the specified option is set.

Syntax

bool QwtAutoScale::option(int opt) const

Parameters

int opt -- option

See also

setOptions

QwtAutoScale::options

Return options

Syntax

int QwtAutoScale::options()

See also

setOptions

QwtAutoScale::reference

Return the reference value

Syntax

double QwtAutoScale::reference()

See also

setReference

QwtAutoScale::scaleDiv

Returns a const reference to the scale division

Syntax

const QwtScaleDiv& QwtAutoScale::scaleDiv()

Description

The scale division consists of two boundary values, an array of major tickmarks and an array of minor tickmarks.

See also

QwtScaleDiv
Qwt Widget Library 01/09/97