@cornerstonejs/tools 1.42.0 → 1.42.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/dist/cjs/eventListeners/segmentation/imageChangeEventListener.js +18 -5
- package/dist/cjs/eventListeners/segmentation/imageChangeEventListener.js.map +1 -1
- package/dist/cjs/stateManagement/segmentation/convertStackToVolumeSegmentation.d.ts +10 -0
- package/dist/cjs/stateManagement/segmentation/convertStackToVolumeSegmentation.js +65 -0
- package/dist/cjs/stateManagement/segmentation/convertStackToVolumeSegmentation.js.map +1 -0
- package/dist/cjs/stateManagement/segmentation/convertVolumeToStackSegmentation.d.ts +8 -0
- package/dist/cjs/stateManagement/segmentation/convertVolumeToStackSegmentation.js +92 -0
- package/dist/cjs/stateManagement/segmentation/convertVolumeToStackSegmentation.js.map +1 -0
- package/dist/cjs/stateManagement/segmentation/index.d.ts +3 -1
- package/dist/cjs/stateManagement/segmentation/index.js +5 -1
- package/dist/cjs/stateManagement/segmentation/index.js.map +1 -1
- package/dist/cjs/stateManagement/segmentation/segmentationState.d.ts +2 -1
- package/dist/cjs/stateManagement/segmentation/segmentationState.js +8 -1
- package/dist/cjs/stateManagement/segmentation/segmentationState.js.map +1 -1
- package/dist/cjs/store/ToolGroupManager/ToolGroup.js +3 -0
- package/dist/cjs/store/ToolGroupManager/ToolGroup.js.map +1 -1
- package/dist/cjs/tools/annotation/AngleTool.js +2 -2
- package/dist/cjs/tools/annotation/AngleTool.js.map +1 -1
- package/dist/cjs/tools/annotation/BidirectionalTool.js +2 -2
- package/dist/cjs/tools/annotation/BidirectionalTool.js.map +1 -1
- package/dist/cjs/tools/annotation/CircleROITool.js +8 -8
- package/dist/cjs/tools/annotation/CircleROITool.js.map +1 -1
- package/dist/cjs/tools/annotation/EllipticalROITool.js +7 -7
- package/dist/cjs/tools/annotation/EllipticalROITool.js.map +1 -1
- package/dist/cjs/tools/annotation/LengthTool.js +2 -2
- package/dist/cjs/tools/annotation/LengthTool.js.map +1 -1
- package/dist/cjs/tools/annotation/PlanarFreehandROITool.js +5 -5
- package/dist/cjs/tools/annotation/PlanarFreehandROITool.js.map +1 -1
- package/dist/cjs/tools/annotation/ProbeTool.js +3 -3
- package/dist/cjs/tools/annotation/ProbeTool.js.map +1 -1
- package/dist/cjs/tools/annotation/RectangleROITool.js +7 -7
- package/dist/cjs/tools/annotation/RectangleROITool.js.map +1 -1
- package/dist/cjs/tools/displayTools/Labelmap/labelmapDisplay.js +10 -0
- package/dist/cjs/tools/displayTools/Labelmap/labelmapDisplay.js.map +1 -1
- package/dist/cjs/tools/segmentation/BrushTool.js +8 -4
- package/dist/cjs/tools/segmentation/BrushTool.js.map +1 -1
- package/dist/cjs/tools/segmentation/strategies/fillCircle.js +4 -6
- package/dist/cjs/tools/segmentation/strategies/fillCircle.js.map +1 -1
- package/dist/cjs/tools/segmentation/strategies/utils/isWithinThreshold.d.ts +1 -1
- package/dist/cjs/tools/segmentation/strategies/utils/isWithinThreshold.js.map +1 -1
- package/dist/cjs/utilities/index.d.ts +2 -1
- package/dist/cjs/utilities/index.js +5 -4
- package/dist/cjs/utilities/index.js.map +1 -1
- package/dist/cjs/utilities/segmentation/createImageIdReferenceMap.d.ts +2 -0
- package/dist/cjs/utilities/segmentation/createImageIdReferenceMap.js +11 -0
- package/dist/cjs/utilities/segmentation/createImageIdReferenceMap.js.map +1 -0
- package/dist/cjs/utilities/segmentation/index.d.ts +2 -1
- package/dist/cjs/utilities/segmentation/index.js +3 -1
- package/dist/cjs/utilities/segmentation/index.js.map +1 -1
- package/dist/cjs/utilities/segmentation/thresholdSegmentationByRange.js.map +1 -1
- package/dist/cjs/utilities/segmentation/triggerSegmentationRender.js +8 -4
- package/dist/cjs/utilities/segmentation/triggerSegmentationRender.js.map +1 -1
- package/dist/cjs/utilities/stackPrefetch/stackContextPrefetch.js +2 -5
- package/dist/cjs/utilities/stackPrefetch/stackContextPrefetch.js.map +1 -1
- package/dist/cjs/utilities/stackPrefetch/stackPrefetchUtils.js +2 -1
- package/dist/cjs/utilities/stackPrefetch/stackPrefetchUtils.js.map +1 -1
- package/dist/esm/eventListeners/segmentation/imageChangeEventListener.js +18 -5
- package/dist/esm/eventListeners/segmentation/imageChangeEventListener.js.map +1 -1
- package/dist/esm/stateManagement/segmentation/convertStackToVolumeSegmentation.js +47 -0
- package/dist/esm/stateManagement/segmentation/convertStackToVolumeSegmentation.js.map +1 -0
- package/dist/esm/stateManagement/segmentation/convertVolumeToStackSegmentation.js +72 -0
- package/dist/esm/stateManagement/segmentation/convertVolumeToStackSegmentation.js.map +1 -0
- package/dist/esm/stateManagement/segmentation/index.js +3 -1
- package/dist/esm/stateManagement/segmentation/index.js.map +1 -1
- package/dist/esm/stateManagement/segmentation/segmentationState.js +7 -1
- package/dist/esm/stateManagement/segmentation/segmentationState.js.map +1 -1
- package/dist/esm/store/ToolGroupManager/ToolGroup.js +3 -0
- package/dist/esm/store/ToolGroupManager/ToolGroup.js.map +1 -1
- package/dist/esm/tools/annotation/AngleTool.js +1 -1
- package/dist/esm/tools/annotation/AngleTool.js.map +1 -1
- package/dist/esm/tools/annotation/BidirectionalTool.js +1 -1
- package/dist/esm/tools/annotation/BidirectionalTool.js.map +1 -1
- package/dist/esm/tools/annotation/CircleROITool.js +1 -1
- package/dist/esm/tools/annotation/CircleROITool.js.map +1 -1
- package/dist/esm/tools/annotation/EllipticalROITool.js +1 -1
- package/dist/esm/tools/annotation/EllipticalROITool.js.map +1 -1
- package/dist/esm/tools/annotation/LengthTool.js +1 -1
- package/dist/esm/tools/annotation/LengthTool.js.map +1 -1
- package/dist/esm/tools/annotation/PlanarFreehandROITool.js +1 -1
- package/dist/esm/tools/annotation/PlanarFreehandROITool.js.map +1 -1
- package/dist/esm/tools/annotation/ProbeTool.js +1 -1
- package/dist/esm/tools/annotation/ProbeTool.js.map +1 -1
- package/dist/esm/tools/annotation/RectangleROITool.js +1 -1
- package/dist/esm/tools/annotation/RectangleROITool.js.map +1 -1
- package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js +11 -1
- package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js.map +1 -1
- package/dist/esm/tools/segmentation/BrushTool.js +8 -4
- package/dist/esm/tools/segmentation/BrushTool.js.map +1 -1
- package/dist/esm/tools/segmentation/strategies/fillCircle.js +4 -6
- package/dist/esm/tools/segmentation/strategies/fillCircle.js.map +1 -1
- package/dist/esm/tools/segmentation/strategies/utils/isWithinThreshold.js.map +1 -1
- package/dist/esm/utilities/index.js +2 -1
- package/dist/esm/utilities/index.js.map +1 -1
- package/dist/esm/utilities/segmentation/createImageIdReferenceMap.js +8 -0
- package/dist/esm/utilities/segmentation/createImageIdReferenceMap.js.map +1 -0
- package/dist/esm/utilities/segmentation/index.js +2 -1
- package/dist/esm/utilities/segmentation/index.js.map +1 -1
- package/dist/esm/utilities/segmentation/thresholdSegmentationByRange.js.map +1 -1
- package/dist/esm/utilities/segmentation/triggerSegmentationRender.js +8 -4
- package/dist/esm/utilities/segmentation/triggerSegmentationRender.js.map +1 -1
- package/dist/esm/utilities/stackPrefetch/stackContextPrefetch.js +1 -1
- package/dist/esm/utilities/stackPrefetch/stackContextPrefetch.js.map +1 -1
- package/dist/esm/utilities/stackPrefetch/stackPrefetchUtils.js +2 -1
- package/dist/esm/utilities/stackPrefetch/stackPrefetchUtils.js.map +1 -1
- package/dist/types/eventListeners/segmentation/imageChangeEventListener.d.ts.map +1 -1
- package/dist/types/stateManagement/segmentation/convertStackToVolumeSegmentation.d.ts +11 -0
- package/dist/types/stateManagement/segmentation/convertStackToVolumeSegmentation.d.ts.map +1 -0
- package/dist/types/stateManagement/segmentation/convertVolumeToStackSegmentation.d.ts +9 -0
- package/dist/types/stateManagement/segmentation/convertVolumeToStackSegmentation.d.ts.map +1 -0
- package/dist/types/stateManagement/segmentation/index.d.ts +3 -1
- package/dist/types/stateManagement/segmentation/index.d.ts.map +1 -1
- package/dist/types/stateManagement/segmentation/segmentationState.d.ts +2 -1
- package/dist/types/stateManagement/segmentation/segmentationState.d.ts.map +1 -1
- package/dist/types/store/ToolGroupManager/ToolGroup.d.ts.map +1 -1
- package/dist/types/tools/annotation/AngleTool.d.ts.map +1 -1
- package/dist/types/tools/annotation/PlanarFreehandROITool.d.ts.map +1 -1
- package/dist/types/tools/displayTools/Labelmap/labelmapDisplay.d.ts.map +1 -1
- package/dist/types/tools/segmentation/BrushTool.d.ts.map +1 -1
- package/dist/types/tools/segmentation/strategies/fillCircle.d.ts.map +1 -1
- package/dist/types/tools/segmentation/strategies/utils/isWithinThreshold.d.ts +1 -1
- package/dist/types/tools/segmentation/strategies/utils/isWithinThreshold.d.ts.map +1 -1
- package/dist/types/types/LabelmapTypes.d.ts.map +1 -1
- package/dist/types/utilities/index.d.ts +2 -1
- package/dist/types/utilities/index.d.ts.map +1 -1
- package/dist/types/utilities/segmentation/createImageIdReferenceMap.d.ts +3 -0
- package/dist/types/utilities/segmentation/createImageIdReferenceMap.d.ts.map +1 -0
- package/dist/types/utilities/segmentation/index.d.ts +2 -1
- package/dist/types/utilities/segmentation/index.d.ts.map +1 -1
- package/dist/types/utilities/segmentation/triggerSegmentationRender.d.ts.map +1 -1
- package/dist/types/utilities/stackPrefetch/stackPrefetchUtils.d.ts.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +3 -3
- package/src/eventListeners/segmentation/imageChangeEventListener.ts +42 -6
- package/src/stateManagement/segmentation/convertStackToVolumeSegmentation.ts +98 -0
- package/src/stateManagement/segmentation/convertVolumeToStackSegmentation.ts +153 -0
- package/src/stateManagement/segmentation/index.ts +4 -0
- package/src/stateManagement/segmentation/segmentationState.ts +17 -0
- package/src/store/ToolGroupManager/ToolGroup.ts +4 -0
- package/src/tools/annotation/AngleTool.ts +1 -2
- package/src/tools/annotation/BidirectionalTool.ts +1 -1
- package/src/tools/annotation/CircleROITool.ts +1 -1
- package/src/tools/annotation/EllipticalROITool.ts +1 -1
- package/src/tools/annotation/LengthTool.ts +1 -1
- package/src/tools/annotation/PlanarFreehandROITool.ts +1 -2
- package/src/tools/annotation/ProbeTool.ts +1 -1
- package/src/tools/annotation/RectangleROITool.ts +1 -1
- package/src/tools/displayTools/Labelmap/labelmapDisplay.ts +16 -2
- package/src/tools/segmentation/BrushTool.ts +11 -7
- package/src/tools/segmentation/strategies/fillCircle.ts +4 -7
- package/src/tools/segmentation/strategies/utils/isWithinThreshold.ts +1 -1
- package/src/types/LabelmapTypes.ts +2 -5
- package/src/utilities/index.ts +4 -1
- package/src/utilities/segmentation/createImageIdReferenceMap.ts +23 -0
- package/src/utilities/segmentation/index.ts +2 -0
- package/src/utilities/segmentation/thresholdSegmentationByRange.ts +2 -2
- package/src/utilities/segmentation/triggerSegmentationRender.ts +15 -10
- package/src/utilities/stackPrefetch/stackContextPrefetch.ts +1 -1
- package/src/utilities/stackPrefetch/stackPrefetchUtils.ts +5 -1
- package/dist/cjs/utilities/roundNumber.d.ts +0 -2
- package/dist/cjs/utilities/roundNumber.js +0 -30
- package/dist/cjs/utilities/roundNumber.js.map +0 -1
- package/dist/esm/utilities/roundNumber.js +0 -28
- package/dist/esm/utilities/roundNumber.js.map +0 -1
- package/dist/types/utilities/roundNumber.d.ts +0 -3
- package/dist/types/utilities/roundNumber.d.ts.map +0 -1
- package/src/utilities/roundNumber.ts +0 -44
|
@@ -42,11 +42,8 @@ export type LabelmapSegmentationDataVolume = {
|
|
|
42
42
|
|
|
43
43
|
export type LabelmapSegmentationDataStack = {
|
|
44
44
|
/**
|
|
45
|
-
* This is a Map from referenced imageId to the segmentation (Derived)
|
|
46
|
-
*
|
|
47
|
-
* Todo: later I guess we can have it as Record<string, metadata> where metadata
|
|
48
|
-
* can contain a derived image arbitrary information, for use cases such that the labelmap is
|
|
49
|
-
* derived from another image that is irrelevant to the current viewport.
|
|
45
|
+
* This is a Map from referenced imageId to the segmentation (Derived) imageIds (can be
|
|
46
|
+
* multiple) that are associated with it.
|
|
50
47
|
*/
|
|
51
48
|
imageIdReferenceMap: Map<string, string>;
|
|
52
49
|
};
|
package/src/utilities/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { utilities } from '@cornerstonejs/core';
|
|
2
|
+
|
|
1
3
|
import {
|
|
2
4
|
getAnnotationNearPoint,
|
|
3
5
|
getAnnotationNearPointOnEnabledElement,
|
|
@@ -21,7 +23,6 @@ import jumpToSlice from './viewport/jumpToSlice';
|
|
|
21
23
|
import pointInShapeCallback from './pointInShapeCallback';
|
|
22
24
|
import pointInSurroundingSphereCallback from './pointInSurroundingSphereCallback';
|
|
23
25
|
import scroll from './scroll';
|
|
24
|
-
import roundNumber from './roundNumber';
|
|
25
26
|
import { pointToString } from './pointToString';
|
|
26
27
|
import annotationFrameRange from './annotationFrameRange';
|
|
27
28
|
|
|
@@ -44,6 +45,8 @@ import * as dynamicVolume from './dynamicVolume';
|
|
|
44
45
|
import * as polyDataUtils from './polyData/utils';
|
|
45
46
|
import * as voi from './voi';
|
|
46
47
|
|
|
48
|
+
const roundNumber = utilities.roundNumber;
|
|
49
|
+
|
|
47
50
|
// Events
|
|
48
51
|
import { triggerEvent } from '@cornerstonejs/core';
|
|
49
52
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a map that associates each imageId with a set of segmentation imageIds.
|
|
3
|
+
* Note that this function assumes that the imageIds and segmentationImageIds arrays
|
|
4
|
+
* are the same length and same order.
|
|
5
|
+
*
|
|
6
|
+
* @param imageIdsArray - An array of imageIds.
|
|
7
|
+
* @param segmentationImageIds - An array of segmentation imageIds.
|
|
8
|
+
* @returns A map that maps each imageId to a set of segmentation imageIds.
|
|
9
|
+
*/
|
|
10
|
+
function createImageIdReferenceMap(
|
|
11
|
+
imageIdsArray: string[],
|
|
12
|
+
segmentationImageIds: string[]
|
|
13
|
+
): Map<string, string> {
|
|
14
|
+
const imageIdReferenceMap = new Map<string, string>(
|
|
15
|
+
imageIdsArray.map((imageId, index) => {
|
|
16
|
+
return [imageId, segmentationImageIds[index]];
|
|
17
|
+
})
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
return imageIdReferenceMap;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { createImageIdReferenceMap };
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
setBrushThresholdForToolGroup,
|
|
16
16
|
} from './brushThresholdForToolGroup';
|
|
17
17
|
import thresholdSegmentationByRange from './thresholdSegmentationByRange';
|
|
18
|
+
import { createImageIdReferenceMap } from './createImageIdReferenceMap';
|
|
18
19
|
import contourAndFindLargestBidirectional from './contourAndFindLargestBidirectional';
|
|
19
20
|
import createBidirectionalToolData from './createBidirectionalToolData';
|
|
20
21
|
import segmentContourAction from './segmentContourAction';
|
|
@@ -33,6 +34,7 @@ export {
|
|
|
33
34
|
getBrushThresholdForToolGroup,
|
|
34
35
|
setBrushThresholdForToolGroup,
|
|
35
36
|
thresholdSegmentationByRange,
|
|
37
|
+
createImageIdReferenceMap,
|
|
36
38
|
contourAndFindLargestBidirectional,
|
|
37
39
|
createBidirectionalToolData,
|
|
38
40
|
segmentContourAction,
|
|
@@ -64,7 +64,7 @@ function thresholdSegmentationByRange(
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
function _handleDifferentSizeVolume(
|
|
67
|
-
scalarData: Types.
|
|
67
|
+
scalarData: Types.PixelDataTypedArray,
|
|
68
68
|
segmentationIndex: number,
|
|
69
69
|
volumeInfo: any,
|
|
70
70
|
volumeInfoList: any,
|
|
@@ -112,7 +112,7 @@ function _handleDifferentSizeVolume(
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
function _handleSameSizeVolume(
|
|
115
|
-
scalarData: Types.
|
|
115
|
+
scalarData: Types.PixelDataTypedArray,
|
|
116
116
|
segmentationIndex: number,
|
|
117
117
|
volumeInfo: any
|
|
118
118
|
) {
|
|
@@ -113,18 +113,23 @@ class SegmentationRenderingEngine {
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
const { viewportsInfo } = toolGroup;
|
|
116
|
-
const viewports = [];
|
|
117
116
|
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
const viewports = viewportsInfo
|
|
118
|
+
.map(({ viewportId, renderingEngineId }) => {
|
|
119
|
+
const renderingEngine = getRenderingEngine(renderingEngineId);
|
|
120
120
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
if (!renderingEngine) {
|
|
122
|
+
console.warn('rendering Engine has been destroyed');
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
const viewport = renderingEngine.getViewport(viewportId);
|
|
127
|
+
|
|
128
|
+
if (viewport) {
|
|
129
|
+
return viewport;
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
.filter(Boolean);
|
|
128
133
|
|
|
129
134
|
const segmentationDisplayToolInstance = toolGroup.getToolInstance(
|
|
130
135
|
SegmentationDisplayTool.toolName
|
|
@@ -173,7 +178,7 @@ class SegmentationRenderingEngine {
|
|
|
173
178
|
viewports.forEach(({ element }) => {
|
|
174
179
|
element.addEventListener(
|
|
175
180
|
Enums.Events.IMAGE_RENDERED,
|
|
176
|
-
onSegmentationRender
|
|
181
|
+
onSegmentationRender as EventListener
|
|
177
182
|
);
|
|
178
183
|
});
|
|
179
184
|
|
|
@@ -52,9 +52,13 @@ export function getStackData(element) {
|
|
|
52
52
|
const { viewport } = enabledElement;
|
|
53
53
|
|
|
54
54
|
if (!(viewport instanceof StackViewport)) {
|
|
55
|
-
throw
|
|
55
|
+
// we shouldn't throw error here, since the viewport might have
|
|
56
|
+
// changed from stack to volume during prefetch
|
|
57
|
+
console.warn(
|
|
56
58
|
'stackPrefetch: element must be a StackViewport, VolumeViewport stackPrefetch not yet implemented'
|
|
57
59
|
);
|
|
60
|
+
|
|
61
|
+
return null;
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
return {
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function roundNumber(value, precision = 2) {
|
|
4
|
-
if (Array.isArray(value)) {
|
|
5
|
-
return value.map((v) => roundNumber(v, precision)).join(', ');
|
|
6
|
-
}
|
|
7
|
-
if (value === undefined || value === null || value === '') {
|
|
8
|
-
return 'NaN';
|
|
9
|
-
}
|
|
10
|
-
value = Number(value);
|
|
11
|
-
if (value < 0.0001) {
|
|
12
|
-
return `${value}`;
|
|
13
|
-
}
|
|
14
|
-
const fixedPrecision = value >= 100
|
|
15
|
-
? precision - 2
|
|
16
|
-
: value >= 10
|
|
17
|
-
? precision - 1
|
|
18
|
-
: value >= 1
|
|
19
|
-
? precision
|
|
20
|
-
: value >= 0.1
|
|
21
|
-
? precision + 1
|
|
22
|
-
: value >= 0.01
|
|
23
|
-
? precision + 2
|
|
24
|
-
: value >= 0.001
|
|
25
|
-
? precision + 3
|
|
26
|
-
: precision + 4;
|
|
27
|
-
return value.toFixed(fixedPrecision);
|
|
28
|
-
}
|
|
29
|
-
exports.default = roundNumber;
|
|
30
|
-
//# sourceMappingURL=roundNumber.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"roundNumber.js","sourceRoot":"","sources":["../../../src/utilities/roundNumber.ts"],"names":[],"mappings":";;AAYA,SAAS,WAAW,CAClB,KAA4C,EAC5C,SAAS,GAAG,CAAC;IAEb,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACxB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KAC/D;IACD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE,EAAE;QACzD,OAAO,KAAK,CAAC;KACd;IACD,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,IAAI,KAAK,GAAG,MAAM,EAAE;QAClB,OAAO,GAAG,KAAK,EAAE,CAAC;KACnB;IACD,MAAM,cAAc,GAClB,KAAK,IAAI,GAAG;QACV,CAAC,CAAC,SAAS,GAAG,CAAC;QACf,CAAC,CAAC,KAAK,IAAI,EAAE;YACb,CAAC,CAAC,SAAS,GAAG,CAAC;YACf,CAAC,CAAC,KAAK,IAAI,CAAC;gBACZ,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,KAAK,IAAI,GAAG;oBACd,CAAC,CAAC,SAAS,GAAG,CAAC;oBACf,CAAC,CAAC,KAAK,IAAI,IAAI;wBACf,CAAC,CAAC,SAAS,GAAG,CAAC;wBACf,CAAC,CAAC,KAAK,IAAI,KAAK;4BAChB,CAAC,CAAC,SAAS,GAAG,CAAC;4BACf,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC;IACpB,OAAO,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;AACvC,CAAC;AAED,kBAAe,WAAW,CAAC"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
function roundNumber(value, precision = 2) {
|
|
2
|
-
if (Array.isArray(value)) {
|
|
3
|
-
return value.map((v) => roundNumber(v, precision)).join(', ');
|
|
4
|
-
}
|
|
5
|
-
if (value === undefined || value === null || value === '') {
|
|
6
|
-
return 'NaN';
|
|
7
|
-
}
|
|
8
|
-
value = Number(value);
|
|
9
|
-
if (value < 0.0001) {
|
|
10
|
-
return `${value}`;
|
|
11
|
-
}
|
|
12
|
-
const fixedPrecision = value >= 100
|
|
13
|
-
? precision - 2
|
|
14
|
-
: value >= 10
|
|
15
|
-
? precision - 1
|
|
16
|
-
: value >= 1
|
|
17
|
-
? precision
|
|
18
|
-
: value >= 0.1
|
|
19
|
-
? precision + 1
|
|
20
|
-
: value >= 0.01
|
|
21
|
-
? precision + 2
|
|
22
|
-
: value >= 0.001
|
|
23
|
-
? precision + 3
|
|
24
|
-
: precision + 4;
|
|
25
|
-
return value.toFixed(fixedPrecision);
|
|
26
|
-
}
|
|
27
|
-
export default roundNumber;
|
|
28
|
-
//# sourceMappingURL=roundNumber.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"roundNumber.js","sourceRoot":"","sources":["../../../src/utilities/roundNumber.ts"],"names":[],"mappings":"AAYA,SAAS,WAAW,CAClB,KAA4C,EAC5C,SAAS,GAAG,CAAC;IAEb,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACxB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KAC/D;IACD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE,EAAE;QACzD,OAAO,KAAK,CAAC;KACd;IACD,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,IAAI,KAAK,GAAG,MAAM,EAAE;QAClB,OAAO,GAAG,KAAK,EAAE,CAAC;KACnB;IACD,MAAM,cAAc,GAClB,KAAK,IAAI,GAAG;QACV,CAAC,CAAC,SAAS,GAAG,CAAC;QACf,CAAC,CAAC,KAAK,IAAI,EAAE;YACb,CAAC,CAAC,SAAS,GAAG,CAAC;YACf,CAAC,CAAC,KAAK,IAAI,CAAC;gBACZ,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,KAAK,IAAI,GAAG;oBACd,CAAC,CAAC,SAAS,GAAG,CAAC;oBACf,CAAC,CAAC,KAAK,IAAI,IAAI;wBACf,CAAC,CAAC,SAAS,GAAG,CAAC;wBACf,CAAC,CAAC,KAAK,IAAI,KAAK;4BAChB,CAAC,CAAC,SAAS,GAAG,CAAC;4BACf,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC;IACpB,OAAO,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;AACvC,CAAC;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"roundNumber.d.ts","sourceRoot":"","sources":["../../../src/utilities/roundNumber.ts"],"names":[],"mappings":"AAYA,iBAAS,WAAW,CAClB,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,EAC5C,SAAS,SAAI,GACZ,MAAM,CA0BR;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Truncates decimal points to that there is at least 1+precision significant
|
|
3
|
-
* digits.
|
|
4
|
-
*
|
|
5
|
-
* For example, with the default precision 2 (3 significant digits)
|
|
6
|
-
* * Values larger than 100 show no information after the decimal point
|
|
7
|
-
* * Values between 10 and 99 show 1 decimal point
|
|
8
|
-
* * Values between 1 and 9 show 2 decimal points
|
|
9
|
-
*
|
|
10
|
-
* @param value - to return a fixed measurement value from
|
|
11
|
-
* @param precision - defining how many digits after 1..9 are desired
|
|
12
|
-
*/
|
|
13
|
-
function roundNumber(
|
|
14
|
-
value: string | number | (string | number)[],
|
|
15
|
-
precision = 2
|
|
16
|
-
): string {
|
|
17
|
-
if (Array.isArray(value)) {
|
|
18
|
-
return value.map((v) => roundNumber(v, precision)).join(', ');
|
|
19
|
-
}
|
|
20
|
-
if (value === undefined || value === null || value === '') {
|
|
21
|
-
return 'NaN';
|
|
22
|
-
}
|
|
23
|
-
value = Number(value);
|
|
24
|
-
if (value < 0.0001) {
|
|
25
|
-
return `${value}`;
|
|
26
|
-
}
|
|
27
|
-
const fixedPrecision =
|
|
28
|
-
value >= 100
|
|
29
|
-
? precision - 2
|
|
30
|
-
: value >= 10
|
|
31
|
-
? precision - 1
|
|
32
|
-
: value >= 1
|
|
33
|
-
? precision
|
|
34
|
-
: value >= 0.1
|
|
35
|
-
? precision + 1
|
|
36
|
-
: value >= 0.01
|
|
37
|
-
? precision + 2
|
|
38
|
-
: value >= 0.001
|
|
39
|
-
? precision + 3
|
|
40
|
-
: precision + 4;
|
|
41
|
-
return value.toFixed(fixedPrecision);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export default roundNumber;
|