Skip to content

Commit ac0b7c1

Browse files
committed
Cleanup
1 parent 9877eb5 commit ac0b7c1

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

src/core/core.controller.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,8 @@ class Chart {
247247
// Before init plugin notification
248248
plugins.notify(me, 'beforeInit');
249249

250-
// helpers.dom.retinaScale(me, me.options.devicePixelRatio);
251-
252250
if (me.options.responsive) {
251+
// Initial resize before chart draws (must be silent to preserve initial animations).
253252
me.resize(true);
254253
} else {
255254
helpers.dom.retinaScale(me, me.options.devicePixelRatio);
@@ -299,6 +298,7 @@ class Chart {
299298
}
300299
// the canvas render width and height will be casted to integers so make sure that
301300
// the canvas display style uses the same integer values to avoid blurring effect.
301+
// Set to 0 instead of canvas.size because the size defaults to 300x150 if the element is collapsed
302302
const newWidth = Math.max(0, Math.floor(width));
303303
const newHeight = Math.max(0, Math.floor(aspectRatio ? newWidth / aspectRatio : height));
304304

@@ -909,7 +909,7 @@ class Chart {
909909
if (canvas) {
910910
me.unbindEvents();
911911
helpers.canvas.clear(me);
912-
me.platform.releaseContext(me, me.ctx);
912+
me.platform.releaseContext(me.ctx);
913913
me.canvas = null;
914914
me.ctx = null;
915915
}
@@ -939,10 +939,10 @@ class Chart {
939939
});
940940

941941
if (me.options.responsive) {
942-
// resize
943942
listener = function(width, height) {
944943
me.resize(false, width, height);
945944
};
945+
946946
me.platform.addEventListener(me, 'resize', listener);
947947
listeners.resize = listener;
948948
}

src/platform/platform.dom.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
252252
function 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
*/
277280
export 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

Comments
 (0)