From ff2b6f9e62f0c90b91fd36f545f7ce5d80d8f686 Mon Sep 17 00:00:00 2001 From: "Hu, Vince" Date: Sun, 14 Jul 2024 01:50:34 +0800 Subject: [PATCH 1/2] exclude 0 angle from inRange to not showing tooltip when all data are hidden Signed-off-by: Hu, Vince --- 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 1595016c9b0..6ed4080e3d6 100644 --- a/src/elements/element.arc.ts +++ b/src/elements/element.arc.ts @@ -324,7 +324,7 @@ export default class ArcElement extends Element { ], useFinalPosition); const rAdjust = (this.options.spacing + this.options.borderWidth) / 2; const _circumference = valueOrDefault(circumference, endAngle - startAngle); - const betweenAngles = _circumference >= TAU || _angleBetween(angle, startAngle, endAngle); + const betweenAngles = _circumference >= TAU || (_angleBetween(angle, startAngle, endAngle) && startAngle !== endAngle);; const withinRadius = _isBetween(distance, innerRadius + rAdjust, outerRadius + rAdjust); return (betweenAngles && withinRadius); From 78caabe0b2ee453844c3debdfe883a870adfec55 Mon Sep 17 00:00:00 2001 From: "Hu, Vince" Date: Wed, 31 Jul 2024 15:23:13 +0800 Subject: [PATCH 2/2] test 0 angle point not in arc range --- src/elements/element.arc.ts | 3 ++- test/specs/element.arc.tests.js | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/elements/element.arc.ts b/src/elements/element.arc.ts index 6ed4080e3d6..e2bd26f523b 100644 --- a/src/elements/element.arc.ts +++ b/src/elements/element.arc.ts @@ -324,7 +324,8 @@ export default class ArcElement extends Element { ], useFinalPosition); const rAdjust = (this.options.spacing + this.options.borderWidth) / 2; const _circumference = valueOrDefault(circumference, endAngle - startAngle); - const betweenAngles = _circumference >= TAU || (_angleBetween(angle, startAngle, endAngle) && startAngle !== endAngle);; + const nonZeroBetween = _angleBetween(angle, startAngle, endAngle) && startAngle !== endAngle; + const betweenAngles = _circumference >= TAU || nonZeroBetween; const withinRadius = _isBetween(distance, innerRadius + rAdjust, outerRadius + rAdjust); return (betweenAngles && withinRadius); diff --git a/test/specs/element.arc.tests.js b/test/specs/element.arc.tests.js index e8ba72f3a0a..63d20caaec4 100644 --- a/test/specs/element.arc.tests.js +++ b/test/specs/element.arc.tests.js @@ -281,4 +281,26 @@ describe('Arc element tests', function() { expect(ctx.getCalls().length).toBeGreaterThan(0); }); + + it ('should determine not in range when angle 0', function() { + // Mock out the arc as if the controller put it there + var arc = new Chart.elements.ArcElement({ + startAngle: 0, + endAngle: 0, + x: 0, + y: 0, + innerRadius: 0, + outerRadius: 10, + circumference: 0, + options: { + spacing: 0, + offset: 0, + borderWidth: 0 + } + }); + + var center = arc.getCenterPoint(); + + expect(arc.inRange(center.x, 1)).toBe(false); + }); });