@@ -30,10 +30,10 @@ <h1>Remote control demo</h1>
3030 < button id ="btn-add-signal " disabled > add_signal (sine)</ button >
3131 < button id ="btn-add-image " disabled > add_image (gradient)</ button >
3232 < div class ="row ">
33- < button id ="btn-fft " disabled > calc(fft) on last </ button >
34- < button id ="btn-get " disabled > get_signal_xy(last )</ button >
33+ < button id ="btn-fft " disabled > calc(fft) on selection </ button >
34+ < button id ="btn-get " disabled > get_signal_xy(current )</ button >
3535 </ div >
36- < button id ="btn-remove " disabled > delete_object(last )</ button >
36+ < button id ="btn-remove " disabled > delete_object(current )</ button >
3737 < button id ="btn-reset " disabled > reset_all</ button >
3838 < div id ="log " aria-live ="polite "> </ div >
3939 </ div >
@@ -76,9 +76,6 @@ <h1>Remote control demo</h1>
7676 // Expose for Playwright (`page.evaluate(() => window.__client.…)`).
7777 window . __client = client ;
7878
79- let lastSignalId = null ;
80- let lastImageId = null ;
81-
8279 const buttons = {
8380 version : document . getElementById ( "btn-version" ) ,
8481 list : document . getElementById ( "btn-list" ) ,
@@ -112,35 +109,31 @@ <h1>Remote control demo</h1>
112109 const N = 256 ;
113110 const xs = Array . from ( { length : N } , ( _ , i ) => i / N ) ;
114111 const ys = xs . map ( ( x ) => Math . sin ( 2 * Math . PI * 5 * x ) ) ;
115- lastSignalId = await wrap ( "add_signal" , ( ) => client . addSignal ( "Sine 5 Hz" , xs , ys ) ) ;
112+ await wrap ( "add_signal" , ( ) => client . addSignal ( "Sine 5 Hz" , xs , ys ) ) ;
116113 } ;
117114 buttons . addImage . onclick = async ( ) => {
118115 const N = 32 ;
119116 const data = Array . from ( { length : N } , ( _ , i ) =>
120117 Array . from ( { length : N } , ( _ , j ) => i + j ) ,
121118 ) ;
122- lastImageId = await wrap ( "add_image" , ( ) => client . addImage ( "Gradient" , data ) ) ;
123- } ;
124- buttons . fft . onclick = ( ) => {
125- if ( ! lastSignalId ) return logLine ( "!" , "no signal yet — add a signal first" ) ;
126- return wrap ( "calc(fft)" , ( ) => client . calc ( "fft" , null , [ lastSignalId ] ) ) ;
119+ await wrap ( "add_image" , ( ) => client . addImage ( "Gradient" , data ) ) ;
127120 } ;
128- buttons . get . onclick = ( ) => {
129- if ( ! lastSignalId ) return logLine ( "!" , "no signal yet" ) ;
130- return wrap ( "get_signal_xy" , ( ) => client . getSignalXY ( lastSignalId ) ) ;
121+ // Operate on whatever the user has selected inside the iframe.
122+ // ``client.calc(...)`` with ``sources=null`` already defaults to
123+ // the current selection on the DataLab-Web side.
124+ buttons . fft . onclick = ( ) =>
125+ wrap ( "calc(fft)" , ( ) => client . calc ( "fft" ) ) ;
126+ buttons . get . onclick = async ( ) => {
127+ const sel = await client . getSelection ( ) ;
128+ if ( sel . length === 0 ) return logLine ( "!" , "no current selection" ) ;
129+ return wrap ( "get_signal_xy" , ( ) => client . getSignalXY ( sel [ 0 ] ) ) ;
131130 } ;
132131 buttons . remove . onclick = async ( ) => {
133- const id = lastSignalId ?? lastImageId ;
134- if ( ! id ) return logLine ( "!" , "no object to delete" ) ;
135- await wrap ( "delete_object" , ( ) => client . deleteObject ( id ) ) ;
136- if ( id === lastSignalId ) lastSignalId = null ;
137- else lastImageId = null ;
138- } ;
139- buttons . reset . onclick = async ( ) => {
140- await wrap ( "reset_all" , ( ) => client . resetAll ( ) ) ;
141- lastSignalId = null ;
142- lastImageId = null ;
132+ const sel = await client . getSelection ( ) ;
133+ if ( sel . length === 0 ) return logLine ( "!" , "no current selection" ) ;
134+ return wrap ( "delete_object" , ( ) => client . deleteObject ( sel [ 0 ] ) ) ;
143135 } ;
136+ buttons . reset . onclick = ( ) => wrap ( "reset_all" , ( ) => client . resetAll ( ) ) ;
144137
145138 ( async ( ) => {
146139 try {
0 commit comments