]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Deprecate Chart.{Type} classes (#5868)
authorSimon Brunel <simonbrunel@users.noreply.github.com>
Thu, 29 Nov 2018 06:56:20 +0000 (07:56 +0100)
committerGitHub <noreply@github.com>
Thu, 29 Nov 2018 06:56:20 +0000 (07:56 +0100)
It looks like these classes are a legacy from version 1 but we actually never promoted their usage. Instead, the regular way to create a chart is to set the type in the config, for example: `new Chart(ctx, {type: 'bar'})`. Some types are actually missing (no `Chart.HorizontalBar` or `Chart.Pie`) but it's also not scalable because it can easily conflict with other classes scoped under the `Chart` namespace.

src/chart.js
src/charts/Chart.Bar.js [deleted file]
src/charts/Chart.Bubble.js [deleted file]
src/charts/Chart.Doughnut.js [deleted file]
src/charts/Chart.Line.js [deleted file]
src/charts/Chart.PolarArea.js [deleted file]
src/charts/Chart.Radar.js [deleted file]
src/charts/Chart.Scatter.js [deleted file]
test/specs/global.deprecations.tests.js

index 1f6982ce47e2078314c70ca2bb395388154ed8c3..7b393e6b069e4cc114a3232c1dc22a55a5dcfd99 100644 (file)
@@ -42,14 +42,6 @@ require('./controllers/controller.polarArea')(Chart);
 require('./controllers/controller.radar')(Chart);
 require('./controllers/controller.scatter')(Chart);
 
-require('./charts/Chart.Bar')(Chart);
-require('./charts/Chart.Bubble')(Chart);
-require('./charts/Chart.Doughnut')(Chart);
-require('./charts/Chart.Line')(Chart);
-require('./charts/Chart.PolarArea')(Chart);
-require('./charts/Chart.Radar')(Chart);
-require('./charts/Chart.Scatter')(Chart);
-
 // Loading built-in plugins
 var plugins = require('./plugins');
 for (var k in plugins) {
@@ -116,8 +108,33 @@ Chart.canvasHelpers = Chart.helpers.canvas;
 /**
  * Provided for backward compatibility, use Chart.layouts instead.
  * @namespace Chart.layoutService
- * @deprecated since version 2.8.0
+ * @deprecated since version 2.7.3
  * @todo remove at version 3
  * @private
  */
 Chart.layoutService = Chart.layouts;
+
+/**
+ * Provided for backward compatibility, instead we should create a new Chart
+ * by setting the type in the config (`new Chart(id, {type: '{chart-type}'}`).
+ * @deprecated since version 2.8.0
+ * @todo remove at version 3
+ */
+Chart.helpers.each(
+       [
+               'Bar',
+               'Bubble',
+               'Doughnut',
+               'Line',
+               'PolarArea',
+               'Radar',
+               'Scatter'
+       ],
+       function(klass) {
+               Chart[klass] = function(ctx, cfg) {
+                       return new Chart(ctx, Chart.helpers.merge(cfg || {}, {
+                               type: klass.charAt(0).toLowerCase() + klass.slice(1)
+                       }));
+               };
+       }
+);
diff --git a/src/charts/Chart.Bar.js b/src/charts/Chart.Bar.js
deleted file mode 100644 (file)
index e1ad796..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-'use strict';
-
-module.exports = function(Chart) {
-
-       Chart.Bar = function(context, config) {
-               config.type = 'bar';
-
-               return new Chart(context, config);
-       };
-
-};
diff --git a/src/charts/Chart.Bubble.js b/src/charts/Chart.Bubble.js
deleted file mode 100644 (file)
index 2de4a10..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-'use strict';
-
-module.exports = function(Chart) {
-
-       Chart.Bubble = function(context, config) {
-               config.type = 'bubble';
-               return new Chart(context, config);
-       };
-
-};
diff --git a/src/charts/Chart.Doughnut.js b/src/charts/Chart.Doughnut.js
deleted file mode 100644 (file)
index e1e8ce5..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-'use strict';
-
-module.exports = function(Chart) {
-
-       Chart.Doughnut = function(context, config) {
-               config.type = 'doughnut';
-
-               return new Chart(context, config);
-       };
-
-};
diff --git a/src/charts/Chart.Line.js b/src/charts/Chart.Line.js
deleted file mode 100644 (file)
index e89662f..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-'use strict';
-
-module.exports = function(Chart) {
-
-       Chart.Line = function(context, config) {
-               config.type = 'line';
-
-               return new Chart(context, config);
-       };
-
-};
diff --git a/src/charts/Chart.PolarArea.js b/src/charts/Chart.PolarArea.js
deleted file mode 100644 (file)
index e07e4ba..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-'use strict';
-
-module.exports = function(Chart) {
-
-       Chart.PolarArea = function(context, config) {
-               config.type = 'polarArea';
-
-               return new Chart(context, config);
-       };
-
-};
diff --git a/src/charts/Chart.Radar.js b/src/charts/Chart.Radar.js
deleted file mode 100644 (file)
index d17bd5d..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-'use strict';
-
-module.exports = function(Chart) {
-
-       Chart.Radar = function(context, config) {
-               config.type = 'radar';
-
-               return new Chart(context, config);
-       };
-
-};
diff --git a/src/charts/Chart.Scatter.js b/src/charts/Chart.Scatter.js
deleted file mode 100644 (file)
index 9006e57..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-'use strict';
-
-module.exports = function(Chart) {
-       Chart.Scatter = function(context, config) {
-               config.type = 'scatter';
-               return new Chart(context, config);
-       };
-};
index 11d25d1d9b69ce6d200d41f988f82920f95454cd..6992f23cf1ee2ab4daeb60b99c94829d20d758a3 100644 (file)
@@ -1,5 +1,32 @@
 describe('Deprecations', function() {
        describe('Version 2.8.0', function() {
+               [
+                       ['Bar', 'bar'],
+                       ['Bubble', 'bubble'],
+                       ['Doughnut', 'doughnut'],
+                       ['Line', 'line'],
+                       ['PolarArea', 'polarArea'],
+                       ['Radar', 'radar'],
+                       ['Scatter', 'scatter']
+               ].forEach(function(descriptor) {
+                       var klass = descriptor[0];
+                       var type = descriptor[1];
+
+                       describe('Chart.' + klass, function() {
+                               it('should be defined as a function', function() {
+                                       expect(Chart[klass]).toBeDefined();
+                                       expect(typeof Chart[klass]).toBe('function');
+                               });
+                               it('should create a chart of type "' + type + '"', function() {
+                                       var chart = new Chart[klass]('foo', {data: {}});
+                                       expect(chart instanceof Chart.Controller).toBeTruthy();
+                                       expect(chart.config.type).toBe(type);
+                               });
+                       });
+               });
+       });
+
+       describe('Version 2.7.3', function() {
                describe('Chart.layoutService', function() {
                        it('should be defined and an alias of Chart.layouts', function() {
                                expect(Chart.layoutService).toBeDefined();