@sjcrh/proteinpaint-shared 2.87.0 → 2.87.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjcrh/proteinpaint-shared",
3
- "version": "2.87.0",
3
+ "version": "2.87.1",
4
4
  "description": "ProteinPaint code that is shared between server and client-side workspaces",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -1,4 +1,4 @@
1
- import { roundValue } from './roundValue.js'
1
+ import { roundValueAuto } from './roundValue.js'
2
2
 
3
3
  /* This file generates summary statistics on any given array of numbers*/
4
4
 
@@ -42,15 +42,15 @@ export default function summaryStats(array) {
42
42
  return {
43
43
  values: [
44
44
  { id: 'total', label: 'Total', value: n },
45
- { id: 'min', label: 'Minimum', value: roundValue(min, 2) },
46
- { id: 'p25', label: '1st quartile', value: roundValue(p25, 2) },
47
- { id: 'median', label: 'Median', value: roundValue(median, 2) },
48
- { id: 'mean', label: 'Mean', value: roundValue(mean(arr), 2) },
49
- { id: 'p75', label: '3rd quartile', value: roundValue(p75, 2) },
50
- { id: 'max', label: 'Maximum', value: roundValue(max, 2) },
51
- { id: 'SD', label: 'Standard deviation', value: roundValue(stdDev, 2) },
52
- { id: 'variance', label: 'Variance', value: roundValue(variance, 2) },
53
- { id: 'IQR', label: 'Inter-quartile range', value: roundValue(IQR, 2) }
45
+ { id: 'min', label: 'Minimum', value: roundValueAuto(min) },
46
+ { id: 'p25', label: '1st quartile', value: roundValueAuto(p25) },
47
+ { id: 'median', label: 'Median', value: roundValueAuto(median) },
48
+ { id: 'mean', label: 'Mean', value: roundValueAuto(mean(arr)) },
49
+ { id: 'p75', label: '3rd quartile', value: roundValueAuto(p75) },
50
+ { id: 'max', label: 'Maximum', value: roundValueAuto(max) },
51
+ { id: 'SD', label: 'Standard deviation', value: roundValueAuto(stdDev) },
52
+ { id: 'variance', label: 'Variance', value: roundValueAuto(variance) },
53
+ { id: 'IQR', label: 'Inter-quartile range', value: roundValueAuto(IQR) }
54
54
  ]
55
55
  }
56
56
  }
package/src/roundValue.js CHANGED
@@ -7,16 +7,22 @@ round a value to specified digits
7
7
  value: given value
8
8
  digits: number of digits to round to
9
9
  */
10
+
10
11
  export function roundValue(value, digits) {
11
12
  const v = Number(value)
12
13
  if (Number.isInteger(v)) return v
13
- if (Math.abs(v) < 1) return Number(v.toPrecision(digits))
14
+ const abs = Math.abs(v)
15
+ if (abs < 1 || abs > 9999) {
16
+ //Number() reverts positive values less than 10^21 to a whole number
17
+ return abs > 9999 ? v.toPrecision(digits) : Number(v.toPrecision(digits))
18
+ }
14
19
  return Number(v.toFixed(digits))
15
20
  }
16
21
 
17
22
  export function roundValueAuto(value) {
23
+ if (!value && value != 0) return value
18
24
  const dp = decimalPlacesUntilFirstNonZero(value)
19
- let digits = Math.abs(value) > 1 ? 2 : dp > 0 ? dp + 1 : 2
25
+ const digits = Math.abs(value) > 1 ? 2 : dp > 0 ? dp + 1 : 2
20
26
 
21
27
  return roundValue(value, digits)
22
28
  }