Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ 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.scale')(Chart);
require('./core/core.scaleService')(Chart);
require('./core/core.title')(Chart);
require('./core/core.legend')(Chart);
require('./core/core.tooltip')(Chart);

require('./elements/element.arc')(Chart);
Expand Down
23 changes: 0 additions & 23 deletions src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ module.exports = function(Chart) {
this.ensureScalesHaveIDs();
this.buildOrUpdateControllers();
this.buildScales();
this.buildSurroundingItems();
this.updateLayout();
this.resetElements();
this.initToolTip();
Expand Down Expand Up @@ -166,28 +165,6 @@ module.exports = function(Chart) {
Chart.scaleService.addScalesToLayout(this);
},

buildSurroundingItems: function() {
if (this.options.title) {
this.titleBlock = new Chart.Title({
ctx: this.chart.ctx,
options: this.options.title,
chart: this
});

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() {
Chart.layoutService.update(this, this.chart.width, this.chart.height);
},
Expand Down
17 changes: 17 additions & 0 deletions src/core/core.legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
};
18 changes: 18 additions & 0 deletions src/core/core.title.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
};
9 changes: 9 additions & 0 deletions test/core.plugin.tests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
// Plugin tests
describe('Test the plugin system', function() {
var oldPlugins;

beforeAll(function() {
oldPlugins = Chart.plugins;
});
afterAll(function() {
Chart.plugins = oldPlugins;
});

beforeEach(function() {
Chart.plugins = [];
});
Expand Down