/* Copyright (c) 2008-2020 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/jkqtpbarchart.h" #include "jkqtplotter/jkqtpbaseplotter.h" #include #include #include #include "jkqtplotter/jkqtptools.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()) { } void JKQTPBarVerticalGraph::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) { painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); QPen p=getLinePenForRects(painter, parent); QPen np(Qt::NoPen); QBrush b=getFillBrush(painter, parent); //int y=rect.top()+rect.height()/2.0; painter.setPen(p); painter.setBrush(b); painter.drawRect(rect); } QColor JKQTPBarVerticalGraph::getKeyLabelColor() const { return getFillColor(); } void JKQTPBarVerticalGraph::draw(JKQTPEnhancedPainter& painter) { #ifdef JKQTBP_AUTOTIMER JKQTPAutoOutputTimer jkaaot("JKQTPBarHorizontalGraph::draw"); #endif if (parent==nullptr) return; JKQTPDatastore* datastore=parent->getDatastore(); if (datastore==nullptr) return; drawErrorsBefore(painter); QPen p=getLinePenForRects(painter, parent); QBrush b=getFillBrush(painter, parent); int imax=static_cast(qMin(datastore->getRows(static_cast(xColumn)), datastore->getRows(static_cast(yColumn)))); int imin=0; if (imaxgetXAxis()->isLogAxis()) x0=transformX(parent->getXAxis()->getMin()); double y0=transformY(0); if (parent->getYAxis()->isLogAxis()) y0=transformY(parent->getYAxis()->getMin()); double delta=1; double deltap=0; double deltam=0; intSortData(); const bool hasStackPar=hasStackParent(); for (int iii=imin; iiiget(static_cast(xColumn),static_cast(i)); int sr=datastore->getNextLowerIndex(xColumn, i); int lr=datastore->getNextHigherIndex(xColumn, i); double yv=datastore->get(static_cast(yColumn),static_cast(i)); double yv0=y0; if (!qFuzzyIsNull(baseline)) yv0=transformY(baseline); if (hasStackPar) { double stackLastY=getParentStackedMax(i); const double yvold=yv; yv0=transformY(stackLastY)-(getLineWidth()); yv=stackLastY+yvold; } if (sr<0 && lr<0) { // only one x-value deltam=0.5; deltap=0.5; } else if (lr<0) { // the right-most x-value deltap=deltam=fabs(xv-datastore->get(xColumn,sr))/2.0; } else if (sr<0) { // the left-most x-value deltam=deltap=fabs(datastore->get(xColumn,lr)-xv)/2.0; } else { deltam=fabs(xv-datastore->get(xColumn,sr))/2.0; deltap=fabs(datastore->get(xColumn,lr)-xv)/2.0; } //std::cout<getDatastore(); if (datastore==nullptr) return; drawErrorsBefore(painter); QPen p=getLinePenForRects(painter, parent); QBrush b=getFillBrush(painter, parent); int imax=static_cast(qMin(datastore->getRows(static_cast(xColumn)), datastore->getRows(static_cast(yColumn)))); 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(baseline)) xv0=transformX(baseline); 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 (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) { double x=xv0; if (!qFuzzyIsNull(baseline)) x=transformX(baseline); 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="<0) { smallestGreaterZero=baseline; minx=baseline; maxx=baseline; } if (parent==nullptr) return false; JKQTPDatastore* datastore=parent->getDatastore(); int imin=0; int imax=static_cast(qMin(datastore->getRows(static_cast(xColumn)), datastore->getRows(static_cast(yColumn)))); if (imaxmaxx) maxx=xv; if (xvget(static_cast(xColumn),static_cast(i)); if (JKQTPIsOKFloat(xv)) { if (xv>maxx) maxx=xv; if (xvgetDatastore(); 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)); double delta, deltap, deltam; int sr=datastore->getNextLowerIndex(yColumn, i); int lr=datastore->getNextHigherIndex(yColumn, i); 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(yv) && JKQTPIsOKFloat(delta) ) { if (start || yv+shift*delta+width*delta/2.0>maxy) maxy=yv+shift*delta+width*delta/2.0; if (start || yv+shift*delta-width*delta/2.0getCurrentPlotterStyle().graphFillColorDerivationMode, c)); c.setAlphaF(0.5); setHighlightingLineColor(c); } void JKQTPBarVerticalGraph::setShift(double __value) { this->shift = __value; } double JKQTPBarVerticalGraph::getShift() const { return this->shift; } void JKQTPBarVerticalGraph::setWidth(double __value) { this->width = __value; } double JKQTPBarVerticalGraph::getWidth() const { return this->width; } void JKQTPBarVerticalGraph::setBaseline(double __value) { this->baseline = __value; } double JKQTPBarVerticalGraph::getBaseline() const { return this->baseline; } void JKQTPBarVerticalGraph::setFillColor_and_darkenedColor(QColor fill, int colorDarker) { setFillColor(fill); setLineColor(fill.darker(colorDarker)); } JKQTPBarHorizontalErrorGraph::JKQTPBarHorizontalErrorGraph(JKQTBasePlotter *parent): JKQTPBarHorizontalGraph(parent) { setErrorColorFromGraphColor(getKeyLabelColor()); initErrorStyle(parent, parentPlotStyle); } JKQTPBarHorizontalErrorGraph::JKQTPBarHorizontalErrorGraph(JKQTPlotter *parent): JKQTPBarHorizontalErrorGraph(parent->getPlotter()) { } bool JKQTPBarHorizontalErrorGraph::usesColumn(int c) const { return JKQTPBarHorizontalGraph::usesColumn(c)|| JKQTPXGraphErrors::errorUsesColumn(c); } bool JKQTPBarHorizontalErrorGraph::getXMinMax(double &minx, double &maxx, double &smallestGreaterZero) { if (xErrorColumn<0 || xErrorStyle==JKQTPNoError) { return JKQTPBarHorizontalGraph::getXMinMax(minx, maxx, smallestGreaterZero); } else { bool start=false; minx=0; maxx=0; smallestGreaterZero=0; if (parent==nullptr) return false; JKQTPDatastore* datastore=parent->getDatastore(); 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 (xvvgetPlotter()) { } bool JKQTPBarVerticalErrorGraph::usesColumn(int c) const { return JKQTPBarVerticalGraph::usesColumn(c)|| JKQTPYGraphErrors::errorUsesColumn(c); } bool JKQTPBarVerticalErrorGraph::getYMinMax(double &miny, double &maxy, double &smallestGreaterZero) { if (yErrorColumn<0 || yErrorStyle==JKQTPNoError) { miny=0; maxy=0; smallestGreaterZero=0; if (baseline>0) { smallestGreaterZero=baseline; miny=baseline; maxy=baseline; } if (parent==nullptr) return false; JKQTPDatastore* datastore=parent->getDatastore(); 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 (yv0) { smallestGreaterZero=baseline; miny=baseline; maxy=baseline; } if (parent==nullptr) return false; JKQTPDatastore* datastore=parent->getDatastore(); 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 || yvvgetPlotter()) { } void JKQTPBarVerticalStackableGraph::stackUpon(JKQTPBarVerticalStackableGraph *parentGraph) { stackParent=parentGraph; } void JKQTPBarVerticalStackableGraph::dontStackUpon() { stackParent=nullptr; } double JKQTPBarVerticalStackableGraph::getParentStackedMax(int index) const { if (stackParent) { return stackParent->getStackedMax(index); } else { return 0.0; } } bool JKQTPBarVerticalStackableGraph::hasStackParent() const { return stackParent!=nullptr; } const JKQTPBarVerticalStackableGraph *JKQTPBarVerticalStackableGraph::getStackParent() const { return stackParent; } double JKQTPBarVerticalStackableGraph::getStackedMax(int index) const { double height=0; if (parent!=nullptr) { JKQTPDatastore* datastore=parent->getDatastore(); height=datastore->get(static_cast(yColumn),static_cast(index)); } if (stackParent==nullptr) { return height; } else { return stackParent->getStackedMax(index)+height; } } JKQTPBarHorizontalStackableGraph::JKQTPBarHorizontalStackableGraph(JKQTBasePlotter *parent): JKQTPBarHorizontalGraph(parent), stackParent(nullptr) { } JKQTPBarHorizontalStackableGraph::JKQTPBarHorizontalStackableGraph(JKQTPlotter *parent): JKQTPBarHorizontalStackableGraph(parent->getPlotter()) { } void JKQTPBarHorizontalStackableGraph::stackUpon(JKQTPBarHorizontalStackableGraph *parentGraph) { stackParent=parentGraph; } void JKQTPBarHorizontalStackableGraph::dontStackUpon() { stackParent=nullptr; } const JKQTPBarHorizontalStackableGraph *JKQTPBarHorizontalStackableGraph::getStackParent() const { return stackParent; } double JKQTPBarHorizontalStackableGraph::getStackedMax(int index) const { double height=0; if (parent!=nullptr) { JKQTPDatastore* datastore=parent->getDatastore(); height=datastore->get(static_cast(xColumn),static_cast(index)); } if (stackParent==nullptr) { return height; } else { return stackParent->getStackedMax(index)+height; } } double JKQTPBarHorizontalStackableGraph::getParentStackedMax(int index) const { if (stackParent) { return stackParent->getStackedMax(index); } else { return 0.0; } } bool JKQTPBarHorizontalStackableGraph::hasStackParent() const { return stackParent!=nullptr; }