]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
More robust in-between arc calculation see #1301
authorJan Nicklas <j.nicklas@sinnerschrader.com>
Fri, 10 Jul 2015 09:47:48 +0000 (11:47 +0200)
committerJan Nicklas <j.nicklas@sinnerschrader.com>
Fri, 10 Jul 2015 09:47:48 +0000 (11:47 +0200)
src/Chart.Core.js

index 44db42dfcb9fbbe8c210a6a22fbc1541446995e3..8d610418b8db58861fe1dd0d0f80bbf58f73db89 100755 (executable)
                                y: chartY
                        });
 
+                       // Normalize all angles to 0 - 2*PI (0 - 360°)
+                       var pointRelativeAngle = pointRelativePosition.angle % (Math.PI * 2),
+                       var startAngle = (Math.PI * 2 + this.startAngle) % (Math.PI * 2),
+                       var endAngle = (Math.PI * 2 + this.endAngle) % (Math.PI * 2) || 360;
+
+                       // Calculate wether the pointRelativeAngle is between the start and the end angle
+                       var betweenAngles = (endAngle < startAngle) ?
+                               pointRelativeAngle <= endAngle || pointRelativeAngle >= startAngle:
+                               pointRelativeAngle >= startAngle && pointRelativeAngle <= endAngle;
+
                        //Check if within the range of the open/close angle
-                       var betweenAngles = (pointRelativePosition.angle >= this.startAngle && pointRelativePosition.angle <= this.endAngle),
-                               withinRadius = (pointRelativePosition.distance >= this.innerRadius && pointRelativePosition.distance <= this.outerRadius);
+                       var withinRadius = (pointRelativePosition.distance >= this.innerRadius && pointRelativePosition.distance <= this.outerRadius);
 
                        return (betweenAngles && withinRadius);
                        //Ensure within the outside of the arc centre, but inside arc outer