/* Copyright (c) 2008-2022 Jan W. Krieger () This software is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License (LGPL) for more details. You should have received a copy of the GNU Lesser General Public License (LGPL) along with this program. If not, see . */ #include "jkqtplotter/graphs/jkqtplines.h" #include "jkqtplotter/jkqtpbaseplotter.h" #include #include #include #include #include "jkqtcommon/jkqtpdrawingtools.h" #include "jkqtplotter/jkqtptools.h" #include "jkqtplotter/jkqtpimagetools.h" #include "jkqtplotter/graphs/jkqtpimage.h" #include "jkqtplotter/jkqtpbaseelements.h" #include "jkqtplotter/jkqtplotter.h" #define SmallestGreaterZeroCompare_xvsgz() if ((xvsgz>10.0*DBL_MIN)&&((smallestGreaterZero<10.0*DBL_MIN) || (xvsgzgetPlotter()) { } JKQTPXYLineGraph::JKQTPXYLineGraph(JKQTBasePlotter* parent): JKQTPXYGraph(parent), drawLine(true) { sortData=JKQTPXYGraph::Unsorted; initLineStyle(parent, parentPlotStyle, JKQTPPlotStyleType::Default); initSymbolStyle(parent, parentPlotStyle, JKQTPPlotStyleType::Default); } void JKQTPXYLineGraph::draw(JKQTPEnhancedPainter& painter) { #ifdef JKQTBP_AUTOTIMER JKQTPAutoOutputTimer jkaaot("JKQTPXYLineGraph::draw"); #endif if (parent==nullptr) return; const JKQTPDatastore* datastore=parent->getDatastore(); if (datastore==nullptr) return; //qDebug()<<"JKQTPXYLineGraph::draw();"; drawErrorsBefore(painter); { //qDebug()<<"JKQTPXYLineGraph::draw(): "<<1; painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); //qDebug()<<"JKQTPXYLineGraph::draw(): "<<2; const QPen p=getLinePen(painter, parent); const QPen penSelection=getHighlightingLinePen(painter, parent); const auto symType=getSymbolType(); const double xmin=transformX(parent->getXAxis()->getMin()); const double xmax=transformX(parent->getXAxis()->getMax()); const double ymin=transformY(parent->getYAxis()->getMin()); const double ymax=transformY(parent->getYAxis()->getMax()); const double symbolSize=parent->pt2px(painter, getSymbolSize()); const QMarginsF clipMargins=(symType==JKQTPNoSymbol)?QMarginsF(0,0,0,0):QMarginsF(symbolSize,symbolSize,symbolSize,symbolSize); const QRectF cliprect=QRectF(qMin(xmin,xmax),qMin(ymin,ymax),fabs(xmax-xmin),fabs(ymax-ymin))+clipMargins; int imax=0; int imin=0; if (getIndexRange(imin, imax)) { QList 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) ) { if (symType!=JKQTPNoSymbol && cliprect.contains(x,y)) plotStyledSymbol(parent, painter, x, y); if (drawLine) { vec_linesP.last() << QPointF(x,y); } } else { if (drawLine) { if (vec_linesP.size()==0 || vec_linesP.last().size()>0) vec_linesP.push_back(QPolygonF()); } } } } //qDebug()<<"JKQTPXYLineGraph::draw(): "<<4<<" lines="< linesToDraw; if (getUseNonvisibleLineCompression()) linesToDraw=JKQTPClipPolyLines(JKQTPSimplifyPolyLines(vec_linesP, p.widthF()*getNonvisibleLineCompressionAgressiveness()), cliprect); else linesToDraw=JKQTPClipPolyLines(vec_linesP, cliprect); //qDebug()<<"JKQTPXYLineGraph::draw(): linesToDraw.size()=="< linesP.size()=="<0) { if (isHighlighted()) { painter.setPen(penSelection); painter.drawPolyline(linesP); } painter.setPen(p); painter.drawPolyline(linesP); } } } //qDebug()<<"JKQTPXYLineGraph::draw(): "<<6; } } //qDebug()<<"JKQTPXYLineGraph::draw(): "<<7; drawErrorsAfter(painter); //qDebug()<<"JKQTPXYLineGraph::draw() ... done"; } void JKQTPXYLineGraph::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) { painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); QPen p=getLinePen(painter, parent); p.setWidthF(getKeyLineWidthPx(painter,rect,parent)); painter.setPen(p); double y=rect.top()+rect.height()/2.0; if (drawLine) painter.drawLine(QLineF(rect.left(), y, rect.right(), y)); JKQTPPlotSymbol(painter, rect.left()+rect.width()/2.0, rect.top()+rect.height()/2.0, getSymbolType(), getKeySymbolSizePx(painter, rect, parent), getKeySymbolLineWidthPx(painter, rect, parent), getKeyLabelColor(), getSymbolFillColor()); } QColor JKQTPXYLineGraph::getKeyLabelColor() const { return getSymbolColor(); } void JKQTPXYLineGraph::setDrawLine(bool __value) { this->drawLine = __value; } bool JKQTPXYLineGraph::getDrawLine() const { return this->drawLine; } void JKQTPXYLineGraph::setColor(QColor c) { setLineColor(c); setSymbolColor(c); setSymbolFillColor(JKQTPGetDerivedColor(parent->getCurrentPlotterStyle().graphsStyle.defaultGraphStyle.fillColorDerivationMode, c)); c.setAlphaF(0.5); setHighlightingLineColor(c); } JKQTPXYLineErrorGraph::JKQTPXYLineErrorGraph(JKQTBasePlotter *parent): JKQTPXYLineGraph(parent) { setErrorColorFromGraphColor(getSymbolColor()); initErrorStyle(parent, parentPlotStyle); } JKQTPXYLineErrorGraph::JKQTPXYLineErrorGraph(JKQTPlotter *parent): JKQTPXYLineErrorGraph(parent->getPlotter()) { } bool JKQTPXYLineErrorGraph::getXMinMax(double &minx, double &maxx, double &smallestGreaterZero) { if (xErrorColumn<0 || xErrorStyle==JKQTPNoError) { return JKQTPXYLineGraph::getXMinMax(minx, maxx, smallestGreaterZero); } else { bool start=true; minx=0; maxx=0; smallestGreaterZero=0; if (parent==nullptr) return false; const JKQTPDatastore* datastore=parent->getDatastore(); int imax=0; int imin=0; if (getIndexRange(imin, imax)) { for (int i=imin; iget(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(); int imax=0; int imin=0; if (getIndexRange(imin, imax)) { for (int i=imin; iget(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