From 9a73e56bd79ae3862f8337f0d43bb8236a282443 Mon Sep 17 00:00:00 2001
From: Lucio Zambon <lucio.zambon@elettra.eu>
Date: Thu, 23 Jan 2025 15:36:15 +0000
Subject: [PATCH] Update panther2d.js

---
 panther2d.js | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/panther2d.js b/panther2d.js
index a8976eb..0937f71 100644
--- a/panther2d.js
+++ b/panther2d.js
@@ -32,10 +32,12 @@
 	for (let i=0; i<pa.length; i++) {const p = pa[i].split('='); parameters[p[0]] = p[1];}
 	const machineCaseSensitive = document.location.search.indexOf('machine=')>-1? document.location.search.split('machine=')[1].split('&')[0]: 'elettra';
 	const machine = machineCaseSensitive.toLowerCase();
+	const backgroundColor = document.location.search.indexOf('backgroundColor=')>-1? document.location.search.split('backgroundColor=')[1].split('&')[0]: '#333333';
+	$('body').css('backgroundColor', backgroundColor);
 	let measurementStart = false;
 	let cx, cy;
 	let measurementType = document.location.search.indexOf('measurement=')>-1? document.location.search.split('measurement=')[1].split('&')[0].split(','): document.location.search.indexOf('measurement')>-1;
