-
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
Enable arbitrary rotation of datapoints #5319
Conversation
CodeClimate is chirping me about similar code blocks. I was trying to follow the existing conventions, but we may have reached a point where it's getting too repetitive. It might be worth refactoring all the getPointXxxxx(point, index) functions to a single getPointValue(point, index, propertyName) function. I can do that in this PR if desired. |
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.
@joelhamilton5 this is looking good. Just the one comment in the line controller code
src/controllers/controller.line.js
Outdated
pointRotation = custom.pointRotation; | ||
} else if (!isNaN(dataset.pointRotation) || helpers.isArray(dataset.pointRotation)) { | ||
pointRotation = helpers.valueAtIndexOrDefault(dataset.pointRotation, index, pointRotation); | ||
} else if (!isNaN(dataset.pointRotation)) { |
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.
I don't think this case will ever be hit. If !isNaN(dataset.pointRotation)
is true, the previous else if
will run.
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.
Oops, right you are! Fixed.
Looks good to me. Do you have any thoughts on this one @simonbrunel? |
@joelhamilton5 could you rebase this? thanks! |
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.
Looks good, I would rename the element option for elements.point.rotation
, pointRotation
being redundant in this case (at some point we should deprecate element.point.pointStyle
for element.point.style
).
src/controllers/controller.line.js
Outdated
@@ -148,6 +148,19 @@ module.exports = function(Chart) { | |||
return borderWidth; | |||
}, | |||
|
|||
getPointRotation: function(point, index) { | |||
var pointRotation = this.chart.options.elements.point.pointRotation; |
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.
var rotation = this.chart.options.elements.point.rotation;
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 also needs to be added to the element documentation as rotation
.
src/controllers/controller.radar.js
Outdated
@@ -106,6 +106,7 @@ module.exports = function(Chart) { | |||
borderColor: custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.pointBorderColor, index, pointElementOptions.borderColor), | |||
borderWidth: custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.pointBorderWidth, index, pointElementOptions.borderWidth), | |||
pointStyle: custom.pointStyle ? custom.pointStyle : helpers.valueAtIndexOrDefault(dataset.pointStyle, index, pointElementOptions.pointStyle), | |||
pointRotation: custom.pointRotation ? custom.pointRotation : helpers.valueAtIndexOrDefault(dataset.pointRotation, index, pointElementOptions.pointRotation), |
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.
rotation: custom.pointRotation ? ...
@@ -59,6 +60,12 @@ var exports = module.exports = { | |||
return; | |||
} | |||
|
|||
ctx.save(); | |||
ctx.translate(x, y); | |||
ctx.rotate(rotation * Math.PI / 180); |
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.
I don't see how we can do differently right now but I'm a bit worry of these extra save / translate / rotate / restore because drawing point is already pretty slow. Anyway, if we are translating we should remove the use of x
& y
everywhere in the switch
(and remove x = 0
and y = 0
).
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.
Sounds good!
src/controllers/controller.line.js
Outdated
@@ -185,6 +198,7 @@ module.exports = function(Chart) { | |||
// Appearance | |||
radius: custom.radius || helpers.valueAtIndexOrDefault(dataset.pointRadius, index, pointOptions.radius), | |||
pointStyle: custom.pointStyle || helpers.valueAtIndexOrDefault(dataset.pointStyle, index, pointOptions.pointStyle), | |||
pointRotation: me.getPointRotation(point, index), |
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.
rotation: me.getPointRotation(point, index),
src/elements/element.point.js
Outdated
@@ -68,6 +68,7 @@ module.exports = Element.extend({ | |||
var model = this._model; | |||
var ctx = this._chart.ctx; | |||
var pointStyle = vm.pointStyle; | |||
var rotation = vm.pointRotation; |
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.
var rotation = vm.rotation;
…10 (#5275) * Bugfix: Improve polyfill function of log10 to return whole powers of 10 as integer values, as it caused endless loop in IE11 in the tick creation loop. * Compare floating-point numbers directly instead of using unnecessary division. rotate works added docs delete line
@@ -67,6 +68,7 @@ The style of each bubble can be controlled with the following properties: | |||
| `borderColor` | bubble border color | |||
| `borderWidth` | bubble border width (in pixels) | |||
| `pointStyle` | bubble [shape style](../configuration/elements#point-styles) | |||
| `rotation` | bubble rotation (in degrees) |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
@@ -154,7 +155,8 @@ module.exports = function(Chart) { | |||
'hoverBorderWidth', | |||
'hoverRadius', | |||
'hitRadius', | |||
'pointStyle' | |||
'pointStyle', | |||
'rotation' |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
@joelhamilton5 I'm deeply sorry but I'm realizing that for the bubble controller other options are not prefixed (except @etimberg @benmccann what do you think: should we keep it consistent and simple by using Side note: |
I filed an issue to track the cleanup for 3.0: #5572 |
@simonbrunel No problem, it's all fixed up now! |
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.
@joelhamilton5 I think you missed a few changes, right?
docs/charts/bubble.md
Outdated
@@ -67,6 +68,7 @@ The style of each bubble can be controlled with the following properties: | |||
| `borderColor` | bubble border color | |||
| `borderWidth` | bubble border width (in pixels) | |||
| `pointStyle` | bubble [shape style](../configuration/elements#point-styles) | |||
| `pointRotation` | bubble rotation (in degrees) |
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.
pointRotation
-> rotation
src/controllers/controller.bubble.js
Outdated
@@ -154,7 +155,8 @@ module.exports = function(Chart) { | |||
'hoverBorderWidth', | |||
'hoverRadius', | |||
'hitRadius', | |||
'pointStyle' | |||
'pointStyle', | |||
'pointRotation' |
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.
pointRotation
-> rotation
Thanks @joelhamilton5 |
- Calculate the vertices of the shapes so that they are inscribed in the circle that has the radius of `pointRadius` - Remove `translate()` and `rotate()` to fix the regression introduced by chartjs#5319
- Calculate the vertices of the shapes so that they are inscribed in the circle that has the radius of `pointRadius` - Remove `translate()` and `rotate()` to fix the regression introduced by chartjs#5319 - Refactor `rectRounded` for better performance
- Calculate the vertices of the shapes so that they are inscribed in the circle that has the radius of `pointRadius` - Remove `translate()` and `rotate()` to fix the regression introduced by chartjs#5319 - Refactor `rectRounded` for better performance
- Calculate the vertices of the shapes so that they are inscribed in the circle that has the radius of `pointRadius` - Remove `translate()` and `rotate()` to fix the regression introduced by chartjs#5319 - Refactor `rectRounded` for better performance
- Calculate the vertices of the shapes so that they are inscribed in the circle that has the radius of `pointRadius` - Remove `translate()` and `rotate()` to fix the regression introduced by chartjs#5319 - Refactor `rectRounded` for better performance
- Calculate the vertices of the shapes so that they are inscribed in the circle that has the radius of `pointRadius` - Remove `translate()` and `rotate()` to fix the regression introduced by #5319 - Refactor `rectRounded` for better performance
…tjs#5858) - Calculate the vertices of the shapes so that they are inscribed in the circle that has the radius of `pointRadius` - Remove `translate()` and `rotate()` to fix the regression introduced by chartjs#5319 - Refactor `rectRounded` for better performance
Thought I'd take a stab at #5213, it seems like a really useful feature. I added dataset.pointRotation, and point.pointRotation options that accept positive or negative angle (in degrees). The canvas is translated to (0,0) and then rotated before drawing the point, so x & y should now be zero for the tests.
Here is a link to a quick example
I'm new to the codebase so I might have missed something. Happy for any input or suggestions!