@@ -46,7 +46,7 @@ function readUsedSize(element, property) {
4646 * since responsiveness is handled by the controller.resize() method. The config is used
4747 * to determine the aspect ratio to apply in case no explicit height has been specified.
4848 */
49- function initCanvas ( canvas , config ) { // eslint-disable-line no-unused-vars
49+ function initCanvas ( canvas , config ) {
5050 const style = canvas . style ;
5151
5252 // NOTE(SB) canvas.getAttribute('width') !== canvas.width: in the first case it
@@ -250,18 +250,21 @@ function unlistenForResize(proxies) {
250250 * @param {Function } listener
251251 */
252252function listenForResize ( canvas , proxies , listener ) {
253+ // Helper for recursing when canvas is detached from it's parent
253254 const detached = ( ) => listenForResize ( canvas , proxies , listener ) ;
254255
255- // Canvas was detached from it's parent
256+ // First make sure all observers are removed
256257 unlistenForResize ( proxies ) ;
258+ // Then check if we are attached
257259 const container = _getParentNode ( canvas ) ;
258260 if ( container ) {
259- // The canvas was immediately re-attached
261+ // The canvas is attached (or was immediately re-attached when called through `detached`)
260262 proxies . resize = watchForResize ( container , listener ) ;
261263 proxies . detach = watchForDetachment ( canvas , detached ) ;
262264 } else {
265+ // The canvas is detached
263266 proxies . attach = watchForAttachment ( canvas , ( ) => {
264- // The canvas was attached
267+ // The canvas was attached.
265268 removeObserver ( proxies , 'attach' ) ;
266269 const parent = _getParentNode ( canvas ) ;
267270 proxies . resize = watchForResize ( parent , listener ) ;
@@ -276,14 +279,6 @@ function listenForResize(canvas, proxies, listener) {
276279 */
277280export default class DomPlatform extends BasePlatform {
278281
279- /**
280- * Initializes resources that depend on platform options.
281- * @param {HTMLCanvasElement } canvas - The Canvas element.
282- * @private
283- */
284- _ensureLoaded ( canvas ) { // eslint-disable-line no-unused-vars
285- }
286-
287282 acquireContext ( canvas , config ) {
288283 // To prevent canvas fingerprinting, some add-ons undefine the getContext
289284 // method, for example: https://github.com/kkapsner/CanvasBlocker
@@ -300,15 +295,14 @@ export default class DomPlatform extends BasePlatform {
300295 if ( context && context . canvas === canvas ) {
301296 // Load platform resources on first chart creation, to make it possible to
302297 // import the library before setting platform options.
303- this . _ensureLoaded ( canvas ) ;
304298 initCanvas ( canvas , config ) ;
305299 return context ;
306300 }
307301
308302 return null ;
309303 }
310304
311- releaseContext ( context ) { // eslint-disable-line no-unused-vars
305+ releaseContext ( context ) {
312306 const canvas = context . canvas ;
313307 if ( ! canvas [ EXPANDO_KEY ] ) {
314308 return false ;
0 commit comments