1 /**********************************************************************************************
2     Copyright (C) 2014 Oliver Eichler <oliver.eichler@gmx.de>
3 
4     This program is free software: you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation, either version 3 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License
15     along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 
17 **********************************************************************************************/
18 
19 #include "plot/CPlotAxis.h"
20 #include "plot/CPlotAxisTime.h"
21 #include "plot/CPlotData.h"
22 #include "units/IUnit.h"
23 
CPlotData(axistype_e type,QObject * parent)24 CPlotData::CPlotData(axistype_e type, QObject* parent)
25     : QObject(parent)
26     , axisType(type)
27 {
28     setXAxisType(type);
29     yaxis = new CPlotAxis(this);
30 }
31 
32 
~CPlotData()33 CPlotData::~CPlotData()
34 {
35 }
36 
setXAxisType(axistype_e type)37 void CPlotData::setXAxisType(axistype_e type)
38 {
39     delete xaxis;
40 
41     if(type == eAxisLinear)
42     {
43         xaxis = new CPlotAxis(this);
44     }
45     else
46     {
47         xaxis = new CPlotAxisTime(this);
48     }
49     xaxis->setAutoscale(false);
50 
51     axisType = type;
52 }
53 
setLimits()54 void CPlotData::setLimits()
55 {
56     if(lines.size() == 0 || badData)
57     {
58         return;
59     }
60 
61     {
62         const QPointF& p = lines.first().points.first();
63         xmin = p.x();
64         xmax = p.x();
65         ymin = p.y();
66         ymax = p.y();
67     }
68 
69     for(const line_t& line : qAsConst(lines))
70     {
71         const QPolygonF& points = line.points;
72         for(const QPointF& p : points)
73         {
74             if(p.y() != NOFLOAT)
75             {
76                 xmin = qMin(xmin, p.x());
77                 xmax = qMax(xmax, p.x());
78                 ymin = qMin(ymin, p.y());
79                 ymax = qMax(ymax, p.y());
80             }
81         }
82     }
83 
84     if(xmin == xmax)
85     {
86         badData = true;
87     }
88     else
89     {
90         xaxis->setLimits(xmin, xmax);
91         yaxis->setLimits(ymin, ymax);
92     }
93 }
94