source: branches/FACT++_lidctrl_usb/www/viewer/index.js

Last change on this file was 17942, checked in by tbretz, 10 years ago
Fixed a bug which caused clicking on an entry in the autocomplete list to fail.
File size: 44.3 KB
Line 
1'use strict';
2
3// ==========================================================================
4
5function 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
38var editor1;
39var editor2;
40var plot;
41
42function debug(txt)
43{
44 var dbg = document.getElementById("debug");
45 dbg.appendChild(document.createTextNode(txt));
46 dbg.appendChild(document.createElement("br"));
47}
48
49function 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
73function 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
86function 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
98function 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
131function onResizeCameras(event, ui)
132{
133 onResizeGrid('camera');
134
135 drawFullCam("camera1");
136 drawFullCam("camera2");
137 drawFullCam("camera3");
138 drawFullCam("camera4");
139}
140
141function onResizeHistograms(event, ui)
142{
143 onResizeGrid('hist');
144}
145
146function 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", "fact");
190
191 return editor;
192}
193
194function 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
206function setFileChecks(file)
207{
208 var list = document.getElementById("file").data;
209 if (!list)
210 return;
211
212 if (!file)
213 file = document.getElementById("file").value;
214
215 var drs = document.getElementById("drsfile");
216
217 var hasDrs = list[file]&2;
218 var hasCal = list[file]&4;
219 var isMC = list[file]&8;
220
221 if (!hasDrs || isMC)
222 $('#drsfile').prop('checked', false);
223 if (!hasCal || isMC)
224 $('#calibrated').prop('checked', false);
225
226 $('#calibrated').prop('disabled', (!hasCal && !drs.checked) || isMC);
227 $('#drsfile').prop('disabled', !hasDrs || isMC);
228
229 $('#txtcalibrated').css('color', (!hasCal && !drs.checked) || isMC ? 'darkgrey' : 'black');
230 $('#txtdrsfile').css( 'color', !hasDrs || isMC ? 'darkgrey' : 'black');
231 $('#txtmontecarlo').css('color', !isMC ? 'darkgrey' : 'black');
232
233 $('#montecarlo').prop('checked', isMC);
234}
235
236function disableControls(disabled)
237{
238 $('#submit').prop('disabled', disabled);
239 $('#getcamera').prop('disabled', disabled);
240 $('#getwaveforms').prop('disabled', disabled);
241 $('#event').prop('disabled', disabled);
242 $('#pixel').prop('disabled', disabled);
243 $('#cbpx').prop('disabled', disabled);
244 $('#cbpx-c').prop('disabled', disabled);
245 $('#cbpx-b').prop('disabled', disabled);
246 $('#cbpx-p').prop('disabled', disabled);
247 $('#cbpx-x').prop('disabled', disabled);
248 $('#file').prop('disabled', disabled);
249
250 if (disabled)
251 {
252 $('#calibrated').prop('disabled', true);
253 $('#drsfile').prop('disabled', true);
254 $('#montecarlo').prop('disabled', true);
255 }
256 else
257 setFileChecks();
258}
259
260function onGetCameras()
261{
262 var arr =
263 [
264 document.getElementById("camera1").dataAbs,
265 document.getElementById("camera2").dataAbs,
266 document.getElementById("camera3").dataAbs,
267 document.getElementById("camera4").dataAbs,
268 ];
269
270 $('#controls > input[name=data]').val(JSON.stringify(arr));
271 $('#controls > input[name=name]').val('cameras.txt');
272 $('#controls').attr('action','index.php');
273 $('#controls').submit();
274}
275
276function onGetWaveforms()
277{
278 var arr = document.getElementById("waveform").data;
279
280 $('#controls > input[name=data]').val(JSON.stringify(arr));
281 $('#controls > input[name=name]').val('waveforms.txt');
282 $('#controls').attr('action','index.php');
283 $('#controls').submit();
284}
285
286function onGetGeometry()
287{
288 var sqrt32 = Math.sqrt(3)/2;
289
290 var arr = [ new Array(1440), new Array(1440) ];
291
292 for (var i=0; i<1440; i++)
293 {
294 arr[0][i] = coord[i][0]*0.1111;
295 arr[1][i] = coord[i][1]*0.1111*sqrt32;
296 }
297
298 $('#controls > input[name=data]').val(JSON.stringify(arr));
299 $('#controls > input[name=name]').val('geometry.txt');
300 $('#controls').attr('action','index.php');
301 $('#controls').submit();
302}
303
304function onReady()
305{
306 CodeMirror.colorize(null, 'javascript');
307
308 //$('input,select').keypress(function(event) { return event.keyCode != 13; });
309
310 //colorizeHTML("code0");
311 //colorizeHTML("code1");
312
313 $("#accordion").accordion({collapsible:true,active:false,heightStyle:'content'});
314 $("#accordion").find('h3').filter(':contains(Runtime)').hide();
315 if (location.href.search('debug')==-1)
316 $("#accordion").find('h3').filter(':contains(Debug)').hide();
317
318 $("#textcontainer1").resizable({handles:"s",autoHide:true,});
319 $("#textcontainer1").on("resize", onResize);
320
321 $("#textcontainer2").resizable({handles:"s",autoHide:true,});
322 $("#textcontainer2").on("resize", onResize);
323
324 $("#cameracontainer").on("resize", onResizeCameras);
325 onResizeCameras();
326
327 $("#histcontainer").on("resize", onResizeHistograms);
328 onResizeHistograms();
329
330 $("#contcamera1").click(onClickContCamera);
331 $("#contcamera2").click(onClickContCamera);
332 $("#contcamera3").click(onClickContCamera);
333 $("#contcamera4").click(onClickContCamera);
334
335 $("#conthist1").click(onClickContHist);
336 $("#conthist2").click(onClickContHist);
337 $("#conthist3").click(onClickContHist);
338 $("#conthist4").click(onClickContHist);
339
340 $("#camera1").click(onClick);
341 $("#camera2").click(onClick);
342 $("#camera3").click(onClick);
343 $("#camera4").click(onClick);
344
345 $('#camera1').mousedown(onRightMouseClick);
346 $('#camera2').mousedown(onRightMouseClick);
347 $('#camera3').mousedown(onRightMouseClick);
348 $('#camera4').mousedown(onRightMouseClick);
349
350 editor1 = createEditor("editor1");
351 editor2 = createEditor("editor2");
352
353 setupAccordion('#accordion5', '#editorcontainer1', true);
354 setupAccordion('#accordion1', '#editorcontainer2');
355
356 $('#accordion5').on("accordionactivate", function() { $('#editorcontainer1fake').hide(); editor1.refresh(); });
357 $('#accordion1').on("accordionactivate", function() { $('#editorcontainer2fake').hide(); editor2.refresh(); });
358
359 setupAccordion('#accordion2', '#cameracontainer');
360 setupAccordion('#accordion7', '#histcontainer', true);
361 setupAccordion('#accordion3', '#waveformcontainer');
362 setupAccordion('#accordion4', '#helpcontainer', true);
363 setupAccordion('#accordion6', '#ctrlcontainer', true);
364
365 $("#selectfile1").on('change', onFile);
366 $("#selectfile2").on('change', onFile);
367
368 $(document).ajaxStart(function() { disableControls(true) }).ajaxStop(function() { disableControls(false); });
369
370
371 $.ajax({
372 type: "POST",
373 cache: false,
374 url: "index.php",
375 success: onFilelistReceived,
376 error: function(xhr) { if (xhr.status==0) alert("ERROR[0] - Request failed!"); else alert("ERROR[0] - "+xhr.statusText+" ["+xhr.status+"]"); }
377 });
378}
379
380function onFileSelect(event, ui)
381{
382 setFileChecks(ui.item.value);
383 document.getElementById("event").value = 0;
384 onSubmit(ui.item.value);
385}
386
387function onFilelistReceived(result)
388{
389 //var dbg = document.getElementById("debug");
390
391 //var pre = document.createElement("pre");
392 //pre.appendChild(document.createTextNode(rc));
393 //dbg.appendChild(pre);
394
395 var rc;
396 try
397 {
398 rc = JSON.parse(result);
399 }
400 catch (e)
401 {
402 alert("ERROR[0] - Decoding answer:\n"+e);
403 debug(result);
404 return;
405 }
406
407 document.getElementById("file").data = rc;
408
409 var list = [ ];
410 for (var file in rc)
411 list.push(file);
412
413 var opts =
414 {
415 source: list,
416 select: onFileSelect,
417 position: { my: "right top", at: "right bottom", collision: "flipfit" },
418 };
419
420 $("#file").autocomplete(opts);
421 //document.getElementById("file").value = "2014/04/17-181";
422
423 //onSubmit("2014/04/17-181");
424}
425
426function setZoom(xfrom, xto, yfrom, yto)
427{
428 var xaxis = plot.getXAxes()[0];
429 var yaxis = plot.getYAxes()[0];
430
431 if (xfrom!==undefined)
432 xaxis.options.min = xfrom;
433 if (xto!==undefined)
434 xaxis.options.max = xto;
435
436 if (yfrom!==undefined)
437 yaxis.options.min = yfrom;
438 if (yto!==undefined)
439 yaxis.options.max = yto;
440
441 plot.setupGrid();
442 plot.draw();
443 plot.clearSelection();
444}
445
446function onPlotHover(event, pos, item)
447{
448 if (!item)
449 {
450 $("#tooltip").hide();//fadeOut(100);
451 return;
452 }
453
454 var x = item.datapoint[0].toFixed(2);
455 var y = item.datapoint[1].toFixed(2);
456
457 var tooltip = $("#tooltip");
458 tooltip.html(parseInt(x) + " / " + y);
459 tooltip.css({top: item.pageY-20, left: item.pageX+5});
460 tooltip.show();//fadeIn(200);
461}
462
463function drawHist(n)
464{
465 var canv = document.getElementById("camera"+n);
466 var hist = document.getElementById("hist"+n);
467
468 var xmin = parseFloat(document.getElementById("histmin"+n).value);
469 var xmax = parseFloat(document.getElementById("histmax"+n).value);
470 var nbins = 100;//parseInt(xmax-xmin);
471 var step = (xmax-xmin)/nbins;
472 if (step<1)
473 {
474 step = 1;
475 nbins = parseInt(xmax-xmin)+1;
476 }
477
478 var bins = new Array(nbins);
479 for (var i=0; i<nbins; i++)
480 bins[i] = [ xmin+i*step, 0 ];
481
482 var data = canv.dataAbs;
483 for (var i=0; i<1440; i++)
484 if (data[i]!==undefined/* && data[i]!==null*/)
485 {
486 var ix = parseInt((data[i]-xmin)/step);
487 if (ix>=0 && ix<nbins)
488 bins[ix][1] ++;
489 }
490
491 var opts =
492 {
493 grid: {
494 hoverable: true,
495 }
496 };
497
498 var hist = $.plot("#hist"+n, [ { data:bins, bars: {show:true} } ], opts);
499 $('#hist'+n).bind("plothover", onPlotHover);
500}
501
502function processCameraData(n, data)
503{
504 var canv = document.getElementById("camera"+n);
505 canv.dataRel = null;
506
507 if (!Array.isArray(data))
508 return;
509
510 canv.dataAbs = new Array(1440);
511 for (var i=0; i<1440; i++)
512 {
513 var val = data[map[i]];
514 if (!isNaN(val) && val!==null)
515 canv.dataAbs[i] = val;
516 }
517
518 canv.min = Math.min.apply(Math, canv.dataAbs.filter(function(e){return e!==undefined;}));
519 canv.max = Math.max.apply(Math, canv.dataAbs.filter(function(e){return e!==undefined;}));
520
521 canv.dataRel = new Array(1440);
522 for (var i=0; i<1440; i++)
523 {
524 var val = canv.dataAbs[i];
525 if (val!==undefined)
526 canv.dataRel[i] = (val-canv.min)/canv.max;
527 }
528
529 if (document.getElementById("cameraminon"+n).checked)
530 document.getElementById("cameramin"+n).value = canv.min;
531 if (document.getElementById("cameramaxon"+n).checked)
532 document.getElementById("cameramax"+n).value = canv.max;
533
534 // ---------------------------
535
536 var hist = document.getElementById("hist"+n);
537
538 hist.min = canv.min;
539 hist.max = canv.max;
540
541 if (document.getElementById("histminon"+n).checked)
542 document.getElementById("histmin"+n).value = canv.min;
543 if (document.getElementById("histmaxon"+n).checked)
544 document.getElementById("histmax"+n).value = canv.max;
545
546 drawHist(n);
547}
548
549function onDataReceived(result)
550{
551 var err = document.getElementById("error");
552 var dbg = document.getElementById("debug");
553 var con = document.getElementById("console");
554
555 //var pre = document.createElement("pre");
556 //pre.appendChild(document.createTextNode(rc));
557 //dbg.appendChild(pre);
558
559 var rc;
560 try
561 {
562 rc = JSON.parse(result);
563 if (!rc)
564 return;
565 }
566 catch (e)
567 {
568 alert("ERROR[1] - Decoding answer:\n"+e);
569 debug(result);
570 return;
571 }
572
573 var evt = rc.event;
574 var file = rc.file;
575
576 document.getElementById("event").max = file.numEvents-1;
577 var el = document.getElementById("numevents");
578 if (el.firstChild)
579 el.removeChild(el.firstChild);
580 el.appendChild(document.createTextNode(file.numEvents));
581
582 var infotxt = "<pre>";
583 infotxt += "\nStart time: "+new Date(file.runStart*24*3600*1000).toUTCString();
584 infotxt += "\nEnd time: "+new Date(file.runEnd*24*3600*1000).toUTCString();
585 infotxt += "\nRun type: "+file.runType;
586 if (file.drsFile>=0)
587 infotxt += " [drs-step "+file.drsFile+"]";
588
589 $("#runinfo").html(infotxt);
590 $("#eventinfo").html("Trigger: "+evt.trigger.join(' | ')+" [0x"+evt.triggerType.toString(16)+"]");
591
592 if (rc.ret)
593 {
594 while (con.lastChild)
595 con.removeChild(con.lastChild);
596 }
597
598 if (rc.err)
599 {
600 while (err.lastChild)
601 err.removeChild(err.lastChild);
602
603 err.appendChild(document.createTextNode("Javascript runtime exception: "+rc.err.file+":"+rc.err.lineNumber));
604 err.appendChild(document.createTextNode("\n"));
605 err.appendChild(document.createTextNode(rc.err.sourceLine));
606 err.appendChild(document.createTextNode("\n"));
607 err.appendChild(document.createTextNode(rc.err.trace));
608
609 var editor = rc.err.file=="main" ? editor2 : editor1;
610 editor.setCursor(rc.err.lineNumber-1, 1);
611
612 $("#accordion").find('h3').filter(':contains(Runtime)').show();
613 $("#accordion").accordion("option", "active", 0);
614 }
615
616 if (rc.debug!==undefined)
617 {
618 con.appendChild(document.createTextNode(rc.debug));
619
620 debug("PHP execution:");
621 debug("Time Javascripts = "+(rc.timeJs[0]*1000).toFixed(2)+","+(rc.timeJs[1]*1000).toFixed(2)+","+(rc.timeJs[2]*1000).toFixed(2)+ " [ms]");
622 }
623
624 if (rc.ret!==undefined && Array.isArray(rc.ret))
625 {
626 var now = new Date();
627
628 if (rc.ret[0] instanceof Object)
629 processCameraData(1, rc.ret[0]);
630 else
631 processCameraData(1, rc.ret);
632
633 if (rc.ret.length>1)
634 processCameraData(2, rc.ret[1]);
635
636 if (rc.ret.length>2)
637 processCameraData(3, rc.ret[2]);
638
639 if (rc.ret.length>3)
640 processCameraData(4, rc.ret[3]);
641
642 debug("Calc Time = "+(new Date()-now)+" ms");
643 }
644
645 // We have to redraw all of them to display the changed pixel value
646 onCameraMinMax(1);
647 onCameraMinMax(2);
648 onCameraMinMax(3);
649 onCameraMinMax(4);
650
651 debug("Total time = "+(rc.timePhp*1000).toFixed(1)+" ms");
652 debug("Peak memory = "+rc.memory+" MiB");
653
654 if (Array.isArray(rc.waveform))
655 {
656 var waveform = document.getElementById("waveform");
657 waveform.data = [ ];
658
659 var data = [
660 { label: "[0] ", data: new Array(evt.numRoi) },
661 { label: "[1] ", data: new Array(evt.numRoi) },
662 { label: "[2] ", data: new Array(evt.numRoi) },
663 { label: "[3] ", data: new Array(evt.numRoi) },
664 ];
665
666 var min = [];
667 var max = [];
668 if (Array.isArray(rc.waveform) && rc.waveform.length==evt.numRoi)
669 {
670 min.push(Math.min.apply(Math, rc.waveform));
671 max.push(Math.max.apply(Math, rc.waveform));
672
673 var d = data[0].data;
674 for (var i=0; i<evt.numRoi; i++)
675 d[i] = [ i, rc.waveform[i] ];
676
677 waveform.data[0] = rc.waveform;
678 }
679
680 for (var j=0; j<4; j++)
681 {
682 var ref = rc.waveform[j];
683
684 if (Array.isArray(ref) && ref.length==evt.numRoi)
685 {
686 min.push(Math.min.apply(Math, ref));
687 max.push(Math.max.apply(Math, ref));
688
689 var d = data[j].data;
690 for (var i=0; i<evt.numRoi; i++)
691 d[i] = [ i, ref[i] ];
692
693 waveform.data[j] = ref;
694 }
695 }
696
697 waveform.ymin = Math.min.apply(Math, min);
698 waveform.ymax = Math.max.apply(Math, max);
699 waveform.xmin = 0;
700 waveform.xmax = evt.numRoi;
701
702 if (document.getElementById("waveformxminon").checked)
703 document.getElementById("waveformxmin").value = waveform.xmin;
704 if (document.getElementById("waveformxmaxon").checked)
705 document.getElementById("waveformxmax").value = waveform.xmax;
706
707 if (document.getElementById("waveformminon").checked)
708 document.getElementById("waveformmin").value = waveform.ymin;
709 if (document.getElementById("waveformmaxon").checked)
710 document.getElementById("waveformmax").value = waveform.ymax;
711
712 var xmin = document.getElementById("waveformxminon").checked ? waveform.xmin : parseInt(document.getElementById("waveformxmin").value);
713 var xmax = document.getElementById("waveformxmaxon").checked ? waveform.xmax : parseInt(document.getElementById("waveformxmax").value);
714
715 var ymin = document.getElementById("waveformminon").checked ? waveform.ymin : parseInt(document.getElementById("waveformmin").value);
716 var ymax = document.getElementById("waveformmaxon").checked ? waveform.ymax : parseInt(document.getElementById("waveformmax").value);
717
718 var opts =
719 {
720 xaxis: {
721 min: xmin-1,
722 max: xmax+1,
723 },
724 yaxis: {
725 min: ymin-5,
726 max: ymax+5,
727 },
728 series: {
729 lines: {
730 show: true
731 },
732 points: {
733 show: true,
734 symbol: 'cross',
735 }
736 },
737 selection: {
738 mode: "xy"
739 },
740 grid: {
741 hoverable: true,
742 }
743 };
744
745 plot = $.plot("#waveform", data, opts);
746
747 waveform = $('#waveform');
748 waveform.bind("plotselected", function (event, ranges)
749 {
750 setZoom(ranges.xaxis.from, ranges.xaxis.to,
751 ranges.yaxis.from, ranges.yaxis.to);
752 });
753
754 waveform.dblclick(function ()
755 {
756 var waveform = document.getElementById("waveform");
757 setZoom(waveform.xmin-1, waveform.xmax+1, waveform.ymin-5, waveform.ymax+5);
758 });
759 waveform.bind("plothover", onPlotHover);
760 }
761}
762
763function onSubmit(file, pixelOnly)
764{
765 if (!file)
766 file = document.getElementById("file").value;
767
768 var dbg = document.getElementById("debug");
769 while (dbg.lastChild)
770 dbg.removeChild(dbg.lastChild);
771
772 var active = $("#accordion").accordion("option", "active");
773 if (active==0)
774 {
775 $("#accordion").accordion("option", "active", false);
776 $("#accordion").find('h3').filter(':contains(Runtime)').hide();
777 }
778
779 var calibrated = document.getElementById("calibrated");
780 var drsfile = document.getElementById("drsfile");
781 var montecarlo = document.getElementById("montecarlo");
782 var ismc = montecarlo.checked;
783 var calib = !calibrated.disabled && calibrated.checked;
784 var drs = !drsfile.disabled && drsfile.checked;
785 var event = document.getElementById("event").value;
786 var pixel = document.getElementById("pixel").value;
787 var source1 = editor1.getValue();
788 var source2 = editor2.getValue();
789
790 var uri = "file="+file+"&event="+event+"&pixel="+map[pixel];
791 uri += "&source1="+encodeURIComponent(source1);
792 if (!pixelOnly)
793 uri += "&source2="+encodeURIComponent(source2);
794 if (calib)
795 uri += "&calibrated=1";
796 if (drs)
797 uri += "&drsfile=1";
798 if (ismc)
799 uri += "&montecarlo=1";
800
801 $.ajax({
802 type: "POST",
803 cache: false,
804 url: "index.php",
805 data: uri,
806 success: onDataReceived,
807 error: function(xhr) { if (xhr.status==0) alert("ERROR[1] - Request failed!"); else alert("ERROR[1] - "+xhr.statusText+" ["+xhr.status+"]"); }
808 });
809}
810
811function onFile(event, ui)
812{
813 var f = event.target.files[0];
814 if (!f)
815 return;
816
817 if (!f.type.match('text/plain') && !f.type.match('application/javascript') && !f.type.match('application/x-javascript'))
818 {
819 alert("ERROR - Unknown file type: "+f.type);
820 return;
821 }
822
823 var id = event.target.id;
824 var editor = id[id.length-1]=='1' ? editor1 : editor2;
825
826 var reader = new FileReader();
827
828 // Closure to capture the file information.
829 reader.onload = (function(theFile) { return function(e) { editor.setValue(e.target.result); }; })(f);
830 // onloadstart
831 // onloadend
832 // onprogress
833
834 // Read in the text file
835 reader.readAsText(f);
836}
837
838function refreshCameras()
839{
840 drawFullCam("camera1");
841 drawFullCam("camera2");
842 drawFullCam("camera3");
843 drawFullCam("camera4");
844}
845
846function onEvent()
847{
848 onSubmit();
849}
850
851function checkPixel()
852{
853 var pix = parseInt(document.getElementById("pixel").value);
854 var c = parseInt(document.getElementById("cbpx-c").value);
855 var b = parseInt(document.getElementById("cbpx-b").value);
856 var p = parseInt(document.getElementById("cbpx-p").value);
857 var x = parseInt(document.getElementById("cbpx-x").value);
858 var cbpx = parseInt(document.getElementById("cbpx").value);;
859
860 if (pix >=0 && pix <1440 &&
861 c >=0 && c < 4 &&
862 b >=0 && b < 10 &&
863 p >=0 && p < 4 &&
864 x >=0 && x < 9 &&
865 cbpx>=0 && cbpx<1440)
866 return;
867
868 document.getElementById("pixel").value = 0;
869 document.getElementById("cbpx-c").value = 1;
870 document.getElementById("cbpx-b").value = 0;
871 document.getElementById("cbpx-p").value = 3;
872 document.getElementById("cbpx-x").value = 6;
873 document.getElementById("cbpx").value = 393;
874}
875
876
877function onPixel()
878{
879 checkPixel();
880
881 var p = parseInt(document.getElementById("pixel").value);
882
883 var cbpx = map[p];
884
885 document.getElementById("cbpx-c").value = parseInt((cbpx/360));
886 document.getElementById("cbpx-b").value = parseInt((cbpx/36)%10);
887 document.getElementById("cbpx-p").value = parseInt((cbpx/9)%4);
888 document.getElementById("cbpx-x").value = parseInt((cbpx%9));
889 document.getElementById("cbpx").value = parseInt(cbpx);
890
891 onSubmit("", true);
892}
893
894function onCBPX()
895{
896 checkPixel();
897
898 var c = parseInt(document.getElementById("cbpx-c").value);
899 var b = parseInt(document.getElementById("cbpx-b").value);
900 var p = parseInt(document.getElementById("cbpx-p").value);
901 var x = parseInt(document.getElementById("cbpx-x").value);
902
903 var cbpx = c*360 + b*36 + p*9 + x;
904
905 document.getElementById("cbpx").value = parseInt(cbpx);
906 document.getElementById("pixel").value = map.indexOf(cbpx);
907
908 onSubmit("", true);
909}
910
911function onHW()
912{
913 checkPixel();
914
915 var cbpx = parseInt(document.getElementById("cbpx").value);;
916
917 document.getElementById("cbpx-c").value = parseInt((cbpx/360));
918 document.getElementById("cbpx-b").value = parseInt((cbpx/36)%10);
919 document.getElementById("cbpx-p").value = parseInt((cbpx/9)%4);
920 document.getElementById("cbpx-x").value = parseInt((cbpx%9));
921
922 document.getElementById("pixel").value = map.indexOf(cbpx);
923
924 onSubmit("", true);
925}
926
927function isInside(x, y, mouse)
928{
929 var dist = Math.sqrt((mouse.x-x)*(mouse.x-x)+(mouse.y-y)*(mouse.y-y));
930 return dist<0.5;
931
932 /*
933 ctx.translate(x, y);
934 ctx.scale(1/2, 1/3);
935
936 ctx.beginPath();
937 ctx.moveTo( 1, 1);
938 ctx.lineTo( 0, 2);
939 ctx.lineTo(-1, 1);
940 ctx.lineTo(-1, -1);
941 ctx.lineTo( 0, -2);
942 ctx.lineTo( 1, -1);
943 ctx.fill();
944
945 ctx.restore();
946 */
947}
948
949var inprogress = { };
950function moveElement(id, n, target, callback)
951{
952 if (inprogress[id]==n || inprogress[id]<0)
953 return;
954
955 inprogress[id] = target ? -n : n;
956
957 var element = $("#"+id+n); //Allow passing in either a JQuery object or selector
958 var newParent = $(target ? target : "#cont"+id+n); //Allow passing in either a JQuery object or selector
959
960 var oldOffset = element.offset();
961
962 var newOffset = newParent.offset();
963
964 var w = newParent.width();
965 var h = newParent.height();
966
967 var temp = element.appendTo('body');
968 temp.css('position', 'absolute')
969 .css('left', oldOffset.left)
970 .css('top', oldOffset.top)
971 .css('zIndex', 999);
972
973 temp.animate( {'top': newOffset.top, 'left':newOffset.left, 'width':w, 'height': h},
974 'slow', function()
975 {
976 temp = temp.appendTo(newParent);
977 temp.css('position', 'relative');
978 temp.css('width', '');
979 temp.css('height', '');
980 temp.css('zIndex', '');
981 temp.css('left', '0');
982 temp.css('top', '0');
983
984 setSize(id+n, w, h);
985
986 if (callback)
987 callback(id+n);
988
989 inprogress[id] = 0;
990 });
991}
992
993function onClickCont(event, callback)
994{
995 var id = event.target.id;
996 if (!id)
997 id = event.target.parentNode.id;
998
999 var n = parseInt(id[id.length-1]);
1000 var type = id.substr(0, id.length-1);
1001
1002 if (id.substr(0, 4)=="cont")
1003 id = id.substr(4, id.length-4);
1004 if (type.substr(0, 4)=="cont")
1005 type = type.substr(4, type.length-4);
1006
1007 if (id.substr(0, type.length)==type)
1008 {
1009 var cont = document.getElementById("center"+type).childNodes[0];
1010 if (cont)
1011 {
1012 var nn = parseInt(cont.id[cont.id.length-1]);
1013 moveElement(type, nn, null, callback);
1014 }
1015 moveElement(type, n, "#center"+type, callback);
1016
1017 }
1018 else
1019 moveElement(type, n, null, callback);
1020
1021}
1022
1023function onClickContCamera(event)
1024{
1025 onClickCont(event, function(el) { drawFullCam(el); });
1026}
1027
1028function onClickContHist(event)
1029{
1030 onClickCont(event);
1031}
1032
1033function onClick(event)
1034{
1035 var cont = document.getElementById("centercamera").childNodes[0];
1036 if (!cont)
1037 return;
1038
1039 if (cont.id!=event.target.id)
1040 return;
1041
1042 // get click position relative to canvas
1043 var rect = event.target.getBoundingClientRect();
1044
1045 var x = event.clientX - rect.left;
1046 var y = event.clientY - rect.top;
1047
1048 var mouse = { x: x, y: y };
1049
1050 // convert click position to pixel index
1051 var index = getIndex(event.target.id, mouse);
1052 if (index<0)
1053 return;
1054
1055 document.getElementById("pixel").value = index;
1056
1057 onPixel();
1058}
1059
1060function getClickPosition(event)
1061{
1062 var rect = event.target.getBoundingClientRect();
1063
1064 var x = event.clientX - rect.left;
1065 var y = event.clientY - rect.top;
1066
1067 return { x: x, y: y };
1068}
1069
1070function onMinMax(id, n)
1071{
1072 var el = document.getElementById(id+n);
1073
1074 el.zmin = document.getElementById(id+"min"+n).value;
1075 el.zmax = document.getElementById(id+"max"+n).value;
1076}
1077
1078function onCameraMinMax(n)
1079{
1080 onMinMax("camera", n);
1081 drawFullCam("camera"+n);
1082}
1083
1084function onHistMinMax(n)
1085{
1086 onMinMax("hist", n);
1087 drawHist(n);
1088}
1089
1090function onMinMaxOn(id, n)
1091{
1092 var el = document.getElementById(id+n);
1093
1094 var redraw;
1095 if (document.getElementById(id+"minon"+n).checked)
1096 {
1097 document.getElementById(id+"min"+n).setAttribute("disabled", "true");
1098 document.getElementById(id+"min"+n).value = el.min;
1099 redraw = true;
1100 }
1101 else
1102 document.getElementById(id+"min"+n).removeAttribute("disabled");
1103
1104 if (document.getElementById(id+"maxon"+n).checked)
1105 {
1106 document.getElementById(id+"max"+n).setAttribute("disabled", "true");
1107 document.getElementById(id+"max"+n).value = el.max;
1108 redraw = true;
1109 }
1110 else
1111 document.getElementById(id+"max"+n).removeAttribute("disabled");
1112
1113 return redraw;
1114}
1115
1116function onCameraMinMaxOn(n)
1117{
1118 if (onMinMaxOn("camera", n))
1119 onCameraMinMax(n);
1120}
1121
1122function onHistMinMaxOn(n)
1123{
1124 if (onMinMaxOn("hist", n))
1125 onHistMinMax(n);
1126}
1127
1128function onWaveformMinMax()
1129{
1130 var wf = document.getElementById("waveform");
1131
1132 var xmin, xmax, ymin, ymax;
1133
1134 var redraw;
1135 if (!document.getElementById("waveformxminon").checked)
1136 xmin = document.getElementById("waveformxmin").value;
1137 if (!document.getElementById("waveformxmaxon").checked)
1138 xmax = document.getElementById("waveformxmax").value;
1139 if (!document.getElementById("waveformminon").checked)
1140 ymin = document.getElementById("waveformmin").value;
1141 if (!document.getElementById("waveformmaxon").checked)
1142 ymax = document.getElementById("waveformmax").value;
1143
1144 setZoom(xmin, xmax, ymin, ymax);
1145
1146}
1147
1148function onWaveformMinMaxOn()
1149{
1150 var wf = document.getElementById("waveform");
1151
1152 var xmin, xmax, ymin, ymax;
1153
1154 var redraw;
1155 if (document.getElementById("waveformxminon").checked)
1156 {
1157 document.getElementById("waveformxmin").setAttribute("disabled", "true");
1158 document.getElementById("waveformxmin").value = wf.xmin;
1159 xmin = wf.xmin-1;
1160 }
1161 else
1162 document.getElementById("waveformxmin").removeAttribute("disabled");
1163
1164 if (document.getElementById("waveformxmaxon").checked)
1165 {
1166 document.getElementById("waveformxmax").setAttribute("disabled", "true");
1167 document.getElementById("waveformxmax").value = wf.xmax;
1168 xmax = wf.xmax+1;
1169 }
1170 else
1171 document.getElementById("waveformxmax").removeAttribute("disabled");
1172
1173 if (document.getElementById("waveformminon").checked)
1174 {
1175 document.getElementById("waveformmin").setAttribute("disabled", "true");
1176 document.getElementById("waveformmin").value = wf.ymin;
1177 ymin = wf.ymin-5;
1178 }
1179 else
1180 document.getElementById("waveformmin").removeAttribute("disabled");
1181
1182 if (document.getElementById("waveformmaxon").checked)
1183 {
1184 document.getElementById("waveformmax").setAttribute("disabled", "true");
1185 document.getElementById("waveformmax").value = wf.ymax;
1186 ymax = wf.ymax+5;
1187 }
1188 else
1189 document.getElementById("waveformmax").removeAttribute("disabled");
1190
1191 setZoom(xmin, xmax, ymin, ymax);
1192}
1193
1194//document.addEventListener("click", getClickPosition, false);
1195
1196$(document).ready(onReady);
1197
1198// ================================== Pixel mapping =================================================
1199
1200var map = new Array(1440);
1201
1202function initPixelMap()
1203{
1204 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:";
1205 // first: decode the pixel mapping!
1206 var sum = 1036080;
1207 for (var i=0; i<1440; i++)
1208 {
1209 var d0 = codedMap.charCodeAt(i*2) -48;
1210 var d1 = codedMap.charCodeAt(i*2+1)-48;
1211
1212 map[i] = d0 | (d1<<6);
1213 sum -= map[i];
1214 }
1215 if (sum!=0)
1216 alert("Pixel mapping table corrupted!");
1217}
1218
1219initPixelMap();
1220
1221// ================================== Camera Display ================================================
1222
1223var coord = new Array(1440);
1224function initCameraCoordinates()
1225{
1226 coord[0] = [0, 0];
1227 var cnt = 1;
1228 for (var ring=1; ring<24; ring++)
1229 {
1230 for (var s=0; s<6; s++)
1231 {
1232 for (var i=1; i<=ring; i++)
1233 {
1234 var pos = new Position(s, ring, i);
1235 if (pos.d() - pos.x > 395.75)
1236 continue;
1237
1238 coord[cnt++] = [ pos.x, pos.y];
1239 }
1240 }
1241 }
1242
1243 coord[1438] = [7, -22];
1244 coord[1439] = [7, 22];
1245}
1246
1247initCameraCoordinates();
1248
1249function getIndex(id, mouse)
1250{
1251 var canv = document.getElementById(id);
1252
1253 var scale = 83;
1254
1255 var w = Math.min(canv.width/scale, canv.height/scale);
1256
1257 //ctx.translate(canv.width/2, canv.height/2);
1258 //ctx.scale(w*2, w*2);
1259 //ctx.scale(1, Math.sqrt(3)/2);
1260 //ctx.translate(-0.5, 0);
1261
1262 mouse.x -= canv.width/2;
1263 mouse.y -= canv.height/2;
1264 mouse.x /= w*2;
1265 mouse.y /= w*2;
1266 mouse.y /= Math.sqrt(3)/2;
1267 mouse.x -= -0.5;
1268
1269 for (var i=0; i<1440; i++)
1270 if (isInside(coord[i][0], coord[i][1], mouse))
1271 return i;
1272
1273 return -1;
1274}
1275
1276
1277function hueToRGB(hue)
1278{
1279 hue /= 3;
1280 hue %= 6;
1281
1282 if (hue<1) return parseInt(255*hue, 10);
1283 if (hue<3) return parseInt(255, 10);
1284 if (hue<4) return parseInt(255*(4-hue), 10);
1285
1286 return 0.
1287}
1288
1289function hueToHex(flt)
1290{
1291 var s = hueToRGB(flt).toString(16);
1292 return s.length==2 ? s : "0"+s;
1293}
1294
1295function HLStoRGB(hue)
1296{
1297 if (isNaN(hue))
1298 return "fff";
1299
1300 if (hue<0)
1301 return "eef"; // 555
1302
1303 if (hue>1)
1304 return "dde";//"700"; // 666
1305
1306 hue *= 14;
1307
1308 var sr = hueToHex(20-hue);
1309 var sg = hueToHex(14-hue);
1310 var sb = hueToHex(26-hue);
1311
1312 return sr+sg+sb;
1313}
1314
1315function outlineHex(ctx)
1316{
1317 ctx.scale(1/2, 1/3);
1318
1319 ctx.beginPath();
1320 ctx.moveTo( 1, 1);
1321 ctx.lineTo( 0, 2);
1322 ctx.lineTo(-1, 1);
1323 ctx.lineTo(-1, -1);
1324 ctx.lineTo( 0, -2);
1325 ctx.lineTo( 1, -1);
1326 ctx.lineTo( 1, 1);
1327}
1328
1329function fillHex(ctx, i, col, min, max)
1330{
1331 if (col===undefined/* || col===null*/)
1332 return false;
1333
1334 var lvl = max==min ? 0.5 : (col-min)/(max-min);
1335
1336 ctx.fillStyle = "#"+HLStoRGB(lvl);
1337
1338 ctx.save();
1339 ctx.translate(coord[i][0], coord[i][1]);
1340 outlineHex(ctx);
1341 ctx.fill();
1342 ctx.restore();
1343
1344 return true;
1345}
1346
1347function drawHex(ctx, i)
1348{
1349 ctx.save();
1350 ctx.translate(coord[i][0], coord[i][1]);
1351 outlineHex(ctx);
1352 ctx.stroke();
1353 ctx.restore();
1354}
1355
1356
1357function Position(s, ring, i)
1358{
1359 switch (s)
1360 {
1361 case 1: this.x = ring - i*0.5; this.y = + i; break;
1362 case 2: this.x = ring*0.5 - i; this.y = ring ; break;
1363 case 3: this.x = -ring*0.5 - i*0.5; this.y = ring - i; break;
1364 case 4: this.x = -ring + i*0.5; this.y = - i; break;
1365 case 5: this.x = -ring*0.5 + i; this.y = -ring ; break;
1366 case 0: this.x = ring*0.5 + i*0.5; this.y = -ring + i; break;
1367 }
1368 this.d = (function () { return this.x*this.x + this.y*this.y*3/4; });
1369}
1370
1371function drawFullCam(id)
1372{
1373 var canv = document.getElementById(id);
1374 if (!canv)
1375 return;
1376
1377 var ctx = canv.getContext("2d");
1378
1379 ctx.clearRect(0, 0, canv.width, canv.height);
1380
1381 // ======================= Draw Graphics ======================
1382
1383 var data = canv.dataRel;
1384 if (!data)
1385 return;
1386
1387 var pixel = document.getElementById('pixel').value;
1388
1389 var min = (canv.zmin-canv.min)/canv.max;
1390 var max = (canv.zmax-canv.min)/canv.max;
1391
1392 var scale = 83;
1393
1394 var w = Math.min(canv.width/scale, canv.height/scale);
1395
1396 ctx.save();
1397 ctx.translate(canv.width/2, canv.height/2);
1398 ctx.scale(w*2, w*2);
1399 // ctx.rotate(Math.PI/3);
1400
1401 ctx.scale(1, Math.sqrt(3)/2);
1402 ctx.translate(-0.5, 0);
1403
1404 if (document.getElementById('grid').checked)
1405 {
1406 ctx.lineWidth = 0.02;
1407 ctx.strokeStyle = "#000";
1408 for (var i=0; i<1440; i++)
1409 drawHex(ctx, i);
1410 }
1411
1412 var hasData = false;
1413 if (max>=min)
1414 for (var i=0; i<1440; i++)
1415 hasData |= fillHex(ctx, i, data[i], min, max);
1416
1417 // ======================= Draw Ellipse ======================
1418
1419 if (document.getElementById('image').checked)
1420 {
1421 var h = Hillas(canv.dataAbs, canv.zmin, canv.zmax);
1422 if (h)
1423 {
1424 ctx.save();
1425
1426 ctx.scale(1, 2/Math.sqrt(3));
1427
1428 ctx.beginPath();
1429 ctx.moveTo(0.5, 0);
1430 ctx.lineTo(h.mean[0], h.mean[1]);
1431
1432 ctx.strokeStyle = "#CCC";
1433 ctx.lineWidth = 0.1;
1434 ctx.stroke();
1435
1436 ctx.translate(h.mean[0], h.mean[1]);
1437 ctx.rotate(h.phi);
1438
1439 ctx.beginPath();
1440 ctx.moveTo(0, -h.disp);
1441 ctx.lineTo(0, h.disp);
1442
1443 ctx.strokeStyle = "#888";
1444 ctx.lineWidth = 0.15;
1445 ctx.stroke();
1446
1447 ctx.save();
1448 ctx.scale(h.axis[0], h.axis[1]);
1449 ctx.beginPath();
1450 ctx.arc(0, 0, 1, 0, 2*Math.PI);
1451 ctx.restore();
1452
1453 ctx.strokeStyle = "#555";
1454 ctx.lineWidth = 0.15;
1455 ctx.stroke();
1456
1457 ctx.restore();
1458 }
1459 }
1460
1461 // =================== Draw Pixel marker ====================
1462
1463 if (document.getElementById('marker').checked)
1464 {
1465 // Draw marker
1466 ctx.lineWidth = 0.25;
1467 ctx.strokeStyle = "#000";
1468 drawHex(ctx, pixel);
1469 }
1470
1471
1472 ctx.restore();
1473
1474 if (!hasData)
1475 return;
1476
1477 // ======================= Draw Legend ======================
1478
1479 var v0 = parseFloat(canv.zmin);
1480 var v1 = parseFloat(canv.zmax);
1481
1482 var diff = v1-v0;
1483
1484 var cw = canv.width;
1485 //var ch = canv.height;
1486
1487 ctx.font = "8pt Arial";
1488 ctx.textAlign = "right";
1489 ctx.textBaseline = "top";
1490
1491 for (var i=0; i<11; i++)
1492 {
1493 ctx.strokeStyle = "#"+HLStoRGB(i/10);
1494 ctx.strokeText((v0+diff*i/10).toPrecision(3), cw-5, 125-i*12);
1495 }
1496
1497 var pval = parseFloat(canv.dataAbs[pixel]).toFixed(1);
1498 var lmin = parseFloat(canv.min).toFixed(1);
1499 var lmax = parseFloat(canv.max).toFixed(1);
1500
1501 if (isNaN(pval))
1502 pval = "";
1503
1504 var mw = Math.max(ctx.measureText(lmin).width,
1505 ctx.measureText(pval).width,
1506 ctx.measureText(lmax).width);
1507
1508 ctx.textBaseline = "top";
1509 ctx.strokeStyle = "#000";
1510
1511 ctx.strokeText(lmax, 5+mw, 5+24);
1512 ctx.strokeText(pval, 5+mw, 5+12);
1513 ctx.strokeText(lmin, 5+mw, 5);
1514}
1515
1516// ===================================================================
1517
1518function Hillas(data, min, max)
1519{
1520 var mx = 0;
1521 var my = 0;
1522 var sz = 0;
1523
1524 var mx2 = 0;
1525 var my2 = 0;
1526 var mxy = 0;
1527
1528 var cnt = 0;
1529 for (var i=0; i<1440; i++)
1530 {
1531 if (data[i]===undefined || data[i]<min || data[i]>max)
1532 continue;
1533
1534 sz += data[i];
1535 mx += data[i] * coord[i][0];
1536 my += data[i] * coord[i][1];
1537
1538 mx2 += data[i] * coord[i][0]*coord[i][0];
1539 my2 += data[i] * coord[i][1]*coord[i][1];
1540 mxy += data[i] * coord[i][0]*coord[i][1];
1541
1542 cnt++;
1543 }
1544
1545 if (sz==0 || cnt<3)
1546 return;
1547
1548 // Coordinates need to be scaled in y
1549 var f = Math.sqrt(3)/2;
1550
1551 my *= f;
1552 mxy *= f;
1553 my2 *= f*f;
1554
1555 var xx = mx2 - mx*mx/sz;
1556 var yy = my2 - my*my/sz;
1557 var xy = mxy - mx*my/sz;
1558
1559 var d0 = yy - xx;
1560 var d1 = xy*2;
1561 var d2 = Math.sqrt(d0*d0 + d1*d1) + d0;
1562
1563 var phi = 0;
1564 var cos = 0;
1565 var sin = 1;
1566
1567 var axis1 = yy;
1568 var axis2 = xx;
1569
1570 // Correction for scale in x
1571 var ratio = xx/yy;
1572
1573 if (d1!=0 || d2==0)
1574 {
1575 var tand = d2==0 ? 0 : d2 / d1;
1576 var tand2 = tand*tand;
1577
1578 var s2 = tand2+1;
1579 var s = Math.sqrt(s2);
1580
1581 phi = Math.atan(tand)-Math.PI/2;
1582 cos = 1.0 /s;
1583 sin = tand/s;
1584
1585 axis1 = (tand2*yy + d2 + xx);
1586 axis2 = (tand2*xx - d2 + yy);
1587
1588 ratio = axis2/axis1;
1589
1590 axis1 /= s2;
1591 axis2 /= s2;
1592 }
1593
1594 var length = axis1<0 ? 0 : Math.sqrt(axis1/sz);
1595 var width = axis2<0 ? 0 : Math.sqrt(axis2/sz);
1596
1597 return {
1598 "mean": [ mx/sz, my/sz ],
1599 "axis": [ width, length ],
1600 "phi": phi,
1601 "delta": [ cos, sin ],
1602 "sumw": sz,
1603 "count": cnt,
1604 "disp": 1.47/0.1111*(1-Math.sqrt(ratio)),
1605 };
1606}
Note: See TracBrowser for help on using the repository browser.