1
/////////////////////////////////////////////////////////////////////////////
2
// Name: bar3dchartpoints.cpp
7
// Copyright: (C) 2006, Paolo Gava
8
// RCS-ID: $Id: bar3dchartpoints.cpp 7551 2011-11-01 18:13:27Z jenslody $
9
// Licence: wxWindows licence
10
/////////////////////////////////////////////////////////////////////////////
12
//----------------------------------------------------------------------------
14
//----------------------------------------------------------------------------
20
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21
#pragma implementation "bar3dchartpoints.h"
24
// For compilers that support precompilation, includes "wx.h".
25
#include <wx/wxprec.h>
36
#include "wx/bar3dchartpoints.h"
37
#include "wx/chartsizes.h"
40
//+++-S-cf-------------------------------------------------------------------
42
// DESC: has to be created on the heap!
43
// PARAMETERS: std::string name,
46
//----------------------------------------------------------------------E-+++
47
wxBar3DChartPoints::wxBar3DChartPoints(
51
) : wxChartPoints(wxChartPointsTypes::Bar3D()),
56
m_ShowLabel( showlabel)
60
//+++-S-cf-------------------------------------------------------------------
65
//----------------------------------------------------------------------E-+++
66
ChartValue wxBar3DChartPoints::GetXVal(
70
return ( m_Points.GetXVal(n) );
73
//+++-S-cf-------------------------------------------------------------------
78
//----------------------------------------------------------------------E-+++
79
ChartValue wxBar3DChartPoints::GetYVal(
83
return ( m_Points.GetYVal(n) );
86
//+++-S-cf-------------------------------------------------------------------
90
// RETURN: std::string
91
//----------------------------------------------------------------------E-+++
92
wxString wxBar3DChartPoints::GetName(
96
return ( m_Points.GetName(n) );
99
//+++-S-cf-------------------------------------------------------------------
104
//----------------------------------------------------------------------E-+++
105
int wxBar3DChartPoints::GetCount() const
107
return ( m_Points.GetCount() );
110
//+++-S-cf-------------------------------------------------------------------
114
// RETURN: ChartColor
115
//----------------------------------------------------------------------E-+++
116
ChartColor wxBar3DChartPoints::GetColor(
123
//+++-S-cf-------------------------------------------------------------------
128
//----------------------------------------------------------------------E-+++
129
ChartValue wxBar3DChartPoints::GetMaxX() const
131
return ( m_Points.GetMaxX() );
134
//+++-S-cf-------------------------------------------------------------------
139
//----------------------------------------------------------------------E-+++
140
ChartValue wxBar3DChartPoints::GetMaxY() const
142
return ( m_Points.GetMaxY() );
145
//+++-S-cf-------------------------------------------------------------------
150
//----------------------------------------------------------------------E-+++
151
ChartValue wxBar3DChartPoints::GetMinX() const
153
return ( m_Points.GetMinX() );
156
//+++-S-cf-------------------------------------------------------------------
161
//----------------------------------------------------------------------E-+++
162
ChartValue wxBar3DChartPoints::GetMinY() const
164
return ( m_Points.GetMinY() );
167
//+++-S-cf-------------------------------------------------------------------
170
// PARAMETERS: double
172
//----------------------------------------------------------------------E-+++
173
void wxBar3DChartPoints::SetZoom(
180
//+++-S-cf-------------------------------------------------------------------
183
// PARAMETERS: double
185
//----------------------------------------------------------------------E-+++
186
double wxBar3DChartPoints::GetZoom()
188
return ( m_Sizes->GetXZoom() );
191
//+++-S-cf-------------------------------------------------------------------
193
// DESC: Set sizes for drawing
194
// PARAMETERS: ChartSizes sizes
196
//----------------------------------------------------------------------E-+++
197
void wxBar3DChartPoints::SetSizes(
204
//+++-S-cf-------------------------------------------------------------------
206
// DESC: Get sizes for drawing
208
// RETURN: ChartSizes sizes
209
//----------------------------------------------------------------------E-+++
210
wxChartSizes* wxBar3DChartPoints::GetSizes() const
215
//+++-S-cf-------------------------------------------------------------------
219
// RETURN: unsigned long
220
//----------------------------------------------------------------------E-+++
221
ChartColor wxBar3DChartPoints::GetColor() const
226
//+++-S-cf-------------------------------------------------------------------
229
// PARAMETERS: ChartColor c
231
//----------------------------------------------------------------------E-+++
232
void wxBar3DChartPoints::SetColor(
239
//+++-S-cf-------------------------------------------------------------------
243
// RETURN: ChartColor
244
//----------------------------------------------------------------------E-+++
245
wxString wxBar3DChartPoints::GetName() const
250
//+++-S-cf-------------------------------------------------------------------
255
//----------------------------------------------------------------------E-+++
256
void wxBar3DChartPoints::SetName(
263
//+++-S-cf-------------------------------------------------------------------
266
// PARAMETERS: std::string name,
270
//----------------------------------------------------------------------E-+++
271
void wxBar3DChartPoints::Add(
277
m_Points.Add( name, x, y );
280
//+++-S-cf-------------------------------------------------------------------
283
// PARAMETERS: std::string name,
288
//----------------------------------------------------------------------E-+++
289
void wxBar3DChartPoints::Add(
293
ChartColor WXUNUSED(c)
296
//-----------------------------------------------------------------------
298
//-----------------------------------------------------------------------
302
//+++-S-cf-------------------------------------------------------------------
303
// NAME: SetDisplay()
304
// DESC: Set Display option
305
// PARAMETERS: wxDISPLAY_LABEL d
307
//----------------------------------------------------------------------E-+++
308
void wxBar3DChartPoints::SetDisplayTag(
315
//+++-S-cf-------------------------------------------------------------------
316
// NAME: GetDisplay()
317
// DESC: Get Display option
319
// RETURN: wxDISPLAY_LABEL
320
//----------------------------------------------------------------------E-+++
321
wxDISPLAY_LABEL wxBar3DChartPoints::GetDisplayTag() const
326
//+++-S-cf-------------------------------------------------------------------
328
// DESC: Draw Bar chart
329
// PARAMETERS: CHART_HPAINT hp,
332
//----------------------------------------------------------------------E-+++
333
void wxBar3DChartPoints::Draw(
338
//-----------------------------------------------------------------------
339
// get number of bars
340
//-----------------------------------------------------------------------
341
double iNodes = ceil( static_cast<double>(GetCount()) );
343
//-----------------------------------------------------------------------
345
//-----------------------------------------------------------------------
346
wxChartSizes *sizes = GetSizes();
348
//-----------------------------------------------------------------------
350
//-----------------------------------------------------------------------
351
double ValMax = ceil( sizes->GetMaxY() );
355
hp->SetBrush( wxBrush(GetColor(), wxSOLID) );
356
//hp->SetPen( *wxTRANSPARENT_PEN );
357
//hp->SetPen( *wxLIGHT_GREY_PEN );
358
hp->SetPen( wxPen(wxChartColors::GetDarkColor(GetColor(), 15)) );
362
//-----------------------------------------------------------------------
363
// Get the real width of the bar
364
// Assume 80% of sizes->GetWidthBar3d()
365
//-----------------------------------------------------------------------
366
w = sizes->GetWidthBar3d() * 0.80;
368
//-----------------------------------------------------------------------
369
// Get how mutch high deep the bar should start.
370
// Suppose we to use 30 degree
371
// rad = 2 * pi / 360 * grd
372
//-----------------------------------------------------------------------
373
h = ( sizes->GetWidthBar3d() - w ) / cos( 0.5236 ) * sin( 0.5236 );
376
for ( int iNode = 0; iNode < iNodes; ++ iNode )
378
//-------------------------------------------------------------------
379
// Get x-position for iNode bar
380
//-------------------------------------------------------------------
381
double xVal = ceil( GetXVal(iNode) );
382
x = hr->x + GetZoom() * xVal * (
383
sizes->GetWidthBar() * sizes->GetNumBar() +
384
sizes->GetWidthBar3d() * sizes->GetNumBar3d() +
387
//-------------------------------------------------------------------
388
// Get y-position for iNode bar
389
//-------------------------------------------------------------------
390
y = hr->y + ( (hr->h - sizes->GetSizeHeight() )* GetYVal(iNode) ) / ValMax ;
392
hp->DrawRectangle( static_cast<int>(ceil(x)),
393
static_cast<int>(ceil(hr->h - y)),
394
static_cast<int>(ceil(w * GetZoom())),
395
static_cast<int>(ceil(y)));
397
//-------------------------------------------------------------------
398
// Draw Poligon next to main Rectangle
399
//-------------------------------------------------------------------
401
hp->SetBrush( wxBrush(wxChartColors::GetDarkColor(GetColor(),
404
//-------------------------------------------------------------------
405
// Make sure that the difference y and y - h is at lease 1
406
//-------------------------------------------------------------------
407
int y1 = static_cast<int>(ceil(static_cast<double>(hr->h)));
408
int y2 = static_cast<int>(ceil(static_cast<double>(hr->h - h)));
409
int y3 = static_cast<int>(ceil(static_cast<double>(hr->h - y - h)));
410
int y4 = static_cast<int>(ceil(static_cast<double>(hr->h - y)));
411
int d = y1 - y2 > y4 - y3 ? y1 - y2 : y4 - y3;
417
static_cast<int>(ceil(x + w * GetZoom())),
420
static_cast<int>(ceil(x + sizes->GetWidthBar3d() * GetZoom())),
423
static_cast<int>(ceil(x + sizes->GetWidthBar3d() * GetZoom())),
426
static_cast<int>(ceil(x + w * GetZoom())),
430
hp->DrawPolygon( 4, next );
432
//-------------------------------------------------------------------
433
// Draw Poligon on top of main Rectangle
434
//-------------------------------------------------------------------
437
static_cast<int>(ceil(x)),
440
static_cast<int>(ceil(x + w * GetZoom())),
443
static_cast<int>(ceil(x + sizes->GetWidthBar3d() * GetZoom())),
446
static_cast<int>(ceil(x + (sizes->GetWidthBar3d() - w) * GetZoom())),
450
hp->DrawPolygon( 4, top );
452
hp->SetBrush( wxBrush(GetColor(), wxSOLID) );
454
//-------------------------------------------------------------------
455
// Only draw Label if user wants it
456
//-------------------------------------------------------------------
462
switch ( GetDisplayTag() )
465
lbl.Printf( wxT("%d"), static_cast<int>(xVal));
466
wxLbl.Draw( hp, static_cast<int>(ceil(x)),
467
static_cast<int>(ceil(hr->h - y)),
473
lbl.Printf( wxT("%d"), static_cast<int>(GetYVal(iNode)));
475
wxLbl.Draw( hp, static_cast<int>(ceil(x)),
476
static_cast<int>(ceil(hr->h - y)),
482
lbl.Printf( wxT("%4.1f"), xVal);
483
wxLbl.Draw( hp, static_cast<int>(ceil(x)),
484
static_cast<int>(ceil(hr->h - y)),
490
lbl.Printf( wxT("%4.1f"), GetYVal(iNode));
492
wxLbl.Draw( hp, static_cast<int>(ceil(x)),
493
static_cast<int>(ceil(hr->h - y)),
499
lbl = GetName(iNode).c_str();
500
wxLbl.Draw( hp, static_cast<int>(ceil(x)),
501
static_cast<int>(ceil(hr->h - y)),
511
hp->SetPen( *wxBLACK_PEN );
514
//+++-S-cf-------------------------------------------------------------------
515
// NAME: CreateWxBarChartPoints()
517
// PARAMETERS: wxString name
520
// RETURN: CBarChartPoints*
521
//----------------------------------------------------------------------E-+++
522
wxBar3DChartPoints* wxBar3DChartPoints::CreateWxBar3DChartPoints(
528
if ( c == wxCHART_NOCOLOR )
529
c = wxChartColors::GetColor();
531
return new wxBar3DChartPoints( name, c, showlabel );