-
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
feature: legend navigation #11825
base: master
Are you sure you want to change the base?
feature: legend navigation #11825
Conversation
- Add legend pagination as an optional feature - Fix multiline legend overlap in horizontal positioning - Fix legend title left and right padding not working - Fix legend title overlapping with multiple lines
@@ -56,6 +57,26 @@ export class Legend extends Element { | |||
*/ | |||
this._hoveredItem = null; | |||
|
|||
this.navigation = { |
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.
Wouldn't it be more logical if this was undefined unless someone has its feature enabled?
@@ -117,7 +139,272 @@ export class Legend extends Element { | |||
legendItems.reverse(); | |||
} | |||
|
|||
this.legendItems = legendItems; | |||
this.navigation.legendItems = this.legendItems = legendItems; |
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.
Personally I think doing this in 2 steps is a lot more readable and less error prone:
this.navigation.legendItems = this.legendItems = legendItems; | |
this.legendItems = legendItems; | |
this.navigation.legendItems = legendItems; |
this.navigation._width = this.navigation._height = 0; | ||
this.navigation._maxWidth = this.navigation._maxHeight = 0; | ||
this.navigation.itemWidth = this.navigation.itemHeight = 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.
idem
@@ -0,0 +1,56 @@ | |||
{ |
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.
In this test the arrows are vertical, but in the previous test legend-navigation-horizontal-auto-visible
they are horizontal. Is that expected?
I needed this feature to manage many legends on the same chart, but I couldn't find anything besides the HTML legends. Therefore, I decided to implement this feature, and I hope it can be useful for the Chart.js core, as I believe it is essential.
An example of the navigation working, and also the documentation created, can be found here: https://cerbaro.dev/Chart.js/samples/legend/navigation.html
Furthermore, during the process I encountered some issues and ended up solving them.
#11280 - Horizontal padding of the legend title does not work
#11824 - Horizontal legend multiline labels overlaps
I am willing to collaborate with any changes you deem necessary.
Issues related to legend pagination: #10893, #7100, #6545, #3761, #5561, #11425 (There's probably others as well).
There is an open issue for a refactor in the legend plugin (#9342), but I don't know when version 5 will be released, perhaps it would be interesting to add this navigation to the current version anyway.
I would be happy to contribute to the new version if needed.