diff --git a/src/whylogs/viewer/templates/index-hbs-cdn-all-in-for-jupyter-notebook.html b/src/whylogs/viewer/templates/index-hbs-cdn-all-in-for-jupyter-notebook.html
index bf4679c678..a83d37dd88 100644
--- a/src/whylogs/viewer/templates/index-hbs-cdn-all-in-for-jupyter-notebook.html
+++ b/src/whylogs/viewer/templates/index-hbs-cdn-all-in-for-jupyter-notebook.html
@@ -1026,24 +1026,19 @@
Hold on! :)
}
}
- function abbreviateNumber(value) {
- let newValue = value,
- suffixe = ""
- if (value >= 1000) {
- let suffixes = ["", "K", "M", "B","T"];
- let suffixNum = Math.floor( (""+value).length/3 );
- let shortValue = '';
- for (let precision = 2; precision >= 1; precision--) {
- shortValue = parseFloat( (suffixNum != 0 ? (value / Math.pow(1000,suffixNum) ) : value).toPrecision(precision));
- let dotLessShortValue = (shortValue + '').replace(/[^a-zA-Z 0-9]+/g,'');
- if (dotLessShortValue.length <= 2) { break; }
- }
- if (shortValue % 1 != 0) shortValue = shortValue.toFixed(1);
- newValue = shortValue;
- suffixe = suffixes[suffixNum]
- }
- return {value, newValue, suffixe};
- }
+ abbreviate_number = function(value, fixed = 0) {
+ value = +value
+ if (value === null) { return null; } // terminate early
+ if (value === 0) { return '0'; } // terminate early
+ fixed = (!fixed || fixed < 0) ? 0 : fixed; // number of decimal places to show
+ var b = (value).toPrecision(2).split("e"), // get power
+ k = b.length === 1 ? 0 : Math.floor(Math.min(b[1].slice(1), 14) / 3), // floor at decimals, ceiling at trillions
+ c = k < 1 ? value.toFixed(0 + fixed) : (value / Math.pow(10, k * 3) ).toFixed(1 + fixed), // divide by power
+ d = c < 0 ? c : Math.abs(c), // enforce -0 is 0
+ newValue = d,
+ suffixe = ['', 'K', 'M', 'B', 'T'][k]; // append power
+ return {value, newValue, suffixe};
+ }
function formatBytes(bytes, decimals = 2) {
let newValue,
@@ -1079,17 +1074,17 @@ Hold on! :)
`
Handlebars.registerHelper("observations", function (properties) {
- const {value, newValue, suffixe} = abbreviateNumber(referenceProfile.properties.observations)
+ const {value, newValue, suffixe} = abbreviate_number(referenceProfile.properties.observations)
return numberWithSuffixe(value, valueNumber(newValue), valueNumber(suffixe));
});
Handlebars.registerHelper("missingCells", function (properties) {
- const {value, newValue, suffixe} = abbreviateNumber(referenceProfile.properties.missing_cells)
- return numberWithSuffixe(value, newValue, suffixe);
+ const {value, newValue, suffixe} = abbreviate_number(referenceProfile.properties.missing_cells)
+ return numberWithSuffixe(value, valueNumber(newValue), valueNumber(suffixe));
});
Handlebars.registerHelper("missingCellsPercentage", function (properties) {
- const {value, newValue, suffixe} = abbreviateNumber(fixNumberTo(referenceProfile.properties.missing_percentage, 2))
+ const {value, newValue, suffixe} = abbreviate_number(referenceProfile.properties.missing_percentage)
return numberWithSuffixe(value, valueSuffixe(`(${newValue}%)`), suffixe);
});