From 1ae0f5e4d49c271d0958c7e8514823d476a937a0 Mon Sep 17 00:00:00 2001 From: Evert Timberg Date: Wed, 25 May 2016 21:23:46 -0400 Subject: [PATCH] Legend is attached to the graph as a plugin. --- src/chart.js | 4 ++-- src/core/core.controller.js | 10 ---------- src/core/core.legend.js | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/chart.js b/src/chart.js index 58061c2ab..f482369e9 100644 --- a/src/chart.js +++ b/src/chart.js @@ -6,10 +6,10 @@ require('./core/core.animation')(Chart); require('./core/core.controller')(Chart); require('./core/core.datasetController')(Chart); require('./core/core.layoutService')(Chart); -require('./core/core.legend')(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.scaleService')(Chart); require('./core/core.title')(Chart); require('./core/core.tooltip')(Chart); diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 36edf9e7a..b96f57d49 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -176,16 +176,6 @@ module.exports = function(Chart) { Chart.layoutService.addBox(this, this.titleBlock); } - - if (this.options.legend) { - this.legend = new Chart.Legend({ - ctx: this.chart.ctx, - options: this.options.legend, - chart: this - }); - - Chart.layoutService.addBox(this, this.legend); - } }, updateLayout: function() { diff --git a/src/core/core.legend.js b/src/core/core.legend.js index b8ae19eb1..e3005ddfe 100644 --- a/src/core/core.legend.js +++ b/src/core/core.legend.js @@ -347,4 +347,21 @@ module.exports = function(Chart) { } }); + // Register the legend plugin + Chart.pluginService.register({ + beforeInit: function(chartInstance) { + var opts = chartInstance.options; + var legendOpts = opts.legend; + + if (legendOpts) { + chartInstance.legend = new Chart.Legend({ + ctx: chartInstance.chart.ctx, + options: legendOpts, + chart: chartInstance + }); + + Chart.layoutService.addBox(chartInstance, chartInstance.legend); + } + } + }) }; -- 2.47.3