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

[Lens] Set legend pixel width #126018

Merged
merged 17 commits into from
Mar 11, 2022

Conversation

DianaDerevyankina
Copy link
Contributor

@DianaDerevyankina DianaDerevyankina commented Feb 18, 2022

Closes #123803

Summary

Added control to legend settings popover that allows selecting legend width from options like Auto, Small, Medium, Large and Extra large. It is applicable for XY, partition, and heatmap charts with vertical legends.

lens legend width setting

Moved number of columns setting outside of LegendLocationSettings to a separate component to place it below width setting for XY.

image

*Setting doesn't get disabled for XY inside legends though it doesn't work for inside legends for now, but it's supposed to be fixed on the charts side.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@DianaDerevyankina DianaDerevyankina self-assigned this Feb 18, 2022
@DianaDerevyankina DianaDerevyankina added Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.2.0 labels Feb 21, 2022
@DianaDerevyankina DianaDerevyankina marked this pull request as ready for review February 22, 2022 10:26
@DianaDerevyankina DianaDerevyankina requested a review from a team as a code owner February 22, 2022 10:26
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-vis-editors @elastic/kibana-vis-editors-external (Team:VisEditors)

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

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

This looks great Diana!! A small change to be consistent.
When this is disabled (legend is hidden) let's change the tooltip content to:
image

And a note (I don't think we can do something for it from the kibana side)
It doesn't seem to behave correctly when I have a very long text cc @markov00
lens1

<FormattedMessage
id="xpack.lens.shared.legendSizeSetting.tooltip"
defaultMessage="Limited to max of 70% of the chart container.
Vertical legends limited to min of 30% of chart width"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Vertical legends limited to min of 30% of chart width"
Vertical legends limited to min of 30% of chart width."

Copy link
Contributor

@dej611 dej611 left a comment

Choose a reason for hiding this comment

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

Not sure it is something we can fix on the kibana side, but I think this feature does not work properly (in all chart types) when the legend moves on the top or bottom of the visualization:
Screenshot 2022-02-22 at 16 13 06
Screenshot 2022-02-22 at 16 15 32
Screenshot 2022-02-22 at 16 20 33

Perhaps the padding direction is computed on the height rather than width in these cases? cc @markov00

Other issue I noticed is that the setting is ignored when the legend is moved inside the chart as for the XY visualizations:

Screenshot 2022-02-22 at 16 13 45

Last small (nitpick) issue is the removal of the help when the field is disabled. Would it be possible to leave the help icon/tooltip?
Screenshot 2022-02-22 at 16 14 52

@stratoula
Copy link
Contributor

stratoula commented Feb 22, 2022

@dej611 I think that when the legend is on top/bottom it affects the height and not the width. About the inside legends, good catch! We can disable it for now, when the inside position is selected. (unless we can fix it on our side)

@dej611
Copy link
Contributor

dej611 commented Feb 22, 2022

@dej611 I think that when the legend is on top/bottom it affects the height and not the width. About the inside legends, good catch! We can disable it for now, when the inside position is selected. (unless we can fix it on our side)

The problem I see in there is that when on the horizontal positioning the "size" is increasing the space for the legend label to grow and becomes more readable, but for the vertical positioning that is not true anymore rather just some padding + offset unit, and the user should use instead the "columns" to increase the space.
It would be great to harmonize these controls into something better in my opinion. cc @ghudgins what do you think?

@ghudgins
Copy link
Contributor

I agree. I am hoping we can follow this PR up with that more intentional design. I believe the primary way users will eventually do this is with draggable resizable legends. These settings could be derived based on best guess / defaults and reserved as an "advanced" option for fine tuning if we get it wrong. I 100% agree that users won't want to poke at these similar settings. this feature is a 🩹 right now and needs to go through a design process at some point (esp. once elastic-charts does the resizable legend support IMO)

Copy link
Contributor

@MichaelMarcialis MichaelMarcialis left a comment

Choose a reason for hiding this comment

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

Thanks for putting this together, @dziyanadzeraviankina. This is looking great. I've left a few questions and comments below for your review.

Additionally, seeing as these toolbar popovers continue to grow more robust and complex over time, I'm curious if now is a good time to revisit my original modus operandi of "disable form fields when the user has the ability to enable them in the current context." While that thinking works in simpler situations (where there is a desire to showcase all available features to users), I worry that it is now becoming too cluttered and visually noisy for the user to be presented with so many disabled fields that they have to stumble past.

Would it make sense to instead start hiding the fields that are currently being disabled in these toolbar popovers and only showing them when they available (as we've begun doing in the configuration flyouts, per the latest annotation designs)? Or would it be better to make a separate issue/PR for such a task?

CCing @ghudgins and @flash1293, in case they have any thoughts.

Comment on lines 42 to 58
<EuiFieldNumber
placeholder={i18n.translate('xpack.lens.shared.legendSizeSetting.placeholder', {
defaultMessage: 'Auto',
})}
value={legendSize}
min={1}
step={1}
compressed
disabled={isDisabled}
onChange={(e) => {
const value = Number(e.target.value) || undefined;
onLegendSizeChange(value);
}}
append={i18n.translate('xpack.lens.shared.legendSizeSetting.fieldAppend', {
defaultMessage: 'px',
})}
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels a little weird to me that we're restricting users to a percentage range (via the min/max percentage widths/heights being applied behind the scenes), but then asking that users enter a pixel value for their desired legend width/height. I worry that the mixing of percentage and pixel dimensions could be point of confusion to users, especially given that the restricted dimension range is only indicated in the tooltip. Depending on the size of their visualization container, a single visualization may have the user's legend pixel dimensions honored in one scenario but hitting the min/max threshold in another.

Instead, would it make sense to 1) change the input type from pixels to percentages and 2) change this number input to an EuiRange slider (with accompanying showInput prop)? Doing would allow users to immediately see the min and max range via the slider, without having to consult a tooltip. It would also remove any situation of the user being confused over why their applied pixel dimensions aren't being honored when exceeding min/max thresholds, as that wouldn't be possible anymore. For example, if the legend is aligned left or right, then we would show an EuiRange slider (and accompanying showInput prop) with an available range of 30%–70%.

