From 72524239ca4ca4f15314bd426ee1ad10b3c17220 Mon Sep 17 00:00:00 2001 From: stockiNail Date: Wed, 8 Mar 2023 19:13:40 +0100 Subject: [PATCH 1/2] Border is counted as part of ArcElement --- src/elements/element.arc.ts | 2 +- test/specs/element.arc.tests.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/elements/element.arc.ts b/src/elements/element.arc.ts index dff28b62a47..00d9ace8c26 100644 --- a/src/elements/element.arc.ts +++ b/src/elements/element.arc.ts @@ -322,7 +322,7 @@ export default class ArcElement extends Element { 'outerRadius', 'circumference' ], useFinalPosition); - const rAdjust = this.options.spacing / 2; + const rAdjust = this.options.spacing / 2 + this.options.borderWidth / 2; const _circumference = valueOrDefault(circumference, endAngle - startAngle); const betweenAngles = _circumference >= TAU || _angleBetween(angle, startAngle, endAngle); const withinRadius = _isBetween(distance, innerRadius + rAdjust, outerRadius + rAdjust); diff --git a/test/specs/element.arc.tests.js b/test/specs/element.arc.tests.js index fdfddab9315..e8ba72f3a0a 100644 --- a/test/specs/element.arc.tests.js +++ b/test/specs/element.arc.tests.js @@ -13,6 +13,7 @@ describe('Arc element tests', function() { options: { spacing: 0, offset: 0, + borderWidth: 0 } }); @@ -35,6 +36,7 @@ describe('Arc element tests', function() { options: { spacing: 0, offset: 0, + borderWidth: 0 } }); @@ -68,6 +70,27 @@ describe('Arc element tests', function() { options: { spacing: 10, offset: 0, + borderWidth: 0 + } + }); + + expect(arc.inRange(7, 0)).toBe(false); + expect(arc.inRange(15, 0)).toBe(true); + }); + + it ('should include borderWidth for in range check', function() { + // Mock out the arc as if the controller put it there + var arc = new Chart.elements.ArcElement({ + startAngle: 0, + endAngle: Math.PI / 2, + x: 0, + y: 0, + innerRadius: 5, + outerRadius: 10, + options: { + spacing: 0, + offset: 0, + borderWidth: 10 } }); @@ -88,6 +111,7 @@ describe('Arc element tests', function() { options: { spacing: 0, offset: 0, + borderWidth: 0 } }); @@ -106,6 +130,7 @@ describe('Arc element tests', function() { options: { spacing: 0, offset: 0, + borderWidth: 0 } }); @@ -126,6 +151,7 @@ describe('Arc element tests', function() { options: { spacing: 0, offset: 0, + borderWidth: 0 } }); @@ -146,6 +172,7 @@ describe('Arc element tests', function() { options: { spacing: 10, offset: 10, + borderWidth: 0 } }); @@ -166,6 +193,7 @@ describe('Arc element tests', function() { options: { spacing: 0, offset: 0, + borderWidth: 0 } }); @@ -194,6 +222,7 @@ describe('Arc element tests', function() { options: { spacing: 0, offset: 0, + borderWidth: 0 } }); @@ -211,6 +240,7 @@ describe('Arc element tests', function() { options: { spacing: 0, offset: 0, + borderWidth: 0 } }); @@ -230,6 +260,7 @@ describe('Arc element tests', function() { options: { spacing: 0, offset: 0, + borderWidth: 0, scales: { r: { grid: { From b4443d7e66e32bd9b6a088dacdf46b4a92219928 Mon Sep 17 00:00:00 2001 From: stockiNail Date: Wed, 8 Mar 2023 19:20:01 +0100 Subject: [PATCH 2/2] improve calculation --- src/elements/element.arc.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/elements/element.arc.ts b/src/elements/element.arc.ts index 00d9ace8c26..1595016c9b0 100644 --- a/src/elements/element.arc.ts +++ b/src/elements/element.arc.ts @@ -322,7 +322,7 @@ export default class ArcElement extends Element { 'outerRadius', 'circumference' ], useFinalPosition); - const rAdjust = this.options.spacing / 2 + this.options.borderWidth / 2; + const rAdjust = (this.options.spacing + this.options.borderWidth) / 2; const _circumference = valueOrDefault(circumference, endAngle - startAngle); const betweenAngles = _circumference >= TAU || _angleBetween(angle, startAngle, endAngle); const withinRadius = _isBetween(distance, innerRadius + rAdjust, outerRadius + rAdjust);