~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/plugins/contrib/wxSmithContribItems/wxchart/wxchart-1.0/src/chart.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/////////////////////////////////////////////////////////////////////////////
 
2
// Name:        chart.cpp
 
3
// Purpose:     wxChart
 
4
// Author:      Paolo Gava
 
5
// Modified by:
 
6
// Created:
 
7
// Copyright:   (C) 2006, Paolo Gava
 
8
// RCS-ID:      $Id: chart.cpp 4016 2007-05-30 23:08:39Z byo $
 
9
// Licence:     wxWindows licence
 
10
/////////////////////////////////////////////////////////////////////////////
 
11
 
 
12
//----------------------------------------------------------------------------
 
13
// Headers
 
14
//----------------------------------------------------------------------------
 
15
// wx
 
16
 
 
17
// For compilers that support precompilation, includes "wx.h".
 
18
#include <wx/wxprec.h>
 
19
 
 
20
#ifdef __BORLANDC__
 
21
#pragma hdrstop
 
22
#endif
 
23
 
 
24
#include "wx/chart.h"
 
25
 
 
26
//----------------------------------------------------------------------------
 
27
// Define Array/List of Points
 
28
//----------------------------------------------------------------------------
 
29
#include <wx/arrimpl.cpp>
 
30
WX_DEFINE_OBJARRAY(ListChartPoints);
 
31
 
 
32
//+++-S-cf-------------------------------------------------------------------
 
33
//      NAME:           ctor
 
34
//      DESC:
 
35
//      PARAMETERS:     None
 
36
//      RETURN:         None
 
37
//----------------------------------------------------------------------E-+++
 
38
wxChart::wxChart()
 
39
{
 
40
}
 
41
 
 
42
//+++-S-cf-------------------------------------------------------------------
 
43
//      NAME:           dtor
 
44
//      DESC:
 
45
//      PARAMETERS:     None
 
46
//      RETURN:         None
 
47
//----------------------------------------------------------------------E-+++
 
48
wxChart::~wxChart()
 
49
{
 
50
        wxChartPoints* cptmp;
 
51
 
 
52
    size_t num = m_LCP.GetCount();
 
53
 
 
54
    for ( size_t loop = 0;
 
55
          loop < num;
 
56
          loop++ )
 
57
    {
 
58
        cptmp = m_LCP.Item(loop);
 
59
        delete cptmp;
 
60
    }
 
61
 
 
62
        m_LCP.Clear();
 
63
}
 
64
 
 
65
//+++-S-cf-------------------------------------------------------------------
 
66
//      NAME:           Add()
 
67
//      DESC:
 
68
//      PARAMETERS:     CChartPoints* cp
 
69
//      RETURN:         None
 
70
//----------------------------------------------------------------------E-+++
 
71
void wxChart::Add(
 
72
        wxChartPoints* cp
 
73
)
 
74
{
 
75
        m_LCP.Add(cp);
 
76
}
 
77
 
 
78
//+++-S-cf-------------------------------------------------------------------
 
79
//      NAME:           Clear()
 
80
//      DESC:
 
81
//      PARAMETERS:     None
 
82
//      RETURN:         None
 
83
//----------------------------------------------------------------------E-+++
 
84
void wxChart::Clear()
 
85
{
 
86
        m_LCP.Clear();
 
87
}
 
88
 
 
89
//+++-S-cf-------------------------------------------------------------------
 
90
//      NAME:           GetMaxX()
 
91
//      DESC:           Get the max x-val calculated from all chartpoints
 
92
//      PARAMETERS:     None
 
93
//      RETURN:         ChartValue
 
94
//----------------------------------------------------------------------E-+++
 
95
ChartValue wxChart::GetMaxX() const
 
96
{
 
97
        ChartValue valTmp, valRes = 0;
 
98
 
 
99
    size_t num = m_LCP.GetCount();
 
100
 
 
101
    for ( size_t loop = 0;
 
102
          loop < num;
 
103
          loop++ )
 
104
    {
 
105
        valTmp = (m_LCP.Item(loop))->GetMaxX();
 
106
        if ( valTmp > valRes )
 
107
            valRes = valTmp;
 
108
    }
 
109
 
 
110
    //-----------------------------------------------------------------------
 
111
    // if MaxX is 0 could be a Pie chart that doesn't have points like
 
112
    // Bar chart so force this to be something != from 0, otherwise
 
113
    // wont be draw
 
114
    //-----------------------------------------------------------------------
 
115
    if ( valRes == 0 )
 
116
        valRes = 10;
 
117
 
 
118
        return ( valRes );
 
119
}
 
120
 
 
121
//+++-S-cf-------------------------------------------------------------------
 
122
//      NAME:           GetMinX()
 
123
//      DESC:           Get the min x-val calculated from all chartpoints
 
124
//      PARAMETERS:     None
 
125
//      RETURN:         ChartValue
 
126
//----------------------------------------------------------------------E-+++
 
