Enable arbitrary rotation of datapoints#5319
Enable arbitrary rotation of datapoints#5319simonbrunel merged 9 commits intochartjs:masterfrom joel-hamilton:master
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. |
etimberg
left a comment
There was a problem hiding this comment.
@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.
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.
Oops, right you are! Fixed.
|
Looks good to me. Do you have any thoughts on this one @simonbrunel? |
|
@joelhamilton5 could you rebase this? thanks! |
simonbrunel
left a comment
There was a problem hiding this comment.
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
| }, | ||
|
|
||
| getPointRotation: function(point, index) { | ||
| var pointRotation = this.chart.options.elements.point.pointRotation; |
There was a problem hiding this comment.
var rotation = this.chart.options.elements.point.rotation;
There was a problem hiding this comment.
This also needs to be added to the element documentation as rotation.
src/controllers/controller.radar.js
Outdated
| 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.
rotation: custom.pointRotation ? ...
|
|
||
| ctx.save(); | ||
| ctx.translate(x, y); | ||
| ctx.rotate(rotation * Math.PI / 180); |
There was a problem hiding this comment.
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).
src/controllers/controller.line.js
Outdated
| // 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.
rotation: me.getPointRotation(point, index),
src/elements/element.point.js
Outdated
| var model = this._model; | ||
| var ctx = this._chart.ctx; | ||
| var pointStyle = vm.pointStyle; | ||
| var rotation = vm.pointRotation; |
There was a problem hiding this comment.
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
| | `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.
| '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! |
simonbrunel
left a comment
There was a problem hiding this comment.
@joelhamilton5 I think you missed a few changes, right?
docs/charts/bubble.md
Outdated
| | `borderColor` | bubble border color | ||
| | `borderWidth` | bubble border width (in pixels) | ||
| | `pointStyle` | bubble [shape style](../configuration/elements#point-styles) | ||
| | `pointRotation` | bubble rotation (in degrees) |
src/controllers/controller.bubble.js
Outdated
| 'hitRadius', | ||
| 'pointStyle' | ||
| 'pointStyle', | ||
| 'pointRotation' |
|
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!