From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Fri, 15 Nov 2019 12:49:41 +0000 (-0800) Subject: Remove unused helpers.canvas.roundedRect (#6734) X-Git-Tag: v3.0.0-alpha~238 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c12ca17e38f77bd605d0be894f8ddb4bd610fa52;p=thirdparty%2FChart.js.git Remove unused helpers.canvas.roundedRect (#6734) --- diff --git a/docs/getting-started/v3-migration.md b/docs/getting-started/v3-migration.md index 4d8f0f779..a797db8e2 100644 --- a/docs/getting-started/v3-migration.md +++ b/docs/getting-started/v3-migration.md @@ -56,6 +56,7 @@ Chart.js is no longer providing the `Chart.bundle.js` and `Chart.bundle.min.js`. * `helpers.numberOfLabelLines` * `helpers.previousItem` * `helpers.removeEvent` +* `helpers.roundedRect` * `helpers.scaleMerge` * `Scale.getRightValue` * `Scale.mergeTicksOptions` diff --git a/src/helpers/helpers.canvas.js b/src/helpers/helpers.canvas.js index 2a3b4cba0..a34160d5b 100644 --- a/src/helpers/helpers.canvas.js +++ b/src/helpers/helpers.canvas.js @@ -33,48 +33,6 @@ module.exports = { chart.ctx.clearRect(0, 0, chart.width, chart.height); }, - /** - * Creates a "path" for a rectangle with rounded corners at position (x, y) with a - * given size (width, height) and the same `radius` for all corners. - * @param {CanvasRenderingContext2D} ctx - The canvas 2D Context. - * @param {number} x - The x axis of the coordinate for the rectangle starting point. - * @param {number} y - The y axis of the coordinate for the rectangle starting point. - * @param {number} width - The rectangle's width. - * @param {number} height - The rectangle's height. - * @param {number} radius - The rounded amount (in pixels) for the four corners. - * @todo handle `radius` as top-left, top-right, bottom-right, bottom-left array/object? - */ - roundedRect: function(ctx, x, y, width, height, radius) { - if (radius) { - var r = Math.min(radius, height / 2, width / 2); - var left = x + r; - var top = y + r; - var right = x + width - r; - var bottom = y + height - r; - - ctx.moveTo(x, top); - if (left < right && top < bottom) { - ctx.arc(left, top, r, -PI, -HALF_PI); - ctx.arc(right, top, r, -HALF_PI, 0); - ctx.arc(right, bottom, r, 0, HALF_PI); - ctx.arc(left, bottom, r, HALF_PI, PI); - } else if (left < right) { - ctx.moveTo(left, y); - ctx.arc(right, top, r, -HALF_PI, HALF_PI); - ctx.arc(left, top, r, HALF_PI, PI + HALF_PI); - } else if (top < bottom) { - ctx.arc(left, top, r, -PI, 0); - ctx.arc(left, bottom, r, 0, PI); - } else { - ctx.arc(left, top, r, -PI, PI); - } - ctx.closePath(); - ctx.moveTo(x, y); - } else { - ctx.rect(x, y, width, height); - } - }, - drawPoint: function(ctx, style, radius, x, y, rotation) { var type, xOffset, yOffset, size, cornerRadius; var rad = (rotation || 0) * RAD_PER_DEG; diff --git a/test/fixtures/helpers.canvas/rounded-rect.js b/test/fixtures/helpers.canvas/rounded-rect.js deleted file mode 100644 index cbdedacc3..000000000 --- a/test/fixtures/helpers.canvas/rounded-rect.js +++ /dev/null @@ -1,39 +0,0 @@ -var roundedRect = Chart.helpers.canvas.roundedRect; - -module.exports = { - config: { - type: 'line', - plugins: [{ - afterDraw: function(chart) { - var ctx = chart.ctx; - ctx.strokeStyle = '#0000ff'; - ctx.lineWidth = 4; - ctx.fillStyle = '#00ff00'; - ctx.beginPath(); - roundedRect(ctx, 10, 10, 50, 50, 25); - roundedRect(ctx, 70, 10, 100, 50, 25); - roundedRect(ctx, 10, 70, 50, 100, 25); - roundedRect(ctx, 70, 70, 100, 100, 25); - roundedRect(ctx, 180, 10, 50, 50, 100); - roundedRect(ctx, 240, 10, 100, 50, 100); - roundedRect(ctx, 180, 70, 50, 100, 100); - roundedRect(ctx, 240, 70, 100, 100, 100); - roundedRect(ctx, 350, 10, 50, 50, 0); - ctx.fill(); - ctx.stroke(); - } - }], - options: { - scales: { - xAxes: [{display: false}], - yAxes: [{display: false}] - } - } - }, - options: { - canvas: { - height: 256, - width: 512 - } - } -}; diff --git a/test/fixtures/helpers.canvas/rounded-rect.png b/test/fixtures/helpers.canvas/rounded-rect.png deleted file mode 100644 index 8973c9d30..000000000 Binary files a/test/fixtures/helpers.canvas/rounded-rect.png and /dev/null differ diff --git a/test/specs/helpers.canvas.tests.js b/test/specs/helpers.canvas.tests.js index 9654ef28e..3a5fbb836 100644 --- a/test/specs/helpers.canvas.tests.js +++ b/test/specs/helpers.canvas.tests.js @@ -23,70 +23,6 @@ describe('Chart.helpers.canvas', function() { }); }); - describe('roundedRect', function() { - it('should create a rounded rectangle path', function() { - var context = window.createMockContext(); - - helpers.canvas.roundedRect(context, 10, 20, 30, 40, 5); - - expect(context.getCalls()).toEqual([ - {name: 'moveTo', args: [10, 25]}, - {name: 'arc', args: [15, 25, 5, -Math.PI, -Math.PI / 2]}, - {name: 'arc', args: [35, 25, 5, -Math.PI / 2, 0]}, - {name: 'arc', args: [35, 55, 5, 0, Math.PI / 2]}, - {name: 'arc', args: [15, 55, 5, Math.PI / 2, Math.PI]}, - {name: 'closePath', args: []}, - {name: 'moveTo', args: [10, 20]} - ]); - }); - it('should optimize path if radius is exactly half of height', function() { - var context = window.createMockContext(); - - helpers.canvas.roundedRect(context, 10, 20, 40, 30, 15); - - expect(context.getCalls()).toEqual([ - {name: 'moveTo', args: [10, 35]}, - {name: 'moveTo', args: [25, 20]}, - {name: 'arc', args: [35, 35, 15, -Math.PI / 2, Math.PI / 2]}, - {name: 'arc', args: [25, 35, 15, Math.PI / 2, Math.PI * 3 / 2]}, - {name: 'closePath', args: []}, - {name: 'moveTo', args: [10, 20]} - ]); - }); - it('should optimize path if radius is exactly half of width', function() { - var context = window.createMockContext(); - - helpers.canvas.roundedRect(context, 10, 20, 30, 40, 15); - - expect(context.getCalls()).toEqual([ - {name: 'moveTo', args: [10, 35]}, - {name: 'arc', args: [25, 35, 15, -Math.PI, 0]}, - {name: 'arc', args: [25, 45, 15, 0, Math.PI]}, - {name: 'closePath', args: []}, - {name: 'moveTo', args: [10, 20]} - ]); - }); - it('should optimize path if radius is exactly half of width and height', function() { - var context = window.createMockContext(); - - helpers.canvas.roundedRect(context, 10, 20, 30, 30, 15); - - expect(context.getCalls()).toEqual([ - {name: 'moveTo', args: [10, 35]}, - {name: 'arc', args: [25, 35, 15, -Math.PI, Math.PI]}, - {name: 'closePath', args: []}, - {name: 'moveTo', args: [10, 20]} - ]); - }); - it('should optimize path if radius is 0', function() { - var context = window.createMockContext(); - - helpers.canvas.roundedRect(context, 10, 20, 30, 40, 0); - - expect(context.getCalls()).toEqual([{name: 'rect', args: [10, 20, 30, 40]}]); - }); - }); - describe('isPointInArea', function() { it('should determine if a point is in the area', function() { var isPointInArea = helpers.canvas._isPointInArea;