Qwt Programmer's manual
QwtAutoScale
QwtAutoScale - The Qwt Auto-Scaler
#include <qwt_autoscl.h>
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.
- 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
#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";
}
For logarithmic scales, the step size as well as
the margins are measured in decades.
Construct a QwtAutoScale instance
QwtAutoScale::QwtAutoScale()
Destroy a QwtAutoScale instance
QwtAutoScale::~QwtAutoScale()
Adjust the scale to include a given array of input values.
void QwtAutoScale::adjust(double *., int num, int reset)
- double *x
- array of input values
- int num
- size of x
- int reset = 0
- if != 0 reset the scale's contents.
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.
Adjust the scale to include a specified interval
void QwtAutoScale::adjust(double vmin, double vmax, int reset)
- 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.
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.
Set or reset specified scale options
void QwtAutoScale::changeOptions(int opt, bool tf)
- int opt
- or-combined scale options
- bool tf
- If TRUE, set the specified options.
If FALSE, reset these options.
setOptions
Set the interval boundaries to zero and clear the
scale division
void QwtAutoScale::reset()
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.
A reset doesn't affect the margins.
Enable auto-scaling
void QwtAutoScale::setAutoScale()
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.
setScale
Specify margins at the scale's endpoints
void QwtAutoScale::setMargins(double mlo, double mhi)
- 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
Margins can be used to leave a minimum amount of space between
the enclosed intervals and the boundaries of the scale.
- 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.
Specify the maximum number of major intervals
void QwtAutoScale::setMaxMajor(int mx)
- int 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.
Specify the maximum number of minor subdivisions
within major scale intervals
void QwtAutoScale::setMaxMinor(int mx)
- int mx
- maximum number of minor ticks
Specify a user-defined scale and switch off auto-scaling
void QwtAutoScale::setScale(double xmin, double xmax, double step)
- double xmin
- user-defined lower boundary
- double xmax
- user-defined upper boundary
- double step = 0
- 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 (see setMaxMajor.
The fixed-scale mode can switched off using
setAutoScale, which restores the
previous values.
- if xmin > xmax, xmax will be the lower boundary.
- if xmin == xmax, the auto-scaler sets the boundaries to (-0.5, 0.5).
- Options and margins have no effect while auto-scaling is switched off.
Reset scale options and set specified options
void QwtAutoScale::setOptions(int opt)
- int 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.
- 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)
#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);
...
}
changeOptions for a description of the
possible options
Specify a reference point
void QwtAutoScale::setReference(double r)
- double 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.
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.
Return TRUE if auto-scaling is active
bool QwtAutoScale::autoScale()
setAutoScale
Return the margin at the lower end of the scale
double QwtAutoScale::loMargin()
setMargins
Return the margin at the upper end of the scale
double QwtAutoScale::hiMargin()
setMargins
Return the maximum number of major tickmarks
int QwtAutoScale::maxMajor()
setMaxMajor
Return the maximum number of minor scale ticks
int QwtAutoScale::maxMinor()
setMaxMinor
Returns TRUE if the specified option is set.
bool QwtAutoScale::option(int opt) const
int opt -- option
setOptions
Return options
int QwtAutoScale::options()
setOptions
Return the reference value
double QwtAutoScale::reference()
setReference
Returns a const reference to the scale division
const QwtScaleDiv& QwtAutoScale::scaleDiv()
The scale division consists of two boundary values,
an array of major tickmarks and an array of minor
tickmarks.
QwtScaleDiv
Qwt Widget Library 01/09/97