1 | 'use strict';
|
---|
2 |
|
---|
3 | // ==========================================================================
|
---|
4 |
|
---|
5 | function onRightMouseClick(event)
|
---|
6 | {
|
---|
7 | if (event.button!=2)
|
---|
8 | return;
|
---|
9 |
|
---|
10 | var strData = event.target.toDataURL("image/png");
|
---|
11 |
|
---|
12 | var img = document.createElement("img");
|
---|
13 | img.src = strData;
|
---|
14 |
|
---|
15 | $(img).css({ "z-index": "9999", "position": "absolute" });
|
---|
16 | $(img).insertBefore($(event.target));
|
---|
17 |
|
---|
18 | setTimeout(function () { $(img).remove(); }, 100);
|
---|
19 | }
|
---|
20 |
|
---|
21 | (function ($)
|
---|
22 | {
|
---|
23 |
|
---|
24 | $.plot.plugins.push({
|
---|
25 | init: function(plot, classes)
|
---|
26 | {
|
---|
27 | plot.hooks.bindEvents.push(function(plot, eventHolder) { eventHolder.mousedown(onRightMouseClick); });
|
---|
28 | plot.hooks.shutdown.push(function(plot, eventHolder) { eventHolder.unbind("mousedown", onRightMouseClick); });
|
---|
29 | },
|
---|
30 | name: 'saveAsImage',
|
---|
31 | version: '1.0'
|
---|
32 | });
|
---|
33 |
|
---|
34 | })(jQuery);
|
---|
35 |
|
---|
36 | // ==========================================================================
|
---|
37 |
|
---|
38 | var editor1;
|
---|
39 | var editor2;
|
---|
40 | var plot;
|
---|
41 |
|
---|
42 | function debug(txt)
|
---|
43 | {
|
---|
44 | var dbg = document.getElementById("debug");
|
---|
45 | dbg.appendChild(document.createTextNode(txt));
|
---|
46 | dbg.appendChild(document.createElement("br"));
|
---|
47 | }
|
---|
48 |
|
---|
49 | function setupAccordion(accordion, container, inactive)
|
---|
50 | {
|
---|
51 | function onAccordion(event, ui)
|
---|
52 | {
|
---|
53 | if (ui.oldHeader.length==0)
|
---|
54 | $(container).slideDown(400);
|
---|
55 | else
|
---|
56 | $(container).slideUp(400);
|
---|
57 | }
|
---|
58 |
|
---|
59 | var config = { collapsible: true };
|
---|
60 |
|
---|
61 | if (inactive)
|
---|
62 | {
|
---|
63 | config.active = false;
|
---|
64 | $(container).hide();
|
---|
65 | }
|
---|
66 |
|
---|
67 | var acc = $(accordion);
|
---|
68 |
|
---|
69 | acc.accordion(config);
|
---|
70 | acc.on("accordionbeforeactivate", onAccordion);
|
---|
71 | }
|
---|
72 |
|
---|
73 | function onResize(event, ui)
|
---|
74 | {
|
---|
75 | if (!ui.size)
|
---|
76 | return;
|
---|
77 |
|
---|
78 | $(event.target.id).css({marginRight:'2px'});
|
---|
79 |
|
---|
80 | var editor = event.target.id=="textcontainer1" ? editor1 : editor2;
|
---|
81 |
|
---|
82 | editor.setSize("100%", ui.size.height);
|
---|
83 | editor.refresh();
|
---|
84 | }
|
---|
85 |
|
---|
86 | function setSize(id, w, h)
|
---|
87 | {
|
---|
88 | w = parseInt(w);
|
---|
89 | h = parseInt(h);
|
---|
90 |
|
---|
91 | $("#"+id).width(w);
|
---|
92 | $("#"+id).height(h);
|
---|
93 |
|
---|
94 | document.getElementById(id).width=w;
|
---|
95 | document.getElementById(id).height=h;
|
---|
96 | }
|
---|
97 |
|
---|
98 | function onResizeGrid(id)
|
---|
99 | {
|
---|
100 | var w = document.getElementById(id+"container").clientWidth/4;
|
---|
101 |
|
---|
102 | var offy = 0;
|
---|
103 | var offx = 5;
|
---|
104 |
|
---|
105 | var cont = document.getElementById("center"+id).childNodes[0];
|
---|
106 |
|
---|
107 | var nn;
|
---|
108 | if (cont)
|
---|
109 | {
|
---|
110 | nn = parseInt(cont.id[cont.id.length-1]);
|
---|
111 | setSize(id+nn, w*2, w*2);
|
---|
112 | }
|
---|
113 |
|
---|
114 | if (nn!=1)
|
---|
115 | setSize(id+'1', w-offx, w-offy);
|
---|
116 | if (nn!=2)
|
---|
117 | setSize(id+'2', w-offx, w-offy);
|
---|
118 | if (nn!=3)
|
---|
119 | setSize(id+'3', w-offx, w-offy);
|
---|
120 | if (nn!=4)
|
---|
121 | setSize(id+'4', w-offx, w-offy);
|
---|
122 |
|
---|
123 | document.getElementById("center"+id).width=parseInt(w*2);
|
---|
124 |
|
---|
125 | setSize('cont'+id+'1', w, w);
|
---|
126 | setSize('cont'+id+'2', w, w);
|
---|
127 | setSize('cont'+id+'3', w, w);
|
---|
128 | setSize('cont'+id+'4', w, w);
|
---|
129 | }
|
---|
130 |
|
---|
131 | function onResizeCameras(event, ui)
|
---|
132 | {
|
---|
133 | onResizeGrid('camera');
|
---|
134 |
|
---|
135 | drawFullCam("camera1");
|
---|
136 | drawFullCam("camera2");
|
---|
137 | drawFullCam("camera3");
|
---|
138 | drawFullCam("camera4");
|
---|
139 | }
|
---|
140 |
|
---|
141 | function onResizeHistograms(event, ui)
|
---|
142 | {
|
---|
143 | onResizeGrid('hist');
|
---|
144 | }
|
---|
145 |
|
---|
146 | function createEditor(textarea)
|
---|
147 | {
|
---|
148 | var editor;
|
---|
149 |
|
---|
150 | var config =
|
---|
151 | {
|
---|
152 | //value: "function myScript(){return 100;}\n",
|
---|
153 | mode: { name: "text/typescript", globalVars: true },
|
---|
154 | indentUnit: 4,
|
---|
155 | styleActiveLine: true,
|
---|
156 | matchBrackets: true,
|
---|
157 | lineNumbers: true,
|
---|
158 | foldGutter: true,
|
---|
159 | lint: true,
|
---|
160 | highlightSelectionMatches: {showToken: /\w/},
|
---|
161 | gutters: ["CodeMirror-lint-markers", "CodeMirror-linenumbers", "CodeMirror-foldgutter"],
|
---|
162 | extraKeys: {
|
---|
163 | //"Ctrl-D": "duplicateLine",
|
---|
164 | //"Alt--": "goToBracket",
|
---|
165 | //"Ctrl-H": "findPrev",
|
---|
166 | "Ctrl-Down": "autocomplete",
|
---|
167 | "Tab": "indentAuto",
|
---|
168 | "Ctrl-Y": "deleteLine",
|
---|
169 | "Ctrl-.": function(cm) {
|
---|
170 | cm.foldCode(cm.getCursor());
|
---|
171 | },
|
---|
172 | "F11": function(cm) {
|
---|
173 | editor.setOption("fullScreen", !editor.getOption("fullScreen"));
|
---|
174 | },
|
---|
175 | "Ctrl-R": function(cm) {
|
---|
176 | editor.execCommand("replace");
|
---|
177 | },
|
---|
178 | "Esc": function(cm) {
|
---|
179 | if (editor.getOption("fullScreen")) editor.setOption("fullScreen", false);
|
---|
180 | },
|
---|
181 | "Enter": function(cm) {
|
---|
182 | editor.execCommand("indentAuto");
|
---|
183 | editor.execCommand("newlineAndIndent");
|
---|
184 | },
|
---|
185 | }
|
---|
186 | };
|
---|
187 |
|
---|
188 | editor = CodeMirror.fromTextArea(document.getElementById(textarea), config);
|
---|
189 | editor.setOption("theme", "blackboard");
|
---|
190 |
|
---|
191 | return editor;
|
---|
192 | }
|
---|
193 |
|
---|
194 | function colorizeHTML(textarea)
|
---|
195 | {
|
---|
196 | var config =
|
---|
197 | {
|
---|
198 | //value: "function myScript(){return 100;}\n",
|
---|
199 | mode: { name: "text/typescript", globalVars: true },
|
---|
200 | readOnly: true,
|
---|
201 | };
|
---|
202 |
|
---|
203 | CodeMirror.fromTextArea(document.getElementById(textarea), config);
|
---|
204 | }
|
---|
205 |
|
---|
206 | function disableControls(disabled)
|
---|
207 | {
|
---|
208 | $('#submit').prop('disabled', disabled);
|
---|
209 | $('#getcamera').prop('disabled', disabled);
|
---|
210 | $('#getwaveforms').prop('disabled', disabled);
|
---|
211 | $('#event').prop('disabled', disabled);
|
---|
212 | $('#pixel').prop('disabled', disabled);
|
---|
213 | $('#cbpx').prop('disabled', disabled);
|
---|
214 | $('#cbpx-c').prop('disabled', disabled);
|
---|
215 | $('#cbpx-b').prop('disabled', disabled);
|
---|
216 | $('#cbpx-p').prop('disabled', disabled);
|
---|
217 | $('#cbpx-x').prop('disabled', disabled);
|
---|
218 | $('#file').prop('disabled', disabled);
|
---|
219 |
|
---|
220 | if (disabled)
|
---|
221 | $('#calibrated').prop('disabled', true);
|
---|
222 | else
|
---|
223 | {
|
---|
224 | var list = document.getElementById("file").data;
|
---|
225 | if (list)
|
---|
226 | {
|
---|
227 | var file = document.getElementById("file").value;
|
---|
228 | $('#calibrated').prop('disabled', !list[file]);
|
---|
229 | }
|
---|
230 | }
|
---|
231 | }
|
---|
232 |
|
---|
233 | function onGetCameras()
|
---|
234 | {
|
---|
235 | var arr =
|
---|
236 | [
|
---|
237 | document.getElementById("camera1").dataAbs,
|
---|
238 | document.getElementById("camera2").dataAbs,
|
---|
239 | document.getElementById("camera3").dataAbs,
|
---|
240 | document.getElementById("camera4").dataAbs,
|
---|
241 | ];
|
---|
242 |
|
---|
243 | $('#controls > input[name=data]').val(JSON.stringify(arr));
|
---|
244 | $('#controls').attr('action','index.php');
|
---|
245 | $('#controls').submit();
|
---|
246 | }
|
---|
247 |
|
---|
248 | function onGetWaveforms()
|
---|
249 | {
|
---|
250 | var arr = document.getElementById("waveform").data;
|
---|
251 |
|
---|
252 | $('#controls > input[name=data]').val(JSON.stringify(arr));
|
---|
253 | $('#controls').attr('action','index.php');
|
---|
254 | $('#controls').submit();
|
---|
255 | }
|
---|
256 |
|
---|
257 | function onReady()
|
---|
258 | {
|
---|
259 | CodeMirror.colorize(null, 'javascript');
|
---|
260 |
|
---|
261 | //$('input,select').keypress(function(event) { return event.keyCode != 13; });
|
---|
262 |
|
---|
263 | //colorizeHTML("code0");
|
---|
264 | //colorizeHTML("code1");
|
---|
265 |
|
---|
266 | $("#accordion").accordion({collapsible:true,active:false,heightStyle:'content'});
|
---|
267 | $("#accordion").find('h3').filter(':contains(Runtime)').hide();
|
---|
268 | if (location.href.search('debug')==-1)
|
---|
269 | $("#accordion").find('h3').filter(':contains(Debug)').hide();
|
---|
270 |
|
---|
271 | $("#textcontainer1").resizable({handles:"s",autoHide:true,});
|
---|
272 | $("#textcontainer1").on("resize", onResize);
|
---|
273 |
|
---|
274 | $("#textcontainer2").resizable({handles:"s",autoHide:true,});
|
---|
275 | $("#textcontainer2").on("resize", onResize);
|
---|
276 |
|
---|
277 | $("#cameracontainer").on("resize", onResizeCameras);
|
---|
278 | onResizeCameras();
|
---|
279 |
|
---|
280 | $("#histcontainer").on("resize", onResizeHistograms);
|
---|
281 | onResizeHistograms();
|
---|
282 |
|
---|
283 | $("#contcamera1").click(onClickContCamera);
|
---|
284 | $("#contcamera2").click(onClickContCamera);
|
---|
285 | $("#contcamera3").click(onClickContCamera);
|
---|
286 | $("#contcamera4").click(onClickContCamera);
|
---|
287 |
|
---|
288 | $("#conthist1").click(onClickContHist);
|
---|
289 | $("#conthist2").click(onClickContHist);
|
---|
290 | $("#conthist3").click(onClickContHist);
|
---|
291 | $("#conthist4").click(onClickContHist);
|
---|
292 |
|
---|
293 | $("#camera1").click(onClick);
|
---|
294 | $("#camera2").click(onClick);
|
---|
295 | $("#camera3").click(onClick);
|
---|
296 | $("#camera4").click(onClick);
|
---|
297 |
|
---|
298 | $('#camera1').mousedown(onRightMouseClick);
|
---|
299 | $('#camera2').mousedown(onRightMouseClick);
|
---|
300 | $('#camera3').mousedown(onRightMouseClick);
|
---|
301 | $('#camera4').mousedown(onRightMouseClick);
|
---|
302 |
|
---|
303 | editor1 = createEditor("editor1");
|
---|
304 | editor2 = createEditor("editor2");
|
---|
305 |
|
---|
306 | setupAccordion('#accordion5', '#editorcontainer1', true);
|
---|
307 | setupAccordion('#accordion1', '#editorcontainer2');
|
---|
308 |
|
---|
309 | $('#accordion5').on("accordionactivate", function() { $('#editorcontainer1fake').hide(); editor1.refresh(); });
|
---|
310 | $('#accordion1').on("accordionactivate", function() { $('#editorcontainer2fake').hide(); editor2.refresh(); });
|
---|
311 |
|
---|
312 | setupAccordion('#accordion2', '#cameracontainer');
|
---|
313 | setupAccordion('#accordion7', '#histcontainer', true);
|
---|
314 | setupAccordion('#accordion3', '#waveformcontainer');
|
---|
315 | setupAccordion('#accordion4', '#helpcontainer', true);
|
---|
316 | setupAccordion('#accordion6', '#ctrlcontainer', true);
|
---|
317 |
|
---|
318 | $("#selectfile1").on('change', onFile);
|
---|
319 | $("#selectfile2").on('change', onFile);
|
---|
320 |
|
---|
321 | $(document).ajaxStart(function() { disableControls(true) }).ajaxStop(function() { disableControls(false); });
|
---|
322 |
|
---|
323 |
|
---|
324 | $.ajax({
|
---|
325 | type: "POST",
|
---|
326 | cache: false,
|
---|
327 | url: "index.php",
|
---|
328 | success: onFilelistReceived,
|
---|
329 | error: function(xhr) { if (xhr.status==0) alert("ERROR[0] - Request failed!"); else alert("ERROR[0] - "+xhr.statusText+" ["+xhr.status+"]"); }
|
---|
330 | });
|
---|
331 | }
|
---|
332 |
|
---|
333 | function onFileSelect(event, ui)
|
---|
334 | {
|
---|
335 | var list = document.getElementById("file").data;
|
---|
336 | var file = ui.item.value;
|
---|
337 |
|
---|
338 | $('#calibrated').prop('disabled', !list[file]);
|
---|
339 | if (!list[file])
|
---|
340 | $('#calibrated').prop('checked', false);
|
---|
341 |
|
---|
342 | document.getElementById("event").value = 0;
|
---|
343 | onSubmit(ui.item.value);
|
---|
344 | }
|
---|
345 |
|
---|
346 | function onFilelistReceived(result)
|
---|
347 | {
|
---|
348 | //var dbg = document.getElementById("debug");
|
---|
349 |
|
---|
350 | //var pre = document.createElement("pre");
|
---|
351 | //pre.appendChild(document.createTextNode(rc));
|
---|
352 | //dbg.appendChild(pre);
|
---|
353 |
|
---|
354 | var rc;
|
---|
355 | try
|
---|
356 | {
|
---|
357 | rc = JSON.parse(result);
|
---|
358 | }
|
---|
359 | catch (e)
|
---|
360 | {
|
---|
361 | alert("ERROR[0] - Decoding answer:\n"+e);
|
---|
362 | return;
|
---|
363 | }
|
---|
364 |
|
---|
365 | document.getElementById("file").data = rc;
|
---|
366 |
|
---|
367 | var list = [ ];
|
---|
368 | for (var file in rc)
|
---|
369 | list.push(file);
|
---|
370 |
|
---|
371 | var opts =
|
---|
372 | {
|
---|
373 | source: list,
|
---|
374 | select: onFileSelect,
|
---|
375 | position: { my: "right top", at: "right bottom", collision: "flipfit" },
|
---|
376 | };
|
---|
377 |
|
---|
378 | $("#file").autocomplete(opts);
|
---|
379 | document.getElementById("file").value = "2014/04/17-181";
|
---|
380 |
|
---|
381 | onSubmit("2014/04/17-181");
|
---|
382 | }
|
---|
383 |
|
---|
384 | function setZoom(xfrom, xto, yfrom, yto)
|
---|
385 | {
|
---|
386 | var xaxis = plot.getXAxes()[0];
|
---|
387 | var yaxis = plot.getYAxes()[0];
|
---|
388 |
|
---|
389 | if (xfrom!==undefined)
|
---|
390 | xaxis.options.min = xfrom;
|
---|
391 | if (xto!==undefined)
|
---|
392 | xaxis.options.max = xto;
|
---|
393 |
|
---|
394 | if (yfrom!==undefined)
|
---|
395 | yaxis.options.min = yfrom;
|
---|
396 | if (yto!==undefined)
|
---|
397 | yaxis.options.max = yto;
|
---|
398 |
|
---|
399 | plot.setupGrid();
|
---|
400 | plot.draw();
|
---|
401 | plot.clearSelection();
|
---|
402 | }
|
---|
403 |
|
---|
404 | function onPlotHover(event, pos, item)
|
---|
405 | {
|
---|
406 | if (!item)
|
---|
407 | {
|
---|
408 | $("#tooltip").fadeOut(100);
|
---|
409 | return;
|
---|
410 | }
|
---|
411 |
|
---|
412 | var x = item.datapoint[0].toFixed(2);
|
---|
413 | var y = item.datapoint[1].toFixed(2);
|
---|
414 |
|
---|
415 | var tooltip = $("#tooltip");
|
---|
416 | tooltip.html(parseInt(x) + " / " + y);
|
---|
417 | tooltip.css({top: item.pageY-20, left: item.pageX+5});
|
---|
418 | tooltip.fadeIn(200);
|
---|
419 | }
|
---|
420 |
|
---|
421 | function drawHist(n)
|
---|
422 | {
|
---|
423 | var canv = document.getElementById("camera"+n);
|
---|
424 | var hist = document.getElementById("hist"+n);
|
---|
425 |
|
---|
426 | var xmin = parseFloat(document.getElementById("histmin"+n).value);
|
---|
427 | var xmax = parseFloat(document.getElementById("histmax"+n).value);
|
---|
428 | var nbins = 100;//parseInt(xmax-xmin);
|
---|
429 | var step = (xmax-xmin)/nbins;
|
---|
430 | if (step<1)
|
---|
431 | {
|
---|
432 | step = 1;
|
---|
433 | nbins = parseInt(xmax-xmin)+1;
|
---|
434 | }
|
---|
435 |
|
---|
436 | var bins = new Array(nbins);
|
---|
437 | for (var i=0; i<nbins; i++)
|
---|
438 | bins[i] = [ xmin+i*step, 0 ];
|
---|
439 |
|
---|
440 | var data = canv.dataAbs;
|
---|
441 | for (var i=0; i<1440; i++)
|
---|
442 | if (data[i]!==undefined && data[i]!==null)
|
---|
443 | {
|
---|
444 | var ix = parseInt((data[i]-xmin)/step);
|
---|
445 | if (ix>=0 && ix<nbins)
|
---|
446 | bins[ix][1] ++;
|
---|
447 | }
|
---|
448 |
|
---|
449 | var opts =
|
---|
450 | {
|
---|
451 | grid: {
|
---|
452 | hoverable: true,
|
---|
453 | }
|
---|
454 | };
|
---|
455 |
|
---|
456 | var hist = $.plot("#hist"+n, [ { data:bins, bars: {show:true} } ], opts);
|
---|
457 | $('#hist'+n).bind("plothover", onPlotHover);
|
---|
458 | }
|
---|
459 |
|
---|
460 | function processCameraData(n, data)
|
---|
461 | {
|
---|
462 | var canv = document.getElementById("camera"+n);
|
---|
463 |
|
---|
464 | canv.dataAbs = new Array(1440);
|
---|
465 | for (var i=0; i<1440; i++)
|
---|
466 | if (data[i]!==undefined && data[i]!==null)
|
---|
467 | canv.dataAbs[i] = data[i];
|
---|
468 |
|
---|
469 | canv.min = Math.min.apply(Math, canv.dataAbs.filter(function(e){return !isNaN(e)}));
|
---|
470 | canv.max = Math.max.apply(Math, canv.dataAbs.filter(function(e){return !isNaN(e)}));
|
---|
471 |
|
---|
472 | canv.dataRel = new Array(1440);
|
---|
473 | for (var i=0; i<1440; i++)
|
---|
474 | if (data[i]!==undefined && data[i]!==null)
|
---|
475 | canv.dataRel[i] = (data[i]-canv.min)/canv.max;
|
---|
476 |
|
---|
477 | if (document.getElementById("cameraminon"+n).checked)
|
---|
478 | document.getElementById("cameramin"+n).value = canv.min;
|
---|
479 | if (document.getElementById("cameramaxon"+n).checked)
|
---|
480 | document.getElementById("cameramax"+n).value = canv.max;
|
---|
481 |
|
---|
482 | // ---------------------------
|
---|
483 |
|
---|
484 | var hist = document.getElementById("hist"+n);
|
---|
485 |
|
---|
486 | hist.min = canv.min;
|
---|
487 | hist.max = canv.max;
|
---|
488 |
|
---|
489 | if (document.getElementById("histminon"+n).checked)
|
---|
490 | document.getElementById("histmin"+n).value = canv.min;
|
---|
491 | if (document.getElementById("histmaxon"+n).checked)
|
---|
492 | document.getElementById("histmax"+n).value = canv.max;
|
---|
493 |
|
---|
494 | drawHist(n);
|
---|
495 | }
|
---|
496 |
|
---|
497 |
|
---|
498 | function onDataReceived(rc)
|
---|
499 | {
|
---|
500 | var err = document.getElementById("error");
|
---|
501 | var dbg = document.getElementById("debug");
|
---|
502 | var con = document.getElementById("console");
|
---|
503 |
|
---|
504 | //var pre = document.createElement("pre");
|
---|
505 | //pre.appendChild(document.createTextNode(rc));
|
---|
506 | //dbg.appendChild(pre);
|
---|
507 |
|
---|
508 | try
|
---|
509 | {
|
---|
510 | rc = JSON.parse(rc);
|
---|
511 | if (!rc)
|
---|
512 | return;
|
---|
513 | }
|
---|
514 | catch (e)
|
---|
515 | {
|
---|
516 | alert("ERROR[1] - Decoding answer:\n"+e);
|
---|
517 | return;
|
---|
518 | }
|
---|
519 |
|
---|
520 | var evt = rc.event;
|
---|
521 | var file = rc.file;
|
---|
522 |
|
---|
523 | document.getElementById("event").max = file.numEvents;
|
---|
524 | var el = document.getElementById("numevents");
|
---|
525 | if (el.firstChild)
|
---|
526 | el.removeChild(el.firstChild);
|
---|
527 | el.appendChild(document.createTextNode(file.numEvents));
|
---|
528 |
|
---|
529 | var infotxt = "<pre>";
|
---|
530 | infotxt += "\nStart time: "+new Date(file.runStart*24*3600*1000).toUTCString();
|
---|
531 | infotxt += "\nEnd time: "+new Date(file.runEnd*24*3600*1000).toUTCString();
|
---|
532 | infotxt += "\nRun type: "+file.runType;
|
---|
533 | if (file.drsFile>=0)
|
---|
534 | infotxt += " [drs-step "+file.drsFile+"]";
|
---|
535 |
|
---|
536 | $("#runinfo").html(infotxt);
|
---|
537 | $("#eventinfo").html("Trigger: "+evt.trigger.join(' | ')+" [0x"+evt.triggerType.toString(16)+"]");
|
---|
538 |
|
---|
539 | if (rc.ret)
|
---|
540 | {
|
---|
541 | while (con.lastChild)
|
---|
542 | con.removeChild(con.lastChild);
|
---|
543 | }
|
---|
544 |
|
---|
545 | if (rc.err)
|
---|
546 | {
|
---|
547 | while (err.lastChild)
|
---|
548 | err.removeChild(err.lastChild);
|
---|
549 |
|
---|
550 | err.appendChild(document.createTextNode("Javascript runtime exception: "+rc.err.file+":"+rc.err.lineNumber));
|
---|
551 | err.appendChild(document.createTextNode("\n"));
|
---|
552 | err.appendChild(document.createTextNode(rc.err.sourceLine));
|
---|
553 | err.appendChild(document.createTextNode("\n"));
|
---|
554 | err.appendChild(document.createTextNode(rc.err.trace));
|
---|
555 |
|
---|
556 | var editor = rc.err.file=="main" ? editor2 : editor1;
|
---|
557 | editor.setCursor(rc.err.lineNumber-1, 1);
|
---|
558 |
|
---|
559 | $("#accordion").find('h3').filter(':contains(Runtime)').show();
|
---|
560 | $("#accordion").accordion("option", "active", 0);
|
---|
561 | }
|
---|
562 |
|
---|
563 | if (rc.debug!==undefined)
|
---|
564 | {
|
---|
565 | con.appendChild(document.createTextNode(rc.debug));
|
---|
566 |
|
---|
567 | //debug("return "+JSON.stringify(rc.ret));
|
---|
568 | //debug("");
|
---|
569 | debug("PHP execution:");
|
---|
570 | debug("Time Javascripts = "+(rc.timeJs[0]*1000).toFixed(2)+","+(rc.timeJs[1]*1000).toFixed(2)+","+(rc.timeJs[2]*1000).toFixed(2)+ " [ms]");
|
---|
571 | }
|
---|
572 |
|
---|
573 | if (rc.ret!==undefined && Array.isArray(rc.ret))
|
---|
574 | {
|
---|
575 | if (rc.ret[0] instanceof Object)
|
---|
576 | processCameraData(1, rc.ret[0]);
|
---|
577 | else
|
---|
578 | processCameraData(1, rc.ret);
|
---|
579 |
|
---|
580 | if (rc.ret.length>1)
|
---|
581 | processCameraData(2, rc.ret[1]);
|
---|
582 |
|
---|
583 | if (rc.ret.length>2)
|
---|
584 | processCameraData(3, rc.ret[2]);
|
---|
585 |
|
---|
586 | if (rc.ret.length>3)
|
---|
587 | processCameraData(4, rc.ret[3]);
|
---|
588 | }
|
---|
589 |
|
---|
590 | // We have to redraw all of them to display the changed pixel value
|
---|
591 | onCameraMinMax(1);
|
---|
592 | onCameraMinMax(2);
|
---|
593 | onCameraMinMax(3);
|
---|
594 | onCameraMinMax(4);
|
---|
595 |
|
---|
596 | debug("Total time = "+(rc.timePhp*1000).toFixed(1)+" ms");
|
---|
597 | debug("Peak memory = "+rc.memory+" MiB");
|
---|
598 |
|
---|
599 | if (Array.isArray(rc.waveform))
|
---|
600 | {
|
---|
601 | var waveform = document.getElementById("waveform");
|
---|
602 | waveform.data = [ ];
|
---|
603 |
|
---|
604 | var data = [
|
---|
605 | { label: "[0] ", data: new Array(evt.numRoi) },
|
---|
606 | { label: "[1] ", data: new Array(evt.numRoi) },
|
---|
607 | { label: "[2] ", data: new Array(evt.numRoi) },
|
---|
608 | { label: "[3] ", data: new Array(evt.numRoi) },
|
---|
609 | ];
|
---|
610 |
|
---|
611 | var min = [];
|
---|
612 | var max = [];
|
---|
613 | if (Array.isArray(rc.waveform) && rc.waveform.length==evt.numRoi)
|
---|
614 | {
|
---|
615 | min.push(Math.min.apply(Math, rc.waveform));
|
---|
616 | max.push(Math.max.apply(Math, rc.waveform));
|
---|
617 |
|
---|
618 | var d = data[0].data;
|
---|
619 | for (var i=0; i<evt.numRoi; i++)
|
---|
620 | d[i] = [ i, rc.waveform[i] ];
|
---|
621 |
|
---|
622 | waveform.data[0] = rc.waveform;
|
---|
623 | }
|
---|
624 |
|
---|
625 | for (var j=0; j<4; j++)
|
---|
626 | {
|
---|
627 | var ref = rc.waveform[j];
|
---|
628 |
|
---|
629 | if (Array.isArray(ref) && ref.length==evt.numRoi)
|
---|
630 | {
|
---|
631 | min.push(Math.min.apply(Math, ref));
|
---|
632 | max.push(Math.max.apply(Math, ref));
|
---|
633 |
|
---|
634 | var d = data[j].data;
|
---|
635 | for (var i=0; i<evt.numRoi; i++)
|
---|
636 | d[i] = [ i, ref[i] ];
|
---|
637 |
|
---|
638 | waveform.data[j] = ref;
|
---|
639 | }
|
---|
640 | }
|
---|
641 |
|
---|
642 | waveform.ymin = Math.min.apply(Math, min);
|
---|
643 | waveform.ymax = Math.max.apply(Math, max);
|
---|
644 | waveform.xmin = 0;
|
---|
645 | waveform.xmax = evt.numRoi;
|
---|
646 |
|
---|
647 | if (document.getElementById("waveformxminon").checked)
|
---|
648 | document.getElementById("waveformxmin").value = waveform.xmin;
|
---|
649 | if (document.getElementById("waveformxmaxon").checked)
|
---|
650 | document.getElementById("waveformxmax").value = waveform.xmax;
|
---|
651 |
|
---|
652 | if (document.getElementById("waveformminon").checked)
|
---|
653 | document.getElementById("waveformmin").value = waveform.ymin;
|
---|
654 | if (document.getElementById("waveformmaxon").checked)
|
---|
655 | document.getElementById("waveformmax").value = waveform.ymax;
|
---|
656 |
|
---|
657 | var xmin = document.getElementById("waveformxminon").checked ? waveform.xmin : parseInt(document.getElementById("waveformxmin").value);
|
---|
658 | var xmax = document.getElementById("waveformxmaxon").checked ? waveform.xmax : parseInt(document.getElementById("waveformxmax").value);
|
---|
659 |
|
---|
660 | var ymin = document.getElementById("waveformminon").checked ? waveform.ymin : parseInt(document.getElementById("waveformmin").value);
|
---|
661 | var ymax = document.getElementById("waveformmaxon").checked ? waveform.ymax : parseInt(document.getElementById("waveformmax").value);
|
---|
662 |
|
---|
663 | var opts =
|
---|
664 | {
|
---|
665 | xaxis: {
|
---|
666 | min: xmin-1,
|
---|
667 | max: xmax+1,
|
---|
668 | },
|
---|
669 | yaxis: {
|
---|
670 | min: ymin-5,
|
---|
671 | max: ymax+5,
|
---|
672 | },
|
---|
673 | series: {
|
---|
674 | lines: {
|
---|
675 | show: true
|
---|
676 | },
|
---|
677 | points: {
|
---|
678 | show: true,
|
---|
679 | symbol: 'cross',
|
---|
680 | }
|
---|
681 | },
|
---|
682 | selection: {
|
---|
683 | mode: "xy"
|
---|
684 | },
|
---|
685 | grid: {
|
---|
686 | hoverable: true,
|
---|
687 | }
|
---|
688 | };
|
---|
689 |
|
---|
690 | plot = $.plot("#waveform", data, opts);
|
---|
691 |
|
---|
692 | waveform = $('#waveform');
|
---|
693 | waveform.bind("plotselected", function (event, ranges)
|
---|
694 | {
|
---|
695 | setZoom(ranges.xaxis.from, ranges.xaxis.to,
|
---|
696 | ranges.yaxis.from, ranges.yaxis.to);
|
---|
697 | });
|
---|
698 |
|
---|
699 | waveform.dblclick(function ()
|
---|
700 | {
|
---|
701 | var waveform = document.getElementById("waveform");
|
---|
702 | setZoom(waveform.xmin-1, waveform.xmax+1, waveform.ymin-5, waveform.ymax+5);
|
---|
703 | });
|
---|
704 | waveform.bind("plothover", onPlotHover);
|
---|
705 | }
|
---|
706 | }
|
---|
707 |
|
---|
708 | function onSubmit(file, pixelOnly)
|
---|
709 | {
|
---|
710 | if (!file)
|
---|
711 | file = document.getElementById("file").value;
|
---|
712 |
|
---|
713 | var dbg = document.getElementById("debug");
|
---|
714 | while (dbg.lastChild)
|
---|
715 | dbg.removeChild(dbg.lastChild);
|
---|
716 |
|
---|
717 | var active = $("#accordion").accordion("option", "active");
|
---|
718 | if (active==0)
|
---|
719 | {
|
---|
720 | $("#accordion").accordion("option", "active", false);
|
---|
721 | $("#accordion").find('h3').filter(':contains(Runtime)').hide();
|
---|
722 | }
|
---|
723 |
|
---|
724 | var calibrated = document.getElementById("calibrated");
|
---|
725 | var calib = !calibrated.disabled && calibrated.checked;
|
---|
726 | var event = document.getElementById("event").value;
|
---|
727 | var pixel = document.getElementById("pixel").value;
|
---|
728 | var source1 = editor1.getValue();
|
---|
729 | var source2 = editor2.getValue();
|
---|
730 |
|
---|
731 | var uri = "file="+file+"&event="+event+"&pixel="+map[pixel];
|
---|
732 | uri += "&source1="+encodeURIComponent(source1);
|
---|
733 | if (!pixelOnly)
|
---|
734 | uri += "&source2="+encodeURIComponent(source2);
|
---|
735 | if (calib)
|
---|
736 | uri += "&calibrated=1";
|
---|
737 |
|
---|
738 | $.ajax({
|
---|
739 | type: "POST",
|
---|
740 | cache: false,
|
---|
741 | url: "index.php",
|
---|
742 | data: uri,
|
---|
743 | success: onDataReceived,
|
---|
744 | error: function(xhr) { if (xhr.status==0) alert("ERROR[1] - Request failed!"); else alert("ERROR[1] - "+xhr.statusText+" ["+xhr.status+"]"); }
|
---|
745 | });
|
---|
746 | }
|
---|
747 |
|
---|
748 | function onFile(event, ui)
|
---|
749 | {
|
---|
750 | var f = event.target.files[0];
|
---|
751 | if (!f)
|
---|
752 | return;
|
---|
753 |
|
---|
754 | if (!f.type.match('text/plain') && !f.type.match('application/javascript'))
|
---|
755 | {
|
---|
756 | alert("ERROR - Unknown file type.");
|
---|
757 | return;
|
---|
758 | }
|
---|
759 |
|
---|
760 | var id = event.target.id;
|
---|
761 | var editor = id[id.length-1]=='1' ? editor1 : editor2;
|
---|
762 |
|
---|
763 | var reader = new FileReader();
|
---|
764 |
|
---|
765 | // Closure to capture the file information.
|
---|
766 | reader.onload = (function(theFile) { return function(e) { editor.setValue(e.target.result); }; })(f);
|
---|
767 | // onloadstart
|
---|
768 | // onloadend
|
---|
769 | // onprogress
|
---|
770 |
|
---|
771 | // Read in the text file
|
---|
772 | reader.readAsText(f);
|
---|
773 | }
|
---|
774 |
|
---|
775 | function onMarker()
|
---|
776 | {
|
---|
777 | drawFullCam("camera1");
|
---|
778 | drawFullCam("camera2");
|
---|
779 | drawFullCam("camera3");
|
---|
780 | drawFullCam("camera4");
|
---|
781 | }
|
---|
782 |
|
---|
783 | function onEvent()
|
---|
784 | {
|
---|
785 | onSubmit();
|
---|
786 | }
|
---|
787 |
|
---|
788 | function checkPixel()
|
---|
789 | {
|
---|
790 | var pix = parseInt(document.getElementById("pixel").value);
|
---|
791 | var c = parseInt(document.getElementById("cbpx-c").value);
|
---|
792 | var b = parseInt(document.getElementById("cbpx-b").value);
|
---|
793 | var p = parseInt(document.getElementById("cbpx-p").value);
|
---|
794 | var x = parseInt(document.getElementById("cbpx-x").value);
|
---|
795 | var cbpx = parseInt(document.getElementById("cbpx").value);;
|
---|
796 |
|
---|
797 | if (pix >=0 && pix <1440 &&
|
---|
798 | c >=0 && c < 4 &&
|
---|
799 | b >=0 && b < 10 &&
|
---|
800 | p >=0 && p < 4 &&
|
---|
801 | x >=0 && x < 9 &&
|
---|
802 | cbpx>=0 && cbpx<1440)
|
---|
803 | return;
|
---|
804 |
|
---|
805 | document.getElementById("pixel").value = 0;
|
---|
806 | document.getElementById("cbpx-c").value = 1;
|
---|
807 | document.getElementById("cbpx-b").value = 0;
|
---|
808 | document.getElementById("cbpx-p").value = 3;
|
---|
809 | document.getElementById("cbpx-x").value = 6;
|
---|
810 | document.getElementById("cbpx").value = 393;
|
---|
811 | }
|
---|
812 |
|
---|
813 |
|
---|
814 | function onPixel()
|
---|
815 | {
|
---|
816 | checkPixel();
|
---|
817 |
|
---|
818 | var p = parseInt(document.getElementById("pixel").value);
|
---|
819 |
|
---|
820 | var cbpx = map[p];
|
---|
821 |
|
---|
822 | document.getElementById("cbpx-c").value = parseInt((cbpx/360));
|
---|
823 | document.getElementById("cbpx-b").value = parseInt((cbpx/36)%10);
|
---|
824 | document.getElementById("cbpx-p").value = parseInt((cbpx/9)%4);
|
---|
825 | document.getElementById("cbpx-x").value = parseInt((cbpx%9));
|
---|
826 | document.getElementById("cbpx").value = parseInt(cbpx);
|
---|
827 |
|
---|
828 | onSubmit("", true);
|
---|
829 | }
|
---|
830 |
|
---|
831 | function onCBPX()
|
---|
832 | {
|
---|
833 | checkPixel();
|
---|
834 |
|
---|
835 | var c = parseInt(document.getElementById("cbpx-c").value);
|
---|
836 | var b = parseInt(document.getElementById("cbpx-b").value);
|
---|
837 | var p = parseInt(document.getElementById("cbpx-p").value);
|
---|
838 | var x = parseInt(document.getElementById("cbpx-x").value);
|
---|
839 |
|
---|
840 | var cbpx = c*360 + b*36 + p*9 + x;
|
---|
841 |
|
---|
842 | document.getElementById("cbpx").value = parseInt(cbpx);
|
---|
843 | document.getElementById("pixel").value = map.indexOf(cbpx);
|
---|
844 |
|
---|
845 | onSubmit("", true);
|
---|
846 | }
|
---|
847 |
|
---|
848 | function onHW()
|
---|
849 | {
|
---|
850 | checkPixel();
|
---|
851 |
|
---|
852 | var cbpx = parseInt(document.getElementById("cbpx").value);;
|
---|
853 |
|
---|
854 | document.getElementById("cbpx-c").value = parseInt((cbpx/360));
|
---|
855 | document.getElementById("cbpx-b").value = parseInt((cbpx/36)%10);
|
---|
856 | document.getElementById("cbpx-p").value = parseInt((cbpx/9)%4);
|
---|
857 | document.getElementById("cbpx-x").value = parseInt((cbpx%9));
|
---|
858 |
|
---|
859 | document.getElementById("pixel").value = map.indexOf(cbpx);
|
---|
860 |
|
---|
861 | onSubmit("", true);
|
---|
862 | }
|
---|
863 |
|
---|
864 | function isInside(x, y, mouse)
|
---|
865 | {
|
---|
866 | var dist = Math.sqrt((mouse.x-x)*(mouse.x-x)+(mouse.y-y)*(mouse.y-y));
|
---|
867 | return dist<0.5;
|
---|
868 |
|
---|
869 | /*
|
---|
870 | ctx.translate(x, y);
|
---|
871 | ctx.scale(1/2, 1/3);
|
---|
872 |
|
---|
873 | ctx.beginPath();
|
---|
874 | ctx.moveTo( 1, 1);
|
---|
875 | ctx.lineTo( 0, 2);
|
---|
876 | ctx.lineTo(-1, 1);
|
---|
877 | ctx.lineTo(-1, -1);
|
---|
878 | ctx.lineTo( 0, -2);
|
---|
879 | ctx.lineTo( 1, -1);
|
---|
880 | ctx.fill();
|
---|
881 |
|
---|
882 | ctx.restore();
|
---|
883 | */
|
---|
884 | }
|
---|
885 |
|
---|
886 | var inprogress = { };
|
---|
887 | function moveElement(id, n, target, callback)
|
---|
888 | {
|
---|
889 | if (inprogress[id]==n || inprogress[id]<0)
|
---|
890 | return;
|
---|
891 |
|
---|
892 | inprogress[id] = target ? -n : n;
|
---|
893 |
|
---|
894 | var element = $("#"+id+n); //Allow passing in either a JQuery object or selector
|
---|
895 | var newParent = $(target ? target : "#cont"+id+n); //Allow passing in either a JQuery object or selector
|
---|
896 |
|
---|
897 | var oldOffset = element.offset();
|
---|
898 |
|
---|
899 | var newOffset = newParent.offset();
|
---|
900 |
|
---|
901 | var w = newParent.width();
|
---|
902 | var h = newParent.height();
|
---|
903 |
|
---|
904 | var temp = element.appendTo('body');
|
---|
905 | temp.css('position', 'absolute')
|
---|
906 | .css('left', oldOffset.left)
|
---|
907 | .css('top', oldOffset.top)
|
---|
908 | .css('zIndex', 999);
|
---|
909 |
|
---|
910 | temp.animate( {'top': newOffset.top, 'left':newOffset.left, 'width':w, 'height': h},
|
---|
911 | 'slow', function()
|
---|
912 | {
|
---|
913 | temp = temp.appendTo(newParent);
|
---|
914 | temp.css('position', 'relative');
|
---|
915 | temp.css('width', '');
|
---|
916 | temp.css('height', '');
|
---|
917 | temp.css('zIndex', '');
|
---|
918 | temp.css('left', '0');
|
---|
919 | temp.css('top', '0');
|
---|
920 |
|
---|
921 | setSize(id+n, w, h);
|
---|
922 |
|
---|
923 | if (callback)
|
---|
924 | callback(id+n);
|
---|
925 |
|
---|
926 | inprogress[id] = 0;
|
---|
927 | });
|
---|
928 | }
|
---|
929 |
|
---|
930 | function onClickCont(event, callback)
|
---|
931 | {
|
---|
932 | var id = event.target.id;
|
---|
933 | if (!id)
|
---|
934 | id = event.target.parentNode.id;
|
---|
935 |
|
---|
936 | var n = parseInt(id[id.length-1]);
|
---|
937 | var type = id.substr(0, id.length-1);
|
---|
938 |
|
---|
939 | if (id.substr(0, 4)=="cont")
|
---|
940 | id = id.substr(4, id.length-4);
|
---|
941 | if (type.substr(0, 4)=="cont")
|
---|
942 | type = type.substr(4, type.length-4);
|
---|
943 |
|
---|
944 | if (id.substr(0, type.length)==type)
|
---|
945 | {
|
---|
946 | var cont = document.getElementById("center"+type).childNodes[0];
|
---|
947 | if (cont)
|
---|
948 | {
|
---|
949 | var nn = parseInt(cont.id[cont.id.length-1]);
|
---|
950 | moveElement(type, nn, null, callback);
|
---|
951 | }
|
---|
952 | moveElement(type, n, "#center"+type, callback);
|
---|
953 |
|
---|
954 | }
|
---|
955 | else
|
---|
956 | moveElement(type, n, null, callback);
|
---|
957 |
|
---|
958 | }
|
---|
959 |
|
---|
960 | function onClickContCamera(event)
|
---|
961 | {
|
---|
962 | onClickCont(event, function(el) { drawFullCam(el); });
|
---|
963 | }
|
---|
964 |
|
---|
965 | function onClickContHist(event)
|
---|
966 | {
|
---|
967 | onClickCont(event);
|
---|
968 | }
|
---|
969 |
|
---|
970 | function onClick(event)
|
---|
971 | {
|
---|
972 | var cont = document.getElementById("centercamera").childNodes[0];
|
---|
973 | if (!cont)
|
---|
974 | return;
|
---|
975 |
|
---|
976 | if (cont.id!=event.target.id)
|
---|
977 | return;
|
---|
978 |
|
---|
979 | // get click position relative to canvas
|
---|
980 | var rect = event.target.getBoundingClientRect();
|
---|
981 |
|
---|
982 | var x = event.clientX - rect.left;
|
---|
983 | var y = event.clientY - rect.top;
|
---|
984 |
|
---|
985 | var mouse = { x: x, y: y };
|
---|
986 |
|
---|
987 | // convert click position to pixel index
|
---|
988 | var index = getIndex(event.target.id, mouse);
|
---|
989 | if (index<0)
|
---|
990 | return;
|
---|
991 |
|
---|
992 | document.getElementById("pixel").value = index;
|
---|
993 |
|
---|
994 | onPixel();
|
---|
995 | }
|
---|
996 |
|
---|
997 | function getClickPosition(event)
|
---|
998 | {
|
---|
999 | var rect = event.target.getBoundingClientRect();
|
---|
1000 |
|
---|
1001 | var x = event.clientX - rect.left;
|
---|
1002 | var y = event.clientY - rect.top;
|
---|
1003 |
|
---|
1004 | return { x: x, y: y };
|
---|
1005 | }
|
---|
1006 |
|
---|
1007 | function onMinMax(id, n)
|
---|
1008 | {
|
---|
1009 | var el = document.getElementById(id+n);
|
---|
1010 |
|
---|
1011 | el.zmin = document.getElementById(id+"min"+n).value;
|
---|
1012 | el.zmax = document.getElementById(id+"max"+n).value;
|
---|
1013 | }
|
---|
1014 |
|
---|
1015 | function onCameraMinMax(n)
|
---|
1016 | {
|
---|
1017 | onMinMax("camera", n);
|
---|
1018 | drawFullCam("camera"+n);
|
---|
1019 | }
|
---|
1020 |
|
---|
1021 | function onHistMinMax(n)
|
---|
1022 | {
|
---|
1023 | onMinMax("hist", n);
|
---|
1024 | drawHist(n);
|
---|
1025 | }
|
---|
1026 |
|
---|
1027 | function onMinMaxOn(id, n)
|
---|
1028 | {
|
---|
1029 | var el = document.getElementById(id+n);
|
---|
1030 |
|
---|
1031 | var redraw;
|
---|
1032 | if (document.getElementById(id+"minon"+n).checked)
|
---|
1033 | {
|
---|
1034 | document.getElementById(id+"min"+n).setAttribute("disabled", "true");
|
---|
1035 | document.getElementById(id+"min"+n).value = el.min;
|
---|
1036 | redraw = true;
|
---|
1037 | }
|
---|
1038 | else
|
---|
1039 | document.getElementById(id+"min"+n).removeAttribute("disabled");
|
---|
1040 |
|
---|
1041 | if (document.getElementById(id+"maxon"+n).checked)
|
---|
1042 | {
|
---|
1043 | document.getElementById(id+"max"+n).setAttribute("disabled", "true");
|
---|
1044 | document.getElementById(id+"max"+n).value = el.max;
|
---|
1045 | redraw = true;
|
---|
1046 | }
|
---|
1047 | else
|
---|
1048 | document.getElementById(id+"max"+n).removeAttribute("disabled");
|
---|
1049 |
|
---|
1050 | return redraw;
|
---|
1051 | }
|
---|
1052 |
|
---|
1053 | function onCameraMinMaxOn(n)
|
---|
1054 | {
|
---|
1055 | if (onMinMaxOn("camera", n))
|
---|
1056 | onCameraMinMax(n);
|
---|
1057 | }
|
---|
1058 |
|
---|
1059 | function onHistMinMaxOn(n)
|
---|
1060 | {
|
---|
1061 | if (onMinMaxOn("hist", n))
|
---|
1062 | onHistMinMax(n);
|
---|
1063 | }
|
---|
1064 |
|
---|
1065 | function onWaveformMinMax()
|
---|
1066 | {
|
---|
1067 | var wf = document.getElementById("waveform");
|
---|
1068 |
|
---|
1069 | var xmin, xmax, ymin, ymax;
|
---|
1070 |
|
---|
1071 | var redraw;
|
---|
1072 | if (!document.getElementById("waveformxminon").checked)
|
---|
1073 | xmin = document.getElementById("waveformxmin").value;
|
---|
1074 | if (!document.getElementById("waveformxmaxon").checked)
|
---|
1075 | xmax = document.getElementById("waveformxmax").value;
|
---|
1076 | if (!document.getElementById("waveformminon").checked)
|
---|
1077 | ymin = document.getElementById("waveformmin").value;
|
---|
1078 | if (!document.getElementById("waveformmaxon").checked)
|
---|
1079 | ymax = document.getElementById("waveformmax").value;
|
---|
1080 |
|
---|
1081 | setZoom(xmin, xmax, ymin, ymax);
|
---|
1082 |
|
---|
1083 | }
|
---|
1084 |
|
---|
1085 | function onWaveformMinMaxOn()
|
---|
1086 | {
|
---|
1087 | var wf = document.getElementById("waveform");
|
---|
1088 |
|
---|
1089 | var xmin, xmax, ymin, ymax;
|
---|
1090 |
|
---|
1091 | var redraw;
|
---|
1092 | if (document.getElementById("waveformxminon").checked)
|
---|
1093 | {
|
---|
1094 | document.getElementById("waveformxmin").setAttribute("disabled", "true");
|
---|
1095 | document.getElementById("waveformxmin").value = wf.xmin;
|
---|
1096 | xmin = wf.xmin-1;
|
---|
1097 | }
|
---|
1098 | else
|
---|
1099 | document.getElementById("waveformxmin").removeAttribute("disabled");
|
---|
1100 |
|
---|
1101 | if (document.getElementById("waveformxmaxon").checked)
|
---|
1102 | {
|
---|
1103 | document.getElementById("waveformxmax").setAttribute("disabled", "true");
|
---|
1104 | document.getElementById("waveformxmax").value = wf.xmax;
|
---|
1105 | xmax = wf.xmax+1;
|
---|
1106 | }
|
---|
1107 | else
|
---|
1108 | document.getElementById("waveformxmax").removeAttribute("disabled");
|
---|
1109 |
|
---|
1110 | if (document.getElementById("waveformminon").checked)
|
---|
1111 | {
|
---|
1112 | document.getElementById("waveformmin").setAttribute("disabled", "true");
|
---|
1113 | document.getElementById("waveformmin").value = wf.ymin;
|
---|
1114 | ymin = wf.ymin-5;
|
---|
1115 | }
|
---|
1116 | else
|
---|
1117 | document.getElementById("waveformmin").removeAttribute("disabled");
|
---|
1118 |
|
---|
1119 | if (document.getElementById("waveformmaxon").checked)
|
---|
1120 | {
|
---|
1121 | document.getElementById("waveformmax").setAttribute("disabled", "true");
|
---|
1122 | document.getElementById("waveformmax").value = wf.ymax;
|
---|
1123 | ymax = wf.ymax+5;
|
---|
1124 | }
|
---|
1125 | else
|
---|
1126 | document.getElementById("waveformmax").removeAttribute("disabled");
|
---|
1127 |
|
---|
1128 | setZoom(xmin, xmax, ymin, ymax);
|
---|
1129 | }
|
---|
1130 |
|
---|
1131 | //document.addEventListener("click", getClickPosition, false);
|
---|
1132 |
|
---|
1133 | $(document).ready(onReady);
|
---|
1134 |
|
---|
1135 | // ================================== Pixel mapping =================================================
|
---|
1136 |
|
---|
1137 | var map = new Array(1440);
|
---|
1138 |
|
---|
1139 | function initPixelMap()
|
---|
1140 | {
|
---|
1141 | var codedMap = "966676:6:A;68656364626Y?\\?;A=A<AGADAN4K4i5g5h5o506W?Z?]?_?>A@A?AJAIAFACAM4J4H4f5d5e5l5m5n516X?[?^?N?P?AA1ABAVAUAKAHAEAO4L4I4G4E4c5a5b5M6j5k5V6Y6\\6_6G?J?O?Q?S?2A4A3AYAXAWAbA_AnAkAhA3404F4D4B4`5^5_5J6K6L6S6T6W6Z6]6E?H?K?M?R?T?V?5A7A6A\\A[AZAeAdAaA^AmAjAgA24o3m3C4A4?4]5[5\\5G6H6I6P6Q6R6U6X6[6^6F?I?L?<?>?U?;@=@8Ah@9AMALA]ABCACfAcA`AoAlAiA4414n3l3<4@4>425Z5X5Y5D6E6F698N6O608E8H8K8H>K>N>?>B>=???A?<@>@@@i@k@j@PAOANAECDCCC<C9CZCWCTC=3:3734313=4;4943515o4W5U5V5A6B6C6687888m7n7C8F8I8F>I>L>=>@>C>E>@?B?D??@A@C@l@n@m@SARAQAHCGCFC?C>C;C8CYCVCSC<393633303n2:4846405n4l4T5R5S5>6?6@6384858j7k7l7o7D8G8J8G>J>M>>>A>D>4>6>C?3?5?B@2@4@o@_@0ALBKBTA0CoBIC8D7D@C=C:C[CXCUC>3;3835323o2m2k27454j3m4k4i4Q5O5P5C7<6=6g71828o8h7i7S9<8?8B8Q>T>W>@=C=F=e<h<5>7>9>4?6?8?3@5@7@`@b@a@OBNBMB3C2C1C;D:D9D_D\\DQCNCKCF3C3@3>2;282Z1W1l2j2h2k3i3g3j4h4f4N5L5M5@7A7B7d7e7f7l8m8n8P9Q9:8=8@8O>R>U>>=A=D=c<f<i<k<8>:><>7?9?;?6@8@:@c@e@d@RBQBPB6C5C4C>D=D<DbDaD^D[DPCMCJCE3B3?3=2:272Y1V1T1i2g2e2h3f3d3g4e4c4K5I5J5=7>7?7a7b7c7i8j8k8M9N9O9R9;8>8A8P>S>V>?=B=E=d<g<j<Z<\\<;>k=m=:?j>l>9@i?k?f@V@g@CBBBSBgBfB7CoCnC?DSDRDcD`D]DRCOCLCG3D3A3?2<292[1X1U1S1Q1f2d2b2e3c3a3d4b4`4H5F5G5:7;7<7^7_7`7f8g8h8J9K9L97:::=:@:C:F:I:I=L=O=7=:===n<1=[<]<_<l=n=0>k>m>o>j?l?n?W@Y@X@FBEBDBjBiBhB2D1D0DVDUDTDCE@EOELEIEXEUERE5222o1l1i1f1c1`1R1P1N1c2a2_2b3`3^3a4_4]4<5:5;5778797[7\\7]7c8d8e8G9H9I94:5:8:;:>:A:D:G:G=J=M=5=8=;=l<o<2=4=^<`<b<o=1>3>n>0?2?m?o?1@Z@\\@[@IBHBGBmBlBkB5D4D3DYDXDWDFEEEBE?ENEKEHEWETEQE4212n1k1h1e1b1_1]1O1M1K1`2^2\\2_3]3[3^4\\4Z4957585475767X7Y7Z7`8a8b8D9E9F91:2:3:6:9:<:?:B:E:H:H=K=N=6=9=<=m<0=3=d;f;a<H<J<2>b=d=1?a>c>0@`?b?]@D@^@:B9BJB^B]BnBfCeC6DJDIDZDnDmDGEDEAEPEMEJEYEVESE623202m1j1g1d1a1^1\\1[0L1J1?1]2[2Y2\\3Z3X3[4Y4W4654555172737U7V7W7]8^8_8A9B9C9e9o90:n9g:j:m:L:O:R:U:X:[:];`;c;T;W;Z;7<9<e;g;i;I<K<M<c=e=g=b>d>f>a?c?e?E@G@F@=B<B;BaB`B_BiChCgCMDLDKD1E0EoD9E7E<F9F6FaE^E[EjEgEdER0O0L0I0F0C0n0l0\\0Z0X0@1>1<1Z2X2V2Y3W3U3X4V4T4E5C5D5n6o607R7S7T7Z8[8\\8>9?9@9b9c9d9l9m9e:h:k:J:M:P:S:V:Y:[;^;a;R;U;X;6<8<:<;<h;j;l;L<N<P<f=h=j=e>g>i>d?f?h?N@Q@H@@B?B>BdBcBbBlCkCjCPDODND4E3E2E;E:E8E6E;F8F5F`E]EZEiEfEcEQ0N0K0H0E0B0m0k0j0Y0W0U0=1;191W2U2S2V3T3R3U4S4Q4B5@5A5k6l6m6O7P7Q7W8X8Y8;9<9=9_9`9a9j9k9\\:_:f:i:l:K:N:Q:T:W:Z:\\;_;b;S;V;Y;C<E<G<<<m;k;1<2<O<Q<S<i=[=P=h>X>Z>g?M@O@R@U@S@J@I@AB1B0BeBTB\\CmCAD@DQDiDhD5EdD<E4F2F0F=F:F7FbE_E\\EkEhEeES0P0M0J0G0D011o0h0g0e0V0T0`0:181Q2T2R2H2S3Q3P3R4P4K3?5=5>5c6i6j6h6M7N7L7U8V8T899:9W9]9^9\\9g9h9i9]:`:c:5;2;o:>;;;8;P;M;J;G;D;A;?<A<D<F<=<><n;o;3<5<R<T<Y=Z=Q=R=Y>[>\\>^>P@T@L@K@5B4B3B2BVBUB^C]CCDBDkDjDfDeD>E=E3F1FnElE@FCFFFIFLFOF;0>0A0205080513101i0f0d0c0b0_0I1H1D1P2O2G2F2D2O3N3M3J3H3a6b6e6f6g6I7J7K7R8S8397989V9Y9Z9[9f9^:a:d:4;1;n:=;:;7;O;L;I;F;C;@;@<B<0<4<U<V<X<`=]=\\=S=U=W=]>_>`>8B7B6BZBXBWB_CaC`CFDEDDDlDgDoEmE>FAFDFGFJFMF90<0?0003060714121a0^0]0G1C1B1N2L2E2C2B2@2L3I3`6d6E7F7G7H7O8Q8192969T9U9X96;3;0;?;<;9;Q;N;K;H;E;B;W<Y<^=_=a=T=V=X=\\B[BYBdCcCbCHDGD?FBFEFHFKFNF:0=0@0104070F1E1A1M2K2J2I2A2D7L8M8N8P809495961b:";
|
---|
1142 | // first: decode the pixel mapping!
|
---|
1143 | var sum = 1036080;
|
---|
1144 | for (var i=0; i<1440; i++)
|
---|
1145 | {
|
---|
1146 | var d0 = codedMap.charCodeAt(i*2) -48;
|
---|
1147 | var d1 = codedMap.charCodeAt(i*2+1)-48;
|
---|
1148 |
|
---|
1149 | map[i] = d0 | (d1<<6);
|
---|
1150 | sum -= map[i];
|
---|
1151 | }
|
---|
1152 | if (sum!=0)
|
---|
1153 | alert("Pixel mapping table corrupted!");
|
---|
1154 | }
|
---|
1155 |
|
---|
1156 | initPixelMap();
|
---|
1157 |
|
---|
1158 | // ================================== Camera Display ================================================
|
---|
1159 |
|
---|
1160 | var coord = new Array(1440);
|
---|
1161 | function initCameraCoordinates()
|
---|
1162 | {
|
---|
1163 | coord[0] = [0, 0];
|
---|
1164 | var cnt = 1;
|
---|
1165 | for (var ring=1; ring<24; ring++)
|
---|
1166 | {
|
---|
1167 | for (var s=0; s<6; s++)
|
---|
1168 | {
|
---|
1169 | for (var i=1; i<=ring; i++)
|
---|
1170 | {
|
---|
1171 | var pos = new Position(s, ring, i);
|
---|
1172 | if (pos.d() - pos.x > 395.75)
|
---|
1173 | continue;
|
---|
1174 |
|
---|
1175 | coord[cnt++] = [ pos.x, pos.y];
|
---|
1176 | }
|
---|
1177 | }
|
---|
1178 | }
|
---|
1179 |
|
---|
1180 | coord[1438] = [7, -22];
|
---|
1181 | coord[1439] = [7, 22];
|
---|
1182 | }
|
---|
1183 |
|
---|
1184 | initCameraCoordinates();
|
---|
1185 |
|
---|
1186 | function getIndex(id, mouse)
|
---|
1187 | {
|
---|
1188 | var canv = document.getElementById(id);
|
---|
1189 |
|
---|
1190 | var scale = 83;
|
---|
1191 |
|
---|
1192 | var w = Math.min(canv.width/scale, canv.height/scale);
|
---|
1193 |
|
---|
1194 | //ctx.translate(canv.width/2, canv.height/2);
|
---|
1195 | //ctx.scale(w*2, w*2);
|
---|
1196 | //ctx.scale(1, Math.sqrt(3)/2);
|
---|
1197 | //ctx.translate(-0.5, 0);
|
---|
1198 |
|
---|
1199 | mouse.x -= canv.width/2;
|
---|
1200 | mouse.y -= canv.height/2;
|
---|
1201 | mouse.x /= w*2;
|
---|
1202 | mouse.y /= w*2;
|
---|
1203 | mouse.y /= Math.sqrt(3)/2;
|
---|
1204 | mouse.x -= -0.5;
|
---|
1205 |
|
---|
1206 | for (var i=0; i<1440; i++)
|
---|
1207 | if (isInside(coord[i][0], coord[i][1], mouse))
|
---|
1208 | return i;
|
---|
1209 |
|
---|
1210 | return -1;
|
---|
1211 | }
|
---|
1212 |
|
---|
1213 |
|
---|
1214 | function hueToRGB(hue)
|
---|
1215 | {
|
---|
1216 | hue /= 3;
|
---|
1217 | hue %= 6;
|
---|
1218 |
|
---|
1219 | if (hue<1) return parseInt(255*hue, 10);
|
---|
1220 | if (hue<3) return parseInt(255, 10);
|
---|
1221 | if (hue<4) return parseInt(255*(4-hue), 10);
|
---|
1222 |
|
---|
1223 | return 0.
|
---|
1224 | }
|
---|
1225 |
|
---|
1226 | function hueToHex(flt)
|
---|
1227 | {
|
---|
1228 | var s = hueToRGB(flt).toString(16);
|
---|
1229 | return s.length==2 ? s : "0"+s;
|
---|
1230 | }
|
---|
1231 |
|
---|
1232 | function HLStoRGB(hue)
|
---|
1233 | {
|
---|
1234 | if (isNaN(hue))
|
---|
1235 | return "fff";
|
---|
1236 |
|
---|
1237 | if (hue<0)
|
---|
1238 | return "eef"; // 555
|
---|
1239 |
|
---|
1240 | if (hue>1)
|
---|
1241 | return "700"; // 666
|
---|
1242 |
|
---|
1243 | hue *= 14;
|
---|
1244 |
|
---|
1245 | var sr = hueToHex(20-hue);
|
---|
1246 | var sg = hueToHex(14-hue);
|
---|
1247 | var sb = hueToHex(26-hue);
|
---|
1248 |
|
---|
1249 | return sr+sg+sb;
|
---|
1250 | }
|
---|
1251 |
|
---|
1252 | function outlineHex(ctx)
|
---|
1253 | {
|
---|
1254 | ctx.scale(1/2, 1/3);
|
---|
1255 |
|
---|
1256 | ctx.beginPath();
|
---|
1257 | ctx.moveTo( 1, 1);
|
---|
1258 | ctx.lineTo( 0, 2);
|
---|
1259 | ctx.lineTo(-1, 1);
|
---|
1260 | ctx.lineTo(-1, -1);
|
---|
1261 | ctx.lineTo( 0, -2);
|
---|
1262 | ctx.lineTo( 1, -1);
|
---|
1263 | ctx.lineTo( 1, 1);
|
---|
1264 | }
|
---|
1265 |
|
---|
1266 | function drawHex(ctx, x, y, col, min, max)
|
---|
1267 | {
|
---|
1268 | if (col===undefined || col===null || max<min)
|
---|
1269 | return;
|
---|
1270 |
|
---|
1271 | var lvl = (col-min)/(max-min);
|
---|
1272 |
|
---|
1273 | ctx.fillStyle = "#"+HLStoRGB(lvl);
|
---|
1274 |
|
---|
1275 | ctx.save();
|
---|
1276 | ctx.translate(x, y);
|
---|
1277 | outlineHex(ctx);
|
---|
1278 | ctx.fill();
|
---|
1279 | ctx.restore();
|
---|
1280 | }
|
---|
1281 |
|
---|
1282 | function Position(s, ring, i)
|
---|
1283 | {
|
---|
1284 | switch (s)
|
---|
1285 | {
|
---|
1286 | case 1: this.x = ring - i*0.5; this.y = + i; break;
|
---|
1287 | case 2: this.x = ring*0.5 - i; this.y = ring ; break;
|
---|
1288 | case 3: this.x = -ring*0.5 - i*0.5; this.y = ring - i; break;
|
---|
1289 | case 4: this.x = -ring + i*0.5; this.y = - i; break;
|
---|
1290 | case 5: this.x = -ring*0.5 + i; this.y = -ring ; break;
|
---|
1291 | case 0: this.x = ring*0.5 + i*0.5; this.y = -ring + i; break;
|
---|
1292 | }
|
---|
1293 | this.d = (function () { return this.x*this.x + this.y*this.y*3/4; });
|
---|
1294 | }
|
---|
1295 |
|
---|
1296 | function drawFullCam(id)
|
---|
1297 | {
|
---|
1298 | var canv = document.getElementById(id);
|
---|
1299 | if (!canv)
|
---|
1300 | return;
|
---|
1301 |
|
---|
1302 | var ctx = canv.getContext("2d");
|
---|
1303 |
|
---|
1304 | ctx.clearRect(0, 0, canv.width, canv.height);
|
---|
1305 |
|
---|
1306 | // ======================= Draw Graphics ======================
|
---|
1307 |
|
---|
1308 | var data = canv.dataRel;
|
---|
1309 | if (!data)
|
---|
1310 | return;
|
---|
1311 |
|
---|
1312 | var pixel = document.getElementById('pixel').value;
|
---|
1313 |
|
---|
1314 | var min = (canv.zmin-canv.min)/canv.max;
|
---|
1315 | var max = (canv.zmax-canv.min)/canv.max;
|
---|
1316 |
|
---|
1317 | var scale = 83;
|
---|
1318 |
|
---|
1319 | var w = Math.min(canv.width/scale, canv.height/scale);
|
---|
1320 |
|
---|
1321 | ctx.save();
|
---|
1322 | ctx.translate(canv.width/2, canv.height/2);
|
---|
1323 | ctx.scale(w*2, w*2);
|
---|
1324 | // ctx.rotate(Math.PI/3);
|
---|
1325 |
|
---|
1326 | ctx.scale(1, Math.sqrt(3)/2);
|
---|
1327 | ctx.translate(-0.5, 0);
|
---|
1328 |
|
---|
1329 | for (var i=0; i<1440; i++)
|
---|
1330 | drawHex(ctx, coord[i][0], coord[i][1], data[map[i]], min, max);
|
---|
1331 |
|
---|
1332 | if (document.getElementById('marker').checked)
|
---|
1333 | {
|
---|
1334 | // Draw marker
|
---|
1335 | ctx.save();
|
---|
1336 |
|
---|
1337 | ctx.lineWidth = 0.25;
|
---|
1338 | ctx.fillStyle = "#000";
|
---|
1339 |
|
---|
1340 | ctx.translate(coord[pixel][0], coord[pixel][1]);
|
---|
1341 | outlineHex(ctx);
|
---|
1342 | ctx.stroke();
|
---|
1343 |
|
---|
1344 | ctx.restore();
|
---|
1345 | }
|
---|
1346 |
|
---|
1347 | ctx.restore();
|
---|
1348 |
|
---|
1349 | // ======================= Draw Legend ======================
|
---|
1350 |
|
---|
1351 | var pval = parseFloat(canv.dataAbs[map[pixel]]).toFixed(1);
|
---|
1352 | var lmin = parseFloat(canv.min).toFixed(1);
|
---|
1353 | var lmax = parseFloat(canv.max).toFixed(1);
|
---|
1354 |
|
---|
1355 | var v0 = parseFloat(canv.zmin);
|
---|
1356 | var v1 = parseFloat(canv.zmax);
|
---|
1357 |
|
---|
1358 | var diff = v1-v0;
|
---|
1359 |
|
---|
1360 | var cw = canv.width;
|
---|
1361 | //var ch = canv.height;
|
---|
1362 |
|
---|
1363 | ctx.font = "8pt Arial";
|
---|
1364 | ctx.textAlign = "right";
|
---|
1365 | ctx.textBaseline = "top";
|
---|
1366 |
|
---|
1367 | for (var i=0; i<11; i++)
|
---|
1368 | {
|
---|
1369 | ctx.strokeStyle = "#"+HLStoRGB(i/10);
|
---|
1370 | ctx.strokeText((v0+diff*i/10).toPrecision(3), cw-5, 125-i*12);
|
---|
1371 | }
|
---|
1372 |
|
---|
1373 | var mw = Math.max(ctx.measureText(lmin).width,
|
---|
1374 | ctx.measureText(pval).width,
|
---|
1375 | ctx.measureText(lmax).width);
|
---|
1376 |
|
---|
1377 | ctx.textBaseline = "top";
|
---|
1378 | ctx.strokeStyle = "#000";
|
---|
1379 |
|
---|
1380 | ctx.strokeText(lmax, 5+mw, 5+24);
|
---|
1381 | ctx.strokeText(pval, 5+mw, 5+12);
|
---|
1382 | ctx.strokeText(lmin, 5+mw, 5);
|
---|
1383 | }
|
---|