127
ChartValue wxChart::GetMinX() const
 
128
{
 
129
        ChartValue valTmp, valRes = 0;
 
130
 
 
131
    size_t num = m_LCP.GetCount();
 
132
 
 
133
    for ( size_t loop = 0;
 
134
          loop < num;
 
135
          loop++ )
 
136
    {
 
137
        valTmp = (m_LCP.Item(loop))->GetMinX();
 
138
        if ( loop == 0 )
 
139
            valRes = valTmp;
 
140
        else
 
141
            if ( valTmp < valRes )
 
142
                valRes = valTmp;
 
143
    }
 
144
 
 
145
        return ( valRes );
 
146
}
 
147
 
 
148
//+++-S-cf-------------------------------------------------------------------
 
149
//      NAME:           GetYMax()
 
150
//      DESC:           Get the max y-val calculated from all chartpoints
 
151
//      PARAMETERS:     None
 
152
//      RETURN:         ChartValue
 
153
//----------------------------------------------------------------------E-+++
 
154
ChartValue wxChart::GetMaxY() const
 
155
{
 
156
        ChartValue valTmp, valRes = 0;
 
157
 
 
158
    size_t num = m_LCP.GetCount();
 
159
 
 
160
    for ( size_t loop = 0;
 
161
          loop < num;
 
162
          loop++ )
 
163
    {
 
164
        valTmp = (m_LCP.Item(loop))->GetMaxY();
 
165
        if ( valTmp > valRes )
 
166
            valRes = valTmp;
 
167
    }
 
168
 
 
169
    //-----------------------------------------------------------------------
 
170
    // if MaxY is 0 could be a Pie chart that doesn't have points like
 
171
    // Bar chart so force this to be something != from 0, otherwise
 
172
    // wont be draw
 
173
    //-----------------------------------------------------------------------
 
174
    if ( valRes == 0 )
 
175
        valRes = 10;
 
176
 
 
177
    return ( valRes );
 
178
}
 
179
 
 
180
//+++-S-cf-------------------------------------------------------------------
 
181
//      NAME:           GetYMin()
 
182
//      DESC:           Get the min y-val calculated from all chartpoints
 
183
//      PARAMETERS:     None
 
184
//      RETURN:         ChartValue
 
185
//----------------------------------------------------------------------E-+++
 
186
ChartValue wxChart::GetMinY() const
 
187
{
 
188
        ChartValue valTmp, valRes = 0;
 
189
 
 
190
    size_t num = m_LCP.GetCount();
 
191
 
 
192
    for ( size_t loop = 0;
 
193
          loop < num;
 
194
          loop++ )
 
195
    {
 
196
        valTmp = (m_LCP.Item(loop))->GetMinY();
 
197
        if ( loop == 0 )
 
198
            valRes = valTmp;
 
199
        else
 
200
            if ( valTmp < valRes )
 
201
                valRes = valTmp;
 
202
    }
 
203
 
 
204
        return ( valRes );
 
205
}
 
206
 
 
207
//+++-S-cf-------------------------------------------------------------------
 
208
//      NAME:           GetNumBarPoints()
 
209
//      DESC:           Number of bar points is used to calculate the width
 
210
//                              of the chart
 
211
//      PARAMETERS:     None
 
212
//      RETURN:         None
 
213
//----------------------------------------------------------------------E-+++
 
214
int wxChart::GetNumBarPoints() const
 
215
{
 
216
        int valRes = 0;
 
217
 
 
218
    size_t num = m_LCP.GetCount();
 
219
 
 
220
    for ( size_t loop = 0;
 
221
          loop < num;
 
222
          loop++ )
 
223
    {
 
224
        if ( *(m_LCP.Item(loop)) == wxChartPointsTypes::Bar() )
 
225
            valRes += 1;
 
226
    }
 
227
 
 
228
        return ( valRes );
 
229
}
 
230
 
 
231
//+++-S-cf-------------------------------------------------------------------
 
232
//      NAME:           GetNumBar3DPoints()
 
233
//      DESC:           Number of bar points is used to calculate the width
 
234
//                              of the chart
 
235
//      PARAMETERS:     None
 
236
//      RETURN:         None
 
237
//----------------------------------------------------------------------E-+++
 
238
int wxChart::GetNumBar3DPoints() const
 
239
{
 
240
        int valRes = 0;
 
241
 
 
242
    size_t num = m_LCP.GetCount();
 
243
 
 
244
    for ( size_t loop = 0;
 
245
          loop < num;
 
246
          loop++ )
 
247
    {
 
248
        if ( *(m_LCP.Item(loop)) == wxChartPointsTypes::Bar3D() )
 
249
            valRes += 1;
 
250
    }
 
251
 
 
252
        return ( valRes );
 
253
}
 
254
 
 
255
//+++-S-cf-------------------------------------------------------------------
 
256
//      NAME:           SetZoom
 
257
//      DESC:           Set zoom
 
