series_data.h
Go to the documentation of this file.
1 #ifndef SERIES_DATA_H
2 #define SERIES_DATA_H
3 
4 #include "PlotJuggler/plotdata.h"
5 #include "qwt_series_data.h"
6 
7 class DataSeriesBase: public QwtSeriesData<QPointF>
8 {
9 
10 public:
11  DataSeriesBase(const PlotData* transformed):
12  _transformed_data(transformed),
13  _time_offset(0)
14  {}
15 
16  virtual QPointF sample( size_t i ) const override
17  {
18  const auto& p = _transformed_data->at(i);
19  return QPointF(p.x - _time_offset, p.y);
20  }
21 
22  virtual size_t size() const override
23  {
24  return _transformed_data->size();
25  }
26 
27  QRectF boundingRect() const override
28  {
29  QRectF box = _bounding_box;
30  box.setLeft( _bounding_box.left() - _time_offset );
31  box.setRight( _bounding_box.right() - _time_offset );
32  return box;
33  }
34 
35  void setTimeOffset(double offset)
36  {
37  _time_offset = offset;
38  }
39 
40 
41  void calculateBoundingBox();
42 
43  virtual PlotData::RangeValueOpt getVisualizationRangeY(PlotData::RangeTime range_X) = 0;
44 
45  virtual nonstd::optional<QPointF> sampleFromTime(double t) = 0;
46 
47  virtual bool updateCache() = 0;
48 
50  {
51  if( this->size() < 2 )
52  return PlotData::RangeTimeOpt();
53  else{
55  _bounding_box.right() - _time_offset } );
56  }
57  }
58 
59  const PlotData* transformedData() const { return _transformed_data; }
60 
61 protected:
62  QRectF _bounding_box;
63 
64 private:
66  double _time_offset;
67 };
68 
69 //--------------------------------------------
71 {
72  if( _transformed_data->size() == 0)
73  {
74  _bounding_box = QRectF();
75  return;
76  }
77 
78  double min_y = _transformed_data->front().y;
79  double max_y = _transformed_data->front().y;
80 
81  for (const auto& p: *_transformed_data )
82  {
83  if( p.y < min_y )
84  {
85  min_y = p.y;
86  }
87  else if( p.y > max_y )
88  {
89  max_y = p.y;
90  }
91  }
92 
93  _bounding_box.setLeft( _transformed_data->front().x );
94  _bounding_box.setRight( _transformed_data->back().x );
95  _bounding_box.setBottom( min_y );
96  _bounding_box.setTop( max_y );
97 }
98 
99 #endif // SERIES_DATA_H
100 
101 
const Point & at(size_t index) const
Definition: plotdata.h:288
virtual size_t size() const override
Definition: series_data.h:22
virtual nonstd::optional< QPointF > sampleFromTime(double t)=0
virtual PlotData::RangeTimeOpt getVisualizationRangeX()
Definition: series_data.h:49
Abstract interface for iterating over samples.
const PlotData * transformedData() const
Definition: series_data.h:59
double _time_offset
Definition: series_data.h:66
void setTimeOffset(double offset)
Definition: series_data.h:35
void calculateBoundingBox()
Definition: series_data.h:70
QRectF boundingRect() const override
Definition: series_data.h:27
virtual PlotData::RangeValueOpt getVisualizationRangeY(PlotData::RangeTime range_X)=0
const Point & front() const
Definition: plotdata.h:112
DataSeriesBase(const PlotData *transformed)
Definition: series_data.h:11
QRectF _bounding_box
Definition: series_data.h:62
virtual size_t size() const
Definition: plotdata.h:308
virtual bool updateCache()=0
const PlotData * _transformed_data
Definition: series_data.h:65
virtual QPointF sample(size_t i) const override
Definition: series_data.h:16
nonstd::optional< RangeTime > RangeTimeOpt
Definition: plotdata.h:38


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:18