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 number formatting within Lens #56253

Merged
merged 26 commits into from
Feb 28, 2020

Conversation

wylieconlon
Copy link
Contributor

Release note

Lens now allows you to format numbers as Percent or Bytes from within Lens, with a setting for the number of decimal places to show:

Screenshot 2020-01-28 17 59 16

Screenshot 2020-01-28 17 59 20

Screenshot 2020-01-28 17 59 26

Detail

The original scope of this change was larger, but contains two breaking changes that aren't possible to mitigate: #53972

The reduced-scope change introduces an expression function called lens_format_column columnId="a" format="bytes" maxDecimals=3 which sets the formatHint property of the kibana_datatable. This function is responsible for generating numeral.js patterns, such as 0,0.[000]%, depending on the formatter and number of decimals selected.

Users do not get to set numeral.js patterns directly, because this lets us change the implementation to Intl.NumberFormat in 8.0 without causing another breaking change.

Checklist

@wylieconlon wylieconlon added release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.0.0 Feature:Lens v7.7.0 labels Jan 28, 2020
@wylieconlon wylieconlon requested review from timroes and a team January 28, 2020 23:05
@wylieconlon wylieconlon requested a review from a team as a code owner January 28, 2020 23:05
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@@ -83,6 +83,7 @@ export type IFieldFormatId = FIELD_FORMAT_IDS | string;

