JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
|
this virtual class is the base for any type of coordinate axis, to be drawn by JKQTBasePlotter. More...
#include <jkqtpcoordinateaxes.h>
Classes | |
struct | Axis0ElementsSizeDescription |
struct | AxisElementsSizeDescription |
return value type for getSize1() and getSize2() More... | |
Public Slots | |
void | resetTickUnit () |
resets tickUnitFactor and tickUnitName in one call | |
void | setAbsoluteRange (double aamin, double aamax) |
sets absolutely limiting range of the plot | |
void | setArrowSizeFactor (double f) |
factor used to calculate the size of line arrows | |
void | setAutoAxisSpacing (bool __value) |
calculated property: indicates whether the object should use automatic tick spacing for the x axis (calculated by calcPlotScaling() ) | |
void | setAxisColor (const QColor &__value) |
color of the axis (labels, ticks, axis itself ...) | |
void | setAxisLabel (const QString &__value) |
axis label of the axis | |
void | setAxisMinWidth (double __value) |
absolute minimum range width, feature switched off when <0 | |
void | setColor (QColor c) |
sets all colors (line, ticks, label, ...) of the axis | |
void | setDrawGrid (bool __value) |
indicates whether to draw the major grid lines | |
void | setDrawMinorGrid (bool __value) |
indicates whether to draw the major grid lines | |
void | setDrawMode0 (JKQTPCADrawMode __value) |
draw mode of the zero axis | |
void | setDrawMode1 (JKQTPCADrawMode __value) |
draw mode of the main (left/bottom) axis | |
void | setDrawMode2 (JKQTPCADrawMode __value) |
draw mode of the secondary (right/top) axis | |
void | setGridColor (const QColor &__value) |
color of the grid | |
void | setGridColor (const QColor &__value, double alpha) |
color of the grid | |
void | setGridStyle (Qt::PenStyle __value) |
line stye of the grid lines | |
void | setGridWidth (double __value) |
width of the grid lines (in pixel) | |
void | setInverted (bool __value) |
indicates whether the axis is to be inverted or not | |
void | setLabelColor (QColor c) |
color of the axis label | |
void | setLabelDigits (int __value) |
digits used for tick labels | |
void | setLabelDistance (double __value) |
distance between tick label and axis label in pt | |
void | setLabelFontSize (double __value) |
fontsize of the axis labels | |
void | setLabelPosition (JKQTPLabelPosition __value) |
position of the axis label | |
void | setLineWidth (double __value) |
line width of axis in pt | |
void | setLineWidthZeroAxis (double __value) |
line width of 0-line in pt | |
void | setLogAxis (bool __value) |
indicates whether the y axis has a logarithmic scale | |
void | setLogAxisBase (double __value) |
the base for a logarithmic x axis | |
void | setMax (double amax) |
set axis minimum range of plot axis | |
void | setMin (double amin) |
set axis minimum range of plot axis | |
void | setMinorGridColor (const QColor &__value) |
color of the grid | |
void | setMinorGridColor (const QColor &__value, double alpha) |
color of the grid | |
void | setMinorGridStyle (Qt::PenStyle __value) |
line stye of the grid lines | |
void | setMinorGridWidth (double __value) |
width of the grid lines (in pixel) | |
void | setMinorTickColor (QColor c) |
color of minor ticks | |
void | setMinorTickInsideLength (double __value) |
length of a minor axis tick inside the plot border in pt | |
void | setMinorTickLabelColor (QColor c) |
color of minor tick labels | |
void | setMinorTickLabelFontSize (double __value) |
fontsize of the minor axis tick labels | |
void | setMinorTickLabelFullNumber (bool __value) |
indicates whether the minor tick labels should be full numbers, or just a number between 0..10 | |
void | setMinorTickLabelsEnabled (bool __value) |
if true , the plotter displays minor axis labels as number between 1 and 10 in some cases | |
void | setMinorTickOutsideLength (double __value) |
length of a minor axis tick outside the plot border in pt | |
void | setMinorTicks (int __value) |
number of minor grid lines per (major) axis tick interval | |
void | setMinorTicks (unsigned int __value) |
number of minor grid lines per (major) axis tick interval | |
void | setMinorTickWidth (double __value) |
line width of minor ticks in pt | |
void | setMinTicks (unsigned int __value) |
minimum number of axis ticks | |
void | setNoAbsoluteRange () |
do not use an absolute range of plot axis | |
void | setRange (double amin, double amax) |
set range of plot axis | |
void | setRangeFixed (bool fixed) |
fixes/ufixes the axis | |
void | setShowZeroAxis (bool __value) |
indicates whether to draw a thick axis line at x=0 (zero axis) | |
void | setTickColor (QColor c) |
color of axis ticks | |
void | setTickDateFormat (const QString &__value) |
format string for date tick labels, see QDateTime::toString() documentation for details on format strings | |
void | setTickDateTimeFormat (const QString &__value) |
format string for datetime tick labels, see QDateTime::toString() documentation for details on format strings | |
void | setTickFormatFormat (const QString &__value) |
format string for std::format tick labels, (see e.g. https://en.cppreference.com/w/cpp/utility/format/formatter#Standard_format_specification ). The first data parameter is the tick value as double an the second is tickUnitName as string. The following image shows an example for "\\texttt{{ y={:*^+8.1f}}}" : | |
void | setTickInsideLength (double __value) |
length of an axis tick inside the plot border in pt | |
void | setTickLabelAngle (double __value) |
rotation angle of tick labels [-180..180], i.e. given in degrees, default is 0 (horizontal) | |
void | setTickLabelColor (QColor c) |
color of axis tick labels | |
void | setTickLabelDistance (double __value) |
distance between tick end and label start in pt | |
void | setTickLabelFontSize (double __value) |
fontsize of the axis tick labels | |
void | setTickLabelType (JKQTPCALabelType __value) |
indicates how to draw the labels | |
void | setTickMode (int __value) |
mode of the major ticks | |
void | setTickMode (JKQTPLabelTickMode __value) |
mode of the major ticks | |
void | setTickOutsideLength (double __value) |
length of an axis tick outside the plot border in pt | |
void | setTickPrintfFormat (const QString &__value) |
format string for printf tick labels, see https://en.wikipedia.org/wiki/Printf_format_string documentation for details on format strings The first data parameter is the tick value as double an the second is tickUnitName as string. The following image shows an example for "y=%+.2f" : | |
void | setTickTimeFormat (const QString &__value) |
format string for time tick labels, see QDateTime::toString() documentation for details on format strings | |
void | setTickUnit (double factor, const QString &name) |
sets tickUnitFactor and tickUnitName in one call | |
void | setTickUnitFactor (double __value) |
tick values are the actual x/y-coordiniate, divided by this value (e.g. pu to have an axis with values 0, pi, 2pi, 3pi ... ) | |
void | setTickUnitName (const QString &__value) |
name of the factor tickUnitFactor. This string is used in tick-labels to write e.g. "2pi" instead of 6.28... | |
void | setTickUnitPi () |
sets pi-scaling for tickUnitFactor and tickUnitName in one call | |
void | setTickWidth (double __value) |
line width of ticks in pt | |
void | setUserLogTickSpacing (double __value) |
if autoXAxisSpacing is false then this value is used for xTickSpacing. So this is the property which is editable by use of public access methods. | |
void | setUserTickSpacing (double __value) |
if autoXAxisSpacing is false then this value is used for xTickSpacing. So this is the property which is editable by use of public access methods. | |
Public Member Functions | |
JKQTPCoordinateAxis (JKQTBasePlotter *parent) | |
class constructor | |
virtual | ~JKQTPCoordinateAxis () |
class destructor | |
void | addAxisTickLabel (double x, const QString &label) |
add a new tick label to the axis | |
void | addAxisTickLabels (const double *x, const QString *label, int items) |
add a new tick label to the axis | |
void | addAxisTickLabels (const double *x, const QStringList &label) |
add a new tick label to the axis | |
void | addAxisTickLabels (const QVector< double > &x, const QString *label) |
add a new tick label to the axis | |
void | addAxisTickLabels (const QVector< double > &x, const QStringList &label) |
add a new tick label to the axis | |
void | calcPlotScaling (bool force=false) |
calculate the scaling and offset values from axis min/max values | |
void | clearAxisTickLabels () |
clear axis tick labels. This switches back to automatic labels mode for the axis. | |
virtual void | drawAxes (JKQTPEnhancedPainter &painter, int move1=0, int move2=0)=0 |
draw the axes | |
virtual void | drawGrids (JKQTPEnhancedPainter &painter)=0 |
draw grids | |
QString | floattolabel (double data) const |
convert a float to a tick label string | |
QString | floattolabel (double data, int past_comma) const |
convert a float to a tick label string with a given precision | |
double | getAbsoluteMax () const |
returns the current absolute max | |
double | getAbsoluteMin () const |
returns the current absolute min | |
double | getArrowSizeFactor () const |
factor used to calculate the size of line arrows | |
bool | getAutoAxisSpacing () const |
calculated property: indicates whether the object should use automatic tick spacing for the x axis (calculated by calcPlotScaling() ) | |
bool | getAutoLabelDigits () const |
when true , the digits of the labels are calculated automatically | |
QColor | getAxisColor () const |
color of the axis (labels, ticks, axis itself ...) | |
QString | getAxisLabel () const |
axis label of the axis | |
const JKQTPCoordinateAxisStyle & | getCurrentAxisStyle () const |
current style properties for this JKQTBasePlotter | |
bool | getDoUpdateScaling () const |
can be used to switch off calcPlotScaling() temporarily, while modifying some properties | |
bool | getDrawGrid () const |
indicates whether to draw the major grid lines | |
bool | getDrawMinorGrid () const |
indicates whether to draw the major grid lines | |
JKQTPCADrawMode | getDrawMode0 () const |
draw mode of the zero axis | |
JKQTPCADrawMode | getDrawMode1 () const |
draw mode of the main (left/bottom) axis | |
JKQTPCADrawMode | getDrawMode2 () const |
draw mode of the secondary (right/top) axis | |
QColor | getGridColor () const |
color of the grid | |
Qt::PenStyle | getGridStyle () const |
line stye of the grid lines | |
double | getGridWidth () const |
width of the grid lines (in pixel) | |
bool | getInverted () const |
indicates whether the axis is to be inverted or not | |
QColor | getLabelColor () const |
color of the axis label | |
int | getLabelDigits () const |
digits used for tick labels | |
double | getLabelDistance () const |
distance between tick label and axis label in pt | |
double | getLabelFontSize () const |
fontsize of the axis labels | |
JKQTPLabelPosition | getLabelPosition () const |
position of the axis label | |
double | getLineWidth () const |
line width of axis in pt | |
double | getLineWidthZeroAxis () const |
line width of 0-line in pt | |
bool | getLogAxis () const |
indicates whether the y axis has a logarithmic scale | |
double | getLogAxisBase () const |
the base for a logarithmic x axis | |
double | getMax () const |
returns the current max | |
double | getMin () const |
returns the current min | |
QColor | getMinorGridColor () const |
color of the grid | |
Qt::PenStyle | getMinorGridStyle () const |
line stye of the grid lines | |
double | getMinorGridWidth () const |
width of the grid lines (in pixel) | |
QColor | getMinorTickColor () const |
color of minor ticks | |
QColor | getMinorTickLabelColor () const |
color of minor tick labels | |
double | getMinorTickLabelFontSize () const |
fontsize of the minor axis tick labels | |
bool | getMinorTickLabelFullNumber () const |
indicates whether the minor tick labels should be full numbers, or just a number between 0..10 | |
bool | getMinorTickLabelsEnabled () const |
if true , the plotter displays minor axis labels as number between 1 and 10 in some cases | |
double | getMinorTickOutsideLength () const |
length of a minor axis tick outside the plot border in pt | |
unsigned int | getMinorTicks () const |
number of minor grid lines per (major) axis tick interval | |
double | getMinorTickWidth () const |
line width of minor ticks in pt | |
unsigned int | getMinTicks () const |
minimum number of axis ticks | |
JKQTBasePlotter * | getParent () |
parent plotter class | |
const JKQTBasePlotter * | getParent () const |
parent plotter class | |
virtual bool | getParentOtheraxisInverted () const =0 |
is other (perpendicular) axis inverted (needed for grids) | |
virtual double | getParentOtheraxisOffset () const =0 |
pixel offset of (perpendicular) other axis (needed for grids) | |
virtual double | getParentOtheraxisWidth () const =0 |
width of other (perpendicular) axis (needed for grids) | |
virtual double | getParentPlotOffset () const =0 |
offset of the plot in the direction of the axis | |
virtual double | getParentPlotWidth () const =0 |
width of the plot in the direction of the axis | |
bool | getShowZeroAxis () const |
indicates whether to draw a thick axis line at x=0 (zero axis) | |
virtual AxisElementsSizeDescription | getSize1 (JKQTPEnhancedPainter &painter)=0 |
returns the sizerequirement of the left/bottom axis in pixels | |
virtual AxisElementsSizeDescription | getSize2 (JKQTPEnhancedPainter &painter)=0 |
returns the size of the right/top axis in pixels | |
QColor | getTickColor () const |
color of axis ticks | |
QString | getTickDateFormat () const |
format string for date tick labels, see QDateTime::toString() documentation for details on format strings | |
QString | getTickDateTimeFormat () const |
format string for datetime tick labels, see QDateTime::toString() documentation for details on format strings | |
QString | getTickFormatfFormat () const |
format string for std::format tick labels, (see e.g. https://en.cppreference.com/w/cpp/utility/format/formatter#Standard_format_specification ). The first data parameter is the tick value as double an the second is tickUnitName as string. The following image shows an example for "\\texttt{{ y={:*^+8.1f}}}" : | |
double | getTickLabelAngle () const |
rotation angle of tick labels [-180..180], i.e. given in degrees, default is 0 (horizontal) | |
QColor | getTickLabelColor () const |
color of axis tick labels | |
double | getTickLabelDistance () const |
distance between tick end and label start in pt | |
double | getTickLabelFontSize () const |
fontsize of the axis tick labels | |
JKQTPCALabelType | getTickLabelType () const |
indicates how to draw the labels | |
JKQTPLabelTickMode | getTickMode () const |
mode of the major ticks | |
double | getTickOutsideLength () const |
length of an axis tick outside the plot border in pt | |
QString | getTickPrintfFormat () const |
format string for printf tick labels, see https://en.wikipedia.org/wiki/Printf_format_string documentation for details on format strings The first data parameter is the tick value as double an the second is tickUnitName as string. The following image shows an example for "y=%+.2f" : | |
double | getTickSpacing () const |
calculated property: axis tick spacing (calculated by calcPlotScaling() and calcTickSpacing() ) for logarithmic/linear axes. | |
QString | getTickTimeFormat () const |
format string for time tick labels, see QDateTime::toString() documentation for details on format strings | |
double | getTickUnitFactor () const |
tick values are the actual x/y-coordiniate, divided by this value (e.g. pu to have an axis with values 0, pi, 2pi, 3pi ... ) | |
QString | getTickUnitName () const |
name of the factor tickUnitFactor. This string is used in tick-labels to write e.g. "2pi" instead of 6.28... | |
double | getTickWidth () const |
line width of ticks in pt | |
double | getUserLogTickSpacing () const |
if autoXAxisSpacing is false then this value is used for xTickSpacing. So this is the property which is editable by use of public access methods. | |
double | getUserTickSpacing () const |
if autoXAxisSpacing is false then this value is used for xTickSpacing. So this is the property which is editable by use of public access methods. | |
bool | isAxisRangeFixed () const |
returns whether the axis range is fixed, i.e. may not change! | |
bool | isLinearAxis () const |
returns whether this axis uses linear scaling (is false e.g. for isLogAxis()==true) | |
bool | isLogAxis () const |
returns whether this axis uses logarithmic scaling | |
void | loadCurrentAxisStyle (const QSettings &settings, const QString &group="plot/axes/") |
replace the current style properties for this JKQTBasePlotter with properties loaded from settings | |
virtual void | loadSettings (const QSettings &settings, const QString &group=QString("plots/axes/")) |
loads the plot properties from a QSettings object | |
double | p2x (double x) const |
return x coordinate from x-pixel | |
virtual double | parentOtherAxisX2P (double x) const =0 |
calls x2p() of the other axis (or returns NAN if the other axis does not exist | |
void | saveCurrentAxisStyle (QSettings &settings, const QString &group="plot/axes/") const |
store the current style properties for this JKQTBasePlotter with properties loaded from settings | |
virtual void | saveSettings (QSettings &settings, const QString &group=QString("plots/axes/")) const |
saves the plot properties into a QSettings object. | |
void | setAutoLabelDigits (bool __value) |
when true , the digits of the labels are calculated automatically | |
void | setCurrentAxisStyle (const JKQTPCoordinateAxisStyle &style) |
replace the current style properties for this JKQTBasePlotter | |
void | setDoUpdateScaling (bool __value) |
can be used to switch off calcPlotScaling() temporarily, while modifying some properties | |
virtual void | setParent (JKQTBasePlotter *parent) |
double | x2p (double x) const |
return x-pixel coordinate from x coordinate | |
Protected Member Functions | |
double | calcLinearTickSpacing () |
calculates the tick spacing for a linear axis that spans awidth and that should show at least JKQTPCoordinateAxisStyle::minTicks JKQTPCoordinateAxisStyle::ticks. | |
int | calcLinearUnitDigits () |
Calculate the number of digits needed for the labels of an axis that starts at minval and where the tick spacing is tickSpacing. | |
double | calcLogTickSpacing () |
same as calcLinearTickSpacing(), but for logarithmic scaling | |
void | drawAxisLine (JKQTPEnhancedPainter &painter, const QLineF &l, JKQTPCADrawMode drawMode) const |
draw the axis line l (pointing from axismin to axismax) optionally decorated as specified by drawMode using JKQTPEnhancedPainter painter | |
QSizeF | getMaxTickLabelSize (JKQTPEnhancedPainter &painter, double *ascent=nullptr, double *descent=nullptr) |
calculates the maximum width and height (returned as QSize) of all tick labels. Ascent and descent may also be returned in the two additional pointer arguments- | |
bool | getNextLabel (double &x, QString &label, bool init=false) |
calculates the next label from the given parameters. | |
double | getNextLabelDistance (double x) |
returns the distance from the current tick position (x before call) to the next tick position | |
JKQTMathText * | getParentMathText () |
retun parents JKQTMathText* object | |
const JKQTMathText * | getParentMathText () const |
retun parents JKQTMathText* object | |
virtual Axis0ElementsSizeDescription | getSize0 (JKQTPEnhancedPainter &painter) |
returns the size of the zero axis in pixels, the first part of the return-value is the lhs size and the second part the rhs size | |
double | getZeroAxisPos (bool *drawZeroAxis=nullptr) |
calculate the position of the zero-axis (and whether to draw it or not) | |
virtual bool | isSecondaryAxis () const |
figures out (possibly by probing the parent JKQTBasePlotter), whether this axis is a secondary axis | |
void | redrawPlot () |
simply calls the redrawPlot method of the parent plotter class | |
Protected Attributes | |
bool | autoAxisSpacing |
calculated property: indicates whether the object should use automatic tick spacing for the x axis (calculated by calcPlotScaling() ) | |
double | axisabsoultemax |
absoulte maximum of axis (axismin/axismax xan not be set above this) | |
double | axisabsoultemin |
absoulte minimum of axis (axismin/axismax xan not be set below this) | |
QString | axisLabel |
axis label of the axis | |
double | axismax |
current view: maximum of axis | |
double | axismin |
current view: minimum of axis | |
double | axisMinWidth |
absolute minimum range width, feature switched off when <0 | |
QString | axisPrefix |
axis prefix for storage of parameters | |
bool | axisRangeFixed |
indicates whether this axis is fixed, i.e. axismin and axismax are frozen to their current values | |
JKQTPCoordinateAxisStyle | axisStyle |
current style properties for this coordinate axis instance | |
bool | doUpdateScaling |
can be used to switch off calcPlotScaling() temporarily, while modifying some properties | |
bool | inverted |
indicates whether the axis is to be inverted or not | |
bool | logAxis |
indicates whether the y axis has a logarithmic scale | |
double | logAxisBase |
the base for a logarithmic x axis | |
double | offset |
calculated property: axis offset (calculated by calcPlotScaling() ) | |
bool | paramsChanged |
indicates whether one of the parameters has changed sinse the last recalculation of tickSpacing ... | |
JKQTBasePlotter * | parent |
parent plotter class | |
double | scale |
calculated property: axis scaling factor (calculated by calcPlotScaling() ) | |
double | scaleSign |
this is used by x2p() and p2x() to determine the sign | |
QVector< QPair< double, QString > > | tickLabels |
a list of tick labels. | |
double | tickSpacing |
calculated property: axis tick spacing (calculated by calcPlotScaling() and calcTickSpacing() ) for logarithmic/linear axes. | |
double | tickSpacingLog |
calculated property: axis tick spacing for logarithmic JKQTPCoordinateAxisStyle::ticks (calculated by calcPlotScaling() and calcTickSpacing() ) axes. | |
double | tickStart |
calculated property: x position of the first tick (calculated by calcPlotScaling() ). Given in system coordinates, not pixel coordinates. | |
double | tickUnitFactor |
tick values are the actual x/y-coordiniate, divided by this value (e.g. pu to have an axis with values 0, pi, 2pi, 3pi ... ) | |
QString | tickUnitName |
name of the factor tickUnitFactor. This string is used in tick-labels to write e.g. "2pi" instead of 6.28... | |
double | userLogTickSpacing |
if autoXAxisSpacing is false then this value is used for xTickSpacing. So this is the property which is editable by use of public access methods. | |
double | userTickSpacing |
if autoXAxisSpacing is false then this value is used for xTickSpacing. So this is the property which is editable by use of public access methods. | |
double | width |
calculated property: width of plot on axis (calculated by calcPlotScaling() ) | |
this virtual class is the base for any type of coordinate axis, to be drawn by JKQTBasePlotter.
Classes derived from JKQTPCoordinateAxis implements all the functionality needed for a coordinate axis:
Most of the actual draw and measure functions have to be implemented in descendents of this class (namely JKQTPHorizontalAxis and JKQTPVerticalAxis, as they are specific to whether the axis is drawn horizontally or vertically.
Each axis is split up into several parts, as depicted in this image:
Which parts to actually draw is set by the diverse properties.
The plot itself is positioned inside the widget (see Plot Sizes & Borders for details). You simply supply the widget dimensions and the border widths between the plot and the widget. The Object then calculates the size of the plot:
The plot shows the parameter range xmin ... xmax and ymin ... ymax. Note that if you plot logarithmic plots you may only plot positive (>0) values. Any other value may lead to an error or unpredictable behaviour.
From these parameters the object calculates the scaling laws for plotting pints to the screen. The next paragraphs show all calculations for x- and y-coordinates, ahough this class only implements a generic form. The actual calculation is also influenced by the parameters set in the child classes!
width = xmax - xmin
height = ymax - ymin
plotWidth = widgetWidth - plotBorderLeft - plotBorderRight
plotHeight = widgetHeight - plotBorderTop - plotBorderBottom
xPlotOffset = plotBorderLeft
yPlotOffset = plotBorderTop
These parameters are common to all scaling laws. The next image explains these formulas:
The actual scaling laws may be derived from these equations:
Here denotes a point in pixel coordinates (green coordinate system) and denotes a point in the plotting coordinate system.
If you assume a linear scaling law.
you can derive:
If you have a logarithmic axis (i.e. we plot insetad of for a given base ) we get the same formulas, but with exchanged by . If we use the equation we finally get the scaling laws:
From these we can calculate their parameters with the same defining equations as above:
The object implements the above coordinate transformations in the (inline) method x2p(). The inverse transformations are implemented in p2x(). They can be used to show the system coordinates of the current mouse position.
In some cases it may be necessary to invert the direction of increasing coordinates on an axis. One such case is image analysis, as computer images usually have coordinates starting with (0,0) at the top left and increasing to the right (x) and down (y). You can invert any axis by setting setInverted(true)
.
This section explains how this component draws the ticks on coordinate axes and the grids that may be drawn below the plots. In principle both - grids and axes - are drawn the same way, i.e. with the same step widths. There are two types of ticks and grids: The major and the minor ticks/grids. The major ticks also show a label that denotes the value they represent. Between two major ticks the axis shows JKQTPCoordinateAxisStyle::minorTicks small ticks that are not accompanied by a label. The next image shows an example of an axis:
For the labels this class also uses an algorithm that extimates the number of valid digits (after the comma) that are needed so that two adjacent labels do not show the same text, so if you plot the range 1.10 .. 1.15 The algorithm will show at least two valid digits, as with one digit the labels would be 1.1, 1.1, 1.1, 1.1, 1.1, 1.1. With two digits they are 1.10, 1.11, 1.12, 1.13, 1.14, 1.15. The class may also use a method that can write 1m
instead of 0.001
and 1k
instead of 1000
(the algorithm supports the "exponent letters" f, p, n, u, m, k, M, G, T, P. The latter option may (de)activated by using showXExponentCharacter and showYExponentCharacter.
For grids applies the same. There are two grids that are drawn in different styles (often the major grid is drawn thicker and darker than the minor grid).
The minor ticks and grid lines are generated automatically, depending in the setting of JKQTPCoordinateAxisStyle::minorTicks. These properties give the number of minor ticks between two major ticks, so if the major ticks are at 1,2,3,... and you want minor ticks at 1.1, 1.2, 1.3,... then you will have to set JKQTPCoordinateAxisStyle::minorTicks=9
as there are nine ticks between two major ticks. So the minor tick spacing is calculated as:
The same applies for logarithmic axes. If the major ticks are at 1,10,100,... and you set JKQTPCoordinateAxisStyle::minorTicks=9
the program will generate 9 equally spaced minor ticks in between, so you have minor ticks at 2,3,4,...,11,12,13,... This results in a standard logarithmic axis. If you set JKQTPCoordinateAxisStyle::minorTicks=1
then you will get minor ticks at 5,15,150,...
The major tick-tick distances of linear axes may be calculated automatically in a way that the axis shows at least a given number of ticks JKQTPCoordinateAxisStyle::minTicks
. The algorithm takes that tick spacing that will give a number of ticks per axis nearest but ">="
to the given JKQTPCoordinateAxisStyle::minTicks
. The Algorithm is described in detail with the function calcLinearTickSpacing(). To activate this automatic tick spacing you have to set autoAxisSpacing=true
.
In some cases it is desired to put the axis ticks not at 1,2,3,... but rather at , , or any other unit than ,i.e.:
You can use these methods to set such a factor:
|
explicit |
class constructor
|
virtual |
class destructor
void JKQTPCoordinateAxis::addAxisTickLabel | ( | double | x, |
const QString & | label | ||
) |
add a new tick label to the axis
void JKQTPCoordinateAxis::addAxisTickLabels | ( | const double * | x, |
const QString * | label, | ||
int | items | ||
) |
add a new tick label to the axis
void JKQTPCoordinateAxis::addAxisTickLabels | ( | const double * | x, |
const QStringList & | label | ||
) |
add a new tick label to the axis
void JKQTPCoordinateAxis::addAxisTickLabels | ( | const QVector< double > & | x, |
const QString * | label | ||
) |
add a new tick label to the axis
void JKQTPCoordinateAxis::addAxisTickLabels | ( | const QVector< double > & | x, |
const QStringList & | label | ||
) |
add a new tick label to the axis
|
protected |
calculates the tick spacing for a linear axis that spans awidth and that should show at least JKQTPCoordinateAxisStyle::minTicks JKQTPCoordinateAxisStyle::ticks.
The algorithm used in here works as follows:
There is only a limited subset of allowed tick distances. These distances are 1 (resulting in 10 JKQTPCoordinateAxisStyle::ticks per decade, i.e. 0,1,2,3,4,...), 2 (5 JKQTPCoordinateAxisStyle::ticks/decade, i.e. 0,2,4,...), 2.5 (4 JKQTPCoordinateAxisStyle::ticks/decade, i.e. 0,2.5,5,...) and 5 (2 JKQTPCoordinateAxisStyle::ticks/decade, i.e. 0,5,10,15,...). So the axis is divided into decades that each is divided into JKQTPCoordinateAxisStyle::ticks, as defined above. With these preconditions the algorithm tries to find a tick increment which is one of the above distances multiplied by a power of 10. This increment is determined in a way, that the axis contains at least JKQTPCoordinateAxisStyle::minTicks JKQTPCoordinateAxisStyle::ticks:
false
, then the algorithm decreases the exponent and returns to step 3.
|
protected |
Calculate the number of digits needed for the labels of an axis that starts at minval and where the tick spacing is tickSpacing.
This method determines how many digits to output for the labels on a coordinate axis. This is done by testing different digit numbers and comparing subsequent labels. If two labels are equal, then we need more valid digits to distinguish them.
|
protected |
same as calcLinearTickSpacing(), but for logarithmic scaling
void JKQTPCoordinateAxis::calcPlotScaling | ( | bool | force = false | ) |
calculate the scaling and offset values from axis min/max values
This is only executed when paramChanged==true
, as otherwise the data has to be still correct. recalculating may be forced by caling calcPlotScaing(true);
void JKQTPCoordinateAxis::clearAxisTickLabels | ( | ) |
clear axis tick labels. This switches back to automatic labels mode for the axis.
|
pure virtual |
draw the axes
painter | the painter to use for drawing |
move1 | offset in pixels on the major side (horizontal: bottom, vertical: left) |
move2 | offset in pixels on the secondary side (horizontal: top, vertical: right) |
Implemented in JKQTPVerticalAxisBase, JKQTPVerticalIndependentAxis, JKQTPHorizontalAxisBase, and JKQTPHorizontalIndependentAxis.
|
protected |
draw the axis line l (pointing from axismin to axismax) optionally decorated as specified by drawMode using JKQTPEnhancedPainter painter
|
pure virtual |
draw grids
Implemented in JKQTPVerticalAxisBase, and JKQTPHorizontalAxisBase.
QString JKQTPCoordinateAxis::floattolabel | ( | double | data | ) | const |
convert a float to a tick label string
QString JKQTPCoordinateAxis::floattolabel | ( | double | data, |
int | past_comma | ||
) | const |
convert a float to a tick label string with a given precision
|
inline |
returns the current absolute max
|
inline |
returns the current absolute min
|
inline |
factor used to calculate the size of line arrows
|
inline |
calculated property: indicates whether the object should use automatic tick spacing for the x axis (calculated by calcPlotScaling() )
|
inline |
when true
, the digits of the labels are calculated automatically
|
inline |
color of the axis (labels, ticks, axis itself ...)
|
inline |
axis label of the axis
const JKQTPCoordinateAxisStyle & JKQTPCoordinateAxis::getCurrentAxisStyle | ( | ) | const |
current style properties for this JKQTBasePlotter
|
inline |
can be used to switch off calcPlotScaling() temporarily, while modifying some properties
use setDoUpdateScaling() to set this property
|
inline |
indicates whether to draw the major grid lines
|
inline |
indicates whether to draw the major grid lines
|
inline |
|
inline |
draw mode of the main (left/bottom) axis
|
inline |
draw mode of the secondary (right/top) axis
|
inline |
color of the grid
|
inline |
line stye of the grid lines
|
inline |
width of the grid lines (in pixel)
|
inline |
indicates whether the axis is to be inverted or not
|
inline |
color of the axis label
|
inline |
digits used for tick labels
|
inline |
distance between tick label and axis label in pt
|
inline |
fontsize of the axis labels
|
inline |
position of the axis label
|
inline |
line width of axis in pt
|
inline |
line width of 0-line in pt
|
inline |
indicates whether the y axis has a logarithmic scale
|
inline |
the base for a logarithmic x axis
|
inline |
returns the current max
|
protected |
calculates the maximum width and height (returned as QSize) of all tick labels. Ascent and descent may also be returned in the two additional pointer arguments-
|
inline |
returns the current min
|
inline |
color of the grid
|
inline |
line stye of the grid lines
|
inline |
width of the grid lines (in pixel)
|
inline |
color of minor ticks
|
inline |
color of minor tick labels
|
inline |
fontsize of the minor axis tick labels
|
inline |
indicates whether the minor tick labels should be full numbers, or just a number between 0..10
|
inline |
if true
, the plotter displays minor axis labels as number between 1 and 10 in some cases
|
inline |
length of a minor axis tick outside the plot border in pt
|
inline |
number of minor grid lines per (major) axis tick interval
|
inline |
line width of minor ticks in pt
|
inline |
minimum number of axis ticks
|
protected |
calculates the next label from the given parameters.
true
on success and false
if there is no more label x | before call: the position of the label for which the text should be returned (or JKQTPCoordinateAxisStyle::tickStart for first call), after call: position of the next label (given in world coordinates!) |
label | after call: text of the (input) tick label This is an empty string, if the label is not visible! |
init | call this function with init=true to obtain the first label (at JKQTPCoordinateAxisStyle::tickStart) |
|
protected |
returns the distance from the current tick position (x before call) to the next tick position
|
inline |
parent plotter class
|
inline |
parent plotter class
|
protected |
retun parents JKQTMathText* object
|
protected |
retun parents JKQTMathText* object
|
pure virtual |
is other (perpendicular) axis inverted (needed for grids)
Implemented in JKQTPVerticalAxis, JKQTPVerticalIndependentAxis, JKQTPHorizontalAxis, and JKQTPHorizontalIndependentAxis.
|
pure virtual |
pixel offset of (perpendicular) other axis (needed for grids)
Implemented in JKQTPVerticalAxis, JKQTPVerticalIndependentAxis, JKQTPHorizontalAxis, and JKQTPHorizontalIndependentAxis.
|
pure virtual |
width of other (perpendicular) axis (needed for grids)
Implemented in JKQTPVerticalAxis, JKQTPVerticalIndependentAxis, JKQTPHorizontalAxis, and JKQTPHorizontalIndependentAxis.
|
pure virtual |
offset of the plot in the direction of the axis
Implemented in JKQTPVerticalAxis, JKQTPVerticalIndependentAxis, JKQTPHorizontalAxis, and JKQTPHorizontalIndependentAxis.
|
pure virtual |
width of the plot in the direction of the axis
Implemented in JKQTPVerticalAxis, JKQTPVerticalIndependentAxis, JKQTPHorizontalAxis, and JKQTPHorizontalIndependentAxis.
|
inline |
indicates whether to draw a thick axis line at x=0 (zero axis)
|
protectedvirtual |
returns the size of the zero axis in pixels, the first part of the return-value is the lhs size and the second part the rhs size
Reimplemented in JKQTPVerticalAxisBase, and JKQTPHorizontalAxisBase.
|
pure virtual |
returns the sizerequirement of the left/bottom axis in pixels
painter | a JKQTPEnhancedPainter to use for determining sizes (the same that would be used for drawing!) |
Implemented in JKQTPVerticalAxisBase, and JKQTPHorizontalAxisBase.
|
pure virtual |
returns the size of the right/top axis in pixels
painter | a JKQTPEnhancedPainter to use for determining sizes (the same that would be used for drawing!) |
Implemented in JKQTPVerticalAxisBase, and JKQTPHorizontalAxisBase.
|
inline |
color of axis ticks
|
inline |
format string for date tick labels, see QDateTime::toString() documentation for details on format strings
|
inline |
format string for datetime tick labels, see QDateTime::toString() documentation for details on format strings
|
inline |
format string for std::format tick labels, (see e.g. https://en.cppreference.com/w/cpp/utility/format/formatter#Standard_format_specification ). The first data parameter is the tick value as double
an the second is tickUnitName as string. The following image shows an example for "\\texttt{{ y={:*^+8.1f}}}"
:
JKQtPlotter_ENABLED_CXX20=ON
if your compiler supports this.
|
inline |
rotation angle of tick labels [-180..180], i.e. given in degrees, default is 0 (horizontal)
These images show some example rotations:
|
inline |
color of axis tick labels
|
inline |
distance between tick end and label start in pt
|
inline |
fontsize of the axis tick labels
|
inline |
indicates how to draw the labels
|
inline |
mode of the major ticks
|
inline |
length of an axis tick outside the plot border in pt
|
inline |
format string for printf tick labels, see https://en.wikipedia.org/wiki/Printf_format_string documentation for details on format strings The first data parameter is the tick value as double
an the second is tickUnitName as string. The following image shows an example for "y=%+.2f"
:
|
inline |
calculated property: axis tick spacing (calculated by calcPlotScaling() and calcTickSpacing() ) for logarithmic/linear axes.
|
inline |
format string for time tick labels, see QDateTime::toString() documentation for details on format strings
|
inline |
tick values are the actual x/y-coordiniate, divided by this value (e.g. pu to have an axis with values 0, pi, 2pi, 3pi ...
)
|
inline |
name of the factor tickUnitFactor. This string is used in tick-labels to write e.g. "2pi"
instead of 6.28...
|
inline |
line width of ticks in pt
|
inline |
if autoXAxisSpacing is false
then this value is used for xTickSpacing. So this is the property which is editable by use of public access methods.
|
inline |
if autoXAxisSpacing is false
then this value is used for xTickSpacing. So this is the property which is editable by use of public access methods.
|
protected |
calculate the position of the zero-axis (and whether to draw it or not)
|
inline |
returns whether the axis range is fixed, i.e. may not change!
bool JKQTPCoordinateAxis::isLinearAxis | ( | ) | const |
returns whether this axis uses linear scaling (is false e.g. for isLogAxis()==true)
bool JKQTPCoordinateAxis::isLogAxis | ( | ) | const |
returns whether this axis uses logarithmic scaling
|
protectedvirtual |
figures out (possibly by probing the parent JKQTBasePlotter), whether this axis is a secondary axis
void JKQTPCoordinateAxis::loadCurrentAxisStyle | ( | const QSettings & | settings, |
const QString & | group = "plot/axes/" |
||
) |
replace the current style properties for this JKQTBasePlotter with properties loaded from settings
settings | the QSettings object to read from |
group | group in settings to read from |
|
virtual |
loads the plot properties from a QSettings object
|
inline |
return x coordinate from x-pixel
|
pure virtual |
calls x2p() of the other axis (or returns NAN
if the other axis does not exist
Implemented in JKQTPVerticalAxis, JKQTPVerticalIndependentAxis, JKQTPHorizontalAxis, and JKQTPHorizontalIndependentAxis.
|
protected |
simply calls the redrawPlot method of the parent plotter class
|
slot |
resets tickUnitFactor and tickUnitName in one call
void JKQTPCoordinateAxis::saveCurrentAxisStyle | ( | QSettings & | settings, |
const QString & | group = "plot/axes/" |
||
) | const |
store the current style properties for this JKQTBasePlotter with properties loaded from settings
settings | the QSettings object to write to |
group | group in settings to write to |
|
virtual |
saves the plot properties into a QSettings object.
This method only saves those properties that differ from their default value.
|
slot |
sets absolutely limiting range of the plot
The user (or programmer) cannot zoom to a viewport that is larger than the range given to this function.
aamin | absolute minimum of the axis |
aamax | absolute maximum of the axis |
|
slot |
factor used to calculate the size of line arrows
|
slot |
calculated property: indicates whether the object should use automatic tick spacing for the x axis (calculated by calcPlotScaling() )
|
inline |
when true
, the digits of the labels are calculated automatically
|
slot |
color of the axis (labels, ticks, axis itself ...)
|
slot |
axis label of the axis
|
slot |
absolute minimum range width, feature switched off when <0
|
slot |
sets all colors (line, ticks, label, ...) of the axis
void JKQTPCoordinateAxis::setCurrentAxisStyle | ( | const JKQTPCoordinateAxisStyle & | style | ) |
replace the current style properties for this JKQTBasePlotter
|
inline |
can be used to switch off calcPlotScaling() temporarily, while modifying some properties
use setDoUpdateScaling() to set this property
|
slot |
indicates whether to draw the major grid lines
|
slot |
indicates whether to draw the major grid lines
|
slot |
|
slot |
draw mode of the main (left/bottom) axis
|
slot |
draw mode of the secondary (right/top) axis
|
slot |
color of the grid
|
slot |
color of the grid
|
slot |
line stye of the grid lines
|
slot |
width of the grid lines (in pixel)
|
slot |
indicates whether the axis is to be inverted or not
|
slot |
color of the axis label
|
slot |
digits used for tick labels
|
slot |
distance between tick label and axis label in pt
|
slot |
fontsize of the axis labels
|
slot |
position of the axis label
|
slot |
line width of axis in pt
|
slot |
line width of 0-line in pt
|
slot |
indicates whether the y axis has a logarithmic scale
|
slot |
the base for a logarithmic x axis
|
slot |
set axis minimum range of plot axis
amax | new maximum |
|
slot |
set axis minimum range of plot axis
amin | new minimum |
|
slot |
color of the grid
|
slot |
color of the grid
|
slot |
line stye of the grid lines
|
slot |
width of the grid lines (in pixel)
|
slot |
color of minor ticks
|
slot |
length of a minor axis tick inside the plot border in pt
|
slot |
color of minor tick labels
|
slot |
fontsize of the minor axis tick labels
|
slot |
indicates whether the minor tick labels should be full numbers, or just a number between 0..10
|
slot |
if true
, the plotter displays minor axis labels as number between 1 and 10 in some cases
|
slot |
length of a minor axis tick outside the plot border in pt
|
slot |
number of minor grid lines per (major) axis tick interval
|
slot |
number of minor grid lines per (major) axis tick interval
|
slot |
line width of minor ticks in pt
|
slot |
minimum number of axis ticks
|
slot |
do not use an absolute range of plot axis
|
virtual |
|
slot |
set range of plot axis
amin | new minimum |
amax | new maximum |
|
slot |
fixes/ufixes the axis
a fixed axis's range (minimum/maximum) may not be changed by the user!)
|
slot |
indicates whether to draw a thick axis line at x=0 (zero axis)
|
slot |
color of axis ticks
|
slot |
format string for date tick labels, see QDateTime::toString() documentation for details on format strings
|
slot |
format string for datetime tick labels, see QDateTime::toString() documentation for details on format strings
|
slot |
format string for std::format tick labels, (see e.g. https://en.cppreference.com/w/cpp/utility/format/formatter#Standard_format_specification ). The first data parameter is the tick value as double
an the second is tickUnitName as string. The following image shows an example for "\\texttt{{ y={:*^+8.1f}}}"
:
JKQtPlotter_ENABLED_CXX20=ON
if your compiler supports this.
|
slot |
length of an axis tick inside the plot border in pt
|
slot |
rotation angle of tick labels [-180..180], i.e. given in degrees, default is 0 (horizontal)
These images show some example rotations:
|
slot |
color of axis tick labels
|
slot |
distance between tick end and label start in pt
|
slot |
fontsize of the axis tick labels
|
slot |
indicates how to draw the labels
|
slot |
mode of the major ticks
|
slot |
mode of the major ticks
|
slot |
length of an axis tick outside the plot border in pt
|
slot |
format string for printf tick labels, see https://en.wikipedia.org/wiki/Printf_format_string documentation for details on format strings The first data parameter is the tick value as double
an the second is tickUnitName as string. The following image shows an example for "y=%+.2f"
:
|
slot |
format string for time tick labels, see QDateTime::toString() documentation for details on format strings
|
slot |
sets tickUnitFactor and tickUnitName in one call
|
slot |
tick values are the actual x/y-coordiniate, divided by this value (e.g. pu to have an axis with values 0, pi, 2pi, 3pi ...
)
|
slot |
name of the factor tickUnitFactor. This string is used in tick-labels to write e.g. "2pi"
instead of 6.28...
|
slot |
sets pi-scaling for tickUnitFactor and tickUnitName in one call
|
slot |
line width of ticks in pt
|
slot |
if autoXAxisSpacing is false
then this value is used for xTickSpacing. So this is the property which is editable by use of public access methods.
|
slot |
if autoXAxisSpacing is false
then this value is used for xTickSpacing. So this is the property which is editable by use of public access methods.
|
inline |
return x-pixel coordinate from x coordinate
|
protected |
calculated property: indicates whether the object should use automatic tick spacing for the x axis (calculated by calcPlotScaling() )
|
protected |
absoulte maximum of axis (axismin/axismax xan not be set above this)
|
protected |
absoulte minimum of axis (axismin/axismax xan not be set below this)
|
protected |
axis label of the axis
|
protected |
current view: maximum of axis
|
protected |
current view: minimum of axis
|
protected |
absolute minimum range width, feature switched off when <0
|
protected |
axis prefix for storage of parameters
|
protected |
indicates whether this axis is fixed, i.e. axismin and axismax are frozen to their current values
|
protected |
current style properties for this coordinate axis instance
|
protected |
can be used to switch off calcPlotScaling() temporarily, while modifying some properties
use setDoUpdateScaling() to set this property
|
protected |
indicates whether the axis is to be inverted or not
|
protected |
indicates whether the y axis has a logarithmic scale
|
protected |
the base for a logarithmic x axis
|
protected |
calculated property: axis offset (calculated by calcPlotScaling() )
|
protected |
indicates whether one of the parameters has changed sinse the last recalculation of tickSpacing ...
|
protected |
parent plotter class
|
protected |
calculated property: axis scaling factor (calculated by calcPlotScaling() )
|
protected |
|
protected |
a list of tick labels.
If this list contains items, this class will NOT plot a standard x-axis, but only mark the positions in this list. Every item is a x-position together with the label to be plotted there. The label may contain LaTeX markup.
|
protected |
calculated property: axis tick spacing (calculated by calcPlotScaling() and calcTickSpacing() ) for logarithmic/linear axes.
|
protected |
calculated property: axis tick spacing for logarithmic JKQTPCoordinateAxisStyle::ticks (calculated by calcPlotScaling() and calcTickSpacing() ) axes.
|
protected |
calculated property: x position of the first tick (calculated by calcPlotScaling() ). Given in system coordinates, not pixel coordinates.
|
protected |
tick values are the actual x/y-coordiniate, divided by this value (e.g. pu to have an axis with values 0, pi, 2pi, 3pi ...
)
|
protected |
name of the factor tickUnitFactor. This string is used in tick-labels to write e.g. "2pi"
instead of 6.28...
|
protected |
if autoXAxisSpacing is false
then this value is used for xTickSpacing. So this is the property which is editable by use of public access methods.
|
protected |
if autoXAxisSpacing is false
then this value is used for xTickSpacing. So this is the property which is editable by use of public access methods.
|
protected |
calculated property: width of plot on axis (calculated by calcPlotScaling() )