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] Stack as percentage #70703

Merged
merged 34 commits into from
Sep 15, 2020
Merged

Conversation

flash1293
Copy link
Contributor

@flash1293 flash1293 commented Jul 3, 2020

Related: #57389
Fixes: #72320

This PR implements a "percentage mode" for area and bar charts. There are quite some uncertainties around this I want to explore with this PR.

Screenshot 2020-07-03 at 13 38 18

TODOs

  • Write tests
  • Integrate additional icons

Functionality

There are multiple options how to offer this functionality - it could be a flag in the chart level settings, a layer level setting or even a metric level setting. However I think this is best shown as a new "chart type" in the popover:
Screenshot 2020-07-03 at 13 38 23

We would need an icon similar to the "stacked" chart icons.

This also includes a suggestion to show the current chart as percentage if a stacked chart is used:

Screenshot 2020-07-03 at 13 45 14

It's possible to use a percentage layer along with a non-percentage layer:
Screenshot 2020-07-03 at 13 57 44

Transitions between charts are described in #70703 (comment)

This PR also changes the default percentage formatting to maximum two decimal places (instead of always showing three)

Implementation

On a technical level these are simply new series types of the xy chart: 'bar_percentage_stacked' | 'bar_horizontal_percentage_stacked' | 'area_percentage_stacked'. If the type includes percentage, percentage mode will be activated on the series spec. Also, the axis formatter will be overwritten with a percentage formatter.

This PR does not implement the "Other" bucket for the terms operation - I get why this is related but I think there are still a lot of valid use cases for a percentage mode even without this feature. IMHO we should split it out into a separate PR.

@flash1293
Copy link
Contributor Author

@wylieconlon @mbondyra @cchaos @AlonaNadler Looking for feedback on this one as well.

@flash1293
Copy link
Contributor Author

@elasticmachine merge upstream

@AlonaNadler
Copy link

The pr failed for me, anything Im missing?

@flash1293
Copy link
Contributor Author

@AlonaNadler updated the PR, should work again.

@mbondyra
Copy link
Contributor

mbondyra commented Jul 16, 2020

@flash1293 when it comes to how to offer the functionality, I agree with you, for me the most friendly would be to present it as another chart type (until we have 30 types of charts I think we're safe with going this direction and I don't think we plan many more soon).
Same for 'others' - that could be added later.
I've tested the PR and noticed one bug when switching to area_stacked_percentage (not sure if you're looking for this kind of feedback or just design-wise as it's still a draft)
image

Also, it's worth to mention, we need icons for main chart switcher and the xy chart one:

For the layer xy chart one, maybe it makes sense to add a tooltip with name because it's not that clear only looking at the icons.

@flash1293
Copy link
Contributor Author

@mbondyra Thanks for the review, I didn't expect this failure so it's good to know :) I will make sure I get this one when cleaning up the PR.

I remember some early mock ups with a search bar and filters in the chart switcher - if it gets too busy we can introduce something like this.

@cchaos
Copy link
Contributor

cchaos commented Jul 16, 2020

Question: What makes the configuration of a Stacked vs Percentage stacked chart so different that it needs to be a separate chart type?

@flash1293
Copy link
Contributor Author

flash1293 commented Jul 16, 2020

@cchaos It's not about difference, more about discoverability and consistent ui - we are treating stacked charts vs non-stacked counterparts the same way and you could ask the same question there. None of the xy chart variants "need" to be a different chart type, we could also present all of these settings as a set of UI controls like it's done in Visualize:
Screenshot 2020-07-16 at 18 02 27

Happy to change it to a switch somewhere though, this is exactly what I want to discuss here :)

@cchaos
Copy link
Contributor

cchaos commented Jul 17, 2020

I do think there is an added ease-of-use to supplying this chart as a specific chart type, but I also want to ensure that users who may start in a normal bar or stacked bar can easily change it (or know how to change it) to display as percentages. So a couple thoughts on that (and these might already be addressed, just want to reiterate them):

  1. Switching to the percentage style from any other x/y chart type will be able to take all configurations without any problems
  2. Perhaps we still offer this setting in the config popover for all x/y charts, so it's another place where they can find it

