From e52f32e04a7c99379bbf2f4b5fcfe3dc4a6b22a7 Mon Sep 17 00:00:00 2001 From: Simon Brunel Date: Mon, 8 Jan 2018 17:35:52 +0100 Subject: [PATCH] Rename Chart.layout to Chart.layouts --- src/chart.js | 6 +++--- src/core/core.controller.js | 6 +++--- src/core/{core.layout.js => core.layouts.js} | 0 src/core/core.scaleService.js | 4 ++-- src/plugins/plugin.legend.js | 10 +++++----- src/plugins/plugin.title.js | 10 +++++----- ...layoutService.tests.js => core.layouts.tests.js} | 13 +++++++++++-- test/specs/global.deprecations.tests.js | 8 ++++---- 8 files changed, 33 insertions(+), 24 deletions(-) rename src/core/{core.layout.js => core.layouts.js} (100%) rename test/specs/{core.layoutService.tests.js => core.layouts.tests.js} (97%) diff --git a/src/chart.js b/src/chart.js index 70d70a66995..a958e343ff8 100644 --- a/src/chart.js +++ b/src/chart.js @@ -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'); @@ -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; diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 157bc50a423..e32255edcea 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -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'); @@ -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( @@ -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. diff --git a/src/core/core.layout.js b/src/core/core.layouts.js similarity index 100% rename from src/core/core.layout.js rename to src/core/core.layouts.js diff --git a/src/core/core.scaleService.js b/src/core/core.scaleService.js index bfbf832094a..f2ea01d329a 100644 --- a/src/core/core.scaleService.js +++ b/src/core/core.scaleService.js @@ -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) { @@ -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); }); } }; diff --git a/src/plugins/plugin.legend.js b/src/plugins/plugin.legend.js index 3715ea3d5f7..3f1559c3003 100644 --- a/src/plugins/plugin.legend.js +++ b/src/plugins/plugin.legend.js @@ -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; @@ -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; } @@ -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; } }, diff --git a/src/plugins/plugin.title.js b/src/plugins/plugin.title.js index 0a233f9bca4..47588844d4c 100644 --- a/src/plugins/plugin.title.js +++ b/src/plugins/plugin.title.js @@ -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; @@ -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; } @@ -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; } } diff --git a/test/specs/core.layoutService.tests.js b/test/specs/core.layouts.tests.js similarity index 97% rename from test/specs/core.layoutService.tests.js rename to test/specs/core.layouts.tests.js index a8673971b06..19b3a14b240 100644 --- a/test/specs/core.layoutService.tests.js +++ b/test/specs/core.layouts.tests.js @@ -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 diff --git a/test/specs/global.deprecations.tests.js b/test/specs/global.deprecations.tests.js index 08d5e79dbab..535b9af3307 100644 --- a/test/specs/global.deprecations.tests.js +++ b/test/specs/global.deprecations.tests.js @@ -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); }); }); }); @@ -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); };