]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Remove proposal and obsolete features (#7425)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Tue, 26 May 2020 23:16:23 +0000 (02:16 +0300)
committerGitHub <noreply@github.com>
Tue, 26 May 2020 23:16:23 +0000 (19:16 -0400)
21 files changed:
babel.config.json
docs/docs/developers/axes.md
docs/docs/developers/charts.md
package-lock.json
package.json
rollup.config.js
src/core/core.controller.js
src/core/core.datasetController.js
src/core/core.element.js
src/elements/element.arc.js
src/elements/element.line.js
src/elements/element.point.js
src/elements/element.rectangle.js
src/helpers/helpers.core.js
src/scales/scale.category.js
src/scales/scale.linear.js
src/scales/scale.logarithmic.js
src/scales/scale.radialLinear.js
src/scales/scale.time.js
test/specs/core.scale.tests.js
test/specs/helpers.core.tests.js

index dedc58c80ae3f9a4f4a484727d54d428d7878c6e..f49a9a87ca761147b2e4ae019c9b37a2e64514c4 100644 (file)
@@ -3,27 +3,9 @@
     "@babel/preset-env"
   ],
   "plugins": [
-    "@babel/plugin-proposal-class-properties",
     "@babel/plugin-transform-object-assign"
   ],
   "env": {
-    "es6": {
-      "presets": [
-        [
-          "@babel/preset-env",
-          {
-            "targets": {
-              "esmodules": true
-            },
-            "modules": false,
-            "useBuiltIns": false
-          }
-        ]
-      ],
-      "plugins": [
-        "@babel/plugin-proposal-class-properties"
-      ]
-    },
     "test": {
       "plugins": [
         "istanbul"
index fc64933afd3e308971a34d37304b6e536d2accb3..d6adadbe4a1ef4cc3fdf2bf5408afa910e4a1adb 100644 (file)
@@ -5,9 +5,9 @@ title: New Axes
 Axes in Chart.js can be individually extended. Axes should always derive from `Chart.Scale` but this is not a mandatory requirement.
 
 ```javascript
-let MyScale = Chart.Scale.extend({
+class MyScale extends Chart.Scale{
     /* extensions ... */
-});
+}
 MyScale.id = 'myScale';
 MyScale.defaults = defaultConfigObject;
 
index 75b3a1c4a7a44f8aad9fe8bb38f20ec6a396787f..6149b6af547a781b311a8e904652ac154a5a7191 100644 (file)
@@ -5,10 +5,11 @@ title: New Charts
 Chart.js 2.0 introduces the concept of controllers for each dataset. Like scales, new controllers can be written as needed.
 
 ```javascript
-Chart.controllers.MyType = Chart.DatasetController.extend({
+class MyType extends Chart.DatasetController {
 
-});
+}
 
+Chart.controllers.MyType = MyType;
 
 // Now we can create a new instance of our chart, using the Chart.js API
 new Chart(ctx, {
@@ -67,6 +68,7 @@ The following methods may optionally be overridden by derived dataset controller
 Extending or replacing an existing controller type is easy. Simply replace the constructor for one of the built in types with your own.
 
 The built in controller types are:
+
 * `Chart.controllers.line`
 * `Chart.controllers.bar`
 * `Chart.controllers.horizontalBar`
@@ -84,10 +86,10 @@ For example, to derive a new chart type that extends from a bubble chart, you wo
 Chart.defaults.derivedBubble = Chart.defaults.bubble;
 
 // I think the recommend using Chart.controllers.bubble.extend({ extensions here });
-var custom = Chart.controllers.bubble.extend({
-    draw: function(ease) {
+class Custom extends Chart.controllers.bubble {
+    draw() {
         // Call super method first
-        Chart.controllers.bubble.prototype.draw.call(this, ease);
+        super.draw(arguments);
 
         // Now we can do some custom drawing for this dataset. Here we'll draw a red box around the first point in each dataset
         var meta = this.getMeta();
@@ -105,7 +107,7 @@ var custom = Chart.controllers.bubble.extend({
 
 // Stores the controller so that the chart initialization routine can look it up with
 // Chart.controllers[type]
-Chart.controllers.derivedBubble = custom;
+Chart.controllers.derivedBubble = Custom;
 
 // Now we can create and use our new chart type
 new Chart(ctx, {
index 928cba7ad2cfae8d3e69beac2c09168204579a08..8e0bfe043c734260937b85e8d18985453c23c290 100644 (file)
         "semver": "^5.5.0"
       }
     },
-    "@babel/helper-create-class-features-plugin": {
-      "version": "7.9.6",
-      "resolved": "https://registry.npmjs.org/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.9.6.tgz",
-      "integrity": "sha512-6N9IeuyHvMBRyjNYOMJHrhwtu4WJMrYf8hVbEHD3pbbbmNOk1kmXSQs7bA4dYDUaIx4ZEzdnvo6NwC3WHd/Qow==",
-      "dev": true,
-      "requires": {
-        "@babel/helper-function-name": "^7.9.5",
-        "@babel/helper-member-expression-to-functions": "^7.8.3",
-        "@babel/helper-optimise-call-expression": "^7.8.3",
-        "@babel/helper-plugin-utils": "^7.8.3",
-        "@babel/helper-replace-supers": "^7.9.6",
-        "@babel/helper-split-export-declaration": "^7.8.3"
-      }
-    },
     "@babel/helper-create-regexp-features-plugin": {
       "version": "7.8.8",
       "resolved": "https://registry.npmjs.org/@babel/helper-create-regexp-features-plugin/-/helper-create-regexp-features-plugin-7.8.8.tgz",
         "@babel/plugin-syntax-async-generators": "^7.8.0"
       }
     },
-    "@babel/plugin-proposal-class-properties": {
-      "version": "7.8.3",
-      "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.8.3.tgz",
-      "integrity": "sha512-EqFhbo7IosdgPgZggHaNObkmO1kNUe3slaKu54d5OWvy+p9QIKOzK1GAEpAIsZtWVtPXUHSMcT4smvDrCfY4AA==",
-      "dev": true,
-      "requires": {
-        "@babel/helper-create-class-features-plugin": "^7.8.3",
-        "@babel/helper-plugin-utils": "^7.8.3"
-      }
-    },
     "@babel/plugin-proposal-dynamic-import": {
       "version": "7.8.3",
       "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-dynamic-import/-/plugin-proposal-dynamic-import-7.8.3.tgz",
index 7ee84f647d382653ca12571f66e0e8c6bca28c56..2c0b522219e4be0f5bc9715c495f80cc104b4ec3 100644 (file)
@@ -34,7 +34,6 @@
   },
   "devDependencies": {
     "@babel/core": "^7.9.6",
-    "@babel/plugin-proposal-class-properties": "^7.8.3",
     "@babel/plugin-transform-object-assign": "^7.8.3",
     "@babel/preset-env": "^7.9.6",
     "@rollup/plugin-commonjs": "^11.1.0",
index beba09218a716c4fcb60363cfe31d187e13415b6..554e154f399d4aa9bd02b6f64d3e6d4b95a98be7 100644 (file)
@@ -74,7 +74,6 @@ module.exports = [
                plugins: [
                        json(),
                        resolve(),
-                       babel({envName: 'es6'}),
                        cleanup({
                                sourcemap: true
                        })
@@ -92,7 +91,6 @@ module.exports = [
                plugins: [
                        json(),
                        resolve(),
-                       babel({envName: 'es6'}),
                        terser({
                                output: {
                                        preamble: banner
index 220fa198fec7299962072d731d1e9c0be58bbb35..c31e92a9423f334a66b9d26fab16b9f3f3126bf1 100644 (file)
@@ -172,16 +172,7 @@ function getCanvas(item) {
        return item;
 }
 
-export default class Chart {
-
-       static version = version;
-
-       /**
-        * NOTE(SB) We actually don't use this container anymore but we need to keep it
-        * for backward compatibility. Though, it can still be useful for plugins that
-        * would need to work on multiple charts?!
-        */
-       static instances = {};
+class Chart {
 
        constructor(item, config) {
                const me = this;
@@ -1128,3 +1119,14 @@ export default class Chart {
                return changed;
        }
 }
+
+Chart.version = version;
+
+/**
+ * NOTE(SB) We actually don't use this container anymore but we need to keep it
+ * for backward compatibility. Though, it can still be useful for plugins that
+ * would need to work on multiple charts?!
+ */
+Chart.instances = {};
+
+export default Chart;
index 4d95ec7023d54847f45fdc520bad3f4da5194d1f..478f773605621646d80dbeecb6590f359efc5665 100644 (file)
@@ -1,5 +1,5 @@
 import Animations from './core.animations';
-import {isObject, inherits, merge, _merger, isArray, valueOrDefault, mergeIf, arrayEquals} from '../helpers/helpers.core';
+import {isObject, merge, _merger, isArray, valueOrDefault, mergeIf, arrayEquals} from '../helpers/helpers.core';
 import {resolve} from '../helpers/helpers.options';
 import {getHoverColor} from '../helpers/helpers.color';
 import {sign} from '../helpers/helpers.math';
@@ -218,8 +218,6 @@ function getFirstScaleId(chart, axis) {
 
 export default class DatasetController {
 
-       static extend = inherits;
-
        /**
         * @param {Chart} chart
         * @param {number} datasetIndex
index a5a56f550df80e40bcce013221a53c2d47c6ee15..039ef657b41dbb933938f421fa395f15a06f9693 100644 (file)
@@ -1,10 +1,7 @@
-import {inherits} from '../helpers/helpers.core';
 import {isNumber} from '../helpers/helpers.math';
 
 export default class Element {
 
-       static extend = inherits;
-
        constructor() {
                this.x = undefined;
                this.y = undefined;
index bd0435390c50314f5d29d561a8e500cd63bfd2fb..3f14196c884afd4872a2e9e4fbea823ca1a1a711 100644 (file)
@@ -84,9 +84,7 @@ function drawBorder(ctx, vm, arc) {
        ctx.stroke();
 }
 
-export default class Arc extends Element {
-
-       static _type = 'arc';
+class Arc extends Element {
 
        constructor(cfg) {
                super();
@@ -197,3 +195,7 @@ export default class Arc extends Element {
                ctx.restore();
        }
 }
+
+Arc._type = 'arc';
+
+export default Arc;
index 4a479e5abc32f5a831adaeb302003a87351559ea..76c72e685ff8442593e0184cd98c96ae45c0a6e0 100644 (file)
@@ -196,9 +196,7 @@ function _getInterpolationMethod(options) {
        return _pointInLine;
 }
 
-export default class Line extends Element {
-
-       static _type = 'line';
+class Line extends Element {
 
        constructor(cfg) {
                super();
@@ -357,3 +355,7 @@ export default class Line extends Element {
                ctx.restore();
        }
 }
+
+Line._type = 'line';
+
+export default Line;
index c26c1cb3f5782e57f2e2c32c3017956adf109ec8..ec2468eb4f8727ba1eee36f1a5d74893f21a966e 100644 (file)
@@ -17,9 +17,7 @@ defaults.set('elements', {
        }
 });
 
-export default class Point extends Element {
-
-       static _type = 'point';
+class Point extends Element {
 
        constructor(cfg) {
                super();
@@ -86,3 +84,7 @@ export default class Point extends Element {
                return options.radius + options.hitRadius;
        }
 }
+
+Point._type = 'point';
+
+export default Point;
index 55878f782e92bc980cc141a108deb05c7f3ba046..739de83e1319c2e76c8c99bc624215ffafef5f61 100644 (file)
@@ -124,9 +124,7 @@ function inRange(bar, x, y, useFinalPosition) {
                && (skipY || y >= bounds.top && y <= bounds.bottom);
 }
 
-export default class Rectangle extends Element {
-
-       static _type = 'rectangle';
+class Rectangle extends Element {
 
        constructor(cfg) {
                super();
@@ -187,3 +185,7 @@ export default class Rectangle extends Element {
                return axis === 'x' ? this.width / 2 : this.height / 2;
        }
 }
+
+Rectangle._type = 'rectangle';
+
+export default Rectangle;
index 0e5ad2a4b4c72bfe50970097ad221efc90e23249..6a5f52581553ac73ba9c2042c8e7ca0347a78986 100644 (file)
@@ -293,33 +293,6 @@ export function _mergerIf(key, target, source) {
        }
 }
 
-/**
- * Basic javascript inheritance based on the model created in Backbone.js
- */
-export function inherits(extensions) {
-       // eslint-disable-next-line no-invalid-this
-       const me = this;
-       const ChartElement = (extensions && Object.prototype.hasOwnProperty.call(extensions, 'constructor')) ? extensions.constructor : function() {
-               // eslint-disable-next-line prefer-rest-params
-               return me.apply(this, arguments);
-       };
-
-       const Surrogate = function() {
-               this.constructor = ChartElement;
-       };
-
-       Surrogate.prototype = me.prototype;
-       ChartElement.prototype = new Surrogate();
-       ChartElement.extend = inherits;
-
-       if (extensions) {
-               Object.assign(ChartElement.prototype, extensions);
-       }
-
-       ChartElement.__super__ = me.prototype;
-       return ChartElement;
-}
-
 /**
  * @private
  */
index 57aa5439bd0176651777948d5e5e54fa91524830..3386aa1e08afc8412c95de4786bd7be7d53235ab 100644 (file)
@@ -3,11 +3,7 @@ import Scale from '../core/core.scale';
 const defaultConfig = {
 };
 
-export default class CategoryScale extends Scale {
-
-       static id = 'category';
-       // INTERNAL: static default options, registered in src/index.js
-       static defaults = defaultConfig;
+class CategoryScale extends Scale {
 
        constructor(cfg) {
                super(cfg);
@@ -109,3 +105,10 @@ export default class CategoryScale extends Scale {
                return this.bottom;
        }
 }
+
+CategoryScale.id = 'category';
+
+// INTERNAL: default options, registered in src/index.js
+CategoryScale.defaults = defaultConfig;
+
+export default CategoryScale;
index d84bff9d8b5440b31a23140fce1216ae91fa9690..f6392e5e64d3e5956d57eeff5a4691b5afb26f10 100644 (file)
@@ -8,11 +8,7 @@ const defaultConfig = {
        }
 };
 
-export default class LinearScale extends LinearScaleBase {
-
-       static id = 'linear';
-       // INTERNAL: static default options, registered in src/index.js
-       static defaults = defaultConfig;
+class LinearScale extends LinearScaleBase {
 
        determineDataLimits() {
                const me = this;
@@ -66,3 +62,10 @@ export default class LinearScale extends LinearScaleBase {
                return this._startValue + this.getDecimalForPixel(pixel) * this._valueRange;
        }
 }
+
+LinearScale.id = 'linear';
+
+// INTERNAL: default options, registered in src/index.js
+LinearScale.defaults = defaultConfig;
+
+export default LinearScale;
index 26ca37f7b0a034e4a5467678b9e51a39b63f4eaa..7efc88ceb530f3d53fd09d793a65b89fcd87183b 100644 (file)
@@ -57,11 +57,7 @@ const defaultConfig = {
        }
 };
 
-export default class LogarithmicScale extends Scale {
-
-       static id = 'logarithmic';
-       // INTERNAL: static default options, registered in src/index.js
-       static defaults = defaultConfig;
+class LogarithmicScale extends Scale {
 
        constructor(cfg) {
                super(cfg);
@@ -187,3 +183,10 @@ export default class LogarithmicScale extends Scale {
                return Math.pow(10, me._startValue + decimal * me._valueRange);
        }
 }
+
+LogarithmicScale.id = 'logarithmic';
+
+// INTERNAL: default options, registered in src/index.js
+LogarithmicScale.defaults = defaultConfig;
+
+export default LogarithmicScale;
index e31f628f9fe3833c1501169da14827f3086fe077..f8fb11fe4584d424049ddd11e4b8bd3f94bf267c 100644 (file)
@@ -289,11 +289,7 @@ function numberOrZero(param) {
        return isNumber(param) ? param : 0;
 }
 
-export default class RadialLinearScale extends LinearScaleBase {
-
-       static id = 'radialLinear';
-       // INTERNAL: static default options, registered in src/index.js
-       static defaults = defaultConfig;
+class RadialLinearScale extends LinearScaleBase {
 
        constructor(cfg) {
                super(cfg);
@@ -547,3 +543,10 @@ export default class RadialLinearScale extends LinearScaleBase {
         */
        drawTitle() {}
 }
+
+RadialLinearScale.id = 'radialLinear';
+
+// INTERNAL: default options, registered in src/index.js
+RadialLinearScale.defaults = defaultConfig;
+
+export default RadialLinearScale;
index 480cd706c1999c49e1fbe5af81aaab9d1e5617f7..a6b505c7e13429f4f3da6c5b3c66f4ce9f14464c 100644 (file)
@@ -542,11 +542,7 @@ const defaultConfig = {
        }
 };
 
-export default class TimeScale extends Scale {
-
-       static id = 'time';
-       // INTERNAL: static default options, registered in src/index.js
-       static defaults = defaultConfig;
+class TimeScale extends Scale {
 
        /**
         * @param {object} props
@@ -812,3 +808,10 @@ export default class TimeScale extends Scale {
                return capacity > 0 ? capacity : 1;
        }
 }
+
+TimeScale.id = 'time';
+
+// INTERNAL: default options, registered in src/index.js
+TimeScale.defaults = defaultConfig;
+
+export default TimeScale;
index 7a0da05dd8fb07b5afb1589e15cfcb118a4fb7a6..556fea585a2132fd3f1cb0482b882e3952d73f51 100644 (file)
@@ -454,15 +454,15 @@ describe('Core.scale', function() {
                });
 
                it('should default to one layer for custom scales', function() {
-                       var customScale = Chart.Scale.extend({
-                               draw: function() {},
-                               convertTicksToLabels: function() {
+                       class CustomScale extends Chart.Scale {
+                               draw() {}
+                               convertTicksToLabels() {
                                        return ['tick'];
                                }
-                       });
-                       customScale.id = 'customScale';
-                       customScale.defaults = {};
-                       Chart.scaleService.registerScale(customScale);
+                       }
+                       CustomScale.id = 'customScale';
+                       CustomScale.defaults = {};
+                       Chart.scaleService.registerScale(CustomScale);
 
                        var chart = window.acquireChart({
                                type: 'line',
index 2586173e78916af210bcffef70bc0603497d80bd..aa687784ed59d9947487b62bb87bc2d17d17a2af 100644 (file)
@@ -429,57 +429,4 @@ describe('Chart.helpers.core', function() {
                        expect(output.o.a).not.toBe(a1);
                });
        });
-
-       describe('extend', function() {
-               it('should merge object properties in target and return target', function() {
-                       var target = {a: 'abc', b: 56};
-                       var object = {b: 0, c: [2, 5, 6]};
-                       var result = Object.assign(target, object);
-
-                       expect(result).toBe(target);
-                       expect(target).toEqual({a: 'abc', b: 0, c: [2, 5, 6]});
-               });
-               it('should merge multiple objects properties in target', function() {
-                       var target = {a: 0, b: 1};
-                       var o0 = {a: 2, c: 3, d: 4};
-                       var o1 = {a: 5, c: 6};
-                       var o2 = {a: 7, e: 8};
-
-                       Object.assign(target, o0, o1, o2);
-
-                       expect(target).toEqual({a: 7, b: 1, c: 6, d: 4, e: 8});
-               });
-               it('should not deeply merge object properties in target', function() {
-                       var target = {a: {b: 0, c: 1}};
-                       var object = {a: {b: 2, d: 3}};
-
-                       Object.assign(target, object);
-
-                       expect(target).toEqual({a: {b: 2, d: 3}});
-                       expect(target.a).toBe(object.a);
-               });
-       });
-
-       describe('inherits', function() {
-               it('should return a derived class', function() {
-                       var A = function() {};
-                       A.prototype.p0 = 41;
-                       A.prototype.p1 = function() {
-                               return '42';
-                       };
-
-                       A.inherits = helpers.inherits;
-                       var B = A.inherits({p0: 43, p2: [44]});
-                       var C = A.inherits({p3: 45, p4: [46]});
-                       var b = new B();
-
-                       expect(b instanceof A).toBeTruthy();
-                       expect(b instanceof B).toBeTruthy();
-                       expect(b instanceof C).toBeFalsy();
-
-                       expect(b.p0).toBe(43);
-                       expect(b.p1()).toBe('42');
-                       expect(b.p2).toEqual([44]);
-               });
-       });
 });