improved/breaking change: reworked class hierarchy of violin plots

This commit is contained in:
jkriege2 2020-09-21 13:53:33 +02:00
parent 0faa51c9f5
commit a65a713ea6
4 changed files with 268 additions and 226 deletions

View File

@ -99,6 +99,10 @@ digraph
JKQTPBoxplotElementBase [URL="\link JKQTPBoxplotElementBase"]
noteJKQTPBoxplotElementBase [shape="note", color="lightyellow",style=filled,fontsize=8,label="base class for all\ngraphs that represent \na single boxplot"];
JKQTPBoxplotElementBase -> noteJKQTPBoxplotElementBase [style=dashed,arrowhead=none];
JKQTPViolinplotElementBase [URL="\link JKQTPViolinplotElementBase"]
noteJKQTPViolinplotElementBase [shape="note", color="lightyellow",style=filled,fontsize=8,label="base class for all\ngraphs that represent \na single violin plot"];
JKQTPViolinplotElementBase -> noteJKQTPViolinplotElementBase [style=dashed,arrowhead=none];
}
JKQTPPlotElement -> JKQTPGraph
@ -106,6 +110,7 @@ digraph
JKQTPPlotElement -> JKQTPPlotAnnotationElement
JKQTPPlotElement -> JKQTPRangeBase
JKQTPPlotElement -> JKQTPBoxplotElementBase
JKQTPPlotElement -> JKQTPViolinplotElementBase
JKQTPGraph -> JKQTPXYGraph
JKQTPGraph -> JKQTPSingleColumnGraph

View File

@ -33,6 +33,7 @@ Changes, compared to \ref page_whatsnew_V2019_11 "v2019.11" include:
<li>improved/breaking change: reworked class hierarchy of filled line graphs.</li>
<li>improved/breaking change: reworked class hierarchy of range plot elements (JKQTPVerticalRange and JKQTPHorizontalRange).</li>
<li>improved/breaking change: reworked class hierarchy of boxplots.</li>
<li>improved/breaking change: reworked class hierarchy of violin plots.</li>
<li>improved/breaking change: reworked graph Base-Classes (promoted several setters to slots, added Q_PROPERTY- and Q_ENUM-declarations...)</li>
<li>improved/breaking change: made more functions and function parameters const</li>
<li>bugfixed/improved: aspect ratio handling in JKQTPlotter.</li>

View File

@ -35,12 +35,8 @@
JKQTPViolinplotVerticalElement::JKQTPViolinplotVerticalElement(JKQTBasePlotter* parent):
JKQTPGeometricPlotElement(DrawAsGraphicElement, parent)
JKQTPViolinplotElementBase::JKQTPViolinplotElementBase(JKQTBasePlotter* parent):
JKQTPPlotElement(parent)
{
pos=JKQTP_NAN;
median=JKQTP_NAN;
@ -57,6 +53,151 @@ JKQTPViolinplotVerticalElement::JKQTPViolinplotVerticalElement(JKQTBasePlotter*
}
void JKQTPViolinplotElementBase::setPos(double __value)
{
this->pos = __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<int>(__value);
}
int JKQTPViolinplotElementBase::getViolinPositionColumn() const
{
return violinPositionColumn;
}
void JKQTPViolinplotElementBase::setViolinFrequencyColumn(int __value)
{
violinFrequencyColumn=__value;
}
void JKQTPViolinplotElementBase::setViolinFrequencyColumn(size_t __value)
{
violinFrequencyColumn=static_cast<int>(__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())
{
@ -197,146 +338,23 @@ bool JKQTPViolinplotVerticalElement::getYMinMax(double& miny, double& maxy, doub
return true;
}
void JKQTPViolinplotVerticalElement::setPos(double __value)
{
this->pos = __value;
}
double JKQTPViolinplotVerticalElement::getPos() const
{
return this->pos;
}
void JKQTPViolinplotVerticalElement::setMedian(double __value)
{
if (this->median != __value) {
this->median = __value;
drawMedian=true;
}
}
double JKQTPViolinplotVerticalElement::getMedian() const
{
return this->median;
}
void JKQTPViolinplotVerticalElement::setMean(double __value)
{
if (this->mean != __value) {
this->mean = __value;
drawMean=true;
}
}
double JKQTPViolinplotVerticalElement::getMean() const
{
return this->mean;
}
void JKQTPViolinplotVerticalElement::setMin(double __value)
{
if (this->min != __value) {
this->min = __value;
drawMinMax=true;
}
}
double JKQTPViolinplotVerticalElement::getMin() const
{
return this->min;
}
void JKQTPViolinplotVerticalElement::setMax(double __value)
{
if (this->max != __value) {
this->max = __value;
drawMinMax=true;
}
}
double JKQTPViolinplotVerticalElement::getMax() const
{
return this->max;
}
void JKQTPViolinplotVerticalElement::setDrawMean(bool __value)
{
this->drawMean = __value;
}
bool JKQTPViolinplotVerticalElement::getDrawMean() const
{
return this->drawMean;
}
void JKQTPViolinplotVerticalElement::setDrawMedian(bool __value)
{
this->drawMedian = __value;
}
bool JKQTPViolinplotVerticalElement::getDrawMedian() const
{
return this->drawMedian;
}
void JKQTPViolinplotVerticalElement::setDrawMinMax(bool __value)
{
this->drawMinMax = __value;
}
bool JKQTPViolinplotVerticalElement::getDrawMinMax() const
{
return this->drawMinMax;
}
void JKQTPViolinplotVerticalElement::setViolinPositionColumn(int __value)
{
violinPositionColumn=__value;
}
void JKQTPViolinplotVerticalElement::setViolinPositionColumn(size_t __value)
{
violinPositionColumn=static_cast<int>(__value);
}
int JKQTPViolinplotVerticalElement::getViolinPositionColumn() const
{
return violinPositionColumn;
}
void JKQTPViolinplotVerticalElement::setViolinFrequencyColumn(int __value)
{
violinFrequencyColumn=__value;
}
void JKQTPViolinplotVerticalElement::setViolinFrequencyColumn(size_t __value)
{
violinFrequencyColumn=static_cast<int>(__value);
}
int JKQTPViolinplotVerticalElement::getViolinFrequencyColumn() const
{
return violinFrequencyColumn;
}
void JKQTPViolinplotVerticalElement::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) {
plotVerticalKeyMarker(parent, painter, rect);
}
QColor JKQTPViolinplotVerticalElement::getKeyLabelColor() const {
return getLineColor();
}
void JKQTPViolinplotVerticalElement::setColor(QColor c)
JKQTPViolinplotHorizontalElement::JKQTPViolinplotHorizontalElement(JKQTBasePlotter *parent):
JKQTPViolinplotElementBase(parent)
{
setViolinplotColor(c, getParent());
}
JKQTPViolinplotHorizontalElement::JKQTPViolinplotHorizontalElement(JKQTPlotter *parent):
JKQTPViolinplotHorizontalElement(parent->getPlotter())
{
}
void JKQTPViolinplotHorizontalElement::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) {
plotHorizontalKeyMarker(parent, painter, rect);
@ -387,16 +405,6 @@ bool JKQTPViolinplotHorizontalElement::getYMinMax(double& miny, double& maxy, do
}
JKQTPViolinplotHorizontalElement::JKQTPViolinplotHorizontalElement(JKQTBasePlotter *parent):
JKQTPViolinplotVerticalElement(parent)
{
}
JKQTPViolinplotHorizontalElement::JKQTPViolinplotHorizontalElement(JKQTPlotter *parent):
JKQTPViolinplotHorizontalElement(parent->getPlotter())
{
}
void JKQTPViolinplotHorizontalElement::draw(JKQTPEnhancedPainter& painter) {
#ifdef JKQTBP_AUTOTIMER
JKQTPAutoOutputTimer jkaaot("JKQTPViolinplotHorizontalElement::draw");

View File

@ -33,6 +33,109 @@
/** \brief This implements a single vertical <a href="https://en.wikipedia.org/wiki/Violin_plot">Violin Plot</a> as a "geometric element"
* \ingroup jkqtplotter_statgraphs
* \ingroup jkqtplotter_diverse
*
* Represents a violin plot in one of the following styles:
*
* \image html JKQTPGraphViolinplot_SmoothViolin.png
*
* \image html JKQTPGraphViolinplot_StepViolin.png
*
* \image html JKQTPGraphViolinplot_BoxViolin.png
*
* \see JKQTPViolinplotVerticalElement, JKQTPViolinplotHorizontalElement
*
*/
class JKQTPLOTTER_LIB_EXPORT JKQTPViolinplotElementBase: public JKQTPPlotElement, public JKQTPGraphViolinplotStyleMixin {
Q_OBJECT
public:
/** \brief class constructor */
JKQTPViolinplotElementBase(JKQTBasePlotter* parent=nullptr);
/** \brief returns the color to be used for the key label */
virtual QColor getKeyLabelColor() const override;
/** \copydoc pos */
void setPos(double __value);
/** \copydoc pos */
double getPos() const;
/** \copydoc median */
double getMedian() const;
/** \copydoc mean */
double getMean() const;
/** \copydoc min */
double getMin() const;
/** \copydoc max */
double getMax() const;
/** \copydoc drawMean */
bool getDrawMean() const;
/** \copydoc drawMedian */
bool getDrawMedian() const;
/** \copydoc drawMinMax */
bool getDrawMinMax() const;
/** \copydoc violinPositionColumn */
int getViolinPositionColumn() const;
/** \copydoc violinFrequencyColumn */
int getViolinFrequencyColumn() const;
public slots:
/** \brief set the color of the graph (colors all elements, based on the given color \a c ) */
virtual void setColor(QColor c);
/** \copydoc violinFrequencyColumn */
void setViolinFrequencyColumn(int __value);
/** \copydoc violinFrequencyColumn */
void setViolinFrequencyColumn(size_t __value);
/** \copydoc violinPositionColumn */
void setViolinPositionColumn(int __value);
/** \copydoc violinPositionColumn */
void setViolinPositionColumn(size_t __value);
/** \copydoc drawMinMax */
void setDrawMinMax(bool __value);
/** \copydoc drawMedian */
void setDrawMedian(bool __value);
/** \copydoc drawMean */
void setDrawMean(bool __value);
/** \copydoc max */
void setMax(double __value);
/** \copydoc min */
void setMin(double __value);
/** \copydoc mean */
void setMean(double __value);
/** \copydoc median */
void setMedian(double __value);
protected:
/** \brief the position of the boxplot on the "other" axis */
double pos;
/** \brief the median value to be used for the boxplot */
double median;
/** \brief the mean value to be used for the boxplot */
double mean;
/** \brief indicates whether to draw the mean */
bool drawMean;
/** \brief indicates whether to draw the median */
bool drawMedian;
/** \brief indicates whether to draw the percentiles */
bool drawMinMax;
/** \brief the minimum value to be used for the boxplot */
double min;
/** \brief the maximum value to be used for the boxplot */
double max;
/** \brief column with data for the violin outline: category values (along min-max-axis) */
int violinPositionColumn;
/** \brief column with data for the violin outline: frequency values (perpendicular to min-max-axis) */
int violinFrequencyColumn;
};
/*! \brief This implements a single vertical <a href="https://en.wikipedia.org/wiki/Violin_plot">Violin Plot</a> as a "geometric element"
\ingroup jkqtplotter_statgraphs
\ingroup jkqtplotter_diverse
@ -60,7 +163,7 @@
\see \ref JKQTPlotterViolinplotGraphs
*/
class JKQTPLOTTER_LIB_EXPORT JKQTPViolinplotVerticalElement: public JKQTPGeometricPlotElement, public JKQTPGraphViolinplotStyleMixin {
class JKQTPLOTTER_LIB_EXPORT JKQTPViolinplotVerticalElement: public JKQTPViolinplotElementBase {
Q_OBJECT
public:
/** \brief class constructor */
@ -72,10 +175,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPViolinplotVerticalElement: public JKQTPGeometr
virtual void draw(JKQTPEnhancedPainter& painter) override;
/** \brief plots a key marker inside the specified rectangle \a rect */
virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) override;
/** \brief returns the color to be used for the key label */
virtual QColor getKeyLabelColor() const override;
/*! \brief set the color of the graph (colors all elements, based on the given color \a c )*/
virtual void setColor(QColor c);
/** \brief get the maximum and minimum x-value of the graph
@ -90,78 +190,6 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPViolinplotVerticalElement: public JKQTPGeometr
virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override;
/*! \copydoc pos */
void setPos(double __value);
/*! \copydoc pos */
double getPos() const;
/*! \copydoc median */
void setMedian(double __value);
/*! \copydoc median */
double getMedian() const;
/*! \copydoc mean */
void setMean(double __value);
/*! \copydoc mean */
double getMean() const;
/*! \copydoc min */
void setMin(double __value);
/*! \copydoc min */
double getMin() const;
/*! \copydoc max */
void setMax(double __value);
/*! \copydoc max */
double getMax() const;
/*! \copydoc drawMean */
void setDrawMean(bool __value);
/*! \copydoc drawMean */
bool getDrawMean() const;
/*! \copydoc drawMedian */
void setDrawMedian(bool __value);
/*! \copydoc drawMedian */
bool getDrawMedian() const;
/*! \copydoc drawMinMax */
void setDrawMinMax(bool __value);
/*! \copydoc drawMinMax */
bool getDrawMinMax() const;
/*! \copydoc violinPositionColumn */
void setViolinPositionColumn(int __value);
/*! \copydoc violinPositionColumn */
void setViolinPositionColumn(size_t __value);
/*! \copydoc violinPositionColumn */
int getViolinPositionColumn() const;
/*! \copydoc violinFrequencyColumn */
void setViolinFrequencyColumn(int __value);
/*! \copydoc violinFrequencyColumn */
void setViolinFrequencyColumn(size_t __value);
/*! \copydoc violinFrequencyColumn */
int getViolinFrequencyColumn() const;
protected:
/** \brief the position of the boxplot on the "other" axis */
double pos;
/** \brief the median value to be used for the boxplot */
double median;
/** \brief the mean value to be used for the boxplot */
double mean;
/** \brief indicates whether to draw the mean */
bool drawMean;
/** \brief indicates whether to draw the median */
bool drawMedian;
/** \brief indicates whether to draw the percentiles */
bool drawMinMax;
/** \brief the minimum value to be used for the boxplot */
double min;
/** \brief the maximum value to be used for the boxplot */
double max;
/** \brief column with data for the violin outline: category values (along min-max-axis) */
int violinPositionColumn;
/** \brief column with data for the violin outline: frequency values (perpendicular to min-max-axis) */
int violinFrequencyColumn;
};
@ -191,7 +219,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPViolinplotVerticalElement: public JKQTPGeometr
\see \ref JKQTPlotterViolinplotGraphs
*/
class JKQTPLOTTER_LIB_EXPORT JKQTPViolinplotHorizontalElement: public JKQTPViolinplotVerticalElement {
class JKQTPLOTTER_LIB_EXPORT JKQTPViolinplotHorizontalElement: public JKQTPViolinplotElementBase {
Q_OBJECT
public:
/** \brief class constructor */