using new JKQTPGraphLineAndFillStyleMixin where appropriate

This commit is contained in:
jkriege2 2020-09-19 14:55:46 +02:00
parent 6875e0ae6c
commit 34fa59ebf4
7 changed files with 315 additions and 341 deletions

View File

@ -33,13 +33,12 @@
JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase(JKQTBasePlotter* parent): JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase(JKQTBasePlotter* parent):
JKQTPEvaluatedFunctionWithErrorsGraphBase(parent), JKQTPEvaluatedFunctionWithErrorsGraphBase(parent),
drawLine(true),
fillCurve(false),
drawErrorPolygons(false), drawErrorPolygons(false),
drawErrorLines(false) drawErrorLines(false)
{ {
initLineStyle(parent, parentPlotStyle); initLineStyle(parent, parentPlotStyle);
initFillStyle(parent, parentPlotStyle); initFillStyle(parent, parentPlotStyle);
setFillCurve(false);
errorColor=getLineColor().lighter(); errorColor=getLineColor().lighter();
errorFillColor=getLineColor().lighter(); errorFillColor=getLineColor().lighter();
@ -71,16 +70,6 @@ JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::~JKQTPEvaluatedFunctionWithErr
} }
void JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::setDrawLine(bool __value)
{
this->drawLine = __value;
}
bool JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::getDrawLine() const
{
return this->drawLine;
}
void JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) { void JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) {
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
QPen p=getLinePen(painter, parent); QPen p=getLinePen(painter, parent);
@ -90,10 +79,10 @@ void JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::drawKeyMarker(JKQTPEnhanc
QBrush b=getFillBrush(painter, parent); QBrush b=getFillBrush(painter, parent);
const double y=rect.top()+rect.height()/2.0; const double y=rect.top()+rect.height()/2.0;
painter.setPen(np); painter.setPen(np);
if (drawLine) painter.setPen(p); if (getDrawLine()) painter.setPen(p);
painter.setBrush(b); painter.setBrush(b);
if (fillCurve) painter.drawRect(rect); if (getFillCurve()) painter.drawRect(rect);
if (!fillCurve && drawLine) painter.drawLine(QLineF(rect.left(), y, rect.right(), y)); if (!getFillCurve() && getDrawLine()) painter.drawLine(QLineF(rect.left(), y, rect.right(), y));
} }
@ -262,7 +251,7 @@ void JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::drawXGraph(JKQTPEnhancedP
y=qBound(yami, y, yama); y=qBound(yami, y, yama);
if (fillCurve) { if (getFillCurve()) {
if (!first) filledPolygon<<QPointF(x, y0); if (!first) filledPolygon<<QPointF(x, y0);
filledPolygon<<QPointF(x, y); filledPolygon<<QPointF(x, y);
if (it+1==data.end()) filledPolygon<<QPointF(x, y0); if (it+1==data.end()) filledPolygon<<QPointF(x, y0);
@ -273,7 +262,7 @@ void JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::drawXGraph(JKQTPEnhancedP
epBottom<<QPointF(x, yme); epBottom<<QPointF(x, yme);
} }
if (drawLine) { if (getDrawLine()) {
linePolygon<<QPointF(x, y); linePolygon<<QPointF(x, y);
} }
@ -299,13 +288,13 @@ void JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::drawXGraph(JKQTPEnhancedP
painter.drawPolygon(poly, Qt::OddEvenFill); painter.drawPolygon(poly, Qt::OddEvenFill);
} }
if (fillCurve) { if (getFillCurve()) {
painter.save(); auto __finalpaintfillc=JKQTPFinally([&painter]() {painter.restore();}); painter.save(); auto __finalpaintfillc=JKQTPFinally([&painter]() {painter.restore();});
painter.setBrush(b); painter.setBrush(b);
painter.setPen(np); painter.setPen(np);
painter.drawPolygon(filledPolygon, Qt::OddEvenFill); painter.drawPolygon(filledPolygon, Qt::OddEvenFill);
} }
if (drawLine) { if (getDrawLine()) {
painter.save(); auto __finalpaintline=JKQTPFinally([&painter]() {painter.restore();}); painter.save(); auto __finalpaintline=JKQTPFinally([&painter]() {painter.restore();});
painter.setPen(p); painter.setPen(p);
painter.drawPolyline(linePolygon); painter.drawPolyline(linePolygon);
@ -389,7 +378,7 @@ void JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::drawYGraph(JKQTPEnhancedP
x=qBound(xami, x, xama); x=qBound(xami, x, xama);
if (fillCurve) { if (getFillCurve()) {
if (!first) filledPolygon<<QPointF(x0, y); if (!first) filledPolygon<<QPointF(x0, y);
filledPolygon<<QPointF(x, y); filledPolygon<<QPointF(x, y);
if (it+1==data.end()) filledPolygon<<QPointF(x0, y); if (it+1==data.end()) filledPolygon<<QPointF(x0, y);
@ -400,7 +389,7 @@ void JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::drawYGraph(JKQTPEnhancedP
epBottom<<QPointF(xme, y); epBottom<<QPointF(xme, y);
} }
if (drawLine) { if (getDrawLine()) {
linePolygon<<QPointF(x, y); linePolygon<<QPointF(x, y);
} }
@ -425,13 +414,13 @@ void JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::drawYGraph(JKQTPEnhancedP
} }
painter.drawPolygon(poly, Qt::OddEvenFill); painter.drawPolygon(poly, Qt::OddEvenFill);
} }
if (fillCurve) { if (getFillCurve()) {
painter.save(); auto __finalpaintfillc=JKQTPFinally([&painter]() {painter.restore();}); painter.save(); auto __finalpaintfillc=JKQTPFinally([&painter]() {painter.restore();});
painter.setBrush(b); painter.setBrush(b);
painter.setPen(np); painter.setPen(np);
painter.drawPolygon(filledPolygon, Qt::OddEvenFill); painter.drawPolygon(filledPolygon, Qt::OddEvenFill);
} }
if (drawLine) { if (getDrawLine()) {
painter.save(); auto __finalpaintline=JKQTPFinally([&painter]() {painter.restore();}); painter.save(); auto __finalpaintline=JKQTPFinally([&painter]() {painter.restore();});
painter.setPen(p); painter.setPen(p);
painter.drawPolyline(linePolygon); painter.drawPolyline(linePolygon);

View File

@ -44,7 +44,7 @@
* *
* \see e.g. JKQTPXFunctionLineGraph for a concrete implementation * \see e.g. JKQTPXFunctionLineGraph for a concrete implementation
*/ */
class JKQTPLOTTER_LIB_EXPORT JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase: public JKQTPEvaluatedFunctionWithErrorsGraphBase, public JKQTPGraphLineStyleMixin, public JKQTPGraphFillStyleMixin { class JKQTPLOTTER_LIB_EXPORT JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase: public JKQTPEvaluatedFunctionWithErrorsGraphBase, public JKQTPGraphLineAndFillStyleMixin {
Q_OBJECT Q_OBJECT
public: public:
@ -62,8 +62,6 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase: p
/** \brief returns the color to be used for the key label */ /** \brief returns the color to be used for the key label */
virtual QColor getKeyLabelColor() const override; virtual QColor getKeyLabelColor() const override;
/*! \copydoc drawLine */
bool getDrawLine() const;
/*! \copydoc drawErrorPolygons */ /*! \copydoc drawErrorPolygons */
@ -89,8 +87,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase: p
/*! \brief set color, fill color and error color at the same time */ /*! \brief set color, fill color and error color at the same time */
void setColor(QColor c); void setColor(QColor c);
/*! \copydoc drawLine */
void setDrawLine(bool __value);
/*! \copydoc drawErrorPolygons */ /*! \copydoc drawErrorPolygons */
void setDrawErrorPolygons(bool __value); void setDrawErrorPolygons(bool __value);
/*! \copydoc drawErrorLines */ /*! \copydoc drawErrorLines */
@ -115,12 +112,6 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase: p
/** \brief indicates whether to draw a line or not */
bool drawLine;
/** \brief indicates whether to fill the space between the curve and the x-axis */
bool fillCurve;
/** \brief indicates whether an error polygon should be drawn */ /** \brief indicates whether an error polygon should be drawn */
bool drawErrorPolygons; bool drawErrorPolygons;
/** \brief indicates whether error lines should be drawn */ /** \brief indicates whether error lines should be drawn */

View File

@ -187,9 +187,12 @@ void JKQTPFilledVerticalRangeGraph::draw(JKQTPEnhancedPainter &painter)
poly_all.append(plow[i]); poly_all.append(plow[i]);
} }
} }
painter.setBrush(b);
painter.setPen(np); if (getFillCurve()) {
painter.drawPolygon(poly_all); painter.setBrush(b);
painter.setPen(np);
painter.drawPolygon(poly_all);
}
if (getDrawLine()) { if (getDrawLine()) {
@ -299,9 +302,12 @@ void JKQTPFilledHorizontalRangeGraph::draw(JKQTPEnhancedPainter &painter)
poly_all.append(plow[i]); poly_all.append(plow[i]);
} }
} }
painter.setBrush(b);
painter.setPen(np); if (getFillCurve()) {
painter.drawPolygon(poly_all); painter.setBrush(b);
painter.setPen(np);
painter.drawPolygon(poly_all);
}
if (getDrawLine()) { if (getDrawLine()) {

View File

@ -39,8 +39,6 @@
JKQTPSpecialLineHorizontalGraph::JKQTPSpecialLineHorizontalGraph(JKQTBasePlotter* parent): JKQTPSpecialLineHorizontalGraph::JKQTPSpecialLineHorizontalGraph(JKQTBasePlotter* parent):
JKQTPXYGraph(parent) JKQTPXYGraph(parent)
{ {
m_drawLine=true;
m_fillCurve=false;
m_drawSymbols=false; m_drawSymbols=false;
m_specialLineType=JKQTPStepLeft; m_specialLineType=JKQTPStepLeft;
m_baseline=0; m_baseline=0;
@ -49,6 +47,7 @@ JKQTPSpecialLineHorizontalGraph::JKQTPSpecialLineHorizontalGraph(JKQTBasePlotter
initLineStyle(parent, parentPlotStyle); initLineStyle(parent, parentPlotStyle);
initFillStyle(parent, parentPlotStyle); initFillStyle(parent, parentPlotStyle);
initSymbolStyle(parent, parentPlotStyle); initSymbolStyle(parent, parentPlotStyle);
setFillCurve(false);
} }
@ -65,10 +64,10 @@ void JKQTPSpecialLineHorizontalGraph::drawKeyMarker(JKQTPEnhancedPainter& painte
QBrush b=getFillBrush(painter, parent); QBrush b=getFillBrush(painter, parent);
const double y=rect.top()+rect.height()/2.0; const double y=rect.top()+rect.height()/2.0;
painter.setPen(np); painter.setPen(np);
if (m_drawLine) painter.setPen(p); if (getDrawLine()) painter.setPen(p);
painter.setBrush(b); painter.setBrush(b);
if (m_fillCurve) painter.drawRect(rect); if (getFillCurve()) painter.drawRect(rect);
if (!m_fillCurve && m_drawLine) painter.drawLine(QLineF(rect.left(), y, rect.right(), y)); if (!getFillCurve() && getDrawLine()) painter.drawLine(QLineF(rect.left(), y, rect.right(), y));
if (m_drawSymbols) { if (m_drawSymbols) {
plotStyledSymbol(parent, painter, rect.center().x(), rect.center().y(), rect.width()*0.5); plotStyledSymbol(parent, painter, rect.center().x(), rect.center().y(), rect.width()*0.5);
} }
@ -79,16 +78,6 @@ QColor JKQTPSpecialLineHorizontalGraph::getKeyLabelColor() const {
return getLineColor(); return getLineColor();
} }
void JKQTPSpecialLineHorizontalGraph::setDrawLine(bool __value)
{
this->m_drawLine = __value;
}
bool JKQTPSpecialLineHorizontalGraph::getDrawLine() const
{
return this->m_drawLine;
}
void JKQTPSpecialLineHorizontalGraph::setDrawSymbols(bool __value) void JKQTPSpecialLineHorizontalGraph::setDrawSymbols(bool __value)
{ {
m_drawSymbols=__value; m_drawSymbols=__value;
@ -99,15 +88,6 @@ bool JKQTPSpecialLineHorizontalGraph::getDrawSymbols() const
return m_drawSymbols; return m_drawSymbols;
} }
void JKQTPSpecialLineHorizontalGraph::setFillCurve(bool __value)
{
this->m_fillCurve = __value;
}
bool JKQTPSpecialLineHorizontalGraph::getFillCurve() const
{
return this->m_fillCurve;
}
void JKQTPSpecialLineHorizontalGraph::setSpecialLineType(const JKQTPSpecialLineType &__value) void JKQTPSpecialLineHorizontalGraph::setSpecialLineType(const JKQTPSpecialLineType &__value)
{ {
@ -155,164 +135,159 @@ void JKQTPSpecialLineHorizontalGraph::draw(JKQTPEnhancedPainter& painter) {
QPen np(Qt::NoPen); QPen np(Qt::NoPen);
QBrush b=getFillBrush(painter, parent); QBrush b=getFillBrush(painter, parent);
int imax=static_cast<int>(qMin(datastore->getRows(static_cast<size_t>(xColumn)), datastore->getRows(static_cast<size_t>(yColumn)))); int imax=0;
int imin=0; int imin=0;
if (imax<imin) { if (getIndexRange(imin, imax)) {
int h=imin;
imin=imax;
imax=h;
}
if (imin<0) imin=0;
if (imax<0) imax=0;
QPainterPath pl, pf;
QVector<QPointF> ps;
double xold=-1; QPainterPath pl, pf;
double yold=-1; QVector<QPointF> ps;
// double xstart=-1;
// double ystart=-1;
//double x0=transformX(0);
//if (parent->getXAxis()->isLogAxis()) x0=transformX(parent->getXAxis()->getMin());
double y0=transformY(m_baseline);
if (parent->getYAxis()->isLogAxis()) {
y0=transformY(parent->getYAxis()->getMin());
if (m_baseline>0 && m_baseline>parent->getYAxis()->getMin()) y0=transformY(m_baseline);
else y0=transformY(parent->getYAxis()->getMin());
}
bool subsequentItem=false;
intSortData();
for (int iii=imin; iii<imax; iii++) {
int i=qBound(imin, getDataIndex(iii), imax);
double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i));
double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i));
//std::cout<<"(xv, yv) = ( "<<xv<<", "<<yv<<" )\n";
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) {
double x=transformX(xv);
double y=transformY(yv);
if (JKQTPIsOKFloat(x) && JKQTPIsOKFloat(y)) {
ps.append(QPointF(x,y));
if (subsequentItem) {
//double xl1=xold;
//double yl1=yold;
//double xl2=x;
//double yl2=y;
if (m_specialLineType==JKQTPStepCenter) { double xold=-1;
// x/y double yold=-1;
// |--------* // double xstart=-1;
// | // double ystart=-1;
// *--------| //double x0=transformX(0);
// xold/yold //if (parent->getXAxis()->isLogAxis()) x0=transformX(parent->getXAxis()->getMin());
const double d=(x-xold); double y0=transformY(m_baseline);
pf.lineTo(xold+d/2.0, yold); if (parent->getYAxis()->isLogAxis()) {
pf.lineTo(xold+d/2.0, y); y0=transformY(parent->getYAxis()->getMin());
if (m_baseline>0 && m_baseline>parent->getYAxis()->getMin()) y0=transformY(m_baseline);
else y0=transformY(parent->getYAxis()->getMin());
}
bool subsequentItem=false;
intSortData();
for (int iii=imin; iii<imax; iii++) {
const int i=qBound(imin, getDataIndex(iii), imax);
const double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i));
const double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i));
//std::cout<<"(xv, yv) = ( "<<xv<<", "<<yv<<" )\n";
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) {
const double x=transformX(xv);
const double y=transformY(yv);
if (JKQTPIsOKFloat(x) && JKQTPIsOKFloat(y)) {
ps.append(QPointF(x,y));
if (subsequentItem) {
//double xl1=xold;
//double yl1=yold;
//double xl2=x;
//double yl2=y;
if (m_specialLineType==JKQTPStepCenter) {
// x/y
// |--------*
// |
// *--------|
// xold/yold
const double d=(x-xold);
pf.lineTo(xold+d/2.0, yold);
pf.lineTo(xold+d/2.0, y);
pf.lineTo(x, y);
if (getDrawLine()) {
pl.lineTo(xold+d/2.0, yold);
pl.lineTo(xold+d/2.0, y);
pl.lineTo(x, y);
}
} else if (m_specialLineType==JKQTPStepLeft) {
// x/y
// |----------------*
// |
// *
// xold/yold
pf.lineTo(xold, y);
pf.lineTo(x, y);
if (getDrawLine()) {
pl.lineTo(xold, y);
pl.lineTo(x, y);
}
} else if (m_specialLineType==JKQTPStepRight) {
// x/y
// *
// |
// *----------------|
// xold/yold
pf.lineTo(x, yold);
pf.lineTo(x, y);
if (getDrawLine()) {
pl.lineTo(x, yold);
pl.lineTo(x, y);
}
} else if (m_specialLineType==JKQTPStepAverage) {
// x/y
// *
// |
// |----------------|
// |
// *
// xold/yold
//const double d=(x-xold);
const double h=(y-yold);
pf.lineTo(xold, yold+h/2.0);
pf.lineTo(x, yold+h/2.0);
pf.lineTo(x,y);
if (getDrawLine()) {
pl.lineTo(xold, yold+h/2.0);
pl.lineTo(x, yold+h/2.0);
pl.lineTo(x,y);
}
} else if (m_specialLineType==JKQTPDirectLine) {
// x/y
// /----*
// /----/
// *----/
// xold/yold
pf.lineTo(x, y);
if (getDrawLine()) {
pl.lineTo(x, y);
}
}
//std::cout<<"line ("<<xl1<<", "<<yl1<<") -- ("<<xl2<<", "<<yl2<<")"<<std::endl;
} else {
if (getDrawLine()) pl.moveTo(x,y);
pf.moveTo(x, y0);
pf.lineTo(x, y); pf.lineTo(x, y);
if (m_drawLine) { //xstart=x;
pl.lineTo(xold+d/2.0, yold); //ystart=y0;
pl.lineTo(xold+d/2.0, y);
pl.lineTo(x, y);
}
} else if (m_specialLineType==JKQTPStepLeft) {
// x/y
// |----------------*
// |
// *
// xold/yold
pf.lineTo(xold, y);
pf.lineTo(x, y);
if (m_drawLine) {
pl.lineTo(xold, y);
pl.lineTo(x, y);
}
} else if (m_specialLineType==JKQTPStepRight) {
// x/y
// *
// |
// *----------------|
// xold/yold
pf.lineTo(x, yold);
pf.lineTo(x, y);
if (m_drawLine) {
pl.lineTo(x, yold);
pl.lineTo(x, y);
}
} else if (m_specialLineType==JKQTPStepAverage) {
// x/y
// *
// |
// |----------------|
// |
// *
// xold/yold
//const double d=(x-xold);
const double h=(y-yold);
pf.lineTo(xold, yold+h/2.0);
pf.lineTo(x, yold+h/2.0);
pf.lineTo(x,y);
if (m_drawLine) {
pl.lineTo(xold, yold+h/2.0);
pl.lineTo(x, yold+h/2.0);
pl.lineTo(x,y);
}
} else if (m_specialLineType==JKQTPDirectLine) {
// x/y
// /----*
// /----/
// *----/
// xold/yold
pf.lineTo(x, y);
if (m_drawLine) {
pl.lineTo(x, y);
}
} }
xold=x;
//std::cout<<"line ("<<xl1<<", "<<yl1<<") -- ("<<xl2<<", "<<yl2<<")"<<std::endl; yold=y;
} else { subsequentItem=true;
if (m_drawLine) pl.moveTo(x,y);
pf.moveTo(x, y0);
pf.lineTo(x, y);
//xstart=x;
//ystart=y0;
} }
xold=x; }
yold=y; }
subsequentItem=true; if (getFillCurve()) {
pf.lineTo(xold, y0);
pf.closeSubpath();
}
painter.save();
auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
if (getFillCurve()) {
painter.fillPath(pf, b);
}
if (isHighlighted()) {
painter.setBrush(QBrush(Qt::transparent));
painter.setPen(ph);
painter.drawPath(pl);
}
if (getDrawLine()) {
painter.setBrush(QBrush(Qt::transparent));
painter.setPen(p);
painter.drawPath(pl);
}
if (m_drawSymbols) {
painter.save();
auto __finalpaintsym=JKQTPFinally([&painter]() {painter.restore();});
for (auto& ppoint: ps) {
plotStyledSymbol(parent, painter, ppoint.x(), ppoint.y());
} }
} }
} }
if (m_fillCurve) {
pf.lineTo(xold, y0);
pf.closeSubpath();
}
painter.save();
auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
if (m_fillCurve) {
painter.fillPath(pf, b);
}
if (isHighlighted()) {
painter.setBrush(QBrush(Qt::transparent));
painter.setPen(ph);
painter.drawPath(pl);
}
if (m_drawLine) {
painter.setBrush(QBrush(Qt::transparent));
painter.setPen(p);
painter.drawPath(pl);
}
if (m_drawSymbols) {
painter.save();
auto __finalpaintsym=JKQTPFinally([&painter]() {painter.restore();});
for (auto& ppoint: ps) {
plotStyledSymbol(parent, painter, ppoint.x(), ppoint.y());
}
}
drawErrorsAfter(painter); drawErrorsAfter(painter);
} }
@ -353,136 +328,132 @@ void JKQTPSpecialLineVerticalGraph::draw(JKQTPEnhancedPainter& painter) {
QPen np(Qt::NoPen); QPen np(Qt::NoPen);
QBrush b=getFillBrush(painter, parent); QBrush b=getFillBrush(painter, parent);
int imax=static_cast<int>(qMin(datastore->getRows(static_cast<size_t>(xColumn)), datastore->getRows(static_cast<size_t>(yColumn)))); int imax=0;
int imin=0; int imin=0;
if (imax<imin) { if (getIndexRange(imin, imax)) {
int h=imin;
imin=imax;
imax=h;
}
if (imin<0) imin=0;
if (imax<0) imax=0;
QPainterPath pl, pf;
QVector<QPointF> ps;
double xold=-1; QPainterPath pl, pf;
double yold=-1; QVector<QPointF> ps;
double x0=transformX(m_baseline);
if (parent->getXAxis()->isLogAxis()) {
if (m_baseline>0 && m_baseline>parent->getXAxis()->getMin()) x0=transformX(m_baseline);
else x0=transformX(parent->getXAxis()->getMin());
}
bool first=false;
intSortData();
for (int iii=imin; iii<imax; iii++) {
int i=qBound(imin, getDataIndex(iii), imax);
double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i));
double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i));
//std::cout<<"(xv, yv) = ( "<<xv<<", "<<yv<<" )\n";
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) {
double x=transformX(xv);
double y=transformY(yv);
if (JKQTPIsOKFloat(x) && JKQTPIsOKFloat(y)) {
ps.append(QPointF(x,y));
if (first) {
//double xl1=xold;
//double yl1=yold;
//double xl2=x;
//double yl2=y;
if (m_specialLineType==JKQTPStepCenter) { double xold=-1;
double d=(y-yold); double yold=-1;
pf.lineTo(xold, yold+d/2.0); double x0=transformX(m_baseline);
pf.lineTo(x, yold+d/2.0); if (parent->getXAxis()->isLogAxis()) {
if (m_baseline>0 && m_baseline>parent->getXAxis()->getMin()) x0=transformX(m_baseline);
else x0=transformX(parent->getXAxis()->getMin());
}
bool first=false;
intSortData();
for (int iii=imin; iii<imax; iii++) {
const int i=qBound(imin, getDataIndex(iii), imax);
const double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i));
const double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i));
//std::cout<<"(xv, yv) = ( "<<xv<<", "<<yv<<" )\n";
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) {
const double x=transformX(xv);
const double y=transformY(yv);
if (JKQTPIsOKFloat(x) && JKQTPIsOKFloat(y)) {
ps.append(QPointF(x,y));
if (first) {
//double xl1=xold;
//double yl1=yold;
//double xl2=x;
//double yl2=y;
if (m_specialLineType==JKQTPStepCenter) {
double d=(y-yold);
pf.lineTo(xold, yold+d/2.0);
pf.lineTo(x, yold+d/2.0);
pf.lineTo(x, y);
if (getDrawLine()) {
pl.lineTo(xold, yold+d/2.0);
pl.lineTo(x, yold+d/2.0);
pl.lineTo(x, y);
}
} else if (m_specialLineType==JKQTPStepLeft) {
pf.lineTo(x, yold);
pf.lineTo(x, y);
if (getDrawLine()) {
pl.lineTo(x, yold);
pl.lineTo(x, y);
}
} else if (m_specialLineType==JKQTPStepRight) {
pf.lineTo(xold, y);
pf.lineTo(x, y);
if (getDrawLine()) {
pl.lineTo(xold, y);
pl.lineTo(x, y);
}
} else if (m_specialLineType==JKQTPStepAverage) {
// x/y
// |-------*
// |
// |
// |
// *--------|
// xold/yold
const double d=(x-xold);
//const double h=(y-yold);
pf.lineTo(xold+d/2.0, yold);
pf.lineTo(xold+d/2.0, y);
pf.lineTo(x,y);
if (getDrawLine()) {
pl.lineTo(xold+d/2.0, yold);
pl.lineTo(xold+d/2.0, y);
pl.lineTo(x,y);
}
} else if (m_specialLineType==JKQTPDirectLine) {
// x/y
// /----*
// /----/
// *----/
// xold/yold
pf.lineTo(x, y);
if (getDrawLine()) {
pl.lineTo(x, y);
}
}
//std::cout<<"line ("<<xl1<<", "<<yl1<<") -- ("<<xl2<<", "<<yl2<<")"<<std::endl;
} else {
if (getDrawLine()) pl.moveTo(x,y);
pf.moveTo(x0, y);
pf.lineTo(x, y); pf.lineTo(x, y);
if (m_drawLine) {
pl.lineTo(xold, yold+d/2.0);
pl.lineTo(x, yold+d/2.0);
pl.lineTo(x, y);
}
} else if (m_specialLineType==JKQTPStepLeft) {
pf.lineTo(x, yold);
pf.lineTo(x, y);
if (m_drawLine) {
pl.lineTo(x, yold);
pl.lineTo(x, y);
}
} else if (m_specialLineType==JKQTPStepRight) {
pf.lineTo(xold, y);
pf.lineTo(x, y);
if (m_drawLine) {
pl.lineTo(xold, y);
pl.lineTo(x, y);
}
} else if (m_specialLineType==JKQTPStepAverage) {
// x/y
// |-------*
// |
// |
// |
// *--------|
// xold/yold
const double d=(x-xold);
//const double h=(y-yold);
pf.lineTo(xold+d/2.0, yold);
pf.lineTo(xold+d/2.0, y);
pf.lineTo(x,y);
if (m_drawLine) {
pl.lineTo(xold+d/2.0, yold);
pl.lineTo(xold+d/2.0, y);
pl.lineTo(x,y);
}
} else if (m_specialLineType==JKQTPDirectLine) {
// x/y
// /----*
// /----/
// *----/
// xold/yold
pf.lineTo(x, y);
if (m_drawLine) {
pl.lineTo(x, y);
}
} }
xold=x;
//std::cout<<"line ("<<xl1<<", "<<yl1<<") -- ("<<xl2<<", "<<yl2<<")"<<std::endl; yold=y;
} else { first=true;
if (m_drawLine) pl.moveTo(x,y);
pf.moveTo(x0, y);
pf.lineTo(x, y);
} }
xold=x;
yold=y;
first=true;
} }
} }
} pf.lineTo(x0, yold);
pf.lineTo(x0, yold); pf.closeSubpath();
pf.closeSubpath(); painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
if (m_fillCurve) { if (getFillCurve()) {
painter.fillPath(pf, b); painter.fillPath(pf, b);
} }
if (isHighlighted()) { if (isHighlighted()) {
painter.setBrush(QBrush(Qt::transparent)); painter.setBrush(QBrush(Qt::transparent));
painter.setPen(ph); painter.setPen(ph);
painter.drawPath(pl); painter.drawPath(pl);
} }
if (m_drawLine) { if (getDrawLine()) {
painter.setBrush(QBrush(Qt::transparent)); painter.setBrush(QBrush(Qt::transparent));
painter.setPen(p); painter.setPen(p);
painter.drawPath(pl); painter.drawPath(pl);
} }
if (m_drawSymbols) { if (m_drawSymbols) {
painter.save(); painter.save();
auto __finalpaintsym=JKQTPFinally([&painter]() {painter.restore();}); auto __finalpaintsym=JKQTPFinally([&painter]() {painter.restore();});
for (auto& point: ps) { for (auto& point: ps) {
plotStyledSymbol(parent, painter, point.x(), point.y()); plotStyledSymbol(parent, painter, point.x(), point.y());
}
} }
} }

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 JKQTPGraphLineStyleMixin, public JKQTPGraphFillStyleMixin, public JKQTPGraphSymbolStyleMixin { class JKQTPLOTTER_LIB_EXPORT JKQTPSpecialLineHorizontalGraph: public JKQTPXYGraph, public JKQTPGraphLineAndFillStyleMixin, public JKQTPGraphSymbolStyleMixin {
Q_OBJECT Q_OBJECT
public: public:
/** \brief class constructor */ /** \brief class constructor */
@ -65,18 +65,11 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPSpecialLineHorizontalGraph: public JKQTPXYGrap
/** \brief returns the color to be used for the key label */ /** \brief returns the color to be used for the key label */
virtual QColor getKeyLabelColor() const override; virtual QColor getKeyLabelColor() const override;
/*! sets whether to draw a line or not */
void setDrawLine(bool __value);
/*! returns whether the graph line is drawn */
bool getDrawLine() const;
/*! sets whether to draw symbols */ /*! sets whether to draw symbols */
void setDrawSymbols(bool __value); void setDrawSymbols(bool __value);
/*! returns whether symbols are drawn */ /*! returns whether symbols are drawn */
bool getDrawSymbols() const; bool getDrawSymbols() const;
/*! sets whether to fill the space between the curve and the baseline/x-axis */
void setFillCurve(bool __value);
/*! returns whether the space between the curve and the baseline/x-axis is filled */
bool getFillCurve() const;
/** \brief set the type of connecting (step-)lines */ /** \brief set the type of connecting (step-)lines */
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 */
@ -88,12 +81,9 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPSpecialLineHorizontalGraph: public JKQTPXYGrap
/** \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:
/** \brief indicates whether to draw a line or not */
bool m_drawLine;
/** \brief indicates whether to draw a symbols or not */ /** \brief indicates whether to draw a symbols or not */
bool m_drawSymbols; bool m_drawSymbols;
/** \brief indicates whether to fill the space between the curve and the baseline/x-axis */
bool m_fillCurve;
/** \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!!!) */ /** \brief baseline of the plot (NOTE: 0 is interpreted as until plot border in log-mode!!!) */

View File

@ -567,7 +567,7 @@ double JKQTPGraphDecoratedHeadLineStyleMixin::calcHeadDecoratorSize(double line_
JKQTPGraphLineAndFillStyleMixin::JKQTPGraphLineAndFillStyleMixin(): JKQTPGraphLineAndFillStyleMixin::JKQTPGraphLineAndFillStyleMixin():
m_drawLine(true) m_drawLine(true), m_fillCurve(true)
{ {
} }
@ -586,3 +586,18 @@ bool JKQTPGraphLineAndFillStyleMixin::doDrawLine() const
{ {
return m_drawLine; return m_drawLine;
} }
void JKQTPGraphLineAndFillStyleMixin::setFillCurve(bool __value)
{
m_fillCurve=__value;
}
bool JKQTPGraphLineAndFillStyleMixin::getFillCurve() const
{
return m_fillCurve;
}
bool JKQTPGraphLineAndFillStyleMixin::doFillCurve() const
{
return m_fillCurve;
}

View File

@ -461,10 +461,22 @@ public:
bool getDrawLine() const; bool getDrawLine() const;
/*! \copydoc m_drawLine */ /*! \copydoc m_drawLine */
bool doDrawLine() const; bool doDrawLine() const;
/*! \copydoc m_fillCurve */
void setFillCurve(bool __value);
/*! \copydoc m_fillCurve */
bool getFillCurve() const;
/*! \copydoc m_fillCurve */
bool doFillCurve() const;
Q_PROPERTY(bool drawLine MEMBER m_drawLine READ getDrawLine WRITE setDrawLine) Q_PROPERTY(bool drawLine MEMBER m_drawLine READ getDrawLine WRITE setDrawLine)
Q_PROPERTY(bool fillCurve MEMBER m_fillCurve READ getFillCurve WRITE setFillCurve)
private: private:
/** \brief indicates whether to draw a line on the circumference of the described area (i.e. along the data points from \c xColumn and \c yColumn as well as \c xColumn and \c yColumn2 or not */ /** \brief indicates whether to draw a line on the circumference of the described area (i.e. along the data points from \c xColumn and \c yColumn as well as \c xColumn and \c yColumn2 or not */
bool m_drawLine; bool m_drawLine;
/** \brief indicates whether to fill the space between the curve and the x-axis */
bool m_fillCurve;
}; };