@haniffalab/cherita-react 0.2.0-dev.2024-11-14.065cb0d1 → 0.2.0-dev.2024-12-16.f6e39628

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.
@@ -53,7 +53,7 @@ function binDiscrete(data) {
53
53
  };
54
54
  }
55
55
  function getContinuousLabel(code, binEdges) {
56
- return `[ ${(0, _string.prettyNumerical)(binEdges[code][0])}, ${(0, _string.prettyNumerical)(binEdges[code][1])}${code === binEdges.length - 1 ? " ]" : " )"}`;
56
+ return `[ ${(0, _string.formatNumerical)(binEdges[code][0])}, ${(0, _string.formatNumerical)(binEdges[code][1], _string.FORMATS.EXPONENTIAL)}${code === binEdges.length - 1 ? " ]" : " )"}`;
57
57
  }
58
58
  function CategoricalItem(_ref) {
59
59
  let {
@@ -88,7 +88,7 @@ function CategoricalItem(_ref) {
88
88
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
89
89
  className: "pl-1 m-0",
90
90
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Tooltip, {
91
- title: `${(0, _string.prettyNumerical)(pct)}%`,
91
+ title: `${(0, _string.formatNumerical)(pct, _string.FORMATS.EXPONENTIAL)}%`,
92
92
  placement: "left",
93
93
  arrow: true,
94
94
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
@@ -98,7 +98,7 @@ function CategoricalItem(_ref) {
98
98
  style: {
99
99
  fontWeight: "lighter"
100
100
  },
101
- children: (0, _string.prettyNumerical)(parseInt(value_counts))
101
+ children: (0, _string.formatNumerical)(parseInt(value_counts), _string.FORMATS.EXPONENTIAL)
102
102
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
103
103
  className: "value-pct-gauge-container",
104
104
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_xCharts.Gauge, {
@@ -179,7 +179,7 @@ function CategoricalObs(_ref2) {
179
179
  value_counts: obs.value_counts[obs.values[index]],
180
180
  pct: obs.value_counts[obs.values[index]] / totalCounts * 100,
181
181
  isOmitted: _lodash.default.includes(obs.omit, obs.codes[obs.values[index]]),
182
- label: (0, _string.prettyNumerical)(obs.values[index])
182
+ label: obs.values[index]
183
183
  };
184
184
  };
185
185
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.ListGroup, {
@@ -233,14 +233,14 @@ function ObsContinuousStats(_ref3) {
233
233
  children: "Min"
234
234
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
235
235
  className: "text-end",
236
- children: (0, _string.prettyNumerical)(obs.min)
236
+ children: (0, _string.formatNumerical)(obs.min, _string.FORMATS.EXPONENTIAL)
237
237
  })]
238
238
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("tr", {
239
239
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
240
240
  children: "Max"
241
241
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
242
242
  className: "text-end",
243
- children: (0, _string.prettyNumerical)(obs.max)
243
+ children: (0, _string.formatNumerical)(obs.max, _string.FORMATS.EXPONENTIAL)
244
244
  })]
245
245
  })]
246
246
  })
@@ -254,14 +254,14 @@ function ObsContinuousStats(_ref3) {
254
254
  children: "Mean"
255
255
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
256
256
  className: "text-end",
257
- children: (0, _string.prettyNumerical)(obs.mean)
257
+ children: (0, _string.formatNumerical)(obs.mean, _string.FORMATS.EXPONENTIAL)
258
258
  })]
259
259
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("tr", {
260
260
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
261
261
  children: "Median"
262
262
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
263
263
  className: "text-end",
264
- children: (0, _string.prettyNumerical)(obs.median)
264
+ children: (0, _string.formatNumerical)(obs.median, _string.FORMATS.EXPONENTIAL)
265
265
  })]
266
266
  })]
267
267
  })
@@ -280,9 +280,9 @@ function ObsContinuousStats(_ref3) {
280
280
  },
281
281
  xAxis: {
282
282
  data: fetchedData.kde_values[0],
283
- valueFormatter: v => `${(0, _string.prettyNumerical)(v)}`
283
+ valueFormatter: v => `${(0, _string.formatNumerical)(v, _string.FORMATS.EXPONENTIAL)}`
284
284
  },
