Skip to content
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

Update plugin.legend.js with a new option: 'alignment'. #5866

Closed
wants to merge 1 commit into from

Conversation

Zmimmy
Copy link

@Zmimmy Zmimmy commented Nov 27, 2018

The position options for the legend only allow top, bottom, left, and right. Then the legends are aligned in the center on the top and bottom and at the top in left and right.

This adds a new option to the legend: 'alignment' which allow the legend to be aligned within its layout box.

In the case of position top or bottom, the legend can be aligned 'left', 'right', or 'center', with center being the default. For position right or left the legend can be aligned 'top', 'center', or 'bottom', with top being default as the current behavior.

Updated the legend help page to reflect these changes.

Similar: #3706

See: http://jsfiddle.net/pdht9ces/10/

Copy link
Member

@etimberg etimberg left a comment

Choose a reason for hiding this comment

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

@Zmimmy that's for this MR. I've left a few comments about the position computations that allow the code to handle some more cases. Additionally, what kind of tests do you think would be appropriate for this feature?

src/plugins/plugin.legend.js Outdated Show resolved Hide resolved
src/plugins/plugin.legend.js Outdated Show resolved Hide resolved
src/plugins/plugin.legend.js Outdated Show resolved Hide resolved
@simonbrunel
Copy link
Member

@Zmimmy Thanks!

Before reviewing, I would like to align the API with the one in this comment:

  • rename legend.alignment by legend.align
  • rename left, center, right by start, center, end
  • rename top, center, bottom by start, center, end

No need to implement stretch of course because it would be more complex.

src/plugins/plugin.legend.js Outdated Show resolved Hide resolved
src/plugins/plugin.legend.js Outdated Show resolved Hide resolved
src/plugins/plugin.legend.js Outdated Show resolved Hide resolved
@nagix
Copy link
Contributor

nagix commented Nov 28, 2018

We also need additional logic in

x = cursor.x = me.left + ((legendWidth - lineWidths[cursor.line]) / 2) + labelOpts.padding;
and
y = cursor.y = me.top + labelOpts.padding;
to reset x or y position based on the alignment configuration.

@nagix
Copy link
Contributor

nagix commented Nov 28, 2018

I'm assuming the following default row/column alignment, which needs to be considered in case of more than one row/column, but does this make sense?

  • position: 'top' or 'bottom'
    • align: 'start' -> Each row is aligned to the left
    • align: 'center' -> Each row is aligned to the center
    • align: 'end' -> Each row is aligned to the right
  • position: 'left' or 'right'
    • align: 'start' -> Each column is aligned to the top
    • align: 'center' -> Each column is aligned to the middle
    • align: 'end' -> Each column is aligned to the bottom

@Zmimmy
Copy link
Author

Zmimmy commented Nov 28, 2018

Thanks for all the feedback! We just started using chartJS and I am not super familiar with the codebase yet so I appreciate all the insight. I will start making those changes this afternoon.

…egend to be aligned within its layout box.

The legend can be aligned in 3 ways 'start', 'center' (default), or 'end'.
Updated the legend help page to reflect these changes.
Add a number tests to test the new align option
@Zmimmy
Copy link
Author

Zmimmy commented Nov 29, 2018

I have made the changes and added test cases.

I'm assuming the following default row/column alignment, which needs to be considered in case of more than one row/column, but does this make sense?

  • position: 'top' or 'bottom'

    • align: 'start' -> Each row is aligned to the left
    • align: 'center' -> Each row is aligned to the center
    • align: 'end' -> Each row is aligned to the right
  • position: 'left' or 'right'

Yes, this makes sense and is now happening.

  • align: 'start' -> Each column is aligned to the top
  • align: 'center' -> Each column is aligned to the middle
  • align: 'end' -> Each column is aligned to the bottom

This also makes sense but is not currently happening exactly like this when there are multiple columns, all the columns default to the top of the legend container.

@michvllni
Copy link

Any update on this? I'd really appreciate this feature.

@baradhili
Copy link

Checking @Zmimmy did you get a chance to remediate?

@YonathanB
Copy link

Waiting for that feature :)

@simonbrunel
Copy link
Member

@Zmimmy Thanks for your contribution! We decided to go with #6141 since the implementation is a bit simpler and consistent whatever the legend orientation.

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.

None yet

7 participants