-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Polar area: align start angle with angleLines #5919
Conversation
I think that's a breaking change, right? |
@simonbrunel Yes, its breaking change. Also a bug fix 🙈 |
I don't think we can/should change the unit of |
Should not have it both ways either 2.7.3 |
I updated the PR description with a before / after screenshots. The problem is when there is no angle lines, the current (2.7.3) behavior is not bugged but Another question: why |
function getValueCount(scale) {
var opts = scale.options;
return opts.angleLines.display || opts.pointLabels.display ? scale.chart.data.labels.length : 0;
} getIndexAngle divides by that 0 getIndexAngle: function(index) {
var angleMultiplier = (Math.PI * 2) / getValueCount(this); |
I think not. Something should still be done. Couple of options come in mind;
|
I would suggest to
This won't break existing projects. |
Maybe |
This was my initial approach.
What about radar charts with startAngle defined in degrees? Custom chart types using radialLinear axis? |
I notice that |
It seems to me like the fundamental problem here is that all the radialLinear scale methods like Here's from the radialLinear scale:
The problem here is that the scale doesn't know whether I'm not really sure how to fix this while maintaining backwards compatibility. I think I agree with @kurkle when he calls it a bug in the polarArea chart. It may be a bit painful to change it, but it's also a bit painful to leave this bug in place. I would vote for fixing the bug which I think means we need to change to degrees @simonbrunel @nagix thoughts? |
This problem appears only when var startAngleRadians = (this.chart.config.type === 'polarArea') ?
startAngle + Math.PI * 0.5 :
startAngle * Math.PI * 2 / 360; |
How about this? (it does not work with decimal angles between -6.28 and 6.28 degrees (about), excluding 0. But who needs those in a chart?): helpers.autoRadians = function(angle) {
var TAU = 2 * Math.PI;
if (angle >= -TAU && angle <= TAU && Math.floor(angle) !== angle) {
console.warn('angles defined in radians are deprecated and will not be supported in 3.0.');
return angle;
}
return helpers.toRadians(angle);
};
Demonstrated in this pen: https://codepen.io/kurkle/pen/ZVvrqg Added "&& Math.floor(angle) !== angle" to allow whole degrees of 1..6 (this leaves tiny holes in radian support)
|
Another idea: we could introduce an option for degrees vs radians. Then the scale doesn't need to know which chart is being used and users can specify which ever they prefer |
492b0a6
to
fb5c00b
Compare
src/scales/scale.radialLinear.js
Outdated
? me.chart.options.startAngle | ||
: 0; | ||
|
||
var startAngleRadians = (me.chart.config.type === 'polarArea') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, but it'd be nicer if the scale didn't have to know about the chart type. What if we instead introduce an option for degrees vs radians? Then the scale doesn't need to know which chart is being used and users can specify which ever they prefer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to fix a bug here, I'd rather not introduce a new option to work around it.
If this was fixed using a new option, then would have to specify conflicting defaults to chart types. IMO that would be a new confusing public API to keep backward compatible.
I just remembered this PR. It might be a good idea to standardize on degrees vs radians now that we're working on 3.0, so I'll reopen this one. @kurkle you can close it again if it's not something you want to eventually pursue |
Rebased |
The polar area behavior is changed? It's now in degrees with 0 at the top, which wasn't the case before? If that's right, then it'd be good to add something to migration guide about that |
var angle = (index * angleMultiplier + startAngle) % 360; | ||
|
||
return (angle < 0 ? angle + 360 : angle) * Math.PI * 2 / 360; | ||
return _normalizeAngle(index * angleMultiplier + toRadians(startAngle)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit surprising to me that this is returning radians now that all the options are specified in degrees. Should we just standardize on degrees everywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CanvasRenderingContext2d
is going to need radians as input, so need to convert at some point.
IMO its clear that options are degrees, while everything internal (API included) should be radians.
There are only couple of things that contribute to that opinion:
- developers are usually familiar with radians
- people in general (users) are more likely familiar with degrees.
- most functions require radians as input
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. That makes sense. Should we convert determineLimits
to use radians and remove the toDegrees
function in that case?
@kurkle this one will need to be rebased |
Ok, this is going nowhere. |
I'd rather merge as is than let perfect be the enemy of good |
Polar area treats startAngle as radians and 0 at right. However radar chart and radialLinear scale expects startAngle to be degrees and 0 to be at top.
https://codepen.io/kurkle/pen/RERWEz
Note: I did not botrher changing values displayed to radians for this gif. They were just converted to radians for config.
Fixes #5907