qwt_series_data.cpp
Go to the documentation of this file.
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 
13 static inline QRectF qwtBoundingRect( const QPointF& sample )
14 {
15  return QRectF( sample.x(), sample.y(), 0.0, 0.0 );
16 }
17 
18 static inline QRectF qwtBoundingRect( const QwtPoint3D& sample )
19 {
20  return QRectF( sample.x(), sample.y(), 0.0, 0.0 );
21 }
22 
23 static inline QRectF qwtBoundingRect( const QwtPointPolar& sample )
24 {
25  return QRectF( sample.azimuth(), sample.radius(), 0.0, 0.0 );
26 }
27 
28 static 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 
34 static 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 
54 static 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 
60 static 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 
84 template< class T >
85 QRectF 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 
136 QRectF qwtBoundingRect( const QwtSeriesData< QPointF >& series, int from, int to )
137 {
138  return qwtBoundingRectT< QPointF >( series, from, to );
139 }
140 
153  const QwtSeriesData< QwtPoint3D >& series, int from, int to )
154 {
155  return qwtBoundingRectT< QwtPoint3D >( series, from, to );
156 }
157 
173  const QwtSeriesData< QwtPointPolar >& series, int from, int to )
174 {
175  return qwtBoundingRectT< QwtPointPolar >( series, from, to );
176 }
177 
190  const QwtSeriesData< QwtIntervalSample >& series, int from, int to )
191 {
192  return qwtBoundingRectT< QwtIntervalSample >( series, from, to );
193 }
194 
207  const QwtSeriesData< QwtOHLCSample >& series, int from, int to )
208 {
209  return qwtBoundingRectT< QwtOHLCSample >( series, from, to );
210 }
211 
224  const QwtSeriesData< QwtSetSample >& series, int from, int to )
225 {
226  return qwtBoundingRectT< QwtSetSample >( series, from, to );
227 }
228 
241  const QwtSeriesData< QwtVectorFieldSample >& series, int from, int to )
242 {
243  return qwtBoundingRectT< QwtVectorFieldSample >( series, from, to );
244 }
245 
251  : QwtArraySeriesData< QPointF >( samples )
252 {
253 }
254 
264 {
265  if ( cachedBoundingRect.width() < 0.0 )
267 
268  return cachedBoundingRect;
269 }
270 
277  : QwtArraySeriesData< QwtPoint3D >( samples )
278 {
279 }
280 
290 {
291  if ( cachedBoundingRect.width() < 0.0 )
293 
294  return cachedBoundingRect;
295 }
296 
303  : QwtArraySeriesData< QwtIntervalSample >( samples )
304 {
305 }
306 
316 {
317  if ( cachedBoundingRect.width() < 0.0 )
319 
320  return cachedBoundingRect;
321 }
322 
330 {
331 }
332 
342 {
343  if ( cachedBoundingRect.width() < 0.0 )
345 
346  return cachedBoundingRect;
347 }
348 
354  : QwtArraySeriesData< QwtSetSample >( samples )
355 {
356 }
357 
367 {
368  if ( cachedBoundingRect.width() < 0.0 )
370 
371  return cachedBoundingRect;
372 }
373 
379  : QwtArraySeriesData< QwtOHLCSample >( samples )
380 {
381 }
382 
392 {
393  if ( cachedBoundingRect.width() < 0.0 )
395 
396  return cachedBoundingRect;
397 }
Open-High-Low-Close sample used in financial charts.
Definition: qwt_samples.h:143
QwtTradingChartData(const QVector< QwtOHLCSample > &=QVector< QwtOHLCSample >())
A point in polar coordinates.
QwtIntervalSeriesData(const QVector< QwtIntervalSample > &=QVector< QwtIntervalSample >())
double value
value
Definition: qwt_samples.h:85
double radius() const
Returns the radius.
A class representing an interval.
Definition: qwt_interval.h:22
double x() const
Definition: qwt_point_3d.h:103
double minValue() const
Definition: qwt_interval.h:192
virtual QRectF boundingRect() const QWT_OVERRIDE
Calculate the bounding rectangle.
Abstract interface for iterating over samples.
virtual QRectF boundingRect() const QWT_OVERRIDE
Calculate the bounding rectangle.
const QVector< QPointF > samples() const
double x
x coordinate of the position
Definition: qwt_samples.h:257
A sample of the types (x1...xn, y) or (x, y1..yn)
Definition: qwt_samples.h:73
QRectF cachedBoundingRect
Can be used to cache a calculated bounding rectangle.
QwtPoint3D class defines a 3D point in double coordinates.
Definition: qwt_point_3d.h:22
virtual QRectF boundingRect() const QWT_OVERRIDE
Calculate the bounding rectangle.
A sample of the types (x1-x2, y) or (x, y1-y2)
Definition: qwt_samples.h:20
static QRectF qwtBoundingRect(const QPointF &sample)
Sample used in vector fields.
Definition: qwt_samples.h:243
QwtSetSeriesData(const QVector< QwtSetSample > &=QVector< QwtSetSample >())
Template class for data, that is organized as QVector.
double azimuth() const
Returns the azimuth.
double width() const
Return the width of an interval.
Definition: qwt_interval.h:227
double y
y coordinate of the position
Definition: qwt_samples.h:260
virtual QRectF boundingRect() const QWT_OVERRIDE
Calculate the bounding rectangle.
double y() const
Definition: qwt_point_3d.h:109
QwtVectorFieldData(const QVector< QwtVectorFieldSample > &=QVector< QwtVectorFieldSample >())
virtual size_t size() const =0
virtual T sample(size_t i) const =0
QwtPointSeriesData(const QVector< QPointF > &=QVector< QPointF >())
double value
Value.
Definition: qwt_samples.h:31
virtual QRectF boundingRect() const QWT_OVERRIDE
Calculate the bounding rectangle.
QRectF qwtBoundingRectT(const QwtSeriesData< T > &series, int from, int to)
Calculate the bounding rectangle of a series subset.
QwtPoint3DSeriesData(const QVector< QwtPoint3D > &=QVector< QwtPoint3D >())
QVector< double > set
Vector of values associated to value.
Definition: qwt_samples.h:88
double maxValue() const
Definition: qwt_interval.h:198
QwtInterval boundingInterval() const
Calculate the bounding interval of the OHLC values.
Definition: qwt_samples.h:220
virtual QRectF boundingRect() const QWT_OVERRIDE
Calculate the bounding rectangle.
QwtInterval interval
Interval.
Definition: qwt_samples.h:34


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Jun 19 2023 03:01:39