qwt_series_data.cpp
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
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>
86  const QwtSeriesData<T>& series, int from, int to )
87 {
88  QRectF boundingRect( 1.0, 1.0, -2.0, -2.0 ); // invalid;
89 
90  if ( from < 0 )
91  from = 0;
92 
93  if ( to < 0 )
94  to = series.size() - 1;
95 
96  if ( to < from )
97  return boundingRect;
98 
99  int i;
100  for ( i = from; i <= to; i++ )
101  {
102  const QRectF rect = qwtBoundingRect( series.sample( i ) );
103  if ( rect.width() >= 0.0 && rect.height() >= 0.0 )
104  {
105  boundingRect = rect;
106  i++;
107  break;
108  }
109  }
110 
111  for ( ; i <= to; i++ )
112  {
113  const QRectF rect = qwtBoundingRect( series.sample( i ) );
114  if ( rect.width() >= 0.0 && rect.height() >= 0.0 )
115  {
116  boundingRect.setLeft( qMin( boundingRect.left(), rect.left() ) );
117  boundingRect.setRight( qMax( boundingRect.right(), rect.right() ) );
118  boundingRect.setTop( qMin( boundingRect.top(), rect.top() ) );
119  boundingRect.setBottom( qMax( boundingRect.bottom(), rect.bottom() ) );
120  }
121  }
122 
123  return boundingRect;
124 }
125 
138  const QwtSeriesData<QPointF> &series, int from, int to )
139 {
140  return qwtBoundingRectT<QPointF>( series, from, to );
141 }
142 
155  const QwtSeriesData<QwtPoint3D> &series, int from, int to )
156 {
157  return qwtBoundingRectT<QwtPoint3D>( series, from, to );
158 }
159 
175  const QwtSeriesData<QwtPointPolar> &series, int from, int to )
176 {
177  return qwtBoundingRectT<QwtPointPolar>( series, from, to );
178 }
179 
192  const QwtSeriesData<QwtIntervalSample>& series, int from, int to )
193 {
194  return qwtBoundingRectT<QwtIntervalSample>( series, from, to );
195 }
196 
209  const QwtSeriesData<QwtOHLCSample>& series, int from, int to )
210 {
211  return qwtBoundingRectT<QwtOHLCSample>( series, from, to );
212 }
213 
226  const QwtSeriesData<QwtSetSample>& series, int from, int to )
227 {
228  return qwtBoundingRectT<QwtSetSample>( series, from, to );
229 }
230 
243  const QwtSeriesData<QwtVectorFieldSample> &series, int from, int to )
244 {
245  return qwtBoundingRectT<QwtVectorFieldSample>( series, from, to );
246 }
247 
253  const QVector<QPointF> &samples ):
254  QwtArraySeriesData<QPointF>( samples )
255 {
256 }
257 
267 {
268  if ( d_boundingRect.width() < 0.0 )
269  d_boundingRect = qwtBoundingRect( *this );
270 
271  return d_boundingRect;
272 }
273 
279  const QVector<QwtPoint3D> &samples ):
280  QwtArraySeriesData<QwtPoint3D>( samples )
281 {
282 }
283 
293 {
294  if ( d_boundingRect.width() < 0.0 )
295  d_boundingRect = qwtBoundingRect( *this );
296 
297  return d_boundingRect;
298 }
299 
307 {
308 }
309 
319 {
320  if ( d_boundingRect.width() < 0.0 )
321  d_boundingRect = qwtBoundingRect( *this );
322 
323  return d_boundingRect;
324 }
325 
333  d_maxMagnitude( -1.0 )
334 {
335 }
336 
346 {
347  if ( d_boundingRect.width() < 0.0 )
348  d_boundingRect = qwtBoundingRect( *this );
349 
350  return d_boundingRect;
351 }
352 
354 {
355  if ( d_maxMagnitude < 0.0 )
356  {
357  double max = 0.0;
358 
359  for ( uint i = 0; i < size(); i++ )
360  {
361  const QwtVectorFieldSample s = sample( i );
362 
363  const double l = s.vx * s.vx + s.vy * s.vy;
364  if ( l > max )
365  max = l;
366  }
367 
368  d_maxMagnitude = std::sqrt( max );
369  }
370 
371  return d_maxMagnitude;
372 }
373 
380  QwtArraySeriesData<QwtSetSample>( samples )
381 {
382 }
383 
393 {
394  if ( d_boundingRect.width() < 0.0 )
395  d_boundingRect = qwtBoundingRect( *this );
396 
397  return d_boundingRect;
398 }
399 
407 {
408 }
409 
419 {
420  if ( d_boundingRect.width() < 0.0 )
421  d_boundingRect = qwtBoundingRect( *this );
422 
423  return d_boundingRect;
424 }
Open-High-Low-Close sample used in financial charts.
Definition: qwt_samples.h:147
QwtTradingChartData(const QVector< QwtOHLCSample > &=QVector< QwtOHLCSample >())
A point in polar coordinates.
QwtIntervalSeriesData(const QVector< QwtIntervalSample > &=QVector< QwtIntervalSample >())
QwtInterval boundingInterval() const
Calculate the bounding interval of the OHLC values.
Definition: qwt_samples.h:225
QRectF d_boundingRect
Can be used to cache a calculated bounding rectangle.
double value
value
Definition: qwt_samples.h:89
A class representing an interval.
Definition: qwt_interval.h:22
const QVector< QPointF > samples() const
double minValue() const
Definition: qwt_interval.h:190
virtual QRectF boundingRect() const QWT_OVERRIDE
Calculate the bounding rectangle.
Abstract interface for iterating over samples.
double radius() const
Returns the radius.
virtual QRectF boundingRect() const QWT_OVERRIDE
Calculate the bounding rectangle.
double y() const
Definition: qwt_point_3d.h:107
double azimuth() const
Returns the azimuth.
double maxValue() const
Definition: qwt_interval.h:196
virtual size_t size() const QWT_OVERRIDE
A sample of the types (x1...xn, y) or (x, y1..yn)
Definition: qwt_samples.h:77
#define max(A, B)
Definition: Socket.h:88
QwtPoint3D class defines a 3D point in double coordinates.
Definition: qwt_point_3d.h:21
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)
virtual QwtVectorFieldSample sample(size_t index) const QWT_OVERRIDE
QwtSetSeriesData(const QVector< QwtSetSample > &=QVector< QwtSetSample >())
Template class for data, that is organized as QVector.
double x() const
Definition: qwt_point_3d.h:101
virtual double maxMagnitude() const
virtual QRectF boundingRect() const QWT_OVERRIDE
Calculate the bounding rectangle.
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 >())
double width() const
Return the width of an interval.
Definition: qwt_interval.h:225
QVector< double > set
Vector of values associated to value.
Definition: qwt_samples.h:92
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 Sun Dec 6 2020 03:48:10