JKQtPlotter/lib/jkqtplotter/jkqtpgraphs.h

546 lines
23 KiB
C
Raw Normal View History

/*
Copyright (c) 2008-2018 Jan W. Krieger (<jan@jkrieger.de>)
2015-07-12 22:34:27 +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 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/>.
*/
/**
* \defgroup jkqtplotter_elements Plot Elements
* \ingroup jkqtplotter
* \defgroup jkqtplotter_plots Graphs
* \ingroup jkqtplotter_elements
*/
/** \file jkqtpgraphs.h
* \ingroup jkqtplotter
*/
#include <QString>
#include <QPainter>
#include <QPair>
#include "jkqtplottertools/jkqtptools.h"
#include "jkqtplottertools/jkqtp_imexport.h"
#include "jkqtplottertools/jkqtpdrawingtools.h"
#include "jkqtplotter/jkqtpgraphsbase.h"
#include "jkqtplottertools/jkqtpenhancedpainter.h"
#ifndef jkqtpgraphs_H
#define jkqtpgraphs_H
// forward declarations
class JKQtBasePlotter;
class JKQtPlotter;
class JKQTPcoordinateAxis;
class JKQTPdatastore;
//class JKQTPColorPaletteTools;
/*! \brief This implements xy line plots. This also alows to draw symbols at the data points.
\ingroup jkqtplotter_plots
\image html plot_lineplots.png
*/
class LIB_EXPORT JKQTPxyLineGraph: public JKQTPxyGraph {
Q_OBJECT
public:
/** \brief class constructor */
JKQTPxyLineGraph(JKQtBasePlotter* parent=nullptr);
/** \brief class constructor */
2015-08-04 01:04:19 +08:00
JKQTPxyLineGraph(JKQtPlotter* parent);
/** \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;
/** \brief returns the color to be used for the key label */
virtual QColor getKeyLabelColor() override;
JKQTPGET_SET_MACRO(QColor, color)
JKQTPGET_SET_MACRO(QColor, fillColor)
JKQTPGET_SET_MACRO(Qt::PenStyle, style)
JKQTPGET_SET_MACRO(double, lineWidth)
JKQTPGET_SET_MACRO(JKQTPgraphSymbols, symbol)
JKQTPGET_SET_MACRO(double, symbolWidth)
JKQTPGET_SET_MACRO(double, symbolSize)
JKQTPGET_SET_MACRO(bool, drawLine)
JKQTPGET_SET_MACRO(bool, drawSelectionLine)
JKQTPGET_SET_MACRO(QColor, selectionLineColor)
protected:
/** \brief if \c true, draws a thick shadow around the line*/
bool drawSelectionLine;
/** \brief color for the shadow, or a lighter version of the line color, if transparent (default) */
QColor selectionLineColor;
/** \brief which plot style to use from the parent plotter (via JKQtPlotterBase::getPlotStyle() and JKQtPlotterBase::getNextStyle() ) */
int parentPlotStyle;
/** \brief color of the graph */
QColor color;
/** \brief color of the graph fill */
QColor fillColor;
/** \brief linestyle of the graph lines */
Qt::PenStyle style;
/** \brief width (pixels) of the graph */
double lineWidth;
/** \brief which symbol to use for the datapoints */
JKQTPgraphSymbols symbol;
/** \brief size (diameter in pixels) of the symbol for the data points */
double symbolSize;
/** \brief width (in pixels) of the lines used to plot the symbol for the data points */
double symbolWidth;
/** \brief indicates whether to draw a line or not */
bool drawLine;
QPen getLinePen(JKQTPEnhancedPainter &painter) const;
QPen getSymbolPen(JKQTPEnhancedPainter& painter) const;
QBrush getBrush(JKQTPEnhancedPainter &painter) const;
};
/*! \brief This implements xy scatter plots (like JKQTPxyLineGraph), but the color and size of the symbols may be taken from a column.
\ingroup jkqtplotter_plots
set the properties sizeColumn and/or colorColumn to change the size and/or color of the symbols according to the values in the column.
*/
class LIB_EXPORT JKQTPxyParametrizedScatterGraph: public JKQTPxyLineGraph, public JKQTPColorPaletteTools {
Q_OBJECT
public:
/** \brief class constructor */
JKQTPxyParametrizedScatterGraph(JKQtBasePlotter* parent=nullptr);
/** \brief class constructor */
2015-08-04 01:04:19 +08:00
JKQTPxyParametrizedScatterGraph(JKQtPlotter* parent);
/** \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;
/** \brief returns the color to be used for the key label */
virtual QColor getKeyLabelColor() override;
JKQTPGET_SET_MACRO(int, sizeColumn)
JKQTPSET_CAST_MACRO(size_t, int, sizeColumn)
JKQTPGET_SET_MACRO(int, colorColumn)
JKQTPSET_CAST_MACRO(size_t, int, colorColumn)
JKQTPGET_SET_MACRO(int, symbolColumn)
JKQTPSET_CAST_MACRO(size_t, int, symbolColumn)
JKQTPGET_SET_MACRO(int, linewidthColumn)
JKQTPSET_CAST_MACRO(size_t, int, linewidthColumn)
JKQTPGET_SET_MACRO(bool, colorColumnContainsRGB)
JKQTPGET_SET_MACRO(bool, gridModeForSymbolSize)
JKQTPGET_SET_MACRO(double, gridDeltaX)
JKQTPGET_SET_MACRO(double, gridDeltaY)
JKQTPGET_SET_MACRO(double, gridSymbolFractionSize)
virtual void setParent(JKQtBasePlotter* parent) override;
/*! \brief if the graph plots outside the actual plot field of view (e.g. color bars, scale bars, ...)
\note If you want to draw outside, then you'll also have to implement drawOutside()
*/
virtual void getOutsideSize(JKQTPEnhancedPainter& painter, int& leftSpace, int& rightSpace, int& topSpace, int& bottomSpace) override;
/*! \brief plots outside the actual plot field of view (e.g. color bars, scale bars, ...)
\note If you want to draw outside, then you'll also have to implement getOutsideSize(), so enough space is reserved
The four value supplied tell the method where to draw (inside one of the rectangles).
*/
virtual void drawOutside(JKQTPEnhancedPainter& painter, QRect leftSpace, QRect rightSpace, QRect topSpace, QRect bottomSpace) override;
/** \brief determine min/max data value of the image */
virtual void cbGetDataMinMax(double& imin, double& imax) override;
/** \copydoc JKQTPgraph::usesColumn() */
virtual bool usesColumn(int c) const override;
virtual double getInternalDataMin() const override;
virtual double getInternalDataMax() const override;
protected:
/** \brief this column contains the symbol size in pt */
int sizeColumn;
/** \brief this column contains the symbol color */
int colorColumn;
/** \brief this column contains the symbol type */
int symbolColumn;
/** \brief this column contains the line width */
int linewidthColumn;
/** \brief if the gridModeForSymbolSize mode is actiavted (true), the plot assumes that the scatter symbols are ordered in a grid. It the uses the given griDeltaX and gridDeltaY to calculate the symbol size, so they fill the available space to a fraction gridSymbolFractionSize. */
bool gridModeForSymbolSize;
/** \brief if the gridModeForSymbolSize mode is actiavted (true), the plot assumes that the scatter symbols are ordered in a grid. It the uses the given griDeltaX and gridDeltaY to calculate the symbol size, so they fill the available space to a fraction gridSymbolFractionSize. */
double gridDeltaX;
/** \brief if the gridModeForSymbolSize mode is actiavted (true), the plot assumes that the scatter symbols are ordered in a grid. It the uses the given griDeltaX and gridDeltaY to calculate the symbol size, so they fill the available space to a fraction gridSymbolFractionSize. */
double gridDeltaY;
/** \brief if the gridModeForSymbolSize mode is actiavted (true), the plot assumes that the scatter symbols are ordered in a grid. It the uses the given griDeltaX and gridDeltaY to calculate the symbol size, so they fill the available space to a fraction gridSymbolFractionSize. */
double gridSymbolFractionSize;
/** \brief if this is true, the value in the colorColumn is converted to an integer, representing a color in ARGB format (as in QRgb) */
bool colorColumnContainsRGB;
double getLocalLineWidth(int i);
double getLocalSymbolSize(int i);
QColor getLocalColor(int i);
JKQTPgraphSymbols getLocalSymbolType(int i);
/** \brief internally used to store the range of the color column */
double intColMin;
/** \brief internally used to store the range of the color column */
double intColMax;
};
/*! \brief This implements xy line plots with x and y error indicators.
\ingroup jkqtplotter_plots
\image html plot_errorbarlineplots.png
\image html plot_errorlinelineplots.png
\image html plot_errorpolygonlineplots.png
*/
class LIB_EXPORT JKQTPxyLineErrorGraph: public JKQTPxyLineGraph, public JKQTPxyGraphErrors {
Q_OBJECT
public:
/** \brief class constructor */
JKQTPxyLineErrorGraph(JKQtBasePlotter* parent=nullptr);
/** \brief class constructor */
JKQTPxyLineErrorGraph(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;
/** \copydoc JKQTPgraph::usesColumn() */
virtual bool usesColumn(int c) const override;
protected:
/** \brief this function is used to plot error inidcators before plotting the graphs. */
virtual void drawErrorsBefore(JKQTPEnhancedPainter& painter) override;
};
/*! \brief This implements xy scatter plots (like JKQTPxyLineGraph), but the color and size of the symbols may be taken from a column. with errorbars
\ingroup jkqtplotter_plots
set the properties sizeColumn and/or colorColumn to change the size and/or color of the symbols according to the values in the column.
*/
class LIB_EXPORT JKQTPxyParametrizedErrorScatterGraph: public JKQTPxyParametrizedScatterGraph, public JKQTPxyGraphErrors {
Q_OBJECT
public:
JKQTPxyParametrizedErrorScatterGraph(JKQtBasePlotter* parent=nullptr);
JKQTPxyParametrizedErrorScatterGraph(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;
/** \copydoc JKQTPgraph::usesColumn() */
virtual bool usesColumn(int c) const override;
protected:
/** \brief this function is used to plot error inidcators before plotting the graphs. */
virtual void drawErrorsBefore(JKQTPEnhancedPainter& painter) override;
/** \brief this function can be used to set the color of the error indicators automatically
*
* return \c true and the colors to use, if applicable, the default implementation returns false */
virtual bool intPlotXYErrorIndicatorsGetColor(JKQTPEnhancedPainter& painter, JKQtBasePlotter* parent, JKQTPgraph* parentGraph, int xColumn, int yColumn, int xErrorColumn, int yErrorColumn, JKQTPerrorPlotstyle xErrorStyle, JKQTPerrorPlotstyle yErrorStyle, int index, QColor& errorColor, QColor& errorFillColor) override;
};
/*! \brief This implements a step plot with values \f$ \left(x, f(x) \right) \f$
\ingroup jkqtplotter_plots
A step plot starts at \f$ \left(x_{i-1}, f(x_{i-1})\right) \f$ and then goes on to
\f$ \left(x_{i}, f(x_{i-1})\right) \f$. There it raises immediately to
\f$ \left(x_i, f(x_i)\right) \f$.
If you want the \f$ x_i \f$ values in the center of the steps, use
\code JKQTPstepHorizontalGraph::set_xCentered(true) \endcode . In that case the steps
go from \f$ \left(x_{i-1}, f(x_{i-1})\right) \f$ to \f$ \left(x_{i}-\delta/2, f(x_{i-1})\right) \f$ ,
then to \f$ \left(x_{i}-\delta/2, f(x_{i})\right) \f$ and finally
to \f$ \left(x_{i}, f(x_{i})\right) \f$ where \f$ \delta=(x_{i}-x_{i-1}) \f$ .
This diagram shows a plot with \code JKQTPstepHorizontalGraph::set_valuesCentered(false) \endcode :
\image html plot_stephorplot1.png
This diagram shows a plot with \code JKQTPstepHorizontalGraph::set_valuesCentered(true) \endcode :
\image html plot_stephorplot2.png
*/
class LIB_EXPORT JKQTPstepHorizontalGraph: public JKQTPxyGraph {
Q_OBJECT
public:
/** \brief class constructor */
JKQTPstepHorizontalGraph(JKQtBasePlotter* parent=nullptr);
/** \brief class constructor */
JKQTPstepHorizontalGraph(JKQtPlotter* parent);
/** \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;
/** \brief returns the color to be used for the key label */
virtual QColor getKeyLabelColor() override;
JKQTPGET_SET_MACRO(QColor, color)
JKQTPGET_SET_MACRO(QColor, fillColor)
JKQTPGET_SET_MACRO(Qt::BrushStyle, fillStyle)
JKQTPGET_SET_MACRO(Qt::PenStyle, style)
JKQTPGET_SET_MACRO(double, lineWidth)
JKQTPGET_SET_MACRO(bool, drawLine)
JKQTPGET_SET_MACRO(bool, fillCurve)
JKQTPGET_SET_MACRO(JKQTPstepType, stepType)
protected:
/** \brief color of the graph */
QColor color;
/** \brief color of the graph fill */
QColor fillColor;
/** \brief linestyle of the graph lines */
Qt::PenStyle style;
/** \brief width (pixels) of the graph */
double lineWidth;
/** \brief fill style, if the curve should be filled */
Qt::BrushStyle fillStyle;
/** \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 specifies whether the steps elongate to the left, the right, or are centered around the \f$ x_i \f$ values. */
JKQTPstepType stepType;
/** \brief which plot style to use from the parent plotter (via JKQtPlotterBase::getPlotStyle() and JKQtPlotterBase::getNextStyle() ) */
int parentPlotStyle;
QBrush getBrush(JKQTPEnhancedPainter& painter) const;
QPen getLinePen(JKQTPEnhancedPainter &painter) const;
};
/*! \brief This implements a step plot with values \f$ \left(f(y), y \right) \f$
\ingroup jkqtplotter_plots
A step plot starts at \f$ \left(f(y_{i-1}), x_{i-1}\right) \f$ and then goes on to
\f$ \left(f(y_{i-1}), y_{i}\right) \f$. There it raises immediately to
\f$ \left(f(y_i), y_i\right) \f$.
If you want the \f$ y_i \f$ values in the center of the steps, use
\code JKQTPstepHorizontalGraph::set_valuesCentered(true) \endcode . In that case the steps
go from \f$ \left(f(y_{i-1}), y_{i-1})\right) \f$ to \f$ \left(f(y_{i-1}), y_{i}-\delta/2\right) \f$ ,
then to \f$ \left(f(y_{i}, y_{i}-\delta/2\right) \f$ and finally
to \f$ \left(f(y_{i}), y_{i}\right) \f$ where \f$ \delta=(y_{i}-y_{i-1}) \f$ .
This diagram shows a plot with \code JKQTPstepHorizontalGraph::set_xCentered(false) \endcode :
\image html plot_stepverplot1.png
This diagram shows a plot with \code JKQTPstepHorizontalGraph::set_xCentered(true) \endcode :
\image html plot_stepverplot2.png
*/
class LIB_EXPORT JKQTPstepVerticalGraph: public JKQTPstepHorizontalGraph {
Q_OBJECT
public:
/** \brief class constructor */
JKQTPstepVerticalGraph(JKQtBasePlotter* parent=nullptr);
/** \brief class constructor */
JKQTPstepVerticalGraph(JKQtPlotter* parent);
/** \brief plots the graph to the plotter object specified as parent */
virtual void draw(JKQTPEnhancedPainter& painter) override;
};
/*! \brief simply marks a range (and possibly a centerline) in a plot. This may be used to display e.g. mean +/- stddev
or a range of interest, or the range of good values, ...
\ingroup jkqtplotter_plots
*/
class LIB_EXPORT JKQTPhorizontalRange: public JKQTPgraph {
Q_OBJECT
public:
/** \brief class constructor */
JKQTPhorizontalRange(JKQtBasePlotter* parent=nullptr);
/** \brief class constructor */
2015-08-04 01:04:19 +08:00
JKQTPhorizontalRange(JKQtPlotter* parent);
/** \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;
/** \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 returns the color to be used for the key label */
virtual QColor getKeyLabelColor() override;
void setDrawCenterLineOnly();
JKQTPGET_SET_MACRO(QColor, color)
JKQTPGET_SET_MACRO(QColor, fillColor)
JKQTPGET_SET_MACRO(Qt::BrushStyle, fillStyle)
JKQTPGET_SET_MACRO(Qt::PenStyle, style)
JKQTPGET_SET_MACRO(double, lineWidth)
JKQTPGET_SET_MACRO(QColor, centerColor)
JKQTPGET_SET_MACRO(Qt::PenStyle, centerStyle)
JKQTPGET_SET_MACRO(double, centerLineWidth)
JKQTPGET_SET_MACRO(double, rangeMin)
JKQTPGET_SET_MACRO(double, rangeMax)
JKQTPGET_SET_MACRO(double, sizeMin)
JKQTPGET_SET_MACRO(double, sizeMax)
JKQTPGET_SET_MACRO(bool, unlimitedSizeMin)
JKQTPGET_SET_MACRO(bool, unlimitedSizeMax)
JKQTPGET_SET_MACRO(double, rangeCenter)
JKQTPGET_SET_MACRO(bool, plotCenterLine)
JKQTPGET_SET_MACRO(bool, invertedRange)
JKQTPGET_SET_MACRO(bool, plotRange)
JKQTPGET_SET_MACRO(bool, fillRange)
JKQTPGET_SET_MACRO(bool, plotRangeLines)
protected:
/** \brief min-value of range */
double rangeMin;
/** \brief max-value of range */
double rangeMax;
/** \brief where to plot the center line */
double rangeCenter;
double sizeMin;
double sizeMax;
bool unlimitedSizeMin;
bool unlimitedSizeMax;
/** \brief indicates whether to plot a center line */
bool plotCenterLine;
/** \brief if \c true, fills the parts outside the given range */
bool invertedRange;
/** \brief if \c true, the range is plotted, if \c false, only the center line is plotted (if \a plotCenterLine is \c true ) */
bool plotRange;
/** \brief if \c true, draws lines at the range borders \a color */
bool plotRangeLines;
/** \brief if \c true, this fills the range with \a fillCOlor */
bool fillRange;
/** \brief color of the graph */
QColor color;
/** \brief color of the center line graph */
QColor centerColor;
/** \brief color of the graph fill */
QColor fillColor;
/** \brief linestyle of the graph lines */
Qt::PenStyle style;
/** \brief linestyle of the center line graph lines */
Qt::PenStyle centerStyle;
/** \brief width (pixels) of the graph */
double lineWidth;
/** \brief width (pixels) of the center line graph */
double centerLineWidth;
/** \brief fill style, if the curve should be filled */
Qt::BrushStyle fillStyle;
/** \brief which plot style to use from the parent plotter (via JKQtPlotterBase::getPlotStyle() and JKQtPlotterBase::getNextStyle() ) */
int parentPlotStyle;
QBrush getBrush(JKQTPEnhancedPainter& painter) const;
QPen getLinePen(JKQTPEnhancedPainter &painter) const;
};
/*! \brief simply marks a range (and possibly a centerline) in a plot. This may be used to display e.g. mean +/- stddev
or a range of interest, or the range of good values, ...
\ingroup jkqtplotter_plots
*/
class LIB_EXPORT JKQTPverticalRange: public JKQTPhorizontalRange {
Q_OBJECT
public:
/** \brief class constructor */
JKQTPverticalRange(JKQtBasePlotter* parent=nullptr);
/** \brief class constructor */
2015-08-04 01:04:19 +08:00
JKQTPverticalRange(JKQtPlotter* parent);
/** \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;
/** \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;
};
#endif // jkqtpgraphs_H