@reekon-tools/boldr-utils 1.6.2 → 1.6.4
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/index.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export { parseMeasurement } from './utils/parseMeasurement.js';
|
|
|
5
5
|
export { useParseMeasurement } from './hooks/useParseMeasurement.js';
|
|
6
6
|
export * from './types/firestore.js';
|
|
7
7
|
export * from './types/layout.js';
|
|
8
|
-
export { getToleranceColor, calculateDeviationPercentage, isWithinTolerance, generateToleranceGradient, createDefaultToleranceThresholds, DEFAULT_TOLERANCE_COLORS, type ToleranceThreshold, type ToleranceConfig, } from './utils/tolerance.js';
|
|
8
|
+
export { getToleranceColor, getToleranceSecondaryColor, calculateDeviationPercentage, isWithinTolerance, generateToleranceGradient, createDefaultToleranceThresholds, DEFAULT_TOLERANCE_COLORS, DEFAULT_TOLERANCE_SECONDARY_COLORS, type ToleranceThreshold, type ToleranceConfig, } from './utils/tolerance.js';
|
package/dist/index.js
CHANGED
|
@@ -5,4 +5,4 @@ export { parseMeasurement } from './utils/parseMeasurement.js';
|
|
|
5
5
|
export { useParseMeasurement } from './hooks/useParseMeasurement.js';
|
|
6
6
|
export * from './types/firestore.js';
|
|
7
7
|
export * from './types/layout.js';
|
|
8
|
-
export { getToleranceColor, calculateDeviationPercentage, isWithinTolerance, generateToleranceGradient, createDefaultToleranceThresholds, DEFAULT_TOLERANCE_COLORS, } from './utils/tolerance.js';
|
|
8
|
+
export { getToleranceColor, getToleranceSecondaryColor, calculateDeviationPercentage, isWithinTolerance, generateToleranceGradient, createDefaultToleranceThresholds, DEFAULT_TOLERANCE_COLORS, DEFAULT_TOLERANCE_SECONDARY_COLORS, } from './utils/tolerance.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DecimalTolerance, FractionalTolerance, Units } from '../types/firestore.js';
|
|
2
|
+
export declare const roundToT1Values: (value: number, u: Units) => number;
|
|
2
3
|
export declare const convertMicrometers: (micrometers: number | null | undefined, unit: Units, fractionalTolerance: FractionalTolerance, decimalTolerance: DecimalTolerance) => {
|
|
3
4
|
value: string;
|
|
4
5
|
unit: string;
|
|
@@ -1,12 +1,35 @@
|
|
|
1
1
|
import { Units, convertUnitsToReadable, } from '../types/firestore.js';
|
|
2
2
|
import { create, all } from 'mathjs';
|
|
3
3
|
const math = create(all);
|
|
4
|
+
// The T1 rounds differently depending on the selected measurement unit.
|
|
5
|
+
// This function mirrors the rounding behavior implemented on the firmware.
|
|
6
|
+
// The value being rounded is in microns.
|
|
7
|
+
export const roundToT1Values = (value, u) => {
|
|
8
|
+
switch (u) {
|
|
9
|
+
case Units.Millimeters:
|
|
10
|
+
case Units.Centimeters:
|
|
11
|
+
return Math.round(value / 500) * 500;
|
|
12
|
+
case Units.Meters:
|
|
13
|
+
return Math.round(value / 1000) * 1000;
|
|
14
|
+
case Units.Inches:
|
|
15
|
+
return Math.round(value / 508) * 508;
|
|
16
|
+
case Units.Feet:
|
|
17
|
+
return Math.round(value / 304.8) * 304.8;
|
|
18
|
+
case Units.FeetInchesDecimal:
|
|
19
|
+
return Math.round(value / 508) * 508;
|
|
20
|
+
case Units.FractionalInches:
|
|
21
|
+
case Units.FeetInchesFractional:
|
|
22
|
+
return value;
|
|
23
|
+
default:
|
|
24
|
+
return Math.round(value / 500) * 500;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
4
27
|
export const convertMicrometers = (micrometers, unit, fractionalTolerance, decimalTolerance) => {
|
|
5
28
|
if (micrometers == null || isNaN(micrometers)) {
|
|
6
29
|
return { value: 'NaN', unit: '' };
|
|
7
30
|
}
|
|
8
31
|
try {
|
|
9
|
-
const converted = math.unit(micrometers, 'um');
|
|
32
|
+
const converted = math.unit(roundToT1Values(micrometers, unit), 'um');
|
|
10
33
|
let value = 0;
|
|
11
34
|
let displayUnit = '';
|
|
12
35
|
switch (unit) {
|
|
@@ -16,6 +16,10 @@ export declare const DEFAULT_TOLERANCE_COLORS: {
|
|
|
16
16
|
readonly IN_TOLERANCE: "#22c55e";
|
|
17
17
|
readonly OUT_OF_TOLERANCE: "#ef4444";
|
|
18
18
|
};
|
|
19
|
+
export declare const DEFAULT_TOLERANCE_SECONDARY_COLORS: {
|
|
20
|
+
readonly IN_TOLERANCE: "#268F0A";
|
|
21
|
+
readonly OUT_OF_TOLERANCE: "#A91507";
|
|
22
|
+
};
|
|
19
23
|
/**
|
|
20
24
|
* Calculates the appropriate color for a measurement based on tolerance thresholds
|
|
21
25
|
*
|
|
@@ -27,6 +31,17 @@ export declare const DEFAULT_TOLERANCE_COLORS: {
|
|
|
27
31
|
* @returns The color hex string to use for the measurement
|
|
28
32
|
*/
|
|
29
33
|
export declare function getToleranceColor(actualValue: number, target: number, min: number, max: number, toleranceConfig?: ToleranceConfig | null): string;
|
|
34
|
+
/**
|
|
35
|
+
* Calculates the appropriate color for a measurement based on tolerance thresholds
|
|
36
|
+
*
|
|
37
|
+
* @param actualValue - The measured value
|
|
38
|
+
* @param target - The target/nominal value
|
|
39
|
+
* @param min - The minimum acceptable value (used as negative tolerance from target)
|
|
40
|
+
* @param max - The maximum acceptable value (used as positive tolerance from target)
|
|
41
|
+
* @param toleranceConfig - Optional tolerance configuration with custom thresholds
|
|
42
|
+
* @returns The color hex string to use for the measurement
|
|
43
|
+
*/
|
|
44
|
+
export declare function getToleranceSecondaryColor(actualValue: number, target: number, min: number, max: number, toleranceConfig?: ToleranceConfig | null): string;
|
|
30
45
|
/**
|
|
31
46
|
* Calculates the deviation percentage of a measurement from its target
|
|
32
47
|
*
|
package/dist/utils/tolerance.js
CHANGED
|
@@ -5,6 +5,10 @@ export const DEFAULT_TOLERANCE_COLORS = {
|
|
|
5
5
|
IN_TOLERANCE: '#22c55e', // Green
|
|
6
6
|
OUT_OF_TOLERANCE: '#ef4444', // Red
|
|
7
7
|
};
|
|
8
|
+
export const DEFAULT_TOLERANCE_SECONDARY_COLORS = {
|
|
9
|
+
IN_TOLERANCE: '#268F0A', // Green
|
|
10
|
+
OUT_OF_TOLERANCE: '#A91507', // Red
|
|
11
|
+
};
|
|
8
12
|
/**
|
|
9
13
|
* Calculates the appropriate color for a measurement based on tolerance thresholds
|
|
10
14
|
*
|
|
@@ -42,6 +46,43 @@ export function getToleranceColor(actualValue, target, min, max, toleranceConfig
|
|
|
42
46
|
}
|
|
43
47
|
return applicableColor;
|
|
44
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Calculates the appropriate color for a measurement based on tolerance thresholds
|
|
51
|
+
*
|
|
52
|
+
* @param actualValue - The measured value
|
|
53
|
+
* @param target - The target/nominal value
|
|
54
|
+
* @param min - The minimum acceptable value (used as negative tolerance from target)
|
|
55
|
+
* @param max - The maximum acceptable value (used as positive tolerance from target)
|
|
56
|
+
* @param toleranceConfig - Optional tolerance configuration with custom thresholds
|
|
57
|
+
* @returns The color hex string to use for the measurement
|
|
58
|
+
*/
|
|
59
|
+
export function getToleranceSecondaryColor(actualValue, target, min, max, toleranceConfig) {
|
|
60
|
+
// If no tolerance config provided, use simple green/red logic
|
|
61
|
+
if (!toleranceConfig?.thresholds || toleranceConfig.thresholds.length === 0) {
|
|
62
|
+
const isWithinTolerance = actualValue >= target - min && actualValue <= target + max;
|
|
63
|
+
return isWithinTolerance
|
|
64
|
+
? DEFAULT_TOLERANCE_SECONDARY_COLORS.IN_TOLERANCE
|
|
65
|
+
: DEFAULT_TOLERANCE_SECONDARY_COLORS.OUT_OF_TOLERANCE;
|
|
66
|
+
}
|
|
67
|
+
// Calculate deviation percentage
|
|
68
|
+
const deviation = Math.abs(actualValue - target);
|
|
69
|
+
const toleranceRange = max + min; // Fixed: total tolerance range
|
|
70
|
+
const deviationPercentage = toleranceRange > 0 ? (deviation / toleranceRange) * 100 : 0;
|
|
71
|
+
// Sort thresholds by percentage to ensure correct evaluation order
|
|
72
|
+
const sortedThresholds = toleranceConfig.thresholds.sort((a, b) => a.percentage - b.percentage);
|
|
73
|
+
// If deviation is below the first threshold, it's in tolerance (green)
|
|
74
|
+
if (deviationPercentage < sortedThresholds[0].percentage) {
|
|
75
|
+
return DEFAULT_TOLERANCE_SECONDARY_COLORS.IN_TOLERANCE;
|
|
76
|
+
}
|
|
77
|
+
// Find the highest threshold that the deviation exceeds
|
|
78
|
+
let applicableColor = sortedThresholds[0].color;
|
|
79
|
+
for (const threshold of sortedThresholds) {
|
|
80
|
+
if (deviationPercentage >= threshold.percentage) {
|
|
81
|
+
applicableColor = threshold.color;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return applicableColor;
|
|
85
|
+
}
|
|
45
86
|
/**
|
|
46
87
|
* Calculates the deviation percentage of a measurement from its target
|
|
47
88
|
*
|