NEW: added option to draw a zero axis to JKQTPCoordinateAxis, which draws an axis at the origin of the coordinate system

This commit is contained in:
jkriege2 2022-09-25 15:34:05 +02:00
parent e2fba9957e
commit 8855891eea
52 changed files with 581 additions and 174 deletions

View File

@ -177,6 +177,7 @@ if(JKQtPlotter_BUILD_EXAMPLES)
rgbimageplot
rgbimageplot_qt
mandelbrot
geo_coordinateaxis0
#speed
)
@ -198,6 +199,7 @@ if(JKQtPlotter_BUILD_EXAMPLES)
filledgraphs/JKQTPFilledCurveXGraph,JKQTPFilledCurveYGraph/--smallscreenshotplot
filledgraphs_errors/JKQTPFilledCurveXErrorGraph,JKQTPFilledCurveYErrorGraph/--smallscreenshotplot
evalcurve/JKQTPXYFunctionLineGraph/--smallscreenshotplot
geo_coordinateaxis0/JKQTPCoordinateAxisStyleDrawMode0
)

View File

@ -98,12 +98,15 @@ All test-projects are Qt-projects that use qmake to build. You can load them int
<tr><td> \image html geometric_small.png
<td> \subpage JKQTPlotterGeometricGraphs
<td> `JKQTPGeometricPlotElement`, `JKQTPGeoArc`, `JKQTPGeoLine`, `JKQTPGeoRectangle`, ...
<tr><td> \image html geo_arrows_small.png
<td> \subpage JKQTPlotterGeometricArrows
<td> `JKQTPGeoArrow`, ...
<tr><td> \image html geo_simple_small.png
<td> \subpage JKQTPlotterGeometricGraphsSimple
<td> `JKQTPGeoEllipse`, `JKQTPGeoArc`, `JKQTPGeoChord`, `JKQTPGeoPie`
<tr><td> \image html geo_arrows_small.png
<td> \subpage JKQTPlotterGeometricArrows
<td> `JKQTPGeoArrow`, ...
<tr><td> \image html geo_coordinateaxis0_small.png
<td> \subpage JKQTPlotterGeometricCoordinateAxis0
<td> `JKQTPCoordinateAxisStyle::drawMode0`, `JKQTPGeoPolygon`, `JKQTPGeoEllipse`
</table>
\subsection jkqtp_extut_keyaxesstyles Examples for Styling the Plot, Keys, Axes, ...

View File

@ -59,6 +59,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
JKQTPCALTprintf for general formatting with a printf-format string </li>
<li>NEW: all elements of a coordinate axis may have their own color now </li>
<li>NEW: added possibility to scale the axis ticks by a factor (e.g. pi) to generate axes with ticks <tt>0pi, 1pi, 2pi ...</tt> </li>
<li>NEW: added option to draw a zero axis to JKQTPCoordinateAxis, which draws an axis at the origin of the coordinate system </li>
</ul></li>
<li>JKQTMathText:<ul>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 KiB

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 64 KiB

After

Width:  |  Height:  |  Size: 47 KiB

View File

@ -66,6 +66,7 @@ add_subdirectory(filledgraphs_errors)
add_subdirectory(functionplot)
add_subdirectory(geo_arrows)
add_subdirectory(geo_simple)
add_subdirectory(geo_coordinateaxis0)
add_subdirectory(geometric)
add_subdirectory(imageplot)
add_subdirectory(imageplot_cimg)

View File

