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
jkqtpbarchart.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 jkqtpgraphsbarchart_H
21#define jkqtpgraphsbarchart_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/jkqtpgraphsbase.h"
30#include "jkqtplotter/jkqtpgraphsbaseerrors.h"
31#include "jkqtplotter/jkqtpgraphsbasestylingmixins.h"
32#include "jkqtplotter/graphs/jkqtpbarchartbase.h"
33
34
35/** \brief This implements a vertical bar graph with bars between \f$ y=\mbox{baseline} \f$ and \f$ y=f(x) \f$
36 * \ingroup jkqtplotter_barcharts
37 *
38 *
39 * This class draws vertical bargraphs. The basic properties are defined and documented with JKQTPBarGraphBase .
40 *
41 * The a horizontal is defined by a series of datapoints \c (x,y=f(x)) .
42 * Bars are then drawn fromm a baseline (often \c =0 ) to the value \c y=f(x) at each position \c x .
43 * Thus the class is derived from JKQTPXYBaselineGraph, which provides a baseline as well as columns for \c x and \c y values.
44 *
45 * \image html JKQTPBarVerticalGraph.png
46 *
47 * \see \ref JKQTPlotterBarcharts, jkqtpstatAddHHistogram1D(), jkqtpstatAddHHistogram1DAutoranged()
48 *
49 *
50 */
52 Q_OBJECT
53 public:
54 /** \brief class constructor */
56 /** \brief class constructor */
58
59 /** \brief plots the graph to the plotter object specified as parent */
60 virtual void draw(JKQTPEnhancedPainter& painter) override;
61
62 /** \copydoc JKQTPPlotElement::getXMinMax() */
63 virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override;
64 /** \copydoc JKQTPPlotElement::getYMinMax() */
65 virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override;
66
67 public Q_SLOTS:
68
69 protected:
70
71 /** \brief this function is used by autoscaleBarWidthAndShift() to determine whether a given graph shall be taken into account when autoscaling.
72 * Typically this returns \c true for all JKQTPBarGraphBase-derved objects with the same orientation (horizontal or vertical) */
73 virtual bool considerForAutoscaling( JKQTPBarGraphBase* other) const override;
74
75};
76
77/*! \brief This implements a vertical bar graph with bars between \f$ y=\mbox{baseline} \f$ and \f$ y=f(x) \f$
78 * and error indicator
79 * \ingroup jkqtplotter_barcharts
80 *
81 * This works much the same as JKQTPBarHorizontalGraph, but also draws error indicators.
82 * Here is an example output:
83 *
84 * \image html JKQTPBarVerticalErrorGraph.png
85 *
86 * Error indicators are defined and styled with the functions from JKQTPYGraphErrors .
87 *
88 * \see jkqtpstatAddYErrorBarGraph(), JKQTPBarVerticalGraph, \ref JKQTPlotterBarcharts
89 */
91 Q_OBJECT
92 public:
93 /** \brief class constructor */
95 /** \brief class constructor */
97
98 /** \copydoc JKQTPGraph::usesColumn() */
99 virtual bool usesColumn(int c) const override;
100 /** \brief get the maximum and minimum y-value of the graph
101 *
102 * The result is given in the two parameters which are call-by-reference parameters!
103 */
104 virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override;
105
106 /** \brief returns the column that contains the bar height errors */
107 int getBarErrorColumn() const;
108 /** \brief returns the column that contains the lower bar height errors */
110 /** \brief returns the error style of the bar */
112 /** \brief returns whether the errors of the bars are symmetric */
114
115 public Q_SLOTS:
116 /** \brief sets whether the errors of the bars are symmetric */
117 void setBarErrorSymmetric(bool __value);
118 /** \brief sets the error style of the bar */
120 /** \brief sets the column that contains the bar height errors */
121 void setBarErrorColumn(int column) ;
122
123 /** \brief sets the column that contains the bar height errors */
124 void setBarErrorColumn(size_t column) ;
125 /** \brief sets the column that contains the bar height errors */
126 void setBarLowerErrorColumn(int column) ;
127
128 /** \brief sets the column that contains the bar height errors */
129 void setBarLowerErrorColumn(size_t column) ;
130
131 protected:
132 /** \brief this function is used to plot error inidcators before plotting the graphs. */
133 virtual void drawErrorsAfter(JKQTPEnhancedPainter& painter) override;
134};
135
136
137
138
139
140/** \brief This implements a horizontal bar graph with bars between \f$ x=\mbox{baseline} \f$ and \f$ x=f(y) \f$
141 * \ingroup jkqtplotter_barcharts
142 *
143 * This class draws horizontal bargraphs. The basic properties are defined and documented with JKQTPBarGraphBase .
144 *
145 * The a horizontal is defined by a series of datapoints \c (y,x=f(y)) .
146 * Bars are then drawn fromm a baseline (often \c =0 ) to the value \c x=f(y) at each position \c y.
147 * Thus the class is derived from JKQTPXYBaselineGraph, which provides a baseline as well as columns for \c x and \c y values.
148 *
149 * \image html JKQTPBarHorizontalGraph.png
150 *
151 * \see \ref JKQTPlotterBarcharts, jkqtpstatAddVHistogram1D(), jkqtpstatAddVHistogram1DAutoranged()
152 *
153 *
154 */
156 Q_OBJECT
157 public:
158 /** \brief class constructor */
160 /** \brief class constructor */
162
163 /** \brief plots the graph to the plotter object specified as parent */
164 virtual void draw(JKQTPEnhancedPainter& painter) override;
165
166 /** \copydoc JKQTPPlotElement::getXMinMax() */
167 virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override;
168 /** \copydoc JKQTPPlotElement::getYMinMax() */
169 virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override;
170 /** \brief returns the column used as "key" for the current graph (typically this call getXColumn(), but for horizontal graphs like filled curves or barcharts it may call getYColumn() ) */
171 virtual int getKeyColumn() const override;
172 /** \brief returns the column used as "value" for the current graph (typically this call getXColumn(), but for horizontal graphs like filled curves or barcharts it may call getYColumn() ) */
173 virtual int getValueColumn() const override;
174 public Q_SLOTS:
175 /** \brief sets the column used as "key" for the current graph (typically this call setXColumn(), but for horizontal graphs like filled curves or barcharts it may call setYColumn() ) */
176 virtual void setKeyColumn(int __value) override;
177 /** \brief sets the column used as "value" for the current graph (typically this call setXColumn(), but for horizontal graphs like filled curves or barcharts it may call setYColumn() ) */
178 virtual void setValueColumn(int __value) override;
179 protected:
180
181 /** \brief this function is used by autoscaleBarWidthAndShift() to determine whether a given graph shall be taken into account when autoscaling.
182 * Typically this returns \c true for all JKQTPBarGraphBase-derved objects with the same orientation (horizontal or vertical) */
183 virtual bool considerForAutoscaling( JKQTPBarGraphBase* other) const override;
184 };
185
186
187
188/*! \brief This implements a horizontal bar graph with bars between \f$ x=\mbox{baseline} \f$ and \f$ x=f(y) \f$
189 * and error indicator
190 * \ingroup jkqtplotter_barcharts
191 *
192 * This works much the same as JKQTPBarHorizontalGraph, but also draws error indicators.
193 * Here is an example output:
194 *
195 * \image html JKQTPBarHorizontalErrorGraph.png
196 *
197 * Error indicators are defined and styled by functions from JKQTPXGraphErrors.
198 *
199 * \see jkqtpstatAddXErrorBarGraph(), JKQTPBarHorizontalGraph, \ref JKQTPlotterBarcharts
200 *
201 */
203 Q_OBJECT
204 public:
205 /** \brief class constructor */
207 /** \brief class constructor */
209
210 /** \copydoc JKQTPGraph::usesColumn() */
211 virtual bool usesColumn(int c) const override;
212 /** \copydoc JKQTPPlotElement::getXMinMax() */
213 virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override;
214
215
216 /** \brief returns the column that contains the bar height errors */
217 int getBarErrorColumn() const;
218 /** \brief returns the column that contains the lower bar height errors */
220 /** \brief returns the error style of the bar */
222 /** \brief returns whether the errors of the bars are symmetric */
224
225 public Q_SLOTS:
226 /** \brief sets whether the errors of the bars are symmetric */
227 void setBarErrorSymmetric(bool __value);
228 /** \brief sets the error style of the bar */
230 /** \brief sets the column that contains the bar height errors */
231 void setBarErrorColumn(int column) ;
232
233 /** \brief sets the column that contains the bar height errors */
234 void setBarErrorColumn(size_t column) ;
235 /** \brief sets the column that contains the bar height errors */
236 void setBarLowerErrorColumn(int column) ;
237
238 /** \brief sets the column that contains the bar height errors */
239 void setBarLowerErrorColumn(size_t column) ;
240 protected:
241 /** \brief this function is used to plot error inidcators before plotting the graphs. */
242 virtual void drawErrorsAfter(JKQTPEnhancedPainter& painter) override;
243};
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258/*! \brief This implements a vertical bar graph with bars between \f$ y=\mbox{baseline} \f$ and \f$ y=f(x) \f$
259 * Optionally several graphs of this type may be stacked on top of each other
260 * \ingroup jkqtplotter_barcharts
261 *
262 * Draw stacked barcharts by connecting several plots by calling \c setStackedParent(belowPlot) for each plot
263 *
264 * \image html JKQTPBarVerticalGraphStacked.png
265 *
266 * \see JKQTPBarVerticalGraph, \ref JKQTPlotterStackedBarChart
267 */
269 Q_OBJECT
270 public:
271 /** \brief class constructor */
273 /** \brief class constructor */
275 /** \brief stacks this barchart upon the given \a parentGraph */
277 /** \brief unstacks this graph (i.e. deletes the parent graph in the stack) */
279 /** \brief returns the stack parent graph, or \c nullptr */
281 /** \brief returns the stack parent graph, or \c nullptr */
283
284 protected:
285
286 /** \brief if set (!=nullptr), the current plot is drawn stacked onto this plot
287 *
288 * draw stacked barcharts by connecting several plots by calling \c setStackedParent(belowPlot) for each plot
289 */
291
292 /** \brief used to generate stacked plots: returns the upper boundary of the parent plot in a stack, for the index-th datapoint */
293 double getParentStackedMax(int index) const ;
294
295
296 /** \copydoc JKQTPBarGraphBase::hasStackParent() */
297 virtual bool hasStackParent() const override;
298 /** \brief used to generate stacked plots: returns the upper boundary of this plot in a stack, for the index-th datapoint */
299 double getStackedMax(int index) const;
300 /** \copydoc JKQTPBarGraphStackInternalInterface::getBottomOfStack() */
302
303};
304
305
306
307
308
309
310/*! \brief This implements a horizontal bar graph with bars between \f$ x=\mbox{baseline} \f$ and \f$ x=f(y) \f$
311 * Optionally several graphs of this type may be stacked on top of each other
312 * \ingroup jkqtplotter_barcharts
313 *
314 * Draw stacked barcharts by connecting several plots by calling \c setStackedParent(belowPlot) for each plot
315 *
316 * \image html JKQTPBarHorizontalGraphStacked.png
317 *
318 *
319 * \see JKQTPBarHorizontalGraph, \ref JKQTPlotterStackedBarChart
320 */
322 Q_OBJECT
323 public:
324 /** \brief class constructor */
326 /** \brief class constructor */
328 /** \brief stacks this barchart upon the given \a parentGraph */
330 /** \brief unstacks this graph (i.e. deletes the parent graph in the stack) */
332 /** \brief returns the stack parent graph, or \c nullptr */
334 /** \brief returns the stack parent graph, or \c nullptr */
336
337 protected:
338
339 /** \brief if set (!=nullptr), the current plot is drawn stacked onto this plot
340 *
341 * draw stacked barcharts by connecting several plots by calling \c setStackedParent(belowPlot) for each plot
342 */
344
345 /** \brief used to generate stacked plots: returns the upper boundary of the parent plot in a stack, for the index-th datapoint */
346 virtual double getParentStackedMax(int index) const override;
347
348 /** \copydoc JKQTPBarGraphBase::hasStackParent() */
349 virtual bool hasStackParent() const override;
350 /** \brief used to generate stacked plots: returns the upper boundary of this plot in a stack, for the index-th datapoint */
351 double getStackedMax(int index) const;
352 /** \copydoc JKQTPBarGraphStackInternalInterface::getBottomOfStack() */
354};
355
356
357
358
359
360
361
362
363#endif // jkqtpgraphsbarchart_H
base class for 2D plotter classes (used by the plotter widget JKQTPlotter)
Definition jkqtpbaseplotter.h:394
This is a base-class for all bar graphs with vertical or horizontal orientation (the orientation is i...
Definition jkqtpbarchartbase.h:152
This is an interface-class for all stackable bargraphs ... it is used internally for autoscaling only...
Definition jkqtpbarchartbase.h:479
This implements a horizontal bar graph with bars between and and error indicator.
Definition jkqtpbarchart.h:202
void setBarErrorColumn(int column)
sets the column that contains the bar height errors
virtual bool getXMinMax(double &minx, double &maxx, double &smallestGreaterZero) override
get the maximum and minimum x-value of the graph
JKQTPBarHorizontalErrorGraph(JKQTBasePlotter *parent=nullptr)
class constructor
void setBarErrorSymmetric(bool __value)
sets whether the errors of the bars are symmetric
JKQTPBarHorizontalErrorGraph(JKQTPlotter *parent)
class constructor
JKQTPErrorPlotstyle getBarErrorStyle() const
returns the error style of the bar
void setBarErrorStyle(JKQTPErrorPlotstyle __value)
sets the error style of the bar
virtual bool usesColumn(int c) const override
returns true if the given column is used by the graph
void setBarErrorColumn(size_t column)
sets the column that contains the bar height errors
bool getBarErrorSymmetric() const
returns whether the errors of the bars are symmetric
int getBarErrorColumn() const
returns the column that contains the bar height errors
int getBarLowerErrorColumn() const
returns the column that contains the lower bar height errors
void setBarLowerErrorColumn(int column)
sets the column that contains the bar height errors
virtual void drawErrorsAfter(JKQTPEnhancedPainter &painter) override
this function is used to plot error inidcators before plotting the graphs.
void setBarLowerErrorColumn(size_t column)
sets the column that contains the bar height errors
This implements a horizontal bar graph with bars between and .
Definition jkqtpbarchart.h:155
virtual bool considerForAutoscaling(JKQTPBarGraphBase *other) const override
this function is used by autoscaleBarWidthAndShift() to determine whether a given graph shall be take...
JKQTPBarHorizontalGraph(JKQTPlotter *parent)
class constructor
virtual bool getYMinMax(double &miny, double &maxy, double &smallestGreaterZero) override
get the maximum and minimum y-value of the graph
virtual void setValueColumn(int __value) override
sets the column used as "value" for the current graph (typically this call setXColumn(),...
virtual void draw(JKQTPEnhancedPainter &painter) override
plots the graph to the plotter object specified as parent
virtual int getValueColumn() const override
returns the column used as "value" for the current graph (typically this call getXColumn(),...
virtual void setKeyColumn(int __value) override
sets the column used as "key" for the current graph (typically this call setXColumn(),...
JKQTPBarHorizontalGraph(JKQTBasePlotter *parent=nullptr)
class constructor
virtual bool getXMinMax(double &minx, double &maxx, double &smallestGreaterZero) override
get the maximum and minimum x-value of the graph
virtual int getKeyColumn() const override
returns the column used as "key" for the current graph (typically this call getXColumn(),...
This implements a horizontal bar graph with bars between and Optionally several graphs of this type...
Definition jkqtpbarchart.h:321
void dontStackUpon()
unstacks this graph (i.e. deletes the parent graph in the stack)
virtual JKQTPBarGraphBase * getBottomOfStack() override
returns the barchart at the bottom of this stack (i.e. traverses the stack until there are no more pa...
JKQTPBarHorizontalStackableGraph(JKQTPlotter *parent)
class constructor
const JKQTPBarHorizontalStackableGraph * getStackParent() const
returns the stack parent graph, or nullptr
void stackUpon(JKQTPBarHorizontalStackableGraph *parentGraph)
stacks this barchart upon the given parentGraph
double getStackedMax(int index) const
used to generate stacked plots: returns the upper boundary of this plot in a stack,...
JKQTPBarHorizontalStackableGraph * stackParent
if set (!=nullptr), the current plot is drawn stacked onto this plot
Definition jkqtpbarchart.h:343
virtual bool hasStackParent() const override
returns true, if a stack parent is set (if available)
JKQTPBarHorizontalStackableGraph * getStackParent()
returns the stack parent graph, or nullptr
virtual double getParentStackedMax(int index) const override
used to generate stacked plots: returns the upper boundary of the parent plot in a stack,...
JKQTPBarHorizontalStackableGraph(JKQTBasePlotter *parent=nullptr)
class constructor
This implements a vertical bar graph with bars between and and error indicator.
Definition jkqtpbarchart.h:90
bool getBarErrorSymmetric() const
returns whether the errors of the bars are symmetric
virtual bool getYMinMax(double &miny, double &maxy, double &smallestGreaterZero) override
get the maximum and minimum y-value of the graph
int getBarErrorColumn() const
returns the column that contains the bar height errors
void setBarErrorStyle(JKQTPErrorPlotstyle __value)
sets the error style of the bar
JKQTPErrorPlotstyle getBarErrorStyle() const
returns the error style of the bar
void setBarErrorColumn(int column)
sets the column that contains the bar height errors
virtual bool usesColumn(int c) const override
returns true if the given column is used by the graph
void setBarErrorColumn(size_t column)
sets the column that contains the bar height errors
JKQTPBarVerticalErrorGraph(JKQTPlotter *parent)
class constructor
void setBarLowerErrorColumn(int column)
sets the column that contains the bar height errors
virtual void drawErrorsAfter(JKQTPEnhancedPainter &painter) override
this function is used to plot error inidcators before plotting the graphs.
JKQTPBarVerticalErrorGraph(JKQTBasePlotter *parent=nullptr)
class constructor
void setBarLowerErrorColumn(size_t column)
sets the column that contains the bar height errors
int getBarLowerErrorColumn() const
returns the column that contains the lower bar height errors
void setBarErrorSymmetric(bool __value)
sets whether the errors of the bars are symmetric
This implements a vertical bar graph with bars between and .
Definition jkqtpbarchart.h:51
JKQTPBarVerticalGraph(JKQTPlotter *parent)
class constructor
virtual bool getYMinMax(double &miny, double &maxy, double &smallestGreaterZero) override
get the maximum and minimum y-value of the graph
virtual void draw(JKQTPEnhancedPainter &painter) override
plots the graph to the plotter object specified as parent
virtual bool getXMinMax(double &minx, double &maxx, double &smallestGreaterZero) override
get the maximum and minimum x-value of the graph
virtual bool considerForAutoscaling(JKQTPBarGraphBase *other) const override
this function is used by autoscaleBarWidthAndShift() to determine whether a given graph shall be take...
JKQTPBarVerticalGraph(JKQTBasePlotter *parent=nullptr)
class constructor
This implements a vertical bar graph with bars between and Optionally several graphs of this type m...
Definition jkqtpbarchart.h:268
const JKQTPBarVerticalStackableGraph * getStackParent() const
returns the stack parent graph, or nullptr
void stackUpon(JKQTPBarVerticalStackableGraph *parentGraph)
stacks this barchart upon the given parentGraph
void dontStackUpon()
unstacks this graph (i.e. deletes the parent graph in the stack)
JKQTPBarVerticalStackableGraph(JKQTPlotter *parent)
class constructor
JKQTPBarVerticalStackableGraph * getStackParent()
returns the stack parent graph, or nullptr
double getParentStackedMax(int index) const
used to generate stacked plots: returns the upper boundary of the parent plot in a stack,...
JKQTPBarVerticalStackableGraph(JKQTBasePlotter *parent=nullptr)
class constructor
virtual bool hasStackParent() const override
returns true, if a stack parent is set (if available)
virtual JKQTPBarGraphBase * getBottomOfStack() override
returns the barchart at the bottom of this stack (i.e. traverses the stack until there are no more pa...
JKQTPBarVerticalStackableGraph * stackParent
if set (!=nullptr), the current plot is drawn stacked onto this plot
Definition jkqtpbarchart.h:290
double getStackedMax(int index) const
used to generate stacked plots: returns the upper boundary of this plot in a stack,...
this class extends the QPainter
Definition jkqtpenhancedpainter.h:33
This class is the base class for graphs that only display error indicators in x-direction.
Definition jkqtpgraphsbaseerrors.h:299
This class is the base class for graphs that only display error indicators in y-direction.
Definition jkqtpgraphsbaseerrors.h:323
plotter widget for scientific plots (uses JKQTBasePlotter to do the actual drawing)
Definition jkqtplotter.h:364
QFlags< JKQTPErrorPlotstyleElements > JKQTPErrorPlotstyle
specifies the plot styles for the error information, e.g. error bars, boxes, lines ....
Definition jkqtptools.h:728
#define JKQTPLOTTER_LIB_EXPORT
Definition jkqtplotter_imexport.h:89