285
- valueFormatter: v => `${(0, _string.prettyNumerical)(v)}`,
285
+ valueFormatter: v => `${(0, _string.formatNumerical)(v, _string.FORMATS.EXPONENTIAL)}`,
286
286
  slotProps: {
287
287
  popper: {
288
288
  className: "feature-histogram-tooltip"
@@ -360,7 +360,7 @@ function ContinuousObs(_ref4) {
360
360
  value_counts: obs.value_counts[obs.values[index]],
361
361
  pct: obs.value_counts[obs.values[index]] / totalCounts * 100,
362
362
  isOmitted: _lodash.default.includes(obs.omit, obs.codes[obs.values[index]]),
363
- label: getContinuousLabel(obs.codes[obs.values[index]], obs.bins.binEdges)
363
+ label: isNaN(obs.values[index]) ? "NaN" : getContinuousLabel(obs.codes[obs.values[index]], obs.bins.binEdges)
364
364
  };
365
365
  };
366
366
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
@@ -160,7 +160,7 @@ function ObsColsList(_ref) {
160
160
  }
161
161
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.Accordion.Item, {
162
162
  eventKey: item.name,
163
- className: active === item.name && "cherita-accordion-active",
163
+ className: active === item.name && dataset.colorEncoding === _constants.COLOR_ENCODINGS.OBS && "cherita-accordion-active",
164
164
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Accordion.Header, {
165
165
  children: item.name
166
166
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Accordion.Body, {
@@ -43,13 +43,13 @@ function Legend(_ref) {
43
43
  children: dataset.colorEncoding === _constants.COLOR_ENCODINGS.VAR ? dataset.selectedVar?.name : dataset.selectedObs?.name
44
44
  }), spanList, /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
45
45
  className: "domain-min",
46
- children: (0, _string.prettyNumerical)(min)
46
+ children: (0, _string.formatNumerical)(min, _string.FORMATS.EXPONENTIAL)
47
47
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
48
48
  className: "domain-med",
49
- children: (0, _string.prettyNumerical)((min + max) * 0.5)
49
+ children: (0, _string.formatNumerical)((min + max) * 0.5, _string.FORMATS.EXPONENTIAL)
50
50
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
51
51
  className: "domain-max",
52
- children: (0, _string.prettyNumerical)(max)
52
+ children: (0, _string.formatNumerical)(max, _string.FORMATS.EXPONENTIAL)
53
53
  })]
54
54
  })
55
55
  });
@@ -285,7 +285,7 @@ function Scatterplot(_ref) {
285
285
  if (dataset.selectedObs.type === _constants.OBS_TYPES.CATEGORICAL) {
286
286
  inSlice &= !_lodash.default.includes(dataset.selectedObs.omit, values[index]);
287
287
  } else if (dataset.selectedObs.type === _constants.OBS_TYPES.CONTINUOUS) {
288
- if (Number.isNaN(values[index])) {
288
+ if (isNaN(values[index])) {
289
289
  inSlice &= !_lodash.default.includes(dataset.selectedObs.omit, -1);
290
290
  } else {
291
291
  inSlice &= isInBins(values[index], dataset.selectedObs.bins.binEdges, _lodash.default.without(dataset.selectedObs.omit, -1));
@@ -448,7 +448,7 @@ function Scatterplot(_ref) {
448
448
  const getLabel = function (o, v) {
449
449
  let isVar = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
450
450
  if (isVar || o.type === _constants.OBS_TYPES.CONTINUOUS) {
451
- return `${o.name}: ${(0, _string.prettyNumerical)(parseFloat(v))}`;
451
+ return `${o.name}: ${(0, _string.formatNumerical)(parseFloat(v))}`;
452
452
  } else {
453
453
  return `${o.name}: ${o.codesMap[v]}`;
454
454
  }
@@ -27,12 +27,12 @@ function Toolbox(_ref) {
27
27
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFontawesome.FontAwesomeIcon, {
28
28
  icon: _freeSolidSvgIcons.faDroplet
29
29
  }), " ", mode]
30
- }), (mode || !Number.isNaN(obsLength)) && (mode !== null && !Number.isNaN(slicedLength) && slicedLength !== obsLength ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Button.default, {
30
+ }), (mode || !isNaN(obsLength)) && (mode !== null && !isNaN(slicedLength) && slicedLength !== obsLength ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Button.default, {
31
31
  size: "sm",
32
- children: [(0, _string.prettyNumerical)(slicedLength), " out of", " ", (0, _string.prettyNumerical)(obsLength), " cells"]
32
+ children: [(0, _string.formatNumerical)(slicedLength), " out of", " ", (0, _string.formatNumerical)(obsLength), " cells"]
33
33
  }) : /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Button.default, {
34
34
  size: "sm",
35
- children: [(0, _string.prettyNumerical)(obsLength), " cells"]
35
+ children: [(0, _string.formatNumerical)(obsLength), " cells"]
36
36
  }))]
37
37
  })
38
38
  });
@@ -72,11 +72,11 @@ function VarHistogram(_ref) {
72
72
  let {
73
73
  dataIndex
74
74
  } = _ref2;
75
- return `${(0, _string.prettyNumerical)(fetchedData.hist[dataIndex])}`;
75
+ return `${(0, _string.formatNumerical)(fetchedData.hist[dataIndex])}`;
76
76
  },
