Skip to content

Commit

Permalink
Even better responsive sizing
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Jun 16, 2015
1 parent 63530ba commit 8d1f280
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
10 changes: 7 additions & 3 deletions Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,8 @@
Chart.instances[this.id] = this;

if (this.options.responsive) {
this.resize();
// Silent resize before chart draws
this.resize(true);
}

this.initialize.call(this);
Expand Down Expand Up @@ -1255,7 +1256,7 @@
return this;
},

resize: function resize() {
resize: function resize(silent) {
this.stop();
var canvas = this.chart.canvas,
newWidth = helpers.getMaximumWidth(this.chart.canvas),
Expand All @@ -1266,6 +1267,10 @@

helpers.retinaScale(this.chart);

if (!silent) {
this.update(this.options.responsiveAnimationDuration);
}

return this;
},

Expand Down Expand Up @@ -1635,7 +1640,6 @@
// Cascade the resize event down to the chart.
if (instance.options.responsive) {
instance.resize();
instance.update(Chart.defaults.global.responsiveAnimationDuration);
}
});
}, 16);
Expand Down
2 changes: 1 addition & 1 deletion Chart.min.js

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
Chart.instances[this.id] = this;

if (this.options.responsive) {
this.resize();
// Silent resize before chart draws
this.resize(true);
}

this.initialize.call(this);
Expand Down Expand Up @@ -73,7 +74,7 @@
return this;
},

resize: function resize() {
resize: function resize(silent) {
this.stop();
var canvas = this.chart.canvas,
newWidth = helpers.getMaximumWidth(this.chart.canvas),
Expand All @@ -84,6 +85,10 @@

helpers.retinaScale(this.chart);

if (!silent) {
this.update(this.options.responsiveAnimationDuration);
}

return this;
},

Expand Down
1 change: 0 additions & 1 deletion src/core/core.responsive.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
// Cascade the resize event down to the chart.
if (instance.options.responsive) {
instance.resize();
instance.update(Chart.defaults.global.responsiveAnimationDuration);
}
});
}, 16);
Expand Down

0 comments on commit 8d1f280

Please sign in to comment.