From d4e32e3f2d51b136bd73b4c932e633eadea6241e Mon Sep 17 00:00:00 2001 From: GTripathee Date: Wed, 18 Feb 2026 13:05:55 +0100 Subject: [PATCH 1/5] value view element has visibility option. --- .../ViewDescriptors/ValueViewDescriptor.swift | 65 ++++++++++++------- phyphox-iOS/phyphox/Info.plist | 2 +- 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ValueViewDescriptor.swift b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ValueViewDescriptor.swift index c1ef8ae1..7ab572fa 100644 --- a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ValueViewDescriptor.swift +++ b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ValueViewDescriptor.swift @@ -125,30 +125,36 @@ struct ValueViewDescriptor: ViewDescriptor, Equatable { } } - return "function (data) {" + - " if (!data.hasOwnProperty(\"\(bufferName)\"))" + - " return;" + - " var x = data[\"\(bufferName)\"][\"data\"][data[\"\(bufferName)\"][\"data\"].length-1];" + - " var v = null;" + - mappingCode + + let unitCode = setUnit() + let formatCode = setFormatedCoordinate() + let asciiCode = setAsciiFormat(bufferName: bufferName) + let visibilityCode = setVisibility(id, visibilityBuffer?.name ?? "") - "\(setUnit())" + - - "\(setFormatedCoordinate())" + + let dataSetupFunction = """ + function (data) { + if (!data.hasOwnProperty(\"\(bufferName)\")) + return; + var x = data[\"\(bufferName)\"][\"data\"][data[\"\(bufferName)\"][\"data\"].length-1]; + var v = null; + \(mappingCode) + \(unitCode) + \(formatCode) + \(asciiCode) + var valueElement = document.getElementById(\"element\(id)\").getElementsByClassName(\"value\")[0]; + var valueNumber = valueElement.getElementsByClassName(\"valueNumber\")[0]; + var valueUnit = valueElement.getElementsByClassName(\"valueUnit\")[0]; + if (v == null) { + v = x; + valueUnit.textContent = unitLabel; + } else { + valueUnit.textContent = \"\"; + } + valueNumber.textContent = v; + \(visibilityCode) + } + """ - "\(setAsciiFormat(bufferName: bufferName))" + - - " var valueElement = document.getElementById(\"element\(id)\").getElementsByClassName(\"value\")[0];" + - " var valueNumber = valueElement.getElementsByClassName(\"valueNumber\")[0];" + - " var valueUnit = valueElement.getElementsByClassName(\"valueUnit\")[0];" + - " if (v == null) {" + - " v = x;" + - " valueUnit.textContent = unitLabel;" + - " } else { " + - " valueUnit.textContent = \"\";" + - " } " + - " valueNumber.textContent = v;" + - "}" + return dataSetupFunction } func setUnit() -> String { @@ -208,4 +214,19 @@ struct ValueViewDescriptor: ViewDescriptor, Equatable { } """ } + + func setVisibility(_ id: Int, _ visibilityLabel: String) -> String { + if visibilityLabel.isEmpty { return "" } + return """ + if (data.hasOwnProperty(\"\(visibilityLabel)\")) { + var elementVisibilityIndicator = data[\"\(visibilityLabel)\"][\"data\"][data[\"\(visibilityLabel)\"][\"data\"].length-1]; + var valueMainElement = document.getElementById(\"element\(id)\"); + if (elementVisibilityIndicator <= 0.0 || elementVisibilityIndicator.length == 0) { + valueMainElement.style.display = "none"; + } else { + valueMainElement.style.display = "block"; + } + """ + } } + diff --git a/phyphox-iOS/phyphox/Info.plist b/phyphox-iOS/phyphox/Info.plist index 89681c0a..6306b0bd 100644 --- a/phyphox-iOS/phyphox/Info.plist +++ b/phyphox-iOS/phyphox/Info.plist @@ -52,7 +52,7 @@ CFBundleVersion - 17276 + 17278 LSRequiresIPhoneOS LSSupportsOpeningDocumentsInPlace From 8fa8597c82cb3266bba6bb1391936d254dabe76d Mon Sep 17 00:00:00 2001 From: GTripathee Date: Wed, 18 Feb 2026 13:09:08 +0100 Subject: [PATCH 2/5] add parent uupdatemode for visiblity as single. --- .../phyphox/Experiments/ViewDescriptors/ViewDescriptor.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ViewDescriptor.swift b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ViewDescriptor.swift index 64b3c19d..faa88279 100644 --- a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ViewDescriptor.swift +++ b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ViewDescriptor.swift @@ -21,6 +21,10 @@ extension ViewDescriptor { var localizedLabel: String { return translation?.localizeString(label) ?? label } + + func getVisibilityUpdateMode() -> String { + return "single" + } func generateDataCompleteHTMLWithID(_ id: Int) -> String { return "function() {}" From 9e839670c04e55811314560bb83ee2a9ea8bc903 Mon Sep 17 00:00:00 2001 From: GTripathee Date: Wed, 18 Feb 2026 14:17:18 +0100 Subject: [PATCH 3/5] add visibility code to all the web view elements- --- .../ButtonViewDescriptor.swift | 20 ++++++++++++++ .../CameraViewDescriptor.swift | 20 ++++++++++++++ .../ViewDescriptors/DepthGUIDescriptor.swift | 20 ++++++++++++++ .../DropdownViewDescriptor.swift | 22 ++++++++++++++++ .../ViewDescriptors/EditViewDescriptor.swift | 26 ++++++++++++++++++- .../ViewDescriptors/GraphViewDescriptor.swift | 23 ++++++++++++++++ .../ViewDescriptors/ImageViewDescriptor.swift | 20 ++++++++++++++ .../ViewDescriptors/InfoViewDescriptor.swift | 20 ++++++++++++++ .../SliderViewDescriptor.swift | 26 +++++++++++++++++-- 9 files changed, 194 insertions(+), 3 deletions(-) diff --git a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ButtonViewDescriptor.swift b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ButtonViewDescriptor.swift index d500f0e9..6ce1d129 100644 --- a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ButtonViewDescriptor.swift +++ b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ButtonViewDescriptor.swift @@ -77,7 +77,27 @@ struct ButtonViewDescriptor: ViewDescriptor, Equatable { mappingCode + " else {v = \"\(localizedLabel)\";}" + " var valueNumber = document.getElementById(\"element\(id)\").getElementsByClassName(\"valueNumber\")[0];" + " valueNumber.textContent = v;" + + " \(setVisiblity(id))" + "}" } + + func setVisiblity(_ id: Int) -> String { + + guard let visibilityLabel = visibilityBuffer?.name else { + return "" + } + + return """ + if (data.hasOwnProperty(\"\(visibilityLabel)\")) {" + var elementVisibilityIndicator = data[\"\(visibilityLabel)\"][\"data\"][data[\"\(visibilityLabel)\"][\"data\"].length-1]; + var buttonElement = document.getElementById(\"element\(id)\"); + if (elementVisibilityIndicator <= 0.0 || elementVisibilityIndicator.length == 0) { + buttonElement.style.display = \"none\"; + } else { + buttonElement.style.display = \"block\"; + } + } + """ + } } diff --git a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/CameraViewDescriptor.swift b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/CameraViewDescriptor.swift index f425c13c..7f666720 100644 --- a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/CameraViewDescriptor.swift +++ b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/CameraViewDescriptor.swift @@ -34,4 +34,24 @@ struct CameraViewDescriptor: ViewDescriptor, Equatable { let warningText = localize("remoteCameraWarning").replacingOccurrences(of: "\"", with: "\\\"") return "
\(localizedLabel)
" } + + func setDataHTMLWithID(_ id: Int) -> String { + guard let visibilityLabel = visibilityBuffer?.name else { + return "" + } + + return """ + function (data) { + if (data.hasOwnProperty(\"\(visibilityLabel)\")) { + var x = data[\"\(visibilityLabel)\"][\"data\"][data[\"\(visibilityLabel)\"][\"data\"].length-1]; + var cameraElement = document.getElementById(\"element\(id)\"); + if (x <= 0.0 || x.length == 0) { + cameraElement.style.display = \"none\"; + } else { + cameraElement.style.display = \"block\"; + } + } + } + """ + } } diff --git a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/DepthGUIDescriptor.swift b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/DepthGUIDescriptor.swift index c7954ed5..4977d856 100644 --- a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/DepthGUIDescriptor.swift +++ b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/DepthGUIDescriptor.swift @@ -26,4 +26,24 @@ struct DepthGUIViewDescriptor: ViewDescriptor, Equatable { let warningText = localize("remoteDepthGUIWarning").replacingOccurrences(of: "\"", with: "\\\"") return "
\(localizedLabel)
" } + + func setDataHTMLWithID(_ id: Int) -> String { + guard let visibilityLabel = visibilityBuffer?.name else { + return "" + } + + return """ + function (data) { + if (data.hasOwnProperty(\"\(visibilityLabel)\")) { + var x = data[\"\(visibilityLabel)\"][\"data\"][data[\"\(visibilityLabel)\"][\"data\"].length-1]; + var depthGuiElement = document.getElementById(\"element\(id)\"); + if (x <= 0.0 || x.length == 0) { + depthGuiElement.style.display = \"none\"; + } else { + depthGuiElement.style.display = \"block\"; + } + } + } + """ + } } diff --git a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/DropdownViewDescriptor.swift b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/DropdownViewDescriptor.swift index eb376d85..6cacf28f 100644 --- a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/DropdownViewDescriptor.swift +++ b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/DropdownViewDescriptor.swift @@ -92,11 +92,33 @@ struct DropdownViewDescriptor: ViewDescriptor, Equatable { dropdownElement.selectedIndex = 0 } + \(setVisiblity(id)) + } """ } + func setVisiblity(_ id: Int) -> String { + + guard let visibilityLabel = visibilityBuffer?.name else { + return "" + } + + return """ + if (data.hasOwnProperty(\"\(visibilityLabel)\")) { + var elementVisibilityIndicator = data[\"\(visibilityLabel)\"][\"data\"][data[\"\(visibilityLabel)\"][\"data\"].length-1]; + var dropDownElement = document.getElementById(\"element\(id)\"); + if (elementVisibilityIndicator <= 0.0 || elementVisibilityIndicator.length == 0) { + dropDownElement.style.display = \"none\"; + } else { + dropDownElement.style.display = \"block\"; + } + } + + """ + } + } diff --git a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/EditViewDescriptor.swift b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/EditViewDescriptor.swift index 4de2220b..bf376184 100644 --- a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/EditViewDescriptor.swift +++ b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/EditViewDescriptor.swift @@ -73,15 +73,39 @@ struct EditViewDescriptor: ViewDescriptor, Equatable { func setDataHTMLWithID(_ id: Int) -> String { let bufferName = buffer.name.replacingOccurrences(of: "\"", with: "\\\"") + + return "function (data) {" + "var valueElement = document.getElementById(\"element\(id)\").getElementsByClassName(\"value\")[0];" + "if (!data.hasOwnProperty(\"\(bufferName)\"))" + " return;" + "var x = data[\"\(bufferName)\"][\"data\"][data[\"\(bufferName)\"][\"data\"].length-1];" + - "console.log(\"editElement buffer value is \" +x);" + + "if (valueElement !== document.activeElement)" + " valueElement.value = (x*\(factor))" + + + "\(setVisiblity(id))" + "}" } + + func setVisiblity(_ id: Int) -> String { + + guard let visibilityLabel = visibilityBuffer?.name else { + return "" + } + + return """ + if (data.hasOwnProperty(\"\(visibilityLabel)\")) { + var editElement = document.getElementById(\"element\(id)\"); + var elementVisibilityIndicator = data[\"\(visibilityLabel)\"][\"data\"][data[\"\(visibilityLabel)\"][\"data\"].length-1]; + + if (elementVisibilityIndicator <= 0.0 || elementVisibilityIndicator.length == 0) { + editElement.style.display = \"none\"; + } else { + editElement.style.display = \"block\"; + } + } + """ + } } diff --git a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/GraphViewDescriptor.swift b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/GraphViewDescriptor.swift index b56daa5c..e44b501e 100644 --- a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/GraphViewDescriptor.swift +++ b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/GraphViewDescriptor.swift @@ -586,7 +586,30 @@ struct GraphViewDescriptor: ViewDescriptor, Equatable { } code += "}" + code += setVisiblity(id) + return code } + func setVisiblity(_ id: Int) -> String { + + guard let visibilityLabel = visibilityBuffer?.name else { + return "" + } + + return """ + if (data.hasOwnProperty(\"\(visibilityLabel)\")) { + var elementVisibilityIndicator = data[\"\(visibilityLabel)\"][\"data\"][data[\"\(visibilityLabel)\"][\"data\"].length-1]; + var graphElement = document.getElementById(\"element\(id)\"); + if (elementVisibilityIndicator <= 0.0 || elementVisibilityIndicator.length == 0) { + graphElement.style.display = \"none\"; + if ((graphElement.classList && graphElement.classList.contains(\"exclusive\")) || (graphElement.className.indexOf(\"exclusive\") > -1)) {; + leaveExclusive(); } + } else { + graphElement.style.display = \"block\"; + } + } + """ + } + } diff --git a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ImageViewDescriptor.swift b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ImageViewDescriptor.swift index 6e3a8c32..d4686bfd 100644 --- a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ImageViewDescriptor.swift +++ b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ImageViewDescriptor.swift @@ -34,4 +34,24 @@ struct ImageViewDescriptor: ResourceViewDescriptor, Equatable { return "

" } + func setDataHTMLWithID(_ id: Int) -> String { + guard let visibilityLabel = visibilityBuffer?.name else { + return "" + } + + return """ + function (data) { + if (data.hasOwnProperty(\"\(visibilityLabel)\")) { + var x = data[\"\(visibilityLabel)\"][\"data\"][data[\"\(visibilityLabel)\"][\"data\"].length-1]; + var imageElement = document.getElementById(\"element\(id)\"); + if (x <= 0.0 || x.length == 0) { + imageElement.style.display = \"none\"; + } else { + imageElement.style.display = \"block\"; + } + } + } + """ + } + } diff --git a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/InfoViewDescriptor.swift b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/InfoViewDescriptor.swift index c8419457..090bd35d 100644 --- a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/InfoViewDescriptor.swift +++ b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/InfoViewDescriptor.swift @@ -32,4 +32,24 @@ struct InfoViewDescriptor: ViewDescriptor, Equatable { func generateViewHTMLWithID(_ id: Int) -> String { return "

\(localizedLabel)

" } + + func setDataHTMLWithID(_ id: Int) -> String { + guard let visibilityLabel = visibilityBuffer?.name else { + return "" + } + + return """ + function (data) { + if (data.hasOwnProperty(\"\(visibilityLabel)\")) { + var x = data[\"\(visibilityLabel)\"][\"data\"][data[\"\(visibilityLabel)\"][\"data\"].length-1]; + var infoElement = document.getElementById(\"element\(id)\"); + if (x <= 0.0) { + infoElement.style.display = \"none\"; + } else { + infoElement.style.display = \"block\"; + } + } + } + """ + } } diff --git a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/SliderViewDescriptor.swift b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/SliderViewDescriptor.swift index 802a603a..f3fc1419 100644 --- a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/SliderViewDescriptor.swift +++ b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/SliderViewDescriptor.swift @@ -59,7 +59,7 @@ struct SliderViewDescriptor: ViewDescriptor, Equatable { let minValueFormatted = numberFormatter(for: minValue) let maxValueFormatted = numberFormatter(for: maxValue) - let defaultValueFormatted = numberFormatter(for: defaultValue ?? 0.0) + let defaultValueFormatted = numberFormatter(for: defaultValue) let bufferName = outputBuffers[.Empty]?.name ?? "" @@ -73,7 +73,7 @@ struct SliderViewDescriptor: ViewDescriptor, Equatable { private func generateTwoSlidersHTML(_ id: Int) -> String{ let minValueFormatted = numberFormatter(for: minValue) let maxValueFormatted = numberFormatter(for: maxValue) - let defaultValueFormatted = numberFormatter(for: defaultValue ?? 0.0) + let defaultValueFormatted = numberFormatter(for: defaultValue) let valueTag = showValue ? "\(localizedLabel)" + "\(defaultValueFormatted)" : "" @@ -160,6 +160,8 @@ struct SliderViewDescriptor: ViewDescriptor, Equatable { sliderElement.classList.remove(\"isSliderUpdating\"); } }); + + \(setVisiblity(id)) } @@ -259,4 +261,24 @@ struct SliderViewDescriptor: ViewDescriptor, Equatable { } + func setVisiblity(_ id: Int) -> String { + + guard let visibilityLabel = visibilityBuffer?.name else { + return "" + } + + return """ + if (data.hasOwnProperty(\"\(visibilityLabel)\")) { + var elementVisibilityIndicator = data[\"\(visibilityLabel)\"][\"data\"][data[\"\(visibilityLabel)\"][\"data\"].length-1]; + var sliderElement = document.getElementById(\"element\(visibilityLabel)\"); + if (elementVisibilityIndicator <= 0.0 || elementVisibilityIndicator.length == 0) { + sliderElement.style.display = \"none\"; + } else { + sliderElement.style.display = \"block\"; + } + } + + """ + } + } From 5b7d096e8395430e4c2bd5b714fa0a699606eef9 Mon Sep 17 00:00:00 2001 From: GTripathee Date: Wed, 18 Feb 2026 17:10:26 +0100 Subject: [PATCH 4/5] fix some missings literals in the code. --- .../CameraViewDescriptor.swift | 1 - .../ViewDescriptors/DepthGUIDescriptor.swift | 1 - .../DropdownViewDescriptor.swift | 20 ++++++------- .../ViewDescriptors/GraphViewDescriptor.swift | 28 +++++++++---------- .../ViewDescriptors/ImageViewDescriptor.swift | 1 - .../SliderViewDescriptor.swift | 4 +-- .../SwitchViewDescriptor.swift | 20 ++++++++++++- .../ViewDescriptors/ValueViewDescriptor.swift | 1 + phyphox-iOS/phyphox/Info.plist | 2 +- 9 files changed, 45 insertions(+), 33 deletions(-) diff --git a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/CameraViewDescriptor.swift b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/CameraViewDescriptor.swift index 7f666720..30c10d6c 100644 --- a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/CameraViewDescriptor.swift +++ b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/CameraViewDescriptor.swift @@ -51,7 +51,6 @@ struct CameraViewDescriptor: ViewDescriptor, Equatable { cameraElement.style.display = \"block\"; } } - } """ } } diff --git a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/DepthGUIDescriptor.swift b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/DepthGUIDescriptor.swift index 4977d856..ec02f87f 100644 --- a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/DepthGUIDescriptor.swift +++ b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/DepthGUIDescriptor.swift @@ -43,7 +43,6 @@ struct DepthGUIViewDescriptor: ViewDescriptor, Equatable { depthGuiElement.style.display = \"block\"; } } - } """ } } diff --git a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/DropdownViewDescriptor.swift b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/DropdownViewDescriptor.swift index 6cacf28f..8903c0d1 100644 --- a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/DropdownViewDescriptor.swift +++ b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/DropdownViewDescriptor.swift @@ -102,20 +102,18 @@ struct DropdownViewDescriptor: ViewDescriptor, Equatable { func setVisiblity(_ id: Int) -> String { - guard let visibilityLabel = visibilityBuffer?.name else { - return "" - } + guard let visibilityLabel = visibilityBuffer?.name else { return "" } return """ if (data.hasOwnProperty(\"\(visibilityLabel)\")) { - var elementVisibilityIndicator = data[\"\(visibilityLabel)\"][\"data\"][data[\"\(visibilityLabel)\"][\"data\"].length-1]; - var dropDownElement = document.getElementById(\"element\(id)\"); - if (elementVisibilityIndicator <= 0.0 || elementVisibilityIndicator.length == 0) { - dropDownElement.style.display = \"none\"; - } else { - dropDownElement.style.display = \"block\"; - } - } + var elementVisibilityIndicator = data[\"\(visibilityLabel)\"][\"data\"][data[\"\(visibilityLabel)\"][\"data\"].length-1]; + var dropDownElement = document.getElementById(\"element\(id)\"); + if (elementVisibilityIndicator <= 0.0 || elementVisibilityIndicator.length == 0) { + dropDownElement.style.display = \"none\"; + } else { + dropDownElement.style.display = \"block\"; + } + } """ } diff --git a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/GraphViewDescriptor.swift b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/GraphViewDescriptor.swift index e44b501e..d6c993a1 100644 --- a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/GraphViewDescriptor.swift +++ b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/GraphViewDescriptor.swift @@ -584,31 +584,31 @@ struct GraphViewDescriptor: ViewDescriptor, Equatable { code += "elementData[\(id)][\"datasets\"][\(i)] = data[\"\(bufferName)\"];" } } - code += "}" code += setVisiblity(id) + code += "}" + return code } func setVisiblity(_ id: Int) -> String { - guard let visibilityLabel = visibilityBuffer?.name else { - return "" - } + guard let visibilityLabel = visibilityBuffer?.name else { return "" } return """ if (data.hasOwnProperty(\"\(visibilityLabel)\")) { - var elementVisibilityIndicator = data[\"\(visibilityLabel)\"][\"data\"][data[\"\(visibilityLabel)\"][\"data\"].length-1]; - var graphElement = document.getElementById(\"element\(id)\"); - if (elementVisibilityIndicator <= 0.0 || elementVisibilityIndicator.length == 0) { - graphElement.style.display = \"none\"; - if ((graphElement.classList && graphElement.classList.contains(\"exclusive\")) || (graphElement.className.indexOf(\"exclusive\") > -1)) {; - leaveExclusive(); } - } else { - graphElement.style.display = \"block\"; - } - } + var elementVisibilityIndicator = data[\"\(visibilityLabel)\"][\"data\"][data[\"\(visibilityLabel)\"][\"data\"].length-1]; + var graphElement = document.getElementById(\"element\(id)\"); + if (elementVisibilityIndicator <= 0.0 || elementVisibilityIndicator.length == 0) { + graphElement.style.display = \"none\"; + if ((graphElement.classList && graphElement.classList.contains(\"exclusive\")) || (graphElement.className.indexOf(\"exclusive\") > -1)) { + leaveExclusive(); + } + } else { + graphElement.style.display = \"block\"; + } + } """ } diff --git a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ImageViewDescriptor.swift b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ImageViewDescriptor.swift index d4686bfd..df962b3d 100644 --- a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ImageViewDescriptor.swift +++ b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ImageViewDescriptor.swift @@ -50,7 +50,6 @@ struct ImageViewDescriptor: ResourceViewDescriptor, Equatable { imageElement.style.display = \"block\"; } } - } """ } diff --git a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/SliderViewDescriptor.swift b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/SliderViewDescriptor.swift index f3fc1419..fdac5f88 100644 --- a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/SliderViewDescriptor.swift +++ b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/SliderViewDescriptor.swift @@ -263,9 +263,7 @@ struct SliderViewDescriptor: ViewDescriptor, Equatable { func setVisiblity(_ id: Int) -> String { - guard let visibilityLabel = visibilityBuffer?.name else { - return "" - } + guard let visibilityLabel = visibilityBuffer?.name else { return "" } return """ if (data.hasOwnProperty(\"\(visibilityLabel)\")) { diff --git a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/SwitchViewDescriptor.swift b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/SwitchViewDescriptor.swift index 95d84b75..68473f2a 100644 --- a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/SwitchViewDescriptor.swift +++ b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/SwitchViewDescriptor.swift @@ -58,10 +58,28 @@ struct SwitchViewDescriptor: ViewDescriptor, Equatable { var value = radioButton.checked ? 1.0 : 0.0; ajax('control?cmd=set&buffer=\(buffer.name)&value='+value); }; - } + \(setVisiblity(id)) + } """ } + + func setVisiblity(_ id: Int) -> String { + + guard let visibilityLabel = visibilityBuffer?.name else { return "" } + + return """ + if (data.hasOwnProperty(\"\(visibilityLabel)\")) {" + var elementVisibilityIndicator = data[\"\(visibilityLabel)\"][\"data\"][data[\"\(visibilityLabel)\"][\"data\"].length-1]; + var toggleElement = document.getElementById(\"element\(id)\"); + if (elementVisibilityIndicator <= 0.0 || elementVisibilityIndicator.length == 0) { + toggleElement.style.display = \"none\"; + } else { + toggleElement.style.display = \"block\"; + } + } + """ + } } diff --git a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ValueViewDescriptor.swift b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ValueViewDescriptor.swift index 7ab572fa..7f5e760c 100644 --- a/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ValueViewDescriptor.swift +++ b/phyphox-iOS/phyphox/Experiments/ViewDescriptors/ValueViewDescriptor.swift @@ -226,6 +226,7 @@ struct ValueViewDescriptor: ViewDescriptor, Equatable { } else { valueMainElement.style.display = "block"; } + } """ } } diff --git a/phyphox-iOS/phyphox/Info.plist b/phyphox-iOS/phyphox/Info.plist index 6306b0bd..f32c04cc 100644 --- a/phyphox-iOS/phyphox/Info.plist +++ b/phyphox-iOS/phyphox/Info.plist @@ -52,7 +52,7 @@ CFBundleVersion - 17278 + 17285 LSRequiresIPhoneOS LSSupportsOpeningDocumentsInPlace From 8bbbebb6d722093bef4b8d1edee3457be4ee142d Mon Sep 17 00:00:00 2001 From: GTripathee Date: Mon, 16 Mar 2026 15:40:09 +0100 Subject: [PATCH 5/5] Update index file to accept extra parameters like visibilityUpdateMode and visibilityInput. --- phyphox-iOS/phyphox/Info.plist | 2 +- .../WebServer/ExperimentWebServer.swift | 2 + .../WebServer/WebServerUtilities.swift | 49 ++++++++++++++----- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/phyphox-iOS/phyphox/Info.plist b/phyphox-iOS/phyphox/Info.plist index f32c04cc..114417a5 100644 --- a/phyphox-iOS/phyphox/Info.plist +++ b/phyphox-iOS/phyphox/Info.plist @@ -52,7 +52,7 @@ CFBundleVersion - 17285 + 17296 LSRequiresIPhoneOS LSSupportsOpeningDocumentsInPlace diff --git a/phyphox-iOS/phyphox/UI/MainView/ExperimentView/WebServer/ExperimentWebServer.swift b/phyphox-iOS/phyphox/UI/MainView/ExperimentView/WebServer/ExperimentWebServer.swift index ae8e099e..8cf8f07a 100644 --- a/phyphox-iOS/phyphox/UI/MainView/ExperimentView/WebServer/ExperimentWebServer.swift +++ b/phyphox-iOS/phyphox/UI/MainView/ExperimentView/WebServer/ExperimentWebServer.swift @@ -225,6 +225,8 @@ final class ExperimentWebServer { if value.count > 0 { let raw = b.toArray() + dict["visibilityUpdateMode"] = "single" as AnyObject + if value == "full" || (value == "partial" && self.forceFullUpdate == true) { dict["updateMode"] = "full" as AnyObject dict["buffer"] = raw.map({$0.isFinite ? $0 as AnyObject : NSNull() as AnyObject}) as AnyObject //The array may contain NaN or Inf, which will throw an error in the JSON conversion. diff --git a/phyphox-iOS/phyphox/UI/MainView/ExperimentView/WebServer/WebServerUtilities.swift b/phyphox-iOS/phyphox/UI/MainView/ExperimentView/WebServer/WebServerUtilities.swift index 7efc917f..3809764b 100644 --- a/phyphox-iOS/phyphox/UI/MainView/ExperimentView/WebServer/WebServerUtilities.swift +++ b/phyphox-iOS/phyphox/UI/MainView/ExperimentView/WebServer/WebServerUtilities.swift @@ -116,28 +116,53 @@ final class WebServerUtilities { } updateMode = "partial" } - viewLayout += ", \"updateMode\": \"\(graph.partialUpdate ? updateMode : "full")\", \"dataInput\": [\(dataInput)], \"dataInputFunction\":\n\(graph.setDataHTMLWithID(idx))\n" + + var keyValuePairForVisibilityInput = "" + if let visibilityInput = graph.visibilityBuffer?.name { + keyValuePairForVisibilityInput += ", \"visibilityInput\": [\"\(visibilityInput)\"] " + } + + viewLayout += ", \"updateMode\": \"\(graph.partialUpdate ? updateMode : "full")\", \"visibilityUpdateMode\": \"single\" \(keyValuePairForVisibilityInput), \"dataInput\": [\(dataInput)] ,\"dataInputFunction\":\n\(graph.setDataHTMLWithID(idx))\n" } - else if element is InfoViewDescriptor { - viewLayout += ", \"updateMode\": \"none\"" + else if let info = element as? InfoViewDescriptor { + var keyValuePairForVisibilityInput = "" + if let visibilityInput = info.visibilityBuffer?.name { + keyValuePairForVisibilityInput += ", \"visibilityInput\": [\"\(visibilityInput)\"] " + } + + viewLayout += ", \"updateMode\": \"none\", \"visibilityUpdateMode\": \"single\" \(keyValuePairForVisibilityInput), \"dataInputFunction\":\n\(info.setDataHTMLWithID(idx))\n" } else if element is SeparatorViewDescriptor { - viewLayout += ", \"updateMode\": \"none\"" + viewLayout += ", \"updateMode\": \"none\", \"visibilityUpdateMode\": \"single\"" } else if let value = element as? ValueViewDescriptor { - viewLayout += ", \"updateMode\": \"\(value.updateMode())\", \"dataInput\":[\"\(value.buffer.name)\"], \"dataInputFunction\":\n\(value.setDataHTMLWithID(idx))\n" + var keyValuePairForVisibilityInput = "" + if let visibilityInput = value.visibilityBuffer?.name { + keyValuePairForVisibilityInput += ", \"visibilityInput\": [\"\(visibilityInput)\"] " + } + + viewLayout += ", \"updateMode\": \"\(value.updateMode())\", \"visibilityUpdateMode\": \"single\" \(keyValuePairForVisibilityInput), \"dataInput\":[\"\(value.buffer.name)\"], \"dataInputFunction\":\n\(value.setDataHTMLWithID(idx))\n" } else if let edit = element as? EditViewDescriptor { - viewLayout += ", \"updateMode\": \"input\", \"dataInput\":[\"\(edit.buffer.name)\"], \"dataInputFunction\":\n\(edit.setDataHTMLWithID(idx))\n" + var keyValuePairForVisibilityInput = "" + if let visibilityInput = edit.visibilityBuffer?.name { + keyValuePairForVisibilityInput += ", \"visibilityInput\": [\"\(visibilityInput)\"] " + } + viewLayout += ", \"updateMode\": \"input\", \"visibilityUpdateMode\": \"single\" \(keyValuePairForVisibilityInput), \"dataInput\":[\"\(edit.buffer.name)\"], \"dataInputFunction\":\n\(edit.setDataHTMLWithID(idx))\n" } else if let button = element as? ButtonViewDescriptor { - viewLayout += ", \"updateMode\": \"single\", \"dataInput\": [\"\(button.buffer?.name ?? "")\"], \"dataInputFunction\":\n\(button.setDataHTMLWithID(idx))\n " + var keyValuePairForVisibilityInput = "" + if let visibilityInput = button.visibilityBuffer?.name { + keyValuePairForVisibilityInput += ", \"visibilityInput\": [\"\(visibilityInput)\"] " + } + + viewLayout += ", \"updateMode\": \"single\", \"visibilityUpdateMode\": \"single\", \"visibilityInput\": [\"\(button.visibilityBuffer?.name ?? "")\"], \"dataInput\": [\"\(button.buffer?.name ?? "")\"], \"dataInputFunction\":\n\(button.setDataHTMLWithID(idx))\n " } else if let toggle = element as? SwitchViewDescriptor { - viewLayout += ", \"updateMode\": \"single\", \"dataInput\": [\"\(toggle.buffer.name)\"], \"dataInputFunction\":\n\(toggle.setDataHTMLWithID(idx))\n " + viewLayout += ", \"updateMode\": \"single\", \"visibilityUpdateMode\": \"single\", \"visibilityInput\": [\"\(toggle.visibilityBuffer?.name ?? "")\"], \"dataInput\": [\"\(toggle.buffer.name)\"], \"dataInputFunction\":\n\(toggle.setDataHTMLWithID(idx))\n " } else if let dropdown = element as? DropdownViewDescriptor { - viewLayout += ", \"updateMode\": \"single\", \"dataInput\": [\"\(dropdown.buffer.name)\"], \"dataInputFunction\":\n\(dropdown.setDataHTMLWithID(idx))\n " + viewLayout += ", \"updateMode\": \"single\", \"visibilityUpdateMode\": \"single\", \"visibilityInput\": [\"\(dropdown.visibilityBuffer?.name ?? "")\"], \"dataInput\": [\"\(dropdown.buffer.name)\"], \"dataInputFunction\":\n\(dropdown.setDataHTMLWithID(idx))\n " } else if let slider = element as? SliderViewDescriptor { var bufferName = "" @@ -149,10 +174,10 @@ final class WebServerUtilities { bufferName += "\"" + (slider.outputBuffers[.UpperValue]?.name ?? " ").replacingOccurrences(of: "\\", with: "\\\\").replacingOccurrences(of: "\"", with: "\\\"") + "\"" } - viewLayout += ", \"updateMode\": \"single\", \"dataInput\": [\(bufferName)], \"dataInputFunction\":\n\(slider.setDataHTMLWithID(idx))\n " + viewLayout += ", \"updateMode\": \"single\", \"visibilityUpdateMode\": \"single\", \"visibilityInput\": [\"\(slider.visibilityBuffer?.name ?? "")\"], \"dataInput\": [\(bufferName)], \"dataInputFunction\":\n\(slider.setDataHTMLWithID(idx))\n " } - else if element is ImageViewDescriptor { - viewLayout += ", \"updateMode\": \"none\"" + else if let image = element as? ImageViewDescriptor { + viewLayout += ", \"updateMode\": \"none\", \"visibilityUpdateMode\": \"single\", \"visibilityInput\": [\"\(image.visibilityBuffer?.name ?? "")\"], \"dataInputFunction\":\n\(image.setDataHTMLWithID(idx))\n" } viewLayout += "}"