-	let measurementEvent = 'contextmenu';
+	let hidecomponents = document.location.search.indexOf('hidecomponents=')>-1? document.location.search.split('hidecomponents=')[1].split('&')[0].split(','): false;
 	if (typeof measurementType == "object") {
 		const index = measurementType.indexOf('left'); 
 		if (index>-1) {
@@ -291,7 +293,7 @@
 	}
 	let latticeFile = document.location.href.split('?')[0].split('/').slice(0,-1).join('/')+'/'+machine+'_lattice.json';
 	if (machine.indexOf('simulator_')>-1) {latticeFile = document.location.href.split('?')[0].split('/').slice(0,-1).join('/')+'/'+'simulator.php?lattice&machine='+machine.split('simulator_')[1];}
-	const menuParams = {machine: machineCaseSensitive.toLowerCase(), search: '', backgroundColor: '#333333'};
+	const menuParams = {machine: machineCaseSensitive.toLowerCase(), search: '', backgroundColor: backgroundColor};
 	gui.title('PAnTHer - controls');
 	// if (navigator.userAgent.indexOf('Firefox/63')>-1) {$( "body" ).append('<button id="starter" style="align: center;height: 500px; width: 95%;background-color: #449944; font-size: 100px;" onClick="mystart()">START</button>');}
 	function mystart() {
@@ -469,8 +471,8 @@
 	}
 	function initShortcut(lattice) {
 		const index = [];
-		for (let l in lattice.conf.shortcut2d) {
-			const cmd = "document.location = document.location.pathname + '?"+lattice.conf.shortcut2d[l]+"';";
+		for (let l in lattice.conf.shortcut['2d']) {
+			const cmd = "document.location = document.location.pathname + '?"+lattice.conf.shortcut['2d'][l]+"';";
 			index.push('<button onclick="'+cmd+'" id="'+l.toLowerCase().split(' ').join('')+'">'+l+'</button>');
 		}
 		$('body').append('<div style="position: absolute; left: 5px; bottom: 5px;">'+index.join(' ')+'</div>');
@@ -519,7 +521,7 @@
 				if (typeof blm != 'undefined') blmMenu(lattice, facilities, menuParams);
 				bpmInit(facilities); 
 				if (typeof bpmData != 'undefined') bpmMenu(lattice, facilities, menuParams);
-				if (lattice.conf && lattice.conf.shortcut2d) initShortcut(lattice);
+				if (lattice.conf && lattice.conf.shortcut && lattice.conf.shortcut["2d"]) initShortcut(lattice);
 				if (lattice.conf && lattice.conf.index) initIndex(lattice);
 			}
 			$('.scale').attr('transform', "scale(2)");
@@ -564,6 +566,7 @@
 				const zoom = document.location.search.indexOf('zoom=')>-1? document.location.search.split('zoom=')[1].split('&')[0]-0: default_zoom;
 				panZoomPanther.zoom(zoom);
 				setTimeout(panZoomPanther.pan, 600, {x: pan[0], y: pan[1]});
+				setTimeout(myZoom, 1000, zoom, zoom);
 			}
 			if (state) {
 				fetch(conf.stateSrcUrl, {cache: "no-store"}).then((response) => {return response.text();}).then((data) => {
@@ -613,6 +616,7 @@
 			gui.add(menuParams, 'gotoAdmin').name('Admin');
 			menuParams.goto3D =  function() {document.location = './panther.php?machine='+menuParams.machine;}; 
 			gui.add(menuParams, 'goto3D').name('3D');
+			// if (document.location.search.indexOf('expandbl')>-1) $('#blBtn').click();
 		});
 	}
 	function showStatus(i, stat) {
@@ -863,7 +867,9 @@
 				const compid = comp + (components[i].length > 0 && $('#'+comp+'_'+components[i].length)[0]? '_'+components[i].length: '');
 				const aka = components[i].alias && components[i].alias.length? components[i].alias: [];
 				const compClass = typeof components[i].class == 'undefined'? '': ' '+components[i].class;
-				appendSvg("use", {href:"#"+compid, id: id[0], name:components[i].name, "data-embedded":components[i].embedded, "data-aka": aka, class: comp+' '+section+facility+compClass, style:"cursor: pointer", transform:transform}, openTooltip);
+				const attr = {href:"#"+compid, id: id[0], name:components[i].name, "data-embedded":components[i].embedded, "data-aka": aka, class: comp+' '+section+facility+compClass, style:"cursor: pointer", transform:transform};
+				if (hidecomponents && (hidecomponents.indexOf(comp)>-1 || hidecomponents[0]=='*')) attr.visibility = 'hidden';
+				appendSvg("use", attr, openTooltip);
 				if (components[i].type == 'label' || components[i].type == 'beamlineDown' || components[i].type == 'beamlineUp') 
 					appendLabel2(components[i], section+facility, 'none', x, y, beta, components[i].labelReverse);
 				else
@@ -993,7 +999,9 @@
 				const section = sections[i].bending.name.indexOf('_')>-1? sections[i].bending.name.split('_')[1].split('.')[0]+' ': '';
 				const comp = sections[i].bending.type.replace('dipolefermi','bending');
 				const compid = comp + (sections[i].bending.length > 0 && $('#'+comp+'_'+sections[i].bending.length)[0]? '_'+sections[i].bending.length: '');
-				appendSvg("use", {href:"#"+compid, id:sections[i].bending.name.replace('.','_'), class: 'bending '+section+facility, style:"cursor: pointer", transform:"translate("+rescale(sections[i].start.x)+" "+rescale(sections[i].start.z)+") rotate("+gamma+") translate(-600 -200)"}, openTooltip);
+				const attr = {href:"#"+compid, id:sections[i].bending.name.replace('.','_'), class: 'bending '+section+facility, style:"cursor: pointer", transform:"translate("+rescale(sections[i].start.x)+" "+rescale(sections[i].start.z)+") rotate("+gamma+") translate(-600 -200)"};
+				if (hidecomponents && (hidecomponents.indexOf(comp)>-1 || hidecomponents[0]=='*')) attr.visibility = 'hidden';
+				appendSvg("use", attr, openTooltip);
 				appendLabel(sections[i].bending.name, 'bending '+section+facility, 'block', sections[i].start.x, sections[i].start.z, gamma+180, sections[i].bending.labelReverse);
 			}
 			alpha = beta;
-- 
GitLab