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 }
QwtIntervalSample::interval
QwtInterval interval
Interval.
Definition: qwt_samples.h:41
QwtVectorFieldSample
Sample used in vector fields.
Definition: qwt_samples.h:243
QwtVectorFieldSample::y
double y
y coordinate of the position
Definition: qwt_samples.h:260
QwtInterval::minValue
double minValue() const
Definition: qwt_interval.h:192
qwtBoundingRect
static QRectF qwtBoundingRect(const QPointF &sample)
Definition: qwt_series_data.cpp:13
QwtPointPolar
A point in polar coordinates.
Definition: qwt_point_polar.h:28
QwtPoint3D::y
double y() const
Definition: qwt_point_3d.h:109
QwtOHLCSample::time
double time
Definition: qwt_samples.h:158
QwtInterval
A class representing an interval.
Definition: qwt_interval.h:22
QwtPointPolar::azimuth
double azimuth() const
Returns the azimuth.
Definition: qwt_point_polar.h:108
QwtInterval::width
double width() const
Return the width of an interval.
Definition: qwt_interval.h:227
QwtSetSample
A sample of the types (x1...xn, y) or (x, y1..yn)
Definition: qwt_samples.h:73
qwtBoundingRectT
QRectF qwtBoundingRectT(const QwtSeriesData< T > &series, int from, int to)
Calculate the bounding rectangle of a series subset.
Definition: qwt_series_data.cpp:85
QwtSeriesData
Abstract interface for iterating over samples.
Definition: qwt_plot_barchart.h:18
qwt_point_polar.h
QwtPoint3D::x
double x() const
Definition: qwt_point_3d.h:103
QwtSeriesData::sample
virtual T sample(size_t i) const =0
QwtIntervalSample
A sample of the types (x1-x2, y) or (x, y1-y2)
Definition: qwt_samples.h:20
QwtOHLCSample::boundingInterval
QwtInterval boundingInterval() const
Calculate the bounding interval of the OHLC values.
Definition: qwt_samples.h:220
QwtSetSample::set
QVector< double > set
Vector of values associated to value.
Definition: qwt_samples.h:88
QwtVectorFieldSample::x
double x
x coordinate of the position
Definition: qwt_samples.h:257
QwtSeriesData::size
virtual size_t size() const =0
QwtInterval::maxValue
double maxValue() const
Definition: qwt_interval.h:198
QwtPointPolar::radius
double radius() const
Returns the radius.
Definition: qwt_point_polar.h:102
QwtPoint3D
QwtPoint3D class defines a 3D point in double coordinates.
Definition: qwt_point_3d.h:22
QwtSetSample::value
double value
value
Definition: qwt_samples.h:85
QwtOHLCSample
Open-High-Low-Close sample used in financial charts.
Definition: qwt_samples.h:143
qwt_series_data.h
QwtIntervalSample::value
double value
Value.
Definition: qwt_samples.h:38


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:46