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

Custom formatter for mesasures in Bits #649

Open
fstolba opened this issue Jul 10, 2020 · 6 comments
Open

Custom formatter for mesasures in Bits #649

fstolba opened this issue Jul 10, 2020 · 6 comments

Comments

@fstolba
Copy link

fstolba commented Jul 10, 2020

Hello and thanks for this grandiose project!

We would be happy to have a formatter that writes "b" (lowercase B, signifying "bits") instead of "B" (uppercase B, signifying "bytes") following the relevant SI prefix (Ki/Mi/Gi).

Having bit based units displayed as B is actually quite irritating. At the moment we're calculating everything as Megabits and display that as a plain number but it's hard to read (739273 Megabits) and having SI prefixes for bits would be nicer.

Is this possible with plain numbro.js? The v1 docs only talk about Bytes.

@adrianmroz
Copy link
Collaborator

I can't format that way with either version of numbro.js. Sadly, I don't think we can do anything about it - I don't see any other library that handles your case (which sounds simple!).

@fstolba
Copy link
Author

fstolba commented Jul 10, 2020

Thanks for the feedback. I went searching upstream at the numbro.js repo.

Would it be possible to utilize this feature (Byte symbol localization) for replacing B with b (yes it would def be hacky)?
BenjaminVanRyseghem/numbro#359

@adrianmroz
Copy link
Collaborator

adrianmroz commented Jul 10, 2020

But wouldn't you need to multiply your input by 8?

input: 16
formatter: 2B
custom symbol: 2b

But you wan't to get 16b.

Anyways, we had some plans for better formatters (#504) and I would like to leave this issue for future considerations. Maybe we will be able to handle this case.

@fstolba
Copy link
Author

fstolba commented Jul 10, 2020

Great, thanks for taking this case into consideration.

If calculation is needed to scale the values appropriately, this can be achieved by adding a custom measure with a corresponding formula. In our case the numbers that are shown in the UI are actually "in bits". Formatting them with the numbro bytes formatter does not change the actual value but only attach the suffix SI-Unit + B. So just replacing B with b (like the locale patch linked above does) would suffice.

@paravoid
Copy link

I think I'd reword this to be about "add support for unit prefixes".

SI (multiples of 1000) would be a good start: for example for a unit of "bps" (cf. #634) it would be good to think in terms of "Mbps", "Gbps" etc, rather than "million bps", "billion bps" etc. For a unit of "bytes", then it gets a bit more complicated, as IEC prefixes (base 2) are more commonly used, so "MiB" = 1,048,576 bytes etc.

@paravoid
Copy link

For bytes, it seems like numbro.js offers that support with e.g. format: "0,0.00 b". Anything else is going to be more difficult I think, cf. BenjaminVanRyseghem/numbro#126 for a 2015-era task to add SI support to Numbro.

wmfgerrit pushed a commit to wikimedia/operations-puppet that referenced this issue Oct 19, 2020
This would show bytes units formatted using base 2 IEC/IEEE units
(KiB/MiB/GiB etc.). Unfortunately, no support exists for generalized SI
(or IEC) prefixes for other units, such as bps and pps. See
allegro/turnilo#649 for the upstream feature
request, which also links to the upstream Numbro.js feature request as
well.

Change-Id: I7ddc5ca83fcdb0b5a971effbea8cbbb49afb5094
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants