Specialized axis ticker suited for logarithmic axes. More...
Public Functions | |
QCPAxisTickerLog () | |
double | logBase () const |
int | subTickCount () const |
void | setLogBase (double base) |
void | setSubTickCount (int subTicks) |
double | logBase () const |
int | subTickCount () const |
void | setLogBase (double base) |
void | setSubTickCount (int subTicks) |
![]() | |
QCPAxisTicker () | |
TickStepStrategy | tickStepStrategy () const |
int | tickCount () const |
double | tickOrigin () const |
void | setTickStepStrategy (TickStepStrategy strategy) |
void | setTickCount (int count) |
void | setTickOrigin (double origin) |
virtual void | generate (const QCPRange &range, const QLocale &locale, QChar formatChar, int precision, QVector< double > &ticks, QVector< double > *subTicks, QVector< QString > *tickLabels) |
TickStepStrategy | tickStepStrategy () const |
int | tickCount () const |
double | tickOrigin () const |
void | setTickStepStrategy (TickStepStrategy strategy) |
void | setTickCount (int count) |
void | setTickOrigin (double origin) |
virtual void | generate (const QCPRange &range, const QLocale &locale, QChar formatChar, int precision, QVector< double > &ticks, QVector< double > *subTicks, QVector< QString > *tickLabels) |
Protected Functions | |
virtual double | getTickStep (const QCPRange &range) |
virtual int | getSubTickCount (double tickStep) |
virtual QVector< double > | createTickVector (double tickStep, const QCPRange &range) |
virtual double | getTickStep (const QCPRange &range) |
virtual int | getSubTickCount (double tickStep) |
virtual QVector< double > | createTickVector (double tickStep, const QCPRange &range) |
![]() | |
virtual QString | getTickLabel (double tick, const QLocale &locale, QChar formatChar, int precision) |
virtual QVector< double > | createSubTickVector (int subTickCount, const QVector< double > &ticks) |
virtual QVector< QString > | createLabelVector (const QVector< double > &ticks, const QLocale &locale, QChar formatChar, int precision) |
void | trimTicks (const QCPRange &range, QVector< double > &ticks, bool keepOneOutlier) const |
double | pickClosest (double target, const QVector< double > &candidates) const |
double | getMantissa (double input, double *magnitude=0) const |
double | cleanMantissa (double input) const |
virtual QString | getTickLabel (double tick, const QLocale &locale, QChar formatChar, int precision) |
virtual QVector< double > | createSubTickVector (int subTickCount, const QVector< double > &ticks) |
virtual QVector< QString > | createLabelVector (const QVector< double > &ticks, const QLocale &locale, QChar formatChar, int precision) |
void | trimTicks (const QCPRange &range, QVector< double > &ticks, bool keepOneOutlier) const |
double | pickClosest (double target, const QVector< double > &candidates) const |
double | getMantissa (double input, double *magnitude=0) const |
double | cleanMantissa (double input) const |
Additional Inherited Members | |
![]() | |
enum | TickStepStrategy |
enum | TickStepStrategy |
Specialized axis ticker suited for logarithmic axes.
This QCPAxisTicker subclass generates ticks with unequal tick intervals suited for logarithmic axis scales. The ticks are placed at powers of the specified log base (setLogBase).
Especially in the case of a log base equal to 10 (the default), it might be desirable to have tick labels in the form of powers of ten without mantissa display. To achieve this, set the number precision (QCPAxis::setNumberPrecision) to zero and the number format (QCPAxis::setNumberFormat) to scientific (exponential) display with beautifully typeset decimal powers, so a format string of "eb"
. This will result in the following axis tick labels:
The ticker can be created and assigned to an axis like this:
QCPAxisTickerLog::QCPAxisTickerLog | ( | ) |
Constructs the ticker and sets reasonable default values. Axis tickers are commonly created managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker.
void QCPAxisTickerLog::setLogBase | ( | double | base | ) |
Sets the logarithm base used for tick coordinate generation. The ticks will be placed at integer powers of base.
void QCPAxisTickerLog::setSubTickCount | ( | int | subTicks | ) |
Sets the number of sub ticks in a tick interval. Within each interval, the sub ticks are spaced linearly to provide a better visual guide, so the sub tick density increases toward the higher tick.
Note that subTicks is the number of sub ticks (not sub intervals) in one tick interval. So in the case of logarithm base 10 an intuitive sub tick spacing would be achieved with eight sub ticks (the default). This means e.g. between the ticks 10 and 100 there will be eight ticks, namely at 20, 30, 40, 50, 60, 70, 80 and 90.
|
protectedvirtual |
Since logarithmic tick steps are necessarily different for each tick interval, this method does nothing in the case of QCPAxisTickerLog
For general information about this virtual method, see the base class implementation.
Reimplemented from QCPAxisTicker.
|
protectedvirtual |
Returns the sub tick count specified in setSubTickCount. For QCPAxisTickerLog, there is no automatic sub tick count calculation necessary.
For general information about this virtual method, see the base class implementation.
Reimplemented from QCPAxisTicker.
|
protectedvirtual |
Creates ticks with a spacing given by the logarithm base and an increasing integer power in the provided range. The step in which the power increases tick by tick is chosen in order to keep the total number of ticks as close as possible to the tick count (setTickCount). The parameter tickStep is ignored for QCPAxisTickerLog
For general information about this virtual method, see the base class implementation.
Reimplemented from QCPAxisTicker.
|
protectedvirtual |
Takes the entire currently visible axis range and returns a sensible tick step in order to provide readable tick labels as well as a reasonable number of tick counts (see setTickCount, setTickStepStrategy).
If a QCPAxisTicker subclass only wants a different tick step behaviour than the default implementation, it should reimplement this method. See cleanMantissa for a possible helper function.
Reimplemented from QCPAxisTicker.
|
protectedvirtual |
Takes the tickStep, i.e. the distance between two consecutive ticks, and returns an appropriate number of sub ticks for that specific tick step.
Note that a returned sub tick count of e.g. 4 will split each tick interval into 5 sections.
Reimplemented from QCPAxisTicker.
|
protectedvirtual |
Returns a vector containing all coordinates of ticks that should be drawn. The default implementation generates ticks with a spacing of tickStep (mathematically starting at the tick step origin, see setTickOrigin) distributed over the passed range.
In order for the axis ticker to generate proper sub ticks, it is necessary that the first and last tick coordinates returned by this method are just below/above the provided range. Otherwise the outer intervals won't contain any sub ticks.
If a QCPAxisTicker subclass needs maximal control over the generated ticks, it should reimplement this method. Depending on the purpose of the subclass it doesn't necessarily need to base its result on tickStep, e.g. when the ticks are spaced unequally like in the case of QCPAxisTickerLog.
Reimplemented from QCPAxisTicker.