aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2021-12-20 11:49:22 +0300
committerzsloan2022-01-29 00:42:44 -0600
commit53985f5ac92d31f38748d101c9bb1574b11e5f73 (patch)
treeb4bee585a0eb9551f35b4462bc3ad800fe5cca2d
parentaea641e0a6fbd0ea68241efffb7c280222491238 (diff)
downloadgenenetwork2-53985f5ac92d31f38748d101c9bb1574b11e5f73.tar.gz
Format numbers for display
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi * Format the numbers for display, to reduce the number of columns needed for display.
-rw-r--r--wqflask/wqflask/static/new/javascript/partial_correlations.js18
1 files changed, 14 insertions, 4 deletions
diff --git a/wqflask/wqflask/static/new/javascript/partial_correlations.js b/wqflask/wqflask/static/new/javascript/partial_correlations.js
index e61dc250..fdba247f 100644
--- a/wqflask/wqflask/static/new/javascript/partial_correlations.js
+++ b/wqflask/wqflask/static/new/javascript/partial_correlations.js
@@ -66,6 +66,16 @@ function rho_or_r(method) {
return "r";
}
+function format_number(num) {
+ if(num === null) {
+ return NaN;
+ }
+ if(Math.abs(num) <= 1.04e-4) {
+ return num.toExponential(2);
+ }
+ return num.toFixed(5);
+}
+
function display_publish_results(primary, controls, correlations, method) {
table = document.getElementById("part-corr-results-publish");
table.setAttribute("style", "display: block;");
@@ -88,16 +98,16 @@ function display_publish_results(primary, controls, correlations, method) {
'td[data-column-heading="N"]').innerHTML = item["noverlap"];
new_row.querySelector(
`td[data-column-heading="Partial ${rho_or_r(method)}"]`
- ).innerHTML = item["partial_corr"];
+ ).innerHTML = format_number(item["partial_corr"]);
new_row.querySelector(
`td[data-column-heading="p(partial ${rho_or_r(method)})"]`
- ).innerHTML = item["partial_corr_p_value"];
+ ).innerHTML = format_number(item["partial_corr_p_value"]);
new_row.querySelector(
`td[data-column-heading="${rho_or_r(method)}"]`
- ).innerHTML = item["corr"];
+ ).innerHTML = format_number(item["corr"]);
new_row.querySelector(
`td[data-column-heading="p(${rho_or_r(method)})"]`
- ).innerHTML = item["corr_p_value"];
+ ).innerHTML = format_number(item["corr_p_value"]);
new_row.querySelector(
`td[data-column-heading="delta ${rho_or_r(method)}"]`
).innerHTML = format_number(item["delta"]);