]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Bugfix/issue 11804 tooltip show for all invisible (#11858)
authorhuqingkun <huqingkun@gmail.com>
Mon, 12 Aug 2024 15:56:35 +0000 (23:56 +0800)
committerGitHub <noreply@github.com>
Mon, 12 Aug 2024 15:56:35 +0000 (11:56 -0400)
* exclude 0 angle from inRange to not showing tooltip when all data are hidden

Signed-off-by: Hu, Vince <Qingkun.Hu@fmr.com>
* test 0 angle point not in arc range

---------

Signed-off-by: Hu, Vince <Qingkun.Hu@fmr.com>
src/elements/element.arc.ts
test/specs/element.arc.tests.js

index 1595016c9b04674a672b1ec1531c91af39c841d7..e2bd26f523b713730ded97a3f8f11dd5d7d0f662 100644 (file)
@@ -324,7 +324,8 @@ export default class ArcElement extends Element<ArcProps, ArcOptions> {
     ], 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 nonZeroBetween = _angleBetween(angle, startAngle, endAngle) && startAngle !== endAngle;
+    const betweenAngles = _circumference >= TAU || nonZeroBetween;
     const withinRadius = _isBetween(distance, innerRadius + rAdjust, outerRadius + rAdjust);
 
     return (betweenAngles && withinRadius);
index e8ba72f3a0a7ba775cf1474930420e0b52630e6e..63d20caaec4819de51a1f51daa51dfe782dfda23 100644 (file)
@@ -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);
+  });
 });