-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
343 lines (311 loc) · 13.1 KB
/
index.html
File metadata and controls
343 lines (311 loc) · 13.1 KB
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<!doctype html>
<html lang="en">
<head>
<title>Visualization | Traffic Signaling </title>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.6.0/dist/umd/popper.min.js" integrity="sha384-KsvD1yqQ1/1+IA7gi3P0tyJcT3vR+NdBTt13hSJ2lnve8agRGXTTyNaBYmCR/Nwi" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/js/bootstrap.min.js" integrity="sha384-nsg8ua9HAw1y0W1btsyWgBklPnCUAFLuTMS2G72MMONqmOymq585AcH49TLBQObG" crossorigin="anonymous"></script>
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.4.0/font/bootstrap-icons.css" rel="stylesheet">
<style type="text/css">
html, body {
margin: 0;
padding: 0;
}
body, html {
height: 100%;
width: 100%;
}
#svg {
max-width: 100%;
max-height: 100%;
}
.box {
border-radius: 50%;
display: inline-block;
height: 20px;
vertical-align: text-bottom;
width: 20px;
}
</style>
<style>
/*https://bootsnipp.com/snippets/DOXy4*/
.files input {
outline: 2px dashed #92b0b3;
outline-offset: -10px;
-webkit-transition: outline-offset .15s ease-in-out, background-color .15s linear;
transition: outline-offset .15s ease-in-out, background-color .15s linear;
padding: 120px 0px 85px 35%;
text-align: center !important;
margin: 0;
width: 100% !important;
}
.files input:focus{ outline: 2px dashed #92b0b3; outline-offset: -10px;
-webkit-transition: outline-offset .15s ease-in-out, background-color .15s linear;
transition: outline-offset .15s ease-in-out, background-color .15s linear; border:1px solid #92b0b3;
}
.files{ position:relative}
.files:after { pointer-events: none;
position: absolute;
top: 60px;
left: 0;
width: 50px;
right: 0;
height: 56px;
content: "";
background-image: url("data:image/svg+xml, <svg xmlns='http://www.w3.org/2000/svg' fill='%23333' viewBox='0 0 16 16'><path d='M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z'/><path d='M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3z'/></svg>");
display: block;
margin: 0 auto;
background-size: 100%;
background-repeat: no-repeat;
}
.color input{ background-color:#f1f1f1;}
.files:before {
position: absolute;
bottom: 10px;
left: 0; pointer-events: none;
width: 100%;
right: 0;
height: 57px;
content: " or drag it here. ";
display: block;
margin: 0 auto;
font-weight: 600;
text-transform: capitalize;
text-align: center;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-md navbar-light static-top bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img src="../../icon.png" width="30px" height="30px" class="d-inline-block align-top" alt="">
Traffic Signaling
</a>
<div class="btn-toolbar mb-2 mb-md-0">
<div class="btn-group me-2">
<select id="page_problem_selector" class="form-select" aria-label="Select problem data set">
<option value="a_an_example">A "An Example"</option>
<option value="b_by_the_ocean">B "By The Ocean"</option>
<option value="c_checkmate">C "Checkmate"</option>
<option disabled value="d_daily_commute">D "Daily Commute"</option>
<option value="e_etoile">E "Etoile"</option>
<option disabled value="f_forever_jammed">F "Forever Jammed"</option>
</select>
</div>
</div>
<div class="btn-toolbar mb-2 mb-md-0">
<div class="btn-group me-2">
<button type="button" class="btn btn-primary btn-sm" id="sim_start"><i class="bi bi-play-fill"><i class="bi bi-pause-fill"></i></i> Start / Pause</button>
</div>
<div class="btn-group me-2">
<button type="button" class="btn btn-success btn-sm" id="sim_forward"><i class="bi bi-skip-forward-fill"></i> Step</button>
</div>
<div class="btn-group me-2">
<button type="button" class="btn btn-danger btn-sm" id="sim_reset"><i class="bi bi-x-square-fill"></i> Reset</button>
</div>
</div>
<div class="btn-toolbar mb-2 mb-md-0">
<span class="navbar-text">
Step <span id="sim-step">0</span> / <span id="sim-duration">0</span>
</span>
</div>
<div class="btn-toolbar mb-2 mb-md-0">
<div class="btn-group me-2">
<button type="button" class="btn btn-dark" data-bs-toggle="modal" data-bs-target="#uploadCenter"><i class="bi bi-upload"></i> Upload</button>
</div>
</div>
</div>
</nav>
<div style="position: fixed; bottom: 0px; right: 0px; padding: 5px; text-align: right;">
<b>Street Colors</b>
<div>Empty <span class="box" style="background:#64d66a"></span></div>
<div>1 car <span class="box" style="background:#fe9346"></span></div>
<div>2-4 cars <span class="box" style="background:#f03c32"></span></div>
<div>≥ 5 cars <span class="box" style="background:#861a19"></span></div>
</div>
<div style="position: fixed; bottom: 0px; left: 0px; padding: 5px;">
<b>Legend</b>
<ul style="margin-bottom: 0; padding-inline-start: 20px;">
<li>Drag to move the map</li>
<li>Scroll to zoom in/out</li>
<li>Hover over the intersection to see details</li>
</ul>
</div>
<div>
<svg id="svg"viewBox="0 0 100 100"></svg>
</div>
<!-- Modal -->
<div class="modal fade" id="uploadCenter" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="uploadCenterLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="uploadCenterLabel">Upload Submission File</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
Select Problem Data Set
<select id="modal_problem_selector" class="form-select" aria-label="Select problem data set">
<option value="a_an_example">A "An Example"</option>
<option value="b_by_the_ocean">B "By The Ocean"</option>
<option value="c_checkmate">C "Checkmate"</option>
<option disabled value="d_daily_commute">D "Daily Commute"</option>
<option value="e_etoile">E "Etoile"</option>
<option disabled value="f_forever_jammed">F "Forever Jammed"</option>
</select>
</div>
<div class="modal-body">
<form method="post" action="#" id="#">
<div class="form-group files">
<label>Upload Submission File</label>
<input type="file" class="form-control" multiple="">
</div>
</form>
</div>
</div>
</div>
</div>
<script>
$(window).on("resize", function() {
// avoid scrollbars
container = $("#svg").parent();
w = $(window).width();
h = $(window).height();
h = h - $("#nav").outerHeight();
h = Math.floor(h);
w = Math.floor(w);
// container.css( "height", h + 'px' );
// container.css( "width", w + 'px' );
}).trigger("resize");
var svg = d3.select("svg");
//add zoom capabilities
var zoom_handler = d3.zoom().on("zoom", zoom_actions);
var g, link, node;
var visualization;
var problem_set;
var problem_set_pos;
function visualize(problem_set_name) {
$.ajax({ // read data set
url: 'input/' + problem_set_name + '.json',
async: false,
dataType: 'json',
success: function(data) {
problem_set = data;
}
});
$.ajax({ // read node positions
url: 'input/' + problem_set_name + '.pos',
async: false,
dataType: 'text',
success: function(data) {
problem_set_pos = Array.from(data.trim().split("\n"), x => x.split(" ").map(Number));
}
});
$("#svg").html(""); // reset svg content
visualization = new Visualization(svg, problem_set, problem_set_pos);
};
$(window).on("load", function() {
visualize($("#page_problem_selector :selected").val());
})
$('#page_problem_selector').change(function(){
visualize($(this).val());
});
svg.on("click", function() {
// do something
});
var Visualization = function (svg, data, positions) {
const svg_width = positions[0][0];
const svg_height = positions[0][1];
const n_nodes = data.i.length;
$("#svg").attr("viewBox", "0 0 " + svg_width + " " + svg_height);
//add encompassing group for the zoom
g = svg.append("g").attr("class", "everything");
// set simulation duration
$("#sim-duration").text(data.d)
// reset simulation step
$("#sim-step").text(0)
// Initialize the positions deterministically, with given positions.
data.i.forEach(function(d, i) {
d.x = svg_width * positions[i + 1][0] / positions[0][0];
d.y = svg_height * positions[i + 1][1] / positions[0][1];
});
// Center the nodes in the middle.
var ox = 0, oy = 0;
var max_h = 0, min_h = svg_height, max_w = 0, min_w = svg_width;
data.i.forEach(function(d) {
ox += d.x, oy += d.y;
if (d.x > max_w) max_w = d.x;
if (d.x < min_w) min_w = d.x;
if (d.y > max_h) max_h = d.y;
if (d.y < min_h) min_h = d.y;
});
max_w = Math.floor(1.1 * max_w);
max_h = Math.floor(1.1 * max_h);
ox = ox / n_nodes - svg_width / 2, oy = oy / n_nodes - svg_height / 2;
data.i.forEach(function(d) { d.x -= ox, d.y -= oy; });
$("#svg").attr("viewBox", "0 0 " + max_w + " " + max_h);
link = g.append("g")
.attr("class", "links")
.selectAll("line")
.data(data.s)
.enter().append("line")
.attr("class", "link")
.attr("link-id", function(d) { return d.id; })
.attr("x2", function(d) { return data.i[d.source].x; })
.attr("y2", function(d) { return data.i[d.source].y; })
.attr("x1", function(d) { return data.i[d.target].x; })
.attr("y1", function(d) { return data.i[d.target].y; })
.attr("fill", "none")
.attr("stroke", "black");
node = g.append("g")
.attr("class", "nodes")
.selectAll("circle").data(data.i)
.enter().append("circle")
.attr("class", "node")
.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; })
.attr("node-id", function(d) { return d.id; })
.attr("r", 2.0)
.attr("fill", function(d) { return "#0d6efd"; });
zoom_handler(svg);
};
//Zoom functions
function zoom_actions(){
g.attr("transform", d3.event.transform)
}
function previewfile(file) {
var reader = new FileReader();
reader.onload = function () {
$('#exampleModalCenter').modal('toggle');
$("#svg").html("");
var svg = d3.select("svg");
var visualization = new Visualization(svg, JSON.parse(reader.result));
};
reader.readAsText(file);
}
function readfiles(files) {
var formData = tests.formdata ? new FormData() : null;
for (var i = 0; i < files.length; i++) {
if (tests.formdata) formData.append('file', files[i]);
previewfile(files[i]);
}
}
function readSingleFile(e) {
var file = e.target.files[0];
if (!file) {
return;
}
var reader = new FileReader();
reader.onload = function(e) {
var contents = e.target.result;
displayContents(contents);
};
reader.readAsText(file);
}
</script>
</body>
</html>