Skip to content

Commit 5ee0ff1

Browse files
authored
Border is counted as part of ArcElement (#11180)
* Border is counted as part of ArcElement * improve calculation
1 parent b16f32a commit 5ee0ff1

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/elements/element.arc.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ export default class ArcElement extends Element<ArcProps, ArcOptions> {
322322
'outerRadius',
323323
'circumference'
324324
], useFinalPosition);
325-
const rAdjust = this.options.spacing / 2;
325+
const rAdjust = (this.options.spacing + this.options.borderWidth) / 2;
326326
const _circumference = valueOrDefault(circumference, endAngle - startAngle);
327327
const betweenAngles = _circumference >= TAU || _angleBetween(angle, startAngle, endAngle);
328328
const withinRadius = _isBetween(distance, innerRadius + rAdjust, outerRadius + rAdjust);

test/specs/element.arc.tests.js

+31
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe('Arc element tests', function() {
1313
options: {
1414
spacing: 0,
1515
offset: 0,
16+
borderWidth: 0
1617
}
1718
});
1819

@@ -35,6 +36,7 @@ describe('Arc element tests', function() {
3536
options: {
3637
spacing: 0,
3738
offset: 0,
39+
borderWidth: 0
3840
}
3941
});
4042

@@ -68,6 +70,27 @@ describe('Arc element tests', function() {
6870
options: {
6971
spacing: 10,
7072
offset: 0,
73+
borderWidth: 0
74+
}
75+
});
76+
77+
expect(arc.inRange(7, 0)).toBe(false);
78+
expect(arc.inRange(15, 0)).toBe(true);
79+
});
80+
81+
it ('should include borderWidth for in range check', function() {
82+
// Mock out the arc as if the controller put it there
83+
var arc = new Chart.elements.ArcElement({
84+
startAngle: 0,
85+
endAngle: Math.PI / 2,
86+
x: 0,
87+
y: 0,
88+
innerRadius: 5,
89+
outerRadius: 10,
90+
options: {
91+
spacing: 0,
92+
offset: 0,
93+
borderWidth: 10
7194
}
7295
});
7396

@@ -88,6 +111,7 @@ describe('Arc element tests', function() {
88111
options: {
89112
spacing: 0,
90113
offset: 0,
114+
borderWidth: 0
91115
}
92116
});
93117

@@ -106,6 +130,7 @@ describe('Arc element tests', function() {
106130
options: {
107131
spacing: 0,
108132
offset: 0,
133+
borderWidth: 0
109134
}
110135
});
111136

@@ -126,6 +151,7 @@ describe('Arc element tests', function() {
126151
options: {
127152
spacing: 0,
128153
offset: 0,
154+
borderWidth: 0
129155
}
130156
});
131157

@@ -146,6 +172,7 @@ describe('Arc element tests', function() {
146172
options: {
147173
spacing: 10,
148174
offset: 10,
175+
borderWidth: 0
149176
}
150177
});
151178

@@ -166,6 +193,7 @@ describe('Arc element tests', function() {
166193
options: {
167194
spacing: 0,
168195
offset: 0,
196+
borderWidth: 0
169197
}
170198
});
171199

@@ -194,6 +222,7 @@ describe('Arc element tests', function() {
194222
options: {
195223
spacing: 0,
196224
offset: 0,
225+
borderWidth: 0
197226
}
198227
});
199228

@@ -211,6 +240,7 @@ describe('Arc element tests', function() {
211240
options: {
212241
spacing: 0,
213242
offset: 0,
243+
borderWidth: 0
214244
}
215245
});
216246

@@ -230,6 +260,7 @@ describe('Arc element tests', function() {
230260
options: {
231261
spacing: 0,
232262
offset: 0,
263+
borderWidth: 0,
233264
scales: {
234265
r: {
235266
grid: {

0 commit comments

Comments
 (0)