From 657e53c1170bcf4997b852a14ec181d6d72e49ef Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Wed, 19 Jun 2013 15:00:37 +1000 Subject: [PATCH 1/2] make charts dependent on calculated width --- Chart.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Chart.js b/Chart.js index e34e08a48..fb8fb0c54 100644 --- a/Chart.js +++ b/Chart.js @@ -25,8 +25,20 @@ this.ctx = context; //Variables global to the chart - var width = this.width = context.canvas.width; - var height = this.height = context.canvas.height; + var computeDimension = function(element,dimension) + { + if (element['offset'+dimension]) + { + return element['offset'+dimension]; + } + else + { + return document.defaultView.getComputedStyle(element).getPropertyValue(dimension); + } + } + + var width = this.width = computeDimension(context.canvas,'Width'); + var height = this.height = computeDimension(context.canvas,'Height'); this.aspectRatio = this.width / this.height; //High pixel density displays - multiply the size of the canvas height/width by the device pixel ratio, then scale. helpers.retinaScale(this); From 9ab36291a99b72245bbc1dd6b5e9b1391871f882 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Thu, 27 Jun 2013 16:14:48 +1000 Subject: [PATCH 2/2] force calculated width/heights back to context, for firefox compatibility --- Chart.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Chart.js b/Chart.js index fb8fb0c54..3c217c87d 100644 --- a/Chart.js +++ b/Chart.js @@ -39,6 +39,11 @@ var width = this.width = computeDimension(context.canvas,'Width'); var height = this.height = computeDimension(context.canvas,'Height'); + + // Firefox requires this to work correctly + context.canvas.width = width; + context.canvas.height = height; + this.aspectRatio = this.width / this.height; //High pixel density displays - multiply the size of the canvas height/width by the device pixel ratio, then scale. helpers.retinaScale(this);