Use element width/height in fallback positioner#327
Use element width/height in fallback positioner#327simonbrunel merged 5 commits intochartjs:masterfrom
Conversation
simonbrunel
left a comment
There was a problem hiding this comment.
The suggested changes should be generic enough to accommodate most custom elements and I also agree that the risk of breaking changes is minimal but not inexistent. I think Chart.js should introduce some conventions on how to describe elements (e.g. x, y, width, height or top, left, bottom, right or cx, cy, width, height, etc...) or provide abstract methods to query the element boundaries and center, so plugins could interoperate better.
My initial thought was to move the positioners to defaults...
Sounds indeed like a pretty big change for little value compare to this PR.
Also the defaults do not apply when the plugin is not registered globally.
...which I still think should be considered as a bug in the core library.
At least couple of Chart.js extensions use x, y, width, height props in their elements, where x, y describe the top/left corner.
This change would utilize the width and height to determine the center point of the element.
This would be a breaking change if there is an extension that both has width/height on the elements and uses x/y for center point.
My initial thought was to move the positioners to defaults and use the element id to find from there, but its a bit larger change and would not work with derived element types (
instanceof PointElementprobably works for derived point elements).Also the defaults do not apply when the plugin is not registered globally.