diff --git a/src/core/js/ext_cosmetics.js b/src/core/js/ext_cosmetics.js index aeb88cc9763ccc48dc01f0a25670fb67cf471198..13bfa66f5bc08b24c22bf219edacbc85b7bbda10 100644 --- a/src/core/js/ext_cosmetics.js +++ b/src/core/js/ext_cosmetics.js @@ -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(); + } } }