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] Allow palette configuration for metric #116170

Merged
merged 36 commits into from
Nov 17, 2021
Merged

Conversation

dej611
Copy link
Contributor

@dej611 dej611 commented Oct 25, 2021

Summary

Fixes #102035

This PR introduces the palette configurator to the metric visualization in Lens.

By default 3 stops are computed starting from the current metric.

Screenshot 2021-11-02 at 16 53 13

Screenshot 2021-11-02 at 16 53 36

Screenshot 2021-11-02 at 16 53 53

Screenshot 2021-11-02 at 16 54 20

Screenshot 2021-11-02 at 16 54 55

When the metric value is 0 then a special [-50, 100] range is used (in order to not collapse the color stop values AND have 0 in the middle of the current range).

Screenshot 2021-11-02 at 16 56 00

Screenshot 2021-11-02 at 17 03 46

It also works for negative values correctly:

Screenshot 2021-11-02 at 17 04 05

Custom stops are respected and override the default computation above when they exists.

  • Build a first version
  • Check compatibility with [MetricVis] Expression metricVis API update.  #114116
  • Check all i18n labels
  • Write tests for the shared palette panel
  • Write tests for the metric expression, dimension panel, visualization, functional
  • Write migration no need, just fallback to none for old metrics
  • Check with negative values
  • Check with zero value
  • Check for array values?
  • Fix reverse bug

Checklist

Delete any items that are not applicable to this PR.

Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release.

When forming the risk matrix, consider some of the following examples and how they may potentially impact the change:

Risk Probability Severity Mitigation/Notes
Multiple Spaces—unexpected behavior in non-default Kibana Space. Low High Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces.
Multiple nodes—Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. High Low Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure.
Code should gracefully handle cases when feature X or plugin Y are disabled. Medium High Unit tests will verify that any feature flag or plugin combination still results in our service operational.
See more potential risk examples

For maintainers

@dej611 dej611 added Team:Visualizations Visualization editors, elastic-charts and infrastructure Feature:Lens labels Oct 25, 2021
@dej611
Copy link
Contributor Author

dej611 commented Oct 27, 2021

@elasticmachine merge upstream

@dej611
Copy link
Contributor Author

dej611 commented Oct 28, 2021

@elasticmachine merge upstream

@dej611
Copy link
Contributor Author

dej611 commented Oct 29, 2021

@elasticmachine merge upstream

@dej611
Copy link
Contributor Author

dej611 commented Nov 2, 2021

@elasticmachine merge upstream

@dej611 dej611 added release_note:feature Makes this part of the condensed release notes v8.1.0 labels Nov 2, 2021
@ghudgins
Copy link

ghudgins commented Nov 3, 2021

I gave this PR a look (from the commit ~18 hours ago). here's my feedback:

  • As long as we aren't on Michael's updated designs I think we need Color Continuity type control. Once we're on Michael's designs this will make more sense
  • The palette preview isn't able to do the right thing (especially on 2 colors) because there's no known domain of the palette. maybe we should just do equal stops on the preview for these types of visualizations (thinking this & goal vis will have the same problem)?

@dej611
Copy link
Contributor Author

dej611 commented Nov 3, 2021

Fixed the two raised issues @ghudgins .
Also now initial values are persisted, using the initial metric as reference.

@dej611
Copy link
Contributor Author

dej611 commented Nov 4, 2021

@elasticmachine merge upstream

@dej611
Copy link
Contributor Author

dej611 commented Nov 5, 2021

@elasticmachine merge upstream

@elastic elastic deleted a comment from kibanamachine Nov 15, 2021

