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

[Pie] Loads the no results screen if all slices have zero value #111931

Merged
merged 10 commits into from
Sep 15, 2021

Conversation

stratoula
Copy link
Contributor

@stratoula stratoula commented Sep 13, 2021

Summary

Fixes #111743

This PR fixes a problem that occurs in the legacy pie (es-charts implementation). What happens here is that when we have data with zero values it fallbacks to Number.EPSILON. This is an actual value and es-charts renders it causing this weird behavior. I changed it to fallback to zero. When the slice value is zero nothing is rendered from the es-charts side. In order to not render a blank component I added a no results component. So if I find that all the metric values are zero then I render this component.

image

I also investigated how Lens behaves. I can't break it. Lens works correctly for zero values. But as I think that this fallback to epsilon doesn't make sense I also changed a bit the getSliceValue to return zero as a fallback. It seems that nothing breaks with this change.

Checklist

@monfera
Copy link
Contributor

monfera commented Sep 13, 2021

Just wanted to mention here too the result of our chat with @stratoula: while there's no record of the driver for adding an epsilon in the very 1st commit of the original Lens PR, it may have been motivated by a desire to show zero valued legend items, which, in the absence of other arguments, is not the best default (there can be a high number of zero-valued items, all with color assignment, which don't show up as slices, so it's generally not valuable or sensible for the user).

So I think the better baseline behavior is to not have legends for zero valued items, unless a real driver becomes known. Product needs to know about this facet, and if there's significant user demand, it's feasible for Kibana to add a toggle for showing zero values, as well as Charts to optionally enable zero-valued items in the legend without a Kibana-side EPSILON hack.

@monfera
Copy link
Contributor

monfera commented Sep 13, 2021

This PR is actually two things:

  • adding a "no data" overlay (please see the related Charts discuss issue here)
  • removing the EPSILON

Why to make this distinction, when both aspects are linked to the referred issue #111743? Because that issue only talks about a use case of all-zero slices, and neither the issue nor the PR discusses the more general circumstance of having some zero slices, which was the likely target of the EPSILON hack (and the special case of all zeros may not have been considered, or a check regressed since)

@stratoula
Copy link
Contributor Author

Thanx @monfera for your comments :)

Another thing that I decided to do in this PR is something that Lens already does. I try to find out if the metric has negative values and display the corresponding message
image

@stratoula stratoula added Feature:Lens Feature:Pie Chart Pie chart visualization feature Team:Visualizations Visualization editors, elastic-charts and infrastructure release_note:fix v7.16.0 v8.0.0 labels Sep 14, 2021
@stratoula stratoula marked this pull request as ready for review September 14, 2021 06:06
@stratoula stratoula requested a review from a team as a code owner September 14, 2021 06:06
@elasticmachine
Copy link
Contributor

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

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.

Did a first code review. Left some minor comments.

}
return Number.EPSILON;
const value = d[metricColumn.id];
return Number.isFinite(value) && value >= 0 ? value : 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can it be Infinity/-Infinity?

Suggested change
return Number.isFinite(value) && value >= 0 ? value : 0;
return Math.max(0, value);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@monfera as you asked about this change wdyt?

Copy link
Contributor

@mbondyra mbondyra Sep 14, 2021

Choose a reason for hiding this comment

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

With the formula usage, it can be, right? count()/0

Copy link
Contributor

Choose a reason for hiding this comment

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

I think in formula that is handled by the expression system. Need to check that.

src/plugins/vis_types/pie/public/pie_component.tsx Outdated Show resolved Hide resolved
}
return Number.EPSILON;
const value = d[metricColumn.id];
return Number.isFinite(value) && value >= 0 ? value : 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

See 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.

Some more feedback from testing it:

  • this more an edge case, but when sizing pie slices by Top Hit + Aggregate with any function for negative or all zero values it shows an empty workspace:

Screenshot 2021-09-14 at 12 14 31

Underneath the server is returning undefined values for each row value:

Screenshot 2021-09-14 at 12 19 45

The legacy version didn't work well either, showing a 0% label:
Screenshot 2021-09-14 at 12 36 37

  • In Lens the negative message is way too long for the suggestions, perhaps it can be improved also for the main workspace:

Screenshot 2021-09-14 at 12 07 48

@stratoula
Copy link
Contributor Author

@elasticmachine merge upstream

@stratoula
Copy link
Contributor Author

Discussed it offline with @dej611. In the example above he used a runtime field which doesn't work currently with top_hit. Here is the PR that fixes it #109531

About the Lens message, I agree, let's make it smaller. Any suggestions?

@mbondyra
Copy link
Contributor

For the error messages, I'd just remove 'try a different visualization type'. Suggestions kind of show it anyway. CC @MichaelMarcialis

I tested Lens only so far with different configurations and all work fine.

  • ‘0’ formula
  • Count()/0 formula
  • Filters that filter data to 0 (either one of them or all of them)
  • Dataset with empty fields only in considered time span
  • Cases from above on 2 or three“ slice by”
  • Intervals (I actually found unrelated issue here, will submit a separate PR)
  • Combinations of top values and filters, timestamp and intervals

stratoula and others added 2 commits September 15, 2021 12:31
Co-authored-by: Marta Bondyra <marta.bondyra@gmail.com>
Co-authored-by: Marta Bondyra <marta.bondyra@gmail.com>
Copy link
Contributor

@mbondyra mbondyra left a comment

Choose a reason for hiding this comment

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

Tested Lens thoroughly and Pie chart a bit less, but still trying to think about all the edgecases. Code LGTM 👌🏼

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
visTypePie 51 52 +1

Async chunks

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

id before after diff
lens 1.6MB 1.6MB -57.0B
visTypePie 75.9KB 77.0KB +1.1KB
total +1.0KB

History

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

@stratoula stratoula added the auto-backport Deprecated - use backport:version if exact versions are needed label Sep 15, 2021
@stratoula stratoula merged commit 34d7f68 into elastic:master Sep 15, 2021
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Sep 15, 2021
…tic#111931)

* [Pie] Loads the no results screen if all slices have zero value

* Add a functional test

* Apply PR changes

* Display no results component if the chart metric has negative values

* Nits

* Apply some of the PR comments

* Change the negative values text

* Update src/plugins/vis_types/pie/public/pie_component.test.tsx

Co-authored-by: Marta Bondyra <marta.bondyra@gmail.com>

* Update src/plugins/vis_types/pie/public/pie_component.test.tsx

Co-authored-by: Marta Bondyra <marta.bondyra@gmail.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Marta Bondyra <marta.bondyra@gmail.com>
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Sep 15, 2021
) (#112250)

* [Pie] Loads the no results screen if all slices have zero value

* Add a functional test

* Apply PR changes

* Display no results component if the chart metric has negative values

* Nits

* Apply some of the PR comments

* Change the negative values text

* Update src/plugins/vis_types/pie/public/pie_component.test.tsx

Co-authored-by: Marta Bondyra <marta.bondyra@gmail.com>

* Update src/plugins/vis_types/pie/public/pie_component.test.tsx

Co-authored-by: Marta Bondyra <marta.bondyra@gmail.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Marta Bondyra <marta.bondyra@gmail.com>

Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co>
Co-authored-by: Marta Bondyra <marta.bondyra@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed Feature:Lens Feature:Pie Chart Pie chart visualization feature release_note:fix Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.16.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pie chart using filters instead of terms displays slices when there is no data
6 participants