@ -0,0 +1,36 @@
cmake_minimum_required(VERSION 3.16)
set(EXAMPLE_NAME geo_coordinateaxis0)
set(EXENAME jkqtptest_${EXAMPLE_NAME})
message( STATUS ".. Building Example ${EXAMPLE_NAME}" )
# Set up source files
set(SOURCES ${EXAMPLE_NAME}.cpp)
set(HEADERS )
set(RESOURCES )
set(UIS )
add_executable(${EXENAME} WIN32 ${SOURCES} ${HEADERS} ${RESOURCES} ${UIS})
target_link_libraries(${EXENAME} JKQTPExampleToolsLib)
target_include_directories(${EXENAME} PRIVATE ../../lib)
if(JKQtPlotter_BUILD_STATIC_LIBS)
target_link_libraries(${EXENAME} JKQTPlotterLib)
elseif(JKQtPlotter_BUILD_SHARED_LIBS)
target_link_libraries(${EXENAME} JKQTPlotterSharedLib)
endif()
# precomiled headers to speed up compilation
if (JKQtPlotter_BUILD_WITH_PRECOMPILED_HEADERS)
target_precompile_headers(${EXENAME} REUSE_FROM jkqtptest_simpletest)
endif (JKQtPlotter_BUILD_WITH_PRECOMPILED_HEADERS)
# Installation
install(TARGETS ${EXENAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
#Installation of Qt DLLs on Windows
jkqtplotter_deployqt(${EXENAME})

View File

@ -0,0 +1,26 @@
# Example (JKQTPlotter): Plot With Axes through Origin {#JKQTPlotterGeometricCoordinateAxis0}
This example draws a coordinate system with several geomtric shapes, where the coordinate axes pass through the origin of the plot, not at the borders. Note that if you move the displayed coordinate ranges, so 0 is not in them, the axes still stick to the borders.
The source code of the main application can be found in [`geo_coordinateaxis0.cpp`](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/geo_coordinateaxis0/geo_coordinateaxis0.cpp).
Apart from the usual code to set up the graphs, the following fragment switches the "normal" axes at the borders off and the zero axis on:
```.cpp
plot.getXAxis()->setShowZeroAxis(false);
plot.getYAxis()->setShowZeroAxis(false);
plot.getXAxis()->setDrawMode1(JKQTPCADMnone);
plot.getXAxis()->setDrawMode2(JKQTPCADMnone);
plot.getXAxis()->setDrawMode0(JKQTPCADMcomplete|JKQTPCADMMaxFilledArrow);
plot.getXAxis()->setLabelPosition(JKQTPLabelMax);
plot.getXAxis()->setAxisLabel("$X$ Coordinate");
plot.getYAxis()->setDrawMode1(JKQTPCADMnone);
plot.getYAxis()->setDrawMode2(JKQTPCADMnone);
plot.getYAxis()->setDrawMode0(JKQTPCADMcomplete|JKQTPCADMMaxFilledArrow);
plot.getYAxis()->setLabelPosition(JKQTPLabelMax);
plot.getYAxis()->setAxisLabel("$Y$ Coordinate");
```
The axes are configured to have an arrow at their max end (`|JKQTPCADMMaxFilledArrow`) and the axis label is also positioned close to the axis max.
The resulting plot looks like this:
![geo_coordinateaxis0](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/geo_coordinateaxis0.png)

View File

@ -0,0 +1,75 @@
/** \example geo_coordinateaxis0.cpp
* This poriject generates a geometric plot with coordinate axes through zero
*
* \ref JKQTPlotterGeometricCoordinateAxis0
*/
#include "jkqtpexampleapplication.h"
#include <QCheckBox>
#include <QComboBox>
#include <QApplication>
#include "jkqtplotter/jkqtplotter.h"
#include "jkqtplotter/graphs/jkqtpgeometric.h"
int main(int argc, char* argv[])
{
JKQTPAppSettingController highDPIController(argc, argv);
JKQTPExampleApplication app(argc, argv);
JKQTPlotter plot;
// 4. create a graph in the plot, which plots the dataset X/Y:
JKQTPGeoPolygon* gp;
plot.addGraph(gp=new JKQTPGeoPolygon(&plot));
gp->appendPoint(1,1);
gp->appendPoint(5,1);
gp->appendPoint(3,4);
gp->setLineColor(Qt::blue);
gp->setLineWidth(1);
gp->setFillColor(QColor("lightblue"), 0.3);
plot.addGraph(gp=new JKQTPGeoPolygon(&plot));
gp->appendPoint(1,2);
gp->appendPoint(-5,1);
gp->appendPoint(-3,-2.5);
gp->appendPoint(6,-2);
gp->setLineColor(Qt::red);
gp->setFillColor(QColor("salmon"), 0.3);
gp->setLineWidth(1);
qDebug()<<gp->getPointCount();
JKQTPGeoEllipse* ell;
plot.addGraph(ell=new JKQTPGeoEllipse(&plot, QPointF(-2,3), QSizeF(7,7)));
ell->setFillColor(QColor("blue"), 0.2);
ell->setLineWidth(1);
plot.getPlotter()->setMaintainAspectRatio(true);
plot.getPlotter()->setMaintainAxisAspectRatio(false);
plot.getXAxis()->setShowZeroAxis(false);
plot.getYAxis()->setShowZeroAxis(false);
plot.getXAxis()->setDrawMode1(JKQTPCADMnone);
plot.getXAxis()->setDrawMode2(JKQTPCADMnone);
plot.getXAxis()->setDrawMode0(JKQTPCADMcomplete|JKQTPCADMMaxFilledArrow);
plot.getXAxis()->setLabelPosition(JKQTPLabelMax);
plot.getXAxis()->setAxisLabel("$X$ Coordinate");
plot.getYAxis()->setDrawMode1(JKQTPCADMnone);
plot.getYAxis()->setDrawMode2(JKQTPCADMnone);
plot.getYAxis()->setDrawMode0(JKQTPCADMcomplete|JKQTPCADMMaxFilledArrow);
plot.getYAxis()->setLabelPosition(JKQTPLabelMax);
plot.getYAxis()->setAxisLabel("$Y$ Coordinate");
// 6. autoscale the plot so the graph is contained
plot.zoomToFit();
// show plotter and make it a decent size
plot.getPlotter()->setPlotLabel(QObject::tr("Coordinate Axes Through Origin"));
plot.show();
plot.resize(290,300);
return app.exec();
}

View File

@ -314,7 +314,7 @@ void JKQTPGeoPolygon::draw(JKQTPEnhancedPainter& painter) {
painter.setPen(getLinePen(painter, parent));
painter.setBrush(getFillBrush(painter, parent));
if ((getDrawMode()==DrawAsGraphicElement) || (getParent()->getXAxis()->isLinearAxis() && getParent()->getYAxis()->isLinearAxis())) {
painter.drawPolygon(points);
painter.drawPolygon(transform(points));
} else {
// for non-linear axes, a line might not be drawn as a line, so we need to segment the line (i.e. linear function in coordinate space)
// and transform each node to draw the corresponding non-linear curve in pixel-space!

View File

@ -458,7 +458,7 @@ void JKQTBasePlotter::setMaintainAspectRatio(bool value) {
void JKQTBasePlotter::setMaintainAxisAspectRatio(bool value) {
maintainAxisAspectRatio=value;
setAspectRatio(axisAspectRatio);
setAspectRatio(aspectRatio);
redrawPlot();
}

View File

@ -949,12 +949,27 @@ void JKQTPCoordinateAxis::setGridColor(const QColor& __value) {
redrawPlot();
}
void JKQTPCoordinateAxis::setGridColor(const QColor &__value, double alpha)
{
this->axisStyle.majorGridStyle.lineColor = __value;
this->axisStyle.majorGridStyle.lineColor.setAlphaF(alpha);
this->paramsChanged=true;
redrawPlot();
}
void JKQTPCoordinateAxis::setMinorGridColor(const QColor& __value) {
this->axisStyle.minorGridStyle.lineColor = __value;
this->paramsChanged=true;
redrawPlot();
}
void JKQTPCoordinateAxis::setMinorGridColor(const QColor& __value, double alpha) {
this->axisStyle.minorGridStyle.lineColor = __value;
this->axisStyle.minorGridStyle.lineColor.setAlphaF(alpha);
this->paramsChanged=true;
redrawPlot();
}
void JKQTPCoordinateAxis::setGridWidth(double __value) {
this->axisStyle.majorGridStyle.lineWidth = __value;
this->paramsChanged=true;
@ -985,6 +1000,13 @@ void JKQTPCoordinateAxis::setDrawMode1(JKQTPCADrawMode __value) {
redrawPlot();
}
void JKQTPCoordinateAxis::setDrawMode0(JKQTPCADrawMode __value)
{
this->axisStyle.drawMode0 = __value;
this->paramsChanged=true;
redrawPlot();
}
void JKQTPCoordinateAxis::setDrawMode2(JKQTPCADrawMode __value) {
this->axisStyle.drawMode2 = __value;
this->paramsChanged=true;
@ -1088,6 +1110,11 @@ void JKQTPCoordinateAxis::setTickLabelColor(QColor c) {
redrawPlot();
}
std::pair<QSizeF,QSizeF> JKQTPCoordinateAxis::getSize0(JKQTPEnhancedPainter &/*painter*/)
{
return std::pair<QSizeF,QSizeF>(QSizeF(0,0),QSizeF(0,0));
}
void JKQTPCoordinateAxis::setAbsoluteRange(double amin, double amax) {
axisabsoultemin=std::min(amin, amax);
@ -1204,6 +1231,15 @@ void JKQTPCoordinateAxis::drawAxisLine(JKQTPEnhancedPainter& painter, const QLin
st2, arrowSize);
}
double JKQTPCoordinateAxis::getZeroAxisPos(bool *drawZeroAxis) {
double zeroaxispos=0;
if (axisStyle.drawMode0!=JKQTPCADMnone) {
zeroaxispos=qBound(getParentOtheraxisOffset(), parentOtherAxisX2P(0), getParentOtheraxisOffset()+getParentOtheraxisWidth());
if(drawZeroAxis) *drawZeroAxis=true;
}
return zeroaxispos;
}
@ -1230,6 +1266,36 @@ double JKQTPVerticalAxis::getParentPlotOffset() const {
return parent->getInternalPlotBorderTop();
}
std::pair<QSizeF,QSizeF> JKQTPVerticalAxis::getSize0(JKQTPEnhancedPainter& painter) {
if (axisStyle.drawMode0==JKQTPCADMnone) return std::pair<QSizeF,QSizeF>(QSizeF(0,0),QSizeF(0,0));
double ptwidth=0;
double ptwidth_r=0;
const double arrowSize=((axisStyle.drawMode0&(JKQTPCADMMinArrow|JKQTPCADMMinFilledArrow|JKQTPCADMMaxArrow|JKQTPCADMMaxFilledArrow))!=int(0))?(axisStyle.getArrowSize(painter, parent)/2.0):0.0;
double labwidth=0;
if (axisStyle.drawMode0.testFlag(JKQTPCADMTicks)) { ptwidth+=axisStyle.tickOutsideLength; ptwidth_r+=axisStyle.tickInsideLength; }
if (axisStyle.drawMode0.testFlag(JKQTPCADMTickLabels)) {
ptwidth+=axisStyle.tickLabelDistance;
// find out the maximum width over all visible plot labels
labwidth+=getMaxTickLabelSize(painter).width();
}
if (axisStyle.drawMode0.testFlag(JKQTPCADMAxisLabel)) {
ptwidth+=axisStyle.labelDistance;
// find out size of axis label
labwidth+=parent->getTextSizeSize(getParent()->getCurrentPlotterStyle().defaultFontName, axisStyle.labelFontSize*parent->getFontSizeMultiplier(), axisLabel, painter).height();
}
const double zaxispos=getZeroAxisPos();
const double bottom=x2p(axismin);
const double bottom_offset=(bottom-zaxispos);
const double top=x2p(axismax);
const double top_offset=(zaxispos-top);
const QSizeF s1(qMax(0.0,qMax(parent->pt2px(painter, ptwidth)+labwidth, arrowSize)-bottom_offset), getParentPlotWidth());
const QSizeF s2(qMax(0.0,qMax(parent->pt2px(painter, ptwidth_r), arrowSize)-top_offset), getParentPlotWidth());
qDebug()<<"JKQTPVerticalAxis::getSize0(): s1="<<s1<<", s2="<<s2<<", bottom_offset="<<bottom_offset<<", top_offset="<<top_offset<<" top="<<top<<", bottom="<<bottom<<", zaxispos="<<zaxispos;
return std::pair<QSizeF,QSizeF>(s1,s2);
}
QSizeF JKQTPVerticalAxis::getSize1(JKQTPEnhancedPainter& painter) {
if (axisStyle.drawMode1==JKQTPCADMnone) return QSize(0,0);
double ptwidth=axisStyle.axisLineOffset;
@ -1247,7 +1313,7 @@ QSizeF JKQTPVerticalAxis::getSize1(JKQTPEnhancedPainter& painter) {
labwidth+=parent->getTextSizeSize(getParent()->getCurrentPlotterStyle().defaultFontName, axisStyle.labelFontSize*parent->getFontSizeMultiplier(), axisLabel, painter).height();
}
return QSizeF(qMax(parent->pt2px(painter, ptwidth)+labwidth, arrowSize), getParentPlotWidth());
return QSizeF(qMax(parent->pt2px(painter, ptwidth)+labwidth, arrowSize), getParentPlotWidth()).expandedTo(getSize0(painter).first);
}
QSizeF JKQTPVerticalAxis::getSize2(JKQTPEnhancedPainter& painter) {
@ -1267,7 +1333,7 @@ QSizeF JKQTPVerticalAxis::getSize2(JKQTPEnhancedPainter& painter) {
labwidth+=parent->getTextSizeSize(getParent()->getCurrentPlotterStyle().defaultFontName, axisStyle.labelFontSize*parent->getFontSizeMultiplier(), axisLabel, painter).height();
}
return QSizeF(qMax(arrowSize, parent->pt2px(painter, ptwidth)+labwidth), getParentPlotWidth());
return QSizeF(qMax(arrowSize, parent->pt2px(painter, ptwidth)+labwidth), getParentPlotWidth()).expandedTo(getSize0(painter).second);
}
@ -1275,6 +1341,10 @@ double JKQTPVerticalAxis::getParentOtheraxisOffset() const {
return parent->x2p(parent->getXMin());
}
double JKQTPVerticalAxis::parentOtherAxisX2P(double x) const
{
return parent->x2p(x);
}
double JKQTPVerticalAxis::getParentOtheraxisWidth() const {
return fabs(parent->x2p(parent->getXMax())-parent->x2p(parent->getXMin()));
@ -1369,34 +1439,32 @@ void JKQTPVerticalAxis::drawTickLabel1(JKQTPEnhancedPainter &painter, double xx,
getParentMathText()->parse(label);
double width, ascent, descent, strikeoutPos;
getParentMathText()->getSizeDetail(painter, width, ascent, descent, strikeoutPos);
if (axisStyle.drawMode1.testFlag(JKQTPCADMTickLabels)) {
double lx=xx-parent->pt2px(painter, labelOffset)-width;
if (axisStyle.tickLabelAngle==90) {
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
painter.translate(lx+width-1.25*strikeoutPos, yy-width/2.0);
double lx=xx-parent->pt2px(painter, labelOffset)-width;
if (axisStyle.tickLabelAngle==90) {
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
painter.translate(lx+width-1.25*strikeoutPos, yy-width/2.0);
painter.rotate(axisStyle.tickLabelAngle);
getParentMathText()->draw(painter, 0,0, parent->getCurrentPlotterStyle().debugShowTextBoxes);
} else if (axisStyle.tickLabelAngle==-90) {
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
painter.translate(lx+width-0.25*strikeoutPos, yy+width/2.0);
painter.rotate(axisStyle.tickLabelAngle);
getParentMathText()->draw(painter, 0,0, parent->getCurrentPlotterStyle().debugShowTextBoxes);
} else if (axisStyle.tickLabelAngle!=0) {
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
if (axisStyle.tickLabelAngle>0) {
painter.translate(lx-strikeoutPos+(width)*(1.0-cos(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI)), yy+strikeoutPos-width*sin(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI));
painter.rotate(axisStyle.tickLabelAngle);
getParentMathText()->draw(painter, 0,0, parent->getCurrentPlotterStyle().debugShowTextBoxes);
} else if (axisStyle.tickLabelAngle==-90) {
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
painter.translate(lx+width-0.25*strikeoutPos, yy+width/2.0);
painter.rotate(axisStyle.tickLabelAngle);
getParentMathText()->draw(painter, 0,0, parent->getCurrentPlotterStyle().debugShowTextBoxes);
} else if (axisStyle.tickLabelAngle!=0) {
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
if (axisStyle.tickLabelAngle>0) {
painter.translate(lx-strikeoutPos+(width)*(1.0-cos(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI)), yy+strikeoutPos-width*sin(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI));
painter.rotate(axisStyle.tickLabelAngle);
} else {
painter.translate(lx+strikeoutPos+(width-strikeoutPos)*(1.0-cos(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI)), yy+strikeoutPos+width*sin(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI));
painter.rotate(axisStyle.tickLabelAngle);
}
getParentMathText()->draw(painter, 0,0, parent->getCurrentPlotterStyle().debugShowTextBoxes);
} else {
getParentMathText()->draw(painter, lx, yy+strikeoutPos, parent->getCurrentPlotterStyle().debugShowTextBoxes);
painter.translate(lx+strikeoutPos+(width-strikeoutPos)*(1.0-cos(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI)), yy+strikeoutPos+width*sin(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI));
painter.rotate(axisStyle.tickLabelAngle);
}
getParentMathText()->draw(painter, 0,0, parent->getCurrentPlotterStyle().debugShowTextBoxes);
} else {
getParentMathText()->draw(painter, lx, yy+strikeoutPos, parent->getCurrentPlotterStyle().debugShowTextBoxes);
}
}
@ -1411,42 +1479,41 @@ void JKQTPVerticalAxis::drawTickLabel2(JKQTPEnhancedPainter &painter, double xx,
double width, ascent, descent, strikeoutPos;
getParentMathText()->getSizeDetail(painter, width, ascent, descent, strikeoutPos);
if (axisStyle.drawMode2.testFlag(JKQTPCADMTickLabels)) {
double lx=xx+parent->pt2px(painter, labelOffset);
if (axisStyle.tickLabelAngle==90) {
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
painter.translate(lx+descent, yy-width/2.0);
painter.rotate(axisStyle.tickLabelAngle);
getParentMathText()->draw(painter, 0,0, parent->getCurrentPlotterStyle().debugShowTextBoxes);
double lx=xx+parent->pt2px(painter, labelOffset);
if (axisStyle.tickLabelAngle==90) {
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
painter.translate(lx+descent, yy-width/2.0);
painter.rotate(axisStyle.tickLabelAngle);
getParentMathText()->draw(painter, 0,0, parent->getCurrentPlotterStyle().debugShowTextBoxes);
} else if (axisStyle.tickLabelAngle==-90) {
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
painter.translate(lx+ascent, yy+width/2.0);
painter.rotate(axisStyle.tickLabelAngle);
getParentMathText()->draw(painter, 0,0, parent->getCurrentPlotterStyle().debugShowTextBoxes);
} else if (axisStyle.tickLabelAngle!=0) {
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
double shiftx=0;
if (axisStyle.tickLabelAngle>0) {
shiftx=strikeoutPos*sin(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI);
} else {
}
painter.translate(lx+shiftx, yy+strikeoutPos);
painter.rotate(-axisStyle.tickLabelAngle);
getParentMathText()->draw(painter, 0,0, parent->getCurrentPlotterStyle().debugShowTextBoxes);
} else if (axisStyle.tickLabelAngle==-90) {
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
painter.translate(lx+ascent, yy+width/2.0);
painter.rotate(axisStyle.tickLabelAngle);
getParentMathText()->draw(painter, 0,0, parent->getCurrentPlotterStyle().debugShowTextBoxes);
} else if (axisStyle.tickLabelAngle!=0) {
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
double shiftx=0;
if (axisStyle.tickLabelAngle>0) {
shiftx=strikeoutPos*sin(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI);
} else {
getParentMathText()->draw(painter, lx, yy+strikeoutPos, parent->getCurrentPlotterStyle().debugShowTextBoxes);
}
painter.translate(lx+shiftx, yy+strikeoutPos);
painter.rotate(-axisStyle.tickLabelAngle);
getParentMathText()->draw(painter, 0,0, parent->getCurrentPlotterStyle().debugShowTextBoxes);
} else {
getParentMathText()->draw(painter, lx, yy+strikeoutPos, parent->getCurrentPlotterStyle().debugShowTextBoxes);
}
}
void JKQTPVerticalAxis::drawAxisLabel1(JKQTPEnhancedPainter &painter, double left, double bottom, QSizeF labelMax) {
void JKQTPVerticalAxis::drawAxisLabel1(JKQTPEnhancedPainter &painter, double left, double bottom, QSizeF labelMax, JKQTPCADrawMode drawMode) {
double labelOffset=parent->pt2px(painter, axisStyle.labelDistance);
if (axisStyle.drawMode1.testFlag(JKQTPCADMTicks)) labelOffset+=parent->pt2px(painter, axisStyle.tickOutsideLength);
if (axisStyle.drawMode1.testFlag(JKQTPCADMTickLabels)) {
if (drawMode.testFlag(JKQTPCADMTicks)) labelOffset+=parent->pt2px(painter, axisStyle.tickOutsideLength);
if (drawMode.testFlag(JKQTPCADMTickLabels)) {
labelOffset+=parent->pt2px(painter, axisStyle.tickLabelDistance);
labelOffset+=labelMax.width();//+labelMax.height();
}
@ -1489,10 +1556,10 @@ void JKQTPVerticalAxis::drawAxisLabel1(JKQTPEnhancedPainter &painter, double lef
painter.resetTransform();
}
void JKQTPVerticalAxis::drawAxisLabel2(JKQTPEnhancedPainter &painter, double right, double bottom, QSizeF labelMax) {
void JKQTPVerticalAxis::drawAxisLabel2(JKQTPEnhancedPainter &painter, double right, double bottom, QSizeF labelMax, JKQTPCADrawMode drawMode) {
double labelOffset=parent->pt2px(painter, axisStyle.labelDistance);
if (axisStyle.drawMode2.testFlag(JKQTPCADMTicks)) labelOffset+=parent->pt2px(painter, axisStyle.tickOutsideLength);
if (axisStyle.drawMode2.testFlag(JKQTPCADMTickLabels)) {
if (drawMode.testFlag(JKQTPCADMTicks)) labelOffset+=parent->pt2px(painter, axisStyle.tickOutsideLength);
if (drawMode.testFlag(JKQTPCADMTickLabels)) {
labelOffset+=parent->pt2px(painter, axisStyle.tickLabelDistance);
labelOffset+=labelMax.width();//+labelMax.height();
}
@ -1576,6 +1643,12 @@ void JKQTPVerticalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
ticklabelOffset2PT+=axisStyle.tickOutsideLength;
minorticklabelOffset2PT+=axisStyle.minorTickOutsideLength;
}
double ticklabelOffset0PT=axisStyle.tickLabelDistance; // offset of tick labels from axis 0
double minorticklabelOffset0PT=axisStyle.tickLabelDistance; // offset ofminor tick labels from axis 0
if (axisStyle.drawMode0.testFlag(JKQTPCADMTicks)) {
ticklabelOffset0PT+=axisStyle.tickOutsideLength;
minorticklabelOffset0PT+=axisStyle.minorTickOutsideLength;
}
//qDebug()<<"JKQTPVerticalAxis:";
//qDebug()<<" left="<<left;
@ -1619,6 +1692,10 @@ void JKQTPVerticalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
if (l.length()>0) painter.drawLine(l);
}
// axis 0 properties
bool drawZeroAxis=false;
const double zeroaxispos=getZeroAxisPos(&drawZeroAxis);
painter.setPen(pmain);
painter.setBrush(pmain.color());
@ -1631,6 +1708,10 @@ void JKQTPVerticalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
const QLineF l(right, x2p(axismin), right, x2p(axismax));
drawAxisLine(painter, l, axisStyle.drawMode1);
}
if (axisStyle.drawMode0.testFlag(JKQTPCADMLine)) {
const QLineF l(zeroaxispos, x2p(axismin), zeroaxispos, x2p(axismax));
drawAxisLine(painter, l, axisStyle.drawMode0);
}
painter.setBrush(Qt::NoBrush);
// plot minor and major ticks + tick labels
@ -1642,8 +1723,8 @@ void JKQTPVerticalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
int cnt=0;
const double arrowFreeSpace=axisStyle.getArrowSize(painter, parent)*1.2;
QVector<QLineF> lines_ptick, lines_ptick2;
QVector<QLineF> lines_pmtick, lines_pmtick2;
QVector<QLineF> lines_ptick, lines_ptick2, lines_ptick0;
QVector<QLineF> lines_pmtick, lines_pmtick2, lines_pmtick0;
{
#ifdef JKQTBP_AUTOTIMER
@ -1653,7 +1734,7 @@ void JKQTPVerticalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
const double mtdist=getNextLabelDistance(y)/static_cast<double>(axisStyle.minorTicks+1); // distance of minor ticks
const double yy=x2p(y); // y tick position
//qDebug()<<" tick @ x="<<x<<" label="<<label<<" mtdist="<<mtdist;
if (!(((axisStyle.drawMode1&(JKQTPCADMMinArrow|JKQTPCADMMinFilledArrow|JKQTPCADMMaxArrow|JKQTPCADMMaxFilledArrow))!=int(0))||((axisStyle.drawMode2&(JKQTPCADMMinArrow|JKQTPCADMMinFilledArrow|JKQTPCADMMaxArrow|JKQTPCADMMaxFilledArrow))!=int(0)))
if (!(((axisStyle.drawMode1&(JKQTPCADMMinArrow|JKQTPCADMMinFilledArrow|JKQTPCADMMaxArrow|JKQTPCADMMaxFilledArrow))!=int(0))||((axisStyle.drawMode2&(JKQTPCADMMinArrow|JKQTPCADMMinFilledArrow|JKQTPCADMMaxArrow|JKQTPCADMMaxFilledArrow))!=int(0))||((axisStyle.drawMode0&(JKQTPCADMMinArrow|JKQTPCADMMinFilledArrow|JKQTPCADMMaxArrow|JKQTPCADMMaxFilledArrow))!=int(0)))
|| (yy>top+arrowFreeSpace && yy<bottom-arrowFreeSpace)) {
// calculate tick lines for axis 1
@ -1665,11 +1746,17 @@ void JKQTPVerticalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
// calculate tick lines for axis 2
if (axisStyle.drawMode2.testFlag(JKQTPCADMTicks)&&(y<=axismax) && (y>=axismin)) {
const QLineF l(right+parent->pt2px(painter, axisStyle.tickOutsideLength), yy, right-parent->pt2px(painter, axisStyle.tickInsideLength), yy);
if (l.length()>0) lines_ptick.append(l);
if (l.length()>0) lines_ptick2.append(l);
}
// calculate tick lines for axis 0
if (axisStyle.drawMode0.testFlag(JKQTPCADMTicks)&&(y<=axismax) && (y>=axismin)) {
const QLineF l(zeroaxispos-parent->pt2px(painter, axisStyle.tickOutsideLength), yy, zeroaxispos+parent->pt2px(painter, axisStyle.tickInsideLength), yy);
if (l.length()>0) lines_ptick0.append(l);
}
// calculate minor ticks and draw minor tick labels
if (axisStyle.drawMode1.testFlag(JKQTPCADMTicks)||axisStyle.drawMode1.testFlag(JKQTPCADMTickLabels)||axisStyle.drawMode2.testFlag(JKQTPCADMTicks)||axisStyle.drawMode2.testFlag(JKQTPCADMTickLabels)) {
if (axisStyle.drawMode1.testFlag(JKQTPCADMTicks)||axisStyle.drawMode1.testFlag(JKQTPCADMTickLabels)||axisStyle.drawMode2.testFlag(JKQTPCADMTicks)||axisStyle.drawMode2.testFlag(JKQTPCADMTickLabels)||axisStyle.drawMode0.testFlag(JKQTPCADMTicks)||axisStyle.drawMode0.testFlag(JKQTPCADMTickLabels)) {
// minor ticks only if no user-defined tickLabels were set and if minor ticks are actiavted (i.e. minorTicks>0)
if ((tickLabels.size()<=0) && (axisStyle.minorTicks>0)) {
double my=y+mtdist; // location of first minor tick
@ -1698,12 +1785,18 @@ void JKQTPVerticalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
const QLineF l(right+parent->pt2px(painter, axisStyle.minorTickOutsideLength), my_pix, right-parent->pt2px(painter, axisStyle.minorTickInsideLength), my_pix);
if (l.length()>0) lines_pmtick.append(l);
}
// calculate minor tick lines, axis 0
if (axisStyle.minorTicks>0&&axisStyle.drawMode0.testFlag(JKQTPCADMTicks)) {
const QLineF l(zeroaxispos-parent->pt2px(painter, axisStyle.minorTickOutsideLength), my_pix, zeroaxispos+parent->pt2px(painter, axisStyle.minorTickInsideLength), my_pix);
if (l.length()>0) lines_pmtick.append(l);
}
// draw minor tick label, axis 1
if (axisStyle.minorTickLabelsEnabled&&axisStyle.minorTicks>0&&(axisStyle.drawMode1.testFlag(JKQTPCADMTickLabels)||axisStyle.drawMode2.testFlag(JKQTPCADMTickLabels))) {
if (axisStyle.minorTickLabelsEnabled&&axisStyle.minorTicks>0&&(axisStyle.drawMode1.testFlag(JKQTPCADMTickLabels)||axisStyle.drawMode2.testFlag(JKQTPCADMTickLabels)||axisStyle.drawMode0.testFlag(JKQTPCADMTickLabels))) {
double val= my/pow(logAxisBase,floor(log(my)/log(logAxisBase)));
if (axisStyle.minorTickLabelFullNumber) val=my;
const QString minorlabel=floattolabel(val);
if (axisStyle.drawMode0.testFlag(JKQTPCADMTickLabels)) drawTickLabel1(painter, zeroaxispos, my_pix, minorticklabelOffset0PT, minorlabel, axisStyle.minorTickLabelFontSize, true);
if (axisStyle.drawMode1.testFlag(JKQTPCADMTickLabels)) drawTickLabel1(painter, left, my_pix, minorticklabelOffset1PT, minorlabel, axisStyle.minorTickLabelFontSize, true);
if (axisStyle.drawMode2.testFlag(JKQTPCADMTickLabels)) drawTickLabel2(painter, right, my_pix, minorticklabelOffset2PT, minorlabel, axisStyle.minorTickLabelFontSize, true);
}
@ -1714,6 +1807,7 @@ void JKQTPVerticalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
}
if (!label.isEmpty() && (y<=axismax && y>=axismin)) {
if (axisStyle.drawMode0.testFlag(JKQTPCADMTickLabels)) drawTickLabel1(painter, zeroaxispos, yy, ticklabelOffset0PT, label, this->axisStyle.tickLabelFontSize, false);
if (axisStyle.drawMode1.testFlag(JKQTPCADMTickLabels)) drawTickLabel1(painter, left, yy, ticklabelOffset1PT, label, this->axisStyle.tickLabelFontSize, false);
if (axisStyle.drawMode2.testFlag(JKQTPCADMTickLabels)) drawTickLabel2(painter, right, yy, ticklabelOffset2PT, label, this->axisStyle.tickLabelFontSize, false);
}
@ -1738,6 +1832,12 @@ void JKQTPVerticalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
painter.setPen(pmtick);
painter.drawLines(lines_pmtick2);
}
if (axisStyle.drawMode0.testFlag(JKQTPCADMTicks)) {
painter.setPen(ptick);
painter.drawLines(lines_ptick0);
painter.setPen(pmtick);
painter.drawLines(lines_pmtick0);
}
}
// plot axis label
@ -1745,13 +1845,19 @@ void JKQTPVerticalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
#ifdef JKQTBP_AUTOTIMER
JKQTPAutoOutputTimer jkaati(QString("JKQTPEnhancedPainter[%1]::drawAxes(): axisLabel1").arg(objectName()));
#endif
drawAxisLabel1(painter, left, bottom, labelMax);
drawAxisLabel1(painter, left, bottom, labelMax, axisStyle.drawMode1);
}
if (!axisLabel.isEmpty() && axisStyle.drawMode0.testFlag(JKQTPCADMAxisLabel)) {
#ifdef JKQTBP_AUTOTIMER
JKQTPAutoOutputTimer jkaati(QString("JKQTPEnhancedPainter[%1]::drawAxes(): axisLabel0").arg(objectName()));
#endif
drawAxisLabel1(painter, zeroaxispos, bottom, labelMax,axisStyle.drawMode0);
}
if (!axisLabel.isEmpty() && axisStyle.drawMode2.testFlag(JKQTPCADMAxisLabel)) {
#ifdef JKQTBP_AUTOTIMER
JKQTPAutoOutputTimer jkaati(QString("JKQTPEnhancedPainter[%1]::drawAxes(): axisLabel2").arg(objectName()));
#endif
drawAxisLabel2(painter, right, bottom, labelMax);
drawAxisLabel2(painter, right, bottom, labelMax,axisStyle.drawMode2);
}
@ -1844,6 +1950,10 @@ double JKQTPVerticalIndependentAxis::getParentOtheraxisOffset() const {
}
double JKQTPVerticalIndependentAxis::parentOtherAxisX2P(double x) const
{
return qQNaN();
}
@ -1873,6 +1983,36 @@ double JKQTPHorizontalAxis::getParentPlotOffset() const {
return parent->getInternalPlotBorderLeft();
}
std::pair<QSizeF,QSizeF> JKQTPHorizontalAxis::getSize0(JKQTPEnhancedPainter& painter) {
if (axisStyle.drawMode0==JKQTPCADMnone) return std::pair<QSizeF,QSizeF>(QSizeF(0,0),QSizeF(0,0));
double ptheight=0;
double ptheight_t=0;
const double arrowSize=((axisStyle.drawMode1&(JKQTPCADMMinArrow|JKQTPCADMMinFilledArrow|JKQTPCADMMaxArrow|JKQTPCADMMaxFilledArrow))!=int(0))?(axisStyle.getArrowSize(painter, parent)/2.0):0.0;
double labheight=0;
if (axisStyle.drawMode1.testFlag(JKQTPCADMTicks)) { ptheight+=axisStyle.tickOutsideLength; ptheight_t+=axisStyle.tickOutsideLength; }
if (axisStyle.drawMode1.testFlag(JKQTPCADMTickLabels)) {
ptheight+=axisStyle.tickLabelDistance;
// find out the maximum width over all visible plot labels
labheight+=getMaxTickLabelSize(painter).height();
}
if (axisStyle.drawMode1.testFlag(JKQTPCADMAxisLabel)) {
ptheight+=axisStyle.labelDistance;
// find out size of axis label
labheight+=parent->getTextSizeSize(getParent()->getCurrentPlotterStyle().defaultFontName, axisStyle.labelFontSize*parent->getFontSizeMultiplier(), axisLabel, painter).height();
}
const double zaxispos=getZeroAxisPos();
const double left=x2p(axismin);
const double left_offset=zaxispos-left;
const double right=x2p(axismax);
const double right_offset=right-zaxispos;
return std::pair<QSizeF,QSizeF>(
QSizeF(getParentPlotWidth(), qMax(0.0,qMax(arrowSize,parent->pt2px(painter, ptheight)+labheight)-left_offset)),
QSizeF(getParentPlotWidth(), qMax(0.0,qMax(arrowSize,parent->pt2px(painter, ptheight_t))-right_offset))
);
}
QSizeF JKQTPHorizontalAxis::getSize1(JKQTPEnhancedPainter& painter) {
if (axisStyle.drawMode1==JKQTPCADMnone) return QSize(0,0);
double ptheight=axisStyle.axisLineOffset;
@ -1890,7 +2030,7 @@ QSizeF JKQTPHorizontalAxis::getSize1(JKQTPEnhancedPainter& painter) {
labheight+=parent->getTextSizeSize(getParent()->getCurrentPlotterStyle().defaultFontName, axisStyle.labelFontSize*parent->getFontSizeMultiplier(), axisLabel, painter).height();
}
return QSizeF(getParentPlotWidth(), qMax(arrowSize,parent->pt2px(painter, ptheight)+labheight));
return QSizeF(getParentPlotWidth(), qMax(arrowSize,parent->pt2px(painter, ptheight)+labheight)).expandedTo(getSize0(painter).first);
}
QSizeF JKQTPHorizontalAxis::getSize2(JKQTPEnhancedPainter& painter) {
@ -1910,7 +2050,7 @@ QSizeF JKQTPHorizontalAxis::getSize2(JKQTPEnhancedPainter& painter) {
labheight+=parent->getTextSizeSize(getParent()->getCurrentPlotterStyle().defaultFontName, axisStyle.labelFontSize*parent->getFontSizeMultiplier(), axisLabel, painter).height();
}
return QSizeF(getParentPlotWidth(), qMax(arrowSize,parent->pt2px(painter, ptheight)+labheight));
return QSizeF(getParentPlotWidth(), qMax(arrowSize,parent->pt2px(painter, ptheight)+labheight)).expandedTo(getSize0(painter).second);
}
@ -1918,7 +2058,10 @@ double JKQTPHorizontalAxis::getParentOtheraxisOffset() const {
return parent->y2p(parent->getYMax());
}
double JKQTPHorizontalAxis::parentOtherAxisX2P(double x) const
{
return parent->y2p(x);
}
double JKQTPHorizontalAxis::getParentOtheraxisWidth() const {
return fabs(parent->y2p(parent->getYMax())-parent->y2p(parent->getYMin()));
}
@ -2003,23 +2146,21 @@ void JKQTPHorizontalAxis::drawTickLabel1(JKQTPEnhancedPainter &painter, double x
double width, ascent, descent, strikeoutPos;
getParentMathText()->getSizeDetail(painter, width, ascent, descent, strikeoutPos);
if (axisStyle.drawMode1.testFlag(JKQTPCADMTickLabels)) {
const double ly0=yy+parent->pt2px(painter, labelOffset);
const double ly=ly0+ascentMax;
if (axisStyle.tickLabelAngle!=0) {
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
if (axisStyle.tickLabelAngle>0) {
painter.translate(xx-fabs(ascent*sin(axisStyle.tickLabelAngle/180.0*JKQTPSTATISTICS_PI)/2.0), ly0+fabs(ascent*cos(axisStyle.tickLabelAngle/180.0*JKQTPSTATISTICS_PI)));
painter.rotate(axisStyle.tickLabelAngle);
} else {
painter.translate(xx+fabs(ascent*sin(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI)/2.0)-width*fabs(cos(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI)), ly0+ascent*fabs(cos(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI))+fabs(width*sin(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI)));
painter.rotate(axisStyle.tickLabelAngle);
}
getParentMathText()->draw(painter, 0,0, parent->getCurrentPlotterStyle().debugShowTextBoxes);
const double ly0=yy+parent->pt2px(painter, labelOffset);
const double ly=ly0+ascentMax;
if (axisStyle.tickLabelAngle!=0) {
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
if (axisStyle.tickLabelAngle>0) {
painter.translate(xx-fabs(ascent*sin(axisStyle.tickLabelAngle/180.0*JKQTPSTATISTICS_PI)/2.0), ly0+fabs(ascent*cos(axisStyle.tickLabelAngle/180.0*JKQTPSTATISTICS_PI)));
painter.rotate(axisStyle.tickLabelAngle);
} else {
getParentMathText()->draw(painter, xx-width/2.0, ly, parent->getCurrentPlotterStyle().debugShowTextBoxes);
painter.translate(xx+fabs(ascent*sin(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI)/2.0)-width*fabs(cos(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI)), ly0+ascent*fabs(cos(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI))+fabs(width*sin(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI)));
painter.rotate(axisStyle.tickLabelAngle);
}
getParentMathText()->draw(painter, 0,0, parent->getCurrentPlotterStyle().debugShowTextBoxes);
} else {
getParentMathText()->draw(painter, xx-width/2.0, ly, parent->getCurrentPlotterStyle().debugShowTextBoxes);
}
}
@ -2033,33 +2174,29 @@ void JKQTPHorizontalAxis::drawTickLabel2(JKQTPEnhancedPainter &painter, double x
getParentMathText()->parse(label);
double width, ascent, descent, strikeoutPos;
getParentMathText()->getSizeDetail(painter, width, ascent, descent, strikeoutPos);
if (axisStyle.drawMode2.testFlag(JKQTPCADMTickLabels)) {
const double ly0=yy-parent->pt2px(painter, labelOffset);
const double ly=ly0-descentMax;
if (axisStyle.tickLabelAngle!=0) {
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
if (axisStyle.tickLabelAngle>0) {
painter.translate(xx+fabs(descent*sin(axisStyle.tickLabelAngle/180.0*JKQTPSTATISTICS_PI)/2.0), ly0-fabs(descent*cos(axisStyle.tickLabelAngle/180.0*JKQTPSTATISTICS_PI)));
painter.rotate(-axisStyle.tickLabelAngle);
} else {
painter.translate(xx-fabs(descent*sin(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI)/2.0)-width*fabs(cos(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI)), ly0-descent*fabs(cos(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI))-fabs(width*sin(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI)));
painter.rotate(-axisStyle.tickLabelAngle);
}
getParentMathText()->draw(painter, 0,0, parent->getCurrentPlotterStyle().debugShowTextBoxes);
const double ly0=yy-parent->pt2px(painter, labelOffset);
const double ly=ly0-descentMax;
if (axisStyle.tickLabelAngle!=0) {
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
if (axisStyle.tickLabelAngle>0) {
painter.translate(xx+fabs(descent*sin(axisStyle.tickLabelAngle/180.0*JKQTPSTATISTICS_PI)/2.0), ly0-fabs(descent*cos(axisStyle.tickLabelAngle/180.0*JKQTPSTATISTICS_PI)));
painter.rotate(-axisStyle.tickLabelAngle);
} else {
getParentMathText()->draw(painter, xx-width/2.0, ly, parent->getCurrentPlotterStyle().debugShowTextBoxes);
painter.translate(xx-fabs(descent*sin(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI)/2.0)-width*fabs(cos(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI)), ly0-descent*fabs(cos(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI))-fabs(width*sin(fabs(axisStyle.tickLabelAngle)/180.0*JKQTPSTATISTICS_PI)));
painter.rotate(-axisStyle.tickLabelAngle);
}
getParentMathText()->draw(painter, 0,0, parent->getCurrentPlotterStyle().debugShowTextBoxes);
} else {
getParentMathText()->draw(painter, xx-width/2.0, ly, parent->getCurrentPlotterStyle().debugShowTextBoxes);
}
}
void JKQTPHorizontalAxis::drawAxisLabel1(JKQTPEnhancedPainter &painter, double left, double bottom, QSizeF labelMax) {
void JKQTPHorizontalAxis::drawAxisLabel1(JKQTPEnhancedPainter &painter, double left, double bottom, QSizeF labelMax, JKQTPCADrawMode drawMode) {
double labelOffset=parent->pt2px(painter, axisStyle.labelDistance);
if (axisStyle.drawMode1.testFlag(JKQTPCADMTicks)) labelOffset+=parent->pt2px(painter, axisStyle.tickOutsideLength);
if (axisStyle.drawMode1.testFlag(JKQTPCADMTickLabels)) {
if (drawMode.testFlag(JKQTPCADMTicks)) labelOffset+=parent->pt2px(painter, axisStyle.tickOutsideLength);
if (drawMode.testFlag(JKQTPCADMTickLabels)) {
labelOffset+=parent->pt2px(painter, axisStyle.tickLabelDistance);
labelOffset+=labelMax.height();//+labelMax.height();
}
@ -2102,10 +2239,10 @@ void JKQTPHorizontalAxis::drawAxisLabel1(JKQTPEnhancedPainter &painter, double l
}
}
void JKQTPHorizontalAxis::drawAxisLabel2(JKQTPEnhancedPainter &painter, double left, double top, QSizeF labelMax) {
void JKQTPHorizontalAxis::drawAxisLabel2(JKQTPEnhancedPainter &painter, double left, double top, QSizeF labelMax, JKQTPCADrawMode drawMode) {
double labelOffset=parent->pt2px(painter, axisStyle.labelDistance);
if (axisStyle.drawMode2.testFlag(JKQTPCADMTicks)) labelOffset+=parent->pt2px(painter, axisStyle.tickOutsideLength);
if (axisStyle.drawMode2.testFlag(JKQTPCADMTickLabels)) {
if (drawMode.testFlag(JKQTPCADMTicks)) labelOffset+=parent->pt2px(painter, axisStyle.tickOutsideLength);
if (drawMode.testFlag(JKQTPCADMTickLabels)) {
labelOffset+=parent->pt2px(painter, axisStyle.tickLabelDistance);
labelOffset+=labelMax.width();//+labelMax.height();
}
@ -2186,6 +2323,12 @@ void JKQTPHorizontalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
ticklabelOffset2PT+=axisStyle.tickOutsideLength;
minorticklabelOffset2PT+=axisStyle.minorTickOutsideLength;
}
double ticklabelOffset0PT=axisStyle.tickLabelDistance; // offset of tick labels from axis 0
double minorticklabelOffset0PT=axisStyle.tickLabelDistance; // offset ofminor tick labels from axis 0
if (axisStyle.drawMode0.testFlag(JKQTPCADMTicks)) {
ticklabelOffset0PT+=axisStyle.tickOutsideLength;
minorticklabelOffset0PT+=axisStyle.minorTickOutsideLength;
}
//qDebug()<<" left="<<left<<"\n";
//qDebug()<<" right="<<right<<"\n";
@ -2225,6 +2368,11 @@ void JKQTPHorizontalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
painter.setPen(pmain);
painter.setBrush(pmain.color());
// axis 0 properties
bool drawZeroAxis=false;
const double zeroaxispos=getZeroAxisPos(&drawZeroAxis);
// draw thick axis lines, left and/or right
if (axisStyle.drawMode1.testFlag(JKQTPCADMLine)) {
const QLineF l(x2p(axismin), bottom, x2p(axismax), bottom);
@ -2234,6 +2382,10 @@ void JKQTPHorizontalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
const QLineF l(x2p(axismin), top, x2p(axismax), top);
drawAxisLine(painter, l, axisStyle.drawMode2);
}
if (axisStyle.drawMode0.testFlag(JKQTPCADMLine)) {
const QLineF l(x2p(axismin), zeroaxispos, x2p(axismax), zeroaxispos);
drawAxisLine(painter, l, axisStyle.drawMode0);
}
painter.setBrush(Qt::NoBrush);
// plot minor and major ticks + tick labels
@ -2244,8 +2396,8 @@ void JKQTPHorizontalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
bool first=true;
// loop through all labels, as they are at the major ticks
int cnt=0;
QVector<QLineF> lines_ptick, lines_ptick2;
QVector<QLineF> lines_pmtick, lines_pmtick2;
QVector<QLineF> lines_ptick, lines_ptick2, lines_ptick0;
QVector<QLineF> lines_pmtick, lines_pmtick2, lines_pmtick0;
const double arrowFreeSpace=axisStyle.getArrowSize(painter, parent)*1.2;
@ -2260,7 +2412,7 @@ void JKQTPHorizontalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
const double xx=x2p(x);
//qDebug()<<" tick @ x="<<x<<" label="<<label<<" mtdist="<<mtdist<<" axisStyle.minorTicks="<<minorTicks;
if (!(((axisStyle.drawMode1&(JKQTPCADMMinArrow|JKQTPCADMMinFilledArrow|JKQTPCADMMaxArrow|JKQTPCADMMaxFilledArrow))!=int(0))||((axisStyle.drawMode2&(JKQTPCADMMinArrow|JKQTPCADMMinFilledArrow|JKQTPCADMMaxArrow|JKQTPCADMMaxFilledArrow))!=int(0)))
if (!(((axisStyle.drawMode1&(JKQTPCADMMinArrow|JKQTPCADMMinFilledArrow|JKQTPCADMMaxArrow|JKQTPCADMMaxFilledArrow))!=int(0))||((axisStyle.drawMode2&(JKQTPCADMMinArrow|JKQTPCADMMinFilledArrow|JKQTPCADMMaxArrow|JKQTPCADMMaxFilledArrow))!=int(0))||((axisStyle.drawMode0&(JKQTPCADMMinArrow|JKQTPCADMMinFilledArrow|JKQTPCADMMaxArrow|JKQTPCADMMaxFilledArrow))!=int(0)))
|| (xx>left+arrowFreeSpace && xx<right-arrowFreeSpace))
{
@ -2270,11 +2422,15 @@ void JKQTPHorizontalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
}
if (axisStyle.drawMode2.testFlag(JKQTPCADMTicks) && x<=axismax && x>=axismin) {
const QLineF l(xx, top+parent->pt2px(painter, axisStyle.tickInsideLength), xx, top-parent->pt2px(painter, axisStyle.tickOutsideLength));
if (l.length()>0) lines_ptick.append(l);//painter.drawLine(l);
if (l.length()>0) lines_ptick2.append(l);//painter.drawLine(l);
}
if (axisStyle.drawMode0.testFlag(JKQTPCADMTicks) && x<=axismax && x>=axismin) {
const QLineF l(xx, zeroaxispos-parent->pt2px(painter, axisStyle.tickInsideLength), xx, zeroaxispos+parent->pt2px(painter, axisStyle.tickOutsideLength));
if (l.length()>0) lines_ptick0.append(l);//painter.drawLine(l);
}
//painter.setPen(pmtick);
if ((tickLabels.size()<=0) && (axisStyle.minorTicks>0) && (axisStyle.drawMode1.testFlag(JKQTPCADMTicks)||axisStyle.drawMode1.testFlag(JKQTPCADMTickLabels)||axisStyle.drawMode2.testFlag(JKQTPCADMTicks)||axisStyle.drawMode2.testFlag(JKQTPCADMTickLabels))) {
if ((tickLabels.size()<=0) && (axisStyle.minorTicks>0) && (axisStyle.drawMode1.testFlag(JKQTPCADMTicks)||axisStyle.drawMode1.testFlag(JKQTPCADMTickLabels)||axisStyle.drawMode2.testFlag(JKQTPCADMTicks)||axisStyle.drawMode2.testFlag(JKQTPCADMTickLabels)||axisStyle.drawMode0.testFlag(JKQTPCADMTicks)||axisStyle.drawMode0.testFlag(JKQTPCADMTickLabels))) {
double mx=x+mtdist;
int minTickCnt=axisStyle.minorTicks;
if (isLogAxis()) {
@ -2295,6 +2451,11 @@ void JKQTPHorizontalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
const QLineF l( mx_pix, bottom-parent->pt2px(painter, axisStyle.minorTickInsideLength), mx_pix, bottom+parent->pt2px(painter, axisStyle.minorTickOutsideLength));
if (l.length()>0) lines_pmtick.append(l);
}
// calculate minor tick lines, axis 0
if (axisStyle.minorTicks>0&&axisStyle.drawMode0.testFlag(JKQTPCADMTicks)) {
const QLineF l( mx_pix, zeroaxispos-parent->pt2px(painter, axisStyle.minorTickInsideLength), mx_pix, zeroaxispos+parent->pt2px(painter, axisStyle.minorTickOutsideLength));
if (l.length()>0) lines_pmtick.append(l);
}
// calculate minor tick lines, axis 2
if (axisStyle.minorTicks>0&&axisStyle.drawMode2.testFlag(JKQTPCADMTicks)) {
const QLineF l( mx_pix, top+parent->pt2px(painter, axisStyle.minorTickInsideLength), mx_pix, top-parent->pt2px(painter, axisStyle.minorTickOutsideLength));
@ -2302,11 +2463,12 @@ void JKQTPHorizontalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
}
// draw minor tick label, axis 1
if (axisStyle.minorTickLabelsEnabled&&axisStyle.minorTicks>0&&(axisStyle.drawMode1.testFlag(JKQTPCADMTickLabels)||axisStyle.drawMode2.testFlag(JKQTPCADMTickLabels))) {
if (axisStyle.minorTickLabelsEnabled&&axisStyle.minorTicks>0&&(axisStyle.drawMode1.testFlag(JKQTPCADMTickLabels)||axisStyle.drawMode2.testFlag(JKQTPCADMTickLabels)||axisStyle.drawMode0.testFlag(JKQTPCADMTickLabels))) {
double val= mx/pow(logAxisBase,floor(log(mx)/log(logAxisBase)));
if (axisStyle.minorTickLabelFullNumber) val=mx;
QString minorlabel=floattolabel(val);
if (axisStyle.drawMode1.testFlag(JKQTPCADMTickLabels)) drawTickLabel1(painter, mx_pix, bottom, minorticklabelOffset1PT, minorlabel, axisStyle.minorTickLabelFontSize, ascentMax, descentMax, true);
if (axisStyle.drawMode0.testFlag(JKQTPCADMTickLabels)) drawTickLabel1(painter, mx_pix, zeroaxispos, minorticklabelOffset0PT, minorlabel, axisStyle.minorTickLabelFontSize, ascentMax, descentMax, true);
if (axisStyle.drawMode2.testFlag(JKQTPCADMTickLabels)) drawTickLabel2(painter, mx_pix, top, minorticklabelOffset2PT, minorlabel, axisStyle.minorTickLabelFontSize, ascentMax, descentMax, true);
}
}
@ -2316,6 +2478,7 @@ void JKQTPHorizontalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
if (!label.isEmpty() && (x<=axismax && x>=axismin)) {
if (axisStyle.drawMode1.testFlag(JKQTPCADMTickLabels)) drawTickLabel1(painter, xx, bottom, ticklabelOffset1PT, label, this->axisStyle.tickLabelFontSize, ascentMax, descentMax, false);
if (axisStyle.drawMode0.testFlag(JKQTPCADMTickLabels)) drawTickLabel1(painter, xx, zeroaxispos, ticklabelOffset0PT, label, this->axisStyle.tickLabelFontSize, ascentMax, descentMax, false);
if (axisStyle.drawMode2.testFlag(JKQTPCADMTickLabels)) drawTickLabel2(painter, xx, top, ticklabelOffset2PT, label, this->axisStyle.tickLabelFontSize, ascentMax, descentMax, false);
}
@ -2341,6 +2504,12 @@ void JKQTPHorizontalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
painter.setPen(pmtick);
painter.drawLines(lines_pmtick2);
}
if (axisStyle.drawMode0.testFlag(JKQTPCADMTicks)) {
painter.setPen(ptick);
painter.drawLines(lines_ptick0);
painter.setPen(pmtick);
painter.drawLines(lines_pmtick0);
}
}
// plot axis label
@ -2348,14 +2517,21 @@ void JKQTPHorizontalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
#ifdef JKQTBP_AUTOTIMER
JKQTPAutoOutputTimer jkaati(QString("JKQTPHorizontalAxis[%1]::drawAxes(): axisLabel1").arg(objectName()));
#endif
drawAxisLabel1(painter, left, bottom, labelMax);
drawAxisLabel1(painter, left, bottom, labelMax, axisStyle.drawMode1);
}
if (!axisLabel.isEmpty() && axisStyle.drawMode0.testFlag(JKQTPCADMAxisLabel)) {
#ifdef JKQTBP_AUTOTIMER
JKQTPAutoOutputTimer jkaati(QString("JKQTPHorizontalAxis[%1]::drawAxes(): axisLabel0").arg(objectName()));
#endif
drawAxisLabel1(painter, left, zeroaxispos, labelMax, axisStyle.drawMode0);
}
if (!axisLabel.isEmpty() && axisStyle.drawMode2.testFlag(JKQTPCADMAxisLabel)) {
#ifdef JKQTBP_AUTOTIMER
JKQTPAutoOutputTimer jkaati(QString("JKQTPHorizontalAxis[%1]::drawAxes(): axisLabel2").arg(objectName()));
#endif
drawAxisLabel2(painter, left, top, labelMax);
drawAxisLabel2(painter, left, top, labelMax, axisStyle.drawMode2);
}
if (getParent()->getCurrentPlotterStyle().debugShowRegionBoxes) {
@ -2447,4 +2623,7 @@ double JKQTPHorizontalIndependentAxis::getParentOtheraxisOffset() const {
return otherAxisOffset;
}
double JKQTPHorizontalIndependentAxis::parentOtherAxisX2P(double x) const
{
return qQNaN();
}

View File

@ -232,10 +232,10 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
/** \brief add a new tick label to the axis */
void addAxisTickLabels(const double* x, const QString* label, int items);
/** \brief returns the size of the left/bottom axis in pt */
/** \brief returns the size of the left/bottom axis in pixels */
virtual QSizeF getSize1(JKQTPEnhancedPainter& painter)=0;
/** \brief returns the size of the right/top axis in pt */
/** \brief returns the size of the right/top axis in pixels */
virtual QSizeF getSize2(JKQTPEnhancedPainter& painter)=0;
/** \brief draw axes */
@ -330,6 +330,8 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
/** \copydoc JKQTPCoordinateAxisStyle::tickMode */
inline JKQTPLabelTickMode getTickMode() const { return this->axisStyle.tickMode; }
/** \copydoc JKQTPCoordinateAxisStyle::drawMode0 */
inline JKQTPCADrawMode getDrawMode0() const { return this->axisStyle.drawMode0; }
/** \copydoc JKQTPCoordinateAxisStyle::drawMode1 */
inline JKQTPCADrawMode getDrawMode1() const { return this->axisStyle.drawMode1; }
/** \copydoc JKQTPCoordinateAxisStyle::drawMode2 */
@ -439,6 +441,8 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
virtual bool getParentOtheraxisInverted() const=0;
/** \brief pixel offset of (perpendicular) other axis (needed for grids) */
virtual double getParentOtheraxisOffset() const=0;
/** \brief calls x2p() of the other axis (or returns \c NAN if the other axis does not exist */
virtual double parentOtherAxisX2P(double x) const =0;
public slots:
/** \brief set range of plot axis */
@ -565,9 +569,13 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
/** \copydoc JKQTPGridStyle::lineColor */
void setGridColor(const QColor& __value);
/** \copydoc JKQTPGridStyle::lineColor */
void setGridColor(const QColor& __value, double alpha);
/** \copydoc JKQTPGridStyle::lineColor */
void setMinorGridColor(const QColor& __value);
/** \copydoc JKQTPGridStyle::lineColor */
void setMinorGridColor(const QColor& __value, double alpha);
/** \copydoc JKQTPGridStyle::lineWidth */
void setGridWidth (double __value);
@ -584,6 +592,8 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
/** \copydoc JKQTPCoordinateAxisStyle::drawMode1 */
void setDrawMode1 (JKQTPCADrawMode __value);
/** \copydoc JKQTPCoordinateAxisStyle::drawMode0 */
void setDrawMode0 (JKQTPCADrawMode __value);
/** \copydoc JKQTPCoordinateAxisStyle::drawMode2 */
void setDrawMode2(JKQTPCADrawMode __value);
@ -631,6 +641,8 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
void setTickLabelColor(QColor c) ;
protected:
/** \brief 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 */
virtual std::pair<QSizeF, QSizeF> getSize0(JKQTPEnhancedPainter& painter) ;
/** \brief indicates whether one of the parameters has changed sinse the last recalculation of tickSpacing ... */
bool paramsChanged;
/** \brief can be used to switch off calcPlotScaling() temporarily, while modifying some properties
@ -818,6 +830,11 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
QSizeF getMaxTickLabelSize(JKQTPEnhancedPainter& painter, double* ascent=nullptr, double* descent=nullptr);
/** \brief draw the axis line \a l (pointing from axismin to axismax) optionally decorated as specified by \a drawMode using JKQTPEnhancedPainter \a painter */
void drawAxisLine(JKQTPEnhancedPainter& painter, const QLineF& l, JKQTPCADrawMode drawMode) const;
/** \brief calculate the position of the zero-axis (and whether to draw it or not) */
double getZeroAxisPos(bool* drawZeroAxis=nullptr);
};
@ -827,6 +844,10 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
/*! \brief implements a vertical axis, based on JKQTPCoordinateAxis (for most of documentation: see JKQTPCoordinateAxis).
\ingroup jkqtpbaseplotter_elements
The positioning of the different axis elements depends on the psition of the "other" axis (here x-axis),
i.e. the corresponding vertical axis:
\image html JKQTPHorizontalAxisPositioning.png
*/
class JKQTPLOTTER_LIB_EXPORT JKQTPVerticalAxis: public JKQTPCoordinateAxis {
Q_OBJECT
@ -835,30 +856,35 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPVerticalAxis: public JKQTPCoordinateAxis {
/** \brief class constructor */
JKQTPVerticalAxis(JKQTBasePlotter* parent);
/** \brief returns the size of the left/bottom axis in pt */
/** \brief returns the size of the left axis in pixels */
virtual QSizeF getSize1(JKQTPEnhancedPainter& painter) override;
/** \brief returns the size of the right/top axis in pt */
/** \brief returns the size of the right axis in pixels */
virtual QSizeF getSize2(JKQTPEnhancedPainter& painter) override;
/** \brief draw axes */
/** copydoc JKQTPCoordinateAxis::drawAxes() */
virtual void drawAxes(JKQTPEnhancedPainter& painter) override;
/** \brief draw grids */
/** copydoc JKQTPCoordinateAxis::drawGrids() */
virtual void drawGrids(JKQTPEnhancedPainter& painter) override;
/** \brief width of the plot in the direction of the axis */
/** copydoc JKQTPCoordinateAxis::getParentPlotWidth() */
virtual double getParentPlotWidth() const override;
/** \brief offset of the plot in the direction of the axis */
/** copydoc JKQTPCoordinateAxis::getParentPlotOffset() */
virtual double getParentPlotOffset() const override;
/** \brief pixel of other (perpendicular) axis (needed for grids) */
/** copydoc JKQTPCoordinateAxis::getParentOtheraxisWidth() */
virtual double getParentOtheraxisWidth() const override;
/** copydoc JKQTPCoordinateAxis::getParentOtheraxisInverted() */
virtual bool getParentOtheraxisInverted() const override;
/** \brief pixel offset of (perpendicular) other axis (needed for grids) */
/** copydoc JKQTPCoordinateAxis::getParentOtheraxisOffset() */
virtual double getParentOtheraxisOffset() const override;
/** copydoc JKQTPCoordinateAxis::parentOtherAxisX2P() */
virtual double parentOtherAxisX2P(double x) const override;
protected:
/** copydoc JKQTPCoordinateAxis::getSize0() */
virtual std::pair<QSizeF,QSizeF> getSize0(JKQTPEnhancedPainter& painter) override;
/** \brief draw a tick label on the left axis 1 with text \a label (with optional rotation) at ( \a xx , \a yy ) (in pixel)
*
* \param painter the JKQTPEnhancedPainter used for drawing
@ -882,16 +908,30 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPVerticalAxis: public JKQTPCoordinateAxis {
*/
void drawTickLabel2(JKQTPEnhancedPainter& painter, double xx, double yy, double labelOffset, const QString &label, double fontSize, bool isMinor=false) ;
/** \brief draw the axis label using \a painter for axis 1 at \c x= \a left and \c y= \a bottom. \a labelMax is the maximum Size of all tick labels */
void drawAxisLabel1(JKQTPEnhancedPainter &painter, double left, double bottom, QSizeF labelMax);
void drawAxisLabel1(JKQTPEnhancedPainter &painter, double left, double bottom, QSizeF labelMax, JKQTPCADrawMode drawMode);
/** \brief draw the axis label using \a painter for axis 2 at \c x= \a right and \c y= \a bottom. \a labelMax is the maximum Size of all tick labels */
void drawAxisLabel2(JKQTPEnhancedPainter &painter, double right, double bottom, QSizeF labelMax);
void drawAxisLabel2(JKQTPEnhancedPainter &painter, double right, double bottom, QSizeF labelMax, JKQTPCADrawMode drawMode);
};
/*! \brief implements a position-indipendent vertical axis, based on JKQTPCoordinateAxis (for most of documentation: see JKQTPCoordinateAxis).
\ingroup jkqtpbaseplotter_elements
This axis may be draw at a user-supplied position (used e.g. for color bar axes)
This axis may be draw at a user-supplied position (used e.g. for color bar axes).
The axis positioning parameters are supplied via the constructor,or setter methods.
\image html JKQTPVerticalIndependentAxisPositioning.png
Basically this class overwrites several virtual methods as follows:
- getParentPlotWidth() returns axisWidth, provided in the connstructor or via setParentPlotWidth()
- getParentPlotOffset() returns axisOffset, provided in the connstructor or via setParentPlotOffset()
- getParentOtheraxisWidth() returns otherAxisWidth, provided in the connstructor or via setParentPlotOtheraxisWidth()
- getParentOtheraxisOffset() returns otherAxisOffset, provided in the connstructor or via setParentPlotOtheraxisOffset()
.
If it is paired with another axis, the parameters of that axis have to be given explizitly in the constructor or with setters.
*/
class JKQTPLOTTER_LIB_EXPORT JKQTPVerticalIndependentAxis: public JKQTPVerticalAxis {
Q_OBJECT
@ -899,16 +939,19 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPVerticalIndependentAxis: public JKQTPVerticalA
public:
/** \brief class constructor */
JKQTPVerticalIndependentAxis(double axisOffset, double axisWidth, double otherAxisOffset, double otherAxisWidth, JKQTBasePlotter* parent);
/** \brief width of the plot in the direction of the axis */
/** copydoc JKQTPCoordinateAxis::getParentPlotWidth() */
virtual double getParentPlotWidth() const override;
/** \brief offset of the plot in the direction of the axis */
/** copydoc JKQTPCoordinateAxis::getParentPlotOffset() */
virtual double getParentPlotOffset() const override;
/** \brief pixel of other (perpendicular) axis (needed for grids) */
/** copydoc JKQTPCoordinateAxis::getParentOtheraxisWidth() */
virtual double getParentOtheraxisWidth() const override;
/** \brief returns whether the other axis is inverted */
/** copydoc JKQTPCoordinateAxis::getParentOtheraxisInverted() */
virtual bool getParentOtheraxisInverted() const override;
/** \brief pixel offset of (perpendicular) other axis (needed for grids) */
/** copydoc JKQTPCoordinateAxis::getParentOtheraxisOffset() */
virtual double getParentOtheraxisOffset() const override;
/** copydoc JKQTPCoordinateAxis::parentOtherAxisX2P() */
virtual double parentOtherAxisX2P(double x) const override;
public slots:
/** \brief set the axis offset */
virtual void setAxisOffset(double __value) ;
@ -939,6 +982,10 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPVerticalIndependentAxis: public JKQTPVerticalA
/*! \brief implements a horizontal axis, based on JKQTPCoordinateAxis (for most of documentation: see JKQTPCoordinateAxis).
\ingroup jkqtpbaseplotter_elements
The positioning of the different axis elements depends on the psition of the "other" axis (here y-axis),
i.e. the corresponding vertical axis:
\image html JKQTPHorizontalAxisPositioning.png
*/
class JKQTPLOTTER_LIB_EXPORT JKQTPHorizontalAxis: public JKQTPCoordinateAxis {
Q_OBJECT
@ -947,30 +994,35 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPHorizontalAxis: public JKQTPCoordinateAxis {
/** \brief class constructor */
JKQTPHorizontalAxis(JKQTBasePlotter* parent);
/** \brief returns the size of the left/bottom axis in pt */
/** \brief returns the size of the bottom axis in pixels */
virtual QSizeF getSize1(JKQTPEnhancedPainter& painter) override;
/** \brief returns the size of the right/top axis in pt */
/** \brief returns the size of the top axis in pixels */
virtual QSizeF getSize2(JKQTPEnhancedPainter& painter) override;
/** \brief draw axes */
/** copydoc JKQTPCoordinateAxis::drawAxes() */
virtual void drawAxes(JKQTPEnhancedPainter& painter) override;
/** \brief draw grids */
/** copydoc JKQTPCoordinateAxis::drawGrids() */
virtual void drawGrids(JKQTPEnhancedPainter& painter) override;
/** \brief width of the plot in the direction of the axis */
/** copydoc JKQTPCoordinateAxis::getParentPlotWidth() */
virtual double getParentPlotWidth() const override;
/** \brief offset of the plot in the direction of the axis */
/** copydoc JKQTPCoordinateAxis::getParentPlotOffset() */
virtual double getParentPlotOffset() const override;
/** \brief pixel of other (perpendicular) axis (needed for grids) */
/** copydoc JKQTPCoordinateAxis::getParentOtheraxisWidth() */
virtual double getParentOtheraxisWidth() const override;
/** \brief returns whether the other axis is inverted */
/** copydoc JKQTPCoordinateAxis::getParentOtheraxisInverted() */
virtual bool getParentOtheraxisInverted() const override;
/** \brief pixel offset of (perpendicular) other axis (needed for grids) */
/** copydoc JKQTPCoordinateAxis::getParentOtheraxisOffset() */
virtual double getParentOtheraxisOffset() const override;
/** copydoc JKQTPCoordinateAxis::parentOtherAxisX2P() */
virtual double parentOtherAxisX2P(double x) const override;
protected:
/** copydoc JKQTPCoordinateAxis::getSize0() */
virtual std::pair<QSizeF, QSizeF> getSize0(JKQTPEnhancedPainter& painter) override;
/** \brief draw a tick label on the lower axis 1 with text \a label (with optional rotation) at ( \a xx , \a yy ) (in pixel)
*
* \param painter the JKQTPEnhancedPainter used for drawing
@ -998,9 +1050,9 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPHorizontalAxis: public JKQTPCoordinateAxis {
*/
void drawTickLabel2(JKQTPEnhancedPainter& painter, double xx, double yy, double labelOffset, const QString &label, double fontSize, double ascentMax, double descentMax, bool isMinor=false) ;
/** \brief draw the axis label using \a painter for axis 1 at \c x= \a left and \c y= \a bottom. \a labelMax is the maximum Size of all tick labels */
void drawAxisLabel1(JKQTPEnhancedPainter &painter, double left, double bottom, QSizeF labelMax);
void drawAxisLabel1(JKQTPEnhancedPainter &painter, double left, double bottom, QSizeF labelMax, JKQTPCADrawMode drawMode);
/** \brief draw the axis label using \a painter for axis 2 at \c x= \a left and \c y= \a top. \a labelMax is the maximum Size of all tick labels */
void drawAxisLabel2(JKQTPEnhancedPainter &painter, double left, double top, QSizeF labelMax);
void drawAxisLabel2(JKQTPEnhancedPainter &painter, double left, double top, QSizeF labelMax, JKQTPCADrawMode drawMode);
};
@ -1008,7 +1060,20 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPHorizontalAxis: public JKQTPCoordinateAxis {
/*! \brief implements a position-indipendent horizontal axis, based on JKQTPCoordinateAxis (for most of documentation: see JKQTPCoordinateAxis).
\ingroup jkqtpbaseplotter_elements
This axis may be draw at a user-supplied position (used e.g. for color bar axes)
This axis may be draw at a user-supplied position (used e.g. for color bar axes).
The axis positioning parameters are supplied via the constructor,or setter methods.
\image html JKQTPHorizontalIndependentAxisPositioning.png
Basically this class overwrites several virtual methods as follows:
- getParentPlotWidth() returns axisWidth, provided in the connstructor or via setParentPlotWidth()
- getParentPlotOffset() returns axisOffset, provided in the connstructor or via setParentPlotOffset()
- getParentOtheraxisWidth() returns otherAxisWidth, provided in the connstructor or via setParentPlotOtheraxisWidth()
- getParentOtheraxisOffset() returns otherAxisOffset, provided in the connstructor or via setParentPlotOtheraxisOffset()
.
If it is paired with another axis, the parameters of that axis have to be given explizitly in the constructor or with setters.
*/
class JKQTPLOTTER_LIB_EXPORT JKQTPHorizontalIndependentAxis: public JKQTPHorizontalAxis {
Q_OBJECT
@ -1016,6 +1081,19 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPHorizontalIndependentAxis: public JKQTPHorizon
public:
/** \brief class constructor */
JKQTPHorizontalIndependentAxis(double axisOffset, double axisWidth, double otherAxisOffset, double otherAxisWidth, JKQTBasePlotter* parent);
/** copydoc JKQTPCoordinateAxis::getParentPlotWidth() */
virtual double getParentPlotWidth() const override;
/** copydoc JKQTPCoordinateAxis::getParentPlotOffset() */
virtual double getParentPlotOffset() const override;
/** copydoc JKQTPCoordinateAxis::getParentOtheraxisWidth() */
virtual double getParentOtheraxisWidth() const override;
/** copydoc JKQTPCoordinateAxis::getParentOtheraxisInverted() */
virtual bool getParentOtheraxisInverted() const override;
/** copydoc JKQTPCoordinateAxis::getParentOtheraxisOffset() */
virtual double getParentOtheraxisOffset() const override;
/** copydoc JKQTPCoordinateAxis::parentOtherAxisX2P() */
virtual double parentOtherAxisX2P(double x) const override;
public slots:
/** \brief set the axis offset */
virtual void setAxisOffset(double __value);
@ -1025,18 +1103,11 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPHorizontalIndependentAxis: public JKQTPHorizon
virtual void setOtherAxisOffset(double __value);
/** \brief set the other axis width */
virtual void setOtherAxisWidth(double __value);
/** \brief set whether the other axis is inverted */
virtual void setOtherAxisInverted(bool __value);
protected:
/** \brief width of the plot in the direction of the axis */
virtual double getParentPlotWidth() const override;
/** \brief offset of the plot in the direction of the axis */
virtual double getParentPlotOffset() const override;
/** \brief pixel of other (perpendicular) axis (needed for grids) */
virtual double getParentOtheraxisWidth() const override;
/** \brief returns whether the other axis is inverted */
virtual bool getParentOtheraxisInverted() const override;
/** \brief pixel offset of (perpendicular) other axis (needed for grids) */
virtual double getParentOtheraxisOffset() const override;
/** \brief the offset of the axis */
double axisOffset;

View File

@ -44,6 +44,7 @@ JKQTPCoordinateAxisStyle::JKQTPCoordinateAxisStyle():
minorTickLabelFullNumber(true),
drawMode1(JKQTPCADMcomplete),
drawMode2(JKQTPCADMLineTicks),
drawMode0(JKQTPCADMnone),
minorTickColor(QColor("black")),
minorTickLabelColor(QColor("black")),
minorTickWidth(1),
@ -111,19 +112,20 @@ void JKQTPCoordinateAxisStyle::loadSettings(const QSettings &settings, const QSt
minorTickInsideLength = settings.value(group+"minor_tick/inside_length", defaultStyle.minorTickInsideLength).toDouble();
tickLabelDistance = settings.value(group+"ticks/label_distance", defaultStyle.tickLabelDistance).toDouble();
labelDistance = settings.value(group+"axis_label/distance", defaultStyle.labelDistance).toDouble();
labelPosition=String2JKQTPLabelPosition(settings.value(group+"axis_label/position", JKQTPLabelPosition2String(labelPosition)).toString());
tickLabelType=String2JKQTPCALabelType(settings.value(group+"ticks/type", JKQTPCALabelType2String(tickLabelType)).toString());
labelColor=jkqtp_String2QColor(settings.value(group+"axis_label/color", jkqtp_QColor2String(labelColor)).toString());
axisColor=jkqtp_String2QColor(settings.value(group+"color", jkqtp_QColor2String(axisColor)).toString());
tickColor=jkqtp_String2QColor(settings.value(group+"ticks/color", jkqtp_QColor2String(tickColor)).toString());
minorTickColor=jkqtp_String2QColor(settings.value(group+"minor_tick/color", jkqtp_QColor2String(minorTickColor)).toString());
tickLabelColor=jkqtp_String2QColor(settings.value(group+"ticks/label_color", jkqtp_QColor2String(tickLabelColor)).toString());
minorTickLabelColor=jkqtp_String2QColor(settings.value(group+"minor_tick/label_color", jkqtp_QColor2String(minorTickLabelColor)).toString());
drawMode1=String2JKQTPCADrawMode(settings.value(group+"draw_mode1", JKQTPCADrawMode2String(drawMode1)).toString());
drawMode2=String2JKQTPCADrawMode(settings.value(group+"draw_mode2", JKQTPCADrawMode2String(drawMode2)).toString());
tickMode=String2JKQTPLabelTickMode(settings.value(group+"ticks/mode", JKQTPLabelTickMode2String(tickMode)).toString());
colorZeroAxis=jkqtp_String2QColor(settings.value(group+"zero_line/color", jkqtp_QColor2String(colorZeroAxis)).toString());
styleZeroAxis=jkqtp_String2QPenStyle(settings.value(group+"zero_line/style", jkqtp_QPenStyle2String(styleZeroAxis)).toString());
labelPosition=String2JKQTPLabelPosition(settings.value(group+"axis_label/position", JKQTPLabelPosition2String(defaultStyle.labelPosition)).toString());
tickLabelType=String2JKQTPCALabelType(settings.value(group+"ticks/type", JKQTPCALabelType2String(defaultStyle.tickLabelType)).toString());
labelColor=jkqtp_String2QColor(settings.value(group+"axis_label/color", jkqtp_QColor2String(defaultStyle.labelColor)).toString());
axisColor=jkqtp_String2QColor(settings.value(group+"color", jkqtp_QColor2String(defaultStyle.axisColor)).toString());
tickColor=jkqtp_String2QColor(settings.value(group+"ticks/color", jkqtp_QColor2String(defaultStyle.tickColor)).toString());
minorTickColor=jkqtp_String2QColor(settings.value(group+"minor_tick/color", jkqtp_QColor2String(defaultStyle.minorTickColor)).toString());
tickLabelColor=jkqtp_String2QColor(settings.value(group+"ticks/label_color", jkqtp_QColor2String(defaultStyle.tickLabelColor)).toString());
minorTickLabelColor=jkqtp_String2QColor(settings.value(group+"minor_tick/label_color", jkqtp_QColor2String(defaultStyle.minorTickLabelColor)).toString());
drawMode1=String2JKQTPCADrawMode(settings.value(group+"draw_mode1", JKQTPCADrawMode2String(defaultStyle.drawMode1)).toString());
drawMode2=String2JKQTPCADrawMode(settings.value(group+"draw_mode2", JKQTPCADrawMode2String(defaultStyle.drawMode2)).toString());
drawMode0=String2JKQTPCADrawMode(settings.value(group+"draw_mode0", JKQTPCADrawMode2String(defaultStyle.drawMode0)).toString());
tickMode=String2JKQTPLabelTickMode(settings.value(group+"ticks/mode", JKQTPLabelTickMode2String(defaultStyle.tickMode)).toString());
colorZeroAxis=jkqtp_String2QColor(settings.value(group+"zero_line/color", jkqtp_QColor2String(defaultStyle.colorZeroAxis)).toString());
styleZeroAxis=jkqtp_String2QPenStyle(settings.value(group+"zero_line/style", jkqtp_QPenStyle2String(defaultStyle.styleZeroAxis)).toString());
axisLineOffset = settings.value(group+"axis_lines_offset", defaultStyle.axisLineOffset).toDouble();
majorGridStyle.loadSettings(settings, group+"grid/", defaultStyle.majorGridStyle);
minorGridStyle.loadSettings(settings, group+"minor_grid/", defaultStyle.minorGridStyle);
@ -134,6 +136,7 @@ void JKQTPCoordinateAxisStyle::saveSettings(QSettings &settings, const QString &
settings.setValue(group+"color", jkqtp_QColor2String(axisColor));
settings.setValue(group+"draw_mode1", JKQTPCADrawMode2String(drawMode1));
settings.setValue(group+"draw_mode2", JKQTPCADrawMode2String(drawMode2));
settings.setValue(group+"draw_mode0", JKQTPCADrawMode2String(drawMode2));
settings.setValue(group+"line_width", lineWidth);
settings.setValue(group+"arrow_size_factor", arrowSizeFactor);
settings.setValue(group+"axis_lines_offset", axisLineOffset);
@ -233,4 +236,5 @@ void JKQTPColorbarCoordinateAxisStyle::initMembersForColorbars() {
tickOutsideLength=0;
minorTickOutsideLength=0;
showZeroAxis=false;
drawMode0=JKQTPCADMnone;
}

View File

@ -73,7 +73,9 @@ public:
/** \brief Support Class for JKQTPCoordinateAxis, which summarizes all properties that define the visual styling of a JKQTPCoordinateAxis
* \ingroup jkqtpplotter_styling_classes
*
* \see JKQTPCoordinateAxis, \ref jkqtpplotter_styling
* \image html jkqtpcoordinateaxis1.png
*
* \see JKQTPCoordinateAxis, \ref jkqtpplotter_styling
*
*/
class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxisStyle {
@ -132,6 +134,13 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxisStyle {
JKQTPCADrawMode drawMode1;
/** \brief draw mode of the secondary (right/top) axis */
JKQTPCADrawMode drawMode2;
/** \brief draw mode of the zero axis
*
* \image html JKQTPCoordinateAxisStyleDrawMode0.png
*
* \see \ref JKQTPlotterGeometricCoordinateAxis0
*/
JKQTPCADrawMode drawMode0;
/** \brief color of minor ticks */
QColor minorTickColor;
/** \brief color of minor tick labels */

Binary file not shown.

Before

Width:  |  Height:  |  Size: 131 KiB

After

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 173 KiB

After

Width:  |  Height:  |  Size: 187 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 75 KiB

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 KiB

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.8 KiB

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB