void ScaleEngine::autoScale (int maxNumSteps, double &x1, double &x2, double &stepSize) const { if (!hasBreak() || testAttribute(QwtScaleEngine::Inverted)){ QwtScaleEngine *engine; if (d_type == QwtScaleTransformation::Log10) engine = new QwtLog10ScaleEngine(); else engine = new QwtLinearScaleEngine(); engine->setAttributes(attributes()); engine->setReference(reference()); engine->setMargins(loMargin(), hiMargin()); engine->autoScale(maxNumSteps, x1, x2, stepSize); delete engine; } else { QwtScaleEngine *engine; if (d_type == QwtScaleTransformation::Log10) engine = new QwtLog10ScaleEngine(); else engine = new QwtLinearScaleEngine(); engine->setAttributes(attributes()); double breakLeft = d_break_left; engine->autoScale(maxNumSteps, x1, breakLeft, stepSize); delete engine; engine = new QwtLinearScaleEngine(); engine->setAttributes(attributes()); double breakRight = d_break_right; engine->autoScale(maxNumSteps, breakRight, x2, stepSize); delete engine; } }
/*! Align and divide an interval \param maxNumSteps Max. number of steps \param x1 First limit of the interval (In/Out) \param x2 Second limit of the interval (In/Out) \param stepSize Step size (Out) \sa QwtLinearScaleEngine::setAttribute */ void QwtLinearScaleEngine::autoScale(int maxNumSteps, double &x1, double &x2, double &stepSize) const { QwtDoubleInterval interval(x1, x2); interval = interval.normalized(); interval.setMinValue(interval.minValue() - loMargin()); interval.setMaxValue(interval.maxValue() + hiMargin()); if (testAttribute(QwtScaleEngine::Symmetric)) interval = interval.symmetrize(reference()); if (testAttribute(QwtScaleEngine::IncludeReference)) interval = interval.extend(reference()); if (interval.width() == 0.0) interval = buildInterval(interval.minValue()); stepSize = divideInterval(interval.width(), qwtMax(maxNumSteps, 1)); if ( !testAttribute(QwtScaleEngine::Floating) ) interval = align(interval, stepSize); x1 = interval.minValue(); x2 = interval.maxValue(); if (testAttribute(QwtScaleEngine::Inverted)) { qSwap(x1, x2); stepSize = -stepSize; } }
/*! \brief Calculate a scale division \param x1 First interval limit \param x2 Second interval limit \param maxMajSteps Maximum for the number of major steps \param maxMinSteps Maximum number of minor steps \param stepSize Step size. If stepSize == 0, the scaleEngine calculates one. \sa QwtScaleEngine::stepSize, LogTimeScaleEngine::subDivide */ QwtScaleDiv LogTimeScaleEngine::divideScale(double x1, double x2, int maxMajSteps, int maxMinSteps, double stepSize) const { QwtDoubleInterval interval = QwtDoubleInterval(x1, x2).normalized(); interval = interval.limited(LOG_MIN, LOG_MAX); if (interval.width() <= 0 ) return QwtScaleDiv(); if (interval.maxValue() / interval.minValue() < 10.0) { // scale width is less than one decade -> build linear scale QwtLinearScaleEngine linearScaler; linearScaler.setAttributes(attributes()); linearScaler.setReference(reference()); linearScaler.setMargins( #if (QWT_VERSION >= 0x050200) lowerMargin(), upperMargin() #else loMargin(), hiMargin() #endif ); return linearScaler.divideScale(x1, x2, maxMajSteps, maxMinSteps, stepSize); } stepSize = qwtAbs(stepSize); if ( stepSize == 0.0 ) { if ( maxMajSteps < 1 ) maxMajSteps = 1; stepSize = divideInterval(log10(interval).width(), maxMajSteps); if ( stepSize < 1.0 ) stepSize = 1.0; // major step must be >= 1 decade } QwtScaleDiv scaleDiv; if ( stepSize != 0.0 ) { QwtValueList ticks[QwtScaleDiv::NTickTypes]; buildTicks(interval, stepSize, maxMinSteps, ticks); scaleDiv = QwtScaleDiv(interval, ticks); } if ( x1 > x2 ) scaleDiv.invert(); return scaleDiv; }
/*! Align and divide an interval \param maxNumSteps Max. number of steps \param x1 First limit of the interval (In/Out) \param x2 Second limit of the interval (In/Out) \param stepSize Step size (Out) \sa QwtScaleEngine::setAttribute */ void LogTimeScaleEngine::autoScale(int maxNumSteps, double &x1, double &x2, double &stepSize) const { if ( x1 > x2 ) qSwap(x1, x2); QwtDoubleInterval interval( #if (QWT_VERSION >= 0x050200) x1 / pow(10.0, lowerMargin()), x2 * pow(10.0, upperMargin()) #else x1 / pow(10.0, loMargin()), x2 * pow(10.0, hiMargin()) #endif ); double logRef = 1.0; if (reference() > LOG_MIN / 2) logRef = qwtMin(reference(), LOG_MAX / 2); if (testAttribute(QwtScaleEngine::Symmetric)) { const double delta = qwtMax(interval.maxValue() / logRef, logRef / interval.minValue()); interval.setInterval(logRef / delta, logRef * delta); } if (testAttribute(QwtScaleEngine::IncludeReference)) interval = interval.extend(logRef); interval = interval.limited(LOG_MIN, LOG_MAX); if (interval.width() == 0.0) interval = buildInterval(interval.minValue()); stepSize = divideInterval(log10(interval).width(), qwtMax(maxNumSteps, 1)); if ( stepSize < 1.0 ) stepSize = 1.0; if (!testAttribute(QwtScaleEngine::Floating)) interval = align(interval, stepSize); x1 = interval.minValue(); x2 = interval.maxValue(); if (testAttribute(QwtScaleEngine::Inverted)) { qSwap(x1, x2); stepSize = -stepSize; } }