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

Last change on this file since 17721 was 17721, checked in by tbretz, 11 years ago
Added missing disable of submit button. Adapted debug output to changes in php.
File size: 30.9 KB
Line 
1'use strict';
2
3var editor1;
4var editor2;
5var plot;
6
7function debug(txt)
8{
9 var dbg = document.getElementById("debug");
10 dbg.appendChild(document.createTextNode(txt));
11 dbg.appendChild(document.createElement("br"));
12}
13
14function setupAccordion(accordion, container, inactive)
15{
16 function onAccordion(event, ui)
17 {
18 if (ui.oldHeader.length==0)
19 $(container).slideDown(400);
20 else
21 $(container).slideUp(400);
22 }
23
24 var config = { collapsible: true };
25
26 if (inactive)
27 {
28 config.active = false;
29 $(container).hide();
30 }
31
32 var acc = $(accordion);
33
34 acc.accordion(config);
35 acc.on("accordionbeforeactivate", onAccordion);
36}
37
38function onResize(event, ui)
39{
40 if (!ui.size)
41 return;
42
43 $(event.target.id).css({marginRight:'2px'});
44
45 var editor = event.target.id=="textcontainer1" ? editor1 : editor2;
46
47 editor.setSize("100%", ui.size.height);
48 editor.refresh();
49}
50
51function onResizeCenter(event, ui)
52{
53 var w = document.getElementById("cameracontainer").clientWidth/4;
54
55 var offy = 0;
56 var offx = 5;
57
58 var cont = document.getElementById("center").childNodes[0];
59
60 var nn;
61 if (cont)
62 {
63 nn = parseInt(cont.id[cont.id.length-1]);
64
65 document.getElementById("camera"+nn).height=parseInt(w*2);
66 document.getElementById("camera"+nn).width=parseInt(w*2);
67 }
68
69 if (nn!=1)
70 {
71 document.getElementById("camera1").height=parseInt(w)-offy;
72 document.getElementById("camera1").width=parseInt(w)-offx;
73 }
74
75 if (nn!=2)
76 {
77 document.getElementById("camera2").height=parseInt(w)-offy;
78 document.getElementById("camera2").width=parseInt(w)-offx;
79 }
80
81 if (nn!=3)
82 {
83 document.getElementById("camera3").height=parseInt(w)-offy;
84 document.getElementById("camera3").width=parseInt(w)-offx;
85 }
86
87 if (nn!=4)
88 {
89 document.getElementById("camera4").height=parseInt(w)-offy;
90 document.getElementById("camera4").width=parseInt(w)-offx;
91 }
92
93 document.getElementById("center").width=parseInt(w*2);
94
95 document.getElementById("cont1").width=parseInt(w);
96 document.getElementById("cont2").width=parseInt(w);
97 document.getElementById("cont3").width=parseInt(w);
98 document.getElementById("cont4").width=parseInt(w);
99
100 document.getElementById("cont1").height=parseInt(w);
101 document.getElementById("cont2").height=parseInt(w);
102 document.getElementById("cont3").height=parseInt(w);
103 document.getElementById("cont4").height=parseInt(w);
104
105 drawFullCam("camera1");
106 drawFullCam("camera2");
107 drawFullCam("camera3");
108 drawFullCam("camera4");
109}
110
111function createEditor(textarea)
112{
113 var editor;
114
115 var config =
116 {
117 //value: "function myScript(){return 100;}\n",
118 mode: { name: "text/typescript", globalVars: true },
119 lineNumbers: true,
120 styleActiveLine: true,
121 matchBrackets: true,
122 indentUnit: 4,
123 foldGutter: true,
124 gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
125 extraKeys: {
126 //"Ctrl-D": "duplicateLine",
127 //"Alt--": "goToBracket",
128 //"Ctrl-H": "findPrev",
129 "Ctrl-Down": "autocomplete",
130 "Tab": "indentAuto",
131 "Ctrl-Y": "deleteLine",
132 "Ctrl-.": function(cm) {
133 cm.foldCode(cm.getCursor());
134 },
135 "F11": function(cm) {
136 editor.setOption("fullScreen", !editor.getOption("fullScreen"));
137 },
138 "Ctrl-R": function(cm) {
139 editor.execCommand("replace");
140 },
141 "Esc": function(cm) {
142 if (editor.getOption("fullScreen")) editor.setOption("fullScreen", false);
143 },
144 "Enter": function(cm) {
145 editor.execCommand("indentAuto");
146 editor.execCommand("newlineAndIndent");
147 },
148 }
149
150 };
151
152 editor = CodeMirror.fromTextArea(document.getElementById(textarea), config);
153 editor.setOption("theme", "blackboard");
154
155 return editor;
156}
157
158function colorizeHTML(textarea)
159{
160 var config =
161 {
162 //value: "function myScript(){return 100;}\n",
163 mode: { name: "text/typescript", globalVars: true },
164 readOnly: true,
165 };
166
167 CodeMirror.fromTextArea(document.getElementById(textarea), config);
168}
169
170function disableControls(disabled)
171{
172 $('#submit').prop('disabled', disabled);
173 $('#event').prop('disabled', disabled);
174 $('#pixel').prop('disabled', disabled);
175 $('#cbpx').prop('disabled', disabled);
176 $('#cbpx-c').prop('disabled', disabled);
177 $('#cbpx-b').prop('disabled', disabled);
178 $('#cbpx-p').prop('disabled', disabled);
179 $('#cbpx-x').prop('disabled', disabled);
180 $('#file').prop('disabled', disabled);
181}
182
183function onReady()
184{
185 //$('input,select').keypress(function(event) { return event.keyCode != 13; });
186
187 //colorizeHTML("code0");
188 //colorizeHTML("code1");
189
190 $("#accordion").accordion({collapsible:true,active:false,heightStyle:'content'});
191 $("#accordion").find('h3').filter(':contains(Runtime)').hide();
192 if (location.href.search('debug')==-1)
193 $("#accordion").find('h3').filter(':contains(Debug)').hide();
194
195 $("#textcontainer1").resizable({handles:"s",autoHide:true,});
196 $("#textcontainer1").on("resize", onResize);
197
198 $("#textcontainer2").resizable({handles:"s",autoHide:true,});
199 $("#textcontainer2").on("resize", onResize);
200
201 $("#cameracontainer").on("resize", onResizeCenter);
202 onResizeCenter();
203
204 $("#cont1").click(onClickNew);
205 $("#cont2").click(onClickNew);
206 $("#cont3").click(onClickNew);
207 $("#cont4").click(onClickNew);
208
209 $("#camera1").click(onClick);
210 $("#camera2").click(onClick);
211 $("#camera3").click(onClick);
212 $("#camera4").click(onClick);
213
214 editor1 = createEditor("editor1");
215 editor2 = createEditor("editor2");
216
217 setupAccordion('#accordion5', '#editorcontainer1', true);
218 setupAccordion('#accordion1', '#editorcontainer2');
219
220 $('#accordion5').on("accordionactivate", function() { $('#editorcontainer1fake').hide(); editor1.refresh(); });
221 $('#accordion1').on("accordionactivate", function() { $('#editorcontainer2fake').hide(); editor2.refresh(); });
222
223 setupAccordion('#accordion2', '#cameracontainer');
224 setupAccordion('#accordion3', '#waveformcontainer');
225 setupAccordion('#accordion4', '#helpcontainer', true);
226
227 $("#selectfile1").on('change', onFile);
228 $("#selectfile2").on('change', onFile);
229
230 $(document).ajaxStart(function() { disableControls(true) }).ajaxStop(function() { disableControls(false); });
231
232
233 $.ajax({
234 type: "POST",
235 cache: false,
236 url: "index.php",
237 success: onFilelistReceived,
238 error: function(xhr) { if (xhr.status==0) alert("ERROR[0] - Request failed!"); else alert("ERROR[0] - "+xhr.statusText+" ["+xhr.status+"]"); }
239 });
240}
241
242function onFileSelect(event, ui)
243{
244 onSubmit(ui.item.value);
245}
246
247function onFilelistReceived(result)
248{
249 var dbg = document.getElementById("debug");
250
251 var pre = document.createElement("pre");
252 pre.appendChild(document.createTextNode(rc));
253 dbg.appendChild(pre);
254
255 var rc;
256 try
257 {
258 rc = JSON.parse(result);
259 }
260 catch (e)
261 {
262 alert("ERROR[0] - Decoding answer:\n"+e);
263 return;
264 }
265
266 $("#file").autocomplete({source: rc, select: onFileSelect} );
267 document.getElementById("file").value = "2014/04/17-181";
268
269 onSubmit("2014/04/17-181");
270}
271
272function setZoom(xfrom, xto, yfrom, yto)
273{
274 var xaxis = plot.getXAxes()[0];
275 var yaxis = plot.getYAxes()[0];
276
277 if (xfrom!==undefined)
278 xaxis.options.min = xfrom;
279 if (xto!==undefined)
280 xaxis.options.max = xto;
281
282 if (yfrom!==undefined)
283 yaxis.options.min = yfrom;
284 if (yto!==undefined)
285 yaxis.options.max = yto;
286
287 plot.setupGrid();
288 plot.draw();
289 plot.clearSelection();
290}
291
292function processCameraData(id, data)
293{
294 var canv = document.getElementById(id);
295
296 canv.dataAbs = [ ];
297 for (var i=0; i<1440; i++)
298 if (data[i]!==undefined && data[i]!==null)
299 canv.dataAbs[i] = data[i];
300
301 canv.min = Math.min.apply(Math, canv.dataAbs.filter(function(e){return !isNaN(e)}));
302 canv.max = Math.max.apply(Math, canv.dataAbs.filter(function(e){return !isNaN(e)}));
303
304 canv.dataRel = [ ];
305 for (var i=0; i<1440; i++)
306 if (data[i]!==undefined && data[i]!==null)
307 canv.dataRel[i] = (data[i]-canv.min)/canv.max;
308
309 var n = id[id.length-1];
310
311 if (document.getElementById("cameraminon"+n).checked)
312 document.getElementById("cameramin"+n).value = canv.min;
313 if (document.getElementById("cameramaxon"+n).checked)
314 document.getElementById("cameramax"+n).value = canv.max;
315
316 onCameraMinMax(n);
317}
318
319
320function onDataReceived(rc)
321{
322 var err = document.getElementById("error");
323 var dbg = document.getElementById("debug");
324 var con = document.getElementById("console");
325
326 var pre = document.createElement("pre");
327 pre.appendChild(document.createTextNode(rc));
328 dbg.appendChild(pre);
329
330 try
331 {
332 rc = JSON.parse(rc);
333 }
334 catch (e)
335 {
336 alert("ERROR[1] - Decoding answer:\n"+e);
337 return;
338 }
339
340 document.getElementById("event").max = rc.event.numEvents;
341 var el = document.getElementById("numevents");
342 if (el.firstChild)
343 el.removeChild(el.firstChild);
344 el.appendChild(document.createTextNode(rc.event.numEvents));
345
346 if (rc.ret)
347 {
348 while (con.lastChild)
349 con.removeChild(con.lastChild);
350 }
351
352 if (rc.err)
353 {
354 while (err.lastChild)
355 err.removeChild(err.lastChild);
356
357 err.appendChild(document.createTextNode("Javascript runtime exception: "+rc.err.file+":"+rc.err.lineNumber));
358 err.appendChild(document.createTextNode("\n"));
359 err.appendChild(document.createTextNode(rc.err.sourceLine));
360 err.appendChild(document.createTextNode("\n"));
361 err.appendChild(document.createTextNode(rc.err.trace));
362
363 var editor = rc.err.file=="main" ? editor2 : editor1;
364 editor.setCursor(rc.err.lineNumber-1, 1);
365
366 $("#accordion").find('h3').filter(':contains(Runtime)').show();
367 $("#accordion").accordion("option", "active", 0);
368 }
369
370 var canv = document.getElementById("camera1");
371
372 if (rc.debug!==undefined)
373 {
374 con.appendChild(document.createTextNode(rc.debug));
375
376 debug("return "+JSON.stringify(rc.ret));
377 debug("");
378 debug("Execution times:");
379 debug("Time Javascripts = "+(rc.timeJs[0]*1000).toFixed(2)+","+(rc.timeJs[1]*1000).toFixed(2)+","+(rc.timeJs[2]*1000).toFixed(2)+ " [ms]");
380 }
381
382 if (rc.ret!==undefined && Array.isArray(rc.ret))
383 {
384 if (!Array.isArray(rc.ret[0]))
385 processCameraData("camera1", rc.ret);
386 else
387 processCameraData("camera1", rc.ret[0]);
388
389 if (rc.ret.length>1)
390 processCameraData("camera2", rc.ret[1]);
391
392 if (rc.ret.length>2)
393 processCameraData("camera3", rc.ret[2]);
394
395 if (rc.ret.length>3)
396 processCameraData("camera4", rc.ret[3]);
397 }
398
399 if (canv.dataAbs && rc.event)
400 document.getElementById("value").value = canv.dataAbs[rc.event.pixel];
401
402 debug("Total time = "+(rc.timePhp*1000).toFixed(1)+" ms");
403 debug("Peak memory = "+rc.memory+" MiB");
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[i] ];
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 // get click position relative to canvas
771 var rect = event.target.getBoundingClientRect();
772
773 var x = event.clientX - rect.left;
774 var y = event.clientY - rect.top;
775
776 var mouse = { x: x, y: y };
777
778 // convert click position to pixel index
779 var index = getIndex(event.target.id, mouse);
780 if (index<0)
781 return;
782
783 document.getElementById("pixel").value = index;
784
785 onPixel();
786}
787
788function getClickPosition(event)
789{
790 var rect = event.target.getBoundingClientRect();
791
792 var x = event.clientX - rect.left;
793 var y = event.clientY - rect.top;
794
795 return { x: x, y: y };
796}
797
798function onCameraMinMax(n)
799{
800 var canv = document.getElementById("camera"+n);
801
802 canv.zmin = document.getElementById("cameramin"+n).value;
803 canv.zmax = document.getElementById("cameramax"+n).value;
804
805 drawFullCam("camera"+n);
806}
807
808function onCameraMinMaxOn(n)
809{
810 var canv = document.getElementById("camera"+n);
811
812 var redraw;
813 if (document.getElementById("cameraminon"+n).checked)
814 {
815 document.getElementById("cameramin"+n).setAttribute("disabled", "true");
816 document.getElementById("cameramin"+n).value = canv.min;
817 redraw = true;
818 }
819 else
820 document.getElementById("cameramin"+n).removeAttribute("disabled");
821
822 if (document.getElementById("cameramaxon"+n).checked)
823 {
824 document.getElementById("cameramax"+n).setAttribute("disabled", "true");
825 document.getElementById("cameramax"+n).value = canv.max;
826 redraw = true;
827 }
828 else
829 document.getElementById("cameramax"+n).removeAttribute("disabled");
830
831 if (redraw)
832 onCameraMinMax(n);
833}
834
835function onWaveformMinMax()
836{
837 var wf = document.getElementById("waveform");
838
839 var xmin, xmax, ymin, ymax;
840
841 var redraw;
842 if (!document.getElementById("waveformminon").checked)
843 ymin = document.getElementById("waveformmin").value;
844 if (!document.getElementById("waveformmaxon").checked)
845 ymax = document.getElementById("waveformmax").value;
846
847 setZoom(xmin, xmax, ymin, ymax);
848
849}
850
851function onWaveformMinMaxOn()
852{
853 var wf = document.getElementById("waveform");
854
855 var xmin, xmax, ymin, ymax;
856
857 var redraw;
858 if (document.getElementById("waveformminon").checked)
859 {
860 document.getElementById("waveformmin").setAttribute("disabled", "true");
861 document.getElementById("waveformmin").value = wf.ymin;
862 ymin = wf.ymin-5;
863 }
864 else
865 document.getElementById("waveformmin").removeAttribute("disabled");
866
867 if (document.getElementById("waveformmaxon").checked)
868 {
869 document.getElementById("waveformmax").setAttribute("disabled", "true");
870 document.getElementById("waveformmax").value = wf.ymax;
871 ymax = wf.ymax+5;
872 }
873 else
874 document.getElementById("waveformmax").removeAttribute("disabled");
875
876 setZoom(xmin, xmax, ymin, ymax);
877}
878
879//document.addEventListener("click", getClickPosition, false);
880
881$(document).ready(onReady);
882
883// ================================== Pixel mapping =================================================
884
885var codedMap = "966676:6:A;68656364626Y?\\?;A=A<AGADAN4K4i5g5h5o506W?Z?]?_?>A@A?AJAIAFACAM4J4H4f5d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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:";
886var map = new Array(1440);
887
888// first: decode the pixel mapping!
889var sum = 1036080;
890for (var i=0; i<1440; i++)
891{
892 var d0 = codedMap.charCodeAt(i*2) -48;
893 var d1 = codedMap.charCodeAt(i*2+1)-48;
894
895 map[i] = d0 | (d1<<6);
896 sum -= map[i];
897}
898if (sum!=0)
899 alert("Pixel mapping table corrupted!");
900
901// ================================== Camera Display ================================================
902
903function hueToRGB(hue)
904{
905 hue /= 3;
906 hue %= 6;
907
908 if (hue<1) return parseInt(255*hue, 10);
909 if (hue<3) return parseInt(255, 10);
910 if (hue<4) return parseInt(255*(4-hue), 10);
911
912 return 0.
913}
914
915function hueToHex(flt)
916{
917 var s = hueToRGB(flt).toString(16);
918 return s.length==2 ? s : "0"+s;
919}
920
921function HLStoRGB(hue)
922{
923 if (isNaN(hue))
924 return "fff";
925
926 if (hue<0)
927 return "eef"; // 555
928
929 if (hue>1)
930 return "700"; // 666
931
932 hue *= 14;
933
934 var sr = hueToHex(20-hue);
935 var sg = hueToHex(14-hue);
936 var sb = hueToHex(26-hue);
937
938 return sr+sg+sb;
939}
940
941function drawHex(ctx, x, y, col, min, max)
942{
943 if (col===undefined || col===null)
944 return;
945
946 var lvl = (col-min)/(max-min);
947
948 ctx.fillStyle = "#"+HLStoRGB(lvl);
949
950 ctx.save();
951
952 ctx.translate(x, y);
953 ctx.scale(1/2, 1/3);
954
955 ctx.beginPath();
956 ctx.moveTo( 1, 1);
957 ctx.lineTo( 0, 2);
958 ctx.lineTo(-1, 1);
959 ctx.lineTo(-1, -1);
960 ctx.lineTo( 0, -2);
961 ctx.lineTo( 1, -1);
962 ctx.fill();
963
964 ctx.restore();
965}
966
967function Position(s, ring, i)
968{
969 switch (s)
970 {
971 case 1: this.x = ring - i*0.5; this.y = + i; break;
972 case 2: this.x = ring*0.5 - i; this.y = ring ; break;
973 case 3: this.x = -ring*0.5 - i*0.5; this.y = ring - i; break;
974 case 4: this.x = -ring + i*0.5; this.y = - i; break;
975 case 5: this.x = -ring*0.5 + i; this.y = -ring ; break;
976 case 0: this.x = ring*0.5 + i*0.5; this.y = -ring + i; break;
977 }
978 this.d = (function () { return this.x*this.x + this.y*this.y*3/4; });
979}
980
981function drawFullCam(id)
982{
983 var canv = document.getElementById(id);
984 if (!canv)
985 return;
986
987 var ctx = canv.getContext("2d");
988
989 ctx.clearRect(0, 0, canv.width, canv.height);
990
991 // ======================= Draw Graphics ======================
992
993 var data = canv.dataRel;
994 if (!data)
995 return;
996
997 var min = (canv.zmin-canv.min)/canv.max;
998 var max = (canv.zmax-canv.min)/canv.max;
999
1000 var scale = 83;
1001
1002 var w = Math.min(canv.width/scale, canv.height/scale);
1003
1004 ctx.save();
1005 ctx.translate(canv.width/2, canv.height/2);
1006 ctx.scale(w*2, w*2);
1007 // ctx.rotate(Math.PI/3);
1008
1009 ctx.scale(1, Math.sqrt(3)/2);
1010 ctx.translate(-0.5, 0);
1011
1012 drawHex(ctx, 0, 0, data[map[0]], min, max);
1013
1014 var cnt = 1;
1015 for (var ring=1; ring<24; ring++)
1016 {
1017 for (var s=0; s<6; s++)
1018 {
1019 for (var i=1; i<=ring; i++)
1020 {
1021 var pos = new Position(s, ring, i);
1022 if (pos.d() - pos.x > 395.75)
1023 continue;
1024
1025 drawHex(ctx, pos.x, pos.y, data[map[cnt]], min, max);
1026 cnt++;
1027 }
1028 }
1029 }
1030
1031 drawHex(ctx, 7, -22, data[map[1438]], min, max);
1032 drawHex(ctx, 7, 22, data[map[1439]], min, max);
1033
1034 ctx.restore();
1035
1036 // ======================= Draw Legend ======================
1037
1038 var lmin = parseFloat(canv.min).toFixed(1);
1039 var lmax = parseFloat(canv.max).toFixed(1);
1040
1041 var v0 = parseFloat(canv.zmin);
1042 var v1 = parseFloat(canv.zmax);
1043
1044 var diff = v1-v0;
1045
1046 var cw = canv.width;
1047 //var ch = canv.height;
1048
1049 ctx.font = "8pt Arial";
1050 ctx.textAlign = "right";
1051 ctx.textBaseline = "top";
1052
1053 for (var i=0; i<11; i++)
1054 {
1055 ctx.strokeStyle = "#"+HLStoRGB(i/10);
1056 ctx.strokeText((v0+diff*i/10).toPrecision(3), cw-5, 125-i*12);
1057 }
1058
1059 var mw = Math.max(ctx.measureText(lmin).width,
1060 ctx.measureText(lmax).width);
1061
1062 ctx.textBaseline = "top";
1063 ctx.strokeStyle = "#000";
1064
1065 //ctx.strokeText(min, 5+mw, 5+24);
1066 ctx.strokeText(lmin, 5+mw, 5+12);
1067 ctx.strokeText(lmax, 5+mw, 5);
1068}
1069
Note: See TracBrowser for help on using the repository browser.