-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
230 lines (198 loc) · 6.44 KB
/
index.html
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
<!DOCTYPE HTML>
<html>
<head>
<script src="js/jquery.js"></script>
<link href="css/bootstrap.css" rel ="stylesheet">
<script src="js/bootstrap.js"></script>
<script src="js/chart.js"></script>
</head>
<body>
<div id="container" class = "container" style="width:100%; margin-top:10px; background:rgb(120,120,120);">
<!-- UPLOAD FILE HERE -->
<input type ='file' id='trainData' style='display:none'></input>
<a id='result'></a>
<!-- This is the buttons -->
<div class = "row" >
<div class="col-md-2" style= "">
<div> <h1><span class="label label-info" id = "time">Time</span></h1></div><br>
<div class = "row">
<div class="btn-group col-md-6">
<div class="input-group input-group-md">
<input type="text" class="form-control" placeholder="Train to slow/stop" aria-describedby="sizing-addon1" id = "trayn">
</div>
</div>
<div class= "col-md-3">
<button type="button" class="btn btn-default" id="slow">Slow</button>
</div>
<div class= "col-md-3">
<button type="button" class="btn btn-default" id="stop">Stop</button>
</div>
</div><br>
<div class= "row">
<div class="col-md-8">
<div class="input-group input-group-md">
<input type="text" class="form-control" placeholder="Train ID" aria-describedby="sizing-addon1" id = "trainid">
</div>
</div>
<div class="col-md-4">
</div>
</div><br>
<div id="traininfo">
</div>
</div>
<div class = "col-md-10" style=" background:black; height:780px;" id = "canvas">
<canvas id="myCanvas" width="80%" height="100%"></canvas>
<p style="color:white;">Hello</p>
</div>
</div>
</div>
<script type="text/javascript">
var ctx = document.getElementById('myCanvas').getContext('2d');
var scaleFactor = 1;
var translateX = 0;
var translateY = 0;
function draw(){
var width = screen.width*8/10;
var height = screen.height;
lanes['1E'] = width*1/8;
lanes['1W'] = width*2/8;
lanes['2N'] = width*3/8;
lanes['2S'] = width*4/8;
lanes['3E'] = width*5/8;
lanes['3W'] = width*6/8;
laneLength['1E'] = 15;
laneLength['1W'] = 15;
laneLength['2N'] = 20;
laneLength['2S'] = 20;
laneLength['3E'] = 25;
laneLength['3W'] = 25;
document.getElementById('myCanvas').width = width;
document.getElementById('myCanvas').height = height;
ctx.translate((width/2-translateX)*(scaleFactor-1),(height/2-translateY)*(scaleFactor-1));
ctx.scale(scaleFactor,scaleFactor);
//for (var i = 1; i < 7; i++){
ctx.clearRect(0, 0, width, height);
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(lanes['1E'],0);
ctx.lineTo(lanes['1E'],468);
ctx.strokeStyle = '#ff0000';
ctx.stroke();
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(lanes['1W'],0);
ctx.lineTo(lanes['1W'],468);
ctx.strokeStyle = '#ff0000';
ctx.stroke();
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(lanes['2N'],0);
ctx.lineTo(lanes['2N'],624);
ctx.strokeStyle = '#ff0000';
ctx.stroke();
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(width*4/8,0);
ctx.lineTo(width*4/8,624);
ctx.strokeStyle = '#ff0000';
ctx.stroke();
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(width*5/8,0);
ctx.lineTo(width*5/8,780);
ctx.strokeStyle = '#ff0000';
ctx.stroke();
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(width*6/8,0);
ctx.lineTo(width*6/8,780);
ctx.strokeStyle = '#ff0000';
ctx.stroke();
// }
ctx.fillStyle = '#f00';
ctx.font = 'italic bold 30px sans-serif';
ctx.textBaseline = 'bottom';
ctx.fillText('1E', lanes['1E']-50, 100);
ctx.fillStyle = '#f00';
ctx.font = 'italic bold 30px sans-serif';
ctx.textBaseline = 'bottom';
ctx.fillText('1W', lanes['1W']-50, 100);
ctx.fillStyle = '#f00';
ctx.font = 'italic bold 30px sans-serif';
ctx.textBaseline = 'bottom';
ctx.fillText('2N', lanes['2N']-50, 100);
ctx.fillStyle = '#f00';
ctx.font = 'italic bold 30px sans-serif';
ctx.textBaseline = 'bottom';
ctx.fillText('2S', width*4/8-50, 100);
ctx.fillStyle = '#f00';
ctx.font = 'italic bold 30px sans-serif';
ctx.textBaseline = 'bottom';
ctx.fillText('3E', width*5/8-50, 100);
ctx.fillStyle = '#f00';
ctx.font = 'italic bold 30px sans-serif';
ctx.textBaseline = 'bottom';
ctx.fillText('3W', width*6/8-50, 100);
for(train in trainsArray){
trainDraw(trainsArray[train]);
}
trainsArray = [];
}
var counter = 0;
var trainsArray = [];
var lanes =[];
var laneLength = [];
function addTrains(train){
//count to 5, every 5th time, redraw
if(++counter >= 5){
draw(trainsArray);
counter =0;
}
trainsArray.push(train);
}
function trainDraw(train){
if ($("#trainid").val() == train.Train) {
console.log(train);
var str = '';
str += '<p>Train: ' + train.Train + ' <\/p><br>';
str += '<p>Speed: ' + train.Speed + ' <\/p><br>';
str += '<p>track: ' + train.track + ' <\/p><br>';
str += '<p>status: ' + train.status + ' <\/p><br>';
$('#traininfo').html(str);
}
ctx.lineWidth = 1;
ctx.beginPath();
console.log(lanes[train.track] +' ' +train.FrtLoc/laneLength[train.track])
ctx.moveTo(lanes[train.track]-10,train.FrtLoc/laneLength[train.track]);
ctx.lineTo(lanes[train.track]+10,train.RearLoc/laneLength[train.track]);
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
var event = 'onwheel' in document ? 'wheel' : 'onmousewheel' in document ? 'mousewheel' : 'DOMMouseScroll';
window.addEventListener(event, wheelHandle);
function wheelHandle(event) {
var normalized;
if (event.wheelDelta) {
normalized = (event.wheelDelta % 120 - 0) == -0 ? event.wheelDelta / 120 : event.wheelDelta / 12;
} else {
var rawAmmount = event.deltaY ? event.deltaY : event.detail;
normalized = -(rawAmmount % 3 ? rawAmmount * 10 : rawAmmount / 3);
}
report(normalized,event);
}
function report(ammout,event) {
console.log('wheel ammout: ' + ammout);
console.log(event.pageX);
console.log(event.pageY);
translateX = event.pageX/2;
translateY = event.pageY/2;
scaleFactor += ammout /100;
}
</script>
<link href="css/main.css"></script>
<script src="js/dataBaseLoop.js"></script>
<script type="js/generateResult.js"></script>
<script src="js/fullscreen.js"></script>
<script src="js/main.js"></script>
</body>
</html>