]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Remove unused helpers.canvas.roundedRect (#6734)
authorBen McCann <322311+benmccann@users.noreply.github.com>
Fri, 15 Nov 2019 12:49:41 +0000 (04:49 -0800)
committerEvert Timberg <evert.timberg+github@gmail.com>
Fri, 15 Nov 2019 12:49:41 +0000 (07:49 -0500)
docs/getting-started/v3-migration.md
src/helpers/helpers.canvas.js
test/fixtures/helpers.canvas/rounded-rect.js [deleted file]
test/fixtures/helpers.canvas/rounded-rect.png [deleted file]
test/specs/helpers.canvas.tests.js

index 4d8f0f77968afff59fdb5400070001436be1d4ae..a797db8e2fcec17b50c2205edfc92e8a8d16fed5 100644 (file)
@@ -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`
index 2a3b4cba0c6874b84f5a2c51dac2aa7d54d9d4e7..a34160d5ba7f6987973b7dc809a0ba64ce96c646 100644 (file)
@@ -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 (file)
index cbdedac..0000000
+++ /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 (file)
index 8973c9d..0000000
Binary files a/test/fixtures/helpers.canvas/rounded-rect.png and /dev/null differ
index 9654ef28e7b40b34f8dd553e5258a7639be14752..3a5fbb836638a55c88d48e3675a1fc83b326d20b 100644 (file)
@@ -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;