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] Add bit formatter #141372

Merged
merged 4 commits into from
Sep 23, 2022
Merged

[Lens] Add bit formatter #141372

merged 4 commits into from
Sep 23, 2022

Conversation

flash1293
Copy link
Contributor

Fixes #139639

adds a basic bit formatter:

Screenshot 2022-09-22 at 12 12 56

Formats a number as bits using numeral.js . Defaults to 0 decimals but it can be formatted.

@flash1293 flash1293 added release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure Feature:Lens backport:skip This commit does not require backporting labels Sep 22, 2022
@flash1293 flash1293 marked this pull request as ready for review September 22, 2022 12:16
@flash1293 flash1293 requested a review from a team as a code owner September 22, 2022 12:16
@elasticmachine
Copy link
Contributor

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

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.

Aren't we missing passing it to a child formatter? Bytes and percent are passed for intervals:
Screenshot 2022-09-22 at 15 21 06
Screenshot 2022-09-22 at 15 20 43

bits:
Screenshot 2022-09-22 at 15 20 58

@flash1293
Copy link
Contributor Author

@mbondyra good catch, I missed that. Should work now. I didn't correctly look up the actual formatter id in all places.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

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.2MB 1.2MB +571.0B

History

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

@drewdaemon
Copy link
Contributor

Given the current approach, the metric vis does not add the correct suffix.

It treats the values as regular numbers since it takes its cue as to how to format the value based on the field formatter's ID.

Have we considered adding a "bits" field formatter?

That would allow the metric vis to detect bits values and harness the power of the Intl.NumberFormat API.

Screen Shot 2022-09-22 at 11 30 07 AM

@flash1293
Copy link
Contributor Author

Good call @andrewctate , I thought about it but decided against it as it increases the surface area further (adding a new formatter which, if we follow the existing setup, needs an advanced setting for the default value) and the new metric vis is already rendering almost the same thing as it's doing the kilo, mega, giga abbreviations already (without the "b" suffix, but otherwise it's identical).

All of the approaches feel kind of hacky, but if you think the bits formatter would be preferable I can adjust the PR.

@flash1293
Copy link
Contributor Author

flash1293 commented Sep 22, 2022

This is where the default pattern is coming from - if we don't want to introduce a new advanced setting, we would need to adjust this logic which I tried to avoid, but maybe it's worth it:

pattern: this.getConfig!(`format:${this.id}:defaultPattern`),

@drewdaemon
Copy link
Contributor

Discussed the metric vis synchronously. Decided this is fine as is for now. We can always add the proper suffix later if we decided it's worth the hassle of adding a new advanced setting.

@flash1293 flash1293 merged commit 02a07f3 into elastic:main Sep 23, 2022
jennypavlova pushed a commit to jennypavlova/kibana that referenced this pull request Sep 27, 2022
* add bit formatter

* default to 0 decimals

* make sure to set format id correctly

* fix test
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.6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] shortcut to bit formatter w. suffix support
6 participants