@@ -150,13 +150,36 @@ function updateElements(chart, state, options, mode) {
150150 if ( ! el || ! ( el instanceof elType ) ) {
151151 el = elements [ i ] = new elType ( ) ;
152152 }
153- const opts = annotation . setContext ( getContext ( chart , el , annotation ) ) ;
153+ const opts = resolveAnnotationOptions ( annotation . setContext ( getContext ( chart , el , annotation ) ) ) ;
154154 const properties = el . resolveElementProperties ( chart , opts ) ;
155155 properties . options = opts ;
156156 animations . update ( el , properties ) ;
157157 }
158158}
159159
160+ function resolveAnnotationOptions ( resolver ) {
161+ const elType = annotationTypes [ resolver . type ] || annotationTypes . line ;
162+ const result = { } ;
163+ result . id = resolver . id ;
164+ result . type = elType . id ;
165+ result . drawTime = resolver . drawTime ;
166+ Object . assign ( result , resolveObj ( resolver , elType . defaults ) , resolveObj ( resolver , elType . defaultRoutes ) ) ;
167+ for ( const hook of hooks ) {
168+ result [ hook ] = resolver [ hook ] ;
169+ }
170+ return result ;
171+ }
172+
173+ function resolveObj ( resolver , defs ) {
174+ const result = { } ;
175+ for ( const name of Object . keys ( defs ) ) {
176+ const optDefs = defs [ name ] ;
177+ const value = resolver [ name ] ;
178+ result [ name ] = isObject ( optDefs ) ? resolveObj ( value , optDefs ) : value ;
179+ }
180+ return result ;
181+ }
182+
160183function getContext ( chart , element , annotation ) {
161184 return element . $context || ( element . $context = Object . assign ( Object . create ( chart . getContext ( ) ) , {
162185 element,
0 commit comments