[4271] | 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_math.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 | {
|
---|
[9383] | 36 | if ( sample.set.empty() )
|
---|
| 37 | return QRectF( sample.value, 0.0, 0.0, -1.0 );
|
---|
| 38 |
|
---|
[8127] | 39 | double minY = sample.set[0];
|
---|
| 40 | double maxY = sample.set[0];
|
---|
[4271] | 41 |
|
---|
[8127] | 42 | for ( int i = 1; i < sample.set.size(); i++ )
|
---|
[4271] | 43 | {
|
---|
[8127] | 44 | if ( sample.set[i] < minY )
|
---|
| 45 | minY = sample.set[i];
|
---|
[9383] | 46 |
|
---|
[8127] | 47 | if ( sample.set[i] > maxY )
|
---|
| 48 | maxY = sample.set[i];
|
---|
[4271] | 49 | }
|
---|
| 50 |
|
---|
[9383] | 51 | return QRectF( sample.value, minY, 0.0, maxY - minY );
|
---|
[4271] | 52 | }
|
---|
| 53 |
|
---|
[8127] | 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 |
|
---|
[4271] | 60 | /*!
|
---|
[8127] | 61 | \brief Calculate the bounding rectangle of a series subset
|
---|
[4271] | 62 |
|
---|
| 63 | Slow implementation, that iterates over the series.
|
---|
| 64 |
|
---|
| 65 | \param series Series
|
---|
| 66 | \param from Index of the first sample, <= 0 means from the beginning
|
---|
| 67 | \param to Index of the last sample, < 0 means to the end
|
---|
| 68 |
|
---|
| 69 | \return Bounding rectangle
|
---|
| 70 | */
|
---|
| 71 |
|
---|
| 72 | template <class T>
|
---|
[8127] | 73 | QRectF qwtBoundingRectT(
|
---|
[4271] | 74 | const QwtSeriesData<T>& series, int from, int to )
|
---|
| 75 | {
|
---|
| 76 | QRectF boundingRect( 1.0, 1.0, -2.0, -2.0 ); // invalid;
|
---|
| 77 |
|
---|
| 78 | if ( from < 0 )
|
---|
| 79 | from = 0;
|
---|
| 80 |
|
---|
| 81 | if ( to < 0 )
|
---|
| 82 | to = series.size() - 1;
|
---|
| 83 |
|
---|
| 84 | if ( to < from )
|
---|
| 85 | return boundingRect;
|
---|
| 86 |
|
---|
| 87 | int i;
|
---|
| 88 | for ( i = from; i <= to; i++ )
|
---|
| 89 | {
|
---|
| 90 | const QRectF rect = qwtBoundingRect( series.sample( i ) );
|
---|
| 91 | if ( rect.width() >= 0.0 && rect.height() >= 0.0 )
|
---|
| 92 | {
|
---|
| 93 | boundingRect = rect;
|
---|
| 94 | i++;
|
---|
| 95 | break;
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | for ( ; 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.setLeft( qMin( boundingRect.left(), rect.left() ) );
|
---|
| 105 | boundingRect.setRight( qMax( boundingRect.right(), rect.right() ) );
|
---|
| 106 | boundingRect.setTop( qMin( boundingRect.top(), rect.top() ) );
|
---|
| 107 | boundingRect.setBottom( qMax( boundingRect.bottom(), rect.bottom() ) );
|
---|
| 108 | }
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | return boundingRect;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | /*!
|
---|
[8127] | 115 | \brief Calculate the bounding rectangle of a series subset
|
---|
[4271] | 116 |
|
---|
| 117 | Slow implementation, that iterates over the series.
|
---|
| 118 |
|
---|
| 119 | \param series Series
|
---|
| 120 | \param from Index of the first sample, <= 0 means from the beginning
|
---|
| 121 | \param to Index of the last sample, < 0 means to the end
|
---|
| 122 |
|
---|
| 123 | \return Bounding rectangle
|
---|
| 124 | */
|
---|
[8127] | 125 | QRectF qwtBoundingRect(
|
---|
[4271] | 126 | const QwtSeriesData<QPointF> &series, int from, int to )
|
---|
| 127 | {
|
---|
| 128 | return qwtBoundingRectT<QPointF>( series, from, to );
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | /*!
|
---|
[8127] | 132 | \brief Calculate the bounding rectangle of a series subset
|
---|
[4271] | 133 |
|
---|
| 134 | Slow implementation, that iterates over the series.
|
---|
| 135 |
|
---|
| 136 | \param series Series
|
---|
| 137 | \param from Index of the first sample, <= 0 means from the beginning
|
---|
| 138 | \param to Index of the last sample, < 0 means to the end
|
---|
| 139 |
|
---|
| 140 | \return Bounding rectangle
|
---|
| 141 | */
|
---|
[8127] | 142 | QRectF qwtBoundingRect(
|
---|
[4271] | 143 | const QwtSeriesData<QwtPoint3D> &series, int from, int to )
|
---|
| 144 | {
|
---|
| 145 | return qwtBoundingRectT<QwtPoint3D>( series, from, to );
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | /*!
|
---|
[8127] | 149 | \brief Calculate the bounding rectangle of a series subset
|
---|
[4271] | 150 |
|
---|
| 151 | The horizontal coordinates represent the azimuth, the
|
---|
| 152 | vertical coordinates the radius.
|
---|
| 153 |
|
---|
| 154 | Slow implementation, that iterates over the series.
|
---|
| 155 |
|
---|
| 156 | \param series Series
|
---|
| 157 | \param from Index of the first sample, <= 0 means from the beginning
|
---|
| 158 | \param to Index of the last sample, < 0 means to the end
|
---|
| 159 |
|
---|
| 160 | \return Bounding rectangle
|
---|
| 161 | */
|
---|
[8127] | 162 | QRectF qwtBoundingRect(
|
---|
[4271] | 163 | const QwtSeriesData<QwtPointPolar> &series, int from, int to )
|
---|
| 164 | {
|
---|
| 165 | return qwtBoundingRectT<QwtPointPolar>( series, from, to );
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | /*!
|
---|
[8127] | 169 | \brief Calculate the bounding rectangle of a series subset
|
---|
[4271] | 170 |
|
---|
| 171 | Slow implementation, that iterates over the series.
|
---|
| 172 |
|
---|
| 173 | \param series Series
|
---|
| 174 | \param from Index of the first sample, <= 0 means from the beginning
|
---|
| 175 | \param to Index of the last sample, < 0 means to the end
|
---|
| 176 |
|
---|
| 177 | \return Bounding rectangle
|
---|
| 178 | */
|
---|
[8127] | 179 | QRectF qwtBoundingRect(
|
---|
[4271] | 180 | const QwtSeriesData<QwtIntervalSample>& series, int from, int to )
|
---|
| 181 | {
|
---|
| 182 | return qwtBoundingRectT<QwtIntervalSample>( series, from, to );
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | /*!
|
---|
[8127] | 186 | \brief Calculate the bounding rectangle of a series subset
|
---|
[4271] | 187 |
|
---|
| 188 | Slow implementation, that iterates over the series.
|
---|
| 189 |
|
---|
| 190 | \param series Series
|
---|
| 191 | \param from Index of the first sample, <= 0 means from the beginning
|
---|
| 192 | \param to Index of the last sample, < 0 means to the end
|
---|
| 193 |
|
---|
| 194 | \return Bounding rectangle
|
---|
| 195 | */
|
---|
[8127] | 196 | QRectF qwtBoundingRect(
|
---|
| 197 | const QwtSeriesData<QwtOHLCSample>& series, int from, int to )
|
---|
| 198 | {
|
---|
| 199 | return qwtBoundingRectT<QwtOHLCSample>( series, from, to );
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | /*!
|
---|
| 203 | \brief Calculate the bounding rectangle of a series subset
|
---|
| 204 |
|
---|
| 205 | Slow implementation, that iterates over the series.
|
---|
| 206 |
|
---|
| 207 | \param series Series
|
---|
| 208 | \param from Index of the first sample, <= 0 means from the beginning
|
---|
| 209 | \param to Index of the last sample, < 0 means to the end
|
---|
| 210 |
|
---|
| 211 | \return Bounding rectangle
|
---|
| 212 | */
|
---|
| 213 | QRectF qwtBoundingRect(
|
---|
[4271] | 214 | const QwtSeriesData<QwtSetSample>& series, int from, int to )
|
---|
| 215 | {
|
---|
| 216 | return qwtBoundingRectT<QwtSetSample>( series, from, to );
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | /*!
|
---|
| 220 | Constructor
|
---|
| 221 | \param samples Samples
|
---|
| 222 | */
|
---|
| 223 | QwtPointSeriesData::QwtPointSeriesData(
|
---|
| 224 | const QVector<QPointF> &samples ):
|
---|
| 225 | QwtArraySeriesData<QPointF>( samples )
|
---|
| 226 | {
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | /*!
|
---|
[8127] | 230 | \brief Calculate the bounding rectangle
|
---|
[4271] | 231 |
|
---|
| 232 | The bounding rectangle is calculated once by iterating over all
|
---|
| 233 | points and is stored for all following requests.
|
---|
| 234 |
|
---|
| 235 | \return Bounding rectangle
|
---|
| 236 | */
|
---|
| 237 | QRectF QwtPointSeriesData::boundingRect() const
|
---|
| 238 | {
|
---|
| 239 | if ( d_boundingRect.width() < 0.0 )
|
---|
| 240 | d_boundingRect = qwtBoundingRect( *this );
|
---|
| 241 |
|
---|
| 242 | return d_boundingRect;
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | /*!
|
---|
| 246 | Constructor
|
---|
| 247 | \param samples Samples
|
---|
| 248 | */
|
---|
| 249 | QwtPoint3DSeriesData::QwtPoint3DSeriesData(
|
---|
| 250 | const QVector<QwtPoint3D> &samples ):
|
---|
| 251 | QwtArraySeriesData<QwtPoint3D>( samples )
|
---|
| 252 | {
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | /*!
|
---|
[8127] | 256 | \brief Calculate the bounding rectangle
|
---|
[4271] | 257 |
|
---|
| 258 | The bounding rectangle is calculated once by iterating over all
|
---|
| 259 | points and is stored for all following requests.
|
---|
| 260 |
|
---|
| 261 | \return Bounding rectangle
|
---|
| 262 | */
|
---|
| 263 | QRectF QwtPoint3DSeriesData::boundingRect() const
|
---|
| 264 | {
|
---|
| 265 | if ( d_boundingRect.width() < 0.0 )
|
---|
| 266 | d_boundingRect = qwtBoundingRect( *this );
|
---|
| 267 |
|
---|
| 268 | return d_boundingRect;
|
---|
| 269 | }
|
---|
| 270 |
|
---|
| 271 | /*!
|
---|
| 272 | Constructor
|
---|
| 273 | \param samples Samples
|
---|
| 274 | */
|
---|
| 275 | QwtIntervalSeriesData::QwtIntervalSeriesData(
|
---|
| 276 | const QVector<QwtIntervalSample> &samples ):
|
---|
| 277 | QwtArraySeriesData<QwtIntervalSample>( samples )
|
---|
| 278 | {
|
---|
| 279 | }
|
---|
| 280 |
|
---|
| 281 | /*!
|
---|
[8127] | 282 | \brief Calculate the bounding rectangle
|
---|
[4271] | 283 |
|
---|
| 284 | The bounding rectangle is calculated once by iterating over all
|
---|
| 285 | points and is stored for all following requests.
|
---|
| 286 |
|
---|
| 287 | \return Bounding rectangle
|
---|
| 288 | */
|
---|
| 289 | QRectF QwtIntervalSeriesData::boundingRect() const
|
---|
| 290 | {
|
---|
| 291 | if ( d_boundingRect.width() < 0.0 )
|
---|
| 292 | d_boundingRect = qwtBoundingRect( *this );
|
---|
| 293 |
|
---|
| 294 | return d_boundingRect;
|
---|
| 295 | }
|
---|
| 296 |
|
---|
| 297 | /*!
|
---|
| 298 | Constructor
|
---|
| 299 | \param samples Samples
|
---|
| 300 | */
|
---|
| 301 | QwtSetSeriesData::QwtSetSeriesData(
|
---|
| 302 | const QVector<QwtSetSample> &samples ):
|
---|
| 303 | QwtArraySeriesData<QwtSetSample>( samples )
|
---|
| 304 | {
|
---|
| 305 | }
|
---|
| 306 |
|
---|
| 307 | /*!
|
---|
[8127] | 308 | \brief Calculate the bounding rectangle
|
---|
[4271] | 309 |
|
---|
| 310 | The bounding rectangle is calculated once by iterating over all
|
---|
| 311 | points and is stored for all following requests.
|
---|
| 312 |
|
---|
| 313 | \return Bounding rectangle
|
---|
| 314 | */
|
---|
| 315 | QRectF QwtSetSeriesData::boundingRect() const
|
---|
| 316 | {
|
---|
| 317 | if ( d_boundingRect.width() < 0.0 )
|
---|
| 318 | d_boundingRect = qwtBoundingRect( *this );
|
---|
| 319 |
|
---|
| 320 | return d_boundingRect;
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 | /*!
|
---|
[8127] | 324 | Constructor
|
---|
| 325 | \param samples Samples
|
---|
[4271] | 326 | */
|
---|
[8127] | 327 | QwtTradingChartData::QwtTradingChartData(
|
---|
| 328 | const QVector<QwtOHLCSample> &samples ):
|
---|
| 329 | QwtArraySeriesData<QwtOHLCSample>( samples )
|
---|
[4271] | 330 | {
|
---|
| 331 | }
|
---|
| 332 |
|
---|
| 333 | /*!
|
---|
[8127] | 334 | \brief Calculate the bounding rectangle
|
---|
[4271] | 335 |
|
---|
| 336 | The bounding rectangle is calculated once by iterating over all
|
---|
| 337 | points and is stored for all following requests.
|
---|
| 338 |
|
---|
| 339 | \return Bounding rectangle
|
---|
| 340 | */
|
---|
[8127] | 341 | QRectF QwtTradingChartData::boundingRect() const
|
---|
[4271] | 342 | {
|
---|
[8127] | 343 | if ( d_boundingRect.width() < 0.0 )
|
---|
[4271] | 344 | d_boundingRect = qwtBoundingRect( *this );
|
---|
| 345 |
|
---|
| 346 | return d_boundingRect;
|
---|
| 347 | }
|
---|