2019-01-20 23:15:10 +08:00
/*
Copyright ( c ) 2008 - 2019 Jan W . Krieger ( < jan @ jkrieger . de > )
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 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/>.
*/
# include <QString>
# include <QPainter>
# include <QPair>
# include "jkqtplotter/jkqtpgraphsbase.h"
# ifndef jkqtpgraphssinglecolumnsymbols_H_INCLUDED
# define jkqtpgraphssinglecolumnsymbols_H_INCLUDED
/*! \brief plots a 1-column set of data-values with symbols onto a JKQtPlotter/JKQtBasePlotter. the data from the single column
is either interpreted as x - or y - values and the missing coordinate is taken from a fixed value position .
\ ingroup jkqtplotter_linesymbolgraphs
The first coordinate of the data is taken from dataColumn i . e .
- the x - values if dataDirection = = DataDirection : : X
- the y - values if dataDirection = = DataDirection : : Y
.
The second coordinate is :
- if positionScatterStyle = = NoScatter it is simply the value of position , e . g . < br > \ image html JKQTPSingleColumnSymbolsGraph_NoScatter . png
- if positionScatterStyle = = RandomScatter it scatters around position in the range [ position - width / 2 . . . position + width / 2 ] , e . g . < br > \ image html JKQTPSingleColumnSymbolsGraph_RandomScatter . png
- if positionScatterStyle = = BeeSwarmScatter it scatters around position with an algorithm that tries to avoid any overlay of the plot symbols ( SLOW ! ) , e . g . < br > \ image html JKQTPSingleColumnSymbolsGraph_BeeSwarmScatter . png
.
All example images above have dataDirection = = DataDirection : : X !
\ see \ ref JKQTPlotterDistributionPlot
*/
2019-02-03 21:04:48 +08:00
class JKQTP_LIB_EXPORT JKQTPSingleColumnSymbolsGraph : public JKQTPSingleColumnGraph {
2019-01-20 23:15:10 +08:00
Q_OBJECT
public :
/** \brief describes how data from dataColumn of a JKQTPSingleColumnSymbolsGraph positioned at position */
enum ScatterStyle {
NoScatter , /*!< \brief missing coordinate is exactly position for every datapoint in dataColumn \image html JKQTPSingleColumnSymbolsGraph_NoScatter.png */
RandomScatter , /*!< \brief missing coordinate scatters around position (with distribution-width width ) \image html JKQTPSingleColumnSymbolsGraph_RandomScatter.png */
BeeSwarmScatter , /*!< \brief missing coordinate scatters around position and the algorithm tries to prevent overlay of two symbols ("bee swarm plot", see e.g. <a href="https://www.r-statistics.com/2011/03/beeswarm-boxplot-and-plotting-it-with-r/">https://www.r-statistics.com/2011/03/beeswarm-boxplot-and-plotting-it-with-r/</a>). Note that this algorithm can be rather slow!!! \image html JKQTPSingleColumnSymbolsGraph_BeeSwarmScatter.png */
} ;
/** \brief class constructor */
JKQTPSingleColumnSymbolsGraph ( JKQTBasePlotter * parent = nullptr ) ;
JKQTPSingleColumnSymbolsGraph ( JKQTPlotter * parent ) ;
/** \brief get the maximum and minimum x-value of the graph
*
* The result is given in the two parameters which are call - by - reference parameters !
*/
virtual bool getXMinMax ( double & minx , double & maxx , double & smallestGreaterZero ) override ;
/** \brief get the maximum and minimum y-value of the graph
*
* The result is given in the two parameters which are call - by - reference parameters !
*/
virtual bool getYMinMax ( double & miny , double & maxy , double & smallestGreaterZero ) override ;
/** \brief plots the graph to the plotter object specified as parent */
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 ;
2019-01-26 20:00:40 +08:00
/*! \brief sets the property position ( \copybrief position ) to the specified \a __value.
2019-01-25 05:49:10 +08:00
\ details Description of the parameter position is : < BLOCKQUOTE > \ copydoc position < / BLOCKQUOTE >
2019-01-20 23:15:10 +08:00
\ see position for more information */
2019-01-26 20:00:40 +08:00
inline virtual void setPosition ( double __value )
2019-01-20 23:15:10 +08:00
{
this - > position = __value ;
}
2019-01-26 20:00:40 +08:00
/*! \brief returns the property position ( \copybrief position ).
2019-01-25 05:49:10 +08:00
\ details Description of the parameter position is : < BLOCKQUOTE > \ copydoc position < / BLOCKQUOTE >
2019-01-20 23:15:10 +08:00
\ see position for more information */
2019-01-26 20:00:40 +08:00
inline virtual double getPosition ( ) const
2019-01-20 23:15:10 +08:00
{
return this - > position ;
}
2019-01-26 20:00:40 +08:00
/*! \brief sets the property width ( \copybrief width ) to the specified \a __value.
2019-01-25 05:49:10 +08:00
\ details Description of the parameter width is : < BLOCKQUOTE > \ copydoc width < / BLOCKQUOTE >
2019-01-20 23:15:10 +08:00
\ see width for more information */
2019-01-26 20:00:40 +08:00
inline virtual void setWidth ( double __value )
2019-01-20 23:15:10 +08:00
{
this - > width = __value ;
}
2019-01-26 20:00:40 +08:00
/*! \brief returns the property width ( \copybrief width ).
2019-01-25 05:49:10 +08:00
\ details Description of the parameter width is : < BLOCKQUOTE > \ copydoc width < / BLOCKQUOTE >
2019-01-20 23:15:10 +08:00
\ see width for more information */
2019-01-26 20:00:40 +08:00
inline virtual double getWidth ( ) const
2019-01-20 23:15:10 +08:00
{
return this - > width ;
}
2019-01-26 20:00:40 +08:00
/*! \brief sets the property dataDirection ( \copybrief dataDirection ) to the specified \a __value.
2019-01-25 05:49:10 +08:00
\ details Description of the parameter dataDirection is : < BLOCKQUOTE > \ copydoc dataDirection < / BLOCKQUOTE >
2019-01-20 23:15:10 +08:00
\ see dataDirection for more information */
2019-01-26 20:00:40 +08:00
inline virtual void setDataDirection ( DataDirection __value )
2019-01-20 23:15:10 +08:00
{
this - > dataDirection = __value ;
}
2019-01-26 20:00:40 +08:00
/*! \brief returns the property dataDirection ( \copybrief dataDirection ).
2019-01-25 05:49:10 +08:00
\ details Description of the parameter dataDirection is : < BLOCKQUOTE > \ copydoc dataDirection < / BLOCKQUOTE >
2019-01-20 23:15:10 +08:00
\ see dataDirection for more information */
2019-01-26 20:00:40 +08:00
inline virtual DataDirection getDataDirection ( ) const
2019-01-20 23:15:10 +08:00
{
return this - > dataDirection ;
}
2019-01-26 20:00:40 +08:00
/*! \brief sets the property positionScatterStyle ( \copybrief positionScatterStyle ) to the specified \a __value.
2019-01-25 05:49:10 +08:00
\ details Description of the parameter positionScatterStyle is : < BLOCKQUOTE > \ copydoc positionScatterStyle < / BLOCKQUOTE >
2019-01-20 23:15:10 +08:00
\ see positionScatterStyle for more information */
2019-01-26 20:00:40 +08:00
inline virtual void setPositionScatterStyle ( ScatterStyle __value )
2019-01-20 23:15:10 +08:00
{
this - > positionScatterStyle = __value ;
}
2019-01-26 20:00:40 +08:00
/*! \brief returns the property positionScatterStyle ( \copybrief positionScatterStyle ).
2019-01-25 05:49:10 +08:00
\ details Description of the parameter positionScatterStyle is : < BLOCKQUOTE > \ copydoc positionScatterStyle < / BLOCKQUOTE >
2019-01-20 23:15:10 +08:00
\ see positionScatterStyle for more information */
2019-01-26 20:00:40 +08:00
inline virtual ScatterStyle getPositionScatterStyle ( ) const
2019-01-20 23:15:10 +08:00
{
return this - > positionScatterStyle ;
}
2019-01-26 20:00:40 +08:00
/*! \brief sets the property fillColor ( \copybrief fillColor ) to the specified \a __value.
2019-01-25 05:49:10 +08:00
\ details Description of the parameter fillColor is : < BLOCKQUOTE > \ copydoc fillColor < / BLOCKQUOTE >
2019-01-20 23:15:10 +08:00
\ see fillColor for more information */
2019-01-26 20:00:40 +08:00
inline virtual void setFillColor ( const QColor & __value )
2019-01-20 23:15:10 +08:00
{
this - > fillColor = __value ;
}
2019-01-26 20:00:40 +08:00
/*! \brief returns the property fillColor ( \copybrief fillColor ).
2019-01-25 05:49:10 +08:00
\ details Description of the parameter fillColor is : < BLOCKQUOTE > \ copydoc fillColor < / BLOCKQUOTE >
2019-01-20 23:15:10 +08:00
\ see fillColor for more information */
2019-01-26 20:00:40 +08:00
inline virtual QColor getFillColor ( ) const
2019-01-20 23:15:10 +08:00
{
return this - > fillColor ;
}
2019-01-26 20:00:40 +08:00
/*! \brief sets the property symbol ( \copybrief symbol ) to the specified \a __value.
2019-01-25 05:49:10 +08:00
\ details Description of the parameter symbol is : < BLOCKQUOTE > \ copydoc symbol < / BLOCKQUOTE >
2019-01-20 23:15:10 +08:00
\ see symbol for more information */
2019-01-26 20:00:40 +08:00
inline virtual void setSymbol ( const JKQTPGraphSymbols & __value )
2019-01-20 23:15:10 +08:00
{
this - > symbol = __value ;
}
2019-01-26 20:00:40 +08:00
/*! \brief returns the property symbol ( \copybrief symbol ).
2019-01-25 05:49:10 +08:00
\ details Description of the parameter symbol is : < BLOCKQUOTE > \ copydoc symbol < / BLOCKQUOTE >
2019-01-20 23:15:10 +08:00
\ see symbol for more information */
2019-01-26 20:00:40 +08:00
inline virtual JKQTPGraphSymbols getSymbol ( ) const
2019-01-20 23:15:10 +08:00
{
return this - > symbol ;
}
2019-01-26 20:00:40 +08:00
/*! \brief sets the property symbolWidth ( \copybrief symbolWidth ) to the specified \a __value.
2019-01-25 05:49:10 +08:00
\ details Description of the parameter symbolWidth is : < BLOCKQUOTE > \ copydoc symbolWidth < / BLOCKQUOTE >
2019-01-20 23:15:10 +08:00
\ see symbolWidth for more information */
2019-01-26 20:00:40 +08:00
inline virtual void setSymbolWidth ( double __value )
2019-01-20 23:15:10 +08:00
{
this - > symbolWidth = __value ;
}
2019-01-26 20:00:40 +08:00
/*! \brief returns the property symbolWidth ( \copybrief symbolWidth ).
2019-01-25 05:49:10 +08:00
\ details Description of the parameter symbolWidth is : < BLOCKQUOTE > \ copydoc symbolWidth < / BLOCKQUOTE >
2019-01-20 23:15:10 +08:00
\ see symbolWidth for more information */
2019-01-26 20:00:40 +08:00
inline virtual double getSymbolWidth ( ) const
2019-01-20 23:15:10 +08:00
{
return this - > symbolWidth ;
}
2019-01-26 20:00:40 +08:00
/*! \brief sets the property symbolSize ( \copybrief symbolSize ) to the specified \a __value.
2019-01-25 05:49:10 +08:00
\ details Description of the parameter symbolSize is : < BLOCKQUOTE > \ copydoc symbolSize < / BLOCKQUOTE >
2019-01-20 23:15:10 +08:00
\ see symbolSize for more information */
2019-01-26 20:00:40 +08:00
inline virtual void setSymbolSize ( double __value )
2019-01-20 23:15:10 +08:00
{
this - > symbolSize = __value ;
}
2019-01-26 20:00:40 +08:00
/*! \brief returns the property symbolSize ( \copybrief symbolSize ).
2019-01-25 05:49:10 +08:00
\ details Description of the parameter symbolSize is : < BLOCKQUOTE > \ copydoc symbolSize < / BLOCKQUOTE >
2019-01-20 23:15:10 +08:00
\ see symbolSize for more information */
2019-01-26 20:00:40 +08:00
inline virtual double getSymbolSize ( ) const
2019-01-20 23:15:10 +08:00
{
return this - > symbolSize ;
}
2019-01-26 19:35:57 +08:00
/** \copydoc seedValue */
inline void setSeedValue ( unsigned int val ) {
seedValue = val ;
}
/** \copydoc seedValue */
inline unsigned int getSeedValue ( ) const {
return seedValue ;
}
2019-01-20 23:15:10 +08:00
protected :
/** \brief interpret the data from dataColumn either as X- or Y-data */
DataDirection dataDirection ;
/** \brief missing coordinate, i.e. if the data from \a dataColumn is interpreted as x-values, this is the y-position and vice versa (see DataDirection ) */
double position ;
/** \brief width of data distribution around position for the missing coordinate (see positionScatterStyle and position) */
double width ;
/** \brief how to distribute the datapoints from dataColumn at the location position */
ScatterStyle positionScatterStyle ;
/** \brief color of the graph fill */
QColor fillColor ;
/** \brief which symbol to use for the datapoints */
JKQTPGraphSymbols symbol ;
/** \brief size (diameter in pt) of the symbol for the data points */
double symbolSize ;
/** \brief width (in pt) of the lines used to plot the symbol for the data points */
double symbolWidth ;
2019-01-26 19:35:57 +08:00
/** \brief seed value for the pseudo-random number generator used for drawing.
*
* This seed is used instead of e . g . the system time to ensure that replotting results in the
* same plot every time . ou can set the seed using setSeedvalue ( ) ) */
unsigned int seedValue ;
2019-01-20 23:15:10 +08:00
QPen getSymbolPen ( JKQTPEnhancedPainter & painter ) const ;
QBrush getBrush ( JKQTPEnhancedPainter & painter ) const ;
} ;
# endif // jkqtpgraphssinglecolumnsymbols_H_INCLUDED