2019-01-10 04:23:24 +08:00
/*
2020-08-26 18:58:23 +08:00
Copyright ( c ) 2008 - 2020 Jan W . Krieger ( < jan @ jkrieger . de > )
2019-01-10 04:23:24 +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
2019-02-08 00:24:46 +08:00
the Free Software Foundation , either version 2.1 of the License , or
2019-01-10 04:23:24 +08:00
( 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>
2019-06-20 22:06:31 +08:00
# include "jkqtplotter/graphs/jkqtpscatter.h"
2019-04-22 19:27:50 +08:00
# include "jkqtplotter/jkqtpgraphsbasestylingmixins.h"
2019-06-22 20:21:32 +08:00
# include "jkqtplotter/jkqtplotter_imexport.h"
2020-09-05 18:44:02 +08:00
# include "jkqtcommon/jkqtpgeometrytools.h"
2020-09-05 19:14:46 +08:00
# include "jkqtplotter/graphs/jkqtpevaluatedfunctionbase.h"
2019-01-10 04:23:24 +08:00
# include <functional>
# ifndef jkqtpgraphsevaluatedfunction_H
# define jkqtpgraphsevaluatedfunction_H
2020-09-08 02:57:25 +08:00
/** \brief This class extends JKQTPEvaluatedFunctionWithErrorsGraphBase with functions to draw the graphs and
* set the drawing style
* \ ingroup jkqtplotter_functiongraphs
*
* \ note Since this class is meant as a base for both f ( x ) - and f ( y ) - functions , it cannot
* implememt JKQTPGraph : : draw ( ) . Therefore it provides two implementations drawXGraph ( )
* and drawYGraph ( ) and the user has to decide in the concrete graph class , which one to call
* ( or whether to do the drawing completely different ) .
*
* \ see e . g . JKQTPXFunctionLineGraph for a concrete implementation
*/
class JKQTPLOTTER_LIB_EXPORT JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase : public JKQTPEvaluatedFunctionWithErrorsGraphBase , public JKQTPGraphLineStyleMixin , public JKQTPGraphFillStyleMixin {
Q_OBJECT
public :
/** \brief class constructor */
JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase ( JKQTBasePlotter * parent = nullptr ) ;
/** \brief class constructor */
JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase ( JKQTPlotter * parent ) ;
/** \brief class destructor */
virtual ~ JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase ( ) 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 ;
/*! \copydoc drawLine */
bool getDrawLine ( ) const ;
/*! \copydoc drawErrorPolygons */
bool getDrawErrorPolygons ( ) const ;
/*! \copydoc drawErrorLines */
bool getDrawErrorLines ( ) const ;
/*! \copydoc errorColor */
virtual QColor getErrorLineColor ( ) const ;
/*! \copydoc errorFillColor */
virtual QColor getErrorFillColor ( ) const ;
/*! \copydoc errorFillStyle */
virtual Qt : : BrushStyle getErrorFillStyle ( ) const ;
/*! \copydoc errorStyle */
virtual Qt : : PenStyle getErrorLineStyle ( ) const ;
/*! \copydoc errorLineWidth */
virtual double getErrorLineWidth ( ) const ;
public slots :
/*! \brief set color, fill color and error color at the same time */
void setColor ( QColor c ) ;
/*! \copydoc drawLine */
void setDrawLine ( bool __value ) ;
/*! \copydoc drawErrorPolygons */
void setDrawErrorPolygons ( bool __value ) ;
/*! \copydoc drawErrorLines */
void setDrawErrorLines ( bool __value ) ;
/*! \copydoc errorColor */
virtual void setErrorLineColor ( const QColor & __value ) ;
/*! \copydoc errorFillColor */
virtual void setErrorFillColor ( const QColor & __value ) ;
/*! \copydoc errorFillStyle */
virtual void setErrorFillStyle ( Qt : : BrushStyle __value ) ;
/*! \copydoc errorStyle */
virtual void setErrorLineStyle ( Qt : : PenStyle __value ) ;
/*! \copydoc errorLineWidth */
virtual void setErrorLineWidth ( double __value ) ;
protected :
/** \brief plots the graph to the plotter object specified as parent */
void drawXGraph ( JKQTPEnhancedPainter & painter ) ;
/** \brief plots the graph to the plotter object specified as parent */
void drawYGraph ( JKQTPEnhancedPainter & painter ) ;
/** \brief indicates whether to draw a line or not */
bool drawLine ;
/** \brief indicates whether to fill the space between the curve and the x-axis */
bool fillCurve ;
/** \brief indicates whether an error polygon should be drawn */
bool drawErrorPolygons ;
/** \brief indicates whether error lines should be drawn */
bool drawErrorLines ;
/** \brief color of the error graph */
QColor errorColor ;
/** \brief color of the error graph fill */
QColor errorFillColor ;
/** \brief linestyle of the error graph lines */
Qt : : PenStyle errorStyle ;
/** \brief width (pixels) of the error graph */
double errorLineWidth ;
/** \brief fill style, if the error curve should be filled */
Qt : : BrushStyle errorFillStyle ;
QBrush getErrorBrush ( JKQTPEnhancedPainter & painter ) const ;
QPen getErrorLinePen ( JKQTPEnhancedPainter & painter ) const ;
} ;
2019-01-10 04:23:24 +08:00
2020-09-05 05:41:23 +08:00
/*! \brief type of functions that may be plotted by JKQTPXFunctionLineGraph and JKQTPYFunctionLineGraph
2019-01-19 16:40:52 +08:00
\ ingroup jkqtplotter_functiongraphs
2019-01-10 04:23:24 +08:00
2019-01-20 17:49:29 +08:00
This is the type of functions \ f $ y = f ( x , \ vec { p } ) \ f $ that may be plottet by JKQTPXFunctionLineGraph
and JKQTPYFunctionLineGraph . It is possible to supply parameters \ f $ \ vec { p } \ f $ to the function that
2019-01-10 04:23:24 +08:00
influence its result . Parameters are given as a pointer to some memory location . The function has to
know on its own how to interpret these .
*/
2020-09-05 19:47:46 +08:00
typedef std : : function < double ( double , const QVector < double > & ) > jkqtpPlotFunctionType ;
2019-01-10 04:23:24 +08:00
2020-09-05 05:41:23 +08:00
/*! \brief simplified type of functions (without parameters) that may be plotted by JKQTPXFunctionLineGraph and JKQTPYFunctionLineGraph
2019-01-19 16:40:52 +08:00
\ ingroup jkqtplotter_functiongraphs
2019-01-10 04:23:24 +08:00
2019-01-20 17:49:29 +08:00
This is the type of functions \ f $ y = f ( x ) \ f $ that may be plottet by JKQTPXFunctionLineGraph
and JKQTPYFunctionLineGraph .
2019-01-10 04:23:24 +08:00
*/
typedef std : : function < double ( double ) > jkqtpSimplePlotFunctionType ;
2020-09-08 02:57:25 +08:00
/** \brief extends JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase with the capabilities to define functions from C++-functors
* of type jkqtpSimplePlotFunctionType or jkqtpPlotFunctionType
* \ ingroup jkqtplotter_functiongraphs
*
* \ see JKQTPXFunctionLineGraph and JKQTPYFunctionLineGraph for a concrete implementation
2019-01-10 04:23:24 +08:00
*/
2020-09-08 02:57:25 +08:00
class JKQTPLOTTER_LIB_EXPORT JKQTPFunctorLineGraphBase : public JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase {
2019-01-10 04:23:24 +08:00
Q_OBJECT
public :
enum SpecialFunction {
Polynomial , /*!< \brief a polynomial \f$ f(x)=p_0+p_1x+p_2x^2+p_3x^3+... \f$ The parameters \a params have to be point to a QVector<double> and contain the parameters \f$ p_0, p_1, ... \f$ */
Line = Polynomial , /*!< \brief a polynomial \f$ f(x)=p_0+p_1x \f$ The parameters \a params have to be point to a QVector<double> and contain the parameters \f$ p_0, p_1, ... \f$ */
Exponential , /*!< \brief an exponential function \f$ f(x)=p_0+p_1\cdot\exp(x/p_2) \f$ or \f$ f(x)=p_0\cdot\exp(x/p_1) \f$ (depending on the number of parameters). The parameters \a params have to be point to a QVector<double> and contain the parameters \f$ p_0, p_1, ... \f$ */
PowerLaw , /*!< \brief an exponential function \f$ f(x)=p_0+p_1\cdot x^{p_3} \f$ or \f$ f(x)=p_0\cdot x^{p_1} \f$ or \f$ f(x)= x^{p_0} \f$ (depending on the number of parameters) The parameters \a params have to be point to a QVector<double> and contain the parameters \f$ p_0, p_1, ... \f$ */
} ;
/** \brief class constructor */
2020-09-08 02:57:25 +08:00
JKQTPFunctorLineGraphBase ( JKQTBasePlotter * parent = nullptr ) ;
2019-01-10 04:23:24 +08:00
/** \brief class constructor */
2020-09-08 02:57:25 +08:00
JKQTPFunctorLineGraphBase ( JKQTPlotter * parent ) ;
2019-05-30 04:40:02 +08:00
/** \brief class constructor */
2020-09-08 02:57:25 +08:00
JKQTPFunctorLineGraphBase ( const jkqtpSimplePlotFunctionType & f , const QString & title , JKQTBasePlotter * parent = nullptr ) ;
2019-05-30 04:40:02 +08:00
/** \brief class constructor */
2020-09-08 02:57:25 +08:00
JKQTPFunctorLineGraphBase ( const jkqtpSimplePlotFunctionType & f , const QString & title , JKQTPlotter * parent ) ;
2019-05-30 04:40:02 +08:00
/** \brief class constructor */
2020-09-08 02:57:25 +08:00
JKQTPFunctorLineGraphBase ( jkqtpSimplePlotFunctionType & & f , const QString & title , JKQTBasePlotter * parent = nullptr ) ;
2019-05-30 04:40:02 +08:00
/** \brief class constructor */
2020-09-08 02:57:25 +08:00
JKQTPFunctorLineGraphBase ( jkqtpSimplePlotFunctionType & & f , const QString & title , JKQTPlotter * parent ) ;
2020-09-05 05:41:23 +08:00
/** \brief class constructor */
2020-09-08 02:57:25 +08:00
JKQTPFunctorLineGraphBase ( SpecialFunction type , const QVector < double > & params , const QString & title , JKQTBasePlotter * parent ) ;
2020-09-05 05:41:23 +08:00
/** \brief class constructor */
2020-09-08 02:57:25 +08:00
JKQTPFunctorLineGraphBase ( SpecialFunction type , const QVector < double > & params , const QString & title , JKQTPlotter * parent ) ;
2019-01-10 04:23:24 +08:00
/** \brief class destructor */
2020-09-08 02:57:25 +08:00
virtual ~ JKQTPFunctorLineGraphBase ( ) override ;
2019-01-10 04:23:24 +08:00
2019-05-30 17:19:56 +08:00
/** \brief sets a functor to be plotted
2019-01-10 04:23:24 +08:00
*
2019-05-30 17:19:56 +08:00
* \ see plotFunction
*/
2019-04-22 19:27:50 +08:00
virtual void setPlotFunctionFunctor ( jkqtpPlotFunctionType & & __value ) ;
2019-05-30 17:19:56 +08:00
/** \brief sets a functor to be plotted
2019-01-10 04:23:24 +08:00
*
2019-05-30 17:19:56 +08:00
* \ see plotFunction
*/
2019-04-22 19:27:50 +08:00
virtual void setPlotFunctionFunctor ( const jkqtpPlotFunctionType & __value ) ;
2019-05-30 17:19:56 +08:00
/** \brief sets a functor to be plotted
2019-01-10 04:23:24 +08:00
*
2019-05-30 17:19:56 +08:00
* \ see simplePlotFunction
*/
2019-04-22 19:27:50 +08:00
virtual void setPlotFunctionFunctor ( jkqtpSimplePlotFunctionType & & __value ) ;
2019-05-30 17:19:56 +08:00
/** \brief sets a functor to be plotted
2019-01-10 04:23:24 +08:00
*
2019-05-30 17:19:56 +08:00
* \ see simplePlotFunction
*/
2019-04-22 19:27:50 +08:00
virtual void setPlotFunctionFunctor ( const jkqtpSimplePlotFunctionType & __value ) ;
2020-09-08 02:57:25 +08:00
/*! \copydoc plotFunction
*
* \ see isSimplePlotFunction ( ) */ \
2019-04-22 19:27:50 +08:00
virtual jkqtpPlotFunctionType getPlotFunctionFunctor ( ) const ;
2020-09-08 02:57:25 +08:00
/*! \copydoc simplePlotFunction
*
* \ see isSimplePlotFunction ( ) */ \
2019-01-26 20:00:40 +08:00
virtual jkqtpSimplePlotFunctionType getSimplePlotFunction ( ) const ;
2019-01-10 04:23:24 +08:00
2020-09-08 02:57:25 +08:00
/** \brief returns whether the plot function was defined as a jkqtpSimpleParametricCurveFunctionType (\c true ) or
* a jkqtpParametricCurveFunctionType ( \ c false ) */
bool isSimplePlotFunction ( ) const ;
2019-01-10 04:23:24 +08:00
2020-09-05 19:14:46 +08:00
2019-05-30 17:19:56 +08:00
/** \brief sets a functor to be used for calculating errors
2019-01-10 04:23:24 +08:00
*
2019-05-30 17:19:56 +08:00
* \ see errorPlotFunction
*/
2019-01-26 20:00:40 +08:00
virtual void setErrorPlotFunction ( jkqtpPlotFunctionType & & __value ) ;
2019-05-30 17:19:56 +08:00
/** \brief sets a functor to be used for calculating errors
2019-01-10 04:23:24 +08:00
*
2019-05-30 17:19:56 +08:00
* \ see errorPlotFunction
*/
2019-01-26 20:00:40 +08:00
virtual void setErrorPlotFunction ( const jkqtpPlotFunctionType & __value ) ;
2019-05-19 04:41:38 +08:00
/*! \copydoc errorPlotFunction */ \
2019-01-26 20:00:40 +08:00
virtual jkqtpPlotFunctionType getErrorPlotFunction ( ) const ;
2019-05-30 17:19:56 +08:00
/** \brief sets a functor to be used for calculating errors
2019-01-10 04:23:24 +08:00
*
2019-05-30 17:19:56 +08:00
* \ see errorSimplePlotFunction
*/
2019-01-26 20:00:40 +08:00
virtual void setErrorPlotFunction ( jkqtpSimplePlotFunctionType & & __value ) ;
2019-05-30 17:19:56 +08:00
/** \brief sets a functor to be used for calculating errors
2019-01-10 04:23:24 +08:00
*
2019-05-30 17:19:56 +08:00
* \ see errorSimplePlotFunction
*/
2019-01-26 20:00:40 +08:00
virtual void setErrorPlotFunction ( const jkqtpSimplePlotFunctionType & __value ) ;
2019-05-19 04:41:38 +08:00
/*! \copydoc errorSimplePlotFunction */ \
2019-01-26 20:00:40 +08:00
virtual jkqtpSimplePlotFunctionType getErrorSimplePlotFunction ( ) const ;
2019-01-10 04:23:24 +08:00
/** \brief sets function to the given special function */
void setSpecialFunction ( SpecialFunction function ) ;
protected :
/** \brief the function to be plotted */
jkqtpPlotFunctionType plotFunction ;
/** \brief a simple function to be plotted, simplified form without parameters */
jkqtpSimplePlotFunctionType simplePlotFunction ;
2020-09-05 19:14:46 +08:00
2019-01-10 04:23:24 +08:00
/** \brief this function calculates the error at a given position */
jkqtpPlotFunctionType errorPlotFunction ;
/** \brief this function calculates the error at a given position, simplified form without parameters */
jkqtpSimplePlotFunctionType errorSimplePlotFunction ;
2020-09-08 02:57:25 +08:00
} ;
2019-04-22 19:27:50 +08:00
2020-09-08 02:57:25 +08:00
/*! \brief This implements line plots where the data is taken from a user supplied function \f$ y=f(x) \f$
\ ingroup jkqtplotter_functiongraphs
2019-01-10 04:23:24 +08:00
2020-09-08 02:57:25 +08:00
This class uses the intelligent plotting algorithm for functions , implemented in JKQTPAdaptiveFunctionGraphEvaluator .
The following image shows some example graphs :
\ image html plot_functionplots . png
\ see \ ref JKQTPlotterFunctionPlots , JKQTPAdaptiveFunctionGraphEvaluator , JKQTPYFunctionLineGraph , JKQTPXYFunctionLineGraph , jkqtpstatAddPolyFit ( ) , jkqtpstatAddWeightedRegression ( ) , jkqtpstatAddRobustIRLSRegression ( ) , jkqtpstatAddRegression ( ) , jkqtpstatAddLinearWeightedRegression ( ) , jkqtpstatAddRobustIRLSLinearRegression ( ) , jkqtpstatAddLinearRegression ( )
*/
class JKQTPLOTTER_LIB_EXPORT JKQTPXFunctionLineGraph : public JKQTPFunctorLineGraphBase {
Q_OBJECT
public :
/** \brief class constructor */
JKQTPXFunctionLineGraph ( JKQTBasePlotter * parent = nullptr ) ;
/** \brief class constructor */
JKQTPXFunctionLineGraph ( JKQTPlotter * parent ) ;
/** \brief class constructor */
JKQTPXFunctionLineGraph ( const jkqtpSimplePlotFunctionType & f , const QString & title , JKQTBasePlotter * parent = nullptr ) ;
/** \brief class constructor */
JKQTPXFunctionLineGraph ( const jkqtpSimplePlotFunctionType & f , const QString & title , JKQTPlotter * parent ) ;
/** \brief class constructor */
JKQTPXFunctionLineGraph ( jkqtpSimplePlotFunctionType & & f , const QString & title , JKQTBasePlotter * parent = nullptr ) ;
/** \brief class constructor */
JKQTPXFunctionLineGraph ( jkqtpSimplePlotFunctionType & & f , const QString & title , JKQTPlotter * parent ) ;
/** \brief class constructor */
JKQTPXFunctionLineGraph ( SpecialFunction type , const QVector < double > & params , const QString & title , JKQTBasePlotter * parent ) ;
/** \brief class constructor */
JKQTPXFunctionLineGraph ( SpecialFunction type , const QVector < double > & params , const QString & title , JKQTPlotter * parent ) ;
/** \brief class destructor */
virtual ~ JKQTPXFunctionLineGraph ( ) override ;
/** \brief plots the graph to the plotter object specified as parent */
virtual void draw ( JKQTPEnhancedPainter & painter ) override ;
protected :
/** \copydoc JKQTPEvaluatedFunctionGraphBase::buildPlotFunctorSpec() */
virtual PlotFunctorSpec buildPlotFunctorSpec ( ) override ;
/** \copydoc JKQTPEvaluatedFunctionWithErrorsGraphBase::buildPlotFunctorSpec() */
virtual std : : function < QPointF ( double ) > buildErrorFunctorSpec ( ) override ;
2019-01-10 04:23:24 +08:00
} ;
/*! \brief This implements line plots where the data is taken from a user supplied function \f$ x=f(y) \f$
2019-01-19 16:40:52 +08:00
\ ingroup jkqtplotter_functiongraphs
2019-01-10 04:23:24 +08:00
2020-09-05 05:41:23 +08:00
The following image shows some example graphs :
\ image html functionplot_fy . png
\ see \ ref JKQTPlotterFunctionPlots , JKQTPXFunctionLineGraph , JKQTPXYFunctionLineGraph
2019-01-10 04:23:24 +08:00
*/
2020-09-08 02:57:25 +08:00
class JKQTPLOTTER_LIB_EXPORT JKQTPYFunctionLineGraph : public JKQTPFunctorLineGraphBase {
2019-01-10 04:23:24 +08:00
Q_OBJECT
public :
/** \brief class constructor */
2019-01-20 17:49:29 +08:00
JKQTPYFunctionLineGraph ( JKQTBasePlotter * parent = nullptr ) ;
2019-01-10 04:23:24 +08:00
/** \brief class constructor */
2019-01-20 23:15:10 +08:00
JKQTPYFunctionLineGraph ( JKQTPlotter * parent ) ;
2019-05-30 04:40:02 +08:00
/** \brief class constructor */
JKQTPYFunctionLineGraph ( const jkqtpSimplePlotFunctionType & f , const QString & title , JKQTBasePlotter * parent = nullptr ) ;
/** \brief class constructor */
JKQTPYFunctionLineGraph ( const jkqtpSimplePlotFunctionType & f , const QString & title , JKQTPlotter * parent ) ;
/** \brief class constructor */
JKQTPYFunctionLineGraph ( jkqtpSimplePlotFunctionType & & f , const QString & title , JKQTBasePlotter * parent = nullptr ) ;
/** \brief class constructor */
JKQTPYFunctionLineGraph ( jkqtpSimplePlotFunctionType & & f , const QString & title , JKQTPlotter * parent ) ;
2020-09-05 05:41:23 +08:00
/** \brief class constructor */
JKQTPYFunctionLineGraph ( SpecialFunction type , const QVector < double > & params , const QString & title , JKQTBasePlotter * parent ) ;
/** \brief class constructor */
JKQTPYFunctionLineGraph ( SpecialFunction type , const QVector < double > & params , const QString & title , JKQTPlotter * parent ) ;
2019-01-10 04:23:24 +08:00
/** \brief plots the graph to the plotter object specified as parent */
virtual void draw ( JKQTPEnhancedPainter & painter ) override ;
protected :
2020-09-08 02:57:25 +08:00
/** \copydoc JKQTPEvaluatedFunctionGraphBase::buildPlotFunctorSpec() */
virtual PlotFunctorSpec buildPlotFunctorSpec ( ) override ;
/** \copydoc JKQTPEvaluatedFunctionWithErrorsGraphBase::buildPlotFunctorSpec() */
virtual std : : function < QPointF ( double ) > buildErrorFunctorSpec ( ) override ;
2019-01-10 04:23:24 +08:00
} ;
# endif // jkqtpgraphsevaluatedfunction_H