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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
/////////////////////////////////////////////////////////////////////////////
// Name: chartwindow.cpp
// Purpose: wxChart
// Author: Paolo Gava
// Modified by:
// Created:
// Copyright: (C) 2006, Paolo Gava
// RCS-ID: $Id: chartwindow.cpp 7551 2011-11-01 18:13:27Z jenslody $
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------
// Headers
//----------------------------------------------------------------------------
// wx
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "chartwindow.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include <wx/wxprec.h>
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "wx/chartwindow.h"
#include "wx/chartsizes.h"
IMPLEMENT_DYNAMIC_CLASS(wxChartWindow, wxWindow)
BEGIN_EVENT_TABLE(wxChartWindow, wxWindow)
EVT_PAINT( wxChartWindow::OnPaint)
EVT_LEFT_DOWN( wxChartWindow::OnMouse)
EVT_LEFT_DCLICK( wxChartWindow::OnMouse)
END_EVENT_TABLE()
//+++-S-cf-------------------------------------------------------------------
// NAME: ctor
// DESC:
// PARAMETERS: wxWindow* parent
// RETURN: None
//----------------------------------------------------------------------E-+++
wxChartWindow::wxChartWindow(
wxScrolledWindow *parent,
bool usegrid
): wxWindow(parent, -1, wxDefaultPosition, wxDefaultSize/*, wxSIMPLE_BORDER*/),
m_WinParent(parent),
m_UseGrid(usegrid)
{
SetBackgroundColour( *wxWHITE );
}
//+++-S-cf-------------------------------------------------------------------
// NAME: Draw()
// DESC: Draw chart points
// PARAMETERS: CHART_HPAINT hp,
// int x,
// int y
// RETURN: None
//----------------------------------------------------------------------E-+++
void wxChartWindow::Draw(
CHART_HPAINT hp,
int x,
int y
)
{
//-----------------------------------------------------------------------
// Get window information
//-----------------------------------------------------------------------
CHART_RECT r;
r.x = x; r.y = y;
r.xscroll = 0; r.yscroll = 0;
GetClientSize( &r.w, &r.h );
//-----------------------------------------------------------------------
// Set Background
//-----------------------------------------------------------------------
#if 0
hp->SetBrush( wxBrush(0xecf1f1, wxSOLID) ); //fcfdd8, *wxLIGHT_GREY_BRUSH
hp->SetPen( *wxTRANSPARENT_PEN );
hp->DrawRectangle(
r.x + 2,
r.y + 5,
static_cast<int>(GetVirtualWidth()),
r.h - 5
);
#endif
//-----------------------------------------------------------------------
// Draw horizontal lines
//-----------------------------------------------------------------------
if ( m_UseGrid )
DrawHLines( hp, &r );
//-----------------------------------------------------------------------
// Draw all charts
//-----------------------------------------------------------------------
m_Chart.Draw( hp, &r );
}
//+++-S-cf-------------------------------------------------------------------
// NAME: DrawHLines()
// DESC: Draw horizontal lines
// PARAMETERS: CHART_HPAINT hp,
// CHART_HRECT hr
// RETURN: None
//----------------------------------------------------------------------E-+++
void wxChartWindow::DrawHLines(
CHART_HPAINT hp,
CHART_HRECT hr
)
{
if ( GetVirtualMaxY() > 0 )
{
double range = GetVirtualMaxY();
double start = 0;
double end = range;
int int_log_range = (int)floor( log10( range ) );
double step = 1.0;
if (int_log_range > 0)
{
for (int i = 0; i < int_log_range; i++)
step *= 10;
}
if (int_log_range < 0)
{
for (int i = 0; i < -int_log_range; i++)
step /= 10;
}
double lower = ceil(start / step) * step;
double upper = floor(end / step) * step;
// if too few values, shrink size
if ((range/step) < 4)
{
step /= 2;
if (lower-step > start) lower -= step;
if (upper+step < end) upper += step;
}
// if still too few, again
if ((range/step) < 4)
{
step /= 2;
if (lower-step > start) lower -= step;
if (upper+step < end) upper += step;
}
wxChartSizes *sizes = GetSizes();
/* C::B begin */
// avoid crashes if style contains USE_GRID and no charts are added to chartctrl
if (!sizes)
return;
/* C::B end */
hp->SetPen( *wxBLACK_DASHED_PEN );
double current = lower;
while (current < upper+(step/2))
{
int y = (int)( (GetVirtualMaxY()-current) /
range * ((double)hr->h - sizes->GetSizeHeight())) - 1;
if ((y > 10) && (y < hr->h - 7 - sizes->GetSizeHeight()))
{
hp->DrawLine( hr->x,
y + sizes->GetSizeHeight() + hr->y,
hr->x + static_cast<int>(GetVirtualWidth()),
y + sizes->GetSizeHeight() + hr->y );
}
current += step;
}
}
}
//+++-S-cf-------------------------------------------------------------------
// NAME: GetVirtualWidth()
// DESC:
// PARAMETERS: NOne
// RETURN: None
//----------------------------------------------------------------------E-+++
ChartValue wxChartWindow::GetVirtualWidth() const
{
int iNodes = static_cast<int>(ceil( GetVirtualMaxX() ));
wxChartSizes *sizes = GetSizes();
/* C::B begin */
// sizes may be NULL, in this case return a fixed value
if (!sizes)
return 1;
/* C::B end */
ChartValue x = 0;
for ( int iNode = 0; iNode <= iNodes; ++ iNode )
{
x += GetZoom() * ( sizes->GetWidthBar() * sizes->GetNumBar() +
sizes->GetWidthBar3d() * sizes->GetNumBar3d() +
sizes->GetGap() );
}
return ( x );
}
//+++-S-cf-------------------------------------------------------------------
// NAME: OnPaint()
// DESC:
// PARAMETERS: wxPaintEvent &event
// RETURN: None
//----------------------------------------------------------------------E-+++
void wxChartWindow::OnPaint(
wxPaintEvent &WXUNUSED(event)
)
{
wxPaintDC dc( this );
m_WinParent->PrepareDC( dc );
//-----------------------------------------------------------------------
// Draw all charts window
//-----------------------------------------------------------------------
Draw( &dc );
}
//+++-S-cf-------------------------------------------------------------------
// NAME: OnMouse()
// DESC:
// PARAMETERS: wxMouseEvent &event
// RETURN: None
//----------------------------------------------------------------------E-+++
void wxChartWindow::OnMouse(
wxMouseEvent &WXUNUSED(event)
)
{
}
|