export class LastFuelPriceProgressHelper { static getSvgClassFromValue( minValue: number, maxValue: number, totalValue: number, isOutdated?: boolean, isTableVariation?: boolean, isCardVariation?: boolean ): string { if (isOutdated) return 'fuel-color-outdated'; // edge case: zero range in table/card context => place in the middle with color 3 if ((isTableVariation || isCardVariation) && maxValue === minValue) { return 'fuel-color-3'; } // calculate percentage of cost in relation to min and max values const percentage = ((totalValue - minValue) / (maxValue - minValue)) * 100; // ensure percentage is within the range [0, 100] const clampedPercentage = Math.min(Math.max(percentage, 0), 100); // cap the effective maximum // - 90% for card variation // - 85% for table variation // - 100% otherwise const effectiveMax = isCardVariation ? 90 : isTableVariation ? 85 : 100; const cappedPercentage = Math.min(clampedPercentage, effectiveMax); // divide into 5 equal sections relative to the effective maximum const sectionSize = effectiveMax / 5; // 17 when 85%, 20 when 100% const colorSection = Math.min( 4, Math.floor(cappedPercentage / sectionSize) ); // return the appropriate class based on the section return `fuel-color-${colorSection + 1}`; } static calculateSvgPosition( minValue: number, maxValue: number, totalValue: number, isOutdated?: boolean, isTableVariation?: boolean, isCardVariation?: boolean ): { svgPosition: number; svgClass: string } { // edge case: zero range in table/card context => place in the middle with color 3 if ((isTableVariation || isCardVariation) && maxValue === minValue) { const effectiveMax = isCardVariation ? 90 : 85; const svgPosition = effectiveMax / 2; const svgClass = isOutdated ? 'fuel-color-outdated' : 'fuel-color-3'; return { svgPosition, svgClass }; } // calculate percentage of cost in relation to min and max values const percentage = ((totalValue - minValue) / (maxValue - minValue)) * 100; // ensure percentage is within the range [0, 100] const clampedPercentage = Math.min(Math.max(percentage, 0), 100); // calculate the position; apply 3% insets only for non-table/non-card variations const effectiveMax = isCardVariation ? 90 : isTableVariation ? 85 : 100; let svgPosition: number; if (!isTableVariation && !isCardVariation) { const minInsetPercent = 3; const maxInsetPercent = 97; const insetRange = maxInsetPercent - minInsetPercent; const mappedPercent = minInsetPercent + insetRange * (clampedPercentage / 100); svgPosition = (mappedPercent / 100) * effectiveMax; // within insets } else { svgPosition = (clampedPercentage / 100) * effectiveMax; // direct mapping for table/card } // use the utility function to get the appropriate class for the SVG based on the value range const svgClass = this.getSvgClassFromValue( minValue, maxValue, totalValue, isOutdated, isTableVariation, isCardVariation ); return { svgPosition, svgClass }; } }