21 return std::log( value ) / std::log( base );
33 std::pow( base, interval.
maxValue() ) );
39 static double qwtStepSize(
double intervalSize,
int maxSteps, uint base )
41 const double minStep =
47 const int numTicks =
qwtCeil( qAbs( intervalSize / minStep ) ) - 1;
51 qAbs( intervalSize ), intervalSize ) > 0 )
54 return 0.5 * intervalSize;
63 static double qwtStepSize(
double intervalSize,
int maxSteps, uint base )
70 for (
int numSteps = maxSteps; numSteps > 1; numSteps-- )
72 const double stepSize = intervalSize / numSteps;
74 const double p = std::floor( std::log( stepSize ) / std::log( base ) );
75 const double fraction = std::pow( base, p );
77 for ( uint n = base; n > 1; n /= 2 )
79 if ( qFuzzyCompare( stepSize, n * fraction ) )
82 if ( n == 3 && ( base % 2 ) == 0 )
84 if ( qFuzzyCompare( stepSize, 2 * fraction ) )
91 return intervalSize * 0.5;
96 static const double _eps = 1.0e-6;
109 double intervalSize )
111 const double eps =
_eps * intervalSize;
113 value = ( value - eps ) / intervalSize;
114 return std::ceil( value ) * intervalSize;
128 const double eps =
_eps * intervalSize;
130 value = ( value + eps ) / intervalSize;
131 return std::floor( value ) * intervalSize;
145 if ( numSteps == 0.0 || intervalSize == 0.0 )
148 return ( intervalSize - (
_eps * intervalSize ) ) / numSteps;
161 double intervalSize,
int numSteps, uint base )
170 const double lx =
qwtLog( base, std::fabs( v ) );
171 const double p = std::floor( lx );
173 const double fraction = std::pow( base, lx - p );
176 while ( ( n > 1 ) && ( fraction <= n / 2 ) )
179 double stepSize = n * std::pow( base, p );
181 stepSize = -stepSize;
193 referenceValue( 0.0 ),
252 delete d_data->transform;
253 d_data->transform = transform;
268 if ( d_data->transform )
282 return d_data->lowerMargin;
293 return d_data->upperMargin;
314 d_data->lowerMargin =
qwtMaxF( lower, 0.0 );
315 d_data->upperMargin =
qwtMaxF( upper, 0.0 );
327 double intervalSize,
int numSteps )
const 330 intervalSize, numSteps, d_data->base );
367 if ( !interval.
isValid() || ticks.count() == 0 )
370 if ( contains( interval, ticks.first() )
371 && contains( interval, ticks.last() ) )
377 for (
int i = 0; i < ticks.count(); i++ )
379 if ( contains( interval, ticks[i] ) )
380 strippedTicks += ticks[i];
382 return strippedTicks;
397 const double delta = ( value == 0.0 ) ? 0.5 : qAbs( 0.5 * value );
400 if ( max - delta < value )
403 if ( -max + delta > value )
406 return QwtInterval( value - delta, value + delta );
420 d_data->attributes |= attribute;
422 d_data->attributes &= ~attribute;
433 return ( d_data->attributes & attribute );
444 d_data->attributes = attributes;
453 return d_data->attributes;
476 return d_data->referenceValue;
493 d_data->base = qMax( base, 2U );
532 double &x1,
double &x2,
double &stepSize )
const 546 if ( interval.
width() == 0.0 )
550 interval.
width(), qMax( maxNumSteps, 1 ),
base() );
553 interval =
align( interval, stepSize );
561 stepSize = -stepSize;
578 int maxMajorSteps,
int maxMinorSteps,
double stepSize )
const 584 qWarning() <<
"QwtLinearScaleEngine::divideScale: overflow";
588 if ( interval.
width() <= 0 )
591 stepSize = qAbs( stepSize );
592 if ( stepSize == 0.0 )
594 if ( maxMajorSteps < 1 )
598 interval.
width(), maxMajorSteps,
base() );
603 if ( stepSize != 0.0 )
606 buildTicks( interval, stepSize, maxMinorSteps, ticks );
628 const QwtInterval& interval,
double stepSize,
int maxMinorSteps,
636 if ( maxMinorSteps > 0 )
644 ticks[i] =
strip( ticks[i], interval );
649 for (
int j = 0; j < ticks[i].count(); j++ )
666 const QwtInterval &interval,
double stepSize )
const 668 int numTicks = qRound( interval.
width() / stepSize ) + 1;
669 if ( numTicks > 10000 )
673 ticks.reserve( numTicks );
676 for (
int i = 1; i < numTicks - 1; i++ )
677 ticks += interval.
minValue() + i * stepSize;
695 int maxMinorSteps,
double stepSize,
700 if ( minStep == 0.0 )
704 const int numTicks =
qwtCeil( qAbs( stepSize / minStep ) ) - 1;
708 medIndex = numTicks / 2;
712 for (
int i = 0; i < majorTicks.count(); i++ )
714 double val = majorTicks[i];
715 for (
int k = 0; k < numTicks; k++ )
719 double alignedValue = val;
724 mediumTicks += alignedValue;
726 minorTicks += alignedValue;
743 const QwtInterval &interval,
double stepSize )
const 751 const double eps = 0.000000000001;
754 if ( -max + stepSize <= x1 )
757 if ( qAbs(x) <= eps || !qFuzzyCompare( x1, x ) )
761 if ( max - stepSize >= x2 )
764 if ( qAbs(x) <= eps || !qFuzzyCompare( x2, x ) )
799 double &x1,
double &x2,
double &stepSize )
const 804 const double logBase =
base();
818 linearScaler.
autoScale( maxNumSteps, x1, x2, stepSize );
821 linearInterval = linearInterval.
limited(
839 interval.
setInterval( logRef / delta, logRef * delta );
843 interval = interval.
extend( logRef );
847 if ( interval.
width() == 0.0 )
851 qMax( maxNumSteps, 1 ) );
852 if ( stepSize < 1.0 )
856 interval =
align( interval, stepSize );
864 stepSize = -stepSize;
881 int maxMajorSteps,
int maxMinorSteps,
double stepSize )
const 886 if ( interval.
width() <= 0 )
889 const double logBase =
base();
901 maxMajorSteps, maxMinorSteps, 0.0 );
904 stepSize = qAbs( stepSize );
905 if ( stepSize == 0.0 )
907 if ( maxMajorSteps < 1 )
912 if ( stepSize < 1.0 )
917 if ( stepSize != 0.0 )
920 buildTicks( interval, stepSize, maxMinorSteps, ticks );
942 const QwtInterval& interval,
double stepSize,
int maxMinorSteps,
950 if ( maxMinorSteps > 0 )
957 ticks[i] =
strip( ticks[i], interval );
969 const QwtInterval &interval,
double stepSize )
const 973 int numTicks = qRound( width / stepSize ) + 1;
974 if ( numTicks > 10000 )
977 const double lxmin = std::log( interval.
minValue() );
978 const double lxmax = std::log( interval.
maxValue() );
979 const double lstep = ( lxmax - lxmin ) /
double( numTicks - 1 );
982 ticks.reserve( numTicks );
986 for (
int i = 1; i < numTicks - 1; i++ )
987 ticks += std::exp( lxmin +
double( i ) * lstep );
1005 int maxMinorSteps,
double stepSize,
1009 const double logBase =
base();
1011 if ( stepSize < 1.1 )
1014 if ( minStep == 0.0 )
1017 const int numSteps = qRound( stepSize / minStep );
1019 int mediumTickIndex = -1;
1020 if ( ( numSteps > 2 ) && ( numSteps % 2 == 0 ) )
1021 mediumTickIndex = numSteps / 2;
1023 for (
int i = 0; i < majorTicks.count() - 1; i++ )
1025 const double v = majorTicks[i];
1026 const double s = logBase / numSteps;
1030 if ( !qFuzzyCompare( s, 1.0 ) )
1031 minorTicks += v * s;
1033 for (
int j = 2; j < numSteps; j++ )
1035 minorTicks += v * j * s;
1040 for (
int j = 1; j < numSteps; j++ )
1042 const double tick = v + j * v * ( logBase - 1 ) / numSteps;
1043 if ( j == mediumTickIndex )
1044 mediumTicks += tick;
1054 if ( minStep == 0.0 )
1057 if ( minStep < 1.0 )
1061 int numTicks = qRound( stepSize / minStep ) - 1;
1065 stepSize, stepSize ) > 0 )
1073 int mediumTickIndex = -1;
1074 if ( ( numTicks > 2 ) && ( numTicks % 2 ) )
1075 mediumTickIndex = numTicks / 2;
1078 const qreal minFactor =
qwtMaxF( std::pow( logBase, minStep ), logBase );
1080 for (
int i = 0; i < majorTicks.count(); i++ )
1082 double tick = majorTicks[i];
1083 for (
int j = 0; j < numTicks; j++ )
1087 if ( j == mediumTickIndex )
1088 mediumTicks += tick;
1108 const QwtInterval &interval,
double stepSize )
const
static QwtInterval qwtLogInterval(double base, const QwtInterval &interval)
void setTransformation(QwtTransform *)
enum MQTTPropertyCodes value
QwtInterval normalized() const
Normalize the limits of the interval.
QwtLinearScaleEngine(uint base=10)
int qwtFuzzyCompare(double value1, double value2, double intervalSize)
Compare 2 values, relative to an interval.
bool testAttribute(Attribute) const
A class representing an interval.
QWT_CONSTEXPR float qwtMaxF(float a, float b)
void setMargins(double lower, double upper)
Specify margins at the scale's endpoints.
static double divideEps(double intervalSize, double numSteps)
Divide an interval into steps.
virtual QwtScaleDiv divideScale(double x1, double x2, int maxMajorSteps, int maxMinorSteps, double stepSize=0.0) const QWT_OVERRIDE
Calculate a scale division for an interval.
virtual void autoScale(int maxNumSteps, double &x1, double &x2, double &stepSize) const QWT_OVERRIDE
QwtInterval buildInterval(double value) const
Build an interval around a value.
A class representing a scale division.
long double widthL() const
Return the width of an interval as long double.
QwtTransform * transformation() const
double upperMargin() const
double lowerMargin() const
QWT_CONSTEXPR float qwtMinF(float a, float b)
static double divideInterval(double intervalSize, int numSteps, uint base)
virtual ~QwtLogScaleEngine()
Destructor.
QwtScaleEngine(uint base=10)
static double qwtLog(double base, double value)
QwtInterval limited(double lowerBound, double upperBound) const
void buildMinorTicks(const QList< double > &majorTicks, int maxMinorSteps, double stepSize, QList< double > &minorTicks, QList< double > &mediumTicks) const
Calculate minor/medium ticks for major ticks.
void setInterval(double minValue, double maxValue, BorderFlags=IncludeBorders)
virtual ~QwtLinearScaleEngine()
Destructor.
basic_reference< false > reference
bool contains(const QwtInterval &, double value) const
virtual void autoScale(int maxNumSteps, double &x1, double &x2, double &stepSize) const QWT_OVERRIDE
Number of valid tick types.
Build a scale which is symmetric to the reference() value.
static double floorEps(double value, double intervalSize)
void buildTicks(const QwtInterval &, double stepSize, int maxMinorSteps, QList< double > ticks[QwtScaleDiv::NTickTypes]) const
Calculate ticks for an interval.
virtual ~QwtScaleEngine()
Destructor.
void buildMinorTicks(const QList< double > &majorTicks, int maxMinorSteps, double stepSize, QList< double > &minorTicks, QList< double > &mediumTicks) const
Calculate minor/medium ticks for major ticks.
QFlags< Attribute > Attributes
Layout attributes.
QwtInterval align(const QwtInterval &, double stepSize) const
Align an interval to a step size.
static double qwtStepSize(double intervalSize, int maxSteps, uint base)
QList< double > strip(const QList< double > &, const QwtInterval &) const
Turn the scale upside down.
static QwtInterval qwtPowInterval(double base, const QwtInterval &interval)
void setReference(double)
Specify a reference point.
static double ceilEps(double value, double intervalSize)
Attributes attributes() const
QList< double > buildMajorTicks(const QwtInterval &interval, double stepSize) const
Calculate major ticks for an interval.
A scale engine for linear scales.
QwtInterval extend(double value) const
Extend the interval.
void buildTicks(const QwtInterval &, double stepSize, int maxMinorSteps, QList< double > ticks[QwtScaleDiv::NTickTypes]) const
Calculate ticks for an interval.
double divideInterval(double intervalSize, int numSteps) const
QwtInterval symmetrize(double value) const
QList< double > buildMajorTicks(const QwtInterval &interval, double stepSize) const
Calculate major ticks for an interval.
double width() const
Return the width of an interval.
Build a scale which includes the reference() value.
QwtScaleEngine::Attributes attributes
QwtLogScaleEngine(uint base=10)
void setAttributes(Attributes)
void setAttribute(Attribute, bool on=true)
QwtInterval align(const QwtInterval &, double stepSize) const
Align an interval to a step size.
virtual QwtScaleDiv divideScale(double x1, double x2, int maxMajorSteps, int maxMinorSteps, double stepSize=0.0) const QWT_OVERRIDE
Calculate a scale division for an interval.
Base class for scale engines.