@@ -14,6 +14,10 @@ function vtkTextActor(publicAPI, model) {
1414 // Set our className
1515 model . classHierarchy . push ( 'vtkTextActor' ) ;
1616
17+ const superDelete = publicAPI . delete ;
18+ const superSetProperty = publicAPI . setProperty ;
19+ let propertySubscription = null ;
20+
1721 publicAPI . makeProperty = vtkTextProperty . newInstance ;
1822
1923 const texture = vtkTexture . newInstance ( {
@@ -38,7 +42,7 @@ function vtkTextActor(publicAPI, model) {
3842 const backgroundColor = publicAPI . getProperty ( ) . getBackgroundColor ( ) ;
3943
4044 const dpr = Math . max ( window . devicePixelRatio || 1 , 1 ) ;
41- const ctx = canvas . getContext ( '2d' ) ;
45+ const ctx = canvas . getContext ( '2d' , { willReadFrequently : true } ) ;
4246
4347 // Set the text properties to measure
4448 const textSize = fontSizeScale ( resolution ) * dpr ;
@@ -110,22 +114,53 @@ function vtkTextActor(publicAPI, model) {
110114 return ImageHelper . canvasToImageData ( canvas ) ;
111115 }
112116
117+ function updateTexture ( ) {
118+ const image = createImageData ( model . input ) ;
119+ texture . setInputData ( image , 0 ) ;
120+ }
121+
122+ function bindProperty ( property ) {
123+ if ( propertySubscription ) {
124+ propertySubscription . unsubscribe ( ) ;
125+ propertySubscription = null ;
126+ }
127+
128+ if ( property ) {
129+ propertySubscription = property . onModified ( ( ) => {
130+ if ( model . input !== undefined ) {
131+ updateTexture ( ) ;
132+ }
133+ } ) ;
134+ }
135+ }
136+
113137 mapper . setInputConnection ( plane . getOutputPort ( ) ) ;
114138
115139 publicAPI . setMapper ( mapper ) ;
116140 publicAPI . addTexture ( texture ) ;
117141
118- model . _onInputChanged = ( _publicAPI , _model , value ) => {
119- const image = createImageData ( value ) ;
120- texture . setInputData ( image , 0 ) ;
142+ publicAPI . setProperty = ( property ) => {
143+ const changed = superSetProperty ( property ) ;
144+ bindProperty ( property ) ;
145+ if ( model . input !== undefined ) {
146+ updateTexture ( ) ;
147+ }
148+ return changed ;
121149 } ;
150+
151+ publicAPI . delete = ( ) => {
152+ if ( propertySubscription ) {
153+ propertySubscription . unsubscribe ( ) ;
154+ propertySubscription = null ;
155+ }
156+ superDelete ( ) ;
157+ } ;
158+
159+ model . _onInputChanged = updateTexture ;
122160}
123161
124162// Default property values
125- const DEFAULT_VALUES = {
126- mapper : null ,
127- property : null ,
128- } ;
163+ const DEFAULT_VALUES = { } ;
129164
130165export function extend ( publicAPI , model , initialValues = { } ) {
131166 Object . assign ( model , DEFAULT_VALUES , initialValues ) ;
0 commit comments