@@ -72,6 +72,7 @@ export class MainSweepComponent implements OnChanges {
7272
7373 activeComponent : 'bias' | 'step' | 'sweep' | null = null ; // Tracks the active component
7474 activeIndex : number | null = null ;
75+ isScrolled = false ;
7576
7677 colorIndex = 0 ;
7778 colors : string [ ] = [
@@ -89,16 +90,22 @@ export class MainSweepComponent implements OnChanges {
8990 component : 'bias' | 'step' | 'sweep' ,
9091 index : number
9192 ) : void {
93+ // Reset scroll flag when switching to a different component
94+ if ( this . activeComponent !== component || this . activeIndex !== index ) {
95+ this . isScrolled = false ;
96+ }
97+
9298 this . activeComponent = component ;
9399 this . activeIndex = index ;
94100 console . log ( `Active Component: ${ component } , Index: ${ index } ` ) ;
95101 }
96102
97103 // Called when an input box loses focus
98- clearActiveComponent ( ) : void {
99- this . activeComponent = null ;
100- this . activeIndex = null ;
101- }
104+ // clearActiveComponent(): void {
105+ // this.activeComponent = null;
106+ // this.activeIndex = null;
107+ // this.isScrolled = false; // Reset scroll flag when clearing active component
108+ // }
102109
103110 showPopupBox = false ;
104111 showTiming = false ;
@@ -144,6 +151,13 @@ export class MainSweepComponent implements OnChanges {
144151 // Handle the change in sweepConfig here if needed
145152 this . updateAll ( ) ;
146153 console . log ( 'sweepConfig updated:' , this . sweepConfig ) ;
154+
155+ // Re-scroll to active plot after data updates if there's an active component
156+ if ( this . activeComponent !== null && this . activeIndex !== null ) {
157+ setTimeout ( ( ) => {
158+ this . scrollToPlotInPlotContainer ( this . activeComponent ! , this . activeIndex ! ) ;
159+ } , 10 ) ;
160+ }
147161 }
148162 }
149163
@@ -171,6 +185,11 @@ export class MainSweepComponent implements OnChanges {
171185 componentType : 'bias' | 'step' | 'sweep' ,
172186 index : number
173187 ) : void {
188+ // Skip scrolling if this is already the active component (clicked again)
189+ if ( this . isScrolled === true ) {
190+ return ;
191+ }
192+
174193 let component : BiasComponent | StepComponent | SweepComponent | undefined ;
175194
176195 if ( componentType === 'bias' ) {
@@ -188,14 +207,18 @@ export class MainSweepComponent implements OnChanges {
188207 block : 'center' , // Align to the center of the viewport
189208 } ) ;
190209 }
210+ this . isScrolled = true ;
191211 }
192212
193213 scrollToPlotInPlotContainer (
194214 componentType : 'bias' | 'step' | 'sweep' ,
195215 index : number
196216 ) : void {
197217 if ( this . plotContainer ) {
198- this . plotContainer . scrollToPlot ( componentType , index ) ;
218+ // Use setTimeout to ensure scroll happens after any pending view updates
219+ setTimeout ( ( ) => {
220+ this . plotContainer . scrollToPlot ( componentType , index ) ;
221+ } , 100 ) ;
199222 }
200223 }
201224
0 commit comments