~ubuntu-branches/ubuntu/raring/codeblocks/raring-proposed

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-08-09 04:38:38 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20100809043838-a59ygguym4eg0jgw
Tags: 10.05-0ubuntu1
* New upstream release. Closes (LP: #322350)
 - Switch to dpkg-source 3.0 (quilt) format
 - Remove unneeded README.source
 - Add debian/get-source-orig script that removes all
   Windows prebuilt binaries
* Bump Standards-Version to 3.9.1
 - Stop shipping *.la files
* debian/control
 - Add cdbs package as Build-Depend
 - Add libbz2-dev and zlib1g-dev packages as
   Build-Depends (needed by libhelp_plugin.so)
 - Remove dpatch package of Build-Depends
 - Add codeblocks-contrib-debug package
 - Split architecture-independent files of codeblocks
   package in codeblocks-common package
* debian/rules
 - Switch to CDBS rules system
 - Add parallel build support
 - Add a call to debian/get-source-orig script
 - Use lzma compression (saves 23,5 MB of free space)
* debian/patches
 - Refresh 01_codeblocks_plugin_path
 - Add 02_no_Makefiles_in_debian_dir to remove any link
   in codeblocks build system to deleted Makefiles of debian directory
 - Drop 02_ftbfs_gcc44 and 03_ftbfs_glib221 (merged in upstream)
* debian/watch
 - Update to use the new host (berlios.de)

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
// Modified by:
6
6
// Created:
7
7
// Copyright:   (C) 2006, Paolo Gava
8
 
// RCS-ID:      $Id: barchartpoints.cpp 4016 2007-05-30 23:08:39Z byo $
 
8
// RCS-ID:      $Id: barchartpoints.cpp 5961 2009-12-08 06:24:32Z mortenmacfly $
9
9
// Licence:     wxWindows licence
10
10
/////////////////////////////////////////////////////////////////////////////
11
11
 
17
17
#include <cmath>
18
18
 
19
19
// wx
 
20
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
 
21
#pragma implementation "barchartpoints.h"
 
22
#endif
20
23
 
21
24
// For compilers that support precompilation, includes "wx.h".
22
25
#include <wx/wxprec.h>
31
34
 
32
35
#include "wx/label.h"
33
36
#include "wx/barchartpoints.h"
 
37
#include "wx/chartsizes.h"
34
38
 
35
39
//+++-S-cf-------------------------------------------------------------------
36
40
//      NAME:           ctor
37
41
//      DESC:           has to be created on the heap!
38
 
//      PARAMETERS:     std::string name,
 
42
//      PARAMETERS:     std::string name, 
39
43
//                              ChartColor c
40
44
//      RETURN:         None
41
45
//----------------------------------------------------------------------E-+++
42
46
wxBarChartPoints::wxBarChartPoints(
43
47
    wxString name,
44
48
        ChartColor c,
45
 
    bool showlabel
 
49
    bool showlabel   
46
50
) : wxChartPoints(wxChartPointsTypes::Bar()),
47
 
        m_Name(name),
 
51
        m_Name(name), 
48
52
        m_Color(c),
49
53
        m_Zoom(1),
50
54
        m_BarTag(NONE),
51
 
    m_ShowLabel( showlabel)
 
55
    m_ShowLabel( showlabel)  
52
56
{
53
57
}
54
58
 
55
59
//+++-S-cf-------------------------------------------------------------------
56
60
//      NAME:           GetXVal()
57
 
//      DESC:
 
61
//      DESC:           
58
62
//      PARAMETERS:     int n
59
63
//      RETURN:         int
60
64
//----------------------------------------------------------------------E-+++
67
71
 
68
72
//+++-S-cf-------------------------------------------------------------------
69
73
//      NAME:           GetYVal()
70
 
//      DESC:
 
74
//      DESC:           
71
75
//      PARAMETERS:     int n
72
76
//      RETURN:         int
73
77
//----------------------------------------------------------------------E-+++
80
84
 
81
85
//+++-S-cf-------------------------------------------------------------------
82
86
//      NAME:           GetName()
83
 
//      DESC:
 
87
//      DESC:           
84
88
//      PARAMETERS:     int n
85
89
//      RETURN:         std::string
86
90
//----------------------------------------------------------------------E-+++
93
97
 
94
98
//+++-S-cf-------------------------------------------------------------------
95
99
//      NAME:           GetCount()
96
 
//      DESC:
 
100
//      DESC:           
97
101
//      PARAMETERS:     None
98
102
//      RETURN:         int
99
103
//----------------------------------------------------------------------E-+++
104
108
 
105
109
//+++-S-cf-------------------------------------------------------------------
106
110
//      NAME:           GetColor()
107
 
//      DESC:
 
111
//      DESC:           
108
112
//      PARAMETERS:     int n
109
113
//      RETURN:         ChartColor
110
114
//----------------------------------------------------------------------E-+++
117
121
 
118
122
//+++-S-cf-------------------------------------------------------------------
119
123
//      NAME:           GetMaxX()
120
 
//      DESC:
 
124
//      DESC:           
121
125
//      PARAMETERS:     None
122
126
//      RETURN:         int
123
127
//----------------------------------------------------------------------E-+++
128
132
 
129
133
//+++-S-cf-------------------------------------------------------------------
130
134
//      NAME:           GetMaxY()
131
 
//      DESC:
 
135
//      DESC:           
132
136
//      PARAMETERS:     None
133
137
//      RETURN:         int
134
138
//----------------------------------------------------------------------E-+++
139
143
 
140
144
//+++-S-cf-------------------------------------------------------------------
141
145
//      NAME:           GetMinX()
142
 
//      DESC:
 
146
//      DESC:           
143
147
//      PARAMETERS:     None
144
148
//      RETURN:         int
145
149
//----------------------------------------------------------------------E-+++
150
154
 
151
155
//+++-S-cf-------------------------------------------------------------------
152
156
//      NAME:           GetMinY()
153
 
//      DESC:
 
157
//      DESC:           
154
158
//      PARAMETERS:     None
155
159
//      RETURN:         int
156
160
//----------------------------------------------------------------------E-+++
180
184
//----------------------------------------------------------------------E-+++
181
185
double wxBarChartPoints::GetZoom()
182
186
{
183
 
        return ( m_Zoom );
 
187
    return ( m_Sizes->GetXZoom() );
184
188
}
185
189
 
186
190
//+++-S-cf-------------------------------------------------------------------
187
191
//      NAME:           SetSizes
188
192
//      DESC:           Set sizes for drawing
189
 
//      PARAMETERS:     ChartSizes sizes
 
193
//      PARAMETERS:     wxChartSizes sizes
190
194
//      RETURN:         None
191
195
//----------------------------------------------------------------------E-+++
192
196
void wxBarChartPoints::SetSizes(
193
 
        ChartSizes sizes
 
197
        wxChartSizes *sizes
194
198
)
195
199
{
196
200
        m_Sizes = sizes;
200
204
//      NAME:           GetSizes
201
205
//      DESC:           Get sizes for drawing
202
206
//      PARAMETERS:     None
203
 
//      RETURN:         ChartSizes sizes
 
207
//      RETURN:         wxChartSizes sizes
204
208
//----------------------------------------------------------------------E-+++
205
 
const ChartSizes& wxBarChartPoints::GetSizes() const
 
209
wxChartSizes* wxBarChartPoints::GetSizes() const
206
210
{
207
211
        return ( m_Sizes );
208
212
}
209
213
 
210
214
//+++-S-cf-------------------------------------------------------------------
211
215
//      NAME:           GetColor()
212
 
//      DESC:
 
216
//      DESC:           
213
217
//      PARAMETERS:     None
214
218
//      RETURN:         unsigned long
215
219
//----------------------------------------------------------------------E-+++
220
224
 
221
225
//+++-S-cf-------------------------------------------------------------------
222
226
//      NAME:           SetColor()
223
 
//      DESC:
 
227
//      DESC:           
224
228
//      PARAMETERS:     ChartColor c
225
229
//      RETURN:         None
226
230
//----------------------------------------------------------------------E-+++
233
237
 
234
238
//+++-S-cf-------------------------------------------------------------------
235
239
//      NAME:           GetName()
236
 
//      DESC:
 
240
//      DESC:           
237
241
//      PARAMETERS:     None
238
242
//      RETURN:         ChartColor
239
243
//----------------------------------------------------------------------E-+++
244
248
 
245
249
//+++-S-cf-------------------------------------------------------------------
246
250
//      NAME:           SetName()
247
 
//      DESC:
 
251
//      DESC:           
248
252
//      PARAMETERS:     None
249
253
//      RETURN:         None
250
254
//----------------------------------------------------------------------E-+++
258
262
//+++-S-cf-------------------------------------------------------------------
259
263
//      NAME:           Add()
260
264
//      DESC:           Add point
261
 
//      PARAMETERS:     std::string name,
262
 
//                              ChartValue x,
 
265
//      PARAMETERS:     std::string name, 
 
266
//                              ChartValue x, 
263
267
//                              ChartValue y
264
268
//      RETURN:         None
265
269
//----------------------------------------------------------------------E-+++
266
270
void wxBarChartPoints::Add(
267
 
    wxString name,
268
 
        ChartValue x,
 
271
    wxString name, 
 
272
        ChartValue x, 
269
273
        ChartValue y
270
274
)
271
275
{
275
279
//+++-S-cf-------------------------------------------------------------------
276
280
//      NAME:           Add()
277
281
//      DESC:           Add point
278
 
//      PARAMETERS:     std::string name,
279
 
//                              ChartValue x,
 
282
//      PARAMETERS:     std::string name, 
 
283
//                              ChartValue x, 
280
284
//                              ChartValue y,
281
285
//                              ChartColor c
282
286
//      RETURN:         None
283
287
//----------------------------------------------------------------------E-+++
284
288
void wxBarChartPoints::Add(
285
 
    wxString name,
286
 
        ChartValue x,
 
289
    wxString name, 
 
290
        ChartValue x, 
287
291
        ChartValue y,
288
292
        ChartColor WXUNUSED(c)
289
293
)
321
325
//+++-S-cf-------------------------------------------------------------------
322
326
//  NAME:       Draw()
323
327
//  DESC:       Draw Bar chart
324
 
//  PARAMETERS: CHART_HPAINT hp,
 
328
//  PARAMETERS: CHART_HPAINT hp, 
325
329
//              CHART_HRECT hr
326
330
//  RETURN:     None
327
331
//----------------------------------------------------------------------E-+++
328
332
void wxBarChartPoints::Draw(
329
 
    CHART_HPAINT hp,
 
333
    CHART_HPAINT hp, 
330
334
    CHART_HRECT hr
331
335
)
332
336
{
336
340
    double iNodes = ceil( static_cast<double>(GetCount()) );
337
341
 
338
342
    //-----------------------------------------------------------------------
 
343
    // Get sizes
 
344
    //-----------------------------------------------------------------------
 
345
    wxChartSizes *sizes = GetSizes();
 
346
 
 
347
    //-----------------------------------------------------------------------
339
348
    // get max height
340
349
    //-----------------------------------------------------------------------
341
 
    double ValMax = ceil( GetMaxY() );
342
 
    if ( ValMax == 0 )
 
350
    double ValMax = ceil( sizes->GetMaxY() );
 
351
    if ( ValMax == 0 ) 
343
352
        ValMax = 1;
344
 
 
345
 
    //-----------------------------------------------------------------------
346
 
    // Get sizes
347
 
    //-----------------------------------------------------------------------
348
 
    ChartSizes sizes = GetSizes();
349
 
 
 
353
    
350
354
    hp->SetBrush( wxBrush(GetColor(), wxSOLID) );
351
355
    hp->SetPen( *wxTRANSPARENT_PEN );
352
356
 
357
361
        // Get x-position for iNode bar
358
362
        //-------------------------------------------------------------------
359
363
        double xVal  = ceil( GetXVal(iNode) );
360
 
        x = hr->x + GetZoom() * xVal * ( sizes.wbar * sizes.nbar +
361
 
                                         sizes.wbar3d * sizes.nbar3d +
362
 
                                         sizes.gap);
 
364
        x = hr->x + GetZoom() * xVal * ( sizes->GetWidthBar() * 
 
365
                sizes->GetNumBar() + 
 
366
                sizes->GetWidthBar3d() * sizes->GetNumBar3d() + 
 
367
                sizes->GetGap() );
363
368
 
364
369
        //-------------------------------------------------------------------
365
370
        // Get y-position for iNode bar
366
371
        //-------------------------------------------------------------------
367
 
        y = hr->y + ( (hr->h - sizes.s_height)* GetYVal(iNode) ) / ValMax ;
 
372
        y = hr->y + ( (hr->h - sizes->GetSizeHeight())* 
 
373
                GetYVal(iNode) ) / ValMax ;
368
374
 
369
375
        hp->DrawRectangle( static_cast<int>(ceil(x)),
370
376
                           static_cast<int>(ceil(hr->h - y)),
371
 
                           static_cast<int>(sizes.wbar * GetZoom()),
 
377
                           static_cast<int>(sizes->GetWidthBar() * GetZoom()), 
372
378
                           static_cast<int>(ceil(y)) );
373
 
 
 
379
        
374
380
        //-------------------------------------------------------------------
375
381
        // Only draw Label if user wants it
376
382
        //-------------------------------------------------------------------
381
387
        wxLabel wxLbl;
382
388
        switch ( GetDisplayTag() )
383
389
        {
384
 
        case XVALUE:
385
 
            lbl.Printf( wxT("%d"), static_cast<int>(xVal));
386
 
            wxLbl.Draw( hp, static_cast<int>(ceil(x)),
387
 
                        static_cast<int>(ceil(hr->h - y)),
388
 
                        GetColor(),
389
 
                        lbl,
390
 
                        UP);
391
 
            break;
392
 
        case YVALUE:
393
 
            lbl.Printf( wxT("%d"), static_cast<int>(GetYVal(iNode)));
394
 
            wxLbl.Draw( hp, static_cast<int>(ceil(x)),
395
 
                        static_cast<int>(ceil(hr->h - y)),
396
 
                        GetColor(),
397
 
                        lbl,
398
 
                        UP );
399
 
            break;
400
 
        case NAME:
401
 
            lbl = GetName(iNode).c_str();
402
 
            wxLbl.Draw( hp, static_cast<int>(ceil(x)),
403
 
                        static_cast<int>(ceil(hr->h - y)),
404
 
                        GetColor(),
405
 
                        lbl,
406
 
                        UP );
407
 
            break;
 
390
            case XVALUE:
 
391
                lbl.Printf( wxT("%d"), static_cast<int>(xVal));
 
392
                wxLbl.Draw( hp, static_cast<int>(ceil(x)), 
 
393
                            static_cast<int>(ceil(hr->h - y)), 
 
394
                            GetColor(),
 
395
                            lbl,
 
396
                            UP);
 
397
                break;
 
398
            case YVALUE:
 
399
                lbl.Printf( wxT("%d"), static_cast<int>(GetYVal(iNode)));
 
400
                wxLbl.Draw( hp, static_cast<int>(ceil(x)), 
 
401
                            static_cast<int>(ceil(hr->h - y)), 
 
402
                            GetColor(),
 
403
                            lbl,
 
404
                            UP );
 
405
                break;
 
406
            case XVALUE_FLOAT:
 
407
                lbl.Printf( wxT("%4.1f"), xVal);
 
408
                wxLbl.Draw( hp, static_cast<int>(ceil(x)), 
 
409
                            static_cast<int>(ceil(hr->h - y)), 
 
410
                            GetColor(),
 
411
                            lbl,
 
412
                            UP);
 
413
                break;
 
414
            case YVALUE_FLOAT:
 
415
                lbl.Printf( wxT("%4.1f"), GetYVal(iNode));
 
416
                wxLbl.Draw( hp, static_cast<int>(ceil(x)), 
 
417
                            static_cast<int>(ceil(hr->h - y)), 
 
418
                            GetColor(),
 
419
                            lbl,
 
420
                            UP );
 
421
                break;
 
422
            case NAME:
 
423
                lbl = GetName(iNode).c_str();
 
424
                wxLbl.Draw( hp, static_cast<int>(ceil(x)), 
 
425
                            static_cast<int>(ceil(hr->h - y)), 
 
426
                            GetColor(),
 
427
                            lbl,
 
428
                            UP );
 
429
                break;
408
430
        default:
409
 
            break;
 
431
            break;      
410
432
        }
411
433
    }
412
434
 
415
437
 
416
438
//+++-S-cf-------------------------------------------------------------------
417
439
//  NAME:       CreateWxBarChartPoints()
418
 
//  DESC:
 
440
//  DESC:       
419
441
//  PARAMETERS: wxString name
420
442
//              ChartColor c
421
443
//              bool showlabel