JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches
jkqtpboxplotbase.h
1/*
2 Copyright (c) 2008-2024 Jan W. Krieger (<jan@jkrieger.de>)
3
4
5
6 This software is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License (LGPL) as published by
8 the Free Software Foundation, either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License (LGPL) for more details.
15
16 You should have received a copy of the GNU Lesser General Public License (LGPL)
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef jkqtpgraphsboxplotbase_H
21#define jkqtpgraphsboxplotbase_H
22
23
24#include <QString>
25#include <QPainter>
26#include <QPair>
27#include "jkqtplotter/jkqtptools.h"
28#include "jkqtplotter/jkqtplotter_imexport.h"
29#include "jkqtplotter/jkqtpimagetools.h"
30#include "jkqtplotter/jkqtpgraphsbase.h"
31#include "jkqtplotter/graphs/jkqtpboxplotstylingmixins.h"
32#include "jkqtplotter/jkqtpgraphsbasestylingmixins.h"
33
34
35
36
37
38/** \brief Base class for graphs representing a series of <a href="http://en.wikipedia.org/wiki/Box_plot">boxplot</a>, elements
39 * \ingroup jkqtplotter_statgraphs
40 *
41 * \image html JKQTPBoxplotVerticalGraph.png
42 *
43 *
44 * The different features of a boxplot are:
45 *
46 * \image html plot_boxplotverticalelement.png
47 *
48 * \see JKQTPBoxplotVerticalGraph, JKQTPBoxplotHorizontalGraph, JKQTPBoxplotElementBase
49 *
50 */
52 Q_OBJECT
53 public:
54
55 /** \brief Sort order in a JKQTPBoxplotVerticalGraph (or one of its child classes) */
57 Unsorted=0,
58 Sorted=1
59 };
60
61
62
63 /** \brief class constructor */
65
66 /** \brief returns the color to be used for the key label */
67 virtual QColor getKeyLabelColor() const override;
68
69 /** \copydoc JKQTPGraph::usesColumn() */
70 virtual bool usesColumn(int c) const override;
71
72 /** \copydoc sortData */
74 /** \copydoc posColumn */
75 int getPositionColumn() const;
76 /** \copydoc medianColumn */
77 int getMedianColumn() const;
78 /** \copydoc meanColumn */
79 int getMeanColumn() const;
80 /** \copydoc minColumn */
81 int getMinColumn() const;
82 /** \copydoc maxColumn */
83 int getMaxColumn() const;
84 /** \copydoc percentile25Column */
86 /** \copydoc percentile75Column */
88 /** \copydoc medianConfidenceColumn */
90
91
92 /** \copydoc boxWidthRelative */
93 double getBoxWidthRelative() const;
94
95
96 /** \copydoc useRelativeBoxWidth */
98 public Q_SLOTS:
99 /** \brief set the color of the graph (colors all elements, based on the given color \a c ) */
100 virtual void setColor(QColor c);
101 /** \copydoc sortData */
103 /** \copydoc sortData */
104 void setDataSortOrder(int __value);
105 /** \copydoc posColumn */
106 void setPositionColumn(int __value);
107 /** \copydoc posColumn */
108 void setPositionColumn (size_t __value);
109 /** \copydoc medianColumn */
110 void setMedianColumn(int __value);
111 /** \copydoc medianColumn */
112 void setMedianColumn (size_t __value);
113 /** \copydoc meanColumn */
114 void setMeanColumn(int __value);
115 /** \copydoc meanColumn */
116 void setMeanColumn (size_t __value);
117 /** \copydoc minColumn */
118 void setMinColumn(int __value);
119 /** \copydoc minColumn */
120 void setMinColumn( size_t __value);
121 /** \copydoc maxColumn */
122 void setMaxColumn(int __value);
123 /** \copydoc maxColumn */
124 void setMaxColumn (size_t __value);
125 /** \copydoc percentile25Column */
126 void setPercentile25Column(int __value);
127 /** \copydoc percentile25Column */
128 void setPercentile25Column (size_t __value);
129 /** \copydoc percentile75Column */
130 void setPercentile75Column(int __value);
131 /** \copydoc percentile75Column */
132 void setPercentile75Column (size_t __value);
133 /** \copydoc medianConfidenceColumn */
134 void setMedianConfidenceColumn (size_t __value);
135 /** \copydoc boxWidthRelative */
136 void setBoxWidthRelative(double __value);
137 /** \copydoc useRelativeBoxWidth */
138 void setUseRelativeBoxWidth(bool __value);
139 protected:
140 /** \brief width of box in percent of distance between the current two posColumn values
141 * if we only plot one box&whiskers then JKQTPGraphBoxplotStyleMixin::boxWidthAbsolute in pt is used */
143 /** \brief if set \c true, boxplot widths are calculated automatically, based on boxWidthRelative,
144 * otherwise JKQTPGraphBoxplotStyleMixin::boxWidthAbsolute is used. */
146
147 /** \brief the column that contains the x-component of the datapoints */
149 /** \brief the column that contains the median-component of the datapoints */
151 /** \brief the column that contains the confidence interval width of the median (e.g. 1.57*IQR/sqrt(n) ). This is used to draw a notch in the plot (if set) */
153 /** \brief the column that contains the median-component of the datapoints. \note This column is strictly optional. */
155 /** \brief the column that contains the minimum-component of the datapoints */
157 /** \brief the column that contains the maximum-component of the datapoints */
159 /** \brief the column that contains the 25% percentile-component of the datapoints */
161 /** \brief the column that contains the 75% percentile-component of the datapoints */
163 /** \brief if \c !=Unsorted, the data is sorted before plotting */
165 /** \brief this array contains the order of indices, in which to access the data in the data columns */
166 QVector<int> sortedIndices;
167
168 /** \brief generates a map from unsorted to sorted data \see getDataIndex() */
169 virtual void intSortData() ;
170 /** \brief retrieves the index of the i-th element when data is sorted (after calling intSortData(), which generates a map from unsorted to sorted data */
171 inline int getDataIndex(int i) const {
172 if (sortData==Unsorted) return i;
173 return sortedIndices.value(i,i);
174 }
175
176};
177
178
179
180
181/** \brief Tbaseclass for a single <a href="http://en.wikipedia.org/wiki/Box_plot">(notched) boxplot</a> as a "geometric element",
182 * where the data is directly given to the object and not stored in a column, as in JKQTPBoxplotGraphBase
183 * \ingroup jkqtplotter_statgraphs
184 * \ingroup jkqtplotter_statgraphs
185 *
186 * The different features of a boxplot are:
187 *
188 * \image html plot_boxplotverticalelement.png
189 *
190 * \see JKQTPBoxplotElementBase, JKQTPBoxplotHorizontalElement, JKQTPBoxplotGraphBase
191 */
193 Q_OBJECT
194 public:
195 /** \brief class constructor */
197 /** \brief class constructor */
199
200 /** \brief returns the color to be used for the key label */
201 virtual QColor getKeyLabelColor() const override;
202
203 /** \copydoc pos */
204 double getPos() const;
205 /** \copydoc median */
206 double getMedian() const;
207 /** \copydoc mean */
208 double getMean() const;
209 /** \copydoc min */
210 double getMin() const;
211 /** \copydoc max */
212 double getMax() const;
213 /** \copydoc percentile25 */
214 double getPercentile25() const;
215 /** \copydoc percentile75 */
216 double getPercentile75() const;
217
218 /** \copydoc drawMean */
219 void setDrawMean(bool __value);
220 /** \copydoc drawMean */
221 bool getDrawMean() const;
222 /** \copydoc drawMedian */
223 bool getDrawMedian() const;
224 /** \copydoc drawMinMax */
225 bool getDrawMinMax() const;
226 /** \copydoc drawNotch */
227 bool getDrawNotch() const;
228
229 /** \copydoc medianConfidenceIntervalWidth */
231 public Q_SLOTS:
232 /** \brief set the color of the graph (colors all elements, based on the given color \a c ) */
233 virtual void setColor(QColor c);
234
235 /** \copydoc pos */
236 void setPos(double __value);
237 /** \copydoc median */
238 void setMedian(double __value);
239 /** \copydoc min */
240 void setMin(double __value);
241 /** \copydoc mean */
242 void setMean(double __value);
243 /** \copydoc max */
244 void setMax(double __value);
245 /** \copydoc percentile25 */
246 void setPercentile25(double __value);
247 /** \copydoc percentile75 */
248 void setPercentile75(double __value);
249 /** \brief set all properties of the plot at once \see pos, median, min, mean, max, percentile25, percentile75 */
250 void setData(double pos, double min, double q25, double median, double mean, double q75, double max);
251
252 /** \copydoc drawMedian */
253 void setDrawMedian(bool __value);
254 /** \copydoc drawMinMax */
255 void setDrawMinMax(bool __value);
256 /** \copydoc drawNotch */
257 void setDrawNotch(bool __value);
258 /** \copydoc medianConfidenceIntervalWidth */
260
261
262 protected:
263
264 /** \brief the position of the boxplot on the "other" axis */
265 double pos;
266 /** \brief the median value to be used for the boxplot */
267 double median;
268 /** \brief the width of the confidence interval around the median */
270 /** \brief indicates whether to draw a notch with width medianConfidenceIntervalWidth */
272 /** \brief the mean value to be used for the boxplot */
273 double mean;
274 /** \brief indicates whether to draw the mean */
276 /** \brief indicates whether to draw the median */
278 /** \brief indicates whether to draw the percentiles */
280 /** \brief the minimum value to be used for the boxplot */
281 double min;
282 /** \brief the maximum value to be used for the boxplot */
283 double max;
284 /** \brief the 25% percentile value to be used for the boxplot */
286 /** \brief the 75% percentile value to be used for the boxplot */
288};
289
290
291
292
293#endif // jkqtpgraphsboxplotbase_H
base class for 2D plotter classes (used by the plotter widget JKQTPlotter)
Definition jkqtpbaseplotter.h:394
Tbaseclass for a single (notched) boxplot as a "geometric element", where the data is directly given ...
Definition jkqtpboxplotbase.h:192
bool drawMinMax
indicates whether to draw the percentiles
Definition jkqtpboxplotbase.h:279
double percentile75
the 75% percentile value to be used for the boxplot
Definition jkqtpboxplotbase.h:287
bool getDrawMean() const
indicates whether to draw the mean
void setMin(double __value)
the minimum value to be used for the boxplot
JKQTPBoxplotElementBase(JKQTBasePlotter *parent=nullptr)
class constructor
void setMedianConfidenceIntervalWidth(double __value)
the width of the confidence interval around the median
void setDrawMean(bool __value)
indicates whether to draw the mean
void setPos(double __value)
the position of the boxplot on the "other" axis
bool drawMedian
indicates whether to draw the median
Definition jkqtpboxplotbase.h:277
void setDrawMedian(bool __value)
indicates whether to draw the median
double min
the minimum value to be used for the boxplot
Definition jkqtpboxplotbase.h:281
bool getDrawMinMax() const
indicates whether to draw the percentiles
double medianConfidenceIntervalWidth
the width of the confidence interval around the median
Definition jkqtpboxplotbase.h:269
void setMedian(double __value)
the median value to be used for the boxplot
double median
the median value to be used for the boxplot
Definition jkqtpboxplotbase.h:267
double getPercentile25() const
the 25% percentile value to be used for the boxplot
double getMin() const
the minimum value to be used for the boxplot
double getPercentile75() const
the 75% percentile value to be used for the boxplot
void setData(double pos, double min, double q25, double median, double mean, double q75, double max)
set all properties of the plot at once
void setMax(double __value)
the maximum value to be used for the boxplot
double getMax() const
the maximum value to be used for the boxplot
double mean
the mean value to be used for the boxplot
Definition jkqtpboxplotbase.h:273
void setDrawMinMax(bool __value)
indicates whether to draw the percentiles
JKQTPBoxplotElementBase(JKQTPlotter *parent)
class constructor
virtual QColor getKeyLabelColor() const override
returns the color to be used for the key label
double getMedian() const
the median value to be used for the boxplot
virtual void setColor(QColor c)
set the color of the graph (colors all elements, based on the given color c )
void setMean(double __value)
the mean value to be used for the boxplot
double getMedianConfidenceIntervalWidth() const
the width of the confidence interval around the median
bool getDrawNotch() const
indicates whether to draw a notch with width medianConfidenceIntervalWidth
void setDrawNotch(bool __value)
indicates whether to draw a notch with width medianConfidenceIntervalWidth
void setPercentile75(double __value)
the 75% percentile value to be used for the boxplot
bool getDrawMedian() const
indicates whether to draw the median
double getPos() const
the position of the boxplot on the "other" axis
double pos
the position of the boxplot on the "other" axis
Definition jkqtpboxplotbase.h:265
bool drawMean
indicates whether to draw the mean
Definition jkqtpboxplotbase.h:275
void setPercentile25(double __value)
the 25% percentile value to be used for the boxplot
double percentile25
the 25% percentile value to be used for the boxplot
Definition jkqtpboxplotbase.h:285
double max
the maximum value to be used for the boxplot
Definition jkqtpboxplotbase.h:283
bool drawNotch
indicates whether to draw a notch with width medianConfidenceIntervalWidth
Definition jkqtpboxplotbase.h:271
double getMean() const
the mean value to be used for the boxplot
Base class for graphs representing a series of boxplot, elements.
Definition jkqtpboxplotbase.h:51
void setMedianConfidenceColumn(size_t __value)
the column that contains the confidence interval width of the median (e.g. 1.57*IQR/sqrt(n) )....
DataSortOrder sortData
if !=Unsorted, the data is sorted before plotting
Definition jkqtpboxplotbase.h:164
void setDataSortOrder(DataSortOrder __value)
if !=Unsorted, the data is sorted before plotting
int getPositionColumn() const
the column that contains the x-component of the datapoints
int getMeanColumn() const
the column that contains the median-component of the datapoints.
int maxColumn
the column that contains the maximum-component of the datapoints
Definition jkqtpboxplotbase.h:158
int percentile25Column
the column that contains the 25% percentile-component of the datapoints
Definition jkqtpboxplotbase.h:160
void setPercentile25Column(size_t __value)
the column that contains the 25% percentile-component of the datapoints
int posColumn
the column that contains the x-component of the datapoints
Definition jkqtpboxplotbase.h:148
void setPercentile25Column(int __value)
the column that contains the 25% percentile-component of the datapoints
void setMedianColumn(size_t __value)
the column that contains the median-component of the datapoints
DataSortOrder getDataSortOrder() const
if !=Unsorted, the data is sorted before plotting
bool getUseRelativeBoxWidth() const
if set true, boxplot widths are calculated automatically, based on boxWidthRelative,...
int getMedianConfidenceColumn() const
the column that contains the confidence interval width of the median (e.g. 1.57*IQR/sqrt(n) )....
virtual void intSortData()
generates a map from unsorted to sorted data
virtual bool usesColumn(int c) const override
returns true if the given column is used by the graph
void setMinColumn(int __value)
the column that contains the minimum-component of the datapoints
int getMaxColumn() const
the column that contains the maximum-component of the datapoints
void setPositionColumn(int __value)
the column that contains the x-component of the datapoints
int getPercentile25Column() const
the column that contains the 25% percentile-component of the datapoints
bool useRelativeBoxWidth
if set true, boxplot widths are calculated automatically, based on boxWidthRelative,...
Definition jkqtpboxplotbase.h:145
QVector< int > sortedIndices
this array contains the order of indices, in which to access the data in the data columns
Definition jkqtpboxplotbase.h:166
int meanColumn
the column that contains the median-component of the datapoints.
Definition jkqtpboxplotbase.h:154
void setMedianColumn(int __value)
the column that contains the median-component of the datapoints
int getPercentile75Column() const
the column that contains the 75% percentile-component of the datapoints
void setMeanColumn(int __value)
the column that contains the median-component of the datapoints.
double getBoxWidthRelative() const
width of box in percent of distance between the current two posColumn values if we only plot one box&...
virtual void setColor(QColor c)
set the color of the graph (colors all elements, based on the given color c )
void setMaxColumn(int __value)
the column that contains the maximum-component of the datapoints
JKQTPBoxplotGraphBase(JKQTBasePlotter *parent=nullptr)
class constructor
void setUseRelativeBoxWidth(bool __value)
if set true, boxplot widths are calculated automatically, based on boxWidthRelative,...
double boxWidthRelative
width of box in percent of distance between the current two posColumn values if we only plot one box&...
Definition jkqtpboxplotbase.h:142
virtual QColor getKeyLabelColor() const override
returns the color to be used for the key label
void setMeanColumn(size_t __value)
the column that contains the median-component of the datapoints.
int percentile75Column
the column that contains the 75% percentile-component of the datapoints
Definition jkqtpboxplotbase.h:162
DataSortOrder
Sort order in a JKQTPBoxplotVerticalGraph (or one of its child classes)
Definition jkqtpboxplotbase.h:56
int getMedianColumn() const
the column that contains the median-component of the datapoints
void setPercentile75Column(int __value)
the column that contains the 75% percentile-component of the datapoints
void setPositionColumn(size_t __value)
the column that contains the x-component of the datapoints
void setBoxWidthRelative(double __value)
width of box in percent of distance between the current two posColumn values if we only plot one box&...
void setMinColumn(size_t __value)
the column that contains the minimum-component of the datapoints
int getDataIndex(int i) const
retrieves the index of the i-th element when data is sorted (after calling intSortData(),...
Definition jkqtpboxplotbase.h:171
void setDataSortOrder(int __value)
if !=Unsorted, the data is sorted before plotting
void setPercentile75Column(size_t __value)
the column that contains the 75% percentile-component of the datapoints
int minColumn
the column that contains the minimum-component of the datapoints
Definition jkqtpboxplotbase.h:156
int medianConfidenceColumn
the column that contains the confidence interval width of the median (e.g. 1.57*IQR/sqrt(n) )....
Definition jkqtpboxplotbase.h:152
int getMinColumn() const
the column that contains the minimum-component of the datapoints
void setMaxColumn(size_t __value)
the column that contains the maximum-component of the datapoints
int medianColumn
the column that contains the median-component of the datapoints
Definition jkqtpboxplotbase.h:150
Styling Mix-In for Boxplots.
Definition jkqtpboxplotstylingmixins.h:46
this virtual base class of the (data-column based) graphs, which are part of a JKQTPlotter plot and w...
Definition jkqtpgraphsbase.h:429
this virtual base class of every element, which is part of a JKQTPlotter plot and may appear in its k...
Definition jkqtpgraphsbase.h:62
plotter widget for scientific plots (uses JKQTBasePlotter to do the actual drawing)
Definition jkqtplotter.h:364
#define JKQTPLOTTER_LIB_EXPORT
Definition jkqtplotter_imexport.h:89