Skip to content

Commit

Permalink
Revert "Cache dimensions"
Browse files Browse the repository at this point in the history
This reverts commit dc0252d.
  • Loading branch information
kurkle committed Jan 16, 2020
1 parent 9de6cac commit 55faccf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
14 changes: 0 additions & 14 deletions src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {};
Expand Down Expand Up @@ -211,7 +210,6 @@ class Chart {
plugins.notify(me, 'beforeInit');

helpers.dom.retinaScale(me, me.options.devicePixelRatio);
me._cacheDimensions();

me.bindEvents();

Expand All @@ -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;
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/helpers/helpers.dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;

Expand Down

0 comments on commit 55faccf

Please sign in to comment.