Also, if this is a direction we're interested in pursuing, then we can probably reconsider whether we need a tooltip for this field at all (since the range slider is a bit more self-explanatory).

Thoughts? CCing @ghudgins and @gvnmagni in case they have any thoughts on this topic.

Copy link
Member

Choose a reason for hiding this comment

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

  1. change the input type from pixels to percentages
    @MichaelMarcialis I don't have a strong opinion here but I can list two reasons why we should not do that:
  1. at a dashboard level you can't nicely align the legend of multiple charts vertically if each chart has different sizes
  2. the legend content doesn't resize/grow/expand in percentage as the legend. Adding configuring it in percentage means that if I configured my chart in lens (with the lens ~4/3 aspect ratio) i probably get a different aspect ratio in a dashboard. If I configured a 20% legend width in a 500px width time chart in Lens and then I'm stretching my chart to the full dashboard horizontal space (let's say 1920px), I may end up with a legend ~400px wide that is actually a bit too much.

It could be instead interesting to change, as a first iteration, the input to a selector with a bunch of predefined sizes like: small (50px), medium (100px), large (200px) xl (300px) etc so it's easier for the user to pick the same choice on multiple charts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. change this number input to an EuiRange slider (with accompanying showInput prop)

I agree that slider could fit perfectly, but unfortunately, we can't tell the chart size from settings bar as it configures the chart without accessing its actual properties like size. That is why we have to go with that limits explanatory tooltip

Copy link
Contributor

Choose a reason for hiding this comment

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

It could be instead interesting to change, as a first iteration, the input to a selector with a bunch of predefined sizes like: small (50px), medium (100px), large (200px) xl (300px) etc so it's easier for the user to pick the same choice on multiple charts

We've adopted this strategy multiple times and I think it makes sense here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, such preset-based interface will reduce a bit the current legend popover layout, which is starting to be quite articulated:

Screenshot 2022-02-24 at 16 43 08

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. at a dashboard level you can't nicely align the legend of multiple charts vertically if each chart has different sizes
  2. the legend content doesn't resize/grow/expand in percentage as the legend. Adding configuring it in percentage means that if I configured my chart in lens (with the lens ~4/3 aspect ratio) i probably get a different aspect ratio in a dashboard. If I configured a 20% legend width in a 500px width time chart in Lens and then I'm stretching my chart to the full dashboard horizontal space (let's say 1920px), I may end up with a legend ~400px wide that is actually a bit too much.

@markov00: Excellent points. I spoke too soon and wasn't considering the repercussions this would have on dashboards.

It could be instead interesting to change, as a first iteration, the input to a selector with a bunch of predefined sizes like: small (50px), medium (100px), large (200px) xl (300px) etc so it's easier for the user to pick the same choice on multiple charts

@markov00, @dej611: I really like this suggestion for how easy it makes it for users to pick a consistent size and because it could potentially alleviate the need for us to even have an "auto" mode at all. Instead, we could simply default to whichever of these predefined sizes makes the most sense. Or do we still require an "auto" sizing mode to allow the legend to collapse down to the width/height of the legend's contents?

In any case, I think we can consolidate the auto toggle and legend size rows into a single row with either an EuiSelect or EuiButtonGroup that contains the available size options (including auto if it is still necessary). Would you be open to making such a change, @dziyanadzeraviankina?

Copy link
Member

Choose a reason for hiding this comment

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

@MichaelMarcialis the auto legend size was a feature requested or preexisting in vislib, it has its own pros and cons but it still an opportunity. I'm totally happy to remove it (since it will alleviate our constraints and layout calculation) but I think this deserve discussing a bit more. Can we chat on Monday about that?

Comment on lines 349 to 353
<LegendSizeSettings
legendSize={legendSize}
onLegendSizeChange={onLegendSizeChange}
isDisabled={mode === 'hide'}
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

My first instinct is to say that this might be better placed immediately after the "Alignment" form row. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

@dziyanadzeraviankina: It looks like the legend size controls moved up a bit, but not immediately after the "Alignment" row in some visualization types. Would it be possible to move above "Number of columns" in the screenshot below?

image

Comment on lines 43 to 45
placeholder={i18n.translate('xpack.lens.shared.legendSizeSetting.placeholder', {
defaultMessage: 'Auto',
})}
Copy link
Contributor

Choose a reason for hiding this comment

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

I've never been a big fan of the UX pattern of deleting/clearing an input field in order to revert to automatic values. I worry that such interactions are not immediately obvious to users. Would you be open to changing this so that there is a separate button group that allows users to switch between auto/custom modes prior to the dimension value input?

Copy link
Contributor

Choose a reason for hiding this comment

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

@dziyanadzeraviankina: Per #126018 (comment), I think we can either do away with the "auto" toggle or merge it with the suggested predefined size controls.

Comment on lines 349 to 353
<LegendSizeSettings
legendSize={legendSize}
onLegendSizeChange={onLegendSizeChange}
isDisabled={mode === 'hide'}
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

This setting doesn't appear to have any affect on legends when they are located inside a visualization. Should this setting be made unavailable in such situations?

image

Copy link
Contributor

@MichaelMarcialis MichaelMarcialis Feb 24, 2022

Choose a reason for hiding this comment

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

@dziyanadzeraviankina: I still have the option to change legend size on legends when they are located inside the visualization. Can we make the option unavailable in such situations?

image

@stratoula stratoula added release_note:enhancement backport:skip This commit does not require backporting and removed release_note:skip Skip the PR/issue when compiling release notes labels Feb 23, 2022
@markov00
Copy link
Member

@dej611

Perhaps the padding direction is computed on the height rather than width in these cases? cc @markov00

Actually yes, if the legend is horizontal, the size is relative to its height, because it refers to the size that is taken away from the chart. In the horizontal legend the chart height is determined by how many items you have on the list and can take up to a max of two rows. If you put two charts vertically aside to each other, the legend size doesn't matter much, but when you put the horizontally aside one to each other then the legend height is important.

I definitely see an option to reduce the legend width when using the horizontal position, but it serves a different objective.

Other issue I noticed is that the setting is ignored when the legend is moved inside the chart as for the XY visualizations:

I will take a look, I'm pretty sure we haven't considered that case, thanks for pointing it out

@DianaDerevyankina
Copy link
Contributor Author

@dej611 @MichaelMarcialis could you please take a look at the new interface?

Copy link
Contributor

@MichaelMarcialis MichaelMarcialis left a comment

Choose a reason for hiding this comment

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

Thanks for making those changes, @dziyanadzeraviankina. Upon re-review, I've added some additional comments, listed below.

Also, I wanted to bump my previous comment/question to @ghudgins and @flash1293 regarding the possibility of switching disabled toolbar form rows to hidden, as the number of options in these have grown quite a bit recently and are starting to look a bit messy. Any thoughts on whether we should address this now, in a separate PR, or discuss further?

@flash1293
Copy link
Contributor

flash1293 commented Feb 28, 2022

regarding the possibility of switching disabled toolbar form rows to hidden, as the number of options in these have grown quite a bit recently and are starting to look a bit messy

I agree with your sentiment here @MichaelMarcialis but I would like to decouple it from this feature. Let's create a separate issue for this.

@flash1293
Copy link
Contributor

My input @dziyanadzeraviankina :

  • Number input vs small/medium/large button group - I'm happy with starting with a button group here, but I would like to keep "auto" for now. "Switching to the most fitting" sounds simple but there's actually a few things we would have to change about how information is passed back and forth and it would be too large in scope for this PR. If we are not sure about button group vs number input let's use the button group because we can always change our mind switching to number input, but not the other way around
  • About "inside legend" - let's assume for now it will be fixed on the charts side, if that's not the case we can easily adjust it later on

@markov00
Copy link
Member

markov00 commented Mar 2, 2022

After a quick call with @MichaelMarcialis an @flash1293 we agreed on:

  • the user should be able to select between auto and S,M,L (please verify if 3 static values are enough or we need a forth one)
  • the current sizing option should affect only the width of vertical legends (left/right positioned)
  • we will extend elastic-charts to consider the s,m,l values when computing the automatic sizing see Limit the automatic legend size to a set of static values elastic-charts#1616

…horizontal legends and move number of columns setting outside of legend location settings component to place legend width setting above
Copy link
Contributor

@dej611 dej611 left a comment

Choose a reason for hiding this comment

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

Tested locally with Safari.

I would perhaps consider to capitalize the first letter of each size.

@flash1293
Copy link
Contributor

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
lens 742 744 +2

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
expressionHeatmap 111 114 +3
lens 335 337 +2
total +5

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
expressionHeatmap 15.6KB 15.6KB +31.0B
expressionPartitionVis 47.0KB 47.0KB +24.0B
lens 1.1MB 1.1MB +2.3KB
total +2.3KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
expressionHeatmap 13.8KB 14.0KB +159.0B
expressionPartitionVis 21.4KB 21.7KB +302.0B
lens 42.6KB 42.8KB +146.0B
visTypeHeatmap 10.4KB 10.4KB +24.0B
total +631.0B
Unknown metric groups

API count

id before after diff
expressionHeatmap 115 118 +3
lens 386 389 +3
total +6

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @dziyanadzeraviankina

Copy link
Contributor

@MichaelMarcialis MichaelMarcialis left a comment

Choose a reason for hiding this comment

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

LGTM. Since we're 1) spinning off the hiding form fields instead of disabling as a separate issue and 2) assuming the Elastic charts team is addressing the sizing of legends when located inside the visualization, I'm approving now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Lens release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Set legend pixel width