Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Border is counted as part of ArcElement #11180

Merged
merged 2 commits into from Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/elements/element.arc.ts
Expand Up @@ -322,7 +322,7 @@ export default class ArcElement extends Element<ArcProps, ArcOptions> {
'outerRadius',
'circumference'
], useFinalPosition);
const rAdjust = this.options.spacing / 2;
const rAdjust = (this.options.spacing + this.options.borderWidth) / 2;
const _circumference = valueOrDefault(circumference, endAngle - startAngle);
const betweenAngles = _circumference >= TAU || _angleBetween(angle, startAngle, endAngle);
const withinRadius = _isBetween(distance, innerRadius + rAdjust, outerRadius + rAdjust);
Expand Down
31 changes: 31 additions & 0 deletions test/specs/element.arc.tests.js
Expand Up @@ -13,6 +13,7 @@ describe('Arc element tests', function() {
options: {
spacing: 0,
offset: 0,
borderWidth: 0
}
});

Expand All @@ -35,6 +36,7 @@ describe('Arc element tests', function() {
options: {
spacing: 0,
offset: 0,
borderWidth: 0
}
});

Expand Down Expand Up @@ -68,6 +70,27 @@ describe('Arc element tests', function() {
options: {
spacing: 10,
offset: 0,
borderWidth: 0
}
});

expect(arc.inRange(7, 0)).toBe(false);
expect(arc.inRange(15, 0)).toBe(true);
});

it ('should include borderWidth for in range check', function() {
// Mock out the arc as if the controller put it there
var arc = new Chart.elements.ArcElement({
startAngle: 0,
endAngle: Math.PI / 2,
x: 0,
y: 0,
innerRadius: 5,
outerRadius: 10,
options: {
spacing: 0,
offset: 0,
borderWidth: 10
}
});

Expand All @@ -88,6 +111,7 @@ describe('Arc element tests', function() {
options: {
spacing: 0,
offset: 0,
borderWidth: 0
}
});

Expand All @@ -106,6 +130,7 @@ describe('Arc element tests', function() {
options: {
spacing: 0,
offset: 0,
borderWidth: 0
}
});

Expand All @@ -126,6 +151,7 @@ describe('Arc element tests', function() {
options: {
spacing: 0,
offset: 0,
borderWidth: 0
}
});

Expand All @@ -146,6 +172,7 @@ describe('Arc element tests', function() {
options: {
spacing: 10,
offset: 10,
borderWidth: 0
}
});

Expand All @@ -166,6 +193,7 @@ describe('Arc element tests', function() {
options: {
spacing: 0,
offset: 0,
borderWidth: 0
}
});

Expand Down Expand Up @@ -194,6 +222,7 @@ describe('Arc element tests', function() {
options: {
spacing: 0,
offset: 0,
borderWidth: 0
}
});

Expand All @@ -211,6 +240,7 @@ describe('Arc element tests', function() {
options: {
spacing: 0,
offset: 0,
borderWidth: 0
}
});

Expand All @@ -230,6 +260,7 @@ describe('Arc element tests', function() {
options: {
spacing: 0,
offset: 0,
borderWidth: 0,
scales: {
r: {
grid: {
Expand Down