/* Copyright (c) 2008-2019 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/jkqtpgraphsrange.h" #include "jkqtplotter/jkqtpbaseplotter.h" #include #include #include #include "jkqtplottertools/jkqtptools.h" #include "jkqtplottertools/jkqtpimagetools.h" #include "jkqtplotter/jkqtpgraphsimage.h" #include "jkqtplotter/jkqtpbaseelements.h" #include "jkqtplotter/jkqtplotter.h" #define SmallestGreaterZeroCompare_xvsgz() if ((xvsgz>10.0*DBL_MIN)&&((smallestGreaterZero<10.0*DBL_MIN) || (xvsgzgetPlotStyle(parentPlotStyle).color(); } rangeMin=rangeMax=0; rangeCenter=0; plotCenterLine=true; plotRange=true; plotRangeLines=true; fillRange=true; } JKQTPHorizontalRange::JKQTPHorizontalRange(JKQTPlotter* parent): JKQTPHorizontalRange(parent->getPlotter()) { } void JKQTPHorizontalRange::draw(JKQTPEnhancedPainter& painter) { #ifdef JKQTBP_AUTOTIMER JKQTPAutoOutputTimer jkaaot("JKQTPHorizontalRange::draw"); #endif double c=transformY(rangeCenter); double cmi=transformY(rangeMin); double cma=transformY(rangeMax); double smi=transformY(parent->getYAxis()->getMin()); double sma=transformY(parent->getYAxis()->getMax()); double mi=transformX(parent->getXAxis()->getMin()); double ma=transformX(parent->getXAxis()->getMax()); if (!unlimitedSizeMin) mi=transformX(sizeMin); if (!unlimitedSizeMax) ma=transformX(sizeMax); //std::cout<<"hor: rangeMin="< "< "<getYAxis()->getMin()); double ma=transformY(parent->getYAxis()->getMax()); double smi=transformX(parent->getXAxis()->getMin()); double sma=transformX(parent->getXAxis()->getMax()); if (!unlimitedSizeMin) mi=transformY(sizeMin); if (!unlimitedSizeMax) ma=transformY(sizeMax); painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); if (plotRange && (cmi!=cma) && JKQTPIsOKFloat(mi) && JKQTPIsOKFloat(ma)) { QPen p=getLinePen(painter, parent); QPen np(Qt::NoPen); QBrush nb(Qt::NoBrush); QBrush b=getFillBrush(painter, parent); QRectF rect(QPointF(cmi, mi), QPointF(cma, ma)); if (fillRange) { painter.setPen(np); painter.setBrush(b); if (invertedRange) { if (JKQTPIsOKFloat(cmi)) { QRectF rectl(QPointF(smi,mi), QPointF(cmi,ma)); painter.drawRect(rectl); } if (JKQTPIsOKFloat(cma)) { QRectF rectr(QPointF(cma,mi), QPointF(sma,ma)); painter.drawRect(rectr); } } else { if (JKQTPIsOKFloat(cmi) && JKQTPIsOKFloat(cma)) painter.drawRect(rect); } } if (plotRangeLines && JKQTPIsOKFloat(cmi) && JKQTPIsOKFloat(cma)) { painter.setPen(p); painter.setBrush(nb); painter.drawLine(rect.left(), rect.top(), rect.left(), rect.bottom()); painter.drawLine(rect.right(), rect.top(), rect.right(), rect.bottom()); } } if (plotCenterLine&& JKQTPIsOKFloat(c) && JKQTPIsOKFloat(ma) && JKQTPIsOKFloat(mi)) { QPen p=painter.pen(); p.setColor(centerColor); p.setStyle(centerStyle); p.setWidthF(qMax(JKQTPlotterDrawingTools::ABS_MIN_LINEWIDTH, parent->pt2px(painter, centerLineWidth*parent->getLineWidthMultiplier()))); painter.setPen(p); painter.drawLine(QLineF(c, mi, c, ma)); } } void JKQTPVerticalRange::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) { painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); QPen p=getLinePen(painter, parent); QPen np(Qt::NoPen); QBrush nb(Qt::NoBrush); QBrush b=getFillBrush(painter, parent); //int y=rect.top()+rect.height()/2.0; if (plotRange) { painter.setPen(np); painter.setBrush(b); if (fillRange) painter.drawRect(rect); painter.setPen(p); painter.setBrush(nb); if (plotRangeLines) { painter.drawLine(rect.left(), rect.top(), rect.left(), rect.bottom()); painter.drawLine(rect.right(), rect.top(), rect.right(), rect.bottom()); } } if (plotCenterLine) { QPen p=painter.pen(); p.setColor(centerColor); p.setStyle(centerStyle); painter.setPen(p); int y=rect.left()+rect.width()/2.0; painter.drawLine(y, rect.top(), y, rect.bottom()); } } bool JKQTPVerticalRange::getXMinMax(double &minx, double &maxx, double &smallestGreaterZero) { minx=rangeMin; maxx=rangeMax; smallestGreaterZero=0; if (rangeMin>0) smallestGreaterZero=rangeMin; return true; } bool JKQTPVerticalRange::getYMinMax(double &miny, double &maxy, double &smallestGreaterZero) { smallestGreaterZero=miny=maxy=0; return false; }