From 92a4654d9b2ae91683c179cbf6186b31952cfcd1 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sun, 27 Oct 2019 13:33:44 -0700 Subject: [PATCH] Remove deprecated helpers (#6607) --- src/core/core.helpers.js | 27 +- src/core/core.ticks.js | 7 +- src/helpers/helpers.canvas.js | 25 -- src/helpers/helpers.core.js | 41 --- src/helpers/helpers.easing.js | 15 +- src/helpers/helpers.math.js | 13 - src/platforms/platform.dom.js | 24 -- test/specs/core.helpers.tests.js | 11 - test/specs/global.deprecations.tests.js | 469 ------------------------ 9 files changed, 6 insertions(+), 626 deletions(-) delete mode 100644 test/specs/global.deprecations.tests.js diff --git a/src/core/core.helpers.js b/src/core/core.helpers.js index 33c94799e..3adbcd392 100644 --- a/src/core/core.helpers.js +++ b/src/core/core.helpers.js @@ -148,16 +148,6 @@ module.exports = function() { return Math.sqrt(Math.pow(pt2.x - pt1.x, 2) + Math.pow(pt2.y - pt1.y, 2)); }; - /** - * Provided for backward compatibility, not available anymore - * @function Chart.helpers.aliasPixel - * @deprecated since version 2.8.0 - * @todo remove at version 3 - */ - helpers.aliasPixel = function(pixelWidth) { - return (pixelWidth % 2 === 0) ? 0 : 0.5; - }; - /** * Returns the aligned pixel value to avoid anti-aliasing blur * @param {Chart} chart - The chart instance. @@ -312,7 +302,7 @@ module.exports = function() { }; // Implementation of the nice number algorithm used in determining where axis labels will go helpers.niceNum = function(range, round) { - var exponent = Math.floor(helpers.log10(range)); + var exponent = Math.floor(helpers.math.log10(range)); var fraction = range / Math.pow(10, exponent); var niceFraction; @@ -582,21 +572,6 @@ module.exports = function() { return longest; }; - /** - * @deprecated - */ - helpers.numberOfLabelLines = function(arrayOfThings) { - var numberOfLines = 1; - helpers.each(arrayOfThings, function(thing) { - if (helpers.isArray(thing)) { - if (thing.length > numberOfLines) { - numberOfLines = thing.length; - } - } - }); - return numberOfLines; - }; - helpers.color = !color ? function(value) { console.error('Color.js not found!'); diff --git a/src/core/core.ticks.js b/src/core/core.ticks.js index d9049fd2f..da1c14fb3 100644 --- a/src/core/core.ticks.js +++ b/src/core/core.ticks.js @@ -1,6 +1,7 @@ 'use strict'; var helpers = require('../helpers/index'); +var math = helpers.math; /** * Namespace to hold static tick generation functions @@ -42,13 +43,13 @@ module.exports = { } } - var logDelta = helpers.log10(Math.abs(delta)); + var logDelta = math.log10(Math.abs(delta)); var tickString = ''; if (tickValue !== 0) { var maxTick = Math.max(Math.abs(ticks[0]), Math.abs(ticks[ticks.length - 1])); if (maxTick < 1e-4) { // all ticks are small numbers; use scientific notation - var logTick = helpers.log10(Math.abs(tickValue)); + var logTick = math.log10(Math.abs(tickValue)); var numExponential = Math.floor(logTick) - Math.floor(logDelta); numExponential = Math.max(Math.min(numExponential, 20), 0); tickString = tickValue.toExponential(numExponential); @@ -65,7 +66,7 @@ module.exports = { }, logarithmic: function(tickValue, index, ticks) { - var remain = tickValue / (Math.pow(10, Math.floor(helpers.log10(tickValue)))); + var remain = tickValue / (Math.pow(10, Math.floor(math.log10(tickValue)))); if (tickValue === 0) { return '0'; diff --git a/src/helpers/helpers.canvas.js b/src/helpers/helpers.canvas.js index 00950f562..221e7de2c 100644 --- a/src/helpers/helpers.canvas.js +++ b/src/helpers/helpers.canvas.js @@ -1,7 +1,5 @@ 'use strict'; -var helpers = require('./helpers.core'); - var PI = Math.PI; var RAD_PER_DEG = PI / 180; var DOUBLE_PI = PI * 2; @@ -233,26 +231,3 @@ var exports = { }; module.exports = exports; - -// DEPRECATIONS - -/** - * Provided for backward compatibility, use Chart.helpers.canvas.clear instead. - * @namespace Chart.helpers.clear - * @deprecated since version 2.7.0 - * @todo remove at version 3 - * @private - */ -helpers.clear = exports.clear; - -/** - * Provided for backward compatibility, use Chart.helpers.canvas.roundedRect instead. - * @namespace Chart.helpers.drawRoundedRectangle - * @deprecated since version 2.7.0 - * @todo remove at version 3 - * @private - */ -helpers.drawRoundedRectangle = function(ctx) { - ctx.beginPath(); - exports.roundedRect.apply(exports, arguments); -}; diff --git a/src/helpers/helpers.core.js b/src/helpers/helpers.core.js index 350a20750..f9c5a0408 100644 --- a/src/helpers/helpers.core.js +++ b/src/helpers/helpers.core.js @@ -317,44 +317,3 @@ var helpers = { }; module.exports = helpers; - -// DEPRECATIONS - -/** - * Provided for backward compatibility, use Chart.helpers.callback instead. - * @function Chart.helpers.callCallback - * @deprecated since version 2.6.0 - * @todo remove at version 3 - * @private - */ -helpers.callCallback = helpers.callback; - -/** - * Provided for backward compatibility, use Array.prototype.indexOf instead. - * Array.prototype.indexOf compatibility: Chrome, Opera, Safari, FF1.5+, IE9+ - * @function Chart.helpers.indexOf - * @deprecated since version 2.7.0 - * @todo remove at version 3 - * @private - */ -helpers.indexOf = function(array, item, fromIndex) { - return Array.prototype.indexOf.call(array, item, fromIndex); -}; - -/** - * Provided for backward compatibility, use Chart.helpers.valueOrDefault instead. - * @function Chart.helpers.getValueOrDefault - * @deprecated since version 2.7.0 - * @todo remove at version 3 - * @private - */ -helpers.getValueOrDefault = helpers.valueOrDefault; - -/** - * Provided for backward compatibility, use Chart.helpers.valueAtIndexOrDefault instead. - * @function Chart.helpers.getValueAtIndexOrDefault - * @deprecated since version 2.7.0 - * @todo remove at version 3 - * @private - */ -helpers.getValueAtIndexOrDefault = helpers.valueAtIndexOrDefault; diff --git a/src/helpers/helpers.easing.js b/src/helpers/helpers.easing.js index 603e3f7f7..350f61f0f 100644 --- a/src/helpers/helpers.easing.js +++ b/src/helpers/helpers.easing.js @@ -1,10 +1,8 @@ 'use strict'; -var helpers = require('./helpers.core'); - /** * Easing functions adapted from Robert Penner's easing equations. - * @namespace Chart.helpers.easingEffects + * @namespace Chart.helpers.effects * @see http://www.robertpenner.com/easing/ */ var effects = { @@ -237,14 +235,3 @@ var effects = { module.exports = { effects: effects }; - -// DEPRECATIONS - -/** - * Provided for backward compatibility, use Chart.helpers.easing.effects instead. - * @function Chart.helpers.easingEffects - * @deprecated since version 2.7.0 - * @todo remove at version 3 - * @private - */ -helpers.easingEffects = effects; diff --git a/src/helpers/helpers.math.js b/src/helpers/helpers.math.js index f2b2b6f01..4cf45f9b8 100644 --- a/src/helpers/helpers.math.js +++ b/src/helpers/helpers.math.js @@ -1,7 +1,5 @@ 'use strict'; -var helpers = require('./helpers.core'); - /** * @alias Chart.helpers.math * @namespace @@ -44,14 +42,3 @@ var exports = { }; module.exports = exports; - -// DEPRECATIONS - -/** - * Provided for backward compatibility, use Chart.helpers.math.log10 instead. - * @namespace Chart.helpers.log10 - * @deprecated since version 2.9.0 - * @todo remove at version 3 - * @private - */ -helpers.log10 = exports.log10; diff --git a/src/platforms/platform.dom.js b/src/platforms/platform.dom.js index 03f8486be..b1964a32a 100644 --- a/src/platforms/platform.dom.js +++ b/src/platforms/platform.dom.js @@ -446,27 +446,3 @@ module.exports = { removeListener(canvas, type, proxy); } }; - -// DEPRECATIONS - -/** - * Provided for backward compatibility, use EventTarget.addEventListener instead. - * EventTarget.addEventListener compatibility: Chrome, Opera 7, Safari, FF1.5+, IE9+ - * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener - * @function Chart.helpers.addEvent - * @deprecated since version 2.7.0 - * @todo remove at version 3 - * @private - */ -helpers.addEvent = addListener; - -/** - * Provided for backward compatibility, use EventTarget.removeEventListener instead. - * EventTarget.removeEventListener compatibility: Chrome, Opera 7, Safari, FF1.5+, IE9+ - * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener - * @function Chart.helpers.removeEvent - * @deprecated since version 2.7.0 - * @todo remove at version 3 - * @private - */ -helpers.removeEvent = removeListener; diff --git a/test/specs/core.helpers.tests.js b/test/specs/core.helpers.tests.js index e6ade2bd7..39f405d32 100644 --- a/test/specs/core.helpers.tests.js +++ b/test/specs/core.helpers.tests.js @@ -378,17 +378,6 @@ describe('Core helper tests', function() { }]); }); - it('count look at all the labels and return maximum number of lines', function() { - window.createMockContext(); - var arrayOfThings1 = ['Foo', 'Bar']; - var arrayOfThings2 = [['Foo', 'Bar'], 'Foo']; - var arrayOfThings3 = [['Foo', 'Bar', 'Boo'], ['Foo', 'Bar'], 'Foo']; - - expect(helpers.numberOfLabelLines(arrayOfThings1)).toEqual(1); - expect(helpers.numberOfLabelLines(arrayOfThings2)).toEqual(2); - expect(helpers.numberOfLabelLines(arrayOfThings3)).toEqual(3); - }); - it ('should get the maximum width and height for a node', function() { // Create div with fixed size as a test bed var div = document.createElement('div'); diff --git a/test/specs/global.deprecations.tests.js b/test/specs/global.deprecations.tests.js deleted file mode 100644 index b5509a3e2..000000000 --- a/test/specs/global.deprecations.tests.js +++ /dev/null @@ -1,469 +0,0 @@ -describe('Deprecations', function() { - describe('Version 2.9.0', function() { - describe('Chart.Scale.mergeTicksOptions', function() { - it('should be defined as a function', function() { - expect(typeof Chart.Scale.prototype.mergeTicksOptions).toBe('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(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('Chart.Chart', function() { - it('should be defined as an alias to Chart', function() { - expect(Chart.Chart).toBe(Chart); - }); - }); - - describe('Chart.helpers.aliasPixel', function() { - it('should be defined as a function', function() { - expect(typeof Chart.helpers.aliasPixel).toBe('function'); - }); - }); - - describe('Chart.LinearScaleBase', function() { - it('should be defined and inherit from Chart.Scale', function() { - expect(typeof Chart.LinearScaleBase).toBe('function'); - expect(Chart.LinearScaleBase.prototype instanceof Chart.Scale).toBeTruthy(); - }); - }); - - describe('Chart.types', function() { - it('should be defined as an empty object', function() { - expect(Chart.types).toEqual({}); - }); - }); - - describe('Chart.helpers.configMerge', function() { - it('should be defined as a function', function() { - expect(typeof Chart.helpers.configMerge).toBe('function'); - }); - }); - - describe('Chart.helpers.scaleMerge', function() { - it('should be defined as a function', function() { - expect(typeof Chart.helpers.scaleMerge).toBe('function'); - }); - }); - }); - - 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(); - expect(Chart.layoutService).toBe(Chart.layouts); - }); - }); - }); - - describe('Version 2.7.0', function() { - describe('Chart.Controller.update(duration, lazy)', function() { - it('should add an animation with the provided options', function() { - var chart = acquireChart({ - type: 'doughnut', - options: { - animation: { - easing: 'linear', - duration: 500 - } - } - }); - - spyOn(Chart.animationService, 'addAnimation'); - - chart.update(800, false); - - expect(Chart.animationService.addAnimation).toHaveBeenCalledWith( - chart, - jasmine.objectContaining({easing: 'linear'}), - 800, - false - ); - }); - }); - - describe('Chart.Controller.render(duration, lazy)', function() { - it('should add an animation with the provided options', function() { - var chart = acquireChart({ - type: 'doughnut', - options: { - animation: { - easing: 'linear', - duration: 500 - } - } - }); - - spyOn(Chart.animationService, 'addAnimation'); - - chart.render(800, true); - - expect(Chart.animationService.addAnimation).toHaveBeenCalledWith( - chart, - jasmine.objectContaining({easing: 'linear'}), - 800, - true - ); - }); - }); - - describe('Chart.helpers.indexOf', function() { - it('should be defined and a function', function() { - expect(typeof Chart.helpers.indexOf).toBe('function'); - }); - it('should returns the correct index', function() { - expect(Chart.helpers.indexOf([1, 2, 42], 42)).toBe(2); - expect(Chart.helpers.indexOf([1, 2, 42], 3)).toBe(-1); - expect(Chart.helpers.indexOf([1, 42, 2, 42], 42, 2)).toBe(3); - expect(Chart.helpers.indexOf([1, 42, 2, 42], 3, 2)).toBe(-1); - }); - }); - - describe('Chart.helpers.clear', function() { - it('should be defined and an alias of Chart.helpers.canvas.clear', function() { - expect(Chart.helpers.clear).toBeDefined(); - expect(Chart.helpers.clear).toBe(Chart.helpers.canvas.clear); - }); - }); - - describe('Chart.helpers.getValueOrDefault', function() { - it('should be defined and an alias of Chart.helpers.valueOrDefault', function() { - expect(Chart.helpers.getValueOrDefault).toBeDefined(); - expect(Chart.helpers.getValueOrDefault).toBe(Chart.helpers.valueOrDefault); - }); - }); - - describe('Chart.helpers.getValueAtIndexOrDefault', function() { - it('should be defined and an alias of Chart.helpers.valueAtIndexOrDefault', function() { - expect(Chart.helpers.getValueAtIndexOrDefault).toBeDefined(); - expect(Chart.helpers.getValueAtIndexOrDefault).toBe(Chart.helpers.valueAtIndexOrDefault); - }); - }); - - describe('Chart.helpers.easingEffects', function() { - it('should be defined and an alias of Chart.helpers.easing.effects', function() { - expect(Chart.helpers.easingEffects).toBeDefined(); - expect(Chart.helpers.easingEffects).toBe(Chart.helpers.easing.effects); - }); - }); - - describe('Chart.helpers.drawRoundedRectangle', function() { - it('should be defined and a function', function() { - expect(typeof Chart.helpers.drawRoundedRectangle).toBe('function'); - }); - it('should call Chart.helpers.canvas.roundedRect', function() { - var ctx = window.createMockContext(); - spyOn(Chart.helpers.canvas, 'roundedRect'); - - Chart.helpers.drawRoundedRectangle(ctx, 10, 20, 30, 40, 5); - - var calls = ctx.getCalls(); - expect(calls[0]).toEqual({name: 'beginPath', args: []}); - expect(Chart.helpers.canvas.roundedRect).toHaveBeenCalledWith(ctx, 10, 20, 30, 40, 5); - }); - }); - - describe('Chart.helpers.addEvent', function() { - it('should be defined and a function', function() { - expect(typeof Chart.helpers.addEvent).toBe('function'); - }); - it('should correctly add event listener', function() { - var listener = jasmine.createSpy('spy'); - Chart.helpers.addEvent(window, 'test', listener); - window.dispatchEvent(new Event('test')); - expect(listener).toHaveBeenCalled(); - }); - }); - - describe('Chart.helpers.removeEvent', function() { - it('should be defined and a function', function() { - expect(typeof Chart.helpers.removeEvent).toBe('function'); - }); - it('should correctly remove event listener', function() { - var listener = jasmine.createSpy('spy'); - Chart.helpers.addEvent(window, 'test', listener); - Chart.helpers.removeEvent(window, 'test', listener); - window.dispatchEvent(new Event('test')); - expect(listener).not.toHaveBeenCalled(); - }); - }); - }); - - describe('Version 2.6.0', function() { - // https://github.com/chartjs/Chart.js/issues/2481 - describe('Chart.Controller', function() { - it('should be defined and an alias of Chart', function() { - expect(Chart.Controller).toBeDefined(); - expect(Chart.Controller).toBe(Chart); - }); - it('should be prototype of chart instances', function() { - var chart = acquireChart({}); - expect(chart.constructor).toBe(Chart.Controller); - expect(chart instanceof Chart.Controller).toBeTruthy(); - expect(Chart.Controller.prototype.isPrototypeOf(chart)).toBeTruthy(); - }); - }); - - describe('chart.chart', function() { - it('should be defined and an alias of chart', function() { - var chart = acquireChart({}); - var proxy = chart.chart; - expect(proxy).toBeDefined(); - expect(proxy).toBe(chart); - }); - it('should defined previously existing properties', function() { - var chart = acquireChart({}, { - canvas: { - style: 'width: 140px; height: 320px' - } - }); - - var proxy = chart.chart; - expect(proxy.config instanceof Object).toBeTruthy(); - expect(proxy.controller instanceof Chart.Controller).toBeTruthy(); - expect(proxy.canvas instanceof HTMLCanvasElement).toBeTruthy(); - expect(proxy.ctx instanceof CanvasRenderingContext2D).toBeTruthy(); - expect(proxy.currentDevicePixelRatio).toBe(window.devicePixelRatio || 1); - expect(proxy.aspectRatio).toBe(140 / 320); - expect(proxy.height).toBe(320); - expect(proxy.width).toBe(140); - }); - }); - - describe('Chart.Animation.animationObject', function() { - it('should be defined and an alias of Chart.Animation', function(done) { - var animation = null; - - acquireChart({ - options: { - animation: { - duration: 50, - onComplete: function(arg) { - animation = arg; - } - } - } - }); - - setTimeout(function() { - expect(animation).not.toBeNull(); - expect(animation.animationObject).toBeDefined(); - expect(animation.animationObject).toBe(animation); - done(); - }, 200); - }); - }); - - describe('Chart.Animation.chartInstance', function() { - it('should be defined and an alias of Chart.Animation.chart', function(done) { - var animation = null; - var chart = acquireChart({ - options: { - animation: { - duration: 50, - onComplete: function(arg) { - animation = arg; - } - } - } - }); - - setTimeout(function() { - expect(animation).not.toBeNull(); - expect(animation.chartInstance).toBeDefined(); - expect(animation.chartInstance).toBe(chart); - done(); - }, 200); - }); - }); - - describe('Chart.elements.Line: fill option', function() { - it('should decode "zero", "top" and "bottom" as "origin", "start" and "end"', function() { - var chart = window.acquireChart({ - type: 'line', - data: { - datasets: [ - {fill: 'zero'}, - {fill: 'bottom'}, - {fill: 'top'}, - ] - } - }); - - ['origin', 'start', 'end'].forEach(function(expected, index) { - var meta = chart.getDatasetMeta(index); - expect(meta.$filler).toBeDefined(); - expect(meta.$filler.fill).toBe(expected); - }); - }); - }); - - describe('Chart.helpers.callCallback', function() { - it('should be defined and an alias of Chart.helpers.callback', function() { - expect(Chart.helpers.callCallback).toBeDefined(); - expect(Chart.helpers.callCallback).toBe(Chart.helpers.callback); - }); - }); - - describe('Time Axis: unitStepSize option', function() { - it('should use the stepSize property', function() { - var chart = window.acquireChart({ - type: 'line', - data: { - labels: ['2015-01-01T20:00:00', '2015-01-01T21:00:00'], - }, - options: { - scales: { - xAxes: [{ - id: 'time', - type: 'time', - bounds: 'ticks', - time: { - unit: 'hour', - unitStepSize: 2 - } - }] - } - } - }); - - var ticks = chart.scales.time.getTicks().map(function(tick) { - return tick.label; - }); - - expect(ticks).toEqual(['8PM', '10PM']); - }); - }); - }); - - describe('Version 2.5.0', function() { - describe('Chart.PluginBase', function() { - it('should exist and extendable', function() { - expect(Chart.PluginBase).toBeDefined(); - expect(Chart.PluginBase.extend).toBeDefined(); - }); - }); - - describe('IPlugin.afterScaleUpdate', function() { - it('should be called after the chart as been layed out', function() { - var sequence = []; - var plugin = {}; - var hooks = [ - 'beforeLayout', - 'afterScaleUpdate', - 'afterLayout' - ]; - - var override = Chart.layouts.update; - Chart.layouts.update = function() { - sequence.push('layoutUpdate'); - override.apply(this, arguments); - }; - - hooks.forEach(function(name) { - plugin[name] = function() { - sequence.push(name); - }; - }); - - window.acquireChart({plugins: [plugin]}); - expect(sequence).toEqual([].concat( - 'beforeLayout', - 'layoutUpdate', - 'afterScaleUpdate', - 'afterLayout' - )); - }); - }); - }); - - describe('Version 2.4.0', function() { - describe('x-axis mode', function() { - it ('behaves like index mode with intersect: false', function() { - var data = { - datasets: [{ - label: 'Dataset 1', - data: [10, 20, 30], - pointHoverBorderColor: 'rgb(255, 0, 0)', - pointHoverBackgroundColor: 'rgb(0, 255, 0)' - }, { - label: 'Dataset 2', - data: [40, 40, 40], - pointHoverBorderColor: 'rgb(0, 0, 255)', - pointHoverBackgroundColor: 'rgb(0, 255, 255)' - }], - labels: ['Point 1', 'Point 2', 'Point 3'] - }; - - var chart = window.acquireChart({ - type: 'line', - data: data - }); - var meta0 = chart.getDatasetMeta(0); - var meta1 = chart.getDatasetMeta(1); - - var evt = { - type: 'click', - chart: chart, - native: true, // needed otherwise things its a DOM event - x: 0, - y: 0 - }; - - var elements = Chart.Interaction.modes['x-axis'](chart, evt); - expect(elements).toEqual([meta0.data[0], meta1.data[0]]); - }); - }); - }); - - describe('Version 2.1.5', function() { - // https://github.com/chartjs/Chart.js/pull/2752 - describe('Chart.pluginService', function() { - it('should be defined and an alias of Chart.plugins', function() { - expect(Chart.pluginService).toBeDefined(); - expect(Chart.pluginService).toBe(Chart.plugins); - }); - }); - - describe('Chart.Legend', function() { - it('should be defined and an instance of Chart.Element', function() { - var legend = new Chart.Legend({}); - expect(Chart.Legend).toBeDefined(); - expect(legend).not.toBe(undefined); - expect(legend instanceof Chart.Element).toBeTruthy(); - }); - }); - - describe('Chart.Title', function() { - it('should be defined and an instance of Chart.Element', function() { - var title = new Chart.Title({}); - expect(Chart.Title).toBeDefined(); - expect(title).not.toBe(undefined); - expect(title instanceof Chart.Element).toBeTruthy(); - }); - }); - }); -}); -- 2.47.2