events | Array[String] | `["mousemove", "mouseout", "click", "touchstart", "touchmove", "touchend"]` | Events that the chart should listen to for tooltips and hovering
onClick | Function | null | Called if the event is of type 'mouseup' or 'click'. Called in the context of the chart and passed an array of active elements
legendCallback | Function | ` function (chart) { }` | Function to generate a legend. Receives the chart object to generate a legend from. Default implementation returns an HTML string.
+onResize | Function | null | Called when a resize occurs. Gets passed two arguemnts: the chart instance and the new size.
### Title Configuration
* End of update (before render occurs)
* Start of draw
* End of draw
+* Before datasets draw
+* After datasets draw
+* Resize
* Before an animation is started
Plugins should derive from Chart.PluginBase and implement the following interface
beforeInit: function(chartInstance) { },
afterInit: function(chartInstance) { },
+ resize: function(chartInstance, newChartSize) { },
+
beforeUpdate: function(chartInstance) { },
afterScaleUpdate: function(chartInstance) { }
afterUpdate: function(chartInstance) { },
},
resize: function resize(silent) {
- var canvas = this.chart.canvas;
- var newWidth = helpers.getMaximumWidth(this.chart.canvas);
- var newHeight = (this.options.maintainAspectRatio && isNaN(this.chart.aspectRatio) === false && isFinite(this.chart.aspectRatio) && this.chart.aspectRatio !== 0) ? newWidth / this.chart.aspectRatio : helpers.getMaximumHeight(this.chart.canvas);
+ var me = this;
+ var chart = me.chart;
+ var canvas = chart.canvas;
+ var newWidth = helpers.getMaximumWidth(canvas);
+ var aspectRatio = chart.aspectRatio;
+ var newHeight = (me.options.maintainAspectRatio && isNaN(aspectRatio) === false && isFinite(aspectRatio) && aspectRatio !== 0) ? newWidth / aspectRatio : helpers.getMaximumHeight(canvas);
+
+ var sizeChanged = chart.width !== newWidth || chart.height !== newHeight;
+
+ if (!sizeChanged) {
+ return me;
+ }
- var sizeChanged = this.chart.width !== newWidth || this.chart.height !== newHeight;
+ canvas.width = chart.width = newWidth;
+ canvas.height = chart.height = newHeight;
- if (!sizeChanged)
- return this;
+ helpers.retinaScale(chart);
- canvas.width = this.chart.width = newWidth;
- canvas.height = this.chart.height = newHeight;
+ // Notify any plugins about the resize
+ var newSize = { width: newWidth, height: newHeight };
+ Chart.pluginService.notifyPlugins('resize', [me, newSize]);
- helpers.retinaScale(this.chart);
+ // Notify of resize
+ if (me.options.onResize) {
+ me.options.onResize(me, newSize);
+ }
if (!silent) {
- this.stop();
- this.update(this.options.responsiveAnimationDuration);
+ me.stop();
+ me.update(me.options.responsiveAnimationDuration);
}
- return this;
+ return me;
},
ensureScalesHaveIDs: function ensureScalesHaveIDs() {