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 | canv.dataRel = null;
|
---|
464 |
|
---|
465 | if (!Array.isArray(data))
|
---|
466 | return;
|
---|
467 |
|
---|
468 | canv.dataAbs = new Array(1440);
|
---|
469 | for (var i=0; i<1440; i++)
|
---|
470 | {
|
---|
471 | var val = data[map[i]];
|
---|
472 | if (!isNaN(val) && val!==null)
|
---|
473 | canv.dataAbs[i] = val;
|
---|
474 | }
|
---|
475 |
|
---|
476 | canv.min = Math.min.apply(Math, canv.dataAbs.filter(function(e){return e!==undefined;}));
|
---|
477 | canv.max = Math.max.apply(Math, canv.dataAbs.filter(function(e){return e!==undefined;}));
|
---|
478 |
|
---|
479 | canv.dataRel = new Array(1440);
|
---|
480 | for (var i=0; i<1440; i++)
|
---|
481 | {
|
---|
482 | var val = canv.dataAbs[i];
|
---|
483 | if (val!==undefined)
|
---|
484 | canv.dataRel[i] = (val-canv.min)/canv.max;
|
---|
485 | }
|
---|
486 |
|
---|
487 | if (document.getElementById("cameraminon"+n).checked)
|
---|
488 | document.getElementById("cameramin"+n).value = canv.min;
|
---|
489 | if (document.getElementById("cameramaxon"+n).checked)
|
---|
490 | document.getElementById("cameramax"+n).value = canv.max;
|
---|
491 |
|
---|
492 | // ---------------------------
|
---|
493 |
|
---|
494 | var hist = document.getElementById("hist"+n);
|
---|
495 |
|
---|
496 | hist.min = canv.min;
|
---|
497 | hist.max = canv.max;
|
---|
498 |
|
---|
499 | if (document.getElementById("histminon"+n).checked)
|
---|
500 | document.getElementById("histmin"+n).value = canv.min;
|
---|
501 | if (document.getElementById("histmaxon"+n).checked)
|
---|
502 | document.getElementById("histmax"+n).value = canv.max;
|
---|
503 |
|
---|
504 | drawHist(n);
|
---|
505 | }
|
---|
506 |
|
---|
507 | function onDataReceived(rc)
|
---|
508 | {
|
---|
509 | var err = document.getElementById("error");
|
---|
510 | var dbg = document.getElementById("debug");
|
---|
511 | var con = document.getElementById("console");
|
---|
512 |
|
---|
513 | //var pre = document.createElement("pre");
|
---|
514 | //pre.appendChild(document.createTextNode(rc));
|
---|
515 | //dbg.appendChild(pre);
|
---|
516 |
|
---|
517 | try
|
---|
518 | {
|
---|
519 | rc = JSON.parse(rc);
|
---|
520 | if (!rc)
|
---|
521 | return;
|
---|
522 | }
|
---|
523 | catch (e)
|
---|
524 | {
|
---|
525 | alert("ERROR[1] - Decoding answer:\n"+e);
|
---|
526 | return;
|
---|
527 | }
|
---|
528 |
|
---|
529 | var evt = rc.event;
|
---|
530 | var file = rc.file;
|
---|
531 |
|
---|
532 | document.getElementById("event").max = file.numEvents;
|
---|
533 | var el = document.getElementById("numevents");
|
---|
534 | if (el.firstChild)
|
---|
535 | el.removeChild(el.firstChild);
|
---|
536 | el.appendChild(document.createTextNode(file.numEvents));
|
---|
537 |
|
---|
538 | var infotxt = "<pre>";
|
---|
539 | infotxt += "\nStart time: "+new Date(file.runStart*24*3600*1000).toUTCString();
|
---|
540 | infotxt += "\nEnd time: "+new Date(file.runEnd*24*3600*1000).toUTCString();
|
---|
541 | infotxt += "\nRun type: "+file.runType;
|
---|
542 | if (file.drsFile>=0)
|
---|
543 | infotxt += " [drs-step "+file.drsFile+"]";
|
---|
544 |
|
---|
545 | $("#runinfo").html(infotxt);
|
---|
546 | $("#eventinfo").html("Trigger: "+evt.trigger.join(' | ')+" [0x"+evt.triggerType.toString(16)+"]");
|
---|
547 |
|
---|
548 | if (rc.ret)
|
---|
549 | {
|
---|
550 | while (con.lastChild)
|
---|
551 | con.removeChild(con.lastChild);
|
---|
552 | }
|
---|
553 |
|
---|
554 | if (rc.err)
|
---|
555 | {
|
---|
556 | while (err.lastChild)
|
---|
557 | err.removeChild(err.lastChild);
|
---|
558 |
|
---|
559 | err.appendChild(document.createTextNode("Javascript runtime exception: "+rc.err.file+":"+rc.err.lineNumber));
|
---|
560 | err.appendChild(document.createTextNode("\n"));
|
---|
561 | err.appendChild(document.createTextNode(rc.err.sourceLine));
|
---|
562 | err.appendChild(document.createTextNode("\n"));
|
---|
563 | err.appendChild(document.createTextNode(rc.err.trace));
|
---|
564 |
|
---|
565 | var editor = rc.err.file=="main" ? editor2 : editor1;
|
---|
566 | editor.setCursor(rc.err.lineNumber-1, 1);
|
---|
567 |
|
---|
568 | $("#accordion").find('h3').filter(':contains(Runtime)').show();
|
---|
569 | $("#accordion").accordion("option", "active", 0);
|
---|
570 | }
|
---|
571 |
|
---|
572 | if (rc.debug!==undefined)
|
---|
573 | {
|
---|
574 | con.appendChild(document.createTextNode(rc.debug));
|
---|
575 |
|
---|
576 | debug("PHP execution:");
|
---|
577 | debug("Time Javascripts = "+(rc.timeJs[0]*1000).toFixed(2)+","+(rc.timeJs[1]*1000).toFixed(2)+","+(rc.timeJs[2]*1000).toFixed(2)+ " [ms]");
|
---|
578 | }
|
---|
579 |
|
---|
580 | if (rc.ret!==undefined && Array.isArray(rc.ret))
|
---|
581 | {
|
---|
582 | var now = new Date();
|
---|
583 |
|
---|
584 | if (rc.ret[0] instanceof Object)
|
---|
585 | processCameraData(1, rc.ret[0]);
|
---|
586 | else
|
---|
587 | processCameraData(1, rc.ret);
|
---|
588 |
|
---|
589 | if (rc.ret.length>1)
|
---|
590 | processCameraData(2, rc.ret[1]);
|
---|
591 |
|
---|
592 | if (rc.ret.length>2)
|
---|
593 | processCameraData(3, rc.ret[2]);
|
---|
594 |
|
---|
595 | if (rc.ret.length>3)
|
---|
596 | processCameraData(4, rc.ret[3]);
|
---|
597 |
|
---|
598 | debug("Calc Time = "+(new Date()-now)+" ms");
|
---|
599 | }
|
---|
600 |
|
---|
601 | // We have to redraw all of them to display the changed pixel value
|
---|
602 | onCameraMinMax(1);
|
---|
603 | onCameraMinMax(2);
|
---|
604 | onCameraMinMax(3);
|
---|
605 | onCameraMinMax(4);
|
---|
606 |
|
---|
607 | debug("Total time = "+(rc.timePhp*1000).toFixed(1)+" ms");
|
---|
608 | debug("Peak memory = "+rc.memory+" MiB");
|
---|
609 |
|
---|
610 | if (Array.isArray(rc.waveform))
|
---|
611 | {
|
---|
612 | var waveform = document.getElementById("waveform");
|
---|
613 | waveform.data = [ ];
|
---|
614 |
|
---|
615 | var data = [
|
---|
616 | { label: "[0] ", data: new Array(evt.numRoi) },
|
---|
617 | { label: "[1] ", data: new Array(evt.numRoi) },
|
---|
618 | { label: "[2] ", data: new Array(evt.numRoi) },
|
---|
619 | { label: "[3] ", data: new Array(evt.numRoi) },
|
---|
620 | ];
|
---|
621 |
|
---|
622 | var min = [];
|
---|
623 | var max = [];
|
---|
624 | if (Array.isArray(rc.waveform) && rc.waveform.length==evt.numRoi)
|
---|
625 | {
|
---|
626 | min.push(Math.min.apply(Math, rc.waveform));
|
---|
627 | max.push(Math.max.apply(Math, rc.waveform));
|
---|
628 |
|
---|
629 | var d = data[0].data;
|
---|
630 | for (var i=0; i<evt.numRoi; i++)
|
---|
631 | d[i] = [ i, rc.waveform[i] ];
|
---|
632 |
|
---|
633 | waveform.data[0] = rc.waveform;
|
---|
634 | }
|
---|
635 |
|
---|
636 | for (var j=0; j<4; j++)
|
---|
637 | {
|
---|
638 | var ref = rc.waveform[j];
|
---|
639 |
|
---|
640 | if (Array.isArray(ref) && ref.length==evt.numRoi)
|
---|
641 | {
|
---|
642 | min.push(Math.min.apply(Math, ref));
|
---|
643 | max.push(Math.max.apply(Math, ref));
|
---|
644 |
|
---|
645 | var d = data[j].data;
|
---|
646 | for (var i=0; i<evt.numRoi; i++)
|
---|
647 | d[i] = [ i, ref[i] ];
|
---|
648 |
|
---|
649 | waveform.data[j] = ref;
|
---|
650 | }
|
---|
651 | }
|
---|
652 |
|
---|
653 | waveform.ymin = Math.min.apply(Math, min);
|
---|
654 | waveform.ymax = Math.max.apply(Math, max);
|
---|
655 | waveform.xmin = 0;
|
---|
656 | waveform.xmax = evt.numRoi;
|
---|
657 |
|
---|
658 | if (document.getElementById("waveformxminon").checked)
|
---|
659 | document.getElementById("waveformxmin").value = waveform.xmin;
|
---|
660 | if (document.getElementById("waveformxmaxon").checked)
|
---|
661 | document.getElementById("waveformxmax").value = waveform.xmax;
|
---|
662 |
|
---|
663 | if (document.getElementById("waveformminon").checked)
|
---|
664 | document.getElementById("waveformmin").value = waveform.ymin;
|
---|
665 | if (document.getElementById("waveformmaxon").checked)
|
---|
666 | document.getElementById("waveformmax").value = waveform.ymax;
|
---|
667 |
|
---|
668 | var xmin = document.getElementById("waveformxminon").checked ? waveform.xmin : parseInt(document.getElementById("waveformxmin").value);
|
---|
669 | var xmax = document.getElementById("waveformxmaxon").checked ? waveform.xmax : parseInt(document.getElementById("waveformxmax").value);
|
---|
670 |
|
---|
671 | var ymin = document.getElementById("waveformminon").checked ? waveform.ymin : parseInt(document.getElementById("waveformmin").value);
|
---|
672 | var ymax = document.getElementById("waveformmaxon").checked ? waveform.ymax : parseInt(document.getElementById("waveformmax").value);
|
---|
673 |
|
---|
674 | var opts =
|
---|
675 | {
|
---|
676 | xaxis: {
|
---|
677 | min: xmin-1,
|
---|
678 | max: xmax+1,
|
---|
679 | },
|
---|
680 | yaxis: {
|
---|
681 | min: ymin-5,
|
---|
682 | max: ymax+5,
|
---|
683 | },
|
---|
684 | series: {
|
---|
685 | lines: {
|
---|
686 | show: true
|
---|
687 | },
|
---|
688 | points: {
|
---|
689 | show: true,
|
---|
690 | symbol: 'cross',
|
---|
691 | }
|
---|
692 | },
|
---|
693 | selection: {
|
---|
694 | mode: "xy"
|
---|
695 | },
|
---|
696 | grid: {
|
---|
697 | hoverable: true,
|
---|
698 | }
|
---|
699 | };
|
---|
700 |
|
---|
701 | plot = $.plot("#waveform", data, opts);
|
---|
702 |
|
---|
703 | waveform = $('#waveform');
|
---|
704 | waveform.bind("plotselected", function (event, ranges)
|
---|
705 | {
|
---|
706 | setZoom(ranges.xaxis.from, ranges.xaxis.to,
|
---|
707 | ranges.yaxis.from, ranges.yaxis.to);
|
---|
708 | });
|
---|
709 |
|
---|
710 | waveform.dblclick(function ()
|
---|
711 | {
|
---|
712 | var waveform = document.getElementById("waveform");
|
---|
713 | setZoom(waveform.xmin-1, waveform.xmax+1, waveform.ymin-5, waveform.ymax+5);
|
---|
714 | });
|
---|
715 | waveform.bind("plothover", onPlotHover);
|
---|
716 | }
|
---|
717 | }
|
---|
718 |
|
---|
719 | function onSubmit(file, pixelOnly)
|
---|
720 | {
|
---|
721 | if (!file)
|
---|
722 | file = document.getElementById("file").value;
|
---|
723 |
|
---|
724 | var dbg = document.getElementById("debug");
|
---|
725 | while (dbg.lastChild)
|
---|
726 | dbg.removeChild(dbg.lastChild);
|
---|
727 |
|
---|
728 | var active = $("#accordion").accordion("option", "active");
|
---|
729 | if (active==0)
|
---|
730 | {
|
---|
731 | $("#accordion").accordion("option", "active", false);
|
---|
732 | $("#accordion").find('h3').filter(':contains(Runtime)').hide();
|
---|
733 | }
|
---|
734 |
|
---|
735 | var calibrated = document.getElementById("calibrated");
|
---|
736 | var calib = !calibrated.disabled && calibrated.checked;
|
---|
737 | var event = document.getElementById("event").value;
|
---|
738 | var pixel = document.getElementById("pixel").value;
|
---|
739 | var source1 = editor1.getValue();
|
---|
740 | var source2 = editor2.getValue();
|
---|
741 |
|
---|
742 | var uri = "file="+file+"&event="+event+"&pixel="+map[pixel];
|
---|
743 | uri += "&source1="+encodeURIComponent(source1);
|
---|
744 | if (!pixelOnly)
|
---|
745 | uri += "&source2="+encodeURIComponent(source2);
|
---|
746 | if (calib)
|
---|
747 | uri += "&calibrated=1";
|
---|
748 |
|
---|
749 | $.ajax({
|
---|
750 | type: "POST",
|
---|
751 | cache: false,
|
---|
752 | url: "index.php",
|
---|
753 | data: uri,
|
---|
754 | success: onDataReceived,
|
---|
755 | error: function(xhr) { if (xhr.status==0) alert("ERROR[1] - Request failed!"); else alert("ERROR[1] - "+xhr.statusText+" ["+xhr.status+"]"); }
|
---|
756 | });
|
---|
757 | }
|
---|
758 |
|
---|
759 | function onFile(event, ui)
|
---|
760 | {
|
---|
761 | var f = event.target.files[0];
|
---|
762 | if (!f)
|
---|
763 | return;
|
---|
764 |
|
---|
765 | if (!f.type.match('text/plain') && !f.type.match('application/javascript'))
|
---|
766 | {
|
---|
767 | alert("ERROR - Unknown file type.");
|
---|
768 | return;
|
---|
769 | }
|
---|
770 |
|
---|
771 | var id = event.target.id;
|
---|
772 | var editor = id[id.length-1]=='1' ? editor1 : editor2;
|
---|
773 |
|
---|
774 | var reader = new FileReader();
|
---|
775 |
|
---|
776 | // Closure to capture the file information.
|
---|
777 | reader.onload = (function(theFile) { return function(e) { editor.setValue(e.target.result); }; })(f);
|
---|
778 | // onloadstart
|
---|
779 | // onloadend
|
---|
780 | // onprogress
|
---|
781 |
|
---|
782 | // Read in the text file
|
---|
783 | reader.readAsText(f);
|
---|
784 | }
|
---|
785 |
|
---|
786 | function refreshCameras()
|
---|
787 | {
|
---|
788 | drawFullCam("camera1");
|
---|
789 | drawFullCam("camera2");
|
---|
790 | drawFullCam("camera3");
|
---|
791 | drawFullCam("camera4");
|
---|
792 | }
|
---|
793 |
|
---|
794 | function onEvent()
|
---|
795 | {
|
---|
796 | onSubmit();
|
---|
797 | }
|
---|
798 |
|
---|
799 | function checkPixel()
|
---|
800 | {
|
---|
801 | var pix = parseInt(document.getElementById("pixel").value);
|
---|
802 | var c = parseInt(document.getElementById("cbpx-c").value);
|
---|
803 | var b = parseInt(document.getElementById("cbpx-b").value);
|
---|
804 | var p = parseInt(document.getElementById("cbpx-p").value);
|
---|
805 | var x = parseInt(document.getElementById("cbpx-x").value);
|
---|
806 | var cbpx = parseInt(document.getElementById("cbpx").value);;
|
---|
807 |
|
---|
808 | if (pix >=0 && pix <1440 &&
|
---|
809 | c >=0 && c < 4 &&
|
---|
810 | b >=0 && b < 10 &&
|
---|
811 | p >=0 && p < 4 &&
|
---|
812 | x >=0 && x < 9 &&
|
---|
813 | cbpx>=0 && cbpx<1440)
|
---|
814 | return;
|
---|
815 |
|
---|
816 | document.getElementById("pixel").value = 0;
|
---|
817 | document.getElementById("cbpx-c").value = 1;
|
---|
818 | document.getElementById("cbpx-b").value = 0;
|
---|
819 | document.getElementById("cbpx-p").value = 3;
|
---|
820 | document.getElementById("cbpx-x").value = 6;
|
---|
821 | document.getElementById("cbpx").value = 393;
|
---|
822 | }
|
---|
823 |
|
---|
824 |
|
---|
825 | function onPixel()
|
---|
826 | {
|
---|
827 | checkPixel();
|
---|
828 |
|
---|
829 | var p = parseInt(document.getElementById("pixel").value);
|
---|
830 |
|
---|
831 | var cbpx = map[p];
|
---|
832 |
|
---|
833 | document.getElementById("cbpx-c").value = parseInt((cbpx/360));
|
---|
834 | document.getElementById("cbpx-b").value = parseInt((cbpx/36)%10);
|
---|
835 | document.getElementById("cbpx-p").value = parseInt((cbpx/9)%4);
|
---|
836 | document.getElementById("cbpx-x").value = parseInt((cbpx%9));
|
---|
837 | document.getElementById("cbpx").value = parseInt(cbpx);
|
---|
838 |
|
---|
839 | onSubmit("", true);
|
---|
840 | }
|
---|
841 |
|
---|
842 | function onCBPX()
|
---|
843 | {
|
---|
844 | checkPixel();
|
---|
845 |
|
---|
846 | var c = parseInt(document.getElementById("cbpx-c").value);
|
---|
847 | var b = parseInt(document.getElementById("cbpx-b").value);
|
---|
848 | var p = parseInt(document.getElementById("cbpx-p").value);
|
---|
849 | var x = parseInt(document.getElementById("cbpx-x").value);
|
---|
850 |
|
---|
851 | var cbpx = c*360 + b*36 + p*9 + x;
|
---|
852 |
|
---|
853 | document.getElementById("cbpx").value = parseInt(cbpx);
|
---|
854 | document.getElementById("pixel").value = map.indexOf(cbpx);
|
---|
855 |
|
---|
856 | onSubmit("", true);
|
---|
857 | }
|
---|
858 |
|
---|
859 | function onHW()
|
---|
860 | {
|
---|
861 | checkPixel();
|
---|
862 |
|
---|
863 | var cbpx = parseInt(document.getElementById("cbpx").value);;
|
---|
864 |
|
---|
865 | document.getElementById("cbpx-c").value = parseInt((cbpx/360));
|
---|
866 | document.getElementById("cbpx-b").value = parseInt((cbpx/36)%10);
|
---|
867 | document.getElementById("cbpx-p").value = parseInt((cbpx/9)%4);
|
---|
868 | document.getElementById("cbpx-x").value = parseInt((cbpx%9));
|
---|
869 |
|
---|
870 | document.getElementById("pixel").value = map.indexOf(cbpx);
|
---|
871 |
|
---|
872 | onSubmit("", true);
|
---|
873 | }
|
---|
874 |
|
---|
875 | function isInside(x, y, mouse)
|
---|
876 | {
|
---|
877 | var dist = Math.sqrt((mouse.x-x)*(mouse.x-x)+(mouse.y-y)*(mouse.y-y));
|
---|
878 | return dist<0.5;
|
---|
879 |
|
---|
880 | /*
|
---|
881 | ctx.translate(x, y);
|
---|
882 | ctx.scale(1/2, 1/3);
|
---|
883 |
|
---|
884 | ctx.beginPath();
|
---|
885 | ctx.moveTo( 1, 1);
|
---|
886 | ctx.lineTo( 0, 2);
|
---|
887 | ctx.lineTo(-1, 1);
|
---|
888 | ctx.lineTo(-1, -1);
|
---|
889 | ctx.lineTo( 0, -2);
|
---|
890 | ctx.lineTo( 1, -1);
|
---|
891 | ctx.fill();
|
---|
892 |
|
---|
893 | ctx.restore();
|
---|
894 | */
|
---|
895 | }
|
---|
896 |
|
---|
897 | var inprogress = { };
|
---|
898 | function moveElement(id, n, target, callback)
|
---|
899 | {
|
---|
900 | if (inprogress[id]==n || inprogress[id]<0)
|
---|
901 | return;
|
---|
902 |
|
---|
903 | inprogress[id] = target ? -n : n;
|
---|
904 |
|
---|
905 | var element = $("#"+id+n); //Allow passing in either a JQuery object or selector
|
---|
906 | var newParent = $(target ? target : "#cont"+id+n); //Allow passing in either a JQuery object or selector
|
---|
907 |
|
---|
908 | var oldOffset = element.offset();
|
---|
909 |
|
---|
910 | var newOffset = newParent.offset();
|
---|
911 |
|
---|
912 | var w = newParent.width();
|
---|
913 | var h = newParent.height();
|
---|
914 |
|
---|
915 | var temp = element.appendTo('body');
|
---|
916 | temp.css('position', 'absolute')
|
---|
917 | .css('left', oldOffset.left)
|
---|
918 | .css('top', oldOffset.top)
|
---|
919 | .css('zIndex', 999);
|
---|
920 |
|
---|
921 | temp.animate( {'top': newOffset.top, 'left':newOffset.left, 'width':w, 'height': h},
|
---|
922 | 'slow', function()
|
---|
923 | {
|
---|
924 | temp = temp.appendTo(newParent);
|
---|
925 | temp.css('position', 'relative');
|
---|
926 | temp.css('width', '');
|
---|
927 | temp.css('height', '');
|
---|
928 | temp.css('zIndex', '');
|
---|
929 | temp.css('left', '0');
|
---|
930 | temp.css('top', '0');
|
---|
931 |
|
---|
932 | setSize(id+n, w, h);
|
---|
933 |
|
---|
934 | if (callback)
|
---|
935 | callback(id+n);
|
---|
936 |
|
---|
937 | inprogress[id] = 0;
|
---|
938 | });
|
---|
939 | }
|
---|
940 |
|
---|
941 | function onClickCont(event, callback)
|
---|
942 | {
|
---|
943 | var id = event.target.id;
|
---|
944 | if (!id)
|
---|
945 | id = event.target.parentNode.id;
|
---|
946 |
|
---|
947 | var n = parseInt(id[id.length-1]);
|
---|
948 | var type = id.substr(0, id.length-1);
|
---|
949 |
|
---|
950 | if (id.substr(0, 4)=="cont")
|
---|
951 | id = id.substr(4, id.length-4);
|
---|
952 | if (type.substr(0, 4)=="cont")
|
---|
953 | type = type.substr(4, type.length-4);
|
---|
954 |
|
---|
955 | if (id.substr(0, type.length)==type)
|
---|
956 | {
|
---|
957 | var cont = document.getElementById("center"+type).childNodes[0];
|
---|
958 | if (cont)
|
---|
959 | {
|
---|
960 | var nn = parseInt(cont.id[cont.id.length-1]);
|
---|
961 | moveElement(type, nn, null, callback);
|
---|
962 | }
|
---|
963 | moveElement(type, n, "#center"+type, callback);
|
---|
964 |
|
---|
965 | }
|
---|
966 | else
|
---|
967 | moveElement(type, n, null, callback);
|
---|
968 |
|
---|
969 | }
|
---|
970 |
|
---|
971 | function onClickContCamera(event)
|
---|
972 | {
|
---|
973 | onClickCont(event, function(el) { drawFullCam(el); });
|
---|
974 | }
|
---|
975 |
|
---|
976 | function onClickContHist(event)
|
---|
977 | {
|
---|
978 | onClickCont(event);
|
---|
979 | }
|
---|
980 |
|
---|
981 | function onClick(event)
|
---|
982 | {
|
---|
983 | var cont = document.getElementById("centercamera").childNodes[0];
|
---|
984 | if (!cont)
|
---|
985 | return;
|
---|
986 |
|
---|
987 | if (cont.id!=event.target.id)
|
---|
988 | return;
|
---|
989 |
|
---|
990 | // get click position relative to canvas
|
---|
991 | var rect = event.target.getBoundingClientRect();
|
---|
992 |
|
---|
993 | var x = event.clientX - rect.left;
|
---|
994 | var y = event.clientY - rect.top;
|
---|
995 |
|
---|
996 | var mouse = { x: x, y: y };
|
---|
997 |
|
---|
998 | // convert click position to pixel index
|
---|
999 | var index = getIndex(event.target.id, mouse);
|
---|
1000 | if (index<0)
|
---|
1001 | return;
|
---|
1002 |
|
---|
1003 | document.getElementById("pixel").value = index;
|
---|
1004 |
|
---|
1005 | onPixel();
|
---|
1006 | }
|
---|
1007 |
|
---|
1008 | function getClickPosition(event)
|
---|
1009 | {
|
---|
1010 | var rect = event.target.getBoundingClientRect();
|
---|
1011 |
|
---|
1012 | var x = event.clientX - rect.left;
|
---|
1013 | var y = event.clientY - rect.top;
|
---|
1014 |
|
---|
1015 | return { x: x, y: y };
|
---|
1016 | }
|
---|
1017 |
|
---|
1018 | function onMinMax(id, n)
|
---|
1019 | {
|
---|
1020 | var el = document.getElementById(id+n);
|
---|
1021 |
|
---|
1022 | el.zmin = document.getElementById(id+"min"+n).value;
|
---|
1023 | el.zmax = document.getElementById(id+"max"+n).value;
|
---|
1024 | }
|
---|
1025 |
|
---|
1026 | function onCameraMinMax(n)
|
---|
1027 | {
|
---|
1028 | onMinMax("camera", n);
|
---|
1029 | drawFullCam("camera"+n);
|
---|
1030 | }
|
---|
1031 |
|
---|
1032 | function onHistMinMax(n)
|
---|
1033 | {
|
---|
1034 | onMinMax("hist", n);
|
---|
1035 | drawHist(n);
|
---|
1036 | }
|
---|
1037 |
|
---|
1038 | function onMinMaxOn(id, n)
|
---|
1039 | {
|
---|
1040 | var el = document.getElementById(id+n);
|
---|
1041 |
|
---|
1042 | var redraw;
|
---|
1043 | if (document.getElementById(id+"minon"+n).checked)
|
---|
1044 | {
|
---|
1045 | document.getElementById(id+"min"+n).setAttribute("disabled", "true");
|
---|
1046 | document.getElementById(id+"min"+n).value = el.min;
|
---|
1047 | redraw = true;
|
---|
1048 | }
|
---|
1049 | else
|
---|
1050 | document.getElementById(id+"min"+n).removeAttribute("disabled");
|
---|
1051 |
|
---|
1052 | if (document.getElementById(id+"maxon"+n).checked)
|
---|
1053 | {
|
---|
1054 | document.getElementById(id+"max"+n).setAttribute("disabled", "true");
|
---|
1055 | document.getElementById(id+"max"+n).value = el.max;
|
---|
1056 | redraw = true;
|
---|
1057 | }
|
---|
1058 | else
|
---|
1059 | document.getElementById(id+"max"+n).removeAttribute("disabled");
|
---|
1060 |
|
---|
1061 | return redraw;
|
---|
1062 | }
|
---|
1063 |
|
---|
1064 | function onCameraMinMaxOn(n)
|
---|
1065 | {
|
---|
1066 | if (onMinMaxOn("camera", n))
|
---|
1067 | onCameraMinMax(n);
|
---|
1068 | }
|
---|
1069 |
|
---|
1070 | function onHistMinMaxOn(n)
|
---|
1071 | {
|
---|
1072 | if (onMinMaxOn("hist", n))
|
---|
1073 | onHistMinMax(n);
|
---|
1074 | }
|
---|
1075 |
|
---|
1076 | function onWaveformMinMax()
|
---|
1077 | {
|
---|
1078 | var wf = document.getElementById("waveform");
|
---|
1079 |
|
---|
1080 | var xmin, xmax, ymin, ymax;
|
---|
1081 |
|
---|
1082 | var redraw;
|
---|
1083 | if (!document.getElementById("waveformxminon").checked)
|
---|
1084 | xmin = document.getElementById("waveformxmin").value;
|
---|
1085 | if (!document.getElementById("waveformxmaxon").checked)
|
---|
1086 | xmax = document.getElementById("waveformxmax").value;
|
---|
1087 | if (!document.getElementById("waveformminon").checked)
|
---|
1088 | ymin = document.getElementById("waveformmin").value;
|
---|
1089 | if (!document.getElementById("waveformmaxon").checked)
|
---|
1090 | ymax = document.getElementById("waveformmax").value;
|
---|
1091 |
|
---|
1092 | setZoom(xmin, xmax, ymin, ymax);
|
---|
1093 |
|
---|
1094 | }
|
---|
1095 |
|
---|
1096 | function onWaveformMinMaxOn()
|
---|
1097 | {
|
---|
1098 | var wf = document.getElementById("waveform");
|
---|
1099 |
|
---|
1100 | var xmin, xmax, ymin, ymax;
|
---|
1101 |
|
---|
1102 | var redraw;
|
---|
1103 | if (document.getElementById("waveformxminon").checked)
|
---|
1104 | {
|
---|
1105 | document.getElementById("waveformxmin").setAttribute("disabled", "true");
|
---|
1106 | document.getElementById("waveformxmin").value = wf.xmin;
|
---|
1107 | xmin = wf.xmin-1;
|
---|
1108 | }
|
---|
1109 | else
|
---|
1110 | document.getElementById("waveformxmin").removeAttribute("disabled");
|
---|
1111 |
|
---|
1112 | if (document.getElementById("waveformxmaxon").checked)
|
---|
1113 | {
|
---|
1114 | document.getElementById("waveformxmax").setAttribute("disabled", "true");
|
---|
1115 | document.getElementById("waveformxmax").value = wf.xmax;
|
---|
1116 | xmax = wf.xmax+1;
|
---|
1117 | }
|
---|
1118 | else
|
---|
1119 | document.getElementById("waveformxmax").removeAttribute("disabled");
|
---|
1120 |
|
---|
1121 | if (document.getElementById("waveformminon").checked)
|
---|
1122 | {
|
---|
1123 | document.getElementById("waveformmin").setAttribute("disabled", "true");
|
---|
1124 | document.getElementById("waveformmin").value = wf.ymin;
|
---|
1125 | ymin = wf.ymin-5;
|
---|
1126 | }
|
---|
1127 | else
|
---|
1128 | document.getElementById("waveformmin").removeAttribute("disabled");
|
---|
1129 |
|
---|
1130 | if (document.getElementById("waveformmaxon").checked)
|
---|
1131 | {
|
---|
1132 | document.getElementById("waveformmax").setAttribute("disabled", "true");
|
---|
1133 | document.getElementById("waveformmax").value = wf.ymax;
|
---|
1134 | ymax = wf.ymax+5;
|
---|
1135 | }
|
---|
1136 | else
|
---|
1137 | document.getElementById("waveformmax").removeAttribute("disabled");
|
---|
1138 |
|
---|
1139 | setZoom(xmin, xmax, ymin, ymax);
|
---|
1140 | }
|
---|
1141 |
|
---|
1142 | //document.addEventListener("click", getClickPosition, false);
|
---|
1143 |
|
---|
1144 | $(document).ready(onReady);
|
---|
1145 |
|
---|
1146 | // ================================== Pixel mapping =================================================
|
---|
1147 |
|
---|
1148 | var map = new Array(1440);
|
---|
1149 |
|
---|
1150 | function initPixelMap()
|
---|
1151 | {
|
---|
1152 | 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:";
|
---|
1153 | // first: decode the pixel mapping!
|
---|
1154 | var sum = 1036080;
|
---|
1155 | for (var i=0; i<1440; i++)
|
---|
1156 | {
|
---|
1157 | var d0 = codedMap.charCodeAt(i*2) -48;
|
---|
1158 | var d1 = codedMap.charCodeAt(i*2+1)-48;
|
---|
1159 |
|
---|
1160 | map[i] = d0 | (d1<<6);
|
---|
1161 | sum -= map[i];
|
---|
1162 | }
|
---|
1163 | if (sum!=0)
|
---|
1164 | alert("Pixel mapping table corrupted!");
|
---|
1165 | }
|
---|
1166 |
|
---|
1167 | initPixelMap();
|
---|
1168 |
|
---|
1169 | // ================================== Camera Display ================================================
|
---|
1170 |
|
---|
1171 | var coord = new Array(1440);
|
---|
1172 | function initCameraCoordinates()
|
---|
1173 | {
|
---|
1174 | coord[0] = [0, 0];
|
---|
1175 | var cnt = 1;
|
---|
1176 | for (var ring=1; ring<24; ring++)
|
---|
1177 | {
|
---|
1178 | for (var s=0; s<6; s++)
|
---|
1179 | {
|
---|
1180 | for (var i=1; i<=ring; i++)
|
---|
1181 | {
|
---|
1182 | var pos = new Position(s, ring, i);
|
---|
1183 | if (pos.d() - pos.x > 395.75)
|
---|
1184 | continue;
|
---|
1185 |
|
---|
1186 | coord[cnt++] = [ pos.x, pos.y];
|
---|
1187 | }
|
---|
1188 | }
|
---|
1189 | }
|
---|
1190 |
|
---|
1191 | coord[1438] = [7, -22];
|
---|
1192 | coord[1439] = [7, 22];
|
---|
1193 | }
|
---|
1194 |
|
---|
1195 | initCameraCoordinates();
|
---|
1196 |
|
---|
1197 | function getIndex(id, mouse)
|
---|
1198 | {
|
---|
1199 | var canv = document.getElementById(id);
|
---|
1200 |
|
---|
1201 | var scale = 83;
|
---|
1202 |
|
---|
1203 | var w = Math.min(canv.width/scale, canv.height/scale);
|
---|
1204 |
|
---|
1205 | //ctx.translate(canv.width/2, canv.height/2);
|
---|
1206 | //ctx.scale(w*2, w*2);
|
---|
1207 | //ctx.scale(1, Math.sqrt(3)/2);
|
---|
1208 | //ctx.translate(-0.5, 0);
|
---|
1209 |
|
---|
1210 | mouse.x -= canv.width/2;
|
---|
1211 | mouse.y -= canv.height/2;
|
---|
1212 | mouse.x /= w*2;
|
---|
1213 | mouse.y /= w*2;
|
---|
1214 | mouse.y /= Math.sqrt(3)/2;
|
---|
1215 | mouse.x -= -0.5;
|
---|
1216 |
|
---|
1217 | for (var i=0; i<1440; i++)
|
---|
1218 | if (isInside(coord[i][0], coord[i][1], mouse))
|
---|
1219 | return i;
|
---|
1220 |
|
---|
1221 | return -1;
|
---|
1222 | }
|
---|
1223 |
|
---|
1224 |
|
---|
1225 | function hueToRGB(hue)
|
---|
1226 | {
|
---|
1227 | hue /= 3;
|
---|
1228 | hue %= 6;
|
---|
1229 |
|
---|
1230 | if (hue<1) return parseInt(255*hue, 10);
|
---|
1231 | if (hue<3) return parseInt(255, 10);
|
---|
1232 | if (hue<4) return parseInt(255*(4-hue), 10);
|
---|
1233 |
|
---|
1234 | return 0.
|
---|
1235 | }
|
---|
1236 |
|
---|
1237 | function hueToHex(flt)
|
---|
1238 | {
|
---|
1239 | var s = hueToRGB(flt).toString(16);
|
---|
1240 | return s.length==2 ? s : "0"+s;
|
---|
1241 | }
|
---|
1242 |
|
---|
1243 | function HLStoRGB(hue)
|
---|
1244 | {
|
---|
1245 | if (isNaN(hue))
|
---|
1246 | return "fff";
|
---|
1247 |
|
---|
1248 | if (hue<0)
|
---|
1249 | return "eef"; // 555
|
---|
1250 |
|
---|
1251 | if (hue>1)
|
---|
1252 | return "700"; // 666
|
---|
1253 |
|
---|
1254 | hue *= 14;
|
---|
1255 |
|
---|
1256 | var sr = hueToHex(20-hue);
|
---|
1257 | var sg = hueToHex(14-hue);
|
---|
1258 | var sb = hueToHex(26-hue);
|
---|
1259 |
|
---|
1260 | return sr+sg+sb;
|
---|
1261 | }
|
---|
1262 |
|
---|
1263 | function outlineHex(ctx)
|
---|
1264 | {
|
---|
1265 | ctx.scale(1/2, 1/3);
|
---|
1266 |
|
---|
1267 | ctx.beginPath();
|
---|
1268 | ctx.moveTo( 1, 1);
|
---|
1269 | ctx.lineTo( 0, 2);
|
---|
1270 | ctx.lineTo(-1, 1);
|
---|
1271 | ctx.lineTo(-1, -1);
|
---|
1272 | ctx.lineTo( 0, -2);
|
---|
1273 | ctx.lineTo( 1, -1);
|
---|
1274 | ctx.lineTo( 1, 1);
|
---|
1275 | }
|
---|
1276 |
|
---|
1277 | function drawHex(ctx, x, y, col, min, max)
|
---|
1278 | {
|
---|
1279 | if (col===undefined/* || col===null*/ || max<min)
|
---|
1280 | return;
|
---|
1281 |
|
---|
1282 | var lvl = max==min ? 0.5 : (col-min)/(max-min);
|
---|
1283 |
|
---|
1284 | ctx.fillStyle = "#"+HLStoRGB(lvl);
|
---|
1285 |
|
---|
1286 | ctx.save();
|
---|
1287 | ctx.translate(x, y);
|
---|
1288 | outlineHex(ctx);
|
---|
1289 | ctx.fill();
|
---|
1290 | ctx.restore();
|
---|
1291 | }
|
---|
1292 |
|
---|
1293 | function Position(s, ring, i)
|
---|
1294 | {
|
---|
1295 | switch (s)
|
---|
1296 | {
|
---|
1297 | case 1: this.x = ring - i*0.5; this.y = + i; break;
|
---|
1298 | case 2: this.x = ring*0.5 - i; this.y = ring ; break;
|
---|
1299 | case 3: this.x = -ring*0.5 - i*0.5; this.y = ring - i; break;
|
---|
1300 | case 4: this.x = -ring + i*0.5; this.y = - i; break;
|
---|
1301 | case 5: this.x = -ring*0.5 + i; this.y = -ring ; break;
|
---|
1302 | case 0: this.x = ring*0.5 + i*0.5; this.y = -ring + i; break;
|
---|
1303 | }
|
---|
1304 | this.d = (function () { return this.x*this.x + this.y*this.y*3/4; });
|
---|
1305 | }
|
---|
1306 |
|
---|
1307 | function drawFullCam(id)
|
---|
1308 | {
|
---|
1309 | var canv = document.getElementById(id);
|
---|
1310 | if (!canv)
|
---|
1311 | return;
|
---|
1312 |
|
---|
1313 | var ctx = canv.getContext("2d");
|
---|
1314 |
|
---|
1315 | ctx.clearRect(0, 0, canv.width, canv.height);
|
---|
1316 |
|
---|
1317 | // ======================= Draw Graphics ======================
|
---|
1318 |
|
---|
1319 | var data = canv.dataRel;
|
---|
1320 | if (!data)
|
---|
1321 | return;
|
---|
1322 |
|
---|
1323 | var pixel = document.getElementById('pixel').value;
|
---|
1324 |
|
---|
1325 | var min = (canv.zmin-canv.min)/canv.max;
|
---|
1326 | var max = (canv.zmax-canv.min)/canv.max;
|
---|
1327 |
|
---|
1328 | var scale = 83;
|
---|
1329 |
|
---|
1330 | var w = Math.min(canv.width/scale, canv.height/scale);
|
---|
1331 |
|
---|
1332 | ctx.save();
|
---|
1333 | ctx.translate(canv.width/2, canv.height/2);
|
---|
1334 | ctx.scale(w*2, w*2);
|
---|
1335 | // ctx.rotate(Math.PI/3);
|
---|
1336 |
|
---|
1337 | ctx.scale(1, Math.sqrt(3)/2);
|
---|
1338 | ctx.translate(-0.5, 0);
|
---|
1339 |
|
---|
1340 | for (var i=0; i<1440; i++)
|
---|
1341 | drawHex(ctx, coord[i][0], coord[i][1], data[i], min, max);
|
---|
1342 |
|
---|
1343 | // =================== Draw Pixel marker ====================
|
---|
1344 |
|
---|
1345 | if (document.getElementById('marker').checked)
|
---|
1346 | {
|
---|
1347 | // Draw marker
|
---|
1348 | ctx.save();
|
---|
1349 |
|
---|
1350 | ctx.lineWidth = 0.25;
|
---|
1351 | ctx.fillStyle = "#000";
|
---|
1352 |
|
---|
1353 | ctx.translate(coord[pixel][0], coord[pixel][1]);
|
---|
1354 | outlineHex(ctx);
|
---|
1355 | ctx.stroke();
|
---|
1356 |
|
---|
1357 | ctx.restore();
|
---|
1358 | }
|
---|
1359 |
|
---|
1360 | // ======================= Draw Ellipse ======================
|
---|
1361 |
|
---|
1362 | if (document.getElementById('image').checked)
|
---|
1363 | {
|
---|
1364 | var h = Hillas(canv.dataAbs, canv.zmin);
|
---|
1365 | if (h)
|
---|
1366 | {
|
---|
1367 | ctx.save();
|
---|
1368 |
|
---|
1369 | ctx.translate(h.mean[0], h.mean[1]);
|
---|
1370 | ctx.rotate(h.phi);
|
---|
1371 |
|
---|
1372 | ctx.save();
|
---|
1373 | ctx.scale(h.axis[0], h.axis[1]);
|
---|
1374 | ctx.beginPath();
|
---|
1375 | ctx.arc(0, 0, 1, 0, 2*Math.PI);
|
---|
1376 | ctx.restore();
|
---|
1377 |
|
---|
1378 | ctx.lineWidth = 0.15;
|
---|
1379 | ctx.strokeStyle = "#555";
|
---|
1380 | ctx.stroke();
|
---|
1381 |
|
---|
1382 | ctx.strokeStyle = "#888";
|
---|
1383 | ctx.beginPath();
|
---|
1384 | ctx.moveTo(0, -h.disp);
|
---|
1385 | ctx.lineTo(0, h.disp);
|
---|
1386 | ctx.stroke();
|
---|
1387 |
|
---|
1388 | ctx.restore();
|
---|
1389 | }
|
---|
1390 | }
|
---|
1391 |
|
---|
1392 | ctx.restore();
|
---|
1393 |
|
---|
1394 | // ======================= Draw Legend ======================
|
---|
1395 |
|
---|
1396 | var pval = parseFloat(canv.dataAbs[pixel]).toFixed(1);
|
---|
1397 | var lmin = parseFloat(canv.min).toFixed(1);
|
---|
1398 | var lmax = parseFloat(canv.max).toFixed(1);
|
---|
1399 |
|
---|
1400 | var v0 = parseFloat(canv.zmin);
|
---|
1401 | var v1 = parseFloat(canv.zmax);
|
---|
1402 |
|
---|
1403 | var diff = v1-v0;
|
---|
1404 |
|
---|
1405 | var cw = canv.width;
|
---|
1406 | //var ch = canv.height;
|
---|
1407 |
|
---|
1408 | ctx.font = "8pt Arial";
|
---|
1409 | ctx.textAlign = "right";
|
---|
1410 | ctx.textBaseline = "top";
|
---|
1411 |
|
---|
1412 | for (var i=0; i<11; i++)
|
---|
1413 | {
|
---|
1414 | ctx.strokeStyle = "#"+HLStoRGB(i/10);
|
---|
1415 | ctx.strokeText((v0+diff*i/10).toPrecision(3), cw-5, 125-i*12);
|
---|
1416 | }
|
---|
1417 |
|
---|
1418 | var mw = Math.max(ctx.measureText(lmin).width,
|
---|
1419 | ctx.measureText(pval).width,
|
---|
1420 | ctx.measureText(lmax).width);
|
---|
1421 |
|
---|
1422 | ctx.textBaseline = "top";
|
---|
1423 | ctx.strokeStyle = "#000";
|
---|
1424 |
|
---|
1425 | ctx.strokeText(lmax, 5+mw, 5+24);
|
---|
1426 | ctx.strokeText(pval, 5+mw, 5+12);
|
---|
1427 | ctx.strokeText(lmin, 5+mw, 5);
|
---|
1428 | }
|
---|
1429 |
|
---|
1430 | // ===================================================================
|
---|
1431 |
|
---|
1432 | function Hillas(data, min)
|
---|
1433 | {
|
---|
1434 | var mx = 0;
|
---|
1435 | var my = 0;
|
---|
1436 | var sz = 0;
|
---|
1437 |
|
---|
1438 | var mx2 = 0;
|
---|
1439 | var my2 = 0;
|
---|
1440 | var mxy = 0;
|
---|
1441 |
|
---|
1442 | var cnt = 0;
|
---|
1443 | for (var i=0; i<1440; i++)
|
---|
1444 | {
|
---|
1445 | if (data[i]===undefined || data[i]<min)
|
---|
1446 | continue;
|
---|
1447 |
|
---|
1448 | sz += data[i];
|
---|
1449 | mx += data[i] * coord[i][0];
|
---|
1450 | my += data[i] * coord[i][1];
|
---|
1451 |
|
---|
1452 | mx2 += data[i] * coord[i][0]*coord[i][0];
|
---|
1453 | my2 += data[i] * coord[i][1]*coord[i][1];
|
---|
1454 | mxy += data[i] * coord[i][0]*coord[i][1];
|
---|
1455 |
|
---|
1456 | cnt++;
|
---|
1457 | }
|
---|
1458 |
|
---|
1459 | if (sz==0 || cnt<3)
|
---|
1460 | return;
|
---|
1461 |
|
---|
1462 | var xx = mx2 - mx*mx/sz;
|
---|
1463 | var yy = my2 - my*my/sz;
|
---|
1464 | var xy = mxy - mx*my/sz;
|
---|
1465 |
|
---|
1466 | var d0 = yy - xx;
|
---|
1467 | var d1 = xy*2;
|
---|
1468 | var d2 = Math.sqrt(d0*d0 + d1*d1) + d0;
|
---|
1469 |
|
---|
1470 | var phi = 0;
|
---|
1471 | var cos = 0;
|
---|
1472 | var sin = 1;
|
---|
1473 |
|
---|
1474 | var axis1 = yy;
|
---|
1475 | var axis2 = xx;
|
---|
1476 | var ratio = xx/yy;
|
---|
1477 |
|
---|
1478 | if (d1!=0 || d2==0)
|
---|
1479 | {
|
---|
1480 | var tand = d2==0 ? 0 : d2 / d1;
|
---|
1481 | var tand2 = tand*tand;
|
---|
1482 |
|
---|
1483 | var s2 = tand2+1;
|
---|
1484 | var s = Math.sqrt(s2);
|
---|
1485 |
|
---|
1486 | phi = Math.atan(tand)-Math.PI/2;
|
---|
1487 | cos = 1.0 /s;
|
---|
1488 | sin = tand/s;
|
---|
1489 |
|
---|
1490 | axis1 = (tand2*yy + d2 + xx)/s2;
|
---|
1491 | axis2 = (tand2*xx - d2 + yy)/s2;
|
---|
1492 | ratio = (tand2*xx - d2 + yy)/(tand2*yy + d2 + xx);
|
---|
1493 | }
|
---|
1494 |
|
---|
1495 | var length = axis1<0 ? 0 : Math.sqrt(axis1/sz);
|
---|
1496 | var width = axis2<0 ? 0 : Math.sqrt(axis2/sz);
|
---|
1497 |
|
---|
1498 | return {
|
---|
1499 | "mean": [ mx/sz, my/sz ],
|
---|
1500 | "axis": [ width, length ],
|
---|
1501 | "phi": phi,
|
---|
1502 | "delta": [ cos, sin ],
|
---|
1503 | "sumw": sz,
|
---|
1504 | "count": cnt,
|
---|
1505 | "disp": 1.42/0.1111*(1-Math.sqrt(ratio)),
|
---|
1506 | };
|
---|
1507 | }
|
---|