From 02502ec2af88186d0db68f496f8c52ae1fd43e60 Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Tue, 28 Nov 2023 17:49:44 -0300 Subject: [PATCH] Use auto-calculated precision instead of custom fractional digits in the `VeryGenericIndicator` --- src/assets/defaults.ts | 11 ---------- .../mini-widgets/VeryGenericIndicator.vue | 20 +++++++++---------- src/types/genericIndicator.ts | 12 ----------- 3 files changed, 9 insertions(+), 34 deletions(-) diff --git a/src/assets/defaults.ts b/src/assets/defaults.ts index 92afe638b..b10fe7bed 100644 --- a/src/assets/defaults.ts +++ b/src/assets/defaults.ts @@ -94,7 +94,6 @@ export const widgetProfiles: Profile[] = [ options: { displayName: 'Pilot Gain', variableName: 'PilotGain', - fractionalDigits: 1, iconName: 'mdi-account-hard-hat', variableUnit: '%', variableMultiplier: 100, @@ -107,7 +106,6 @@ export const widgetProfiles: Profile[] = [ options: { displayName: 'Lights (1)', variableName: 'Lights1', - fractionalDigits: 1, iconName: 'mdi-flashlight', variableUnit: '%', variableMultiplier: 100, @@ -120,7 +118,6 @@ export const widgetProfiles: Profile[] = [ options: { displayName: 'Cam Tilt', variableName: 'CamTilt', - fractionalDigits: 1, iconName: 'mdi-camera-retake', variableUnit: '%', variableMultiplier: 100, @@ -144,7 +141,6 @@ export const widgetProfiles: Profile[] = [ options: { displayName: 'Water Temp', variableName: 'SCALED_PRESSURE2.temperature', - fractionalDigits: 1, iconName: 'mdi-thermometer', variableUnit: '°C', variableMultiplier: '.01', @@ -267,7 +263,6 @@ export const widgetProfiles: Profile[] = [ options: { displayName: 'Pilot Gain', variableName: 'PilotGain', - fractionalDigits: 1, iconName: 'mdi-account-hard-hat', variableUnit: '%', variableMultiplier: 100, @@ -280,7 +275,6 @@ export const widgetProfiles: Profile[] = [ options: { displayName: 'Lights (1)', variableName: 'Lights1', - fractionalDigits: 1, iconName: 'mdi-flashlight', variableUnit: '%', variableMultiplier: 100, @@ -293,7 +287,6 @@ export const widgetProfiles: Profile[] = [ options: { displayName: 'Cam Tilt', variableName: 'CamTilt', - fractionalDigits: 1, iconName: 'mdi-camera-retake', variableUnit: '%', variableMultiplier: 100, @@ -438,7 +431,6 @@ export const widgetProfiles: Profile[] = [ options: { displayName: 'Pilot Gain', variableName: 'PilotGain', - fractionalDigits: 1, iconName: 'mdi-account-hard-hat', variableUnit: '%', variableMultiplier: 100, @@ -451,7 +443,6 @@ export const widgetProfiles: Profile[] = [ options: { displayName: 'Lights (1)', variableName: 'Lights1', - fractionalDigits: 1, iconName: 'mdi-flashlight', variableUnit: '%', variableMultiplier: 100, @@ -464,7 +455,6 @@ export const widgetProfiles: Profile[] = [ options: { displayName: 'Cam Tilt', variableName: 'CamTilt', - fractionalDigits: 1, iconName: 'mdi-camera-retake', variableUnit: '%', variableMultiplier: 100, @@ -488,7 +478,6 @@ export const widgetProfiles: Profile[] = [ options: { displayName: 'Water Temp', variableName: 'SCALED_PRESSURE2.temperature', - fractionalDigits: 1, iconName: 'mdi-thermometer', variableUnit: '°C', variableMultiplier: '.01', diff --git a/src/components/mini-widgets/VeryGenericIndicator.vue b/src/components/mini-widgets/VeryGenericIndicator.vue index 18f56af94..255784698 100644 --- a/src/components/mini-widgets/VeryGenericIndicator.vue +++ b/src/components/mini-widgets/VeryGenericIndicator.vue @@ -40,10 +40,6 @@ -
- Fractional digits - -
Unit @@ -140,7 +136,6 @@ onBeforeMount(() => { Object.assign(miniWidget.value.options, { displayName: '', variableName: '', - fractionalDigits: 1, iconName: 'mdi-help-box', variableUnit: '%', variableMultiplier: 1, @@ -155,14 +150,17 @@ onBeforeMount(() => { const store = useMainVehicleStore() const currentState = ref(0) + +const finalValue = computed(() => Number(miniWidget.value.options.variableMultiplier) * Number(currentState.value)) const parsedState = computed(() => { - if (currentState.value !== undefined) { - return round( - Number(miniWidget.value.options.variableMultiplier) * Number(currentState.value), - miniWidget.value.options.fractionalDigits as number - ).toFixed(miniWidget.value.options.fractionalDigits as number) + if (currentState.value === undefined) { + return '--' } - return '--' + const value = finalValue.value + if (value < 1) return value.toFixed(2) + if (value >= 1 && value < 100) return value.toFixed(1) + if (value >= 10000) return `${(value / 10000).toFixed(0)}k` + return value.toFixed(0) }) const updateVariableState = (): void => { diff --git a/src/types/genericIndicator.ts b/src/types/genericIndicator.ts index 5ca6913a5..00b136d56 100644 --- a/src/types/genericIndicator.ts +++ b/src/types/genericIndicator.ts @@ -18,10 +18,6 @@ export interface VeryGenericIndicatorPreset { * Symbols representing the unit system of the variable */ variableUnit: string - /** - * Number of digits to be displayed after the decimal separator (usually dot) - */ - fractionalDigits: number /** * Value that multiplies the original value to bring it to a representative unit system */ @@ -34,7 +30,6 @@ export const veryGenericIndicatorPresets: VeryGenericIndicatorPreset[] = [ variableName: 'CamTilt', iconName: 'mdi-camera-retake', variableUnit: '%', - fractionalDigits: 0, variableMultiplier: 100, }, { @@ -42,7 +37,6 @@ export const veryGenericIndicatorPresets: VeryGenericIndicatorPreset[] = [ variableName: 'CamPan', iconName: 'mdi-camera-retake', variableUnit: '%', - fractionalDigits: 0, variableMultiplier: 100, }, { @@ -50,7 +44,6 @@ export const veryGenericIndicatorPresets: VeryGenericIndicatorPreset[] = [ variableName: 'TetherTrn', iconName: 'mdi-horizontal-rotate-clockwise', variableUnit: 'x', - fractionalDigits: 0, variableMultiplier: 100, }, { @@ -58,7 +51,6 @@ export const veryGenericIndicatorPresets: VeryGenericIndicatorPreset[] = [ variableName: 'Lights1', iconName: 'mdi-flashlight', variableUnit: '%', - fractionalDigits: 0, variableMultiplier: 100, }, { @@ -66,7 +58,6 @@ export const veryGenericIndicatorPresets: VeryGenericIndicatorPreset[] = [ variableName: 'Lights2', iconName: 'mdi-flashlight', variableUnit: '%', - fractionalDigits: 0, variableMultiplier: 100, }, { @@ -74,7 +65,6 @@ export const veryGenericIndicatorPresets: VeryGenericIndicatorPreset[] = [ variableName: 'PilotGain', iconName: 'mdi-account-hard-hat', variableUnit: '%', - fractionalDigits: 0, variableMultiplier: 100, }, { @@ -82,7 +72,6 @@ export const veryGenericIndicatorPresets: VeryGenericIndicatorPreset[] = [ variableName: 'InputHold', iconName: 'mdi-gesture-tap-hold', variableUnit: '', - fractionalDigits: 0, variableMultiplier: 1, }, { @@ -90,7 +79,6 @@ export const veryGenericIndicatorPresets: VeryGenericIndicatorPreset[] = [ variableName: 'RollPitch', iconName: 'mdi-controller', variableUnit: '', - fractionalDigits: 0, variableMultiplier: 1, }, ]