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

Unit: Add SI prefix for empty unit #79897

Merged
merged 3 commits into from
Feb 23, 2024
Merged

Unit: Add SI prefix for empty unit #79897

merged 3 commits into from
Feb 23, 2024

Conversation

raymalt
Copy link
Contributor

@raymalt raymalt commented Dec 28, 2023

What is this feature?

It adds a new unit under the Misc category called SI prefix, which converts unit-less number labels on the y axis to the SI prefix notation.

Why do we need this feature?

Add the possibility to have SI prefix for empty units, for example convert 10000 to 10 k. This is useful when plotting multiple parameters with similar, but not identical units. One example is AC power quantities (active, reactive, apparent power), whose units are W, VAr and VA. The idea is to use the unit-less SI prefixing to get a clean y axis labeling.

Who is this feature for?

Any user who wants the shortened notation of numbers accomplished by creating SI prefix when a unit is not necessary or possible on the y axis.

Which issue(s) does this PR fix?:

Fixes #78022

Special notes for your reviewer:

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

@raymalt raymalt requested review from a team as code owners December 28, 2023 20:04
@raymalt raymalt requested review from Clarity-89, eledobleefe and oshirohugo and removed request for a team December 28, 2023 20:04
@grafana-pr-automation grafana-pr-automation bot added area/frontend pr/external This PR is from external contributor labels Dec 28, 2023
@raymalt
Copy link
Contributor Author

raymalt commented Dec 28, 2023

I made a similar PR a while back, but it was closed due to inactivity (#78023). I'd love this functionality in my Grafana Cloud instances, so I'm creating a new one here with some improved branching/naming. Please let me know if there is anything lacking or if there is anything I can to better next time to have a PR merged.

@raymalt
Copy link
Contributor Author

raymalt commented Jan 11, 2024

I made a similar PR a while back, but it was closed due to inactivity (#78023). I'd love this functionality in my Grafana Cloud instances, so I'm creating a new one here with some improved branching/naming. Please let me know if there is anything lacking or if there is anything I can to better next time to have a PR merged.

Dear reviewers @Clarity-89 @oshirohugo @eledobleefe

Just wanted to check if there is a chance of a merge of this simple addition? If it's deemed too minor or uninteresting, please let me know.

Thanks!

@@ -45,6 +45,7 @@ export const getCategories = (): ValueFormatCategory[] => [
id: 'short',
fn: scaledUnits(1000, ['', ' K', ' Mil', ' Bil', ' Tri', ' Quadr', ' Quint', ' Sext', ' Sept']),
},
{ name: 'SI prefix', id: 'siprefix', fn: SIPrefix('') },
Copy link
Member

Choose a reason for hiding this comment

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

I think this would be identical to the "short" unit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it would not. For example, 10000000000 would become 10 Bil with the short unit, while the proposed SI prefix unit would return 10 G. Additionally, I don't think there's support for shortening values with exponent below 0. For example, 0.00001 would become the same with the short unit, while SI prefix would return 10 u.

Generally, I believe the SI prefix notation would be much more understandable in the engineering community, and perhaps also elsewhere. Especially since the convention for the number of zeros in billion, trillion etc varies across the globe.

Copy link
Member

Choose a reason for hiding this comment

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

Would it not be a suffix if it's after the 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.

That's an interesting point, but I think the common term is prefix since the letter normally prefixes a unit. It's just that the unit in non-existent in this case. Maybe the name could be clarified to "Unitless SI prefix" or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or maybe SI short to present it as an alternative to the short notation?

Copy link
Member

Choose a reason for hiding this comment

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

@raymalt yes, that is a better name

Copy link
Contributor Author

@raymalt raymalt Jan 22, 2024

Choose a reason for hiding this comment

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

@torkelo ok, I pushed a new commit with an updated naming.

@raymalt raymalt requested a review from torkelo January 12, 2024 13:03
@torkelo torkelo added this to the 10.4.x milestone Jan 29, 2024
@aangelisc aangelisc modified the milestones: 10.4.x, 11.0.x Feb 20, 2024
@Clarity-89
Copy link
Contributor

@raymalt could you please update this PR to the latest main?

@raymalt
Copy link
Contributor Author

raymalt commented Feb 23, 2024

@raymalt could you please update this PR to the latest main?

@Clarity-89 Not entirely sure what I just did was correct, could you please check?

@Clarity-89 Clarity-89 merged commit 43b186a into grafana:main Feb 23, 2024
15 of 16 checks passed
@raymalt raymalt deleted the 78022-unitless-si-prefixes branch February 24, 2024 09:39
yuri-tceretian pushed a commit that referenced this pull request Feb 26, 2024
* Unit: Add SI prefix for empty unit

* Units: Change name from SI prefix to SI short
chalapat pushed a commit to nokia/grafana that referenced this pull request Feb 27, 2024
* Unit: Add SI prefix for empty unit

* Units: Change name from SI prefix to SI short
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to changelog area/frontend pr/external This PR is from external contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Standard options: unit: SI prefix needed
5 participants