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