As for the chart type picker and the icons, we are starting to amass quite a bit of different x/y charts in particular. I can create some icons to indicate these new chart types, but I think we need to go further and:

  1. Stop using the glyph style icons in the layer settings. Maintaining two different icon sets will get unruly and there's quite a disconnect between the two styles that can start creating confusion
  2. In the chart picker, start categorizing the chart types (maybe adding descriptions) and add a quick search/filter input.

@flash1293
Copy link
Contributor Author

@cchaos Thanks for the feedback.

Switching to the percentage style from any other x/y chart type will be able to take all configurations without any problems

I don't see any issues here as soon as Wylies bugfix for multi layer chart switches is solved. Technically this pretty similar to stacking.

Perhaps we still offer this setting in the config popover for all x/y charts, so it's another place where they can find it

You mean the newly introduced "Settings" popover? We can add an option in there as well to convert all of the layers to percentage mode, but take into account we can also configure charts with only partial percentage mode ("Mixed XY chart")

Stop using the glyph style icons in the layer settings. Maintaining two different icon sets will get unruly and there's quite a disconnect between the two styles that can start creating confusion
In the chart picker, start categorizing the chart types (maybe adding descriptions) and add a quick search/filter input.

Both of these sound great, could you throw together a quick mock up? Then I can adjust the chart picker on this PR

@cchaos
Copy link
Contributor

cchaos commented Jul 17, 2020

You mean the newly introduced "Settings" popover?

No I mean the config popover, the one where you select the aggregation and field.

I can get you a mock next week

@flash1293
Copy link
Contributor Author

flash1293 commented Jul 20, 2020

No I mean the config popover, the one where you select the aggregation and field.

Oh, that's a change in how the percentage mode is applied - right now it happens on a per layer basis, but putting it in there would imply it's a per metric setting.

@cchaos
Copy link
Contributor

cchaos commented Jul 20, 2020

I'm playing with the PR and trying to understand percentages better.

From my understanding a percentage chart doesn't make sense to have multiple y-axis unless they are on separate layers. See this example:

Screen Shot 2020-07-20 at 17 24 09 PM

So should we restrict percentage charts to a single y-axis per layer? If so, then it seems that this setting IS metric-based and not necessarily layer based. But we'd have to have some crazy logic about allowing the selection the metric config popover only if there's a single y-axis. We could possibly revisit this option later and concentrate it on just being a chart type for now.

Is there also a short name for it? It's quite a mouthful

@flash1293
Copy link
Contributor Author

flash1293 commented Jul 21, 2020

@cchaos I agree in most cases a percentage chart with multiple metrics on y axis doesn't make sense, but it can make sense if the two metrics are in relation to each other, e.g. sum of netPrice, sum of tax - it's a difficult balance to make it hard to do the wrong thing without restricting justified use cases too much.

About the naming - the only alternative I can think of would be "ratio chart", but it might get confusing considering a quick function named "Filter ratio" or something along those lines. Do we even need to put the full name in the chart switcher like this?

@AlonaNadler
Copy link

Feedback so far. I admit it was hard to test and kept failing on me, changes to intervals, and number of terms in the breakdown by didnt seem to take effect.

  • it makes sense to have a stacked percentage chart as a chart in the chart switchers.
    • We need new icons for that
    • I would organize the charts by types and similarities: first-row bar, stacked bar, stacked % bar. Second: area chart, stacked area, stacked % area. third: line, table, metric. fourth row: pie, donut treemap. last horizontal, horizontal stacked, horizontal percentage. Right now everything looks too similar in the first 3 rows of charts. also horizontal is not being used frequently.
  • stacked requires x-axis, y-axis, breakdown by.
  • Transitions: this is how I suggest we do the transitions
    image

From empty state - if users started by selecting one of the stack % charts:

  • if there is a x-axis and breakdown by but no y-axis we can default to count of records
  • if the chart missing a breakdown by - let's show the red error required dimension
    * if we have a time series with only x-axis, y-axis and users select to move to stacked percentage. How about we move the x-axis

@flash1293
Copy link
Contributor Author

@AlonaNadler Fixed the bug with the area percentage chart. I couldn't reproduce the problem with the unchangeable terms and date histogram params, could you share steps to reproduce for that?

