Loading...
Searching...
No Matches
qwt_series_data.cpp
/******************************************************************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include "qwt_series_data.h"
#include "qwt_point_polar.h"
static inline QRectF qwtBoundingRect( const QPointF& sample )
{
return QRectF( sample.x(), sample.y(), 0.0, 0.0 );
}
static inline QRectF qwtBoundingRect( const QwtPoint3D& sample )
{
return QRectF( sample.x(), sample.y(), 0.0, 0.0 );
}
static inline QRectF qwtBoundingRect( const QwtPointPolar& sample )
{
return QRectF( sample.azimuth(), sample.radius(), 0.0, 0.0 );
}
static inline QRectF qwtBoundingRect( const QwtIntervalSample& sample )
{
return QRectF( sample.interval.minValue(), sample.value,
sample.interval.maxValue() - sample.interval.minValue(), 0.0 );
}
static inline QRectF qwtBoundingRect( const QwtSetSample& sample )
{
if ( sample.set.empty() )
return QRectF( sample.value, 0.0, 0.0, -1.0 );
double minY = sample.set[0];
double maxY = sample.set[0];
for ( int i = 1; i < sample.set.size(); i++ )
{
if ( sample.set[i] < minY )
minY = sample.set[i];
if ( sample.set[i] > maxY )
maxY = sample.set[i];
}
return QRectF( sample.value, minY, 0.0, maxY - minY );
}
static inline QRectF qwtBoundingRect( const QwtOHLCSample& sample )
{
const QwtInterval interval = sample.boundingInterval();
return QRectF( interval.minValue(), sample.time, interval.width(), 0.0 );
}
static inline QRectF qwtBoundingRect( const QwtVectorFieldSample& sample )
{
/*
When displaying a sample as an arrow its length will be
proportional to the magnitude - but not the same.
As the factor between length and magnitude is not known
we can't include vx/vy into the bounding rectangle.
*/
return QRectF( sample.x, sample.y, 0, 0 );
}
template< class T >
QRectF qwtBoundingRectT( const QwtSeriesData< T >& series, int from, int to )
{
QRectF boundingRect( 1.0, 1.0, -2.0, -2.0 ); // invalid;
if ( from < 0 )
from = 0;
if ( to < 0 )
to = series.size() - 1;
if ( to < from )
return boundingRect;
int i;
for ( i = from; i <= to; i++ )
{
const QRectF rect = qwtBoundingRect( series.sample( i ) );
if ( rect.width() >= 0.0 && rect.height() >= 0.0 )
{
boundingRect = rect;
i++;
break;
}
}
for ( ; i <= to; i++ )
{
const QRectF rect = qwtBoundingRect( series.sample( i ) );
if ( rect.width() >= 0.0 && rect.height() >= 0.0 )
{
boundingRect.setLeft( qMin( boundingRect.left(), rect.left() ) );
boundingRect.setRight( qMax( boundingRect.right(), rect.right() ) );
boundingRect.setTop( qMin( boundingRect.top(), rect.top() ) );
boundingRect.setBottom( qMax( boundingRect.bottom(), rect.bottom() ) );
}
}
return boundingRect;
}
QRectF qwtBoundingRect( const QwtSeriesData< QPointF >& series, int from, int to )
{
return qwtBoundingRectT< QPointF >( series, from, to );
}
QRectF qwtBoundingRect(
const QwtSeriesData< QwtPoint3D >& series, int from, int to )
{
return qwtBoundingRectT< QwtPoint3D >( series, from, to );
}
QRectF qwtBoundingRect(
const QwtSeriesData< QwtPointPolar >& series, int from, int to )
{
return qwtBoundingRectT< QwtPointPolar >( series, from, to );
}
QRectF qwtBoundingRect(
const QwtSeriesData< QwtIntervalSample >& series, int from, int to )
{
return qwtBoundingRectT< QwtIntervalSample >( series, from, to );
}
QRectF qwtBoundingRect(
const QwtSeriesData< QwtOHLCSample >& series, int from, int to )
{
return qwtBoundingRectT< QwtOHLCSample >( series, from, to );
}
QRectF qwtBoundingRect(
const QwtSeriesData< QwtSetSample >& series, int from, int to )
{
return qwtBoundingRectT< QwtSetSample >( series, from, to );
}
QRectF qwtBoundingRect(
const QwtSeriesData< QwtVectorFieldSample >& series, int from, int to )
{
return qwtBoundingRectT< QwtVectorFieldSample >( series, from, to );
}
QwtInterval
A class representing an interval.
Definition qwt_interval.h:23
QwtInterval::minValue
double minValue() const
Definition qwt_interval.h:192
QwtInterval::width
double width() const
Return the width of an interval.
Definition qwt_interval.h:227
QwtInterval::maxValue
double maxValue() const
Definition qwt_interval.h:198
QwtIntervalSample
A sample of the types (x1-x2, y) or (x, y1-y2)
Definition qwt_samples.h:21
QwtIntervalSample::interval
QwtInterval interval
Interval.
Definition qwt_samples.h:34
QwtIntervalSample::value
double value
Value.
Definition qwt_samples.h:31
QwtOHLCSample
Open-High-Low-Close sample used in financial charts.
Definition qwt_samples.h:144
QwtOHLCSample::time
double time
Definition qwt_samples.h:158
QwtOHLCSample::boundingInterval
QwtInterval boundingInterval() const
Calculate the bounding interval of the OHLC values.
Definition qwt_samples.h:220
QwtPoint3D
QwtPoint3D class defines a 3D point in double coordinates.
Definition qwt_point_3d.h:23
QwtPoint3D::y
double y() const
Definition qwt_point_3d.h:109
QwtPoint3D::x
double x() const
Definition qwt_point_3d.h:103
QwtPointPolar
A point in polar coordinates.
Definition qwt_point_polar.h:29
QwtPointPolar::radius
double radius() const
Returns the radius.
Definition qwt_point_polar.h:102
QwtPointPolar::azimuth
double azimuth() const
Returns the azimuth.
Definition qwt_point_polar.h:108
QwtSeriesData
Abstract interface for iterating over samples.
Definition qwt_series_data.h:50
QwtSeriesData::size
virtual size_t size() const =0
QwtSeriesData::sample
virtual T sample(size_t i) const =0
QwtSetSample
A sample of the types (x1...xn, y) or (x, y1..yn)
Definition qwt_samples.h:74
QwtSetSample::value
double value
value
Definition qwt_samples.h:85
QwtSetSample::set
QVector< double > set
Vector of values associated to value.
Definition qwt_samples.h:88
QwtVectorFieldSample
Sample used in vector fields.
Definition qwt_samples.h:244
QwtVectorFieldSample::y
double y
y coordinate of the position
Definition qwt_samples.h:260
QwtVectorFieldSample::x
double x
x coordinate of the position
Definition qwt_samples.h:257