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