diff --git a/lib/jkqtplotter/graphs/jkqtpbarchart.cpp b/lib/jkqtplotter/graphs/jkqtpbarchart.cpp index 0773fe7775..dba91e1960 100644 --- a/lib/jkqtplotter/graphs/jkqtpbarchart.cpp +++ b/lib/jkqtplotter/graphs/jkqtpbarchart.cpp @@ -53,27 +53,17 @@ void JKQTPBarVerticalGraph::draw(JKQTPEnhancedPainter& painter) { JKQTPAutoOutputTimer jkaaot("JKQTPBarHorizontalGraph::draw"); #endif if (parent==nullptr) return; - JKQTPDatastore* datastore=parent->getDatastore(); + const JKQTPDatastore* datastore=parent->getDatastore(); if (datastore==nullptr) return; drawErrorsBefore(painter); - QPen p=getLinePenForRects(painter, parent); + const QPen p=getLinePenForRects(painter, parent); + const QBrush b=getFillBrush(painter, parent); - QBrush b=getFillBrush(painter, parent); - - int imax=static_cast(qMin(datastore->getRows(static_cast(xColumn)), datastore->getRows(static_cast(yColumn)))); + int imax=0; int imin=0; - - if (imaxget(static_cast(xColumn),static_cast(i)); - int sr=datastore->getNextLowerIndex(xColumn, i); - int lr=datastore->getNextHigherIndex(xColumn, i); + const double xv=datastore->get(static_cast(xColumn),static_cast(i)); + const int sr=datastore->getNextLowerIndex(xColumn, i); + const int lr=datastore->getNextHigherIndex(xColumn, i); double yv=datastore->get(static_cast(yColumn),static_cast(i)); double yv0=y0; if (!qFuzzyIsNull(getBaseline())) yv0=transformY(getBaseline()); @@ -114,9 +104,9 @@ void JKQTPBarVerticalGraph::draw(JKQTPEnhancedPainter& painter) { delta=deltap+deltam; if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) { - double x=transformX(xv+shift*delta-width*deltam); + const double x=transformX(xv+shift*delta-width*deltam); double y=transformY(yv); - double xx=transformX(xv+shift*delta+width*deltap); + const double xx=transformX(xv+shift*delta+width*deltap); double yy=yv0; //std::cout<<"delta="<getDatastore(); + const JKQTPDatastore* datastore=parent->getDatastore(); if (datastore==nullptr) return; drawErrorsBefore(painter); - QPen p=getLinePenForRects(painter, parent); + const QPen p=getLinePenForRects(painter, parent); + const QBrush b=getFillBrush(painter, parent); - QBrush b=getFillBrush(painter, parent); - - int imax=static_cast(qMin(datastore->getRows(static_cast(xColumn)), datastore->getRows(static_cast(yColumn)))); + int imax=0; int imin=0; - if (imaxgetXAxis()->isLogAxis()) x0=transformX(parent->getXAxis()->getMin()); -// double y0=transformY(0); -// if (parent->getYAxis()->isLogAxis()) y0=transformY(parent->getYAxis()->getMin()); - { - painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); - intSortData(); - const bool hasStackPar=hasStackParent(); - double delta=1; - double deltap=0; - double deltam=0; - for (int iii=imin; iiiget(static_cast(xColumn),static_cast(i)); - double yv=datastore->get(static_cast(yColumn),static_cast(i)); - int sr=datastore->getNextLowerIndex(yColumn, i); - int lr=datastore->getNextHigherIndex(yColumn, i); - double xv0=x0; - if (!qFuzzyIsNull(getBaseline())) xv0=transformX(getBaseline()); - if (hasStackPar) { - double stackLastX=getParentStackedMax(i); - const double xvold=xv; - xv0=transformX(stackLastX)+(getLineWidth()); - xv=stackLastX+xvold; - } + double x0=transformX(0); + if (parent->getXAxis()->isLogAxis()) x0=transformX(parent->getXAxis()->getMin()); + // double y0=transformY(0); + // if (parent->getYAxis()->isLogAxis()) y0=transformY(parent->getYAxis()->getMin()); + { + painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + intSortData(); + const bool hasStackPar=hasStackParent(); + double delta=1; + double deltap=0; + double deltam=0; + for (int iii=imin; iiiget(static_cast(xColumn),static_cast(i)); + double yv=datastore->get(static_cast(yColumn),static_cast(i)); + int sr=datastore->getNextLowerIndex(yColumn, i); + int lr=datastore->getNextHigherIndex(yColumn, i); + double xv0=x0; + if (!qFuzzyIsNull(getBaseline())) xv0=transformX(getBaseline()); + if (hasStackPar) { + double stackLastX=getParentStackedMax(i); + const double xvold=xv; + xv0=transformX(stackLastX)+(getLineWidth()); + xv=stackLastX+xvold; + } - if (sr<0 && lr<0) { // only one y-value - deltam=0.5; - deltap=0.5; - } else if (lr<0) { // the right-most y-value - deltap=deltam=fabs(yv-datastore->get(yColumn,sr))/2.0; - } else if (sr<0) { // the left-most y-value - deltam=deltap=fabs(datastore->get(yColumn,lr)-yv)/2.0; - } else { - deltam=fabs(yv-datastore->get(yColumn,sr))/2.0; - deltap=fabs(datastore->get(yColumn,lr)-yv)/2.0; - } - delta=deltap+deltam; + if (sr<0 && lr<0) { // only one y-value + deltam=0.5; + deltap=0.5; + } else if (lr<0) { // the right-most y-value + deltap=deltam=fabs(yv-datastore->get(yColumn,sr))/2.0; + } else if (sr<0) { // the left-most y-value + deltam=deltap=fabs(datastore->get(yColumn,lr)-yv)/2.0; + } else { + deltam=fabs(yv-datastore->get(yColumn,sr))/2.0; + deltap=fabs(datastore->get(yColumn,lr)-yv)/2.0; + } + delta=deltap+deltam; - if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) { - double x=xv0; - if (!qFuzzyIsNull(getBaseline())) x=transformX(getBaseline()); - double y=transformY(yv+shift*delta+width*deltap); - double xx=transformX(xv); - double yy=transformY(yv+shift*delta-width*deltam); - if (x>xx) { qSwap(x,xx); } - //qDebug()<<"delta="<xx) { qSwap(x,xx); } + //qDebug()<<"delta="<getDatastore(); + const JKQTPDatastore* datastore=parent->getDatastore(); + int imax=0; int imin=0; - int imax=static_cast(qMin(datastore->getRows(static_cast(xColumn)), datastore->getRows(static_cast(yColumn)))); - if (imaxget(static_cast(xColumn),static_cast(i))+getXErrorU(i, datastore); - double xvv=datastore->get(static_cast(xColumn),static_cast(i))-getXErrorL(i, datastore); - if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(xvv) ) { - if (start || xv>maxx) maxx=xv; - if (start || xvmaxx) maxx=xvv; - if (xvvget(static_cast(xColumn),static_cast(i))+getXErrorU(i, datastore); + const double xvv=datastore->get(static_cast(xColumn),static_cast(i))-getXErrorL(i, datastore); + if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(xvv) ) { + if (start || xv>maxx) maxx=xv; + if (start || xvmaxx) maxx=xvv; + if (xvvgetDatastore(); + int imax=0; int imin=0; - int imax=static_cast(qMin(datastore->getRows(static_cast(xColumn)), datastore->getRows(static_cast(yColumn)))); - if (imaxmaxy) maxy=yv; - if (yvget(static_cast(yColumn),static_cast(i)); - if (JKQTPIsOKFloat(yv)) { - if (yv>maxy) maxy=yv; - if (yvmaxy) maxy=yv; + if (yvget(static_cast(yColumn),static_cast(i)); + if (JKQTPIsOKFloat(yv)) { + if (yv>maxy) maxy=yv; + if (yvgetDatastore(); + const JKQTPDatastore* datastore=parent->getDatastore(); + int imax=0; int imin=0; - int imax=static_cast(qMin(datastore->getRows(static_cast(xColumn)), datastore->getRows(static_cast(yColumn)))); - if (imaxget(static_cast(yColumn),static_cast(i))+getYErrorU(i, datastore); - double yvv=datastore->get(static_cast(yColumn),static_cast(i))-getYErrorL(i, datastore); - if (JKQTPIsOKFloat(yv) && JKQTPIsOKFloat(yvv) ) { - if (start || yv>maxy) maxy=yv; - if (start || yvmaxy) maxy=yvv; - if (start || yvvget(static_cast(yColumn),static_cast(i))+getYErrorU(i, datastore); + const double yvv=datastore->get(static_cast(yColumn),static_cast(i))-getYErrorL(i, datastore); + if (JKQTPIsOKFloat(yv) && JKQTPIsOKFloat(yvv) ) { + if (start || yv>maxy) maxy=yv; + if (start || yvmaxy) maxy=yvv; + if (start || yvv(qMin(datastore->getRows(static_cast(xColumn)), datastore->getRows(static_cast(yColumn)))); + int imax=0; int imin=0; - if (imaxgetXAxis()->isLogAxis()) { - if (getBaseline()>0 && getBaseline()>parent->getXAxis()->getMin()) x0=transformX(getBaseline()); - else x0=transformX(parent->getXAxis()->getMin()); - } - // double y0=transformY(getBaseline()); - // if (parent->getYAxis()->isLogAxis()) { - // y0=transformY(parent->getYAxis()->getMin()); - // if (getBaseline()>0 && getBaseline()>parent->getYAxis()->getMin()) y0=transformY(getBaseline()); - // else y0=transformY(parent->getYAxis()->getMin()); - // } - //bool first=false; - QVector lines; - QVector points; - intSortData(); - for (int iii=imin; iiiget(static_cast(xColumn),static_cast(i)); - double yv=datastore->get(static_cast(yColumn),static_cast(i)); - if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) { - double x=transformX(xv); - double y=transformY(yv); - - - lines.append(QLineF(x0, y, x, y)); - points.append(QPointF(x,y)); - // xold=x; - // yold=y; - //first=true; + double x0=transformX(getBaseline()); + if (parent->getXAxis()->isLogAxis()) { + if (getBaseline()>0 && getBaseline()>parent->getXAxis()->getMin()) x0=transformX(getBaseline()); + else x0=transformX(parent->getXAxis()->getMin()); } - } - painter.setPen(p); - if (lines.size()>0) painter.drawLines(lines); - if (drawSymbols && points.size()>0) { - painter.save(); auto __finalpaintsym=JKQTPFinally([&painter]() {painter.restore();}); - for (auto& p: points) { - plotStyledSymbol(parent, painter, p.x(), p.y()); + + QVector lines; + QVector points; + intSortData(); + for (int iii=imin; iiiget(static_cast(xColumn),static_cast(i)); + const double yv=datastore->get(static_cast(yColumn),static_cast(i)); + if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) { + const double x=transformX(xv); + const double y=transformY(yv); + + lines.append(QLineF(x0, y, x, y)); + points.append(QPointF(x,y)); + + } + } + painter.setPen(p); + if (lines.size()>0) painter.drawLines(lines); + if (drawSymbols && points.size()>0) { + painter.save(); auto __finalpaintsym=JKQTPFinally([&painter]() {painter.restore();}); + for (auto& p: points) { + plotStyledSymbol(parent, painter, p.x(), p.y()); + } } } @@ -210,55 +194,42 @@ void JKQTPImpulsesVerticalGraph::draw(JKQTPEnhancedPainter& painter) { QPen p=getLinePen(painter, parent); p.setCapStyle(Qt::FlatCap); - int imax=static_cast(qMin(datastore->getRows(static_cast(xColumn)), datastore->getRows(static_cast(yColumn)))); + int imax=0; int imin=0; - if (imaxgetXAxis()->isLogAxis()) { - // if (getBaseline()>0 && getBaseline()>parent->getXAxis()->getMin()) x0=transformX(getBaseline()); - // else x0=transformX(parent->getXAxis()->getMin()); - // } - double y0=transformY(getBaseline()); - if (parent->getYAxis()->isLogAxis()) { - y0=transformY(parent->getYAxis()->getMin()); - if (getBaseline()>0 && getBaseline()>parent->getYAxis()->getMin()) y0=transformY(getBaseline()); - else y0=transformY(parent->getYAxis()->getMin()); - } - QVector lines; - QVector points; - intSortData(); - for (int iii=imin; iiiget(static_cast(xColumn),static_cast(i)); - double yv=datastore->get(static_cast(yColumn),static_cast(i)); - if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv) ) { - double x=transformX(xv); - double y=transformY(yv); + if (getIndexRange(imin, imax)) { - lines.append(QLineF(x, y0, x, y)); - points.append(QPointF(x,y)); - //xold=x; - //yold=y; - //first=true; + + double y0=transformY(getBaseline()); + if (parent->getYAxis()->isLogAxis()) { + y0=transformY(parent->getYAxis()->getMin()); + if (getBaseline()>0 && getBaseline()>parent->getYAxis()->getMin()) y0=transformY(getBaseline()); + else y0=transformY(parent->getYAxis()->getMin()); } - } - painter.setPen(p); - if (lines.size()>0) painter.drawLines(lines); - if (drawSymbols && points.size()>0) { - painter.save(); auto __finalpaintsym=JKQTPFinally([&painter]() {painter.restore();}); - for (auto& p: points) { - plotStyledSymbol(parent, painter, p.x(), p.y()); + QVector lines; + QVector points; + intSortData(); + for (int iii=imin; iiiget(static_cast(xColumn),static_cast(i)); + const double yv=datastore->get(static_cast(yColumn),static_cast(i)); + if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv) ) { + const double x=transformX(xv); + const double y=transformY(yv); + + + lines.append(QLineF(x, y0, x, y)); + points.append(QPointF(x,y)); + + } + } + painter.setPen(p); + if (lines.size()>0) painter.drawLines(lines); + if (drawSymbols && points.size()>0) { + painter.save(); auto __finalpaintsym=JKQTPFinally([&painter]() {painter.restore();}); + for (auto& p: points) { + plotStyledSymbol(parent, painter, p.x(), p.y()); + } } } } diff --git a/lib/jkqtplotter/graphs/jkqtpscatter.cpp b/lib/jkqtplotter/graphs/jkqtpscatter.cpp index f1427d9fef..b79edc825e 100644 --- a/lib/jkqtplotter/graphs/jkqtpscatter.cpp +++ b/lib/jkqtplotter/graphs/jkqtpscatter.cpp @@ -61,7 +61,7 @@ void JKQTPXYLineGraph::draw(JKQTPEnhancedPainter& painter) { JKQTPAutoOutputTimer jkaaot("JKQTPXYLineGraph::draw"); #endif if (parent==nullptr) return; - JKQTPDatastore* datastore=parent->getDatastore(); + const JKQTPDatastore* datastore=parent->getDatastore(); if (datastore==nullptr) return; //qDebug()<<"JKQTPXYLineGraph::draw();"; @@ -72,63 +72,56 @@ void JKQTPXYLineGraph::draw(JKQTPEnhancedPainter& painter) { painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); //qDebug()<<"JKQTPXYLineGraph::draw(): "<<2; - QPen p=getLinePen(painter, parent); + const QPen p=getLinePen(painter, parent); + const QPen penSelection=getHighlightingLinePen(painter, parent); - QPen penSelection=getHighlightingLinePen(painter, parent); - - - int imax= static_cast(qMin(datastore->getRows(static_cast(xColumn)), datastore->getRows(static_cast(yColumn)))); + int imax=0; int imin=0; + if (getIndexRange(imin, imax)) { - if (imax vec_linesP; - vec_linesP.push_back(QPolygonF()); - intSortData(); - for (int iii=imin; iiiget(static_cast(xColumn),static_cast(i)); - double yv=datastore->get(static_cast(yColumn),static_cast(i)); - double x=transformX(xv); - double y=transformY(yv); - //qDebug()<<"JKQTPXYLineGraph::draw(): (xv, yv) = ( "< vec_linesP; + vec_linesP.push_back(QPolygonF()); + intSortData(); + for (int iii=imin; iiiget(static_cast(xColumn),static_cast(i)); + const double yv=datastore->get(static_cast(yColumn),static_cast(i)); + const double x=transformX(xv); + const double y=transformY(yv); + //qDebug()<<"JKQTPXYLineGraph::draw(): (xv, yv) = ( "<pt2px(painter, symbolSize*1.5), parent->pt2px(painter, symbolWidth*parent->getLineWidthMultiplier()), penSelection.color(), penSelection.color()); - } - if ((!parent->getXAxis()->isLogAxis() || xv>0.0) && (!parent->getYAxis()->isLogAxis() || yv>0.0) ) { - plotStyledSymbol(parent, painter, x, y); - if (drawLine) { - vec_linesP[vec_linesP.size()-1] << QPointF(x,y); + if (isHighlighted() && getSymbolType()!=JKQTPNoSymbol) { + //JKQTPPlotSymbol(painter, x, y, JKQTPFilledCircle, parent->pt2px(painter, symbolSize*1.5), parent->pt2px(painter, symbolWidth*parent->getLineWidthMultiplier()), penSelection.color(), penSelection.color()); + } + if ((!parent->getXAxis()->isLogAxis() || xv>0.0) && (!parent->getYAxis()->isLogAxis() || yv>0.0) ) { + plotStyledSymbol(parent, painter, x, y); + if (drawLine) { + vec_linesP[vec_linesP.size()-1] << QPointF(x,y); + } + } else { + vec_linesP.push_back(QPolygonF()); } - } else { - vec_linesP.push_back(QPolygonF()); } } - } - //qDebug()<<"JKQTPXYLineGraph::draw(): "<<4<<" lines="<getDatastore(); + const JKQTPDatastore* datastore=parent->getDatastore(); + int imax=0; int imin=0; - int imax= static_cast(qMin(datastore->getRows(static_cast(xColumn)), datastore->getRows(static_cast(yColumn)))); - - if (imaxget(static_cast(xColumn),static_cast(i))+getXErrorU(i, datastore); - if (JKQTPIsOKFloat(xv)) { - if (start || xv>maxx) maxx=xv; - if (start || xvget(static_cast(xColumn),static_cast(i))-getXErrorL(i, datastore); - if (JKQTPIsOKFloat(xv)) { - if (start || xv>maxx) maxx=xv; - if (start || xvget(static_cast(xColumn),static_cast(i))+getXErrorU(i, datastore); + if (JKQTPIsOKFloat(xv)) { + if (start || xv>maxx) maxx=xv; + if (start || xvget(static_cast(xColumn),static_cast(i))-getXErrorL(i, datastore); + if (JKQTPIsOKFloat(xv)) { + if (start || xv>maxx) maxx=xv; + if (start || xvgetDatastore(); + const JKQTPDatastore* datastore=parent->getDatastore(); + int imax=0; int imin=0; - int imax= static_cast(qMin(datastore->getRows(static_cast(xColumn)), datastore->getRows(static_cast(yColumn)))); - - if (imaxget(static_cast(yColumn),static_cast(i))+getYErrorU(i, datastore); - if (JKQTPIsOKFloat(yv)) { - if (start || yv>maxy) maxy=yv; - if (start || yvget(static_cast(yColumn),static_cast(i))-getYErrorL(i, datastore); - if (JKQTPIsOKFloat(yv)) { - if (start || yv>maxy) maxy=yv; - if (start || yvget(static_cast(yColumn),static_cast(i))+getYErrorU(i, datastore); + if (JKQTPIsOKFloat(yv)) { + if (start || yv>maxy) maxy=yv; + if (start || yvget(static_cast(yColumn),static_cast(i))-getYErrorL(i, datastore); + if (JKQTPIsOKFloat(yv)) { + if (start || yv>maxy) maxy=yv; + if (start || yv(qMin(datastore->getRows(static_cast(xColumn)), datastore->getRows(static_cast(yColumn)))); + int imax=0; int imin=0; - if (imax lines; - QPolygonF linesP; - QVector linecols; - QVector linecolss; - QVector linewidths; - //qDebug()<<"JKQTPXYLineGraph::draw(): "<<3<<" imin="<