1
/////////////////////////////////////////////////////////////////////////////
2
// Name: chartwindow.cpp
7
// Copyright: (C) 2006, Paolo Gava
8
// RCS-ID: $Id: chartwindow.cpp 7551 2011-11-01 18:13:27Z jenslody $
9
// Licence: wxWindows licence
10
/////////////////////////////////////////////////////////////////////////////
12
//----------------------------------------------------------------------------
14
//----------------------------------------------------------------------------
17
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
18
#pragma implementation "chartwindow.h"
21
// For compilers that support precompilation, includes "wx.h".
22
#include <wx/wxprec.h>
32
#include "wx/chartwindow.h"
33
#include "wx/chartsizes.h"
35
IMPLEMENT_DYNAMIC_CLASS(wxChartWindow, wxWindow)
37
BEGIN_EVENT_TABLE(wxChartWindow, wxWindow)
38
EVT_PAINT( wxChartWindow::OnPaint)
39
EVT_LEFT_DOWN( wxChartWindow::OnMouse)
40
EVT_LEFT_DCLICK( wxChartWindow::OnMouse)
44
//+++-S-cf-------------------------------------------------------------------
47
// PARAMETERS: wxWindow* parent
49
//----------------------------------------------------------------------E-+++
50
wxChartWindow::wxChartWindow(
51
wxScrolledWindow *parent,
53
): wxWindow(parent, -1, wxDefaultPosition, wxDefaultSize/*, wxSIMPLE_BORDER*/),
57
SetBackgroundColour( *wxWHITE );
60
//+++-S-cf-------------------------------------------------------------------
62
// DESC: Draw chart points
63
// PARAMETERS: CHART_HPAINT hp,
67
//----------------------------------------------------------------------E-+++
68
void wxChartWindow::Draw(
74
//-----------------------------------------------------------------------
75
// Get window information
76
//-----------------------------------------------------------------------
79
r.xscroll = 0; r.yscroll = 0;
80
GetClientSize( &r.w, &r.h );
82
//-----------------------------------------------------------------------
84
//-----------------------------------------------------------------------
87
hp->SetBrush( wxBrush(0xecf1f1, wxSOLID) ); //fcfdd8, *wxLIGHT_GREY_BRUSH
88
hp->SetPen( *wxTRANSPARENT_PEN );
92
static_cast<int>(GetVirtualWidth()),
97
//-----------------------------------------------------------------------
98
// Draw horizontal lines
99
//-----------------------------------------------------------------------
101
DrawHLines( hp, &r );
103
//-----------------------------------------------------------------------
105
//-----------------------------------------------------------------------
106
m_Chart.Draw( hp, &r );
109
//+++-S-cf-------------------------------------------------------------------
110
// NAME: DrawHLines()
111
// DESC: Draw horizontal lines
112
// PARAMETERS: CHART_HPAINT hp,
115
//----------------------------------------------------------------------E-+++
116
void wxChartWindow::DrawHLines(
121
if ( GetVirtualMaxY() > 0 )
123
double range = GetVirtualMaxY();
127
int int_log_range = (int)floor( log10( range ) );
129
if (int_log_range > 0)
131
for (int i = 0; i < int_log_range; i++)
134
if (int_log_range < 0)
136
for (int i = 0; i < -int_log_range; i++)
139
double lower = ceil(start / step) * step;
140
double upper = floor(end / step) * step;
142
// if too few values, shrink size
143
if ((range/step) < 4)
146
if (lower-step > start) lower -= step;
147
if (upper+step < end) upper += step;
150
// if still too few, again
151
if ((range/step) < 4)
154
if (lower-step > start) lower -= step;
155
if (upper+step < end) upper += step;
158
wxChartSizes *sizes = GetSizes();
160
// avoid crashes if style contains USE_GRID and no charts are added to chartctrl
165
hp->SetPen( *wxBLACK_DASHED_PEN );
167
double current = lower;
168
while (current < upper+(step/2))
170
int y = (int)( (GetVirtualMaxY()-current) /
171
range * ((double)hr->h - sizes->GetSizeHeight())) - 1;
172
if ((y > 10) && (y < hr->h - 7 - sizes->GetSizeHeight()))
175
y + sizes->GetSizeHeight() + hr->y,
176
hr->x + static_cast<int>(GetVirtualWidth()),
177
y + sizes->GetSizeHeight() + hr->y );
185
//+++-S-cf-------------------------------------------------------------------
186
// NAME: GetVirtualWidth()
190
//----------------------------------------------------------------------E-+++
191
ChartValue wxChartWindow::GetVirtualWidth() const
193
int iNodes = static_cast<int>(ceil( GetVirtualMaxX() ));
194
wxChartSizes *sizes = GetSizes();
197
// sizes may be NULL, in this case return a fixed value
204
for ( int iNode = 0; iNode <= iNodes; ++ iNode )
206
x += GetZoom() * ( sizes->GetWidthBar() * sizes->GetNumBar() +
207
sizes->GetWidthBar3d() * sizes->GetNumBar3d() +
214
//+++-S-cf-------------------------------------------------------------------
217
// PARAMETERS: wxPaintEvent &event
219
//----------------------------------------------------------------------E-+++
220
void wxChartWindow::OnPaint(
221
wxPaintEvent &WXUNUSED(event)
224
wxPaintDC dc( this );
225
m_WinParent->PrepareDC( dc );
227
//-----------------------------------------------------------------------
228
// Draw all charts window
229
//-----------------------------------------------------------------------
233
//+++-S-cf-------------------------------------------------------------------
236
// PARAMETERS: wxMouseEvent &event
238
//----------------------------------------------------------------------E-+++
239
void wxChartWindow::OnMouse(
240
wxMouseEvent &WXUNUSED(event)