From: Jukka Kurkela Date: Thu, 19 Nov 2020 12:55:20 +0000 (+0200) Subject: Remove classic style extensions from docs/tests (#8076) X-Git-Tag: v3.0.0-beta.7~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb1f90ca0e0179e1093fd974c5627a473957a0a1;p=thirdparty%2FChart.js.git Remove classic style extensions from docs/tests (#8076) --- diff --git a/docs/docs/developers/axes.md b/docs/docs/developers/axes.md index e28f937c8..8a60ecb10 100644 --- a/docs/docs/developers/axes.md +++ b/docs/docs/developers/axes.md @@ -11,23 +11,6 @@ class MyScale extends Chart.Scale { MyScale.id = 'myScale'; MyScale.defaults = defaultConfigObject; -// Or in classic style -/* -function MyScale() { - Chart.Scale.call(this, arguments); - // constructor stuff -} -MyScale.prototype = Object.create(Chart.Scale.prototype); -MyScale.prototype.constructor = MyScale; - -MyScale.prototype.draw = function(ctx) { - Chart.Scale.prototype.draw.call(this, arguments); - // ... -} -MyScale.id = 'myScale'; -MyScale.defaults = defaultConfigObject; -*/ - // MyScale is now derived from Chart.Scale ``` diff --git a/docs/docs/developers/charts.md b/docs/docs/developers/charts.md index f4887480f..652cd41f5 100644 --- a/docs/docs/developers/charts.md +++ b/docs/docs/developers/charts.md @@ -113,44 +113,6 @@ new Chart(ctx, { }); ``` -Same example in classic style - -```javascript -function Custom() { - Chart.BubbleController.apply(this, arguments); - // constructor stuff -} -Custom.prototype = Object.create(Chart.BubbleController.prototype); -Custom.prototype.constructor = Custom; - -Custom.prototype.draw = function(ctx) { - Chart.BubbleController.prototype.draw.apply(this, arguments); - - var meta = this.getMeta(); - var pt0 = meta.data[0]; - var radius = pt0.radius; - - var ctx = this.chart.chart.ctx; - ctx.save(); - ctx.strokeStyle = 'red'; - ctx.lineWidth = 1; - ctx.strokeRect(pt0.x - radius, pt0.y - radius, 2 * radius, 2 * radius); - ctx.restore();} -} - -Custom.id = 'derivedBubble'; -Custom.defaults = Chart.defaults.bubble; - -Chart.register(Custom); - -// Now we can create and use our new chart type -new Chart(ctx, { - type: 'derivedBubble', - data: data, - options: options -}); -``` - ## TypeScript Typings If you want your new chart type to be statically typed, you must provide a `.d.ts` TypeScript declaration file. Chart.js provides a way to augment built-in types with user-defined ones, by using the concept of "declaration merging". diff --git a/test/specs/core.registry.tests.js b/test/specs/core.registry.tests.js index e93207dc0..05540390e 100644 --- a/test/specs/core.registry.tests.js +++ b/test/specs/core.registry.tests.js @@ -1,90 +1,4 @@ describe('Chart.registry', function() { - it('should handle a classic controller extension', function() { - function CustomController() { - Chart.controllers.line.apply(this, arguments); - } - CustomController.prototype = Object.create(Chart.controllers.line.prototype); - CustomController.prototype.constructor = CustomController; - CustomController.id = 'myline'; - CustomController.defaults = Chart.defaults.controllers.line; - - Chart.register(CustomController); - - expect(Chart.registry.getController('myline')).toEqual(CustomController); - expect(Chart.defaults.controllers.myline).toEqual(CustomController.defaults); - - Chart.unregister(CustomController); - }); - - it('should handle a classic scale extension', function() { - function CustomScale() { - Chart.Scale.apply(this, arguments); - } - CustomScale.prototype = Object.create(Chart.Scale.prototype); - CustomScale.prototype.constructor = CustomScale; - CustomScale.id = 'myScale'; - CustomScale.defaults = { - foo: 'bar' - }; - - Chart.register(CustomScale); - - expect(Chart.registry.getScale('myScale')).toEqual(CustomScale); - expect(Chart.defaults.scales.myScale).toEqual(CustomScale.defaults); - - Chart.unregister(CustomScale); - - expect(function() { - Chart.registry.getScale('myScale'); - }).toThrow(new Error('"myScale" is not a registered scale.')); - expect(Chart.defaults.scales.myScale).not.toBeDefined(); - }); - - it('should handle a classic element extension', function() { - function CustomElement() { - Chart.Element.apply(this, arguments); - } - CustomElement.prototype = Object.create(Chart.Element.prototype); - CustomElement.prototype.constructor = CustomElement; - CustomElement.id = 'myElement'; - CustomElement.defaults = { - foo: 'baz' - }; - - Chart.register(CustomElement); - - expect(Chart.registry.getElement('myElement')).toEqual(CustomElement); - expect(Chart.defaults.elements.myElement).toEqual(CustomElement.defaults); - - Chart.unregister(CustomElement); - - expect(function() { - Chart.registry.getElement('myElement'); - }).toThrow(new Error('"myElement" is not a registered element.')); - expect(Chart.defaults.elements.myElement).not.toBeDefined(); - }); - - it('should handle a classic plugin', function() { - const CustomPlugin = { - id: 'customPlugin', - defaults: { - custom: 'plugin' - } - }; - - Chart.register(CustomPlugin); - - expect(Chart.registry.getPlugin('customPlugin')).toEqual(CustomPlugin); - expect(Chart.defaults.plugins.customPlugin).toEqual(CustomPlugin.defaults); - - Chart.unregister(CustomPlugin); - - expect(function() { - Chart.registry.getPlugin('customPlugin'); - }).toThrow(new Error('"customPlugin" is not a registered plugin.')); - expect(Chart.defaults.plugins.customPlugin).not.toBeDefined(); - }); - it('should handle an ES6 controller extension', function() { class CustomController extends Chart.DatasetController {} CustomController.id = 'custom';