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

feat(legend): render multiple columns on float config #1159

Merged
merged 8 commits into from
May 25, 2021

Conversation

markov00
Copy link
Member

@markov00 markov00 commented May 14, 2021

Summary

When rendering a floating legend inside the chart (Settings.legendPosition.floating:true), the added Settings.legendPosition.floatingColumns property allows you to specify the number of columns used to distributed the legend items.
Screenshot 2021-05-14 at 19 46 54

Connected issues

This feature was added as part of the Kibana Timelion chart library replacement.

fix #1158

Checklist

Delete any items that are not applicable to this PR.

  • Any consumer-facing exports were added to src/index.ts (and stories only import from ../src except for test data & storybook)
  • Proper documentation or storybook story was added for features that require explanation or tutorials

@markov00 markov00 requested a review from nickofthyme May 14, 2021 17:47
Copy link
Collaborator

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

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

LGTM, tested locally.

I think we should try to constrain the width to within the chart because this could get unwieldy pretty quickly. Constraining the overall width will start to truncate the longest strings to satisfy the constrain.

src/components/legend/style_utils.ts Show resolved Hide resolved
@@ -9,12 +9,6 @@
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we change the .echLegendList styles to include grid by default now?

  .echLegendList {
    display: grid;
  }

  &--horizontal {
    .echLegendList {
      grid-column-gap: $echLegendColumnGap;
      grid-row-gap: $echLegendRowGap;
      margin-top: $echLegendRowGap;
      margin-bottom: $echLegendRowGap;
    }
  }

@@ -68,18 +69,22 @@ export function getLegendListStyle(
return {
paddingTop,
paddingBottom,
...(floating && {
display: 'grid',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Make default, see previous comment

Suggested change
display: 'grid',

Copy link
Member Author

Choose a reason for hiding this comment

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

done in 3b1cfc4

@@ -68,18 +69,22 @@ export function getLegendListStyle(
return {
paddingTop,
paddingBottom,
...(floating && {
display: 'grid',
gridTemplateColumns: `repeat(${clamp(floatingColumns ?? 1, 1, totalItems)}, 1fr`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

1fr will cause the largest string to control the width for all columns like this....

image

If we use auto instead of 1fr then each column width will be independent. Not sure which you think is desirable but I like the independent widths.

image

Suggested change
gridTemplateColumns: `repeat(${clamp(floatingColumns ?? 1, 1, totalItems)}, 1fr`,
gridTemplateColumns: `repeat(${clamp(floatingColumns ?? 1, 1, totalItems)}, auto`,

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed in 3b1cfc4

Copy link
Collaborator

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

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

LGTM just one comment.

@@ -62,16 +62,15 @@ export function getLegendListStyle(
return {
paddingLeft,
paddingRight,
gridTemplateColumns: `repeat(auto-fill, minmax(${legendStyle.verticalWidth}px, 1fr))`,
gridTemplateColumns: `repeat(auto-fill, minmax(${legendStyle.verticalWidth}px, auto))`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this should be auto. The auto with the auto-fill acts differently than without, like below on line 73. I don't see any noticeable difference here so I think we should revert this and revisit how the horizontal legend sizes the columns is a future PR.

Suggested change
gridTemplateColumns: `repeat(auto-fill, minmax(${legendStyle.verticalWidth}px, auto))`,
gridTemplateColumns: `repeat(auto-fill, minmax(${legendStyle.verticalWidth}px, 1fr))`,

Copy link
Member Author

Choose a reason for hiding this comment

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

done here thanks 8facfeb

@markov00 markov00 merged commit c2e4652 into elastic:master May 25, 2021
@markov00 markov00 deleted the 2021_05_14-floating_legend_columns branch May 25, 2021 16:49
nickofthyme pushed a commit that referenced this pull request May 25, 2021
# [29.2.0](v29.1.0...v29.2.0) (2021-05-25)

### Bug Fixes

* **legend:** disable handleLabelClick for one legend item ([#1134](#1134)) ([a7242af](a7242af)), closes [#1055](#1055)

### Features

* **a11y:** add alt text for all chart types  ([#1118](#1118)) ([9e42229](9e42229)), closes [#1107](#1107)
* **legend:** specify number of columns on floating legend ([#1159](#1159)) ([c2e4652](c2e4652)), closes [#1158](#1158)
* simple screenspace constraint solver ([#1141](#1141)) ([eb11480](eb11480))
@nickofthyme
Copy link
Collaborator

🎉 This PR is included in version 29.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@nickofthyme nickofthyme added the released Issue released publicly label May 25, 2021
AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released Issue released publicly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multi column legend
2 participants