kchart

KDChartPlaneSeries.cpp
1/*
2 KDChart - a multi-platform charting engine
3 */
4
5/****************************************************************************
6 ** Copyright (C) 2001-2003 Klarälvdalens Datakonsult AB. All rights reserved.
7 **
8 ** This file is part of the KDChart library.
9 **
10 ** This file may be distributed and/or modified under the terms of the
11 ** GNU General Public License version 2 as published by the Free Software
12 ** Foundation and appearing in the file LICENSE.GPL included in the
13 ** packaging of this file.
14 **
15 ** Licensees holding valid commercial KDChart licenses may use this file in
16 ** accordance with the KDChart Commercial License Agreement provided with
17 ** the Software.
18 **
19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 **
22 ** See http://www.klaralvdalens-datakonsult.se/?page=products for
23 ** information about KDChart Commercial License Agreements.
24 **
25 ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
26 ** licensing are not clear to you.
27 **
28 **********************************************************************/
29
30
31#include "KDChartPlaneSeries.h"
32
33KDChartPlaneSeries::KDChartPlaneSeries( bool isX, double location )
34{
35 setXAxis(isX);
36 setLocation(location);
37}
38
39KDChartPlaneSeries::~KDChartPlaneSeries()
40{
41}
42
43
44uint KDChartPlaneSeries::rows() const
45{
46 return 2;
47}
48
49
50const KDChartData& KDChartPlaneSeries::cell( uint row ) const
51{
52 switch (row)
53 {
54 case 0: return _start;
55 case 1: return _stop;
56 default: Q_ASSERT(0);
57 return _start; // won't get here
58 }
59}
60
61void KDChartPlaneSeries::setCell( uint row, const KDChartData& element)
62{
63 Q_ASSERT(0); // not possible
64 // avoid compiler warnings
65 row = (uint)element.doubleValue();
66}
67
68void KDChartPlaneSeries::expand( uint rows )
69{
70 Q_ASSERT(0); // not possible
71 // avoid compiler warnings
72 rows = 0;
73}
74
75
76
77// NOW for our special API.
78bool KDChartPlaneSeries::isXAxis() const
79{
80 return _isX;
81}
82
83double KDChartPlaneSeries::location() const
84{
85 return _location;
86}
87
88void KDChartPlaneSeries::setXAxis( bool isX )
89{
90 _isX = isX;
91 update();
92}
93
94void KDChartPlaneSeries::setLocation( double location )
95{
96 _location = location;
97 update();
98}
99
100// this is the magic part of the class.
101// draw a line from DBL_MIN to DBL_MAX.
102void KDChartPlaneSeries::update()
103{
104 if ( _isX )
105 {
106 _start = KDChartData( DBL_MIN, _location );
107 _stop = KDChartData( DBL_MAX, _location );
108 }
109 else
110 {
111 _start = KDChartData( _location, DBL_MIN );
112 _stop = KDChartData( _location, DBL_MAX );
113 }
114}
115
116
117
118// we return !ok if its on the infinite axis
119double KDChartPlaneSeries::maxValue( int coordinate, bool &ok ) const
120{
121 // coordinate==0 is the x value...
122 // is not ok
123 if ( _isX == (coordinate==0) )
124 {
125 ok = false;
126 return 0;
127 }
128
129 ok = true;
130 return _location;
131}
132
133
134
135double KDChartPlaneSeries::minValue( int coordinate, bool &ok ) const
136{
137 return maxValue(coordinate,ok);
138}
Encapsulates one data cell in a chart.
double doubleValue(int valNo=1) const
Returns the double value represented by this object, or DBL_MIN if this object does not represent a d...