// NOTE: Cardinality and Sum never receives "null" as value, but always 0, even for empty dataset.
// Mind falsy values here as 0!
const shouldShowResults = row[accessor] != null;
if (!shouldShowResults) {
if (rawValue == null) {
Copy link
Contributor

@mbondyra mbondyra Nov 15, 2021

Choose a reason for hiding this comment

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

  const rawValue = row[accessor];

  // NOTE: Cardinality and Sum never receives "null" as value, but always 0, even for empty dataset.
  // Mind falsy values here as 0!
  if (typeof rawValue !== 'number') {
    return getEmptyState();
  }

This would allow us to avoid type assertion, WDYT?

@mbondyra
Copy link
Contributor

mbondyra commented Nov 16, 2021

When the metric value === 1, the default values for the stops are nice and rounded:
Screenshot 2021-11-16 at 09 32 40
but then the next added stop is not rounded - looks like you may refactor roundStopValues and use it for single value when adding a value.
Screenshot 2021-11-16 at 09 37 58

@mbondyra
Copy link
Contributor

mbondyra commented Nov 16, 2021

  1. Create the following metric visualization with on ecommerce data with timerange of 30 days:

Screenshot 2021-11-16 at 09 45 10

2. For some reason, color is green:

Screenshot 2021-11-16 at 09 45 26

  1. Edit a second stop from 0 to -1 to 0
  2. For some reason, the color switches to yellow:
Nov-16-2021.09-46-58.mp4

I think the initial value color for 0 might not be of a proper type (number instead of string) but not sure.

@mbondyra
Copy link
Contributor

mbondyra commented Nov 16, 2021

**EDIT, nevermind, missed Marco's comment about work on EUI there**

The palette preview isn't able to do the right thing (especially on 2 colors) because there's no known domain of the palette. maybe we should just do equal stops on the preview for these types of visualizations (thinking this & goal vis will have the same problem)?

I wonder if we should do the same also for custom palettes (always display equal stops)? For example, in 0-10-20, because of the current value 1, the last range (red color) looks very small.
Screenshot 2021-11-16 at 09 56 21
For 0-1-2 it looks ok:
Screenshot 2021-11-16 at 09 57 17

@dej611
Copy link
Contributor Author

dej611 commented Nov 16, 2021

The palette preview isn't able to do the right thing (especially on 2 colors) because there's no known domain of the palette. maybe we should just do equal stops on the preview for these types of visualizations (thinking this & goal vis will have the same problem)?

I wonder if we should do the same also for custom palettes (always display equal stops)? For example, in 0-10-20, because of the current value 1, the last range (red color) looks very small.

From my understanding the uniform distribution should be always applied in #116422 . I hope most of the complex code here to disappear with the new UI and stops color structure.

@mbondyra
Copy link
Contributor

Shouldn't we show a palette indicator in the dimension button? Not sure about that because there's just one color displayed at once so it's different than the pie or xy.
metric:
Screenshot 2021-11-17 at 08 30 08
xy breakdown:
Screenshot 2021-11-17 at 08 31 44

@dej611
Copy link
Contributor Author

dej611 commented Nov 17, 2021

Shouldn't we show a palette indicator in the dimension button? Not sure about that because there's just one color displayed at once so it's different than the pie or xy.

That's a good point. I think it is not necessary in this case, but I see why it can still make sense. No strong opinion here. cc @ghudgins @flash1293 what do you think about it?

@flash1293
Copy link
Contributor

In favor of showing the palette indicator to stay consistent - if a dimension is doing coloring, it should be shown in the UI

@dej611
Copy link
Contributor Author

dej611 commented Nov 17, 2021

Addressed all issues reported here:

  • Rounding problem:

When the metric value === 1, the default values for the stops are nice and rounded ... but then the next added stop is not rounded

rounding_stop

Operating the fix on the shared area, this should also fix #117512

  • Initial zero value

zero_metric_case

  • Palette indicator on the dimension field

Screenshot 2021-11-17 at 14 28 02

And all the other code review feedbacks 👍

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.

Code LGTM, tested and all works good 👍🏼

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
lens 676 683 +7

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
lens 237 239 +2

Async chunks

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

id before after diff
lens 955.3KB 961.9KB +6.6KB

Page load bundle

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

id before after diff
lens 43.4KB 44.0KB +662.0B
Unknown metric groups

API count

id before after diff
lens 255 257 +2

History

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

@dej611 dej611 merged commit bf6971c into elastic:main Nov 17, 2021
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Nov 17, 2021
fkanout pushed a commit to fkanout/kibana that referenced this pull request Nov 19, 2021
* ✨ Metrics have colors

* 🏷️ Fix type issues

* 🐛 Fix dimension removal bug

* 🐛 Fix initial stops computation

* 🐛 Fix various bugs + unit tests

* ✅ Add functional tests

* 🐛 Fix the reverse bug and failing tests

* bug: Fix custom stops issue with attached tests

* 🐛 Reintroduced continuity logic and fixed 2 stops problem

* 🐛 Fix palette display + default palette behaviour

* 🐛 Fix edge case when switching to default palettes

* 💄 Display custom stop when available or uniform palette for defaults

* 💄 Integrated feedback

* commit using @elastic.co

* commit using @elastic.co

* 📸 Updated snapshots

* Update x-pack/plugins/lens/public/metric_visualization/expression.scss

Co-authored-by: Michael Marcialis <michael@marcial.is>

* 👌 integrated feedback

* 🐛 Revert codeline change

* :feature: Add palette display on field dimension

* ✅ Fix functional test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Michael Marcialis <michael@marcial.is>
TinLe pushed a commit to TinLe/kibana that referenced this pull request Nov 20, 2021
* ✨ Metrics have colors

* 🏷️ Fix type issues

* 🐛 Fix dimension removal bug

* 🐛 Fix initial stops computation

* 🐛 Fix various bugs + unit tests

* ✅ Add functional tests

* 🐛 Fix the reverse bug and failing tests

* bug: Fix custom stops issue with attached tests

* 🐛 Reintroduced continuity logic and fixed 2 stops problem

* 🐛 Fix palette display + default palette behaviour

* 🐛 Fix edge case when switching to default palettes

* 💄 Display custom stop when available or uniform palette for defaults

* 💄 Integrated feedback

* commit using @elastic.co

* commit using @elastic.co

* 📸 Updated snapshots

* Update x-pack/plugins/lens/public/metric_visualization/expression.scss

Co-authored-by: Michael Marcialis <michael@marcial.is>

* 👌 integrated feedback

* 🐛 Revert codeline change

* :feature: Add palette display on field dimension

* ✅ Fix functional test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Michael Marcialis <michael@marcial.is>
dmlemeshko pushed a commit that referenced this pull request Nov 29, 2021
* ✨ Metrics have colors

* 🏷️ Fix type issues

* 🐛 Fix dimension removal bug

* 🐛 Fix initial stops computation

* 🐛 Fix various bugs + unit tests

* ✅ Add functional tests

* 🐛 Fix the reverse bug and failing tests

* bug: Fix custom stops issue with attached tests

* 🐛 Reintroduced continuity logic and fixed 2 stops problem

* 🐛 Fix palette display + default palette behaviour

* 🐛 Fix edge case when switching to default palettes

* 💄 Display custom stop when available or uniform palette for defaults

* 💄 Integrated feedback

* commit using @elastic.co

* commit using @elastic.co

* 📸 Updated snapshots

* Update x-pack/plugins/lens/public/metric_visualization/expression.scss

Co-authored-by: Michael Marcialis <michael@marcial.is>

* 👌 integrated feedback

* 🐛 Revert codeline change

* :feature: Add palette display on field dimension

* ✅ Fix functional test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Michael Marcialis <michael@marcial.is>
roeehub pushed a commit to build-security/kibana that referenced this pull request Dec 16, 2021
* ✨ Metrics have colors

* 🏷️ Fix type issues

* 🐛 Fix dimension removal bug

* 🐛 Fix initial stops computation

* 🐛 Fix various bugs + unit tests

* ✅ Add functional tests

* 🐛 Fix the reverse bug and failing tests

* bug: Fix custom stops issue with attached tests

* 🐛 Reintroduced continuity logic and fixed 2 stops problem

* 🐛 Fix palette display + default palette behaviour

* 🐛 Fix edge case when switching to default palettes

* 💄 Display custom stop when available or uniform palette for defaults

* 💄 Integrated feedback

* commit using @elastic.co

* commit using @elastic.co

* 📸 Updated snapshots

* Update x-pack/plugins/lens/public/metric_visualization/expression.scss

Co-authored-by: Michael Marcialis <michael@marcial.is>

* 👌 integrated feedback

* 🐛 Revert codeline change

* :feature: Add palette display on field dimension

* ✅ Fix functional test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Michael Marcialis <michael@marcial.is>
gbamparop pushed a commit to gbamparop/kibana that referenced this pull request Jan 12, 2022
* ✨ Metrics have colors

* 🏷️ Fix type issues

* 🐛 Fix dimension removal bug

* 🐛 Fix initial stops computation

* 🐛 Fix various bugs + unit tests

* ✅ Add functional tests

* 🐛 Fix the reverse bug and failing tests

* bug: Fix custom stops issue with attached tests

* 🐛 Reintroduced continuity logic and fixed 2 stops problem

* 🐛 Fix palette display + default palette behaviour

* 🐛 Fix edge case when switching to default palettes

* 💄 Display custom stop when available or uniform palette for defaults

* 💄 Integrated feedback

* commit using @elastic.co

* commit using @elastic.co

* 📸 Updated snapshots

* Update x-pack/plugins/lens/public/metric_visualization/expression.scss

Co-authored-by: Michael Marcialis <michael@marcial.is>

* 👌 integrated feedback

* 🐛 Revert codeline change

* :feature: Add palette display on field dimension

* ✅ Fix functional test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Michael Marcialis <michael@marcial.is>
@smchamberlin
Copy link

smchamberlin commented Dec 14, 2022

@dej611 , is the code that was merged in for this only for metric? I would love to use this in my bar graph ... I see there is an issue already open for bar graph which references this merge, but seems it is still open: #4482
and I only see this in the UI under metric ...

Thanks!

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:feature Makes this part of the condensed release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Allow palette configuration for metric
9 participants