2019-06-17 01:15:40 +08:00
/*
2020-08-26 18:58:23 +08:00
Copyright ( c ) 2008 - 2020 Jan W . Krieger ( < jan @ jkrieger . de > )
2019-06-17 01:15:40 +08:00
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 < http : //www.gnu.org/licenses/>.
*/
2022-04-25 04:07:39 +08:00
# ifndef jkqtpgraphsviolinplotstylingmixins_H
# define jkqtpgraphsviolinplotstylingmixins_H
2019-06-17 01:15:40 +08:00
# include <QString>
# include <QPainter>
# include "jkqtplotter/jkqtptools.h"
2019-06-22 20:21:32 +08:00
# include "jkqtplotter/jkqtplotter_imexport.h"
2022-07-19 16:24:52 +08:00
# include "jkqtplotter/jkqtplotter_configmacros.h"
2019-06-17 01:15:40 +08:00
# include "jkqtplotter/jkqtpgraphsbase.h"
# include "jkqtplotter/jkqtpgraphsbasestylingmixins.h"
/*! \brief Styling Mix-In for Violinplots
\ ingroup jkqtplotter_basegraphs_stylemixins
\ image html JKQTPViolinplotHorizontalElement_elements . png
*/
2019-06-22 20:21:32 +08:00
class JKQTPLOTTER_LIB_EXPORT JKQTPGraphViolinplotStyleMixin : public JKQTPGraphLineStyleMixin , public JKQTPGraphFillStyleMixin {
2022-07-19 16:24:52 +08:00
# ifndef JKQTPLOTTER_WORKAROUND_QGADET_BUG
Q_GADGET
# endif
2019-06-17 01:15:40 +08:00
public :
/** \brief class constructor */
JKQTPGraphViolinplotStyleMixin ( ) ;
void initViolinplotStyle ( JKQTBasePlotter * parent , int & parentPlotStyle ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc violinWidthAbsolute */
2019-06-17 01:15:40 +08:00
void setViolinWidthAbsolute ( double __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc violinWidthAbsolute */
2019-06-17 01:15:40 +08:00
double getViolinWidthAbsolute ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc relativeWhiskerWidth */
2019-06-17 01:15:40 +08:00
void setRelativeWhiskerWidth ( double __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc relativeWhiskerWidth */
2019-06-17 01:15:40 +08:00
double getRelativeWhiskerWidth ( ) const ;
2020-09-21 19:47:54 +08:00
/** \brief set the line style of whisker lines */
2019-06-17 01:15:40 +08:00
void setWhiskerLineStyle ( Qt : : PenStyle __value ) ;
2020-09-21 19:47:54 +08:00
/** \brief get the line style of whisker lines */
2019-06-17 01:15:40 +08:00
Qt : : PenStyle getWhiskerLineStyle ( ) const ;
2020-09-21 19:47:54 +08:00
/** \brief set the width [pt] of whisker lines */
2019-06-17 01:15:40 +08:00
void setWhiskerLineWidth ( double __value ) ;
2020-09-21 19:47:54 +08:00
/** \brief get the width [pt] of whisker lines */
2019-06-17 01:15:40 +08:00
double getWhiskerLineWidth ( ) const ;
2020-09-21 19:47:54 +08:00
/** \brief set the color of whisker lines */
2019-06-17 01:15:40 +08:00
void setWhiskerLineColor ( QColor __value ) ;
2020-09-21 19:47:54 +08:00
/** \brief get the color of whisker lines */
2019-06-17 01:15:40 +08:00
QColor getWhiskerLineColor ( ) const ;
/** \brief sets the dash offset for a custom dash style of whisker lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setDashOffset
*/
void setWhiskerLineDashOffset ( qreal offset ) ;
/** \brief returns the dash offset for a custom dash style of whisker lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setDashOffset
*/
qreal getWhiskerLineDashOffset ( ) const ;
/** \brief sets the dash pattern for a custom dash style of whisker lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setDashPattern
*/
void setWhiskerLineDashPattern ( const QVector < qreal > & pattern ) ;
/** \brief gets the dash pattern for a custom dash style of whisker lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setDashPattern
*/
QVector < qreal > getWhiskerLineDashPattern ( ) const ;
/** \brief sets the join style of whisker lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setJoinStyle
*/
void setWhiskerLineJoinStyle ( Qt : : PenJoinStyle style ) ;
/** \brief returns the join style of whisker lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setJoinStyle
*/
Qt : : PenJoinStyle getWhiskerLineJoinStyle ( ) const ;
/** \brief sets the cap style of whisker lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setCapStyle
*/
void setWhiskerLineCapStyle ( Qt : : PenCapStyle style ) ;
/** \brief gets the cap style of whisker lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setCapStyle
*/
Qt : : PenCapStyle getWhiskerLineCapStyle ( ) const ;
/** \brief sets the brush used to fill the line area of whisker lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setBrush
*/
void setWhiskerLineBrush ( const QBrush & style ) ;
/** \brief gets the brush used to fill the line area of whisker lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setBrush
*/
QBrush getWhiskerLineBrush ( ) const ;
/** \brief build a pen to be used for drawing whiskers */
QPen getWhiskerPen ( JKQTPEnhancedPainter & painter , JKQTBasePlotter * parent ) const ;
2020-09-21 19:47:54 +08:00
/** \brief set the line style of whisker cap lines */
2019-06-17 01:15:40 +08:00
void setWhiskerCapLineStyle ( Qt : : PenStyle __value ) ;
2020-09-21 19:47:54 +08:00
/** \brief get the line style of whisker cap lines */
2019-06-17 01:15:40 +08:00
Qt : : PenStyle getWhiskerCapLineStyle ( ) const ;
2020-09-21 19:47:54 +08:00
/** \brief set the width [pt] of whisker cap lines */
2019-06-17 01:15:40 +08:00
void setWhiskerCapLineWidth ( double __value ) ;
2020-09-21 19:47:54 +08:00
/** \brief get the width [pt] of whisker cap lines */
2019-06-17 01:15:40 +08:00
double getWhiskerCapLineWidth ( ) const ;
2020-09-21 19:47:54 +08:00
/** \brief set the color of whisker cap lines */
2019-06-17 01:15:40 +08:00
void setWhiskerCapLineColor ( QColor __value ) ;
2020-09-21 19:47:54 +08:00
/** \brief get the color of whisker cap lines */
2019-06-17 01:15:40 +08:00
QColor getWhiskerCapLineColor ( ) const ;
/** \brief sets the dash offset for a custom dash style of whisker cap lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setDashOffset
*/
void setWhiskerCapLineDashOffset ( qreal offset ) ;
/** \brief returns the dash offset for a custom dash style of whisker cap lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setDashOffset
*/
qreal getWhiskerCapLineDashOffset ( ) const ;
/** \brief sets the dash pattern for a custom dash style of whisker cap lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setDashPattern
*/
void setWhiskerCapLineDashPattern ( const QVector < qreal > & pattern ) ;
/** \brief gets the dash pattern for a custom dash style of whisker cap lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setDashPattern
*/
QVector < qreal > getWhiskerCapLineDashPattern ( ) const ;
/** \brief sets the join style of whisker cap lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setJoinStyle
*/
void setWhiskerCapLineJoinStyle ( Qt : : PenJoinStyle style ) ;
/** \brief returns the join style of whisker cap lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setJoinStyle
*/
Qt : : PenJoinStyle getWhiskerCapLineJoinStyle ( ) const ;
/** \brief sets the cap style of whisker cap lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setCapStyle
*/
void setWhiskerCapLineCapStyle ( Qt : : PenCapStyle style ) ;
/** \brief gets the cap style of whisker cap lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setCapStyle
*/
Qt : : PenCapStyle getWhiskerCapLineCapStyle ( ) const ;
/** \brief sets the brush used to fill the line area of whisker cap lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setBrush
*/
void setWhiskerCapLineBrush ( const QBrush & style ) ;
/** \brief gets the brush used to fill the line area of whisker cap lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setBrush
*/
QBrush getWhiskerCapLineBrush ( ) const ;
/** \brief build a pen to be used for drawing whisker caps */
QPen getWhiskerCapPen ( JKQTPEnhancedPainter & painter , JKQTBasePlotter * parent ) const ;
2020-09-21 19:47:54 +08:00
/** \brief set the line style of median lines */
2019-06-17 01:15:40 +08:00
void setMedianLineStyle ( Qt : : PenStyle __value ) ;
2020-09-21 19:47:54 +08:00
/** \brief get the line style of median lines */
2019-06-17 01:15:40 +08:00
Qt : : PenStyle getMedianLineStyle ( ) const ;
2020-09-21 19:47:54 +08:00
/** \brief set the width [pt] of median lines */
2019-06-17 01:15:40 +08:00
void setMedianLineWidth ( double __value ) ;
2020-09-21 19:47:54 +08:00
/** \brief get the width [pt] of median lines */
2019-06-17 01:15:40 +08:00
double getMedianLineWidth ( ) const ;
2020-09-21 19:47:54 +08:00
/** \brief set the color of median lines */
2019-06-17 01:15:40 +08:00
void setMedianLineColor ( QColor __value ) ;
2020-09-21 19:47:54 +08:00
/** \brief get the color of median lines */
2019-06-17 01:15:40 +08:00
QColor getMedianLineColor ( ) const ;
/** \brief sets the dash offset for a custom dash style of median lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setDashOffset
*/
void setMedianLineDashOffset ( qreal offset ) ;
/** \brief returns the dash offset for a custom dash style of median lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setDashOffset
*/
qreal getMedianLineDashOffset ( ) const ;
/** \brief sets the dash pattern for a custom dash style of median lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setDashPattern
*/
void setMedianLineDashPattern ( const QVector < qreal > & pattern ) ;
/** \brief gets the dash pattern for a custom dash style of median lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setDashPattern
*/
QVector < qreal > getMedianLineDashPattern ( ) const ;
/** \brief sets the join style of median lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setJoinStyle
*/
void setMedianLineJoinStyle ( Qt : : PenJoinStyle style ) ;
/** \brief returns the join style of median lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setJoinStyle
*/
Qt : : PenJoinStyle getMedianLineJoinStyle ( ) const ;
/** \brief sets the cap style of median lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setCapStyle
*/
void setMedianLineCapStyle ( Qt : : PenCapStyle style ) ;
/** \brief gets the cap style of median lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setCapStyle
*/
Qt : : PenCapStyle getMedianLineCapStyle ( ) const ;
/** \brief sets the brush used to fill the line area of median lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setBrush
*/
void setMedianLineBrush ( const QBrush & style ) ;
/** \brief gets the brush used to fill the line area of median lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setBrush
*/
QBrush getMedianLineBrush ( ) const ;
/** \brief build a pen to be used for drawing medians */
QPen getMedianPen ( JKQTPEnhancedPainter & painter , JKQTBasePlotter * parent ) const ;
2020-09-21 19:47:54 +08:00
/** \brief set the line style of Mean lines */
2019-06-17 01:15:40 +08:00
void setMeanLineStyle ( Qt : : PenStyle __value ) ;
2020-09-21 19:47:54 +08:00
/** \brief get the line style of Mean lines */
2019-06-17 01:15:40 +08:00
Qt : : PenStyle getMeanLineStyle ( ) const ;
/** \brief sets the dash offset for a custom dash style of Mean lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setDashOffset
*/
void setMeanLineDashOffset ( qreal offset ) ;
/** \brief returns the dash offset for a custom dash style of Mean lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setDashOffset
*/
qreal getMeanLineDashOffset ( ) const ;
/** \brief sets the dash pattern for a custom dash style of Mean lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setDashPattern
*/
void setMeanLineDashPattern ( const QVector < qreal > & pattern ) ;
/** \brief gets the dash pattern for a custom dash style of Mean lines
* \ see https : //doc.qt.io/qt-5/qpen.html#setDashPattern
*/
QVector < qreal > getMeanLineDashPattern ( ) const ;
/** \brief set the type of the symbol for the mean */
void setMeanSymbolType ( JKQTPGraphSymbols __value ) ;
/** \brief get the type of the symbol for the mean */
JKQTPGraphSymbols getMeanSymbolType ( ) const ;
/** \brief set the size (=diameter in pt) of the symbol for the mean (in pt) */
void setMeanSize ( double __value ) ;
/** \brief get the size (=diameter in pt) of the symbol for the mean (in pt) */
double getMeanSize ( ) const ;
/** \brief set the color of the symbol for the mean, or mean line */
void setMeanColor ( const QColor & __value ) ;
/** \brief set the color of the symbol for the mean, or mean line */
QColor getMeanColor ( ) const ;
/** \brief set the color of filling of the symbol for the mean */
void setMeanFillColor ( const QColor & __value ) ;
/** \brief set the color of filling of the symbol for the mean */
QColor getMeanFillColor ( ) const ;
/** \brief set the line width of the symbol for the mean outline, or mean line (in pt) */
void setMeanLineWidth ( double __value ) ;
/** \brief get the line width of the symbol for the mean outline, or mean line (in pt) */
double getMeanLineWidth ( ) const ;
/** \brief defines how to draw the violin graph */
enum ViolinStyle {
SmoothViolin , /*!< \brief connect all violin points by lines, resulting in a (nearly) smooth curve \image html JKQTPGraphViolinplot_SmoothViolin.png */
StepViolin , /*!< \brief connect violin points by a steped line, but fully filled \image html JKQTPGraphViolinplot_StepViolin.png */
BoxViolin , /*!< \brief violin datapoints are drawn like a boxplot \image html JKQTPGraphViolinplot_BoxViolin.png */
} ;
/** \brief returns the style of the violin plot */
ViolinStyle getViolinStyle ( ) const ;
/** \brief set the style of the violin plot */
void setViolinStyle ( ViolinStyle style ) ;
/** \brief defines where to draw the violin graph with respect to the violin center position */
enum ViolinPositionMode {
ViolinLeft , /*!< \brief draw violin on the left hand side only (for vertical violins) \image html JKQTPGraphViolinplot_ViolinLeft.png */
ViolinBottom = ViolinLeft , /*!< \brief draw violin on the bottom side only (for horizontal violins) \image html JKQTPGraphViolinplot_ViolinBottom.png */
ViolinRight , /*!< \brief draw violin on the right hand side only (for vertical violins) \image html JKQTPGraphViolinplot_ViolinRight.png */
ViolinTop = ViolinRight , /*!< \brief draw violin on the top side only (for horizontal violins) \image html JKQTPGraphViolinplot_ViolinTop.png */
ViolinBoth /*!< \brief draw violin on the left+right or top+bottom side \image html JKQTPGraphViolinplot_ViolinBoth.png \image html JKQTPGraphViolinplot_ViolinHBoth.png */
} ;
/** \brief returns the position mode of the violin plot */
ViolinPositionMode getViolinPositionMode ( ) const ;
/** \brief set the position mode of the violin plot */
void setViolinPositionMode ( ViolinPositionMode positionMode ) ;
/** \brief constructs a QPen from the line styling properties to draw the mean line */
QPen getMeanLinePen ( JKQTPEnhancedPainter & painter , JKQTBasePlotter * parent ) const ;
/** \brief constructs a QPen from the line styling properties to draw the mean symbol */
QPen getMeanSymbolPen ( JKQTPEnhancedPainter & painter , JKQTBasePlotter * parent ) const ;
/** \brief constructs a QPen from the line styling properties */
QBrush getMeanSymbolBrush ( JKQTPEnhancedPainter & painter , JKQTBasePlotter * parent ) const ;
2020-09-21 19:47:54 +08:00
/** \brief set the color of the graph (colors all elements, based on the given color \a c ) */
2019-06-17 01:15:40 +08:00
void setViolinplotColor ( QColor c , JKQTBasePlotter * parent ) ;
2020-09-21 19:47:54 +08:00
/** \brief set the color of the graph (colors all elements, based on the given color \a c , sets background colors from \a bc ) */
2019-06-17 01:15:40 +08:00
void setViolinplotColor ( QColor c , QColor bc , JKQTBasePlotter * parent ) ;
protected :
/*! \brief plot a symbol at location x,y (in painter coordinates), using the current style
\ param parent parent JKQTBasePlotter of the graph that uses this mix - in ( used e . g . for line - width transformation )
\ param painter the < a href = " http://doc.qt.io/qt-5/qpainter.html " > QPainter < / a > to draw to
\ param x x - coordinate of the symbol center
\ param y y - coordinate of the symbol center
*/
void plotStyledMeanSymbol ( JKQTBasePlotter * parent , JKQTPEnhancedPainter & painter , double x , double y ) const ;
/** \brief draws a vertical boxplot, with all coordinates/sizes given in coordinates of the given painter,
* using the style properties declared in this class . Provide a parameter with \ c JKQTP_NAN of you
* don ' t want it to be drawn , or don ' t know its value
*
* \ param parent parent JKQTBasePlotter of the graph that uses this mix - in ( used e . g . for line - width transformation )
* \ param painter the < a href = " http://doc.qt.io/qt-5/qpainter.html " > QPainter < / a > to draw to
* \ param xp x - coordinate of the boxplot center
* \ param xpleft x - coordinate of the boxplot box left edge
* \ param xpright x - coordinate of the boxplot box right edge
* \ param violin_cat category - dataset for the violin ( y - values of KDE / histogram / . . . )
* \ param violin_freq frequency / count - dataset for the violin ( y - values / frequencies of KDE / histogram / . . . )
* \ param minp y - coordinate of the minimum ( lower whisker )
* \ param medianp y - coordinate the median
* \ param maxp y - coordinate of the maximum ( upper whisker )
* \ param meanp y - coordinate of the mean ( symbol or line )
*/
void plotVerticalViolinplot ( JKQTBasePlotter * parent , JKQTPEnhancedPainter & painter , double xp , double xpleft , double xpright , const QVector < double > & violin_cat , const QVector < double > & violin_freq , double minp , double medianp , double maxp , double meanp = JKQTP_NAN ) const ;
/** \brief draws a horizontal boxplot, with all coordinates/sizes given in coordinates of the given painter,
* using the style properties declared in this class . Provide a parameter with \ c JKQTP_NAN of you
* don ' t want it to be drawn , or don ' t know its value
*
* \ param parent parent JKQTBasePlotter of the graph that uses this mix - in ( used e . g . for line - width transformation )
* \ param painter the < a href = " http://doc.qt.io/qt-5/qpainter.html " > QPainter < / a > to draw to
* \ param yp y - coordinate of the boxplot center
* \ param ypbottom y - coordinate of the boxplot box bottom edge
* \ param yptop y - coordinate of the boxplot box top edge
* \ param violin_cat category - dataset for the violin ( x - values of KDE / histogram / . . . )
* \ param violin_freq frequency / count - dataset for the violin ( y - values / frequencies of KDE / histogram / . . . )
* \ param minp x - coordinate of the minimum ( lower whisker )
* \ param medianp x - coordinate the median
* \ param maxp x - coordinate of the maximum ( upper whisker )
* \ param meanp x - coordinate of the mean ( symbol or line )
*/
void plotHorizontalViolinplot ( JKQTBasePlotter * parent , JKQTPEnhancedPainter & painter , double yp , double ypbottom , double yptop , const QVector < double > & violin_cat , const QVector < double > & violin_freq , double minp , double medianp , double maxp , double meanp = JKQTP_NAN ) const ;
/** \brief draw a small, stylized, vertical symbol into \a rect that symbolizes a boxplot, e.g. in a plot legend */
2020-09-19 04:03:12 +08:00
void plotVerticalKeyMarker ( JKQTBasePlotter * parent , JKQTPEnhancedPainter & painter , const QRectF & rect ) const ;
2019-06-17 01:15:40 +08:00
/** \brief draw a small, stylized, horizontal symbol into \a rect that symbolizes a boxplot, e.g. in a plot legend */
2020-09-19 04:03:12 +08:00
void plotHorizontalKeyMarker ( JKQTBasePlotter * parent , JKQTPEnhancedPainter & painter , const QRectF & rect ) const ;
2019-06-17 01:15:40 +08:00
private :
/** \brief which symbol to use for the datapoints */
JKQTPGraphSymbols m_meanSymbolType ;
/** \brief size (diameter in pt) of the symbol for the data points, given in pt */
double m_meanSymbolSize ;
/** \brief outline color of the symbol or line pen of the mean-line */
QPen m_meanSymbolLinePen ;
/** \brief color of the symbol filling */
QColor m_meanSymbolFillColor ;
/** \brief width (in pt) of the lines used to plot the symbol for the data points, given in pt */
double m_meanSymbolLineWidth ;
/** \brief line style of the whisker lines */
QPen m_whiskerLinePen ;
/** \brief line width (in pt) of the whisker lines */
double whiskerLineWidth ;
/** \brief line style of the whisker cap lines */
QPen m_whiskerCapLinePen ;
/** \brief line width (in pt) of the whisker cap lines */
double whiskerCapLineWidth ;
/** \brief line style of the median lines */
QPen m_medianLinePen ;
/** \brief line width (in pt) of the median lines */
double medianLineWidth ;
/** \brief width of box in pt.
*
* \ note If several boxplots are drawn , the width is typically calculated ,
* based on a relative width and the position distances , see JKQTPBoxplotVerticalGraph : : boxWidthRelative */
double violinWidthAbsolute ;
/** \brief width of the whiskers, relative to the box width (default: 0.5) */
double relativeWhiskerWidth ;
/** \brief the style of the violin plot */
ViolinStyle m_violinStyle ;
/** \brief the position mode of the violin plot */
ViolinPositionMode m_violinPositionMode ;
} ;
# endif // jkqtpgraphsviolinplotstylingmixins_H