moved set/getBaseline() to a special base graph class JKQTPXYBaselineGraph

This commit is contained in:
jkriege2 2020-09-19 15:08:32 +02:00
parent 34fa59ebf4
commit d57da36a99
9 changed files with 90 additions and 94 deletions

View File

@ -92,7 +92,7 @@ void JKQTPBarVerticalGraph::draw(JKQTPEnhancedPainter& painter) {
int lr=datastore->getNextHigherIndex(xColumn, i); int lr=datastore->getNextHigherIndex(xColumn, i);
double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i)); double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i));
double yv0=y0; double yv0=y0;
if (!qFuzzyIsNull(baseline)) yv0=transformY(baseline); if (!qFuzzyIsNull(getBaseline())) yv0=transformY(getBaseline());
if (hasStackPar) { if (hasStackPar) {
double stackLastY=getParentStackedMax(i); double stackLastY=getParentStackedMax(i);
const double yvold=yv; const double yvold=yv;
@ -276,7 +276,7 @@ void JKQTPBarHorizontalGraph::draw(JKQTPEnhancedPainter& painter) {
int sr=datastore->getNextLowerIndex(yColumn, i); int sr=datastore->getNextLowerIndex(yColumn, i);
int lr=datastore->getNextHigherIndex(yColumn, i); int lr=datastore->getNextHigherIndex(yColumn, i);
double xv0=x0; double xv0=x0;
if (!qFuzzyIsNull(baseline)) xv0=transformX(baseline); if (!qFuzzyIsNull(getBaseline())) xv0=transformX(getBaseline());
if (hasStackPar) { if (hasStackPar) {
double stackLastX=getParentStackedMax(i); double stackLastX=getParentStackedMax(i);
const double xvold=xv; const double xvold=xv;
@ -300,7 +300,7 @@ void JKQTPBarHorizontalGraph::draw(JKQTPEnhancedPainter& painter) {
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) { if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) {
double x=xv0; double x=xv0;
if (!qFuzzyIsNull(baseline)) x=transformX(baseline); if (!qFuzzyIsNull(getBaseline())) x=transformX(getBaseline());
double y=transformY(yv+shift*delta+width*deltap); double y=transformY(yv+shift*delta+width*deltap);
double xx=transformX(xv); double xx=transformX(xv);
double yy=transformY(yv+shift*delta-width*deltam); double yy=transformY(yv+shift*delta-width*deltam);
@ -456,10 +456,10 @@ bool JKQTPBarVerticalErrorGraph::getYMinMax(double &miny, double &maxy, double &
miny=0; miny=0;
maxy=0; maxy=0;
smallestGreaterZero=0; smallestGreaterZero=0;
if (baseline>0) { if (getBaseline()>0) {
smallestGreaterZero=baseline; smallestGreaterZero=getBaseline();
miny=baseline; miny=getBaseline();
maxy=baseline; maxy=getBaseline();
} }
if (parent==nullptr) return false; if (parent==nullptr) return false;
@ -476,7 +476,7 @@ bool JKQTPBarVerticalErrorGraph::getYMinMax(double &miny, double &maxy, double &
if (imax<0) imax=0; if (imax<0) imax=0;
for (int i=imin; i<imax; i++) { for (int i=imin; i<imax; i++) {
double yv=baseline; double yv=getBaseline();
if (JKQTPIsOKFloat(yv)) { if (JKQTPIsOKFloat(yv)) {
if (yv>maxy) maxy=yv; if (yv>maxy) maxy=yv;
if (yv<miny) miny=yv; if (yv<miny) miny=yv;
@ -494,13 +494,13 @@ bool JKQTPBarVerticalErrorGraph::getYMinMax(double &miny, double &maxy, double &
return true; return true;
} else { } else {
bool start=false; bool start=false;
miny=baseline; miny=getBaseline();
maxy=baseline; maxy=getBaseline();
smallestGreaterZero=0; smallestGreaterZero=0;
if (baseline>0) { if (getBaseline()>0) {
smallestGreaterZero=baseline; smallestGreaterZero=getBaseline();
miny=baseline; miny=getBaseline();
maxy=baseline; maxy=getBaseline();
} }
if (parent==nullptr) return false; if (parent==nullptr) return false;
@ -610,7 +610,7 @@ double JKQTPBarVerticalStackableGraph::getParentStackedMax(int index) const
if (stackParent) { if (stackParent) {
return stackParent->getStackedMax(index); return stackParent->getStackedMax(index);
} else { } else {
return baseline; return getBaseline();
} }
} }
@ -695,7 +695,7 @@ double JKQTPBarHorizontalStackableGraph::getParentStackedMax(int index) const
if (stackParent) { if (stackParent) {
return stackParent->getStackedMax(index); return stackParent->getStackedMax(index);
} else { } else {
return baseline; return getBaseline();
} }
} }

View File

@ -37,7 +37,7 @@
JKQTPBarGraphBase::JKQTPBarGraphBase(JKQTBasePlotter* parent): JKQTPBarGraphBase::JKQTPBarGraphBase(JKQTBasePlotter* parent):
JKQTPXYGraph(parent), width(0.9), shift(0), baseline(0.0) JKQTPXYBaselineGraph(parent), width(0.9), shift(0)
{ {
initFillStyle(parent, parentPlotStyle); initFillStyle(parent, parentPlotStyle);
initLineStyle(parent, parentPlotStyle); initLineStyle(parent, parentPlotStyle);
@ -134,16 +134,6 @@ double JKQTPBarGraphBase::getWidth() const
return this->width; return this->width;
} }
void JKQTPBarGraphBase::setBaseline(double __value)
{
this->baseline = __value;
}
double JKQTPBarGraphBase::getBaseline() const
{
return this->baseline;
}
void JKQTPBarGraphBase::setFillColor_and_darkenedColor(QColor fill, int colorDarker) void JKQTPBarGraphBase::setFillColor_and_darkenedColor(QColor fill, int colorDarker)
{ {
setFillColor(fill); setFillColor(fill);
@ -152,7 +142,7 @@ void JKQTPBarGraphBase::setFillColor_and_darkenedColor(QColor fill, int colorDar
double JKQTPBarGraphBase::getParentStackedMax(int /*index*/) const double JKQTPBarGraphBase::getParentStackedMax(int /*index*/) const
{ {
return baseline; return getBaseline();
} }
bool JKQTPBarGraphBase::hasStackParent() const bool JKQTPBarGraphBase::hasStackParent() const
@ -165,10 +155,10 @@ bool JKQTPBarGraphBase::getValuesMinMax(double &mmin, double &mmax, double &smal
mmin=0; mmin=0;
mmax=0; mmax=0;
smallestGreaterZero=0; smallestGreaterZero=0;
if (baseline>0) { if (getBaseline()>0) {
smallestGreaterZero=baseline; smallestGreaterZero=getBaseline();
mmin=baseline; mmin=getBaseline();
mmax=baseline; mmax=getBaseline();
} }
if (getBarPositionColumn()<0 || getBarHeightColumn()<0) return false; if (getBarPositionColumn()<0 || getBarHeightColumn()<0) return false;
@ -184,7 +174,7 @@ bool JKQTPBarGraphBase::getValuesMinMax(double &mmin, double &mmax, double &smal
for (int i=imin; i<imax; i++) { for (int i=imin; i<imax; i++) {
double stack=0; double stack=0;
double yv=baseline; double yv=getBaseline();
const double boxstart=getParentStackedMax(i); const double boxstart=getParentStackedMax(i);
if (hasStackParent()) { if (hasStackParent()) {
stack=boxstart; stack=boxstart;

View File

@ -54,7 +54,7 @@
* *
* \see JKQTPBarHorizontalGraph, JKQTPBarVerticalGraph * \see JKQTPBarHorizontalGraph, JKQTPBarVerticalGraph
*/ */
class JKQTPLOTTER_LIB_EXPORT JKQTPBarGraphBase: public JKQTPXYGraph, public JKQTPGraphLineStyleMixin, public JKQTPGraphFillStyleMixin { class JKQTPLOTTER_LIB_EXPORT JKQTPBarGraphBase: public JKQTPXYBaselineGraph, public JKQTPGraphLineStyleMixin, public JKQTPGraphFillStyleMixin {
Q_OBJECT Q_OBJECT
public: public:
/** \brief class constructor */ /** \brief class constructor */
@ -73,8 +73,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPBarGraphBase: public JKQTPXYGraph, public JKQT
double getShift() const; double getShift() const;
/*! \copydoc width */ /*! \copydoc width */
double getWidth() const; double getWidth() const;
/*! \copydoc baseline */
double getBaseline() const;
/** \brief sets the fill color and the color together, where fillColor is set to \a fill and the line-color is set to \c fill.darker(colorDarker) /** \brief sets the fill color and the color together, where fillColor is set to \a fill and the line-color is set to \c fill.darker(colorDarker)
* \see setColor() * \see setColor()
*/ */
@ -103,8 +102,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPBarGraphBase: public JKQTPXYGraph, public JKQT
void setShift(double __value); void setShift(double __value);
/*! \copydoc width */ /*! \copydoc width */
void setWidth(double __value); void setWidth(double __value);
/*! \copydoc baseline */
void setBaseline(double __value);
/** \brief set outline and fill color at the same time /** \brief set outline and fill color at the same time
* \see setFillColor_and_darkenedColor() * \see setFillColor_and_darkenedColor()
@ -137,9 +135,6 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPBarGraphBase: public JKQTPXYGraph, public JKQT
*/ */
double shift; double shift;
/** \brief baseline of the plot (NOTE: 0 is interpreted as until plot border in log-mode!!!)
*/
double baseline;
/** \brief this function is used by autoscaleBarWidthAndShift() to determine whether a given graph shall be taken into account when autoscaling. /** \brief this function is used by autoscaleBarWidthAndShift() to determine whether a given graph shall be taken into account when autoscaling.
* Typically this returns \c true for all JKQTPBarGraphBase-derved objects with the same orientation (horizontal or vertical) */ * Typically this returns \c true for all JKQTPBarGraphBase-derved objects with the same orientation (horizontal or vertical) */

View File

@ -35,9 +35,8 @@
JKQTPImpulsesHorizontalGraph::JKQTPImpulsesHorizontalGraph(JKQTBasePlotter* parent): JKQTPImpulsesHorizontalGraph::JKQTPImpulsesHorizontalGraph(JKQTBasePlotter* parent):
JKQTPXYGraph(parent) JKQTPXYBaselineGraph(parent)
{ {
baseline=0;
drawSymbols=false; drawSymbols=false;
initLineStyle(parent, parentPlotStyle); initLineStyle(parent, parentPlotStyle);
initSymbolStyle(parent, parentPlotStyle); initSymbolStyle(parent, parentPlotStyle);
@ -76,15 +75,15 @@ void JKQTPImpulsesHorizontalGraph::draw(JKQTPEnhancedPainter& painter) {
//double xold=-1; //double xold=-1;
//double yold=-1; //double yold=-1;
double x0=transformX(baseline); double x0=transformX(getBaseline());
if (parent->getXAxis()->isLogAxis()) { if (parent->getXAxis()->isLogAxis()) {
if (baseline>0 && baseline>parent->getXAxis()->getMin()) x0=transformX(baseline); if (getBaseline()>0 && getBaseline()>parent->getXAxis()->getMin()) x0=transformX(getBaseline());
else x0=transformX(parent->getXAxis()->getMin()); else x0=transformX(parent->getXAxis()->getMin());
} }
// double y0=transformY(baseline); // double y0=transformY(getBaseline());
// if (parent->getYAxis()->isLogAxis()) { // if (parent->getYAxis()->isLogAxis()) {
// y0=transformY(parent->getYAxis()->getMin()); // y0=transformY(parent->getYAxis()->getMin());
// if (baseline>0 && baseline>parent->getYAxis()->getMin()) y0=transformY(baseline); // if (getBaseline()>0 && getBaseline()>parent->getYAxis()->getMin()) y0=transformY(getBaseline());
// else y0=transformY(parent->getYAxis()->getMin()); // else y0=transformY(parent->getYAxis()->getMin());
// } // }
//bool first=false; //bool first=false;
@ -145,16 +144,6 @@ void JKQTPImpulsesHorizontalGraph::setColor(QColor c)
setHighlightingLineColor(c); setHighlightingLineColor(c);
} }
void JKQTPImpulsesHorizontalGraph::setBaseline(double __value)
{
this->baseline = __value;
}
double JKQTPImpulsesHorizontalGraph::getBaseline() const
{
return this->baseline;
}
void JKQTPImpulsesHorizontalGraph::setDrawSymbols(bool __value) void JKQTPImpulsesHorizontalGraph::setDrawSymbols(bool __value)
{ {
drawSymbols=__value; drawSymbols=__value;
@ -214,15 +203,15 @@ void JKQTPImpulsesVerticalGraph::draw(JKQTPEnhancedPainter& painter) {
//double xold=-1; //double xold=-1;
//double yold=-1; //double yold=-1;
//bool first=false; //bool first=false;
// double x0=transformX(baseline); // double x0=transformX(getBaseline());
// if (parent->getXAxis()->isLogAxis()) { // if (parent->getXAxis()->isLogAxis()) {
// if (baseline>0 && baseline>parent->getXAxis()->getMin()) x0=transformX(baseline); // if (getBaseline()>0 && getBaseline()>parent->getXAxis()->getMin()) x0=transformX(getBaseline());
// else x0=transformX(parent->getXAxis()->getMin()); // else x0=transformX(parent->getXAxis()->getMin());
// } // }
double y0=transformY(baseline); double y0=transformY(getBaseline());
if (parent->getYAxis()->isLogAxis()) { if (parent->getYAxis()->isLogAxis()) {
y0=transformY(parent->getYAxis()->getMin()); y0=transformY(parent->getYAxis()->getMin());
if (baseline>0 && baseline>parent->getYAxis()->getMin()) y0=transformY(baseline); if (getBaseline()>0 && getBaseline()>parent->getYAxis()->getMin()) y0=transformY(getBaseline());
else y0=transformY(parent->getYAxis()->getMin()); else y0=transformY(parent->getYAxis()->getMin());
} }
QVector<QLineF> lines; QVector<QLineF> lines;

View File

@ -34,7 +34,7 @@
\see JKQTPImpulsesVerticalGraph, \ref JKQTPlotterImpulsePlots \see JKQTPImpulsesVerticalGraph, \ref JKQTPlotterImpulsePlots
*/ */
class JKQTPLOTTER_LIB_EXPORT JKQTPImpulsesHorizontalGraph: public JKQTPXYGraph, public JKQTPGraphLineStyleMixin, public JKQTPGraphSymbolStyleMixin{ class JKQTPLOTTER_LIB_EXPORT JKQTPImpulsesHorizontalGraph: public JKQTPXYBaselineGraph, public JKQTPGraphLineStyleMixin, public JKQTPGraphSymbolStyleMixin{
Q_OBJECT Q_OBJECT
public: public:
/** \brief class constructor */ /** \brief class constructor */
@ -52,11 +52,6 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPImpulsesHorizontalGraph: public JKQTPXYGraph,
/*! \brief color of symbols and impulses in one call */ /*! \brief color of symbols and impulses in one call */
virtual void setColor(QColor c); virtual void setColor(QColor c);
/*! \copydoc baseline */
void setBaseline(double __value);
/*! \copydoc baseline */
double getBaseline() const;
/*! \copydoc drawSymbols */ /*! \copydoc drawSymbols */
void setDrawSymbols(bool __value); void setDrawSymbols(bool __value);
/*! \copydoc drawSymbols */ /*! \copydoc drawSymbols */
@ -64,11 +59,6 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPImpulsesHorizontalGraph: public JKQTPXYGraph,
protected: protected:
/** \brief baseline of the plot (NOTE: 0 is interpreted as until plot border in log-mode!!!)
*
* \image html impulsesplot_baseline.png
*/
double baseline;
/** \brief indicates whether to draw symbols at the top of the impulse /** \brief indicates whether to draw symbols at the top of the impulse
* *
* \image html impulsesplot_symbols.png * \image html impulsesplot_symbols.png

View File

@ -37,11 +37,10 @@
JKQTPSpecialLineHorizontalGraph::JKQTPSpecialLineHorizontalGraph(JKQTBasePlotter* parent): JKQTPSpecialLineHorizontalGraph::JKQTPSpecialLineHorizontalGraph(JKQTBasePlotter* parent):
JKQTPXYGraph(parent) JKQTPXYBaselineGraph(parent)
{ {
m_drawSymbols=false; m_drawSymbols=false;
m_specialLineType=JKQTPStepLeft; m_specialLineType=JKQTPStepLeft;
m_baseline=0;
parentPlotStyle=-1; parentPlotStyle=-1;
initLineStyle(parent, parentPlotStyle); initLineStyle(parent, parentPlotStyle);
@ -99,15 +98,6 @@ JKQTPSpecialLineType JKQTPSpecialLineHorizontalGraph::getSpecialLineType() const
return this->m_specialLineType; return this->m_specialLineType;
} }
void JKQTPSpecialLineHorizontalGraph::setBaseline(double __value)
{
this->m_baseline = __value;
}
double JKQTPSpecialLineHorizontalGraph::getBaseline() const
{
return this->m_baseline;
}
void JKQTPSpecialLineHorizontalGraph::setColor(QColor c) void JKQTPSpecialLineHorizontalGraph::setColor(QColor c)
{ {
@ -150,10 +140,10 @@ void JKQTPSpecialLineHorizontalGraph::draw(JKQTPEnhancedPainter& painter) {
// double ystart=-1; // double ystart=-1;
//double x0=transformX(0); //double x0=transformX(0);
//if (parent->getXAxis()->isLogAxis()) x0=transformX(parent->getXAxis()->getMin()); //if (parent->getXAxis()->isLogAxis()) x0=transformX(parent->getXAxis()->getMin());
double y0=transformY(m_baseline); double y0=transformY(getBaseline());
if (parent->getYAxis()->isLogAxis()) { if (parent->getYAxis()->isLogAxis()) {
y0=transformY(parent->getYAxis()->getMin()); y0=transformY(parent->getYAxis()->getMin());
if (m_baseline>0 && m_baseline>parent->getYAxis()->getMin()) y0=transformY(m_baseline); if (getBaseline()>0 && getBaseline()>parent->getYAxis()->getMin()) y0=transformY(getBaseline());
else y0=transformY(parent->getYAxis()->getMin()); else y0=transformY(parent->getYAxis()->getMin());
} }
bool subsequentItem=false; bool subsequentItem=false;
@ -339,9 +329,9 @@ void JKQTPSpecialLineVerticalGraph::draw(JKQTPEnhancedPainter& painter) {
double xold=-1; double xold=-1;
double yold=-1; double yold=-1;
double x0=transformX(m_baseline); double x0=transformX(getBaseline());
if (parent->getXAxis()->isLogAxis()) { if (parent->getXAxis()->isLogAxis()) {
if (m_baseline>0 && m_baseline>parent->getXAxis()->getMin()) x0=transformX(m_baseline); if (getBaseline()>0 && getBaseline()>parent->getXAxis()->getMin()) x0=transformX(getBaseline());
else x0=transformX(parent->getXAxis()->getMin()); else x0=transformX(parent->getXAxis()->getMin());
} }
bool first=false; bool first=false;

View File

@ -50,7 +50,7 @@ class JKQTPDatastore;
\see JKQTPSpecialLineVerticalGraph, JKQTPFilledCurveXGraph, \ref JKQTPlotterSpecialStepLinePlot \see JKQTPSpecialLineVerticalGraph, JKQTPFilledCurveXGraph, \ref JKQTPlotterSpecialStepLinePlot
*/ */
class JKQTPLOTTER_LIB_EXPORT JKQTPSpecialLineHorizontalGraph: public JKQTPXYGraph, public JKQTPGraphLineAndFillStyleMixin, public JKQTPGraphSymbolStyleMixin { class JKQTPLOTTER_LIB_EXPORT JKQTPSpecialLineHorizontalGraph: public JKQTPXYBaselineGraph, public JKQTPGraphLineAndFillStyleMixin, public JKQTPGraphSymbolStyleMixin {
Q_OBJECT Q_OBJECT
public: public:
/** \brief class constructor */ /** \brief class constructor */
@ -74,10 +74,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPSpecialLineHorizontalGraph: public JKQTPXYGrap
void setSpecialLineType(const JKQTPSpecialLineType & __value); void setSpecialLineType(const JKQTPSpecialLineType & __value);
/** \brief get the type of connecting (step-)lines */ /** \brief get the type of connecting (step-)lines */
JKQTPSpecialLineType getSpecialLineType() const; JKQTPSpecialLineType getSpecialLineType() const;
/*! sets baseline of the plot (NOTE: 0 is interpreted as until plot border in log-mode!!!) */
void setBaseline(double __value);
/*! returns the baseline of the plot (NOTE: 0 is interpreted as until plot border in log-mode!!!) */
double getBaseline() const;
/** \brief set line-color, fill color and symbol color */ /** \brief set line-color, fill color and symbol color */
void setColor(QColor c); void setColor(QColor c);
protected: protected:
@ -86,8 +83,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPSpecialLineHorizontalGraph: public JKQTPXYGrap
bool m_drawSymbols; bool m_drawSymbols;
/** \brief type of connecting (step)lines */ /** \brief type of connecting (step)lines */
JKQTPSpecialLineType m_specialLineType; JKQTPSpecialLineType m_specialLineType;
/** \brief baseline of the plot (NOTE: 0 is interpreted as until plot border in log-mode!!!) */
double m_baseline;
}; };

View File

@ -972,3 +972,19 @@ bool JKQTPXXYGraph::getIndexRange(int &imin, int &imax) const
} }
return ok; return ok;
} }
JKQTPXYBaselineGraph::JKQTPXYBaselineGraph(JKQTBasePlotter *parent):
JKQTPXYGraph(parent), m_baseline(0.0)
{
}
double JKQTPXYBaselineGraph::getBaseline() const
{
return m_baseline;
}
void JKQTPXYBaselineGraph::setBaseline(double __value)
{
m_baseline=__value;
}

View File

@ -638,6 +638,36 @@ protected:
/** \brief This virtual JKQTPGraph descendent extends JKQTPXYGraph adds a baseline-property, which is necessary, e.g. for barcharts, filled graphs to indicate until where to draw the bar or fill the curve (default is 0).
* \ingroup jkqtplotter_basegraphs
*
* \see JKQTPSpecialLineHorizontalGraph, JKQTPBarVerticalGraph, JKQTPImpulsesHorizontalGraph, ...
*/
class JKQTPLOTTER_LIB_EXPORT JKQTPXYBaselineGraph: public JKQTPXYGraph {
Q_OBJECT
public:
/** \brief class constructor */
JKQTPXYBaselineGraph(JKQTBasePlotter* parent=nullptr);
/** \copydoc m_baseline */
double getBaseline() const;
Q_PROPERTY(double baseline READ getBaseline WRITE setBaseline)
public slots:
/** \copydoc m_baseline */
void setBaseline(double __value);
protected:
/** \brief baseline of the plot (NOTE: 0 is interpreted as until plot border in log-mode!!!)
*
* \image html impulsesplot_baseline.png
*/
double m_baseline;
};
/** \brief This virtual JKQTPGraph descendent extends JKQTPXYGraph to two columns for y-values (e.g. for filled range plots in JKQTPFilledVerticalRangeGraph). /** \brief This virtual JKQTPGraph descendent extends JKQTPXYGraph to two columns for y-values (e.g. for filled range plots in JKQTPFilledVerticalRangeGraph).
* \ingroup jkqtplotter_basegraphs * \ingroup jkqtplotter_basegraphs
* *