kchart

KDChartAxesPainter.h
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#ifndef __KDCHARTAXESPAINTER_H__
30#define __KDCHARTAXESPAINTER_H__
31
32#include <tqpen.h>
33#include <tqpainter.h>
34
35#include <KDChartPainter.h>
36#include <KDChartTable.h>
37#include <KDChartAxisParams.h>
38
39class TQDateTime;
40class KDChartParams;
41
43{
44 protected:
46 virtual ~KDChartAxesPainter();
47
48 virtual void paintAxes( TQPainter* painter,
50
51 virtual void paintData( TQPainter* painter,
53 bool paint2nd,
54 KDChartDataRegionList* regions );
55
56 // note: Classes inheriting from KDChartAxesPainter
57 // MUST implement the following abstract functions:
58
59 // Returns whether a normal chart is to be drawn
60 // or a stacked or percentage (or ... ) chart .
61 virtual bool isNormalMode() const = 0;
62
63 // Returns the number of pixels to be added to the clipping area's height
64 // to make room for special arrows indicating oversized, cut data entries.
65 // Chart classes not drawing such indicators must return 0.
66 virtual int clipShiftUp( bool normalMode, double areaWidthP1000 ) const = 0;
67
68 // The actual, chart type specific drawing of the data.
69 virtual void specificPaintData( TQPainter* painter,
70 const TQRect& ourClipRect,
72 KDChartDataRegionList* regions,
73 const KDChartAxisParams* axisPara,
74 bool bNormalMode,
75 uint chart,
76 double logWidth,
77 double areaWidthP1000,
78 double logHeight,
79 double axisYOffset,
80 double minColumnValue,
81 double maxColumnValue,
82 double columnValueDistance,
83 uint chartDatasetStart,
84 uint chartDatasetEnd,
85 uint datasetStart,
86 uint datasetEnd ) = 0;
87
88 virtual bool calculateAllAxesLabelTextsAndCalcValues(
89 TQPainter* painter,
91 double areaWidthP1000,
92 double areaHeightP1000,
93 double& delimLen );
94
95 private:
96 public:
97 // special infos needed by the different painters' implementations
98 // of the specificPaintData() function
99 struct abscissaInfos{
100 const KDChartAxisParams* abscissaPara;
101 bool bCenterThePoints;
102 bool bAbscissaDecreasing;
103 bool bAbscissaIsLogarithmic;
104 bool bCellsHaveSeveralCoordinates;
105 int numValues;
106 int numLabels;
107 bool bAbscissaHasTrueAxisValues;
108 double abscissaStart;
109 double abscissaEnd;
110 double abscissaSpan;
111 double abscissaDelta;
112 bool bAbscissaHasTrueAxisDtValues;
113 double dtLowPos;
114 double dtHighPos;
115 TQDateTime abscissaDtStart;
116 TQDateTime abscissaDtEnd;
117 bool bScaleLessThanDay;
118 double abscissaDtSpan;
119 double abscissaDtPixelsPerScaleUnit;
120 double pointDist;
121 double abscissaPixelsPerUnit;
122 double abscissaZeroPos;
123 };
124 static void calculateAbscissaInfos(
125 const KDChartParams& params,
126 const KDChartTableDataBase& data,
127 uint datasetStart,
128 uint datasetEnd,
129 double logWidth,
130 const TQRect& dataRect,
131 abscissaInfos& infos );
132 static bool calculateAbscissaAxisValue( const TQVariant& value,
133 abscissaInfos& ai,
134 int colNumber,
135 double& xValue );
136
137 static void saveDrawLine( TQPainter& painter,
138 TQPoint pA,
139 TQPoint pZ,
140 TQPen pen );
141 static void calculateLabelTexts(
142 TQPainter* painter,
143 const KDChartTableDataBase& data,
144 const KDChartParams& params,
145 uint axisNumber,
146 double averageValueP1000,
147 double delimLen,
148 // start of return parameters
149 KDChartAxisParams::AxisPos& basicPos,
150 TQPoint& orig,
151 TQPoint& dest,
152 double& pXDeltaFactor,
153 double& pYDeltaFactor,
154 double& pXDelimDeltaFaktor,
155 double& pYDelimDeltaFaktor,
156 double& nSubDelimFactor,
157 double& pDelimDelta,
158 double& nTxtHeight,
159 double& pTextsX,
160 double& pTextsY,
161 double& pTextsW,
162 double& pTextsH,
163 int& textAlign,
164 bool& isLogarithmic,
165 bool& isDateTime,
166 bool& autoDtLabels,
167 TQDateTime& dtLow,
168 TQDateTime& dtHigh,
169 KDChartAxisParams::ValueScale& dtDeltaScale,
170 bool adjustTheValues = false,
171 double trueDelta = 0.0,
172 double trueDeltaPix = 0.0 );
173 static void calculateBasicTextFactors( double nTxtHeight,
174 const KDChartAxisParams& para,
175 double averageValueP1000,
176 KDChartAxisParams::AxisPos basicPos,
177 const TQPoint& orig,
178 double delimLen,
179 uint nLabels,
180 // start of return parameters
181 double& pDelimDelta,
182 double& pTextsX,
183 double& pTextsY,
184 double& pTextsW,
185 double& pTextsH,
186 int& textAlign );
187 static TQString truncateBehindComma( const double nVal,
188 const int behindComma,
189 const double nDelta,
190 int& trueBehindComma );
191 static TQString applyLabelsFormat( const double nVal,
192 int divPow10,
193 int behindComma,
194 double nDelta,
195 int& trueBehindComma,
197 const TQString& decimalPoint,
198 const TQString& thousandsPoint,
199 const TQString& prefix,
200 const TQString& postfix,
201 int totalLen,
202 const TQChar& padFill,
203 bool blockAlign );
204 static void calculateOrdinateFactors( const KDChartAxisParams& para,
205 bool bLogarithmic,
206 double& nDist,
207 double& nDivisor,
208 double& nRound,
209 double& nDelta,
210 double& nSubDelimFactor,
211 double& nLow,
212 double& nHigh,
213 bool findNextRound = false );
214 static void dtAddSecs( const TQDateTime& org, const int secs, TQDateTime& dest );
215 static void dtAddDays( const TQDateTime& org, const int days, TQDateTime& dest );
216 static void dtAddMonths( const TQDateTime& org, const int months, TQDateTime& dest );
217 static void dtAddYears( const TQDateTime& org, const int years, TQDateTime& dest );
218};
219
220#endif
Provide access to the chart axis parameters.
A common base class for classes that implement chart painters for chart types ith axes.
static TQString truncateBehindComma(const double nVal, const int behindComma, const double nDelta, int &trueBehindComma)
Takes double nVal and returns a TQString showing the amount of digits behind the comma that was speci...
virtual ~KDChartAxesPainter()
Destructor.
static void calculateBasicTextFactors(double nTxtHeight, const KDChartAxisParams &para, double averageValueP1000, KDChartAxisParams::AxisPos basicPos, const TQPoint &orig, double delimLen, uint nLabels, double &pDelimDelta, double &pTextsX, double &pTextsY, double &pTextsW, double &pTextsH, int &textAlign)
Calculates some label text factors needed by function calculateLabelTexts()
static void calculateLabelTexts(TQPainter *painter, const KDChartTableDataBase &data, const KDChartParams &params, uint axisNumber, double averageValueP1000, double delimLen, KDChartAxisParams::AxisPos &basicPos, TQPoint &orig, TQPoint &dest, double &pXDeltaFactor, double &pYDeltaFactor, double &pXDelimDeltaFaktor, double &pYDelimDeltaFaktor, double &nSubDelimFactor, double &pDelimDelta, double &nTxtHeight, double &pTextsX, double &pTextsY, double &pTextsW, double &pTextsH, int &textAlign, bool &isLogarithmic, bool &isDateTime, bool &autoDtLabels, TQDateTime &dtLow, TQDateTime &dtHigh, KDChartAxisParams::ValueScale &dtDeltaScale, bool adjustTheValues=false, double trueDelta=0.0, double trueDeltaPix=0.0)
Calculates the actual label texts for one axis.
virtual void paintData(TQPainter *painter, KDChartTableDataBase *data, bool paint2nd, KDChartDataRegionList *regions)
Paints the actual data area and registers the region for the data points if regions is not 0.
virtual void paintAxes(TQPainter *painter, KDChartTableDataBase *data)
Paints the actual axes areas.
static void calculateOrdinateFactors(const KDChartAxisParams &para, bool bLogarithmic, double &nDist, double &nDivisor, double &nRound, double &nDelta, double &nSubDelimFactor, double &nLow, double &nHigh, bool findNextRound=false)
Calculates the factors to be used for calculating ordinate labels texts.
access the chart axis parameters.
The collection class used by KD Chart to store data region information.
NumberNotation
Number notation specifies the general way, how a number is to be shown.
An abstract base class that defines an interface for classes that implement chart drawing.
Bundles the display parameters of a chart.
KD Chart's build-in table data for an easy way of storing data values.