Skip to content

Commit

Permalink
Rename Chart.layout to Chart.layouts (#5118)
Browse files Browse the repository at this point in the history
Chart.layouts seems more consistent with other service names (Chart.plugins, Chart.scales, etc.) but also more inline with the service which handle many layout (one per charts).
  • Loading branch information
simonbrunel authored Jan 9, 2018
1 parent fb3ea03 commit 6bea15e
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Chart.defaults = require('./core/core.defaults');
Chart.Element = require('./core/core.element');
Chart.elements = require('./elements/index');
Chart.Interaction = require('./core/core.interaction');
Chart.layout = require('./core/core.layout');
Chart.layouts = require('./core/core.layouts');
Chart.platform = require('./platforms/platform');
Chart.plugins = require('./core/core.plugins');
Chart.Ticks = require('./core/core.ticks');
Expand Down Expand Up @@ -113,10 +113,10 @@ Chart.PluginBase = Chart.Element.extend({});
Chart.canvasHelpers = Chart.helpers.canvas;

/**
* Provided for backward compatibility, use Chart.layout instead.
* Provided for backward compatibility, use Chart.layouts instead.
* @namespace Chart.layoutService
* @deprecated since version 2.8.0
* @todo remove at version 3
* @private
*/
Chart.layoutService = Chart.layout;
Chart.layoutService = Chart.layouts;
6 changes: 3 additions & 3 deletions src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var defaults = require('./core.defaults');
var helpers = require('../helpers/index');
var Interaction = require('./core.interaction');
var layout = require('./core.layout');
var layouts = require('./core.layouts');
var platform = require('../platforms/platform');
var plugins = require('./core.plugins');

Expand Down Expand Up @@ -47,7 +47,7 @@ module.exports = function(Chart) {
var newOptions = chart.options;

helpers.each(chart.scales, function(scale) {
layout.removeBox(chart, scale);
layouts.removeBox(chart, scale);
});

newOptions = helpers.configMerge(
Expand Down Expand Up @@ -436,7 +436,7 @@ module.exports = function(Chart) {
return;
}

layout.update(this, this.width, this.height);
layouts.update(this, this.width, this.height);

/**
* Provided for backward compatibility, use `afterLayout` instead.
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/core/core.scaleService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var defaults = require('./core.defaults');
var helpers = require('../helpers/index');
var layout = require('./core.layout');
var layouts = require('./core.layouts');

module.exports = function(Chart) {

Expand Down Expand Up @@ -39,7 +39,7 @@ module.exports = function(Chart) {
scale.fullWidth = scale.options.fullWidth;
scale.position = scale.options.position;
scale.weight = scale.options.weight;
layout.addBox(chart, scale);
layouts.addBox(chart, scale);
});
}
};
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/plugin.legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var defaults = require('../core/core.defaults');
var Element = require('../core/core.element');
var helpers = require('../helpers/index');
var layout = require('../core/core.layout');
var layouts = require('../core/core.layouts');

var noop = helpers.noop;

Expand Down Expand Up @@ -523,8 +523,8 @@ function createNewLegendAndAttach(chart, legendOpts) {
chart: chart
});

layout.configure(chart, legend, legendOpts);
layout.addBox(chart, legend);
layouts.configure(chart, legend, legendOpts);
layouts.addBox(chart, legend);
chart.legend = legend;
}

Expand Down Expand Up @@ -556,13 +556,13 @@ module.exports = {
helpers.mergeIf(legendOpts, defaults.global.legend);

if (legend) {
layout.configure(chart, legend, legendOpts);
layouts.configure(chart, legend, legendOpts);
legend.options = legendOpts;
} else {
createNewLegendAndAttach(chart, legendOpts);
}
} else if (legend) {
layout.removeBox(chart, legend);
layouts.removeBox(chart, legend);
delete chart.legend;
}
},
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/plugin.title.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var defaults = require('../core/core.defaults');
var Element = require('../core/core.element');
var helpers = require('../helpers/index');
var layout = require('../core/core.layout');
var layouts = require('../core/core.layouts');

var noop = helpers.noop;

Expand Down Expand Up @@ -206,8 +206,8 @@ function createNewTitleBlockAndAttach(chart, titleOpts) {
chart: chart
});

layout.configure(chart, title, titleOpts);
layout.addBox(chart, title);
layouts.configure(chart, title, titleOpts);
layouts.addBox(chart, title);
chart.titleBlock = title;
}

Expand Down Expand Up @@ -239,13 +239,13 @@ module.exports = {
helpers.mergeIf(titleOpts, defaults.global.title);

if (titleBlock) {
layout.configure(chart, titleBlock, titleOpts);
layouts.configure(chart, titleBlock, titleOpts);
titleBlock.options = titleOpts;
} else {
createNewTitleBlockAndAttach(chart, titleOpts);
}
} else if (titleBlock) {
layout.removeBox(chart, titleBlock);
layouts.removeBox(chart, titleBlock);
delete chart.titleBlock;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
// Tests of the scale service
describe('Test the layout service', function() {
describe('Chart.layouts', function() {
it('should be exposed through Chart.layouts', function() {
expect(Chart.layouts).toBeDefined();
expect(typeof Chart.layouts).toBe('object');
expect(Chart.layouts.defaults).toBeDefined();
expect(Chart.layouts.addBox).toBeDefined();
expect(Chart.layouts.removeBox).toBeDefined();
expect(Chart.layouts.configure).toBeDefined();
expect(Chart.layouts.update).toBeDefined();
});

// Disable tests which need to be rewritten based on changes introduced by
// the following changes: https://github.com/chartjs/Chart.js/pull/2346
// using xit marks the test as pending: http://jasmine.github.io/2.0/introduction.html#section-Pending_Specs
Expand Down
8 changes: 4 additions & 4 deletions test/specs/global.deprecations.tests.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
describe('Deprecations', function() {
describe('Version 2.8.0', function() {
describe('Chart.layoutService', function() {
it('should be defined and an alias of Chart.layout', function() {
it('should be defined and an alias of Chart.layouts', function() {
expect(Chart.layoutService).toBeDefined();
expect(Chart.layoutService).toBe(Chart.layout);
expect(Chart.layoutService).toBe(Chart.layouts);
});
});
});
Expand Down Expand Up @@ -311,8 +311,8 @@ describe('Deprecations', function() {
'afterLayout'
];

var override = Chart.layout.update;
Chart.layout.update = function() {
var override = Chart.layouts.update;
Chart.layouts.update = function() {
sequence.push('layoutUpdate');
override.apply(this, arguments);
};
Expand Down

0 comments on commit 6bea15e

Please sign in to comment.