summaryrefslogtreecommitdiffstats
path: root/kchart/kdchart/KDChartAxesPainter.h
blob: bae3eb5e905068176ce44ffbdb0b4bfec5809592 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/* -*- Mode: C++ -*-
   KDChart - a multi-platform charting engine
   */

/****************************************************************************
 ** Copyright (C) 2001-2003 Klarälvdalens Datakonsult AB.  All rights reserved.
 **
 ** This file is part of the KDChart library.
 **
 ** This file may be distributed and/or modified under the terms of the
 ** GNU General Public License version 2 as published by the Free Software
 ** Foundation and appearing in the file LICENSE.GPL included in the
 ** packaging of this file.
 **
 ** Licensees holding valid commercial KDChart licenses may use this file in
 ** accordance with the KDChart Commercial License Agreement provided with
 ** the Software.
 **
 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 **
 ** See http://www.klaralvdalens-datakonsult.se/?page=products for
 **   information about KDChart Commercial License Agreements.
 **
 ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
 ** licensing are not clear to you.
 **
 **********************************************************************/
#ifndef __KDCHARTAXESPAINTER_H__
#define __KDCHARTAXESPAINTER_H__

#include <tqpen.h>
#include <tqpainter.h>

#include <KDChartPainter.h>
#include <KDChartTable.h>
#include <KDChartAxisParams.h>

class TQDateTime;
class KDChartParams;

class KDChartAxesPainter : public KDChartPainter
{
    protected:
        KDChartAxesPainter( KDChartParams* params );
        virtual ~KDChartAxesPainter();

        virtual void paintAxes( TQPainter* painter,
                KDChartTableDataBase* data );

        virtual void paintData( TQPainter* painter,
                KDChartTableDataBase* data,
                bool paint2nd,
                KDChartDataRegionList* regions );

        // note: Classes inheriting from KDChartAxesPainter
        //       MUST implement the following abstract functions:

        // Returns whether a normal chart is to be drawn
        // or a stacked or percentage (or ... ) chart            .
        virtual bool isNormalMode() const = 0;

        // Returns the number of pixels to be added to the clipping area's height
        // to make room for special arrows indicating oversized, cut data entries.
        // Chart classes not drawing such indicators must return 0.
        virtual int clipShiftUp( bool normalMode, double areaWidthP1000 ) const = 0;

        // The actual, chart type specific drawing of the data.
        virtual void specificPaintData( TQPainter* painter,
                const TQRect& ourClipRect,
                KDChartTableDataBase* data,
                KDChartDataRegionList* regions,
                const KDChartAxisParams* axisPara,
                bool bNormalMode,
                uint chart,
                double logWidth,
                double areaWidthP1000,
                double logHeight,
                double axisYOffset,
                double minColumnValue,
                double maxColumnValue,
                double columnValueDistance,
                uint chartDatasetStart,
                uint chartDatasetEnd,
                uint datasetStart,
                uint datasetEnd ) = 0;

        virtual bool calculateAllAxesLabelTextsAndCalcValues(
                          TQPainter* painter,
                          KDChartTableDataBase* data,
                          double areaWidthP1000,
                          double areaHeightP1000,
                          double& delimLen );

    private:
    public:
        // special infos needed by the different painters' implementations
        // of the specificPaintData() function
        struct abscissaInfos{
            const KDChartAxisParams* abscissaPara;
            bool bCenterThePoints;
            bool bAbscissaDecreasing;
            bool bAbscissaIsLogarithmic;
            bool bCellsHaveSeveralCoordinates;
            int numValues;
            int numLabels;
            bool bAbscissaHasTrueAxisValues;
            double abscissaStart;
            double abscissaEnd;
            double abscissaSpan;
            double abscissaDelta;
            bool bAbscissaHasTrueAxisDtValues;
            double dtLowPos;
            double dtHighPos;
            TQDateTime abscissaDtStart;
            TQDateTime abscissaDtEnd;
            bool bScaleLessThanDay;
            double abscissaDtSpan;
            double abscissaDtPixelsPerScaleUnit;
            double pointDist;
            double abscissaPixelsPerUnit;
            double abscissaZeroPos;
        };
        static void calculateAbscissaInfos(
                const KDChartParams& params,
                const KDChartTableDataBase& data,
                uint datasetStart,
                uint datasetEnd,
                double logWidth,
                const TQRect& dataRect,
                abscissaInfos& infos );
        static bool calculateAbscissaAxisValue( const TQVariant& value,
                                                abscissaInfos& ai,
                                                int colNumber,
                                                double& xValue );

        static void saveDrawLine( TQPainter& painter,
                TQPoint pA,
                TQPoint pZ,
                TQPen pen );
        static void calculateLabelTexts(
                TQPainter* painter,
                const KDChartTableDataBase& data,
                const KDChartParams& params,
                uint axisNumber,
                double averageValueP1000,
                double delimLen,
                // start of return parameters
                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 );
                static void calculateBasicTextFactors( double nTxtHeight,
                        const KDChartAxisParams& para,
                        double averageValueP1000,
                        KDChartAxisParams::AxisPos basicPos,
                        const TQPoint& orig,
                        double delimLen,
                        uint nLabels,
                        // start of return parameters
                        double& pDelimDelta,
                        double& pTextsX,
                        double& pTextsY,
                        double& pTextsW,
                        double& pTextsH,
                        int& textAlign );
                static TQString truncateBehindComma( const double nVal,
                        const int    behindComma,
                        const double nDelta,
                        int& trueBehindComma );
                static TQString applyLabelsFormat( const double nVal,
                        int   divPow10,
                        int   behindComma,
                        double nDelta,
                        int& trueBehindComma,
                        KDChartEnums::NumberNotation notation,
                        const TQString& decimalPoint,
                        const TQString& thousandsPoint,
                        const TQString& prefix,
                        const TQString& postfix,
                        int            totalLen,
                        const TQChar&   padFill,
                        bool           blockAlign );
                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 );
                static void dtAddSecs(   const TQDateTime& org, const int secs,   TQDateTime& dest );
                static void dtAddDays(   const TQDateTime& org, const int days,   TQDateTime& dest );
                static void dtAddMonths( const TQDateTime& org, const int months, TQDateTime& dest );
                static void dtAddYears(  const TQDateTime& org, const int years,  TQDateTime& dest );
};

#endif