From 7a2160461df1541993f1ba2936d87d5292dd14be Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Tue, 5 Nov 2019 15:09:44 -0800 Subject: [PATCH] Remove unused Element methods (#6694) --- docs/getting-started/v3-migration.md | 9 ++-- src/elements/element.arc.js | 14 ----- src/elements/element.point.js | 5 -- src/elements/element.rectangle.js | 20 -------- test/specs/element.arc.tests.js | 23 --------- test/specs/element.point.tests.js | 22 -------- test/specs/element.rectangle.tests.js | 74 --------------------------- 7 files changed, 6 insertions(+), 161 deletions(-) diff --git a/docs/getting-started/v3-migration.md b/docs/getting-started/v3-migration.md index 04dfa426e..41d1bfd20 100644 --- a/docs/getting-started/v3-migration.md +++ b/docs/getting-started/v3-migration.md @@ -53,13 +53,16 @@ Chart.js is no longer providing the `Chart.bundle.js` and `Chart.bundle.min.js`. * `helpers.numberOfLabelLines` * `helpers.removeEvent` * `helpers.scaleMerge` -* `scale.getRightValue` -* `scale.mergeTicksOptions` -* `scale.ticksAsNumbers` +* `Scale.getRightValue` +* `Scale.mergeTicksOptions` +* `Scale.ticksAsNumbers` * `Chart.Controller` * `Chart.chart.chart` * `Chart.types` * `Line.calculatePointY` +* `Element.getArea` +* `Element.height` +* `Element.inLabelRange` * Made `scale.handleDirectionalChanges` private * Made `scale.tickValues` private diff --git a/src/elements/element.arc.js b/src/elements/element.arc.js index 84b5e6335..d5d9fbf15 100644 --- a/src/elements/element.arc.js +++ b/src/elements/element.arc.js @@ -94,15 +94,6 @@ function drawBorder(ctx, vm, arc) { module.exports = Element.extend({ _type: 'arc', - inLabelRange: function(mouseX) { - var vm = this._view; - - if (vm) { - return (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hoverRadius, 2)); - } - return false; - }, - inRange: function(chartX, chartY) { var vm = this._view; @@ -143,11 +134,6 @@ module.exports = Element.extend({ }; }, - getArea: function() { - var vm = this._view; - return Math.PI * ((vm.endAngle - vm.startAngle) / (2 * Math.PI)) * (Math.pow(vm.outerRadius, 2) - Math.pow(vm.innerRadius, 2)); - }, - tooltipPosition: function() { var vm = this._view; var centreAngle = vm.startAngle + ((vm.endAngle - vm.startAngle) / 2); diff --git a/src/elements/element.point.js b/src/elements/element.point.js index dc020c86a..226ed06c0 100644 --- a/src/elements/element.point.js +++ b/src/elements/element.point.js @@ -42,7 +42,6 @@ module.exports = Element.extend({ return vm ? ((Math.pow(mouseX - vm.x, 2) + Math.pow(mouseY - vm.y, 2)) < Math.pow(vm.hitRadius + vm.radius, 2)) : false; }, - inLabelRange: xRange, inXRange: xRange, inYRange: yRange, @@ -54,10 +53,6 @@ module.exports = Element.extend({ }; }, - getArea: function() { - return Math.PI * Math.pow(this._view.radius, 2); - }, - tooltipPosition: function() { var vm = this._view; return { diff --git a/src/elements/element.rectangle.js b/src/elements/element.rectangle.js index 254d77514..1e08df12c 100644 --- a/src/elements/element.rectangle.js +++ b/src/elements/element.rectangle.js @@ -157,22 +157,10 @@ module.exports = Element.extend({ ctx.restore(); }, - height: function() { - var vm = this._view; - return vm.base - vm.y; - }, - inRange: function(mouseX, mouseY) { return inRange(this._view, mouseX, mouseY); }, - inLabelRange: function(mouseX, mouseY) { - var vm = this._view; - return isVertical(vm) - ? inRange(vm, mouseX, null) - : inRange(vm, null, mouseY); - }, - inXRange: function(mouseX) { return inRange(this._view, mouseX, null); }, @@ -195,14 +183,6 @@ module.exports = Element.extend({ return {x: x, y: y}; }, - getArea: function() { - var vm = this._view; - - return isVertical(vm) - ? vm.width * Math.abs(vm.y - vm.base) - : vm.height * Math.abs(vm.x - vm.base); - }, - tooltipPosition: function() { var vm = this._view; return { diff --git a/test/specs/element.arc.tests.js b/test/specs/element.arc.tests.js index 40d52533d..41c720d9b 100644 --- a/test/specs/element.arc.tests.js +++ b/test/specs/element.arc.tests.js @@ -18,10 +18,6 @@ describe('Arc element tests', function() { _index: 1 }); - // Make sure we can run these before the view is added - expect(arc.inRange(2, 2)).toBe(false); - expect(arc.inLabelRange(2)).toBe(false); - // Mock out the view as if the controller put it there arc._view = { startAngle: 0, @@ -60,25 +56,6 @@ describe('Arc element tests', function() { expect(pos.y).toBeCloseTo(0.5); }); - it ('should get the area', function() { - var arc = new Chart.elements.Arc({ - _datasetIndex: 2, - _index: 1 - }); - - // Mock out the view as if the controller put it there - arc._view = { - startAngle: 0, - endAngle: Math.PI / 2, - x: 0, - y: 0, - innerRadius: 0, - outerRadius: Math.sqrt(2), - }; - - expect(arc.getArea()).toBeCloseTo(0.5 * Math.PI, 6); - }); - it ('should get the center', function() { var arc = new Chart.elements.Arc({ _datasetIndex: 2, diff --git a/test/specs/element.point.tests.js b/test/specs/element.point.tests.js index f6700e347..bc51bedef 100644 --- a/test/specs/element.point.tests.js +++ b/test/specs/element.point.tests.js @@ -20,7 +20,6 @@ describe('Chart.elements.Point', function() { // Safely handles if these are called before the viewmodel is instantiated expect(point.inRange(5)).toBe(false); - expect(point.inLabelRange(5)).toBe(false); // Attach a view object as if we were the controller point._view = { @@ -34,13 +33,6 @@ describe('Chart.elements.Point', function() { expect(point.inRange(10, 10)).toBe(false); expect(point.inRange(10, 5)).toBe(false); expect(point.inRange(5, 5)).toBe(false); - - expect(point.inLabelRange(5)).toBe(false); - expect(point.inLabelRange(7)).toBe(true); - expect(point.inLabelRange(10)).toBe(true); - expect(point.inLabelRange(12)).toBe(true); - expect(point.inLabelRange(15)).toBe(false); - expect(point.inLabelRange(20)).toBe(false); }); it ('should get the correct tooltip position', function() { @@ -64,20 +56,6 @@ describe('Chart.elements.Point', function() { }); }); - it('should get the correct area', function() { - var point = new Chart.elements.Point({ - _datasetIndex: 2, - _index: 1 - }); - - // Attach a view object as if we were the controller - point._view = { - radius: 2, - }; - - expect(point.getArea()).toEqual(Math.PI * 4); - }); - it('should get the correct center point', function() { var point = new Chart.elements.Point({ _datasetIndex: 2, diff --git a/test/specs/element.rectangle.tests.js b/test/specs/element.rectangle.tests.js index d6932359e..686eea932 100644 --- a/test/specs/element.rectangle.tests.js +++ b/test/specs/element.rectangle.tests.js @@ -20,7 +20,6 @@ describe('Rectangle element tests', function() { // Safely handles if these are called before the viewmodel is instantiated expect(rectangle.inRange(5)).toBe(false); - expect(rectangle.inLabelRange(5)).toBe(false); // Attach a view object as if we were the controller rectangle._view = { @@ -35,13 +34,6 @@ describe('Rectangle element tests', function() { expect(rectangle.inRange(10, 16)).toBe(false); expect(rectangle.inRange(5, 5)).toBe(false); - expect(rectangle.inLabelRange(5)).toBe(false); - expect(rectangle.inLabelRange(7)).toBe(false); - expect(rectangle.inLabelRange(10)).toBe(true); - expect(rectangle.inLabelRange(12)).toBe(true); - expect(rectangle.inLabelRange(15)).toBe(false); - expect(rectangle.inLabelRange(20)).toBe(false); - // Test when the y is below the base (negative bar) var negativeRectangle = new Chart.elements.Rectangle({ _datasetIndex: 2, @@ -61,38 +53,6 @@ describe('Rectangle element tests', function() { expect(negativeRectangle.inRange(10, -5)).toBe(true); }); - it('should get the correct height', function() { - var rectangle = new Chart.elements.Rectangle({ - _datasetIndex: 2, - _index: 1 - }); - - // Attach a view object as if we were the controller - rectangle._view = { - base: 0, - width: 4, - x: 10, - y: 15 - }; - - expect(rectangle.height()).toBe(-15); - - // Test when the y is below the base (negative bar) - var negativeRectangle = new Chart.elements.Rectangle({ - _datasetIndex: 2, - _index: 1 - }); - - // Attach a view object as if we were the controller - negativeRectangle._view = { - base: -10, - width: 4, - x: 10, - y: -15 - }; - expect(negativeRectangle.height()).toBe(5); - }); - it('should get the correct tooltip position', function() { var rectangle = new Chart.elements.Rectangle({ _datasetIndex: 2, @@ -132,40 +92,6 @@ describe('Rectangle element tests', function() { }); }); - it('should get the correct vertical area', function() { - var rectangle = new Chart.elements.Rectangle({ - _datasetIndex: 2, - _index: 1 - }); - - // Attach a view object as if we were the controller - rectangle._view = { - base: 0, - width: 4, - x: 10, - y: 15 - }; - - expect(rectangle.getArea()).toEqual(60); - }); - - it('should get the correct horizontal area', function() { - var rectangle = new Chart.elements.Rectangle({ - _datasetIndex: 2, - _index: 1 - }); - - // Attach a view object as if we were the controller - rectangle._view = { - base: 0, - height: 4, - x: 10, - y: 15 - }; - - expect(rectangle.getArea()).toEqual(40); - }); - it('should get the center', function() { var rectangle = new Chart.elements.Rectangle({ _datasetIndex: 2, -- 2.47.2