77
77
  xAxis: {
78
78
  data: _lodash.default.range(fetchedData.bin_edges?.length) || null,
79
- valueFormatter: v => `Bin [${(0, _string.prettyNumerical)(fetchedData.bin_edges[v][0])}, ${(0, _string.prettyNumerical)(fetchedData.bin_edges[v][1])}${v === fetchedData.bin_edges.length - 1 ? "]" : ")"}`
79
+ valueFormatter: v => `Bin [${(0, _string.formatNumerical)(fetchedData.bin_edges[v][0], _string.FORMATS.EXPONENTIAL)}, ${(0, _string.formatNumerical)(fetchedData.bin_edges[v][1], _string.FORMATS.EXPONENTIAL)}${v === fetchedData.bin_edges.length - 1 ? "]" : ")"}`
80
80
  },
81
81
  slotProps: {
82
82
  popper: {
@@ -23,7 +23,7 @@ const interpolateColor = (color1, color2, factor) => {
23
23
  return [r, g, b];
24
24
  };
25
25
  const computeColor = (colormap, value) => {
26
- if (!colormap || Number.isNaN(value)) {
26
+ if (!colormap || isNaN(value)) {
27
27
  return [0, 0, 0, 255];
28
28
  } else if (value <= 0) {
29
29
  return parseHexColor(colormap[0]);
@@ -3,16 +3,62 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.prettyNumerical = prettyNumerical;
7
- function prettyNumerical(n) {
6
+ exports.FORMATS = void 0;
7
+ exports.formatNumerical = formatNumerical;
8
+ var _numbro = _interopRequireDefault(require("numbro"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ const FORMATS = exports.FORMATS = {
11
+ EXPONENTIAL: "exponential",
12
+ ABBREVIATION: "abbreviation",
13
+ THOUSAND: "thousand"
14
+ };
15
+ function formatThousand(n) {
8
16
  let precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
9
- if (n === 0) {
17
+ return (0, _numbro.default)(n).format({
18
+ thousandSeparated: true,
19
+ mantissa: precision,
20
+ trimMantissa: true
21
+ });
22
+ }
23
+ function formatExponential(n) {
24
+ let precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
25
+ return (0, _numbro.default)(n).format({
26
+ exponential: true,
27
+ mantissa: precision,
28
+ trimMantissa: true
29
+ });
30
+ }
31
+ function formatAbbreviation(n) {
32
+ let precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
33
+ return (0, _numbro.default)(n).format({
34
+ average: true,
35
+ mantissa: precision,
36
+ trimMantissa: true
37
+ }).toUpperCase();
38
+ }
39
+ function formatNumerical(n) {
40
+ let format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : FORMATS.THOUSAND;
41
+ let precision = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 3;
42
+ if (isNaN(n)) {
43
+ return "NaN";
44
+ } else if (n === 0) {
10
45
  return "0";
11
- } else if (n < 1 / 10 ** precision) {
12
- return n.toExponential(precision);
13
- } else {
14
- return n.toLocaleString(undefined, {
15
- maximumFractionDigits: precision
16
- });
46
+ }
47
+ switch (format) {
48
+ case FORMATS.EXPONENTIAL:
49
+ if (n < 1 / 10 ** precision || n >= 1e6) {
50
+ return formatExponential(n, precision);
51
+ } else {
52
+ return formatThousand(n, precision);
53
+ }
54
+ case FORMATS.ABBREVIATION:
55
+ if (n >= 1e6) {
56
+ return formatAbbreviation(n, precision);
57
+ } else {
58
+ return formatThousand(n, precision);
59
+ }
60
+ case FORMATS.THOUSAND:
61
+ default:
62
+ return formatThousand(n, precision);
17
63
  }
18
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haniffalab/cherita-react",
3
- "version": "0.2.0-dev.2024-11-14.065cb0d1",
3
+ "version": "0.2.0-dev.2024-12-16.f6e39628",
4
4
  "author": "",
5
5
  "license": "",
6
6
  "main": "dist/index.js",
@@ -32,6 +32,7 @@
32
32
  "deck.gl": "^8.9.19",
33
33
  "jquery": "^3.7.0",
34
34
  "nebula.gl": "^1.0.4",
35
+ "numbro": "^2.5.0",
35
36
  "plotly.js": "^2.23.2",
36
37
  "popper.js": "^1.16.1",
37
38
  "react-bootstrap": "^2.7.4",
@@ -100,5 +101,5 @@
100
101
  "url": "https://github.com/haniffalab/cherita-react/issues"
101
102
  },
102
103
  "homepage": "https://github.com/haniffalab/cherita-react#readme",
103
- "prereleaseSha": "065cb0d10bcf8f6bcbc3e3cd78b0b7adc05977ff"
104
+ "prereleaseSha": "f6e396285b478f157db2dd9d8bdd8adbaa262d4c"
104
105
  }