/* Copyright (c) 2008-2024 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/jkqtpviolinplot.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) || (xvsgzpos = __value; } double JKQTPViolinplotElementBase::getPos() const { return this->pos; } void JKQTPViolinplotElementBase::setMedian(double __value) { if (this->median != __value) { this->median = __value; drawMedian=true; } } double JKQTPViolinplotElementBase::getMedian() const { return this->median; } void JKQTPViolinplotElementBase::setMean(double __value) { if (this->mean != __value) { this->mean = __value; drawMean=true; } } double JKQTPViolinplotElementBase::getMean() const { return this->mean; } void JKQTPViolinplotElementBase::setMin(double __value) { if (this->min != __value) { this->min = __value; drawMinMax=true; } } double JKQTPViolinplotElementBase::getMin() const { return this->min; } void JKQTPViolinplotElementBase::setMax(double __value) { if (this->max != __value) { this->max = __value; drawMinMax=true; } } double JKQTPViolinplotElementBase::getMax() const { return this->max; } void JKQTPViolinplotElementBase::setDrawMean(bool __value) { this->drawMean = __value; } bool JKQTPViolinplotElementBase::getDrawMean() const { return this->drawMean; } void JKQTPViolinplotElementBase::setDrawMedian(bool __value) { this->drawMedian = __value; } bool JKQTPViolinplotElementBase::getDrawMedian() const { return this->drawMedian; } void JKQTPViolinplotElementBase::setDrawMinMax(bool __value) { this->drawMinMax = __value; } bool JKQTPViolinplotElementBase::getDrawMinMax() const { return this->drawMinMax; } void JKQTPViolinplotElementBase::setViolinPositionColumn(int __value) { violinPositionColumn=__value; } void JKQTPViolinplotElementBase::setViolinPositionColumn(size_t __value) { violinPositionColumn=static_cast(__value); } int JKQTPViolinplotElementBase::getViolinPositionColumn() const { return violinPositionColumn; } void JKQTPViolinplotElementBase::setViolinFrequencyColumn(int __value) { violinFrequencyColumn=__value; } void JKQTPViolinplotElementBase::setViolinFrequencyColumn(size_t __value) { violinFrequencyColumn=static_cast(__value); } int JKQTPViolinplotElementBase::getViolinFrequencyColumn() const { return violinFrequencyColumn; } QColor JKQTPViolinplotElementBase::getKeyLabelColor() const { return getLineColor(); } void JKQTPViolinplotElementBase::setColor(QColor c) { setViolinplotColor(c, getParent()); } JKQTPViolinplotVerticalElement::JKQTPViolinplotVerticalElement(JKQTBasePlotter* parent): JKQTPViolinplotElementBase(parent) { } JKQTPViolinplotVerticalElement::JKQTPViolinplotVerticalElement(JKQTPlotter* parent): JKQTPViolinplotVerticalElement(parent->getPlotter()) { } void JKQTPViolinplotVerticalElement::draw(JKQTPEnhancedPainter& painter) { #ifdef JKQTBP_AUTOTIMER JKQTPAutoOutputTimer jkaaot("JKQTPViolinplotVerticalElement::draw"); #endif if (parent==nullptr) return; //drawErrorsBefore(painter); { painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); const double xv=pos; const double minv=min; const double maxv=max; const double medianv=median; const double meanv=mean; //std::cout<<"(xv, yv) = ( "<pt2px(painter,getViolinWidthAbsolute()); double xma=x+w/2.0; double xmi=x-w/2.0; QVector violPos; if (violinPositionColumn>=0) violPos=transformY(getParent()->getDatastore()->getData(static_cast(violinPositionColumn))); QVector violFreq; if (violinFrequencyColumn>=0) violFreq=getParent()->getDatastore()->getData(static_cast(violinFrequencyColumn)); plotVerticalViolinplot(parent, painter, x, xmi, xma, violPos, violFreq, (drawMinMax)?min:JKQTP_NAN, (drawMedian)?median:JKQTP_NAN, (drawMinMax)?max:JKQTP_NAN, (drawMean)?mean:JKQTP_NAN); if (drawMedian && JKQTPIsOKFloat(medianv)) { if (JKQTPIsOKFloat(medianv)) { QStringList sl=labelValues, sll=labelNames; sl[labMedian]="\\ul{"+sl[labMedian]+"}"; sll[labMedian]="\\ul{"+sll[labMedian]+"}"; addHitTestData(xv, medianv, "\\ensuremath{\\begin{bmatrix}"+sll.join("\\\\")+"\\end{bmatrix}\\;=\\;\\begin{bmatrix}"+sl.join("\\\\")+"\\end{bmatrix}}"); } } if (drawMinMax) { if (JKQTPIsOKFloat(minv)) { QStringList sl=labelValues, sll=labelNames; sl[labMin]="\\ul{"+sl[labMin]+"}"; sll[labMin]="\\ul{"+sll[labMin]+"}"; addHitTestData(xv, minv, "\\ensuremath{\\begin{bmatrix}"+sll.join("\\\\")+"\\end{bmatrix}\\;=\\;\\begin{bmatrix}"+sl.join("\\\\")+"\\end{bmatrix}}"); } if (JKQTPIsOKFloat(maxv)) { QStringList sl=labelValues, sll=labelNames; sl[labMax]="\\ul{"+sl[labMax]+"}"; sll[labMax]="\\ul{"+sll[labMax]+"}"; addHitTestData(xv, maxv, "\\ensuremath{\\begin{bmatrix}"+sll.join("\\\\")+"\\end{bmatrix}\\;=\\;\\begin{bmatrix}"+sl.join("\\\\")+"\\end{bmatrix}}"); } } if (drawMean && JKQTPIsOKFloat(meanv)) { if (JKQTPIsOKFloat(meanv)) { QStringList sl=labelValues, sll=labelNames; sl[labMean]="\\ul{"+sl[labMean]+"}"; sll[labMean]="\\ul{"+sll[labMean]+"}"; addHitTestData(xv, meanv, "\\ensuremath{\\begin{bmatrix}"+sll.join("\\\\")+"\\end{bmatrix}\\;=\\;\\begin{bmatrix}"+sl.join("\\\\")+"\\end{bmatrix}}"); } } } } //drawErrorsAfter(painter); } bool JKQTPViolinplotVerticalElement::getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) { minx=0; maxx=0; smallestGreaterZero=0; if (parent==nullptr) return false; double xv=pos; double x=transformX(xv); double xma=backtransformX(x-parent->pt2px(getViolinWidthAbsolute(), 72)); double xmi=backtransformX(x+parent->pt2px(getViolinWidthAbsolute(), 72)); if (xmi>xma) qSwap(xmi,xma); maxx=xma; minx=xmi; double xvsgz; xvsgz=xmi; SmallestGreaterZeroCompare_xvsgz(); xvsgz=xma; SmallestGreaterZeroCompare_xvsgz(); return true; } bool JKQTPViolinplotVerticalElement::getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) { miny=0; maxy=0; smallestGreaterZero=0; if (parent==nullptr) return false ; if (drawMedian) { maxy=median; miny=median; } if (min>maxy) maxy=min; if (drawMinMax && (minmaxy)) maxy=max; if (drawMinMax && (maxgetPlotter()) { } void JKQTPViolinplotHorizontalElement::drawKeyMarker(JKQTPEnhancedPainter& painter, const QRectF& rect) { plotHorizontalKeyMarker(parent, painter, rect); } bool JKQTPViolinplotHorizontalElement::getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) { minx=0; maxx=0; smallestGreaterZero=0; if (parent==nullptr) return false; if (drawMedian) { maxx=median; minx=median; } if (min>maxx) maxx=min; if (drawMinMax && (minmaxx)) maxx=max; if (drawMinMax && (maxpt2px(getViolinWidthAbsolute(), 72)); double xmi=backtransformY(x+parent->pt2px(getViolinWidthAbsolute(), 72)); if (xmi>xma) qSwap(xmi,xma); maxy=xma; miny=xmi; double xvsgz; xvsgz=xmi; SmallestGreaterZeroCompare_xvsgz(); xvsgz=xma; SmallestGreaterZeroCompare_xvsgz(); return true; } void JKQTPViolinplotHorizontalElement::draw(JKQTPEnhancedPainter& painter) { #ifdef JKQTBP_AUTOTIMER JKQTPAutoOutputTimer jkaaot("JKQTPViolinplotHorizontalElement::draw"); #endif if (parent==nullptr) return; //drawErrorsBefore(painter); { painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); const double yv=pos; const double minv=min; const double maxv=max; const double medianv=median; const double meanv=mean; //std::cout<<"(xv, yv) = ( "<pt2px(painter,getViolinWidthAbsolute()); double yma=y+w/2.0; double ymi=y-w/2.0; QVector violPos; if (violinPositionColumn>=0) violPos=transformX(getParent()->getDatastore()->getData(static_cast(violinPositionColumn))); QVector violFreq; if (violinFrequencyColumn>=0) violFreq=getParent()->getDatastore()->getData(static_cast(violinFrequencyColumn)); plotHorizontalViolinplot(parent, painter, y, ymi, yma, violPos, violFreq, (drawMinMax)?min:JKQTP_NAN, (drawMedian)?median:JKQTP_NAN, (drawMinMax)?max:JKQTP_NAN, (drawMean)?mean:JKQTP_NAN); if (drawMedian && JKQTPIsOKFloat(medianv)) { if (JKQTPIsOKFloat(medianv)) { QStringList sl=labelValues, sll=labelNames; sl[labMedian]="\\ul{"+sl[labMedian]+"}"; sll[labMedian]="\\ul{"+sll[labMedian]+"}"; addHitTestData(medianv, yv, "\\ensuremath{\\begin{bmatrix}"+sll.join("\\\\")+"\\end{bmatrix}\\;=\\;\\begin{bmatrix}"+sl.join("\\\\")+"\\end{bmatrix}}"); } } if (drawMinMax) { if (JKQTPIsOKFloat(minv)) { QStringList sl=labelValues, sll=labelNames; sl[labMin]="\\ul{"+sl[labMin]+"}"; sll[labMin]="\\ul{"+sll[labMin]+"}"; addHitTestData(minv, yv, "\\ensuremath{\\begin{bmatrix}"+sll.join("\\\\")+"\\end{bmatrix}\\;=\\;\\begin{bmatrix}"+sl.join("\\\\")+"\\end{bmatrix}}"); } if (JKQTPIsOKFloat(maxv)) { QStringList sl=labelValues, sll=labelNames; sl[labMax]="\\ul{"+sl[labMax]+"}"; sll[labMax]="\\ul{"+sll[labMax]+"}"; addHitTestData(maxv, yv, "\\ensuremath{\\begin{bmatrix}"+sll.join("\\\\")+"\\end{bmatrix}\\;=\\;\\begin{bmatrix}"+sl.join("\\\\")+"\\end{bmatrix}}"); } } if (drawMean && JKQTPIsOKFloat(meanv)) { if (JKQTPIsOKFloat(meanv)) { QStringList sl=labelValues, sll=labelNames; sl[labMean]="\\ul{"+sl[labMean]+"}"; sll[labMean]="\\ul{"+sll[labMean]+"}"; addHitTestData(meanv, yv, "\\ensuremath{\\begin{bmatrix}"+sll.join("\\\\")+"\\end{bmatrix}\\;=\\;\\begin{bmatrix}"+sl.join("\\\\")+"\\end{bmatrix}}"); } } } } //drawErrorsAfter(painter); }