source: trunk/FACT++/www/viewer/index.js@ 17711

Last change on this file since 17711 was 17711, checked in by tbretz, 11 years ago
Do not process main when only the pixel has been changed; some imporvements to the main accordion; A slightly nicer test code.
File size: 30.6 KB
Line 
1'use strict';
2
3// display 'Wait'
4
5var editor1;
6var editor2;
7var plot;
8
9function debug(txt)
10{
11 var dbg = document.getElementById("debug");
12 dbg.appendChild(document.createTextNode(txt));
13 dbg.appendChild(document.createElement("br"));
14}
15
16function setupAccordion(accordion, container, inactive)
17{
18 function onAccordion(event, ui)
19 {
20 if (ui.oldHeader.length==0)
21 $(container).slideDown(400);
22 else
23 $(container).slideUp(400);
24 }
25
26 var config = { collapsible: true };
27
28 if (inactive)
29 {
30 config.active = false;
31 $(container).hide();
32 }
33
34 var acc = $(accordion);
35
36 acc.accordion(config);
37 acc.on("accordionbeforeactivate", onAccordion);
38}
39
40function onResize(event, ui)
41{
42 if (!ui.size)
43 return;
44
45 $(event.target.id).css({marginRight:'2px'});
46
47 var editor = event.target.id=="textcontainer1" ? editor1 : editor2;
48
49 editor.setSize("100%", ui.size.height);
50 editor.refresh();
51}
52
53function onResizeCenter(event, ui)
54{
55 var w = document.getElementById("cameracontainer").clientWidth/4;
56
57 var offy = 0;
58 var offx = 5;
59
60 var cont = document.getElementById("center").childNodes[0];
61
62 var nn;
63 if (cont)
64 {
65 nn = parseInt(cont.id[cont.id.length-1]);
66
67 document.getElementById("camera"+nn).height=parseInt(w*2);
68 document.getElementById("camera"+nn).width=parseInt(w*2);
69 }
70
71 if (nn!=1)
72 {
73 document.getElementById("camera1").height=parseInt(w)-offy;
74 document.getElementById("camera1").width=parseInt(w)-offx;
75 }
76
77 if (nn!=2)
78 {
79 document.getElementById("camera2").height=parseInt(w)-offy;
80 document.getElementById("camera2").width=parseInt(w)-offx;
81 }
82
83 if (nn!=3)
84 {
85 document.getElementById("camera3").height=parseInt(w)-offy;
86 document.getElementById("camera3").width=parseInt(w)-offx;
87 }
88
89 if (nn!=4)
90 {
91 document.getElementById("camera4").height=parseInt(w)-offy;
92 document.getElementById("camera4").width=parseInt(w)-offx;
93 }
94
95 document.getElementById("center").width=parseInt(w*2);
96
97 document.getElementById("cont1").width=parseInt(w);
98 document.getElementById("cont2").width=parseInt(w);
99 document.getElementById("cont3").width=parseInt(w);
100 document.getElementById("cont4").width=parseInt(w);
101
102 document.getElementById("cont1").height=parseInt(w);
103 document.getElementById("cont2").height=parseInt(w);
104 document.getElementById("cont3").height=parseInt(w);
105 document.getElementById("cont4").height=parseInt(w);
106
107 drawFullCam("camera1");
108 drawFullCam("camera2");
109 drawFullCam("camera3");
110 drawFullCam("camera4");
111}
112
113function createEditor(textarea)
114{
115 var editor;
116
117 var config =
118 {
119 //value: "function myScript(){return 100;}\n",
120 mode: { name: "text/typescript", globalVars: true },
121 lineNumbers: true,
122 styleActiveLine: true,
123 matchBrackets: true,
124 indentUnit: 4,
125 foldGutter: true,
126 gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
127 extraKeys: {
128 //"Ctrl-D": "duplicateLine",
129 //"Alt--": "goToBracket",
130 //"Ctrl-H": "findPrev",
131 "Ctrl-Down": "autocomplete",
132 "Tab": "indentAuto",
133 "Ctrl-Y": "deleteLine",
134 "Ctrl-.": function(cm) {
135 cm.foldCode(cm.getCursor());
136 },
137 "F11": function(cm) {
138 editor.setOption("fullScreen", !editor.getOption("fullScreen"));
139 },
140 "Ctrl-R": function(cm) {
141 editor.execCommand("replace");
142 },
143 "Esc": function(cm) {
144 if (editor.getOption("fullScreen")) editor.setOption("fullScreen", false);
145 },
146 "Enter": function(cm) {
147 editor.execCommand("indentAuto");
148 editor.execCommand("newlineAndIndent");
149 },
150 }
151
152 };
153
154 editor = CodeMirror.fromTextArea(document.getElementById(textarea), config);
155 editor.setOption("theme", "blackboard");
156
157 return editor;
158}
159
160function colorizeHTML(textarea)
161{
162 var config =
163 {
164 //value: "function myScript(){return 100;}\n",
165 mode: { name: "text/typescript", globalVars: true },
166 readOnly: true,
167 };
168
169 CodeMirror.fromTextArea(document.getElementById(textarea), config);
170}
171
172function disableControls(disabled)
173{
174 $('#event').prop('disabled', disabled);
175 $('#pixel').prop('disabled', disabled);
176 $('#cbpx').prop('disabled', disabled);
177 $('#cbpx-c').prop('disabled', disabled);
178 $('#cbpx-b').prop('disabled', disabled);
179 $('#cbpx-p').prop('disabled', disabled);
180 $('#cbpx-x').prop('disabled', disabled);
181 $('#file').prop('disabled', disabled);
182}
183
184function onReady()
185{
186 //$('input,select').keypress(function(event) { return event.keyCode != 13; });
187
188 //colorizeHTML("code0");
189 //colorizeHTML("code1");
190
191 $("#accordion").accordion({collapsible:true,active:false,heightStyle:'content'});
192 $("#accordion").find('h3').filter(':contains(Runtime)').hide();
193 if (location.href.search('debug')==-1)
194 $("#accordion").find('h3').filter(':contains(Debug)').hide();
195
196 $("#textcontainer1").resizable({handles:"s",autoHide:true,});
197 $("#textcontainer1").on("resize", onResize);
198
199 $("#textcontainer2").resizable({handles:"s",autoHide:true,});
200 $("#textcontainer2").on("resize", onResize);
201
202 $("#cameracontainer").on("resize", onResizeCenter);
203 onResizeCenter();
204
205 $("#cont1").click(onClickNew);
206 $("#cont2").click(onClickNew);
207 $("#cont3").click(onClickNew);
208 $("#cont4").click(onClickNew);
209
210 $("#camera1").click(onClick);
211 $("#camera2").click(onClick);
212 $("#camera3").click(onClick);
213 $("#camera4").click(onClick);
214
215 editor1 = createEditor("editor1");
216 editor2 = createEditor("editor2");
217
218 setupAccordion('#accordion5', '#editorcontainer1', true);
219 setupAccordion('#accordion1', '#editorcontainer2');
220
221 $('#accordion5').on("accordionactivate", function() { $('#editorcontainer1fake').hide(); editor1.refresh(); });
222 $('#accordion1').on("accordionactivate", function() { $('#editorcontainer2fake').hide(); editor2.refresh(); });
223
224 setupAccordion('#accordion2', '#cameracontainer');
225 setupAccordion('#accordion3', '#waveformcontainer');
226 setupAccordion('#accordion4', '#helpcontainer', true);
227
228 $("#selectfile1").on('change', onFile);
229 $("#selectfile2").on('change', onFile);
230
231 $(document).ajaxStart(function() { disableControls(true) }).ajaxStop(function() { disableControls(false); });
232
233
234 $.ajax({
235 type: "POST",
236 cache: false,
237 url: "index.php",
238 success: onFilelistReceived,
239 error: function(xhr) { if (xhr.status==0) alert("ERROR[0] - Request failed!"); else alert("ERROR[0] - "+xhr.statusText+" ["+xhr.status+"]"); }
240 });
241}
242
243function onFileSelect(event, ui)
244{
245 onSubmit(ui.item.value);
246}
247
248function onFilelistReceived(result)
249{
250 var dbg = document.getElementById("debug");
251
252 var pre = document.createElement("pre");
253 pre.appendChild(document.createTextNode(rc));
254 dbg.appendChild(pre);
255
256 var rc;
257 try
258 {
259 rc = JSON.parse(result);
260 }
261 catch (e)
262 {
263 alert("ERROR[0] - Decoding answer:\n"+e);
264 return;
265 }
266
267 $("#file").autocomplete({source: rc, select: onFileSelect} );
268 document.getElementById("file").value = "2014/04/17-181";
269
270 onSubmit("2014/04/17-181");
271}
272
273function setZoom(xfrom, xto, yfrom, yto)
274{
275 var xaxis = plot.getXAxes()[0];
276 var yaxis = plot.getYAxes()[0];
277
278 if (xfrom!==undefined)
279 xaxis.options.min = xfrom;
280 if (xto!==undefined)
281 xaxis.options.max = xto;
282
283 if (yfrom!==undefined)
284 yaxis.options.min = yfrom;
285 if (yto!==undefined)
286 yaxis.options.max = yto;
287
288 plot.setupGrid();
289 plot.draw();
290 plot.clearSelection();
291}
292
293function processCameraData(id, data)
294{
295 var canv = document.getElementById(id);
296
297 canv.dataAbs = [ ];
298 for (var i=0; i<1440; i++)
299 if (data[i]!==undefined && data[i]!==null)
300 canv.dataAbs[i] = data[i];
301
302 canv.min = Math.min.apply(Math, canv.dataAbs.filter(function(e){return !isNaN(e)}));
303 canv.max = Math.max.apply(Math, canv.dataAbs.filter(function(e){return !isNaN(e)}));
304
305 canv.dataRel = [ ];
306 for (var i=0; i<1440; i++)
307 if (data[i]!==undefined && data[i]!==null)
308 canv.dataRel[i] = (data[i]-canv.min)/canv.max;
309
310 var n = id[id.length-1];
311
312 if (document.getElementById("cameraminon"+n).checked)
313 document.getElementById("cameramin"+n).value = canv.min;
314 if (document.getElementById("cameramaxon"+n).checked)
315 document.getElementById("cameramax"+n).value = canv.max;
316
317 onCameraMinMax(n);
318}
319
320
321function onDataReceived(rc)
322{
323 var err = document.getElementById("error");
324 var dbg = document.getElementById("debug");
325 var con = document.getElementById("console");
326
327 var pre = document.createElement("pre");
328 pre.appendChild(document.createTextNode(rc));
329 dbg.appendChild(pre);
330
331 try
332 {
333 rc = JSON.parse(rc);
334 }
335 catch (e)
336 {
337 alert("ERROR[1] - Decoding answer:\n"+e);
338 return;
339 }
340
341 document.getElementById("event").max = rc.event.numEvents;
342 var el = document.getElementById("numevents");
343 if (el.firstChild)
344 el.removeChild(el.firstChild);
345 el.appendChild(document.createTextNode(rc.event.numEvents));
346
347 if (rc.ret)
348 {
349 while (con.lastChild)
350 con.removeChild(con.lastChild);
351 }
352
353 if (rc.err)
354 {
355 while (err.lastChild)
356 err.removeChild(err.lastChild);
357
358 err.appendChild(document.createTextNode("Javascript runtime exception: "+rc.err.file+":"+rc.err.lineNumber));
359 err.appendChild(document.createTextNode("\n"));
360 err.appendChild(document.createTextNode(rc.err.sourceLine));
361 err.appendChild(document.createTextNode("\n"));
362 err.appendChild(document.createTextNode(rc.err.trace));
363
364 var editor = rc.err.file=="main" ? editor2 : editor1;
365 editor.setCursor(rc.err.lineNumber-1, 1);
366
367 $("#accordion").find('h3').filter(':contains(Runtime)').show();
368 $("#accordion").accordion("option", "active", 0);
369 }
370
371 var canv = document.getElementById("camera1");
372
373 if (rc.debug!==undefined)
374 {
375 con.appendChild(document.createTextNode(rc.debug));
376
377 debug("return "+JSON.stringify(rc.ret));
378 debug("");
379 debug("Execution times:");
380 debug("TimeJS="+(rc.timeJs*1000).toFixed(2)+"ms");
381 }
382
383 if (rc.ret!==undefined && Array.isArray(rc.ret))
384 {
385 if (!Array.isArray(rc.ret[0]))
386 processCameraData("camera1", rc.ret);
387 else
388 processCameraData("camera1", rc.ret[0]);
389
390 if (rc.ret.length>1)
391 processCameraData("camera2", rc.ret[1]);
392
393 if (rc.ret.length>2)
394 processCameraData("camera3", rc.ret[2]);
395
396 if (rc.ret.length>3)
397 processCameraData("camera4", rc.ret[3]);
398 }
399
400 if (canv.dataAbs && rc.event)
401 document.getElementById("value").value = canv.dataAbs[rc.event.pixel];
402
403 debug("TimePhp="+(rc.timePhp*1000).toFixed(1)+"ms");
404
405 if (Array.isArray(rc.waveform))
406 {
407 var waveform = document.getElementById("waveform");
408
409 var data = [[],[],[],[]];
410
411 var min = [];
412 var max = [];
413 if (Array.isArray(rc.waveform) && rc.waveform.length==rc.event.numRoi)
414 {
415 min.push(Math.min.apply(Math, rc.waveform));
416 max.push(Math.max.apply(Math, rc.waveform));
417
418 for (var i=0; i<rc.event.numRoi; i++)
419 data[0][i] = [ i, rc.waveform[i] ];
420 }
421
422 for (var j=0; j<4; j++)
423 {
424 var ref = rc.waveform[j];
425
426 if (Array.isArray(ref) && ref.length==rc.event.numRoi)
427 {
428 min.push(Math.min.apply(Math, ref));
429 max.push(Math.max.apply(Math, ref));
430
431 for (var i=0; i<rc.event.numRoi; i++)
432 data[j][i] = [ i, ref ];
433
434 }
435 }
436
437 waveform.ymin = Math.min.apply(Math, min);
438 waveform.ymax = Math.max.apply(Math, max);
439 waveform.xmin = 0;
440 waveform.xmax = rc.event.numRoi;
441
442 if (document.getElementById("waveformminon").checked)
443 document.getElementById("waveformmin").value = waveform.ymin;
444 if (document.getElementById("waveformmaxon").checked)
445 document.getElementById("waveformmax").value = waveform.ymax;
446
447 var ymin = document.getElementById("waveformminon").checked ? waveform.ymin : parseInt(document.getElementById("waveformmin").value);
448 var ymax = document.getElementById("waveformmaxon").checked ? waveform.ymax : parseInt(document.getElementById("waveformmax").value);
449
450 var opts =
451 {
452 xaxis: {
453 min: waveform.xmin-1,
454 max: waveform.xmax+1,
455 },
456 yaxis: {
457 min: ymin-5,
458 max: ymax+5,
459 },
460 series: {
461 lines: {
462 show: true
463 },
464 points: {
465 show: true,
466 symbol: 'cross',
467 }
468 },
469 selection: {
470 mode: "xy"
471 },
472 grid: {
473 hoverable: true,
474 }
475 };
476
477 plot = $.plot("#waveform", data, opts);
478
479 waveform = $('#waveform');
480 waveform.bind("plotselected", function (event, ranges)
481 {
482 setZoom(ranges.xaxis.from, ranges.xaxis.to,
483 ranges.yaxis.from, ranges.yaxis.to);
484 });
485
486 waveform.dblclick(function ()
487 {
488 var waveform = document.getElementById("waveform");
489 setZoom(waveform.xmin-1, waveform.xmax+1, waveform.ymin-5, waveform.ymax+5);
490 });
491 waveform.bind("plothover", function (event, pos, item)
492 {
493 if (!item)
494 {
495 $("#tooltip").fadeOut(100);
496 return;
497 }
498
499 var x = item.datapoint[0].toFixed(2);
500 var y = item.datapoint[1].toFixed(2);
501 //item.series.label
502
503 var tooltip = $("#tooltip");
504 tooltip.html(parseInt(x) + " / " + y);
505 tooltip.css({top: item.pageY-20, left: item.pageX+5});
506 tooltip.fadeIn(200);
507 });
508 }
509
510 //$("#accordion").accordion("refresh");
511}
512
513function onSubmit(file, pixelOnly)
514{
515 if (!file)
516 file = document.getElementById("file").value;
517
518 var dbg = document.getElementById("debug");
519 while (dbg.lastChild)
520 dbg.removeChild(dbg.lastChild);
521
522 var active = $("#accordion").accordion("option", "active");
523 if (active==0)
524 {
525 $("#accordion").accordion("option", "active", false);
526 $("#accordion").find('h3').filter(':contains(Runtime)').hide();
527 }
528
529 var event = document.getElementById("event").value;
530 var pixel = document.getElementById("pixel").value;
531 var source1 = editor1.getValue();
532 var source2 = editor2.getValue();
533
534 var uri = "file="+file+"&event="+event+"&pixel="+map[pixel];
535 uri += "&source1="+encodeURIComponent(source1);
536 if (!pixelOnly)
537 uri += "&source2="+encodeURIComponent(source2);
538
539 $.ajax({
540 type: "POST",
541 cache: false,
542 url: "index.php",
543 data: uri,
544 success: onDataReceived,
545 error: function(xhr) { if (xhr.status==0) alert("ERROR[1] - Request failed!"); else alert("ERROR[1] - "+xhr.statusText+" ["+xhr.status+"]"); }
546 });
547}
548
549function onFile(event, ui)
550{
551 var f = event.target.files[0];
552 if (!f)
553 return;
554
555 if (!f.type.match('text/plain') && !f.type.match('application/javascript'))
556 {
557 alert("ERROR - Unknown file type.");
558 return;
559 }
560
561 var id = event.target.id;
562 var editor = id[id.length-1]=='1' ? editor1 : editor2;
563
564 var reader = new FileReader();
565
566 // Closure to capture the file information.
567 reader.onload = (function(theFile) { return function(e) { editor.setValue(e.target.result); }; })(f);
568 // onloadstart
569 // onloadend
570 // onprogress
571
572 // Read in the text file
573 reader.readAsText(f);
574}
575
576function onEvent()
577{
578 onSubmit();
579}
580
581function onPixel()
582{
583 var p = parseInt(document.getElementById("pixel").value);
584
585 var cbpx = map[p];
586
587 document.getElementById("cbpx-c").value = parseInt((cbpx/360));
588 document.getElementById("cbpx-b").value = parseInt((cbpx/36)%10);
589 document.getElementById("cbpx-p").value = parseInt((cbpx/9)%4);
590 document.getElementById("cbpx-x").value = parseInt((cbpx%9));
591 document.getElementById("cbpx").value = parseInt(cbpx);
592
593 onSubmit("", true);
594}
595
596function onCBPX()
597{
598 var c = parseInt(document.getElementById("cbpx-c").value);
599 var b = parseInt(document.getElementById("cbpx-b").value);
600 var p = parseInt(document.getElementById("cbpx-p").value);
601 var x = parseInt(document.getElementById("cbpx-x").value);
602
603 var cbpx = c*360 + b*36 + p*9 + x;
604
605 document.getElementById("cbpx").value = parseInt(cbpx);
606 document.getElementById("pixel").value = map.indexOf(cbpx);
607
608 onSubmit("", true);
609}
610
611function onHW()
612{
613 var cbpx = parseInt(document.getElementById("cbpx").value);;
614
615 document.getElementById("cbpx-c").value = parseInt((cbpx/360));
616 document.getElementById("cbpx-b").value = parseInt((cbpx/36)%10);
617 document.getElementById("cbpx-p").value = parseInt((cbpx/9)%4);
618 document.getElementById("cbpx-x").value = parseInt((cbpx%9));
619
620 document.getElementById("pixel").value = map.indexOf(cbpx);
621
622 onSubmit("", true);
623}
624
625function isInside(x, y, mouse)
626{
627 var dist = Math.sqrt((mouse.x-x)*(mouse.x-x)+(mouse.y-y)*(mouse.y-y));
628 return dist<0.5;
629
630 /*
631 ctx.translate(x, y);
632 ctx.scale(1/2, 1/3);
633
634 ctx.beginPath();
635 ctx.moveTo( 1, 1);
636 ctx.lineTo( 0, 2);
637 ctx.lineTo(-1, 1);
638 ctx.lineTo(-1, -1);
639 ctx.lineTo( 0, -2);
640 ctx.lineTo( 1, -1);
641 ctx.fill();
642
643 ctx.restore();
644 */
645}
646
647function getIndex(id, mouse)
648{
649 var canv = document.getElementById(id);
650
651 var scale = 83;
652
653 var w = Math.min(canv.width/scale, canv.height/scale);
654
655 //ctx.translate(canv.width/2, canv.height/2);
656 //ctx.scale(w*2, w*2);
657 //ctx.scale(1, Math.sqrt(3)/2);
658 //ctx.translate(-0.5, 0);
659
660 mouse.x -= canv.width/2;
661 mouse.y -= canv.height/2;
662 mouse.x /= w*2;
663 mouse.y /= w*2;
664 mouse.y /= Math.sqrt(3)/2;
665 mouse.x -= -0.5;
666
667 if (isInside(0, 0, mouse))
668 return 0;
669
670 var cnt = 1;
671 for (var ring=1; ring<24; ring++)
672 {
673 for (var s=0; s<6; s++)
674 {
675 for (var i=1; i<=ring; i++)
676 {
677 var pos = new Position(s, ring, i);
678 if (pos.d() - pos.x > 395.75)
679 continue;
680
681 if (isInside(pos.x, pos.y, mouse))
682 return cnt;
683 cnt++;
684 }
685 }
686 }
687
688 if (isInside(7, -22, mouse))
689 return 1438;
690 if (isInside(7, 22, mouse))
691 return 1439;
692
693 return -1;
694}
695
696var inprogress = 0;
697function moveAnimate(n, target)
698{
699 if (inprogress==n || inprogress<0)
700 return;
701
702 inprogress = target ? -n : n;
703
704 var element = $("#camera"+n); //Allow passing in either a JQuery object or selector
705 var newParent = $(target ? target : "#cont"+n); //Allow passing in either a JQuery object or selector
706
707 var oldOffset = element.offset();
708
709 var newOffset = newParent.offset();
710
711 var w = newParent.width();
712 var h = newParent.height();
713
714 var temp = element.appendTo('body');
715 temp.css('position', 'absolute')
716 .css('left', oldOffset.left)
717 .css('top', oldOffset.top)
718 .css('zIndex', 400);
719
720 temp.animate( {'top': newOffset.top, 'left':newOffset.left, 'width':w, 'height': h},
721 'slow', function()
722 {
723 temp = temp.appendTo(newParent);
724 temp.css('position', 'default');
725 temp.css('width', 'default');
726 temp.css('height', 'default');
727 temp.css('left', '0');
728 temp.css('top', '0');
729
730 var canv = document.getElementById("camera"+n);
731
732 canv.width = w;
733 canv.height = h;
734
735 drawFullCam("camera"+n);
736
737 inprogress = 0;
738 });
739}
740
741function onClickNew(event)
742{
743 var id = event.target.id;
744 var n = parseInt(id[id.length-1]);
745
746 if (id.substr(0, 3)=="cam")
747 {
748 var cont = document.getElementById("center").childNodes[0];
749 if (cont)
750 {
751 var nn = parseInt(cont.id[cont.id.length-1]);
752 moveAnimate(nn);
753 }
754 moveAnimate(n, "#center");
755
756 }
757 else
758 moveAnimate(n);
759}
760
761function onClick(event)
762{
763 var cont = document.getElementById("center").childNodes[0];
764 if (!cont)
765 return;
766
767 if (cont.id!=event.target.id)
768 return;
769
770 var mouse = getClickPosition();
771 var index = getIndex(event.target.id, mouse);
772
773 if (index<0)
774 return;
775
776 document.getElementById("pixel").value = index;
777
778 onPixel();
779}
780
781function getClickPosition(event)
782{
783 var event = window.event;
784
785 if (event.offsetX !== undefined && event.offsetY !== undefined)
786 return { x: event.offsetX, y: event.offsetY };
787
788 return { x: event.layerX, y: event.layerY };
789}
790
791function onCameraMinMax(n)
792{
793 var canv = document.getElementById("camera"+n);
794
795 canv.zmin = document.getElementById("cameramin"+n).value;
796 canv.zmax = document.getElementById("cameramax"+n).value;
797
798 drawFullCam("camera"+n);
799}
800
801function onCameraMinMaxOn(n)
802{
803 var canv = document.getElementById("camera"+n);
804
805 var redraw;
806 if (document.getElementById("cameraminon"+n).checked)
807 {
808 document.getElementById("cameramin"+n).setAttribute("disabled", "true");
809 document.getElementById("cameramin"+n).value = canv.min;
810 redraw = true;
811 }
812 else
813 document.getElementById("cameramin"+n).removeAttribute("disabled");
814
815 if (document.getElementById("cameramaxon"+n).checked)
816 {
817 document.getElementById("cameramax"+n).setAttribute("disabled", "true");
818 document.getElementById("cameramax"+n).value = canv.max;
819 redraw = true;
820 }
821 else
822 document.getElementById("cameramax"+n).removeAttribute("disabled");
823
824 if (redraw)
825 onCameraMinMax(n);
826}
827
828function onWaveformMinMax()
829{
830 var wf = document.getElementById("waveform");
831
832 var xmin, xmax, ymin, ymax;
833
834 var redraw;
835 if (!document.getElementById("waveformminon").checked)
836 ymin = document.getElementById("waveformmin").value;
837 if (!document.getElementById("waveformmaxon").checked)
838 ymax = document.getElementById("waveformmax").value;
839
840 setZoom(xmin, xmax, ymin, ymax);
841
842}
843
844function onWaveformMinMaxOn()
845{
846 var wf = document.getElementById("waveform");
847
848 var xmin, xmax, ymin, ymax;
849
850 var redraw;
851 if (document.getElementById("waveformminon").checked)
852 {
853 document.getElementById("waveformmin").setAttribute("disabled", "true");
854 document.getElementById("waveformmin").value = wf.ymin;
855 ymin = wf.ymin-5;
856 }
857 else
858 document.getElementById("waveformmin").removeAttribute("disabled");
859
860 if (document.getElementById("waveformmaxon").checked)
861 {
862 document.getElementById("waveformmax").setAttribute("disabled", "true");
863 document.getElementById("waveformmax").value = wf.ymax;
864 ymax = wf.ymax+5;
865 }
866 else
867 document.getElementById("waveformmax").removeAttribute("disabled");
868
869 setZoom(xmin, xmax, ymin, ymax);
870}
871
872//document.addEventListener("click", getClickPosition, false);
873
874$(document).ready(onReady);
875
876// ================================== Pixel mapping =================================================
877
878var 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\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V8T899: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:";
879var map = new Array(1440);
880
881// first: decode the pixel mapping!
882var sum = 1036080;
883for (var i=0; i<1440; i++)
884{
885 var d0 = codedMap.charCodeAt(i*2) -48;
886 var d1 = codedMap.charCodeAt(i*2+1)-48;
887
888 map[i] = d0 | (d1<<6);
889 sum -= map[i];
890}
891if (sum!=0)
892 alert("Pixel mapping table corrupted!");
893
894// ================================== Camera Display ================================================
895
896function hueToRGB(hue)
897{
898 hue /= 3;
899 hue %= 6;
900
901 if (hue<1) return parseInt(255*hue, 10);
902 if (hue<3) return parseInt(255, 10);
903 if (hue<4) return parseInt(255*(4-hue), 10);
904
905 return 0.
906}
907
908function hueToHex(flt)
909{
910 var s = hueToRGB(flt).toString(16);
911 return s.length==2 ? s : "0"+s;
912}
913
914function HLStoRGB(hue)
915{
916 if (isNaN(hue))
917 return "fff";
918
919 if (hue<0)
920 return "eef"; // 555
921
922 if (hue>1)
923 return "700"; // 666
924
925 hue *= 14;
926
927 var sr = hueToHex(20-hue);
928 var sg = hueToHex(14-hue);
929 var sb = hueToHex(26-hue);
930
931 return sr+sg+sb;
932}
933
934function drawHex(ctx, x, y, col, min, max)
935{
936 if (col===undefined || col===null)
937 return;
938
939 var lvl = (col-min)/(max-min);
940
941 ctx.fillStyle = "#"+HLStoRGB(lvl);
942
943 ctx.save();
944
945 ctx.translate(x, y);
946 ctx.scale(1/2, 1/3);
947
948 ctx.beginPath();
949 ctx.moveTo( 1, 1);
950 ctx.lineTo( 0, 2);
951 ctx.lineTo(-1, 1);
952 ctx.lineTo(-1, -1);
953 ctx.lineTo( 0, -2);
954 ctx.lineTo( 1, -1);
955 ctx.fill();
956
957 ctx.restore();
958}
959
960function Position(s, ring, i)
961{
962 switch (s)
963 {
964 case 1: this.x = ring - i*0.5; this.y = + i; break;
965 case 2: this.x = ring*0.5 - i; this.y = ring ; break;
966 case 3: this.x = -ring*0.5 - i*0.5; this.y = ring - i; break;
967 case 4: this.x = -ring + i*0.5; this.y = - i; break;
968 case 5: this.x = -ring*0.5 + i; this.y = -ring ; break;
969 case 0: this.x = ring*0.5 + i*0.5; this.y = -ring + i; break;
970 }
971 this.d = (function () { return this.x*this.x + this.y*this.y*3/4; });
972}
973
974function drawFullCam(id)
975{
976 var canv = document.getElementById(id);
977 if (!canv)
978 return;
979
980 var ctx = canv.getContext("2d");
981
982 ctx.clearRect(0, 0, canv.width, canv.height);
983
984 // ======================= Draw Graphics ======================
985
986 var data = canv.dataRel;
987 if (!data)
988 return;
989
990 var min = (canv.zmin-canv.min)/canv.max;
991 var max = (canv.zmax-canv.min)/canv.max;
992
993 var scale = 83;
994
995 var w = Math.min(canv.width/scale, canv.height/scale);
996
997 ctx.save();
998 ctx.translate(canv.width/2, canv.height/2);
999 ctx.scale(w*2, w*2);
1000 // ctx.rotate(Math.PI/3);
1001
1002 ctx.scale(1, Math.sqrt(3)/2);
1003 ctx.translate(-0.5, 0);
1004
1005 drawHex(ctx, 0, 0, data[map[0]], min, max);
1006
1007 var cnt = 1;
1008 for (var ring=1; ring<24; ring++)
1009 {
1010 for (var s=0; s<6; s++)
1011 {
1012 for (var i=1; i<=ring; i++)
1013 {
1014 var pos = new Position(s, ring, i);
1015 if (pos.d() - pos.x > 395.75)
1016 continue;
1017
1018 drawHex(ctx, pos.x, pos.y, data[map[cnt]], min, max);
1019 cnt++;
1020 }
1021 }
1022 }
1023
1024 drawHex(ctx, 7, -22, data[map[1438]], min, max);
1025 drawHex(ctx, 7, 22, data[map[1439]], min, max);
1026
1027 ctx.restore();
1028
1029 // ======================= Draw Legend ======================
1030
1031 var lmin = parseFloat(canv.min).toFixed(1);
1032 var lmax = parseFloat(canv.max).toFixed(1);
1033
1034 var v0 = parseFloat(canv.zmin);
1035 var v1 = parseFloat(canv.zmax);
1036
1037 var diff = v1-v0;
1038
1039 var cw = canv.width;
1040 //var ch = canv.height;
1041
1042 ctx.font = "8pt Arial";
1043 ctx.textAlign = "right";
1044 ctx.textBaseline = "top";
1045
1046 for (var i=0; i<11; i++)
1047 {
1048 ctx.strokeStyle = "#"+HLStoRGB(i/10);
1049 ctx.strokeText((v0+diff*i/10).toPrecision(3), cw-5, 125-i*12);
1050 }
1051
1052 var mw = Math.max(ctx.measureText(lmin).width,
1053 ctx.measureText(lmax).width);
1054
1055 ctx.textBaseline = "top";
1056 ctx.strokeStyle = "#000";
1057
1058 //ctx.strokeText(min, 5+mw, 5+24);
1059 ctx.strokeText(lmin, 5+mw, 5+12);
1060 ctx.strokeText(lmax, 5+mw, 5);
1061}
1062
Note: See TracBrowser for help on using the repository browser.