Skip to content

Commit 5204ba8

Browse files
committed
Fix inRange for full circle
1 parent 4168e07 commit 5204ba8

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/elements/element.arc.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,17 @@ class Arc extends Element {
9292
constructor(cfg) {
9393
super();
9494

95+
/** @type object */
9596
this.options = undefined;
97+
/** @type number */
9698
this.circumference = undefined;
99+
/** @type number */
97100
this.startAngle = undefined;
101+
/** @type number */
98102
this.endAngle = undefined;
103+
/** @type number */
99104
this.innerRadius = undefined;
105+
/** @type number */
100106
this.outerRadius = undefined;
101107

102108
if (cfg) {
@@ -112,13 +118,14 @@ class Arc extends Element {
112118
inRange(chartX, chartY, useFinalPosition) {
113119
const point = this.getProps(['x', 'y'], useFinalPosition);
114120
const {angle, distance} = getAngleFromPoint(point, {x: chartX, y: chartY});
115-
const {startAngle, endAngle, innerRadius, outerRadius} = this.getProps([
121+
const {startAngle, endAngle, innerRadius, outerRadius, circumference} = this.getProps([
116122
'startAngle',
117123
'endAngle',
118124
'innerRadius',
119-
'outerRadius'
125+
'outerRadius',
126+
'circumference'
120127
], useFinalPosition);
121-
const betweenAngles = _angleBetween(angle, startAngle, endAngle);
128+
const betweenAngles = circumference >= TAU || _angleBetween(angle, startAngle, endAngle);
122129
const withinRadius = (distance >= innerRadius && distance <= outerRadius);
123130

124131
return (betweenAngles && withinRadius);

test/specs/element.arc.tests.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ describe('Arc element tests', function() {
1919
expect(arc.inRange(-1.0 * Math.sqrt(7), Math.sqrt(7))).toBe(false);
2020
});
2121

22+
it ('should determine if in range, when full circle', function() {
23+
// Mock out the arc as if the controller put it there
24+
var arc = new Chart.elements.Arc({
25+
startAngle: -Math.PI,
26+
endAngle: Math.PI * 1.5,
27+
x: 0,
28+
y: 0,
29+
innerRadius: 0,
30+
outerRadius: 10,
31+
circumference: Math.PI * 2
32+
});
33+
34+
expect(arc.inRange(7, 7)).toBe(true);
35+
});
36+
2237
it ('should get the tooltip position', function() {
2338
// Mock out the arc as if the controller put it there
2439
var arc = new Chart.elements.Arc({

0 commit comments

Comments
 (0)