@@ -4,7 +4,6 @@ import { getPromiseResolver } from './utils/JsHelpers';
44import VisorAppState from './state/appstate/VisorAppState.tsx' ;
55import VisorDatasetState from './state/appstate/VisorDatasetState.tsx' ;
66import VisorPartState from './state/appstate/VisorPartState.tsx' ;
7- import VisorVariableState from './state/appstate/VisorVariableState.tsx' ;
87import { TreeViewUtil } from './treeview/TreeView.tsx' ;
98import { StateInput } from './state/appstate/VisorStateCommon.tsx' ;
109import VisorVtkSceneNode from './state/appstate/vtkInfo/VisorVtkSceneNode.tsx' ;
@@ -66,7 +65,6 @@ export class VisorFrontend {
6665 // Respect base path prefix set by the Dash component (for reverse-proxy deployments).
6766 const bp : string = ( ( window as any ) . __visorArgs ?. basePath ?? '' ) . replace ( / \/ $ / , '' ) ;
6867
69- const self = this ;
7068 this . globalVariableCollection = variableManager . globalVariableCollection ;
7169 this . #unit = '' ;
7270 this . darkMode = darkMode ;
@@ -100,6 +98,18 @@ export class VisorFrontend {
10098 remover ?.( ) ;
10199 } ;
102100 this . defaultActorColor = [ ] ;
101+ // Reports one variable slot's range; errors are logged, not rethrown,
102+ // since the client already applied the range locally.
103+ this . sendVariableRangeAsync = async ( variableId , component , min , max ) => {
104+ try {
105+ await triggerSender ( 'set_variable_range' , { variableId, component, min, max } ) ;
106+ } catch ( err ) {
107+ console . error (
108+ `[VISOR] variable range trigger send failed: variableId='${ variableId } ' component=${ component } ` ,
109+ err
110+ ) ;
111+ }
112+ } ;
103113 this . setVariableRangeAsync = async ( variableId , component , min , max ) => {
104114 const variable = variableManager . globalVariableCollection . getVariable ( variableId ) ;
105115 if ( variable == null ) {
@@ -114,6 +124,7 @@ export class VisorFrontend {
114124 await actorNode . setScalarRangeAsync ( min , max ) ;
115125 }
116126 }
127+ await this . sendVariableRangeAsync ( variableId , component , min , max ) ;
117128 } ;
118129 this . addCameraChangedListener = ( callback ) => {
119130 return renderer . addCameraChangedListener ( callback ) ;
@@ -305,29 +316,9 @@ export class VisorFrontend {
305316 }
306317 sceneState . copyDataset ( datasetState ) ;
307318 }
308- const variableInfos = variableManager . globalVariableCollection ;
309- for ( const variableInfo of variableInfos . array ) {
310- const variableState = new VisorVariableState ( ) ;
311- variableState . setId ( variableInfo . id . toString ( ) ) ;
312- variableState . setArrayName ( variableInfo . name ) ;
313- variableState . setType ( variableInfo . type ) ;
314- variableState . setNumComponents ( variableInfo . numComponents ) ;
315- const magnitudeRange = variableInfo . getRangeInfo ( - 1 ) ;
316- if ( magnitudeRange == null ) {
317- throw new Error ( `range at component ${ - 1 } not found` ) ;
318- }
319- variableState . setMagnitudeRange ( magnitudeRange . customRange ) ;
320- const ranges : number [ ] [ ] = [ ] ;
321- for ( let i = 0 ; i < variableInfo . numComponents ; i ++ ) {
322- const range = variableInfo . getRangeInfo ( i ) ;
323- if ( range == null ) {
324- throw new Error ( `range at component ${ i } not found` ) ;
325- }
326- ranges . push ( range . customRange ) ;
327- }
328- variableState . setRanges ( ranges ) ;
329- sceneState . copyVariable ( variableState ) ;
330- }
319+ // No variable block: the server owns the variable records and
320+ // delivers them on every push. Carrying a copy across a rebuild
321+ // would replace the delivered records with this one.
331322 return appState ;
332323 } ;
333324 this . setAppStateAsync = async ( state , updateUI ) => {
@@ -460,6 +451,13 @@ export class VisorFrontend {
460451 const promise = renderer . setCrossSectionNormalAsync ( crossSectionState . normal ) ;
461452 promises . push ( promise ) ;
462453 }
454+ // Held before the part loop: a part coloured below reads its
455+ // range from these records. Guarded on presence, so a state with
456+ // no variable block leaves the held records alone, while an empty
457+ // block clears them.
458+ if ( sceneState . hasVariableStates ) {
459+ variableManager . setRecords ( sceneState . getVariableStates ( ) ) ;
460+ }
463461 for ( const dataset_state of sceneState . getDatasetStates ( ) ) {
464462 for ( const part_state of dataset_state . getPartStates ( ) ) {
465463 let node ;
@@ -522,24 +520,7 @@ export class VisorFrontend {
522520 }
523521 }
524522 }
525- // wait for all the parts to be updated before updating the variable ranges
526- await Promise . all ( promises ) ;
527- promises . length = 0 ;
528- for ( const variable_state of sceneState . getVariableStates ( ) ) {
529- const idStr = variable_state . id ;
530- if ( variable_state . magnitudeRange !== undefined ) {
531- const range = variable_state . magnitudeRange ;
532- const promise = self . setVariableRangeAsync ( idStr , - 1 , range [ 0 ] , range [ 1 ] ) ;
533- promises . push ( promise ) ;
534- }
535- for ( let i = 0 ; i < variable_state . ranges . length ; i ++ ) {
536- const range = variable_state . ranges [ i ] ;
537- if ( range !== undefined ) {
538- const promise = self . setVariableRangeAsync ( idStr , i , range [ 0 ] , range [ 1 ] ) ;
539- promises . push ( promise ) ;
540- }
541- }
542- }
523+ // Every part is applied before the tree and the panel re-read them.
543524 await Promise . all ( promises ) ;
544525 if ( updateUI ) {
545526 await panelTopRightUtilPromise ;
@@ -549,6 +530,13 @@ export class VisorFrontend {
549530 // above; the tree derives its rows from them here.
550531 treeViewUtil . synchronize ( ) ;
551532 }
533+ // After the tree has taken the delivered selection, so the panel
534+ // re-reads that selection's ranges from the records just held.
535+ // Skipped until the panel exists; its mount reads them itself.
536+ if ( isPanelTopRightUtilSet ( ) ) {
537+ const panelTopRight = await panelTopRightUtilPromise ;
538+ await panelTopRight . refreshSelectionAsync ( ) ;
539+ }
552540 await renderer . resizeAsync ( ) ;
553541 } ;
554542 Object . freeze ( this ) ;
@@ -587,6 +575,14 @@ export class VisorFrontend {
587575 toggleFullScreenAsync : ( ) => Promise < void > ;
588576 addCameraChangedListener : ( callback : ( cameraState : VisorCameraState ) => void ) => ( ) => void ;
589577 globalVariableCollection : VisorVariableCollection ;
578+ /** Reports one variable slot's range to the server, -1 being the magnitude; a failed send is logged, not rethrown. */
579+ sendVariableRangeAsync : (
580+ variableId : string ,
581+ component : number ,
582+ min : number ,
583+ max : number
584+ ) => Promise < void > ;
585+ /** Writes a variable slot's range to the held record, applies it to every part coloured by that slot, then reports it to the server. */
590586 setVariableRangeAsync : (
591587 variableId : string ,
592588 component : number ,
0 commit comments