Skip to content
Snippets Groups Projects
Commit 3c6db64f authored by Vishesh Verma's avatar Vishesh Verma
Browse files

Update file ext_cosmetics.js

parent a40a41b5
No related branches found
No related tags found
1 merge request!143EXTERN: MR 116 Changes
......@@ -129,6 +129,30 @@ var cosmetics = new function () {
document.body.addEventListener(preview.previewReadyEvent.type, _custom_datetime, true);
}
/**
* Prettify double values for display purposes.
*/
const prettify_double_values = () => {
$('.caosdb-f-property-double-value').each(function (index) {
if (!$(this).hasClass("caosdb-v-property-double-prettified")) {
let value = parseFloat(this.innerText);
let prettified_value = "";
if (Math.abs(value) > 1e6 || Math.abs(value) < 1e-6) {
// Use scientific notation for very large or very small values
prettified_value = value.toExponential(1);
} else {
// Otherwise, display with up to 12 significant digits
prettified_value = value.toPrecision(12).replace(/\.?0+$/, '');
}
$(this).addClass("caosdb-v-property-double-prettified");
$(this).hide();
$(this).after(`<span class="caosdb-v-property-double-prettified-newvalue">${prettified_value}</span>`);
}
});
};
this.init = function () {
this.custom_datetime = custom_datetime;
if ("${BUILD_MODULE_EXT_COSMETICS_CUSTOMDATETIME}" == "ENABLED") {
......@@ -138,6 +162,10 @@ var cosmetics = new function () {
if ("${BUILD_MODULE_EXT_COSMETICS_LINKIFY}" == "ENABLED") {
linkify();
}
this.prettify_double_values = prettify_double_values;
if ("${BUILD_MODULE_EXT_COSMETICS_PRETTIFY_DOUBLES}" === "ENABLED") {
prettify_double_values();
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment