Newer
Older
// jshint esversion: 6
// sr/feedback/profile_s/CorrHorFast
// sr/feedback/profile_s->GetSrCorrNames
// sr/feedback/profile_s/OrbitHorFast
function lilclick(par) {
if (par!=123) setTimeout(lilclick, 500, 123);
gPos = $("#fps").children().eq(1).children()[0].getBoundingClientRect();
console.log('lilclick', gPos);
$('#fpsr').css('left', gPos.left);
$('#fpsr').css('top', gPos.top+gPos.height-3);
}
$(".lil-gui.root").click(lilclick);
function getParam(param, defaultValue) {
if (document.location.search.indexOf(param+'=')>-1) return document.location.search.split(param+'=')[1].split('&')[0];
return defaultValue;
}
if (document.location.search.indexOf('machine=esrf')>-1 || document.location.search.indexOf('machine=gof_esrf')>-1) {
gofFactorsHor = {"": 1, "corr": 100000, 'bpm': getParam('positionScaleH', 0.00002)};
gofFactorsVer = {"": 1, "corr": 1, 'bpm': getParam('positionScaleV', 0.00002)};
}
else if (document.location.search.indexOf('machine=gof_soleil')>-1) {
gofFactorsHor = {"": 1, "corr": 50000, 'bpm': getParam('positionScaleH', 0.00002)};
gofFactorsVer = {"": 1, "corr": 10000, 'bpm': getParam('positionScaleV', 0.00002)};
}
else if (document.location.search.indexOf('machine=elettra2')>-1) {
gofFactorsHor = {"": 1, "corr": 500000, 'bpm': getParam('positionScaleH', 0.00002)};
gofFactorsVer = {"": 1, "corr": 500000, 'bpm': getParam('positionScaleV', 0.00002)};
gofFactorsHor = {"": 1, "corr": getParam('positionScaleH', 0.005), 'bpm': getParam('positionScaleH', 0.00002)};
gofFactorsVer = {"": 1, "corr": getParam('positionScaleV', 0.005), 'bpm': getParam('positionScaleV', 0.00002)};
}
let gof = document.location.search.indexOf('gof=')>-1? document.location.search.split('gof=')[1].split('&')[0]: '';
const gofTimeout = document.location.search.indexOf('gofTimeout=')>-1? document.location.search.split('gofTimeout=')[1].split('&')[0]: 10;
const gofPeriod = document.location.search.indexOf('gofPeriod=')>-1? document.location.search.split('gofPeriod=')[1].split('&')[0]: 200;
const gofDisplayerPeriod = document.location.search.indexOf('gofDisplayerPeriod=')>-1? document.location.search.split('gofDisplayerPeriod=')[1].split('&')[0]: 40;
const gofVisibility = gof==''? 'hidden': 'visible';
const gofScaleType = 'slider';
const gofSimfacilities = [];
let gofDataHor = [];
let gofDataVer = [];
let gofScaleHor;
let gofScaleVer;
let gofBuffer = false;
let gofLogScaleHor = false;
let gofLogScaleVer = false;
let gofFactorHor = document.location.search.indexOf('gofFactorHor=')>-1? document.location.search.split('gofFactorHor=')[1].split('&')[0]*1000: localStorage.getItem('reference'+gof+'hor')!=null? localStorage.getItem('reference'+gof+'hor'): gofFactorsHor[gof]*1000;
let gofFactorVer = document.location.search.indexOf('gofFactorVer=')>-1? document.location.search.split('gofFactorVer=')[1].split('&')[0]*1000: localStorage.getItem('reference'+gof+'ver')!=null? localStorage.getItem('reference'+gof+'ver'): gofFactorsVer[gof]*1000;
const gofScaleSteps = 10;
// let ruler = document.location.search.indexOf('ruler')>-1;
rulerInit();
// main.addEventListener('mousemove', function(e) {getRulerposition(main, e, 'sr');});
if (ruler) {
main.style.cursor = 'crosshair';
}
else {
$('#rulerg').hide();
$('#trajectoryWidth').hide();
}
function myreference(param) {
const dir = param.split('_')[0];
const action = param.split('_')[1];
if (action=='set') {
localStorage.setItem('reference'+gof+dir, gofBuffer[dir=='hor'? 0: 1]);
}
if (action=='clear') {
localStorage.removeItem('reference'+gof+dir);
localStorage.removeItem('scale'+gof+dir);
// console.log('elapseHor()',step,gofScaleHor.$fill.style.width, (gofScaleSteps-step)/gofScaleSteps*90);
if (up) {
if (step<gofScaleSteps) {const pc = Math.round((gofScaleSteps-step)/gofScaleSteps*90); gofScaleHor.$fill.style.width=pc+"%";setTimeout(elapseHor, 20, step+1, up); return;}
const buf = gofScaleHor._max;
gofScaleHor.max(buf*10);
gofScaleHor.min(buf/10);
gofScaleHor.step(buf/100);
}
else {
if (step<gofScaleSteps) {const pc = Math.round(step/gofScaleSteps*10); gofScaleHor.$fill.style.width=pc+"%";setTimeout(elapseHor, 20, step+1, up); return;}
const buf = gofScaleHor._max/10;
gofScaleHor.max(buf);
gofScaleHor.min(buf/100);
gofScaleHor.step(buf/1000);
}
gofScaleHor.$fill.style.width="10%";
gofScaleHor.$fill.style.borderColor = '#2cc9ff';
}
if (up) {
if (step<gofScaleSteps) {const pc = Math.round((gofScaleSteps-step)/gofScaleSteps*90); gofScaleVer.$fill.style.width=pc+"%";setTimeout(elapseVer, 20, step+1, up); return;}
const buf = gofScaleVer._max;
gofScaleVer.max(buf*10);
gofScaleVer.min(buf/10);
gofScaleVer.step(buf/100);
}
else {
if (step<gofScaleSteps) {const pc = Math.round(step/gofScaleSteps*10); gofScaleVer.$fill.style.width=pc+"%";setTimeout(elapseVer, 20, step+1, up); return;}
const buf = gofScaleVer._max/10;
gofScaleVer.max(buf);
gofScaleVer.min(buf/100);
gofScaleVer.step(buf/1000);
}
gofScaleVer.$fill.style.width="10%";
gofScaleVer.$fill.style.borderColor = '#2cc9ff';
}
function gofFinishHor() {
// console.log('gofFinishHor()', gofScaleHor.$fill.style.width);
if (gofScaleHor.$fill.style.width=="100%" || gofScaleHor.$fill.style.width=="0%") {
// gofScaleHor.$fill.style.borderColor = 'yellow';
setTimeout(gofElapseHor, 200, 1, gofScaleHor.$fill.style.width=="100%");
if (gofScaleVer.$fill.style.width=="100%" || gofScaleVer.$fill.style.width=="0%") {
setTimeout(gofElapseVer, 200, 1, gofScaleVer.$fill.style.width=="100%");
function gofSetfactorHor(v) {
// console.log('gofSetfactorHor(v)', v, gofScaleHor.$fill.style.width);
gofScaleHor.$fill.style.borderColor = (gofScaleHor.$fill.style.width=="100%" || gofScaleHor.$fill.style.width=="0%")? 'yellow': '#2cc9ff';
gofFactorHor = v * 1000;
if (localStorage.getItem('reference'+gof+'hor')!=null) localStorage.setItem('scale'+gof+'hor', gofFactorHor);
rulerScale('');
}
function gofSetfactorVer(v) {
console.log('gofSetfactorVer(v)', v, gofScaleVer.$fill.style.width);
gofScaleVer.$fill.style.borderColor = (gofScaleVer.$fill.style.width=="100%" || gofScaleVer.$fill.style.width=="0%")? 'yellow': '#2cc9ff';
gofFactorVer = v * 1000;
if (localStorage.getItem('reference'+gof+'ver')!=null) localStorage.setItem('scale'+gof+'ver', gofFactorVer);
rulerScale('');
}
function logscale(dirNum) {
if (dirNum==0) gofLogScaleHor = $('#logHor').attr('checked')=='checked';
else gofLogScaleVer = $('#logVer').attr('checked')=='checked';
}
function gofMenu(lattice, facilities, params) {
console.log('gofMenu',lattice, facilities, params, gui);
$('#notice').hide();
if (['elettra2', 'esrf', 'soleil'].indexOf(machine)>-1) for (let i=0; i<gui.children.length; i++) {
if (['vlv', 'ps', 'bpm', 'blm'].indexOf(gui.children[i].property)>-1) gui.children[i].domElement.style.display = 'none';
}
// params.gof = false;
$('.gofhor').css('display', 'none');
$('.gofver').css('display', 'none');
params.gof = document.location.search.indexOf('gof')>-1 && document.location.search.indexOf('=gof')==-1? 'corr': '';
if (document.location.search.indexOf('gof=')>-1) params.gof = document.location.search.split('gof=')[1].split('&')[0];
if (options.indexOf(params.gof)==-1) params.gof = 'corr';
gui.add(params, 'gof', options).name('gof H <img id="h" src="red.svg" style="margin-bottom: -4px;"> V <img id="v" src="green.svg" style="margin-bottom: -4px;"> ').onChange(function() {gofSwitch(compData, params);});
const maxVer = Math.pow(10, Math.floor(Math.log10(gofFactorVer/1000))+2);
const maxHor = Math.pow(10, Math.floor(Math.log10(gofFactorHor/1000))+2);
menuParams['fps'] = gofMaxFps;
gofFpsMenu = gui.add(menuParams, 'fps', 0.5, 25, 0.5).onChange(function() {fpsSet(menuParams['fps']);}); // .title('fps (max)')
gPos = $("#fps").children().eq(1).children()[0].getBoundingClientRect();
jQuery('<div>', {id: 'fpsr', style: 'z-index: 1000; min-width: 45px; min-height: 3px; position: absolute; background-color: yellow; left: '+(gPos.left+0)+'px; top: '+(gPos.top+gPos.height-3)+'px;', title: 'fps',}).appendTo('body');
// $('#fpsr').hide();
if (gofScaleType == 'slider') {
/*menuParams['ruler'] = ruler;
gui.add(menuParams, 'ruler').onChange(function() {rulerSwitch();});
guiconf(gui, 'ruler');*/
menuParams['scale H'] = gofFactorHor/1000;
gofScaleHor = gui.add(menuParams, 'scale H', maxVer/100, maxVer, Math.round(maxVer/1000)).onChange(function() {gofSetfactorHor(menuParams['scale H'], gui);}).onFinishChange(function() {gofFinishHor(gui);});
guiconf(gui, 'scaleh');
$('#scaleh').children().eq(0).css('color','red');
menuParams['scale V'] = gofFactorHor/1000;
gofScaleVer = gui.add(menuParams, 'scale V', maxHor/100, maxHor, Math.round(maxHor/1000)).onChange(function() {gofSetfactorVer(menuParams['scale V'], gui);}).onFinishChange(function() {gofFinishVer(gui);});
guiconf(gui, 'scalev');
$('#scalev').children().eq(0).css('color','green');
}
else {
const controllerOption = $('.controller.option');
for (let i=0; i<controllerOption.length; i++) {
if (controllerOption.eq(i).children()[0].innerText.indexOf("gof H") > -1) {
$('<div class="gofgauge"><iframe id="vergauge" style="width: 100%;height:250px;" src="../misc/gauge.html?dark&r=115&ringwidth=30&max='+maxVer+'&throttlingPeriod=50&apply=factorVer&extbackground=green&exthighlight=darkgreen&intbackground=green&inthighlight=darkgreen&val='+gofFactorVer/1000+'"></iframe></div>').insertAfter(controllerOption.eq(i));
$('<div class="gofgauge"><iframe id="horgauge" style="width: 100%;height:250px;" src="../misc/gauge.html?dark&r=115&ringwidth=30&max='+maxHor+'&throttlingPeriod=50&apply=factorHor&extbackground=red&exthighlight=darkred&intbackground=red&inthighlight=darkred&val='+gofFactorHor/1000+'"></iframe></div>').insertAfter(controllerOption.eq(i));
$('<div style="padding: 8px;" class="gofgauge">log scale H <img id="h" src="red.svg" style="margin-bottom: -2px;"> <input type="checkbox" id="logHor" onChange="logscale(0)"> log V <img id="h" src="green.svg" style="margin-bottom: -2px;"> <input type="checkbox" id="logVer" onChange="logscale(1)"></div>').insertAfter(controllerOption.eq(i));
if (gof=='') $('.gofgauge').hide();
}
}
}
for (let f in facilities) {
const b = facilities[f];
if (b!='sr') continue;
console.log('gofMenu() - ', b, lattice[b], conf.gofSrcUrl);
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
compData[b].bpmMap = [];
fetch('./bpm.php?machine=elettra&src&sr', {cache: "no-store"})
.then((response) => {return response.json();})
.then((gofNaming) => {
console.log('gofBpmNaming', gofNaming, compData[b].bpmMap);
for (let i in gofNaming) {
const name = gofNaming[i];
for (let bl in compData[b].obj) {
if (name==compData[b].obj[bl] || name==compData[b].obj[bl].replace('.','_')) {compData[b].bpmMap[i] = bl;}
}
}
for (let fi in facilities) {
const facility = facilities[fi];
if (facility!='sr') continue;
console.log(fi, facility, compData);
if (facility.length>0 && typeof compData[facility]!='undefined' && compData[facility].obj && compData[facility].obj.length>0) {
console.log('gofBpmInit', facility, compData[facility]);
const dhor = [];
const dver = [];
for (i=0; i<compData[facility].pos.length; i++) {
// if (i>threshold) break;
const dir = compData[facility].dir[i];
const beta = Math.PI*dir/180;
if (threshold<1000) console.log('i', i, 'pos',compData[facility].pos[i], 'dir', dir, beta, Math.cos(beta), Math.sin(beta));
dhor.push((i==0?'M':'L')+
Math.round(compData[facility].pos[i][0] - f*Math.sin(beta)) + ' ' +
Math.round(compData[facility].pos[i][1] + f*Math.cos(beta))
);
dver.push((i==0?'M':'L')+
Math.round(compData[facility].pos[i][0] - f*1.05*Math.sin(beta)) + ' ' +
Math.round(compData[facility].pos[i][1] + f*1.05*Math.cos(beta))
);
}
console.log(dhor);
appendSvg("path", {id:facility+"_gofbpmhor", class: "gofbpmhor trajectory "+facility, visibility:gofVisibility, name:"gofbpmhor", fill: "none", "stroke-width":"150", "stroke":"red", "stroke-opacity":"0.6", d: dhor.join(' ')+(lattice[facility].sections[0].chamber?' Z':'')}, gof_clicked_hor, false, false, '.svg-pan-zoom_viewport');
appendSvg("path", {id:facility+"_gofbpmver", class: "gofbpmver trajectory "+facility, visibility:gofVisibility, name:"gofbpmver", fill: "none", "stroke-width":"150", "stroke":"limegreen", "stroke-opacity":"0.6", d: dver.join(' ')+(lattice[facility].sections[0].chamber?' Z':'')}, gof_clicked_ver, false, false, '.svg-pan-zoom_viewport');
}
}
});
console.log((conf.gofSrcUrl+'&machine='+machine).replace('?&','?'));
fetch((conf.gofSrcUrl+'&machine='+machine).replace('?&','?'), {cache: "no-store"})
.then((response) => {return response.json();})
.then((gofNaming) => {
console.log('gofNaming', gofNaming, compData[b].corrMap);
for (let i in gofNaming) {
const name = gofNaming[i];
for (let bl in compData[b].obj) {
if (name==compData[b].obj[bl].replace('CHV', 'CORR') || name==compData[b].obj[bl].replace('CHV', 'CORR').replace('.','_')) {compData[b].corrMap[i] = bl;}
for (let fi in facilities) {
const facility = facilities[fi];
if (facility!='sr') continue;
console.log(fi, facility, compData);
if (facility.length>0 && typeof compData[facility]!='undefined' && compData[facility].obj && compData[facility].obj.length>0) {
console.log('gofInit', facility, compData[facility]);
const dhor = [];
const dver = [];
for (i=0; i<compData[facility].pos.length; i++) {
// if (i>threshold) break;
const dir = compData[facility].dir[i];
const beta = Math.PI*dir/180;
if (threshold<1000) console.log('i', i, 'pos',compData[facility].pos[i], 'dir', dir, beta, Math.cos(beta), Math.sin(beta));
dhor.push((i==0?'M':'L')+
Math.round(compData[facility].pos[i][0] - f*Math.sin(beta)) + ' ' +
Math.round(compData[facility].pos[i][1] + f*Math.cos(beta))
);
dver.push((i==0?'M':'L')+
Math.round(compData[facility].pos[i][0] - f*1.05*Math.sin(beta)) + ' ' +
Math.round(compData[facility].pos[i][1] + f*1.05*Math.cos(beta))
);
}
appendSvg("path", {id:facility+"_gofhor", class: "gofhor trajectory "+facility, visibility:gofVisibility, name:"gofhor", fill: "none", "stroke-width":"150", "stroke":"red", "stroke-opacity":"0.6", d: dhor.join(' ')+(lattice[facility].sections[0].chamber?' Z':'')}, gof_clicked_hor, false, false, '.svg-pan-zoom_viewport');
appendSvg("path", {id:facility+"_gofver", class: "gofver trajectory "+facility, visibility:gofVisibility, name:"gofver", fill: "none", "stroke-width":"150", "stroke":"limegreen", "stroke-opacity":"0.6", d: dver.join(' ')+(lattice[facility].sections[0].chamber?' Z':'')}, gof_clicked_ver, false, false, '.svg-pan-zoom_viewport');
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
}
}
rulerScale('');
});
}
if (document.location.search.indexOf('gof')>-1) {/*params.gof=true;*/ setTimeout(gofSwitch, 500, compData, params);}
}
// const threshold = document.location.search.indexOf('threshold=')>-1? document.location.search.split('threshold=')[1].split('&')[0]: 1000;
// const f = document.location.search.indexOf('factor=')>-1? document.location.search.split('factor=')[1].split('&')[0]: 3000;
function gof_clicked_hor(event) {
// console.log('gof hor', event);
openTooltip('trajectory hor '+event.clientX+' '+event.clientY);
}
function gof_clicked_ver(lattice, params) {
// console.log('gof ver');
openTooltip('trajectory ver'+event.clientX+' '+event.clientY);
}
function gof2d(lattice, params) {
console.log('gof2d',lattice, params);
for (let i in lattice) {if (i!='conf') gofSimfacilities.push(i);}
gofMenu(lattice, gofSimfacilities, params);
}
function gofSwitch(gofData, params) {
gof = params.gof;
gofScaleHor.$fill.style.width = "50%";
gofScaleVer.$fill.style.width = "50%";
if (gofData.reader !== false) {
clearInterval(gofData.reader);
}
gofData.reader = false;
if (params.gof=='') {
for (let facility in gofData) {
if (typeof $('#'+facility+"_gofhor").attr('visibility') != 'undefined') {
$('#'+facility+"_gofhor").attr('visibility', "hidden");
$('#'+facility+"_gofver").attr('visibility', "hidden");
if (typeof $('#'+facility+"_gofbpmhor").attr('visibility') != 'undefined') {
$('#'+facility+"_gofbpmhor").attr('visibility', "hidden");
$('#'+facility+"_gofbpmver").attr('visibility', "hidden");
}
$('#scaleh').hide();
$('#scalev').hide();
$('#ruler').hide();
$('#rulerg').hide();
$('#notice').hide();
$('#trajectoryWidth').hide();
$('#application').hide();
$('#applicationReference').hide();
$('#scaleh').show();
$('#scalev').show();
$('#trajectoryWidth').show();
$('#ruler').show();
$('#notice').show();
for (let facility in gofData) {
if (typeof $('#'+facility+"_gofhor").attr('visibility') != 'undefined') {
$('#'+facility+"_gof"+(params.gof=='corr'? '': params.gof)+"hor").attr('visibility', "visible");
$('#'+facility+"_gof"+(params.gof=='corr'? '': params.gof)+"ver").attr('visibility', "visible");
if (typeof gofData[facility] == 'undefined' || typeof gofData[facility][params.gof+'Map'] == 'undefined') continue;
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
gofData.oldIndex = facility;
gofRead(gofData, params);
}
displayer = setInterval(gofDisplay, gofDisplayerPeriod, params);
if (gofTimeout) {
setTimeout(gofRead, gofTimeout, gofData, params);
}
else {
gofData.reader = setInterval(gofRead, gofPeriod, gofData, params);
}
$('.gofhor').css('display', 'block');
$('.gofver').css('display', 'block');
gofFactorHor = localStorage.getItem('scale'+gof+'hor')!=null? localStorage.getItem('scale'+gof+'hor')-0: gofFactorsHor[menuParams.gof]*1000;
gofFactorVer = localStorage.getItem('scale'+gof+'ver')!=null? localStorage.getItem('scale'+gof+'ver')-0: gofFactorsVer[menuParams.gof]*1000;
if (gofScaleType == 'slider') {
const fHor = gofFactorHor/1000;
menuParams['scale H'] = fHor;
const mxHor = Math.pow(10, Math.floor(Math.log10(fHor))+1);
gofScaleHor.max(mxHor);
gofScaleHor.min(mxHor/100);
gofScaleHor.step(mxHor/1000);
gofScaleHor.setValue(fHor);
const fVer = gofFactorVer/1000;
menuParams['scale V'] = fVer;
const mxVer = Math.pow(10, Math.floor(Math.log10(fVer))+1);
gofScaleVer.max(mxVer);
gofScaleVer.min(mxVer/100);
gofScaleVer.step(mxVer/1000);
gofScaleVer.setValue(fVer);
}
else {
document.getElementById("horgauge").contentWindow.maxval = Math.pow(10, Math.floor(Math.log10(gofFactorsHor[params.gof]))+2);
document.getElementById("horgauge").contentWindow.reset();
document.getElementById("horgauge").contentWindow.setVal(gofFactorsHor[params.gof]);
document.getElementById("vergauge").contentWindow.maxval = Math.pow(10, Math.floor(Math.log10(gofFactorsVer[params.gof]))+2);
document.getElementById("vergauge").contentWindow.reset();
document.getElementById("vergauge").contentWindow.setVal(gofFactorsVer[params.gof]);
$('.gofgauge').show();
}
gPos = $("#fps").children().eq(1).children()[0].getBoundingClientRect();
$('#fpsr').css('left', gPos.left);
$('#fpsr').css('top', gPos.top+gPos.height-3);
const horIndex = gof=='corr'? 0: 2;
const verIndex = gof=='corr'? 1: 3;
gofDataHor = [];
gofDataVer = [];
let refHor, refVer;
const referencehor = JSON.parse(localStorage.getItem('reference'+gof+'hor'));
const referencever = JSON.parse(localStorage.getItem('reference'+gof+'ver'));
$('#hor_set').css('background-color',localStorage.getItem('reference'+gof+'hor')!=null?'red':'');
$('#ver_set').css('background-color',localStorage.getItem('reference'+gof+'ver')!=null?'green':'');
if ((gof!='') && gb[horIndex]) {
const valh = gb[horIndex].split(',');
const valv = gb[verIndex].split(',');
console.log('gofRender(), valh, valv', valh, valv, gof, compData[facility].bpmMap);
if (gof=='corr' && typeof compData[facility].corrMap[i] == 'undefined') continue;
if (gof=='bpm' && typeof compData[facility].bpmMap[i] == 'undefined') continue;
const j = gof=='bpm'? compData[facility].bpmMap[i]: compData[facility].corrMap[i];
if (document.location.search.indexOf('pulse=')>-1 && i!=document.location.search.split('pulse=')[1].split('&')[0]) {valh[i] = 0;}
const pos = compData[facility].pos[j];
if (pos==null) continue;
const beta = Math.PI*compData[facility].dir[j]/180;
const vh = localStorage.getItem('reference'+gof+'hor')==null? valh[i]-0: valh[i] - referencehor[i];
// https://en.wikipedia.org/wiki/Logarithmic_scale#Extensions
const valHor = gofLogScaleHor? Math.sign(vh)*Math.log10(1+ Math.abs(vh*Math.LN10)): vh;
const vv = localStorage.getItem('reference'+gof+'ver')==null? valv[i]-0: valv[i] - referencever[i];
const valVer = gofLogScaleVer? Math.sign(vv)*Math.log10(1+ Math.abs(vv*Math.LN10)): vv;
gofDataHor.push((gofDataHor.length==0?'M':'L')+
Math.round(pos[0] - valHor*gofFactorHor*Math.sin(beta)) + ' ' +
Math.round(pos[1] + valHor*gofFactorHor*Math.cos(beta))
);
gofDataVer.push((gofDataVer.length==0?'M':'L')+
Math.round(pos[0] - valVer*gofFactorVer*Math.sin(beta)) + ' ' +
Math.round(pos[1] + valVer*gofFactorVer*Math.cos(beta))
);
}
// console.log('Hor', gofDataHor.join(' ')+(lattice[facility].sections[0].chamber?' Z':''));
$('#'+facility+"_gofbpmhor").attr('d', gofDataHor.join(' ').replaceAll('LNaN NaN L','L')+(lattice[facility].sections[0].chamber?' Z':''));
$('#'+facility+"_gofbpmver").attr('d', gofDataVer.join(' ').replaceAll('LNaN NaN L','L')+(lattice[facility].sections[0].chamber?' Z':''));
}
else {
$('#'+facility+"_gofhor").attr('d', gofDataHor.join(' ')+(lattice[facility].sections[0].chamber?' Z':''));
$('#'+facility+"_gofver").attr('d', gofDataVer.join(' ')+(lattice[facility].sections[0].chamber?' Z':''));
}
}
}
function gofDisplay(params) {
if (gofBuffer==false) return;
gofRender('sr', gofBuffer, params.gof);
$('#delay').html((new Date() - gofDataTs));
}
if (document.location.search.indexOf('nostats')==-1) {
$('#notice').show();
$('#notice').css('color', 'orange');
$('#notice').html('<table style="font-size: 60%"><tr><td colspan="4" style="font-size: 150%" id="lt"></td></tr><tr><td style="width: 50%;">last refresh</td><td style="width: 50%; text-align: right;" id="requiredt"></td></tr><tr><td style="width: 50%;">delay</td><td style="width: 50%; text-align: right;" id="delay"></td></tr></table>');
}
function gofRead(gofData, params) {
// console.log('fetch()',conf.gofUrl+'¶m='+params.gof);
const gofOldSt = gofSt;
if (gofFps<30) $('#fpsr').css('min-width', gofFps/20*gPos.width);
$('#lt').html(gofSt.getFullYear()+'-'+pad(gofSt.getMonth()+1, 2)+'-'+pad(gofSt.getDate(), 2)+' '+pad(gofSt.getHours(), 2)+':'+pad(gofSt.getMinutes(), 2)+':'+pad(gofSt.getSeconds(), 2));
fetch((conf.gofUrl+'&machine='+machine+'¶m='+params.gof).replace('?&','?'), {cache: "no-store"})
.then((response) => {return response.text();})
.then((eventData) => {
if (document.location.search.indexOf('nostats')==-1) {
const lt = new Date();
const requiredt = new Date() - gofSt;
gofDataTs = eventData.split(':')[0];
$('#requiredt').html(requiredt);
$('#delay').html(lt - gofDataTs);
}
gofBuffer = eventData.split(':')[1].split(';');
const gofMinPeriod = 1000/gofMaxFps;
const elapsed = new Date() - gofSt;
const gp = gofMinPeriod-elapsed > gofTimeout? gofMinPeriod-elapsed: gofTimeout;
if (params.gof!='') setTimeout(gofRead, gp, gofData, params);
})
.catch((err) => {
const gofMinPeriod = 1000/gofMaxFps;
const elapsed = new Date() - gofSt;
const gp = gofMinPeriod-elapsed > gofTimeout? gofMinPeriod-elapsed: gofTimeout;
if (params.gof!='') setTimeout(gofRead, gp, gofData, params);