kchart

KDChartPlaneSeries.cpp

00001 /* -*- Mode: C++ -*-
00002    KDChart - a multi-platform charting engine
00003    */
00004 
00005 /****************************************************************************
00006  ** Copyright (C) 2001-2003 Klarälvdalens Datakonsult AB.  All rights reserved.
00007  **
00008  ** This file is part of the KDChart library.
00009  **
00010  ** This file may be distributed and/or modified under the terms of the
00011  ** GNU General Public License version 2 as published by the Free Software
00012  ** Foundation and appearing in the file LICENSE.GPL included in the
00013  ** packaging of this file.
00014  **
00015  ** Licensees holding valid commercial KDChart licenses may use this file in
00016  ** accordance with the KDChart Commercial License Agreement provided with
00017  ** the Software.
00018  **
00019  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021  **
00022  ** See http://www.klaralvdalens-datakonsult.se/?page=products for
00023  **   information about KDChart Commercial License Agreements.
00024  **
00025  ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
00026  ** licensing are not clear to you.
00027  **
00028  **********************************************************************/
00029 
00030 
00031 #include "KDChartPlaneSeries.h"
00032 
00033 KDChartPlaneSeries::KDChartPlaneSeries( bool isX, double location )
00034 {
00035     setXAxis(isX);
00036     setLocation(location);
00037 }
00038 
00039 KDChartPlaneSeries::~KDChartPlaneSeries()
00040 {
00041 }
00042 
00043 
00044 uint KDChartPlaneSeries::rows() const
00045 {
00046     return 2;
00047 }
00048 
00049 
00050 const KDChartData& KDChartPlaneSeries::cell( uint row ) const
00051 {
00052     switch (row)
00053     {
00054         case 0: return _start;
00055         case 1: return _stop;
00056         default: Q_ASSERT(0);
00057                  return _start;  // won't get here
00058     }
00059 }
00060 
00061 void KDChartPlaneSeries::setCell( uint row, const KDChartData& element)
00062 {
00063     Q_ASSERT(0);    // not possible
00064     // avoid compiler warnings
00065     row = (uint)element.doubleValue();
00066 }
00067 
00068 void KDChartPlaneSeries::expand( uint rows )
00069 {
00070     Q_ASSERT(0);    // not possible
00071     // avoid compiler warnings
00072     rows = 0;
00073 }
00074 
00075 
00076 
00077 // NOW for our special API.
00078 bool KDChartPlaneSeries::isXAxis() const
00079 {
00080     return _isX;
00081 }
00082 
00083 double KDChartPlaneSeries::location() const
00084 {
00085     return _location;
00086 }
00087 
00088 void KDChartPlaneSeries::setXAxis( bool isX )
00089 {
00090     _isX = isX;
00091     update();
00092 }
00093 
00094 void KDChartPlaneSeries::setLocation( double location )
00095 {
00096     _location = location;
00097     update();
00098 }
00099 
00100 // this is the magic part of the class.
00101 // draw a line from DBL_MIN to DBL_MAX.
00102 void KDChartPlaneSeries::update()
00103 {
00104     if ( _isX )
00105     {
00106         _start = KDChartData( DBL_MIN, _location );
00107         _stop = KDChartData( DBL_MAX, _location );
00108     }
00109     else
00110     {
00111         _start = KDChartData( _location, DBL_MIN );
00112         _stop = KDChartData( _location, DBL_MAX );
00113     }
00114 }
00115 
00116 
00117 
00118 // we return !ok if its on the infinite axis
00119 double KDChartPlaneSeries::maxValue( int coordinate, bool &ok ) const
00120 {
00121     // coordinate==0 is the x value...
00122     // is not ok
00123     if ( _isX == (coordinate==0) )
00124     {
00125         ok = false;
00126         return 0;
00127     }
00128 
00129     ok = true;
00130     return _location;
00131 }
00132 
00133 
00134 
00135 double KDChartPlaneSeries::minValue( int coordinate, bool &ok ) const
00136 {
00137     return maxValue(coordinate,ok);
00138 }
KDE Home | KDE Accessibility Home | Description of Access Keys