-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHistoryGraph.qml
289 lines (270 loc) · 8.57 KB
/
HistoryGraph.qml
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
import QtQuick 2.0
// A HistoryGraph alapvetően egy Canvas, mivel arra lehet rajzolni.
Canvas {
// Vannak neki további tulajdonságai, amiket kintről kap
property var graphTimestamps;
property var graphVelocities;
property var graphAccelerations;
property var graphCarHeights;
property var carCurrentHeight;
// A Canvas Paint signalja esetén újra kell rajzolni a grafikont.
onPaint: {
// A grafikon rajzolát itt, a QML oldalon, JavaScripben megírva történik.
// Kell egy "drawing context", amire rajzolni tudunk.
var context = getContext("2d");
context.fillStyle = "white"
context.fillRect(0, 0, width, height);
switch(carCurrentHeight) {
case 24:
context.drawImage(image1, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 23:
context.drawImage(image2, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 22:
context.drawImage(image3, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 21:
context.drawImage(image4, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 20:
context.drawImage(image5, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 19:
context.drawImage(image6, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 18:
context.drawImage(image7, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 17:
context.drawImage(image8, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 16:
context.drawImage(image9, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 15:
context.drawImage(image10, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 14:
context.drawImage(image11, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 13:
context.drawImage(image12, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 12:
context.drawImage(image13, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 11:
context.drawImage(image14, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 10:
context.drawImage(image15, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 9:
context.drawImage(image16, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 8:
context.drawImage(image17, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 7:
context.drawImage(image18, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 6:
context.drawImage(image19, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 5:
context.drawImage(image20, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 4:
context.drawImage(image21, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 3:
context.drawImage(image22, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 2:
context.drawImage(image23, width*0.8, height*0.1, width*0.2, height*0.7);
break;
case 1:
context.drawImage(image24, width*0.8, height*0.1, width*0.2, height*0.7);
break;
default:
context.drawImage(image13, width*0.8, height*0.1, width*0.2, height*0.7);
break;
}
// Vízszintes vonalak berajzolása a függőleges pozíció, a szín és a függőleges
// skálázás megadásával. (Erre van külön függvényünk.)
drawHorizontalLine(context, height*0.571, "rgba(0,0,0,1)", 1.0)
// Az adatsorok megrajzolása (a graphTimestamps értékét jelenleg nem használjuk).
// Ez is külön függvénybe került.
//drawDataset(context, graphVelocities, "rgba(110,220,110,1)", 5.0);
//drawDataset(context, graphAccelerations, "rgba(220,110,110,1)", 5.0);
drawTrack(context, graphCarHeights, "rgba(220,110,220,1)", height/28);
//drawDataset(context, graphCarHeights, "rgba(110,110,220,1)", height/60);
} // onPaint vége
// Vízszintes vonal berajzolása.
function drawHorizontalLine(context, y, strokeStyle)
{
context.beginPath();
context.lineWidth = 1;
context.strokeStyle = strokeStyle;
// Mozgás a vonal elejére.
context.moveTo(0, y);
// Vonal végére mozgás.
context.lineTo(width, y) ;
context.stroke();
}
function drawTrack(context, datarow, strokeStyle, verticalScaler)
{
var offsetY = height*0.571;
var offsetX = width*0.79;
context.fillStyle = "rgba(128,128,128,1)";
// A vektoron végigmenve visszafele behúzzuk a nyomvonalat.
for(var i=datarow.length-1 -1; i>=0; i--)
{
var strengthThis = verticalScaler * (24 - datarow[i]);
var strengthPrev = verticalScaler * (24 - datarow[i+1]);
context.beginPath();
context.moveTo(offsetX - 10 * (datarow.length-1 - i -1), offsetY - strengthPrev/2);
context.lineTo(offsetX - 10 * (datarow.length-1 - i) -1, offsetY - strengthThis/2);
context.lineTo(offsetX - 10 * (datarow.length-1 - i) -1, offsetY + strengthThis/2);
context.lineTo(offsetX - 10 * (datarow.length-1 - i -1), offsetY + strengthPrev/2);
context.closePath();
context.fill();
}
}
function drawDataset(context, datarow, strokeStyle, verticalScaler)
{
var offsetY = height/2;
var offsetX = width*0.8;
context.beginPath();
context.lineWidth = 2;
context.strokeStyle = strokeStyle;
context.moveTo(offsetX, offsetY - verticalScaler * datarow[datarow.length-1]);
// A vektoron végigmenve visszafele behúzzuk a grafikon szakaszait.
for(var i=datarow.length-1; i>=0; i--)
{
context.lineTo(offsetX - 10 * (datarow.length-1 - i), offsetY - verticalScaler * datarow[i]);
}
context.stroke();
}
Image{
id: image1
visible: false
source: '8-512 (1).png'
}
Image{
id: image2
visible: false
source: '8-512 (2).png'
}
Image{
id: image3
visible: false
source: '8-512 (3).png'
}
Image{
id: image4
visible: false
source: '8-512 (4).png'
}
Image{
id: image5
visible: false
source: '8-512 (5).png'
}
Image{
id: image6
visible: false
source: '8-512 (6).png'
}
Image{
id: image7
visible: false
source: '8-512 (7).png'
}
Image{
id: image8
visible: false
source: '8-512 (8).png'
}
Image{
id: image9
visible: false
source: '8-512 (9).png'
}
Image{
id: image10
visible: false
source: '8-512 (10).png'
}
Image{
id: image11
visible: false
source: '8-512 (11).png'
}
Image{
id: image12
visible: false
source: '8-512 (12).png'
}
Image{
id: image13
visible: false
source: '8-512 (13).png'
}
Image{
id: image14
visible: false
source: '8-512 (14).png'
}
Image{
id: image15
visible: false
source: '8-512 (15).png'
}
Image{
id: image16
visible: false
source: '8-512 (16).png'
}
Image{
id: image17
visible: false
source: '8-512 (17).png'
}
Image{
id: image18
visible: false
source: '8-512 (18).png'
}
Image{
id: image19
visible: false
source: '8-512 (19).png'
}
Image{
id: image20
visible: false
source: '8-512 (20).png'
}
Image{
id: image21
visible: false
source: '8-512 (21).png'
}
Image{
id: image22
visible: false
source: '8-512 (22).png'
}
Image{
id: image23
visible: false
source: '8-512 (23).png'
}
Image{
id: image24
visible: false
source: '8-512 (24).png'
}
}