From 55faccffe6ae532f43fdcde254791ba6d8c032eb Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Thu, 16 Jan 2020 12:11:42 +0200 Subject: [PATCH] Revert "Cache dimensions" This reverts commit dc0252dc74035eed73bed69acf8921a061eec5e6. --- src/core/core.controller.js | 14 -------------- src/helpers/helpers.dom.js | 10 +++++----- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/core/core.controller.js b/src/core/core.controller.js index e5cd481279b..81aaa9ceba1 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -12,7 +12,6 @@ import scaleService from '../core/core.scaleService'; import Tooltip from './core.tooltip'; const valueOrDefault = helpers.valueOrDefault; -const getStyle = helpers.dom.getStyle; function mergeScaleConfig(config, options) { options = options || {}; @@ -211,7 +210,6 @@ class Chart { plugins.notify(me, 'beforeInit'); helpers.dom.retinaScale(me, me.options.devicePixelRatio); - me._cacheDimensions(); me.bindEvents(); @@ -238,17 +236,6 @@ class Chart { return this; } - _cacheDimensions() { - const me = this; - const canvas = me.canvas; - - me._clientRect = canvas.getBoundingClientRect(); - me._paddingLeft = parseFloat(getStyle(canvas, 'padding-left')); - me._paddingTop = parseFloat(getStyle(canvas, 'padding-top')); - me._paddingRight = parseFloat(getStyle(canvas, 'padding-right')); - me._paddingBottom = parseFloat(getStyle(canvas, 'padding-bottom')); - } - resize(silent) { const me = this; const options = me.options; @@ -272,7 +259,6 @@ class Chart { canvas.style.height = newHeight + 'px'; helpers.dom.retinaScale(me, options.devicePixelRatio); - me._cacheDimensions(); if (!silent) { // Notify any plugins about the resize diff --git a/src/helpers/helpers.dom.js b/src/helpers/helpers.dom.js index 8a266938816..939e4bbe8c7 100644 --- a/src/helpers/helpers.dom.js +++ b/src/helpers/helpers.dom.js @@ -88,7 +88,7 @@ export function getRelativePosition(evt, chart) { var mouseX, mouseY; var e = evt.originalEvent || evt; var canvasElement = evt.target || evt.srcElement; - var boundingRect = chart._clientRect; + var boundingRect = canvasElement.getBoundingClientRect(); var touches = e.touches; if (touches && touches.length > 0) { @@ -103,10 +103,10 @@ export function getRelativePosition(evt, chart) { // Scale mouse coordinates into canvas coordinates // by following the pattern laid out by 'jerryj' in the comments of // https://www.html5canvastutorials.com/advanced/html5-canvas-mouse-coordinates/ - var paddingLeft = chart._paddingLeft; - var paddingTop = chart._paddingTop; - var paddingRight = chart._paddingRight; - var paddingBottom = chart._paddingBottom; + var paddingLeft = parseFloat(getStyle(canvasElement, 'padding-left')); + var paddingTop = parseFloat(getStyle(canvasElement, 'padding-top')); + var paddingRight = parseFloat(getStyle(canvasElement, 'padding-right')); + var paddingBottom = parseFloat(getStyle(canvasElement, 'padding-bottom')); var width = boundingRect.right - boundingRect.left - paddingLeft - paddingRight; var height = boundingRect.bottom - boundingRect.top - paddingTop - paddingBottom;