@@ -70,13 +70,14 @@ class CanvasModel extends DOMWidgetModel {
7070 this . drawImageData ( ) ;
7171
7272 this . on_some_change ( [ 'width' , 'height' ] , this . resizeCanvas , this ) ;
73+ this . on ( 'change:sync_image_data' , this . syncImageData . bind ( this ) ) ;
7374 this . on ( 'msg:custom' , this . onCommand . bind ( this ) ) ;
7475
7576 this . send ( { event : 'client_ready' } , { } ) ;
7677 }
7778
7879 private async drawImageData ( ) {
79- if ( this . get ( 'sync_image_data' ) && this . get ( ' image_data') !== null ) {
80+ if ( this . get ( 'image_data' ) !== null ) {
8081 const img = await fromBytes ( this . get ( 'image_data' ) ) ;
8182
8283 this . ctx . drawImage ( img , 0 , 0 ) ;
@@ -443,6 +444,7 @@ class MultiCanvasModel extends DOMWidgetModel {
443444 super . initialize ( attributes , options ) ;
444445
445446 this . on ( 'change:_canvases' , this . updateListeners . bind ( this ) ) ;
447+ this . on ( 'change:sync_image_data' , this . syncImageData . bind ( this ) ) ;
446448 this . updateListeners ( ) ;
447449 }
448450
@@ -465,7 +467,13 @@ class MultiCanvasModel extends DOMWidgetModel {
465467 const ctx = getContext ( offscreenCanvas ) ;
466468
467469 for ( const canvasModel of this . get ( '_canvases' ) ) {
468- ctx . drawImage ( canvasModel . canvas , 0 , 0 )
470+ ctx . drawImage ( canvasModel . canvas , 0 , 0 ) ;
471+
472+ // Also update the sub-canvas image-data
473+ const bytes = await toBytes ( canvasModel . canvas ) ;
474+
475+ canvasModel . set ( 'image_data' , bytes ) ;
476+ canvasModel . save_changes ( ) ;
469477 }
470478
471479 const bytes = await toBytes ( offscreenCanvas ) ;
0 commit comments