diff --git a/.gitignore b/.gitignore index 514a656667..b7779bff54 100644 --- a/.gitignore +++ b/.gitignore @@ -178,3 +178,6 @@ Sicherungskopie_* /doc/images/JKQTPGLabelTowardsYAxis_small.png /doc/images/JKQTPGLSimpleBoxVertical_small.png /doc/images/JKQTPGLSimpleBox_small.png +/doc/images/JKQTPGLabelCenteredOnDataVertical.png +/doc/images/JKQTPGLabelCenteredOnDataVertical_small.png +/doc/images/JKQTPGLabelCenteredOnData_small.png diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index db2c5f4b27..581818fd9c 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -273,7 +273,7 @@ if(JKQtPlotter_BUILD_EXAMPLES) symbols_and_errors/JKQTPXYLineErrorGraph_JKQTPErrorBars,JKQTPXYLineErrorGraph_JKQTPErrorLines,JKQTPXYLineErrorGraph_JKQTPErrorPolygons/--iteratefunctorsteps--iteratefunctorsteps_suppressinitial--smallscreenshotplot boxplot/JKQTPBoxplotVerticalGraph,JKQTPBoxplotHorizontalGraph/--iteratefunctorsteps--iteratefunctorsteps_suppressinitial--smallscreenshotplot second_axis/JKQTBasePlotter_addSecondaryYAxis,JKQTBasePlotter_addSecondaryXAxis - graphlabels/JKQTPGLabelAwayFromXAxis,JKQTPGLabelAwayFromYAxis,JKQTPGLabelTowardsXAxis,JKQTPGLabelTowardsYAxis,JKQTPGLabelAboveData,JKQTPGLabelRightHandSide,JKQTPGLabelBelowData,JKQTPGLabelLeftHandSide,JKQTPGLSimpleBox,JKQTPGLSimpleBoxVertical,JKQTPGLSimpleBoxAndLine,JKQTPGLSimpleBoxAndLineVertical,JKQTPGLSimpleBoxAndLineONLYLABELS,JKQTPGLSimpleBoxAndLineONLYLABELSVertical/--iteratefunctorsteps--smallscreenshotplot + graphlabels/JKQTPGLabelAwayFromXAxis,JKQTPGLabelAwayFromYAxis,JKQTPGLabelTowardsXAxis,JKQTPGLabelTowardsYAxis,JKQTPGLabelAboveData,JKQTPGLabelRightHandSide,JKQTPGLabelBelowData,JKQTPGLabelLeftHandSide,JKQTPGLabelCenteredOnData,JKQTPGLabelCenteredOnDataVertical,JKQTPGLSimpleBox,JKQTPGLSimpleBoxVertical,JKQTPGLSimpleBoxAndLine,JKQTPGLSimpleBoxAndLineVertical,JKQTPGLSimpleBoxAndLineONLYLABELS,JKQTPGLSimpleBoxAndLineONLYLABELSVertical/--iteratefunctorsteps--smallscreenshotplot vectorfield/JKQTPVectorFieldGraph,JKQTPVectorFieldGraphAnchorBottom,JKQTPVectorFieldGraphAnchorMid,JKQTPVectorFieldGraphAnchorTip,JKQTPVectorFieldGraphAutoscaleLength,JKQTPVectorFieldGraphLengthFromData,JKQTPVectorFieldGraphIgnoreLength,JKQTPVectorFieldGraphIgnoreLengthAutoscaleLineWidthFromLength,JKQTPVectorFieldGraphAutoscaleLengthAutoscaleLineWidthFromLength/--iteratefunctorsteps ) diff --git a/doc/images/JKQTPGLabelCenteredOnData.png b/doc/images/JKQTPGLabelCenteredOnData.png new file mode 100644 index 0000000000..39d4d5a53e Binary files /dev/null and b/doc/images/JKQTPGLabelCenteredOnData.png differ diff --git a/examples/graphlabels/graphlabels.cpp b/examples/graphlabels/graphlabels.cpp index 623f7d7968..f052b427c3 100644 --- a/examples/graphlabels/graphlabels.cpp +++ b/examples/graphlabels/graphlabels.cpp @@ -110,7 +110,19 @@ int main(int argc, char* argv[]) plotV.redrawPlot(); plotH.redrawPlot(); }); + app.addExportStepFunctor([&](){ + gV.second->setLabelPosition(JKQTPGLabelCenteredOnData); + gH.second->setLabelPosition(JKQTPGLabelCenteredOnData); + gV.first->setVisible(false); + gH.first->setVisible(false); + plotV.redrawPlot(); + plotH.redrawPlot(); + }); + + app.addExportStepFunctor([&](){ + gV.first->setVisible(true); + gH.first->setVisible(true); gV.second->setLabelPosition(JKQTPGLabelAwayFromXAxis); gV.second->setLabelBoxType(JKQTPGLSimpleBox); gV.second->setDrawLabelBoxFrame(true); diff --git a/lib/jkqtplotter/graphs/jkqtpgraphlabelstylemixin.cpp b/lib/jkqtplotter/graphs/jkqtpgraphlabelstylemixin.cpp index 40dd7f0033..f5a8b57cf6 100644 --- a/lib/jkqtplotter/graphs/jkqtpgraphlabelstylemixin.cpp +++ b/lib/jkqtplotter/graphs/jkqtpgraphlabelstylemixin.cpp @@ -35,6 +35,7 @@ QString JKQTPGraphLabelPosition2String(JKQTPGraphLabelPosition pos) case JKQTPGLabelAwayFromYAxis: return "label_away_from_yaxis"; case JKQTPGLabelTowardsXAxis: return "label_towards_xaxis"; case JKQTPGLabelTowardsYAxis: return "label_towards_xaxis"; + case JKQTPGLabelCenteredOnData: return "label_centered"; } return "label_away_from_xaxis"; } @@ -50,6 +51,7 @@ JKQTPGraphLabelPosition String2JKQTPGraphLabelPosition(const QString &pos) if (m=="label_away_from_yaxis" || m=="away_from_yaxis") return JKQTPGLabelAwayFromYAxis; if (m=="label_towars_xaxis" || m=="towars_xaxis") return JKQTPGLabelTowardsXAxis; if (m=="label_towars_yaxis" || m=="towars_yaxis") return JKQTPGLabelTowardsYAxis; + if (m=="label_centered" || m=="centered" || m=="label_centered_on_data" || m=="centered_on_data") return JKQTPGLabelCenteredOnData; return JKQTPGraphLabelDefault; } @@ -185,6 +187,7 @@ bool JKQTPGraphValueLabelStyleMixin::isLabelPositioningGrowingInX() const case JKQTPGLabelAwayFromXAxis: case JKQTPGLabelTowardsXAxis: case JKQTPGLabelTowardsYAxis: + case JKQTPGLabelCenteredOnData: return false; } return false; @@ -202,6 +205,7 @@ bool JKQTPGraphValueLabelStyleMixin::isLabelPositioningGrowingInY() const case JKQTPGLabelTowardsYAxis: case JKQTPGLabelLeftHandSide: case JKQTPGLabelRightHandSide: + case JKQTPGLabelCenteredOnData: return false; } return false; @@ -257,7 +261,8 @@ void JKQTPGraphValueLabelStyleMixin::drawLabel(JKQTPEnhancedPainter &painter, co case LabelGeometry::BoxBottom: painter.drawLine(xDataPixel, QPointF(xDataPixel.x(), qMin(g.boxRect.top(),g.boxRect.bottom()))); break; - + case LabelGeometry::BoxCentered: + break; } } @@ -296,6 +301,9 @@ JKQTPGraphValueLabelStyleMixin::LabelGeometry JKQTPGraphValueLabelStyleMixin::ca // rhs res.textRect=QRectF(xDataPixel.x()+res.labelOffsetPx+res.padX+res.lw/2.0, xDataPixel.y()-res.textSize.overallHeight/2.0, res.textSize.width, res.textSize.overallHeight); res.boxpos=LabelGeometry::BoxRight; + } else if (m_labelPosition==JKQTPGLabelCenteredOnData) { + res.textRect=QRectF(xDataPixel.x()-res.textSize.width/2.0, xDataPixel.y()-res.textSize.overallHeight/2.0, res.textSize.width, res.textSize.overallHeight); + res.boxpos=LabelGeometry::BoxCentered; } res.boxRect=QRectF(res.textRect.x()-res.padX-res.lw/2.0, res.textRect.y()-res.padY-res.lw/2.0, res.textRect.width()+res.padX*2.0+res.lw, res.textRect.height()+res.padY*2.0+res.lw); diff --git a/lib/jkqtplotter/graphs/jkqtpgraphlabelstylemixin.h b/lib/jkqtplotter/graphs/jkqtpgraphlabelstylemixin.h index be89ca71f3..c957bee852 100644 --- a/lib/jkqtplotter/graphs/jkqtpgraphlabelstylemixin.h +++ b/lib/jkqtplotter/graphs/jkqtpgraphlabelstylemixin.h @@ -52,6 +52,8 @@ enum JKQTPGraphLabelPosition { JKQTPGLabelLeftHandSide, /*!< \brief all labels always on the left-hand side of the datapoint \image html JKQTPGLabelLeftHandSide.png */ JKQTPGLabelTowardsYAxis, /*!< \brief all labels between the datapoint and the y-axis the datapoint \image html JKQTPGLabelTowardsYAxis.png */ JKQTPGLabelAwayFromYAxis, /*!< \brief all labels pointing away from the y-axis \image html JKQTPGLabelAwayFromYAxis.png */ + JKQTPGLabelCenteredOnData, /*!< \brief graph label is drawn centered arond the data point \c (x,y) \image html JKQTPGLabelCenteredOnData.png */ + JKQTPGraphLabelDefault=JKQTPGLabelAwayFromXAxis, }; @@ -223,7 +225,8 @@ protected: BoxLeft, BoxRight, BoxTop, - BoxBottom + BoxBottom, + BoxCentered }; BoxPos boxpos; };