@reekon-tools/boldr-utils 1.6.3 → 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';
@@ -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
  *
@@ -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
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reekon-tools/boldr-utils",
3
- "version": "1.6.3",
3
+ "version": "1.6.4",
4
4
  "description": "Shared utilities for formulas and measurement conversion used in Reekon apps",
5
5
  "author": "REEKON Tools",
6
6
  "license": "MIT",