mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-11-15 10:05:47 +08:00
NEW: added JKQTPGLabelHalfwaysToXAxis+JKQTPGLabelHalfwaysToYAxis to JKQTPXYGraphLabels
This commit is contained in:
parent
7ed751903a
commit
d9f2383791
2
.gitignore
vendored
2
.gitignore
vendored
@ -187,3 +187,5 @@ Sicherungskopie_*
|
||||
/doc/images/JKQTPBarHorizontalAutoscaleShrinkOnly_small.png
|
||||
/doc/images/JKQTPBarVerticalAutoscaleMaxWidthOnly_small.png
|
||||
/doc/images/JKQTPBarVerticalAutoscaleShrinkOnly_small.png
|
||||
/doc/images/JKQTPGLabelHalfwaysToXAxis_small.png
|
||||
/doc/images/JKQTPGLabelHalfwaysToYAxis_small.png
|
||||
|
@ -276,7 +276,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,JKQTPGLabelCenteredOnData,JKQTPGLabelCenteredOnDataVertical,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,JKQTPGLabelHalfwaysToXAxis,JKQTPGLabelHalfwaysToYAxis/--iteratefunctorsteps--smallscreenshotplot
|
||||
vectorfield/JKQTPVectorFieldGraph,JKQTPVectorFieldGraphAnchorBottom,JKQTPVectorFieldGraphAnchorMid,JKQTPVectorFieldGraphAnchorTip,JKQTPVectorFieldGraphAutoscaleLength,JKQTPVectorFieldGraphLengthFromData,JKQTPVectorFieldGraphIgnoreLength,JKQTPVectorFieldGraphIgnoreLengthAutoscaleLineWidthFromLength,JKQTPVectorFieldGraphAutoscaleLengthAutoscaleLineWidthFromLength/--iteratefunctorsteps
|
||||
paramvectorfield/JKQTPParametrizedVectorFieldGraph,JKQTPParametrizedVectorFieldGraphColorFromMagnitude,JKQTPParametrizedVectorFieldGraphColorFromAngle,JKQTPParametrizedVectorFieldGraphDefaultColor/--iteratefunctorsteps
|
||||
financialgraphs/JKQTPFinancialGraph,JKQTPFinancialGraphCandleStick,JKQTPFinancialGraphSetCandlestickTwoColor,JKQTPFinancialGraphSetCandlestickTwoColor2,JKQTPFinancialGraphSetCandlestickOneColor,JKQTPFinancialGraphOHLC,JKQTPFinancialGraphSetOHLCTwoColor,JKQTPFinancialGraphSidyBySide/--iteratefunctorsteps
|
||||
|
BIN
doc/images/JKQTPGLabelHalfwaysToXAxis.png
Normal file
BIN
doc/images/JKQTPGLabelHalfwaysToXAxis.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
BIN
doc/images/JKQTPGLabelHalfwaysToYAxis.png
Normal file
BIN
doc/images/JKQTPGLabelHalfwaysToYAxis.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
@ -151,6 +151,18 @@ int main(int argc, char* argv[])
|
||||
plotV.redrawPlot();
|
||||
plotH.redrawPlot();
|
||||
});
|
||||
app.addExportStepFunctor([&](){
|
||||
gV.first->setVisible(true);
|
||||
gH.first->setVisible(true);
|
||||
gV.second->setLabelPosition(JKQTPGLabelHalfwaysToXAxis);
|
||||
gV.second->setLabelBoxType(JKQTPGLSimpleBox);
|
||||
gV.second->setDrawLabelBoxFrame(false);
|
||||
gH.second->setLabelPosition(JKQTPGLabelHalfwaysToYAxis);
|
||||
gH.second->setLabelBoxType(JKQTPGLSimpleBox);
|
||||
gH.second->setDrawLabelBoxFrame(false);
|
||||
plotV.redrawPlot();
|
||||
plotH.redrawPlot();
|
||||
});
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
@ -89,9 +89,11 @@ void JKQTPXYGraphLabels::draw(JKQTPEnhancedPainter& painter) {
|
||||
const double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i));
|
||||
const double x=transformX(xv);
|
||||
const double y=transformY(yv);
|
||||
const double blXv=(0.0>=parent->getXMin() && 0.0<=parent->getXMax()) ? 0.0 : parent->getXMin();
|
||||
const double blYv=(0.0>=parent->getYMin() && 0.0<=parent->getYMax()) ? 0.0 : parent->getYMin();
|
||||
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv) && JKQTPIsOKFloat(x) && JKQTPIsOKFloat(y)) {
|
||||
const QString label=generateLabel(xv,yv,iii);
|
||||
drawLabel(painter, QPointF(x,y), QPointF(xv,yv), label, parent);
|
||||
drawLabel(painter, QPointF(x,y), QPointF(xv,yv), label, parent, blXv, blYv);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,8 @@ QString JKQTPGraphLabelPosition2String(JKQTPGraphLabelPosition pos)
|
||||
case JKQTPGLabelTowardsXAxis: return "label_towards_xaxis";
|
||||
case JKQTPGLabelTowardsYAxis: return "label_towards_xaxis";
|
||||
case JKQTPGLabelCenteredOnData: return "label_centered";
|
||||
case JKQTPGLabelHalfwaysToXAxis: return "label_halfways_to_xaxis";
|
||||
case JKQTPGLabelHalfwaysToYAxis: return "label_halfways_to_yaxis";
|
||||
}
|
||||
return "label_away_from_xaxis";
|
||||
}
|
||||
@ -49,8 +51,10 @@ JKQTPGraphLabelPosition String2JKQTPGraphLabelPosition(const QString &pos)
|
||||
if (m=="label_right_hand_side" || m=="right_hand_side" || m=="right_hand" || m=="right" || m=="rhs") return JKQTPGLabelRightHandSide;
|
||||
if (m=="label_away_from_xaxis" || m=="away_from_xaxis") return JKQTPGLabelAwayFromXAxis;
|
||||
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_towards_xaxis" || m=="towardds_xaxis") return JKQTPGLabelTowardsXAxis;
|
||||
if (m=="label_towards_yaxis" || m=="towars_yaxis") return JKQTPGLabelTowardsYAxis;
|
||||
if (m=="label_halfways_to_xaxis" || m=="halfways_to_xaxis") return JKQTPGLabelHalfwaysToXAxis;
|
||||
if (m=="label_halfways_to_yaxis" || m=="halfways_to_yaxis") return JKQTPGLabelHalfwaysToYAxis;
|
||||
if (m=="label_centered" || m=="centered" || m=="label_centered_on_data" || m=="centered_on_data") return JKQTPGLabelCenteredOnData;
|
||||
return JKQTPGraphLabelDefault;
|
||||
}
|
||||
@ -188,6 +192,8 @@ bool JKQTPGraphValueLabelStyleMixin::isLabelPositioningGrowingInX() const
|
||||
case JKQTPGLabelTowardsXAxis:
|
||||
case JKQTPGLabelTowardsYAxis:
|
||||
case JKQTPGLabelCenteredOnData:
|
||||
case JKQTPGLabelHalfwaysToXAxis:
|
||||
case JKQTPGLabelHalfwaysToYAxis:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
@ -206,6 +212,8 @@ bool JKQTPGraphValueLabelStyleMixin::isLabelPositioningGrowingInY() const
|
||||
case JKQTPGLabelLeftHandSide:
|
||||
case JKQTPGLabelRightHandSide:
|
||||
case JKQTPGLabelCenteredOnData:
|
||||
case JKQTPGLabelHalfwaysToXAxis:
|
||||
case JKQTPGLabelHalfwaysToYAxis:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
@ -231,12 +239,12 @@ JKQTPGraphLabelBoxType JKQTPGraphValueLabelStyleMixin::getLabelBoxType() const
|
||||
return m_labelBoxType;
|
||||
}
|
||||
|
||||
void JKQTPGraphValueLabelStyleMixin::drawLabel(JKQTPEnhancedPainter &painter, const QPointF &xDataPixel, const QPointF &xData, const QString &contents, JKQTBasePlotter *parent) const
|
||||
void JKQTPGraphValueLabelStyleMixin::drawLabel(JKQTPEnhancedPainter &painter, const QPointF &xDataPixel, const QPointF &xData, const QString &contents, JKQTBasePlotter *parent, double baselineX, double baselineY) const
|
||||
{
|
||||
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
||||
|
||||
// calculate geometry
|
||||
const LabelGeometry g=calcLabelGeometry(painter, xDataPixel, xData, contents, parent);
|
||||
const LabelGeometry g=calcLabelGeometry(painter, xDataPixel, xData, contents, parent, baselineX, baselineY);
|
||||
|
||||
// draw Box
|
||||
if (m_drawLabelBoxFrame) painter.setPen(getLinePenForRects(painter, parent));
|
||||
@ -275,7 +283,7 @@ void JKQTPGraphValueLabelStyleMixin::drawLabel(JKQTPEnhancedPainter &painter, co
|
||||
parent->getMathText()->draw(painter, Qt::AlignVCenter|Qt::AlignHCenter, g.textRect, parent->getCurrentPlotterStyle().debugShowTextBoxes);
|
||||
}
|
||||
|
||||
JKQTPGraphValueLabelStyleMixin::LabelGeometry JKQTPGraphValueLabelStyleMixin::calcLabelGeometry(JKQTPEnhancedPainter &painter, const QPointF &xDataPixel, const QPointF &xData, const QString &contents, JKQTBasePlotter *parent) const
|
||||
JKQTPGraphValueLabelStyleMixin::LabelGeometry JKQTPGraphValueLabelStyleMixin::calcLabelGeometry(JKQTPEnhancedPainter &painter, const QPointF &xDataPixel, const QPointF &xData, const QString &contents, JKQTBasePlotter *parent, double baselineX, double baselineY) const
|
||||
{
|
||||
LabelGeometry res;
|
||||
res.label=contents;
|
||||
@ -304,6 +312,12 @@ JKQTPGraphValueLabelStyleMixin::LabelGeometry JKQTPGraphValueLabelStyleMixin::ca
|
||||
} 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;
|
||||
} else if (m_labelPosition==JKQTPGLabelHalfwaysToXAxis) {
|
||||
res.textRect=QRectF(xDataPixel.x()-res.textSize.width/2.0, (xDataPixel.y()+parent->getYAxis()->x2p(baselineY))/2.0-res.textSize.overallHeight/2.0, res.textSize.width, res.textSize.overallHeight);
|
||||
res.boxpos=LabelGeometry::BoxCentered;
|
||||
} else if (m_labelPosition==JKQTPGLabelHalfwaysToYAxis) {
|
||||
res.textRect=QRectF((xDataPixel.x()+parent->getXAxis()->x2p(baselineX))/2.0-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);
|
||||
|
@ -53,6 +53,8 @@ enum JKQTPGraphLabelPosition {
|
||||
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 */
|
||||
JKQTPGLabelHalfwaysToXAxis, /*!< \brief all labels half-ways between the datapoint and the x-axis the datapoint \image html JKQTPGLabelHalfwaysToXAxis.png */
|
||||
JKQTPGLabelHalfwaysToYAxis, /*!< \brief all labels half-ways between the datapoint and the y-axis the datapoint \image html JKQTPGLabelHalfwaysToYAxis.png */
|
||||
|
||||
|
||||
JKQTPGraphLabelDefault=JKQTPGLabelAwayFromXAxis,
|
||||
@ -182,9 +184,11 @@ public:
|
||||
* \brief xData x- and y-coordinate of the datapoint (needed for some JKQTPGraphLabelPosition)
|
||||
* \brief contents the text to be rendered
|
||||
* \brief parent the JKQTPBasePlotter in whos context we are drawing (e.g. needed to render \a contents )
|
||||
* \brief baselineX baseline (in graph coordinate system, not pixels) of the graph in x-direction (typically 0), needed for JKQTPGLabelHalfwaysToYAxis
|
||||
* \brief baselineY baseline (in graph coordinate system, not pixels) of the graph in y-direction (typically 0), needed for JKQTPGLabelHalfwaysToXAxis
|
||||
*
|
||||
*/
|
||||
void drawLabel(JKQTPEnhancedPainter& painter, const QPointF& xDataPixel, const QPointF& xData, const QString& contents, JKQTBasePlotter *parent) const;
|
||||
void drawLabel(JKQTPEnhancedPainter& painter, const QPointF& xDataPixel, const QPointF& xData, const QString& contents, JKQTBasePlotter *parent, double baselineX, double baselineY) const;
|
||||
|
||||
|
||||
|
||||
@ -238,9 +242,11 @@ protected:
|
||||
* \brief xData x- and y-coordinate of the datapoint (needed for some JKQTPGraphLabelPosition)
|
||||
* \brief contents the text to be rendered
|
||||
* \brief parent the JKQTPBasePlotter in whos context we are drawing (e.g. needed to render \a contents )
|
||||
* \brief baselineX baseline (in graph coordinate system, not pixels) of the graph in x-direction (typically 0), needed for JKQTPGLabelHalfwaysToYAxis
|
||||
* \brief baselineY baseline (in graph coordinate system, not pixels) of the graph in y-direction (typically 0), needed for JKQTPGLabelHalfwaysToXAxis
|
||||
*
|
||||
*/
|
||||
LabelGeometry calcLabelGeometry(JKQTPEnhancedPainter& painter, const QPointF& xDataPixel, const QPointF& xData, const QString& contents, JKQTBasePlotter *parent) const;
|
||||
LabelGeometry calcLabelGeometry(JKQTPEnhancedPainter& painter, const QPointF& xDataPixel, const QPointF& xData, const QString& contents, JKQTBasePlotter *parent, double baselineX, double baselineY) const;
|
||||
|
||||
private:
|
||||
/** \brief offset of the box rectangle to the actual data point location [pt], this is used for simple boxes and is a rather close distance (e.g. JKQTPGLSimpleBox)
|
||||
|
Loading…
Reference in New Issue
Block a user