-
Notifications
You must be signed in to change notification settings - Fork 0
/
statistik.cpp
executable file
·168 lines (141 loc) · 3.6 KB
/
statistik.cpp
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
// *** ADDED BY HEADER FIXUP ***
#include <wx/brush.h>
#include <wx/colour.h>
#include <wx/dcclient.h>
#include <wx/gdicmn.h>
#include <wx/panel.h>
#include <wx/pen.h>
// *** END ***
#include "statistik.h"
/**Farbwerte von der Trace holen und mit Farbe zeichnen
Skala Implementieren*/
void t_Chart::OnPaint(wxPaintEvent& event)
{
calculate_autoscaling();
/* ------------Painter Settings ----------------------------------------------*/
wxPaintDC dc(this);
wxPen pen(wxColour(0,0,250),6);
pen.SetStyle(wxSOLID);
wxBrush brush;
brush.SetColour(0,100,200);
dc.SetBrush(brush);
/* ------------Draw Background------------------------------------------ */
brush.SetColour(m_r,m_b,m_g);
dc.SetBrush(brush);
wxRect statistik_back(0, 0,chartsize_x,chartsize_y);
dc.DrawRectangle(statistik_back);
//Draw scaling
brush.SetColour(0,0,0);
dc.SetBrush(brush);
int l_pos_x;
int l_pos_y;
t_Dataset::const_iterator s_itor;
//Draw Data
for (s_itor = Data.begin(); s_itor != Data.end(); s_itor++)
{
//Datesatz holen
t_Valuelist *Values = (*s_itor)->get_Data();
//akt_colour = (*s_itor)->get_trace_colour();
t_Valuelist::iterator Value_itor = Values->begin();
int current_pos = 0;
float x = 0;
float y = 0;
l_pos_x = 0;
l_pos_y = 0;
for (Value_itor = Values->begin(); Value_itor != Values->end(); Value_itor++)
{
current_pos++;
x = current_pos * scale_x;
y = ((*Value_itor) + offset_y) * scale_y ;
dc.DrawLine(x,chartsize_y-y,l_pos_x,l_pos_y);
dc.DrawPoint(x,chartsize_y-y);//Draw Datadot
l_pos_x = x;
l_pos_y = chartsize_y-y;
}
}
}
t_Chart::t_Chart(wxWindow* parent, int id): wxPanel(parent,id)
{
Connect(wxEVT_PAINT,wxPaintEventHandler(t_Chart::OnPaint));
set_name("Unnamed Chart");
set_size(200 , 200);
m_r = 255;
m_g = 255;
m_b = 255;
}
t_Chart::~t_Chart()
{
///Delete All Traces
t_Dataset::iterator itor;
for(itor = Data.begin(); itor != Data.end(); itor++)
{
delete (*itor);
}
}
void t_Chart::set_name(std::string const & value)
{
name = value;
}
void t_Chart::set_size(size_t const & x , size_t const & y)
{
chartsize_x = x;
chartsize_y = y;
SetSize(x,y);
}
void t_Chart::calculate_autoscaling()
{
//Multitrace Autoscaling
t_Dataset::iterator s_itor = Data.begin();
min = (*Data.begin())->get_min();
max = (*Data.begin())->get_max();
//Min und Max Werte ermitteln
for (s_itor = Data.begin(); s_itor != Data.end(); s_itor++)
{
if ((*s_itor)->get_min()< min)
{
min = (*s_itor)->get_min();
}
if ((*s_itor)->get_max()> max)
{
max = (*s_itor)->get_max();
}
if ((*s_itor)->get_size()>max_x)
{
max_x = (*s_itor)->get_size();
}
}
// calculate scalings
offset_y = -min;
if ((max-min ) != 0)
{
scale_y = chartsize_y / (max-min);
}
else
{
scale_y = 0;
}
if (max_x != 0)
{
scale_x = chartsize_x / max_x;
}
else
{
scale_x = 0;
}
}
t_Trace* t_Chart::add_Trace()
{
t_Trace *p_Trace = new t_Trace; //Datenliste dynamisch anlegen
Data.push_back(p_Trace); //Zum set hinzufügen
return p_Trace; //Identifier zurückgegben
}
void t_Chart::repaint()
{
Refresh(); //Manual repaint
}
void t_Chart::set_color(int r, int g , int b)
{
m_r = r;
m_g = g;
m_b = b;
}