Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// jshint esversion: 6
const blm = {obj: [], dir: []};
function blmMenu(lattice, facilities, params) {
params.blm = false;
if (document.location.search.indexOf('blm')>-1) {params.blm = document.location.search.indexOf('blm')>-1; blmSwitch(blm, params);}
gui.add(params, 'blm').onChange(function() {blmSwitch(blm, params);});
blm.map = [];
// console.log('blmMenu(), src', conf.blmSrcUrl);
fetch((conf.blmSrcUrl.indexOf('http')==-1? conf.rchan: '')+conf.blmSrcUrl)
.then((response) => {return response.json();})
.then((blmData) => {
// console.log('blmMenu(), blmData', blmData);
let blmCounter = 0;
for (let i in blmData) {
const name = blmData[i].split('/')[2].toUpperCase();
// console.log('blmMenu(), name', name);
// if (name.indexOf(blm.skip)>-1) continue; // blm skip feature
for (let bl in blm.obj) {
// console.log('bl', bl, blm.obj);
if (name==blm.obj[bl] || name=='BLM_'+blm.obj[bl]) {blm.map[bl] = blmCounter; blmCounter++;}
}
}
});
}
function blmSwitch(blm, params) {
if (blm.reader !== false) clearInterval(blm.reader);
blm.reader = false;
// $('.blm').css('display', 'none');
if (blm.reader) $('.blm').show(); else $('.blm').hide();
if (typeof blm[blm.oldIndex] != 'undefined') for (let i=0; i<blm[blm.oldIndex].obj.length; i++) blmUpdate(blm[blm.oldIndex].obj[i], 0);
if (params.blm=='') {
$('#application').hide();
$('#applicationFrame').removeAttr("src");
}
else {
blm.oldIndex = params.blm;
blmRead(blm, params);
blm.reader = setInterval(blmRead, 997, blm, params);
$('.blm').show(); // $('#application').show();
// $('.blm.'+params.blm).css('display', 'block');
$('#applicationFrame').attr("src", "/spa/index.html?s=blm&src="+params.blm+(document.location.search.indexOf('demo')>-1? '&demo': ''));
$("#applicationFrame").height(window.innerHeight);
}
}
function blmRender() {
// console.log('blmRender()', blm);
const blmMax = Math.max.apply(null, blm.val.map(Math.abs)); // https://stackoverflow.com/questions/29515761/find-absolute-max-value-in-javascript-array
let blmPeak = (Math.log10(blmMax) + 2) * 5000;
blmPeak = blmPeak>20000? 20000: (blmPeak<2000? 2000: blmPeak);
const blmFactor = blmPeak/blmMax;
// console.log(blm.obj[i], blm.val[blm.map[i]], blm.dir[i], 100, blmFactor);
for (let i=0; i<blm.obj.length; i++) {
// console.log(blm.obj[i], blm.val[blm.map[i]], blm.dir[i], 100, blmFactor);
blmUpdate(blm.obj[i], blm.val[blm.map[i]], blm.dir[i], 100, blmFactor);
}
// if (params.blm) {blmLabel(blm, params, camera, THREE);}
}
function blmRead(blm, params) {
fetch((conf.blmUrl.indexOf('http')==-1? conf.rchan: '')+conf.blmUrl)
.then((response) => {return response.json();})
.then((eventData) => {
blm.val = eventData;
blmRender();
});
}
function blmColor(val) {
if (document.location.search.indexOf('demo')>-1) {
if (val < 0) return 'white';
else if (val < 1) return 'yellow';
else if (val < 2) return 'orange';
else if (val < 3) return 'red';
else return 'violet';
}
if (val < 20) return 'white';
else if (val < 50) return 'yellow';
else if (val < 100) return 'orange';
else if (val < 200) return 'red';
else return 'violet';
}
function blmUpdate(c, val, direction, width, blmFactor) {
// console.log('blmUpdate()', c, val, direction, width, blmFactor);
if (typeof val !== 'undefined' && typeof blmFactor !== 'undefined') {
document.getElementById(c).height.baseVal.value = Math.abs(val*blmFactor);
document.getElementById(c).style.fill = blmColor(val);
}
else {
document.getElementById(c).height.baseVal.value = Math.abs(40);
document.getElementById(c).style.fill = 'black';
}
}