About the transitions: I like those in general, but we don't have a way to represent "timestamp (on entire time range)" - this is both a problem for building the suggestion as well as configuring it in general (as there is no "entire time range" setting, and using the custom interval comes with its own problems). Also, simply from a UX standpoint - will the user understand how to change that X axis to something meaningful? Not saying it's impossible but it would be a lot of effort to make that work smoothly, so I wonder whether there is a better way? As it's the least effort in the current system I would recommend using auto interval for that date histogram for now to keep the effort for this feature low and make a note for this when we get to improving suggestions in general.

@flash1293
Copy link
Contributor Author

Discussed this with @AlonaNadler and the best option to handle transitions with percentage mode charts is to allow an empty x axis dimension in xy charts in general and behave like Visualize by rendering just a single data point. Percentage mode chart maps bucket dimension to break down first to always render meaningful percentage.

@@ -45,6 +45,24 @@ export function getSuggestions({
table.columns.every((col) => col.operation.dataType !== 'number') ||
table.columns.some((col) => !columnSortOrder.hasOwnProperty(col.operation.dataType))
) {
if (table.changeType === 'unchanged' && state) {
Copy link
Contributor

Choose a reason for hiding this comment

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

For the future:

I've been noticing that now that we have stacked percentage charts, I'm expecting the pie charts to transition to these instead of the regular XY charts. The smallest code change I can think of that would let us do this is to provide a "suggestion context" object like we've previously considered, and this would let the XY charts decide how to apply suggestions based on the previous chart type.

pattern: '0,0[00]%',
},
};
}

This comment was marked as resolved.

@AlonaNadler
Copy link

I went back and forth on the default percentages to show for pie charts with @AlonaNadler: currently we use 3 decimal places, and here you are showing no decimal places. Can @AlonaNadler pick one and we'll use it for both charts?

Can we use two decimal point as the maximum by default?

@flash1293
Copy link
Contributor Author

@AlonaNadler @wylieconlon

  • Addressed the review comments
  • Changed formatting to maximum 2 decimal places. Also adjusted the label in the pie popover

Screenshot 2020-09-07 at 12 04 37

@cchaos Could you check and approve the scss changes? Pretty sure they are inherited your PR on top of this branch anyway.

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

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

It's getting very close, but please update the formatters

formatter = {
id: 'percent',
params: {
pattern: '0.[00]%',
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no customization option for the user?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would also like to point out that the current slider for the decimals is really laggy and may need some sort of debounce. https://share.getcloudapp.com/rRu7AK6N

Copy link
Contributor

Choose a reason for hiding this comment

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

@cchaos that looks like an existing issue for pie charts- this is the XY chart where there's no slider

Copy link
Contributor Author

@flash1293 flash1293 Sep 9, 2020

Choose a reason for hiding this comment

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

It's configurable by configuring the percentage format in the metric dimension. I think it's a good approach for now, if changing the format will become super common we can think about exposing it more prominently.

Screenshot 2020-09-09 at 10 43 46

Let's iterate on that in separate PRs.

@cchaos I created a separate issue for the slider (#77039), as it's not really related to the changes here

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

Just found a couple things when playing with the PR but overall seems good to me. I can approve after the few changes mentioned.

x-pack/plugins/lens/public/pie_visualization/toolbar.tsx Outdated Show resolved Hide resolved
formatter = {
id: 'percent',
params: {
pattern: '0.[00]%',
Copy link
Contributor

Choose a reason for hiding this comment

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

I would also like to point out that the current slider for the decimals is really laggy and may need some sort of debounce. https://share.getcloudapp.com/rRu7AK6N

x-pack/plugins/lens/public/xy_visualization/types.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

Great, LGTM, thanks!

@flash1293
Copy link
Contributor Author

@elasticmachine merge upstream

@flash1293
Copy link
Contributor Author

@wylieconlon Are you fine with the formatting solution for the scope of this PR?

@flash1293
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

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

LGTM, did not run the code again!

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

@kbn/optimizer bundle module count

id value diff baseline
lens 436 +3 433

page load bundle size

id value diff baseline
lens 1.1MB +16.0KB 1.0MB

History

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Lens release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Change default formatter for percentages to 0.[00]
8 participants