258
//      PARAMETERS:     double
 
259
//      RETURN:         None
 
260
//----------------------------------------------------------------------E-+++
 
261
void wxChart::SetZoom(
 
262
        double z
 
263
)
 
264
{
 
265
    size_t num = m_LCP.GetCount();
 
266
 
 
267
    for ( size_t loop = 0;
 
268
          loop < num;
 
269
          loop++ )
 
270
    {
 
271
        (m_LCP.Item(loop))->SetZoom( z );
 
272
    }
 
273
}
 
274
 
 
275
//+++-S-cf-------------------------------------------------------------------
 
276
//  NAME:       GetZoom
 
277
//  DESC:       Get zoom
 
278
//  PARAMETERS: Noce
 
279
//  RETURN:     double
 
280
//----------------------------------------------------------------------E-+++
 
281
double wxChart::GetZoom() const
 
282
{
 
283
    size_t num = m_LCP.GetCount();
 
284
 
 
285
    for ( size_t loop = 0;
 
286
          loop < num;
 
287
        )
 
288
    {
 
289
        return (m_LCP.Item(loop))->GetZoom();
 
290
    }
 
291
 
 
292
    return 1; // default Zoom set to 1
 
293
}
 
294
 
 
295
//+++-S-cf-------------------------------------------------------------------
 
296
//      NAME:           SetSizes
 
297
//      DESC:           Set sizes for drawing
 
298
//      PARAMETERS:     ChartSizes sizes
 
299
//      RETURN:         None
 
300
//----------------------------------------------------------------------E-+++
 
301
void wxChart::SetSizes(
 
302
        ChartSizes sizes
 
303
)
 
304
{
 
305
    size_t num = m_LCP.GetCount();
 
306
 
 
307
    for ( size_t loop = 0;
 
308
          loop < num;
 
309
          loop++ )
 
310
    {
 
311
        (m_LCP.Item(loop))->SetSizes( sizes );
 
312
    }
 
313
}
 
314
 
 
315
//+++-S-cf-------------------------------------------------------------------
 
316
//  NAME:       GetSizes
 
317
//  DESC:       Get sizes for drawing
 
318
//  PARAMETERS: None
 
319
//  RETURN:     ChartSizes sizes
 
320
//----------------------------------------------------------------------E-+++
 
321
ChartSizes wxChart::GetSizes() const
 
322
{
 
323
    size_t num = m_LCP.GetCount();
 
324
 
 
325
    for ( size_t loop = 0;
 
326
          loop < num;
 
327
        )
 
328
    {
 
329
        return (m_LCP.Item(loop))->GetSizes();
 
330
    }
 
331
 
 
332
    return ChartSizes();
 
333
}
 
334
 
 
335
//+++-S-cf-------------------------------------------------------------------
 
336
//      NAME:           Draw()
 
337
//      DESC:
 
338
//      PARAMETERS:     CHART_HPAINT hp,
 
339
//                              CHART_HRECT hr
 
340
//      RETURN:         None
 
341
//----------------------------------------------------------------------E-+++
 
342
void wxChart::Draw(
 
343
        CHART_HPAINT hp,
 
344
        CHART_HRECT hr
 
345
)
 
346
{
 
347
        int iBarCounter = 0;
 
348
        int iBar3DCounter = 0;
 
349
        int xTmp = hr->x;
 
350
 
 
351
    size_t num = m_LCP.GetCount();
 
352
    for ( size_t loop = 0;
 
353
          loop < num;
 
354
          loop++ )
 
355
        {
 
356
                //-------------------------------------------------------------------
 
357
                // Count the number of Bar-Bar3d charts so when more than one bar is
 
358
                // present the first one is draw at position x, the second one at
 
359
                // position x+1*bar_width so just next to the previous one
 
360
                //-------------------------------------------------------------------
 
361
 
 
362
        ChartSizes sizes = m_LCP.Item(loop)->GetSizes();
 
363
        hr->x += (
 
364
            iBarCounter *
 
365
                static_cast<int>(sizes.wbar * m_LCP.Item(loop)->GetZoom()) +
 
366
            iBar3DCounter *
 
367
                static_cast<int>(sizes.wbar3d * m_LCP.Item(loop)->GetZoom())
 
368
        );
 
369
 
 
370
                if ( *(m_LCP.Item(loop)) == wxChartPointsTypes::Bar() )
 
371
                {
 
372
                        iBarCounter += 1;
 
373
                }
 
374
                else if ( *m_LCP.Item(loop) == wxChartPointsTypes::Bar3D() )
 
375
                {
 
376
                        iBar3DCounter += 1;
 
377
                }
 
378
 
 
379
                //-------------------------------------------------------------------
 
380
                // draw all
 
381
                //-------------------------------------------------------------------
 
382
                m_LCP.Item(loop)->Draw( hp, hr );
 
383
 
 
384
                hr->x = xTmp;
 
385
        }
 
386
}