/* 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/jkqtpgraphsfilledcurve.h" #include "jkqtplotter/jkqtpbaseplotter.h" #include #include #include #include "jkqtplottertools/jkqtptools.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) || (xvsgzgetNextStyle(); //std::cout<<"got style settings from parent: "<getPlotStyle(parentPlotStyle).color(); fillColor=parent->getPlotStyle(parentPlotStyle).fillColor(); style=parent->getPlotStyle(parentPlotStyle).style(); lineWidth=parent->getPlotStyle(parentPlotStyle).widthF(); fillStyle=parent->getPlotStyle(parentPlotStyle).fillStyle(); } } JKQTPFilledCurveXGraph::JKQTPFilledCurveXGraph(JKQTPlotter *parent): JKQTPFilledCurveXGraph(parent->getPlotter()) { } void JKQTPFilledCurveXGraph::draw(JKQTPEnhancedPainter& painter) { #ifdef JKQTBP_AUTOTIMER JKQTPAutoOutputTimer jkaaot("JKQTPFilledCurveXGraph::draw"); #endif if (parent==nullptr) return; JKQTPDatastore* datastore=parent->getDatastore(); if (datastore==nullptr) return; drawErrorsBefore(painter); { painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); QPen p=painter.pen(); p.setColor(color); p.setWidthF(qMax(JKQTPlotterDrawinTools::ABS_MIN_LINEWIDTH, parent->pt2px(painter, lineWidth*parent->getLineWidthMultiplier()))); p.setStyle(style); p.setJoinStyle(Qt::RoundJoin); p.setCapStyle(Qt::RoundCap); QPen np(Qt::NoPen); QBrush b=painter.brush(); b.setColor(fillColor); b.setStyle(fillStyle); int imax=static_cast(qMin(datastore->getColumn(static_cast(xColumn)).getRows(), datastore->getColumn(static_cast(yColumn)).getRows())); int imin=0; if (imaxgetXAxis()->isLogAxis()) { // if (baseline>0 && baseline>parent->getXAxis()->getMin()) x0=transformX(baseline); // else x0=transformX(parent->getXAxis()->getMin()); // } double y0=transformY(baseline); if (parent->getYAxis()->isLogAxis()) { y0=transformY(parent->getYAxis()->getMin()); if (baseline>0 && baseline>parent->getYAxis()->getMin()) y0=transformY(baseline); else y0=transformY(parent->getYAxis()->getMin()); } bool first=true; intSortData(); for (int iii=imin; iiiget(static_cast(xColumn),static_cast(i)); double yv=datastore->get(static_cast(yColumn),static_cast(i)); //std::cout<<"(xv, yv) = ( "<getPlotter()) { } void JKQTPFilledCurveYGraph::draw(JKQTPEnhancedPainter& painter) { #ifdef JKQTBP_AUTOTIMER JKQTPAutoOutputTimer jkaaot("JKQTPFilledCurveYGraph::draw"); #endif if (parent==nullptr) return; JKQTPDatastore* datastore=parent->getDatastore(); if (datastore==nullptr) return; drawErrorsBefore(painter); { painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); QPen p=painter.pen(); p.setColor(color); p.setWidthF(qMax(JKQTPlotterDrawinTools::ABS_MIN_LINEWIDTH, parent->pt2px(painter, lineWidth*parent->getLineWidthMultiplier()))); p.setStyle(style); p.setJoinStyle(Qt::RoundJoin); p.setCapStyle(Qt::RoundCap); p.setJoinStyle(Qt::RoundJoin); QPen np(Qt::NoPen); QBrush b=painter.brush(); b.setColor(fillColor); b.setStyle(fillStyle); int imax=static_cast(qMin(datastore->getColumn(static_cast(xColumn)).getRows(), datastore->getColumn(static_cast(yColumn)).getRows())); int imin=0; if (imaxgetXAxis()->isLogAxis()) { if (baseline>0 && baseline>parent->getXAxis()->getMin()) x0=transformX(baseline); else x0=transformX(parent->getXAxis()->getMin()); } /*double y0=transformY(baseline); if (parent->getYAxis()->isLogAxis()) { y0=transformY(parent->getYAxis()->getMin()); if (baseline>0 && baseline>parent->getYAxis()->getMin()) y0=transformY(baseline); else y0=transformY(parent->getYAxis()->getMin()); }*/ bool first=true; intSortData(); for (int iii=imin; iiiget(static_cast(xColumn),static_cast(i)); double yv=datastore->get(static_cast(yColumn),static_cast(i)); //std::cout<<"(xv, yv) = ( "<pt2px(painter, parent->getLineWidthMultiplier()*lineWidth))); p.setStyle(style); p.setJoinStyle(Qt::RoundJoin); p.setCapStyle(Qt::RoundCap); return p; } QBrush JKQTPFilledCurveXGraph::getBrush(JKQTPEnhancedPainter& /*painter*/) const { QBrush b; b.setColor(fillColor); b.setStyle(fillStyle); return b; } JKQTPFilledCurveXErrorGraph::JKQTPFilledCurveXErrorGraph(JKQTBasePlotter *parent): JKQTPFilledCurveXGraph(parent), JKQTPYGraphErrors(color, parent) { setErrorColorFromGraphColor(color); if (parentPlotStyle>=0) setErrorStyleFromPen(parent->getPlotStyle(parentPlotStyle)); } JKQTPFilledCurveXErrorGraph::JKQTPFilledCurveXErrorGraph(JKQTPlotter *parent): JKQTPFilledCurveXErrorGraph(parent->getPlotter()) { } bool JKQTPFilledCurveXErrorGraph::usesColumn(int c) const { return JKQTPFilledCurveXGraph::usesColumn(c)|| JKQTPYGraphErrors::errorUsesColumn(c); } void JKQTPFilledCurveXErrorGraph::drawErrorsAfter(JKQTPEnhancedPainter &painter) { if (sortData==JKQTPXYGraph::Unsorted) plotErrorIndicators(painter, parent, this, xColumn, yColumn); else plotErrorIndicators(painter, parent, this, xColumn, yColumn, 0, 0, &sortedIndices); } JKQTPFilledCurveYErrorGraph::JKQTPFilledCurveYErrorGraph(JKQTBasePlotter *parent): JKQTPFilledCurveYGraph(parent), JKQTPXGraphErrors(color, parent) { setErrorColorFromGraphColor(color); if (parentPlotStyle>=0) setErrorStyleFromPen(parent->getPlotStyle(parentPlotStyle)); } JKQTPFilledCurveYErrorGraph::JKQTPFilledCurveYErrorGraph(JKQTPlotter *parent): JKQTPFilledCurveYErrorGraph(parent->getPlotter()) { } bool JKQTPFilledCurveYErrorGraph::usesColumn(int c) const { return JKQTPFilledCurveYGraph::usesColumn(c)|| JKQTPXGraphErrors::errorUsesColumn(c); } void JKQTPFilledCurveYErrorGraph::drawErrorsAfter(JKQTPEnhancedPainter &painter) { if (sortData==JKQTPXYGraph::Unsorted) plotErrorIndicators(painter, parent, this, xColumn, yColumn); else plotErrorIndicators(painter, parent, this, xColumn, yColumn, 0, 0, &sortedIndices); } JKQTPFilledVerticalRangeGraph::JKQTPFilledVerticalRangeGraph(JKQTBasePlotter *parent): JKQTPXYGraph(parent) { drawSelectionLine=false; selectionLineColor=Qt::transparent; color=QColor("red"); fillColor=color.lighter(); style=Qt::SolidLine; lineWidth=2; parentPlotStyle=-1; drawLine=true; fillStyle=Qt::SolidPattern; if (parent) { // get style settings from parent object parentPlotStyle=parent->getNextStyle(); //std::cout<<"got style settings from parent: "<getPlotStyle(parentPlotStyle).color(); fillColor=parent->getPlotStyle(parentPlotStyle).fillColor(); style=parent->getPlotStyle(parentPlotStyle).style(); lineWidth=parent->getPlotStyle(parentPlotStyle).widthF(); fillStyle=parent->getPlotStyle(parentPlotStyle).fillStyle(); } } JKQTPFilledVerticalRangeGraph::JKQTPFilledVerticalRangeGraph(JKQTPlotter *parent): JKQTPFilledVerticalRangeGraph(parent->getPlotter()) { } bool JKQTPFilledVerticalRangeGraph::getYMinMax(double &miny, double &maxy, double &smallestGreaterZero) { bool start=true; miny=0; maxy=0; smallestGreaterZero=0; if (parent==nullptr) return false; JKQTPDatastore* datastore=parent->getDatastore(); int imin=0; int imax=static_cast(qMin(qMin(datastore->getColumn(static_cast(xColumn)).getRows(), datastore->getColumn(static_cast(yColumn)).getRows()), datastore->getColumn(static_cast(yColumn2)).getRows())); if (imaxget(static_cast(yColumn),static_cast(i)); double yv2=datastore->get(static_cast(yColumn2),static_cast(i)); if (JKQTPIsOKFloat(yv)) { if (start || yv>maxy) maxy=yv; if (start || yvmaxy) maxy=yv2; if (start || yv2getDatastore(); if (datastore==nullptr) return; drawErrorsBefore(painter); { painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); QPen p=painter.pen(); p.setColor(color); p.setWidthF(qMax(JKQTPlotterDrawinTools::ABS_MIN_LINEWIDTH, parent->pt2px(painter, lineWidth*parent->getLineWidthMultiplier()))); p.setStyle(style); p.setJoinStyle(Qt::RoundJoin); p.setCapStyle(Qt::RoundCap); QPen np(Qt::NoPen); QBrush b=painter.brush(); b.setColor(fillColor); b.setStyle(fillStyle); int imax=static_cast(qMin(qMin(datastore->getColumn(static_cast(xColumn)).getRows(), datastore->getColumn(static_cast(yColumn)).getRows()), datastore->getColumn(static_cast(yColumn2)).getRows())); int imin=0; if (imaxget(static_cast(xColumn),static_cast(i)); double yv=datastore->get(static_cast(yColumn),static_cast(i)); double yv2=datastore->get(static_cast(yColumn2),static_cast(i)); //std::cout<<"(xv, yv) = ( "<0) { for (int i=plow.size()-1; i>=0; i--) { poly_all.append(plow[i]); } } painter.setBrush(b); painter.setPen(np); painter.drawPolygon(poly_all); if (drawLine) { painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); if (drawSelectionLine) { QPen penSelection=p; penSelection.setStyle(Qt::SolidLine); QColor selcol=penSelection.color(); selcol.setAlphaF(0.5); penSelection.setColor(selcol); if (selectionLineColor!=Qt::transparent) { penSelection.setColor(selectionLineColor); } penSelection.setWidthF(penSelection.widthF()*3.0); painter.setPen(penSelection); painter.drawPolyline(phigh); painter.drawPolyline(plow); } painter.setPen(p); painter.drawPolyline(phigh); painter.drawPolyline(plow); } } drawErrorsAfter(painter); } void JKQTPFilledVerticalRangeGraph::drawKeyMarker(JKQTPEnhancedPainter &painter, QRectF &rect) { painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); QRectF r=rect; r.setHeight(r.height()/2.0); r.moveTo(r.x(), r.y()+r.height()-1); painter.fillRect(r, getBrush(painter)); if (drawLine) { painter.setPen(getLinePen(painter)); painter.drawLine(QLineF(r.topLeft(), r.topRight())); } } QColor JKQTPFilledVerticalRangeGraph::getKeyLabelColor() { return color; } QBrush JKQTPFilledVerticalRangeGraph::getBrush(JKQTPEnhancedPainter &/*painter*/) const { QBrush b; b.setColor(fillColor); b.setStyle(fillStyle); return b; } QPen JKQTPFilledVerticalRangeGraph::getLinePen(JKQTPEnhancedPainter &painter) const { QPen p; p.setColor(color); p.setWidthF(qMax(JKQTPlotterDrawinTools::ABS_MIN_LINEWIDTH, parent->pt2px(painter, lineWidth*parent->getLineWidthMultiplier()))); p.setStyle(style); p.setJoinStyle(Qt::RoundJoin); p.setCapStyle(Qt::RoundCap); return p; }