From d6289c6129f1222980ea571f6c6f675182d78f35 Mon Sep 17 00:00:00 2001 From: Evert Timberg Date: Wed, 25 May 2016 21:28:02 -0400 Subject: [PATCH] Convert title block to a plugin --- src/chart.js | 2 +- src/core/core.controller.js | 4 ++-- src/core/core.legend.js | 2 +- src/core/core.title.js | 18 ++++++++++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/chart.js b/src/chart.js index f482369e9..90b9c77ee 100644 --- a/src/chart.js +++ b/src/chart.js @@ -8,9 +8,9 @@ require('./core/core.datasetController')(Chart); require('./core/core.layoutService')(Chart); require('./core/core.scaleService')(Chart); require('./core/core.plugin.js')(Chart); -require('./core/core.legend')(Chart); require('./core/core.scale')(Chart); require('./core/core.title')(Chart); +require('./core/core.legend')(Chart); require('./core/core.tooltip')(Chart); require('./elements/element.arc')(Chart); diff --git a/src/core/core.controller.js b/src/core/core.controller.js index b96f57d49..e53faaf6a 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -167,7 +167,7 @@ module.exports = function(Chart) { }, buildSurroundingItems: function() { - if (this.options.title) { + /*if (this.options.title) { this.titleBlock = new Chart.Title({ ctx: this.chart.ctx, options: this.options.title, @@ -175,7 +175,7 @@ module.exports = function(Chart) { }); Chart.layoutService.addBox(this, this.titleBlock); - } + }*/ }, updateLayout: function() { diff --git a/src/core/core.legend.js b/src/core/core.legend.js index e3005ddfe..f625bb881 100644 --- a/src/core/core.legend.js +++ b/src/core/core.legend.js @@ -363,5 +363,5 @@ module.exports = function(Chart) { Chart.layoutService.addBox(chartInstance, chartInstance.legend); } } - }) + }); }; diff --git a/src/core/core.title.js b/src/core/core.title.js index b6d82c07e..ab969d461 100644 --- a/src/core/core.title.js +++ b/src/core/core.title.js @@ -177,4 +177,22 @@ module.exports = function(Chart) { } } }); + + // Register the title plugin + Chart.pluginService.register({ + beforeInit: function(chartInstance) { + var opts = chartInstance.options; + var titleOpts = opts.title; + + if (titleOpts) { + chartInstance.titleBlock = new Chart.Title({ + ctx: chartInstance.chart.ctx, + options: titleOpts, + chart: chartInstance + }); + + Chart.layoutService.addBox(chartInstance, chartInstance.titleBlock); + } + } + }); }; \ No newline at end of file -- 2.47.3