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

Fix arc border with circumference over 2*PI #6215

Merged
merged 6 commits into from Apr 30, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion src/elements/element.arc.js
Expand Up @@ -30,7 +30,7 @@ module.exports = Element.extend({

if (vm) {
var pointRelativePosition = helpers.getAngleFromPoint(vm, {x: chartX, y: chartY});
var angle = pointRelativePosition.angle;
var angle = pointRelativePosition.angle;
var distance = pointRelativePosition.distance;

// Sanitise angle range
Expand Down Expand Up @@ -89,6 +89,10 @@ module.exports = Element.extend({
var pixelMargin = (vm.borderAlign === 'inner') ? 0.33 : 0;
var angleMargin;

if (vm.circumference > Math.PI * 2) {
benmccann marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

@nagix nagix Apr 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in case 0 <= circumference <= 2*PI and 2*PI < circumference <= 4*PI, but appearance is not consistent when circumference > 4*PI. How about looping this part (endAngle - startAngle) / (Math.PI * 2) times?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loop implemented, did some more refactoring to keep CC (and me) happy 😄
Demo updated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a loop would doing % 2PI be more efficient?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etimberg that was my initial approach, but with transparency it is not consistent with circumference > 4*PI.
Not sure if anyone is going to use circumference that high anyway, but now its drawn consistently.

sA += (eA - sA) % (Math.PI * 2);
}

ctx.save();

ctx.beginPath();
Expand Down
@@ -0,0 +1,24 @@
{
"config": {
"type": "doughnut",
"data": {
"labels": ["A"],
"datasets": [{
"data": [100],
"backgroundColor": [
"rgba(153, 102, 255, 0.8)"
],
"borderWidth": 20,
"borderColor": [
"rgb(153, 102, 255)"
]
}]
},
"options": {
"circumference": 7,
"responsive": false,
"legend": false,
"title": false
}
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.