export type IFieldFormatType = (new (params?: any, getConfig?: GetConfigFn) => FieldFormat) & {
id: IFieldFormatId;
title?: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Title is already present on formatters, but the type was not set

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason this needs to be optional? It seems from the FieldFormat class, that the title is the same as id and fieldType always present, and could just be a mandatory string.

@wylieconlon
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Member

@lukeelmers lukeelmers left a comment

Choose a reason for hiding this comment

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

LGTM for app arch (just looking at the update to IFieldFormatType)

@wylieconlon
Copy link
Contributor Author

wylieconlon commented Jan 29, 2020

Tagging for product/design review @AlonaNadler @cchaos

Related issue: #53535

This doesn't yet implement a tab-based UI, I expect that to be coming soon for use in Y-axis styling

@cchaos
Copy link
Contributor

cchaos commented Jan 30, 2020

@wylieconlon Can you explain what "Default format (Number)" is? I would have suspected that we don't need to explicitly say "Default" but that we'd just automatically select "Number".

Screen Shot 2020-01-30 at 15 59 48 PM

So then there'd be no distinction between "Default" and "Custom" numbers, but just a single "Number" option that always shows the decimals option.


When I select a price field, the formatter option still says "Default format (Number)" when in fact it's showing as a currency.

Screen Shot 2020-01-30 at 15 50 32 PM

@wylieconlon
Copy link
Contributor Author

wylieconlon commented Jan 30, 2020 via email

@wylieconlon
Copy link
Contributor Author

That's also why there is a difference between the Default and the "Custom number" formatter, because "Custom number" as implemented here only lets you customize the number of decimal places, while in the Management -> Index pattern settings, you can use a numeral.js pattern.

@AlonaNadler
Copy link

Great work @wylieconlon
Few comments:

  • Custom number decimal didnt work as expected. I configured 3 decimal points but it only showed one. even if it is zeros it needs to show the numbers according to what is configured.
    image

  • When changing the function the formating is lost I would expect it is persistent with the number
    format lens

  • In TSVB it changes between KB and MB dynamically by the scale. It seems like in Lens it is always KB is that accurate ? can we use GB and MB similar to TSVB

  • Format should be applied in the suggestions as well, sometimes it does sometimes it don't
    image

@wylieconlon
Copy link
Contributor Author

Thanks for the feedback! Responses inline.

Custom number decimal didnt work as expected. I configured 3 decimal points but it only showed one. even if it is zeros it needs to show the numbers according to what is configured.
image

Talked with you about this, what I've implemented is the maximum number of decimal places, and what you are asking for is the minimum number of decimal places. We need to talk more about this before making a decision.

When changing the function the formating is lost I would expect it is persistent with the number format

Will fix this.

In TSVB it changes between KB and MB dynamically by the scale. It seems like in Lens it is always KB is that accurate ? can we use GB and MB similar to TSVB

We're using the same format, so this is already happening.

Format should be applied in the suggestions as well, sometimes it does sometimes it don't

I'll look into this, I think we can apply the format to some suggestions but not others. If we are using the same field then it should be doable.

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.

Based on our meeting, I've added some review notes.

<>
<EuiFormRow
label={i18n.translate('xpack.lens.indexPattern.columnFormatLabel', {
defaultMessage: 'Formatter',
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
defaultMessage: 'Formatter',
defaultMessage: 'Display values as',

@AlonaNadler Trying to better describe the input via the label here without being to verbose. But I think "Formatter" is wrong, since it just changes the the way the values are displayed not actual formatting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm trying "Display format" because I do think it's important to be consistent with the rest of Kibana. We call this "Format" everywhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you do Value format instead?

@cchaos
Copy link
Contributor

cchaos commented Feb 11, 2020

  1. Yes I think it's important to persist the decimal point no matter what they've chosen before.
  2. I can consistently reproduce this it just all depends on your output values, I just added bytes field from the sample logs data and you can see the result in the y-axis after changing to Bytes format

Image 2020-02-11 at 4 25 56 PM

3. Hmm ok

@wylieconlon
Copy link
Contributor Author

Okay, both 2 and 3 are related to the same overall issue, which is that our formatters don't have any context. It's especially noticeable because the bytes formatter scales itself between orders of magnitude, but affects dates as well. For example: #7539 #51227

I don't expect to solve these issues in this PR, as it's something the bytes formatter has across Kibana. Feel free to open an issue to discuss the problem of bytes formatting on the Y axis.

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.

PR looks good from my end! 🎉

I will be doing a follow up PR closer to FF for any style tweaks.

@wylieconlon
Copy link
Contributor Author

To do: Change from 3 to 2 decimal places by default

@wylieconlon
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@timroes timroes left a comment

Choose a reason for hiding this comment

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

LGTM

@wylieconlon
Copy link
Contributor Author

@elasticmachine merge upstream

@wylieconlon
Copy link
Contributor Author

@elasticmachine merge upstream

@wylieconlon
Copy link
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@wylieconlon wylieconlon merged commit 6c6bc1f into elastic:master Feb 28, 2020
@wylieconlon wylieconlon deleted the lens/format-selection branch February 28, 2020 18:08
wylieconlon pushed a commit that referenced this pull request Feb 28, 2020
* [Lens] Allow custom number formats on dimensions

* Fix merge issues

* Text and decimal changes from review

* Persist number format across operations

* Respond to review comments

* Change label

* Add persistence

* Fix import

* 2 decimals

* Persist number formatting on drop too

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
jloleysens added a commit to jloleysens/kibana that referenced this pull request Mar 2, 2020
…dex-server-side

* 'master' of github.com:elastic/kibana: (34 commits)
  [Upgrade Assistant] Remove "boom" from reindex service (elastic#58715)
  [data] Clean up QueryStringInput unit tests (elastic#58704)
  [SIEM] Detection Fix typo in Adobe Hijack Persistence rule (elastic#58804)
  Restores [SIEM][CASE] Init Configure Case Page (elastic#58121) (elastic#58924)
  Skips additional failing Ingest Manager integration tests
  Skips failing Ingest Manager integration tests
  Move dev tools styles to NP (elastic#58855)
  change to have kibana --ssl cli option use more recent certs (elastic#57933)
  disable failing suite (elastic#58942)
  Don't start pollEsNodesVersion unless someone subscribes (elastic#56923)
  Do not write UUID file during optimize process (elastic#58899)
  [Endpoint] Task/add nav bar (elastic#58604)
  [Metric Alerts] Add backend support for multiple expressions per alert  (elastic#58672)
  [Metrics Alerts] Fix alerting on a rate aggregation (elastic#58789)
  disable flaky suite (elastic#55953)
  Revert "[SIEM] apollo@3 (elastic#51926)" and "[SIEM][CASE] Init Confi… (elastic#58806)
  [resubmit] Prep agg types for new platform (elastic#58893)
  [Lens] Allow number formatting within Lens (elastic#56253)
  [Autocomplete] Use settings from config rather than UI settings (elastic#58784)
  Improve action and trigger types (elastic#58657)
  ...

# Conflicts:
#	x-pack/plugins/upgrade_assistant/server/routes/reindex_indices/reindex_indices.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants