]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Rename Chart.layout to Chart.layouts (#5118)
authorSimon Brunel <simonbrunel@users.noreply.github.com>
Tue, 9 Jan 2018 13:12:40 +0000 (14:12 +0100)
committerGitHub <noreply@github.com>
Tue, 9 Jan 2018 13:12:40 +0000 (14:12 +0100)
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).

src/chart.js
src/core/core.controller.js
src/core/core.layouts.js [moved from src/core/core.layout.js with 100% similarity]
src/core/core.scaleService.js
src/plugins/plugin.legend.js
src/plugins/plugin.title.js
test/specs/core.layouts.tests.js [moved from test/specs/core.layoutService.tests.js with 97% similarity]
test/specs/global.deprecations.tests.js

index 70d70a669952640b47b6c1007c14b527828cfe66..a958e343ff8eed56d7f9dc6b774552ae9f3e6f61 100644 (file)
@@ -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;
index 157bc50a42362661339e0203f6aeb476fdc81ae2..e32255edcea62385be475998f17f3c21fcdbaaf0 100644 (file)
@@ -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.
index bfbf832094a2ad7a34a829900f4eeee70fd5b328..f2ea01d329ae9935ca4421e6ee6e2fa46a613461 100644 (file)
@@ -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);
                        });
                }
        };
index 3715ea3d5f782b06e398f072b6cb37c26fb594b4..3f1559c300320cb4c300f0a7d52676508260ae27 100644 (file)
@@ -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;
                }
        },
index 0a233f9bca4443f79218d37b39d5c1b48af6c73f..47588844d4c644137e1fb9068c5294a390f9bdf8 100644 (file)
@@ -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;
                }
        }
similarity index 97%
rename from test/specs/core.layoutService.tests.js
rename to test/specs/core.layouts.tests.js
index a8673971b064704981060ebec506e8250b1ebfa1..19b3a14b240d88cf25317834d89823722fa1fa59 100644 (file)
@@ -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
index 08d5e79dbab9a3ab649c8cdcdf29a3499e9fc56a..535b9af3307041896c242d5c64c7b0bacbc62d38 100644 (file)
@@ -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);
                                };