QWT API (English) 7.3.0
Qt Widget Library for Technical Applications - English API Documentation
Loading...
Searching...
No Matches
qwt_samples.h
1/******************************************************************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *
9 * Modified by ChenZongYan in 2024 <czy.t@163.com>
10 * Summary of major modifications (see ChangeLog.md for full history):
11 * 1. CMake build system & C++11 throughout.
12 * 2. Core panner/ zoomer refactored:
13 * - QwtPanner → QwtCachePanner (pixmap-cache version)
14 * - New real-time QwtPlotPanner derived from QwtPicker.
15 * 3. Zoomer supports multi-axis.
16 * 4. Parasite-plot framework:
17 * - QwtFigure, QwtPlotParasiteLayout, QwtPlotTransparentCanvas,
18 * - QwtPlotScaleEventDispatcher, built-in pan/zoom on axis.
19 * 5. New picker: QwtPlotSeriesDataPicker (works with date axis).
20 * 6. Raster & color-map extensions:
21 * - QwtGridRasterData (2-D table + interpolation)
22 * - QwtLinearColorMap::stopColors(), stopPos() API rename.
23 * 7. Bar-chart: expose pen/brush control.
24 * 8. Amalgamated build: single QwtPlot.h / QwtPlot.cpp pair in src-amalgamate.
25 *****************************************************************************/
26
27#ifndef QWT_SAMPLES_H
28#define QWT_SAMPLES_H
29
30#include "qwtcore_global.h"
31#include "qwt_interval.h"
32
33#include <qvector.h>
34#include <qrect.h>
35#include <qnumeric.h>
36
43class QWTCORE_EXPORT QwtStatisticalSample
44{
45public:
50 QwtStatisticalSample(double position = 0.0);
51
53 double position;
54
56 double lower;
57
59 double upper;
60
62 double center;
63};
64
65inline QwtStatisticalSample::QwtStatisticalSample(double pos) : position(pos), lower(0.0), upper(0.0), center(0.0)
66{
67}
68
74class QWTCORE_EXPORT QwtIntervalSample
75{
76public:
78 QwtIntervalSample(double, const QwtInterval&);
79 QwtIntervalSample(double value, double min, double max);
80
81 bool operator==(const QwtIntervalSample&) const;
82 bool operator!=(const QwtIntervalSample&) const;
83
85 double value;
86
89};
90
96{
97}
98
104inline QwtIntervalSample::QwtIntervalSample(double v, const QwtInterval& intv) : value(v), interval(intv)
105{
106}
107
114inline QwtIntervalSample::QwtIntervalSample(double v, double min, double max) : value(v), interval(min, max)
115{
116}
117
122{
123 return value == other.value && interval == other.interval;
124}
125
130{
131 return !(*this == other);
132}
133
139class QWTCORE_EXPORT QwtSetSample
140{
141public:
142 QwtSetSample();
143 explicit QwtSetSample(double, const QVector< double >& = QVector< double >());
144
145 bool operator==(const QwtSetSample& other) const;
146 bool operator!=(const QwtSetSample& other) const;
147
148 double added() const;
149
151 double value;
152
155};
156
161inline QwtSetSample::QwtSetSample() : value(0.0)
162{
163}
164
170inline QwtSetSample::QwtSetSample(double v, const QVector< double >& s) : value(v), set(s)
171{
172}
173
177inline bool QwtSetSample::operator==(const QwtSetSample& other) const
178{
179 return value == other.value && set == other.set;
180}
181
185inline bool QwtSetSample::operator!=(const QwtSetSample& other) const
186{
187 return !(*this == other);
188}
189
194inline double QwtSetSample::added() const
195{
196 double y = 0.0;
197 for (int i = 0; i < set.size(); i++)
198 y += set[ i ];
199
200 return y;
201}
202
210class QWTCORE_EXPORT QwtOHLCSample
211{
212public:
213 QwtOHLCSample(double time = 0.0, double open = 0.0, double high = 0.0, double low = 0.0, double close = 0.0);
214
215 QwtInterval boundingInterval() const;
216
217 bool isValid() const;
218
223 double time;
224
226 double open;
227
229 double high;
230
232 double low;
233
235 double close;
236};
237
246inline QwtOHLCSample::QwtOHLCSample(double t, double o, double h, double l, double c)
247 : time(t), open(o), high(h), low(l), close(c)
248{
249}
250
259inline bool QwtOHLCSample::isValid() const
260{
261 return (low <= high) && (open >= low) && (open <= high) && (close >= low) && (close <= high);
262}
263
271{
272 double minY = open;
273 minY = qMin(minY, high);
274 minY = qMin(minY, low);
275 minY = qMin(minY, close);
276
277 double maxY = open;
278 maxY = qMax(maxY, high);
279 maxY = qMax(maxY, low);
280 maxY = qMax(maxY, close);
281
282 return QwtInterval(minY, maxY);
283}
284
291class QWTCORE_EXPORT QwtVectorFieldSample
292{
293public:
294 QwtVectorFieldSample(double x = 0.0, double y = 0.0, double vx = 0.0, double vy = 0.0);
295
296 QwtVectorFieldSample(const QPointF& pos, double vx = 0.0, double vy = 0.0);
297
298 QPointF pos() const;
299
300 bool isNull() const;
301
303 double x;
304
306 double y;
307
309 double vx;
310
312 double vy;
313};
314
322inline QwtVectorFieldSample::QwtVectorFieldSample(double posX, double posY, double vectorX, double vectorY)
323 : x(posX), y(posY), vx(vectorX), vy(vectorY)
324{
325}
326
333inline QwtVectorFieldSample::QwtVectorFieldSample(const QPointF& pos, double vectorX, double vectorY)
334 : x(pos.x()), y(pos.y()), vx(vectorX), vy(vectorY)
335{
336}
337
342inline QPointF QwtVectorFieldSample::pos() const
343{
344 return QPointF(x, y);
345}
346
352{
353 return (vx == 0.0) && (vy == 0.0);
354}
355
363class QWTCORE_EXPORT QwtBoxSample : public QwtStatisticalSample
364{
365public:
370 QwtBoxSample(double position = 0.0);
371
384 QwtBoxSample(double position, double whiskerLower, double q1, double median, double q3, double whiskerUpper);
385
390 bool isValid() const;
391
399 bool hasMean() const;
400
405 QwtInterval boundingInterval() const;
406
411 QwtInterval boxInterval() const;
412
415
417 double q1;
418
420 double median;
421
423 double q3;
424
427
429 double mean;
430
433};
434
436 : QwtStatisticalSample(pos), whiskerLower(0.0), q1(0.0), median(0.0), q3(0.0), whiskerUpper(0.0),
437 mean(qQNaN()), outlierCount(0)
438{
439}
440
441inline QwtBoxSample::QwtBoxSample(double pos, double wl, double q1v, double med, double q3v, double wu)
442 : QwtStatisticalSample(pos), whiskerLower(wl), q1(q1v), median(med), q3(q3v), whiskerUpper(wu),
443 mean(qQNaN()), outlierCount(0)
444{
445 center = median;
446}
447
448inline bool QwtBoxSample::isValid() const
449{
450 return (whiskerLower <= q1) && (q1 <= median) && (median <= q3) && (q3 <= whiskerUpper);
451}
452
453inline bool QwtBoxSample::hasMean() const
454{
455 return qIsFinite(mean);
456}
457
462
464{
465 return QwtInterval(q1, q3);
466}
467
474class QWTCORE_EXPORT QwtBoxOutlierSample
475{
476public:
480 QwtBoxOutlierSample(double boxPosition = 0.0);
481
487 QwtBoxOutlierSample(double boxPosition, const QVector< double >& values);
488
492 QwtBoxOutlierSample(double boxPosition, QVector< double >&& values);
493
495 bool isEmpty() const
496 {
497 return values.isEmpty();
498 }
499
501 int count() const
502 {
503 return values.size();
504 }
505
508
511};
512
513inline QwtBoxOutlierSample::QwtBoxOutlierSample(double pos) : boxPosition(pos), values()
514{
515}
516
518 : boxPosition(pos), values(vals)
519{
520}
521
523 : boxPosition(pos), values(std::move(vals))
524{
525}
526
527Q_DECLARE_METATYPE(QwtIntervalSample)
528Q_DECLARE_METATYPE(QwtOHLCSample)
529Q_DECLARE_METATYPE(QwtVectorFieldSample)
530Q_DECLARE_METATYPE(QwtBoxSample)
531Q_DECLARE_METATYPE(QwtSetSample)
532
533#endif
Outlier values for a single boxplot position.
Definition qwt_samples.h:475
bool isEmpty() const
Check if no outliers present.
Definition qwt_samples.h:495
double boxPosition
Position of the parent box (matches QwtBoxSample.position)
Definition qwt_samples.h:507
QVector< double > values
All outlier values for this box.
Definition qwt_samples.h:510
int count() const
Get number of outliers.
Definition qwt_samples.h:501
QwtBoxOutlierSample(double boxPosition=0.0)
Default constructor.
Definition qwt_samples.h:513
Sample for box-and-whisker plot (boxplot) visualization.
Definition qwt_samples.h:364
double q3
Third quartile (75th percentile)
Definition qwt_samples.h:423
double whiskerLower
Lower whisker endpoint.
Definition qwt_samples.h:414
double whiskerUpper
Upper whisker endpoint.
Definition qwt_samples.h:426
double mean
Arithmetic mean - NaN, when unknown (the default and full constructor)
Definition qwt_samples.h:429
bool hasMean() const
Check if the sample carries a mean value.
Definition qwt_samples.h:453
int outlierCount
Number of outliers (stored separately, this is count only)
Definition qwt_samples.h:432
QwtBoxSample(double position=0.0)
Default constructor.
Definition qwt_samples.h:435
QwtInterval boundingInterval() const
Get bounding interval including whiskers.
Definition qwt_samples.h:458
bool isValid() const
Check if sample has valid ordering.
Definition qwt_samples.h:448
double q1
First quartile (25th percentile)
Definition qwt_samples.h:417
QwtInterval boxInterval() const
Get box body interval (Q1 to Q3)
Definition qwt_samples.h:463
double median
Median (50th percentile) - also stored in inherited 'center' field.
Definition qwt_samples.h:420
A sample of the types (x1-x2, y) or (x, y1-y2)
Definition qwt_samples.h:75
QwtInterval interval
Interval.
Definition qwt_samples.h:88
bool operator==(const QwtIntervalSample &) const
Equality comparison operator.
Definition qwt_samples.h:121
bool operator!=(const QwtIntervalSample &) const
Inequality comparison operator.
Definition qwt_samples.h:129
QwtIntervalSample()
Default constructor.
Definition qwt_samples.h:95
double value
Value.
Definition qwt_samples.h:85
A class representing an interval.
Definition qwt_interval.h:39
Open-High-Low-Close sample used in financial charts.
Definition qwt_samples.h:211
double high
Highest price.
Definition qwt_samples.h:229
bool isValid() const
Check if a sample is valid.
Definition qwt_samples.h:259
double open
Opening price.
Definition qwt_samples.h:226
double close
Closing price.
Definition qwt_samples.h:235
double time
Time of the sample, usually a number representing a specific interval - like a day.
Definition qwt_samples.h:223
QwtInterval boundingInterval() const
Calculate the bounding interval of the OHLC values.
Definition qwt_samples.h:270
QwtOHLCSample(double time=0.0, double open=0.0, double high=0.0, double low=0.0, double close=0.0)
Constructor with all OHLC values.
Definition qwt_samples.h:246
double low
Lowest price.
Definition qwt_samples.h:232
A sample of the types (x1...xn, y) or (x, y1..yn)
Definition qwt_samples.h:140
double added() const
Return all values of the set added together.
Definition qwt_samples.h:194
double value
value
Definition qwt_samples.h:151
QVector< double > set
Vector of values associated to value.
Definition qwt_samples.h:154
bool operator!=(const QwtSetSample &other) const
Inequality comparison operator.
Definition qwt_samples.h:185
bool operator==(const QwtSetSample &other) const
Equality comparison operator.
Definition qwt_samples.h:177
QwtSetSample()
Default constructor.
Definition qwt_samples.h:161
Base class for statistical samples with position and range.
Definition qwt_samples.h:44
double lower
Lower bound of the statistical range.
Definition qwt_samples.h:56
double position
Position on the "time" axis (x for vertical, y for horizontal orientation)
Definition qwt_samples.h:53
QwtStatisticalSample(double position=0.0)
Default constructor.
Definition qwt_samples.h:65
double upper
Upper bound of the statistical range.
Definition qwt_samples.h:59
double center
Central reference value.
Definition qwt_samples.h:62
Sample used in vector fields.
Definition qwt_samples.h:292
double y
y coordinate of the position
Definition qwt_samples.h:306
QwtVectorFieldSample(double x=0.0, double y=0.0, double vx=0.0, double vy=0.0)
Constructor with position and vector coordinates.
Definition qwt_samples.h:322
QPointF pos() const
Return position as QPointF.
Definition qwt_samples.h:342
bool isNull() const
Check if the vector is null.
Definition qwt_samples.h:351
double vx
x coordinate of the vector
Definition qwt_samples.h:309
double x
x coordinate of the position
Definition qwt_samples.h:303
double vy
y coordinate of the vector
Definition qwt_samples.h:312