Skip to content

Comments

Use element width/height in fallback positioner#327

Merged
simonbrunel merged 5 commits intochartjs:masterfrom
kurkle:positioners
Jul 17, 2022
Merged

Use element width/height in fallback positioner#327
simonbrunel merged 5 commits intochartjs:masterfrom
kurkle:positioners

Conversation

@kurkle
Copy link
Member

@kurkle kurkle commented Jul 16, 2022

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 PointElement probably works for derived point elements).
Also the defaults do not apply when the plugin is not registered globally.

@kurkle kurkle linked an issue Jul 16, 2022 that may be closed by this pull request
Copy link
Member

@simonbrunel simonbrunel left a comment

Choose a reason for hiding this comment

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

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.

@simonbrunel simonbrunel merged commit 9ffe48b into chartjs:master Jul 17, 2022
@kurkle kurkle deleted the positioners branch July 17, 2022 08:32
@simonbrunel simonbrunel added this to the Version 2.1 milestone Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Datalabels aligned differently in matrix chart

2 participants