@@ -288,10 +288,10 @@ export class HttpgdViewer implements IHttpgdViewer {
288288 readonly zoom0 : number = 1 ;
289289 zoom : number = this . zoom0 ;
290290
291- resizeTimeout ?: NodeJS . Timeout ;
291+ protected resizeTimeout ?: NodeJS . Timeout ;
292292 readonly resizeTimeoutLength : number = 1300 ;
293293
294- refreshTimeout ?: NodeJS . Timeout ;
294+ protected refreshTimeout ?: NodeJS . Timeout ;
295295 readonly refreshTimeoutLength : number = 10 ;
296296
297297 private lastExportUri ?: vscode . Uri ;
@@ -331,7 +331,7 @@ export class HttpgdViewer implements IHttpgdViewer {
331331
332332 this . api = new Httpgd ( this . host , this . token , true ) ;
333333 this . api . onPlotsChanged ( ( newState ) => {
334- void this . refreshPlots ( newState . plots ) ;
334+ void this . refreshPlotsDelayed ( newState . plots ) ;
335335 } ) ;
336336 this . api . onConnectionChanged ( ( ) => {
337337 // todo
@@ -567,6 +567,19 @@ export class HttpgdViewer implements IHttpgdViewer {
567567 this . plotHeight = plt . height ;
568568 this . updatePlot ( plt ) ;
569569 }
570+
571+ protected async refreshPlotsDelayed ( plotsIdResponse : HttpgdIdResponse [ ] , redraw : boolean = false , force : boolean = false ) : Promise < void > {
572+ if ( this . refreshTimeoutLength === 0 ) {
573+ await this . refreshPlots ( plotsIdResponse , redraw , force ) ;
574+ } else {
575+ clearTimeout ( this . refreshTimeout ) ;
576+ this . refreshTimeout = setTimeout ( ( ) => {
577+ void this . refreshPlots ( plotsIdResponse , redraw , force ) . then ( ( ) =>
578+ this . refreshTimeout = undefined
579+ ) ;
580+ } , this . refreshTimeoutLength ) ;
581+ }
582+ }
570583
571584 protected async refreshPlots ( plotsIdResponse : HttpgdIdResponse [ ] , redraw : boolean = false , force : boolean = false ) : Promise < void > {
572585 const nPlots = this . plots . length ;
0 commit comments