Qwt User's Guide 6.3.0
Loading...
Searching...
No Matches
qwt_series_data.cpp
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
10#include "qwt_series_data.h"
11#include "qwt_point_polar.h"
12
13static inline QRectF qwtBoundingRect( const QPointF& sample )
14{
15 return QRectF( sample.x(), sample.y(), 0.0, 0.0 );
16}
17
18static inline QRectF qwtBoundingRect( const QwtPoint3D& sample )
19{
20 return QRectF( sample.x(), sample.y(), 0.0, 0.0 );
21}
22
23static inline QRectF qwtBoundingRect( const QwtPointPolar& sample )
24{
25 return QRectF( sample.azimuth(), sample.radius(), 0.0, 0.0 );
26}
27
28static inline QRectF qwtBoundingRect( const QwtIntervalSample& sample )
29{
30 return QRectF( sample.interval.minValue(), sample.value,
31 sample.interval.maxValue() - sample.interval.minValue(), 0.0 );
32}
33
34static inline QRectF qwtBoundingRect( const QwtSetSample& sample )
35{
36 if ( sample.set.empty() )
37 return QRectF( sample.value, 0.0, 0.0, -1.0 );
38
39 double minY = sample.set[0];
40 double maxY = sample.set[0];
41
42 for ( int i = 1; i < sample.set.size(); i++ )
43 {
44 if ( sample.set[i] < minY )
45 minY = sample.set[i];
46
47 if ( sample.set[i] > maxY )
48 maxY = sample.set[i];
49 }
50
51 return QRectF( sample.value, minY, 0.0, maxY - minY );
52}
53
54static inline QRectF qwtBoundingRect( const QwtOHLCSample& sample )
55{
56 const QwtInterval interval = sample.boundingInterval();
57 return QRectF( interval.minValue(), sample.time, interval.width(), 0.0 );
58}
59
60static inline QRectF qwtBoundingRect( const QwtVectorFieldSample& sample )
61{
62 /*
63 When displaying a sample as an arrow its length will be
64 proportional to the magnitude - but not the same.
65 As the factor between length and magnitude is not known
66 we can't include vx/vy into the bounding rectangle.
67 */
68
69 return QRectF( sample.x, sample.y, 0, 0 );
70}
71
84template< class T >
85QRectF qwtBoundingRectT( const QwtSeriesData< T >& series, int from, int to )
86{
87 QRectF boundingRect( 1.0, 1.0, -2.0, -2.0 ); // invalid;
88
89 if ( from < 0 )
90 from = 0;
91
92 if ( to < 0 )
93 to = series.size() - 1;
94
95 if ( to < from )
96 return boundingRect;
97
98 int i;
99 for ( i = from; i <= to; i++ )
100 {
101 const QRectF rect = qwtBoundingRect( series.sample( i ) );
102 if ( rect.width() >= 0.0 && rect.height() >= 0.0 )
103 {
104 boundingRect = rect;
105 i++;
106 break;
107 }
108 }
109
110 for ( ; i <= to; i++ )
111 {
112 const QRectF rect = qwtBoundingRect( series.sample( i ) );
113 if ( rect.width() >= 0.0 && rect.height() >= 0.0 )
114 {
115 boundingRect.setLeft( qMin( boundingRect.left(), rect.left() ) );
116 boundingRect.setRight( qMax( boundingRect.right(), rect.right() ) );
117 boundingRect.setTop( qMin( boundingRect.top(), rect.top() ) );
118 boundingRect.setBottom( qMax( boundingRect.bottom(), rect.bottom() ) );
119 }
120 }
121
122 return boundingRect;
123}
124
136QRectF qwtBoundingRect( const QwtSeriesData< QPointF >& series, int from, int to )
137{
138 return qwtBoundingRectT< QPointF >( series, from, to );
139}
140
152QRectF qwtBoundingRect(
153 const QwtSeriesData< QwtPoint3D >& series, int from, int to )
154{
155 return qwtBoundingRectT< QwtPoint3D >( series, from, to );
156}
157
172QRectF qwtBoundingRect(
173 const QwtSeriesData< QwtPointPolar >& series, int from, int to )
174{
175 return qwtBoundingRectT< QwtPointPolar >( series, from, to );
176}
177
189QRectF qwtBoundingRect(
190 const QwtSeriesData< QwtIntervalSample >& series, int from, int to )
191{
192 return qwtBoundingRectT< QwtIntervalSample >( series, from, to );
193}
194
206QRectF qwtBoundingRect(
207 const QwtSeriesData< QwtOHLCSample >& series, int from, int to )
208{
209 return qwtBoundingRectT< QwtOHLCSample >( series, from, to );
210}
211
223QRectF qwtBoundingRect(
224 const QwtSeriesData< QwtSetSample >& series, int from, int to )
225{
226 return qwtBoundingRectT< QwtSetSample >( series, from, to );
227}
228
240QRectF qwtBoundingRect(
241 const QwtSeriesData< QwtVectorFieldSample >& series, int from, int to )
242{
243 return qwtBoundingRectT< QwtVectorFieldSample >( series, from, to );
244}
A class representing an interval.
double minValue() const
double width() const
Return the width of an interval.
double maxValue() const
A sample of the types (x1-x2, y) or (x, y1-y2)
Definition qwt_samples.h:21
QwtInterval interval
Interval.
Definition qwt_samples.h:34
double value
Value.
Definition qwt_samples.h:31
Open-High-Low-Close sample used in financial charts.
QwtInterval boundingInterval() const
Calculate the bounding interval of the OHLC values.
QwtPoint3D class defines a 3D point in double coordinates.
double y() const
double x() const
A point in polar coordinates.
double radius() const
Returns the radius.
double azimuth() const
Returns the azimuth.
Abstract interface for iterating over samples.
virtual size_t size() const =0
virtual T sample(size_t i) const =0
A sample of the types (x1...xn, y) or (x, y1..yn)
Definition qwt_samples.h:74
double value
value
Definition qwt_samples.h:85
QVector< double > set
Vector of values associated to value.
Definition qwt_samples.h:88
Sample used in vector fields.
double y
y coordinate of the position
double x
x coordinate of the position