diff --git a/Apps/RuuviStation/Sources/Classes/Presentation/Modules/Dashboard/Charts/View/UI/TagChartsMarkerView.swift b/Apps/RuuviStation/Sources/Classes/Presentation/Modules/Dashboard/Charts/View/UI/TagChartsMarkerView.swift index 5527aa8aa..0d7e5791c 100644 --- a/Apps/RuuviStation/Sources/Classes/Presentation/Modules/Dashboard/Charts/View/UI/TagChartsMarkerView.swift +++ b/Apps/RuuviStation/Sources/Classes/Presentation/Modules/Dashboard/Charts/View/UI/TagChartsMarkerView.swift @@ -104,17 +104,7 @@ class TagChartsMarkerView: MarkerImage { } override func refreshContent(entry: ChartDataEntry, highlight _: Highlight) { - var value = "" - switch type { - case .temperature: - value = measurementService.stringWithoutSign(temperature: entry.y) - case .humidity: - value = measurementService.stringWithoutSign(humidity: entry.y) - case .pressure: - value = measurementService.stringWithoutSign(pressure: entry.y) - default: break - } - + let value = GlobalHelpers().formattedString(from: entry.y.round(to: 2)) labelText = value + " " + unit + "\n" + AppDateFormatter.shared.graphMarkerDateString(from: entry.x) diff --git a/Apps/RuuviStation/Sources/Classes/Presentation/Modules/Dashboard/Charts/View/UI/TagChartsView.swift b/Apps/RuuviStation/Sources/Classes/Presentation/Modules/Dashboard/Charts/View/UI/TagChartsView.swift index 69d225a08..709e6608e 100644 --- a/Apps/RuuviStation/Sources/Classes/Presentation/Modules/Dashboard/Charts/View/UI/TagChartsView.swift +++ b/Apps/RuuviStation/Sources/Classes/Presentation/Modules/Dashboard/Charts/View/UI/TagChartsView.swift @@ -5,6 +5,8 @@ import RuuviOntology import RuuviService import UIKit +// swiftlint:disable file_length + protocol TagChartsViewDelegate: NSObjectProtocol { func chartDidTranslate(_ chartView: TagChartsView) func chartValueDidSelect( @@ -310,16 +312,20 @@ extension TagChartsView { min: Double, max: Double, avg: Double, - type _: MeasurementType + type: MeasurementType, + measurementService: RuuviServiceMeasurement ) { - let roundedTo = 2 - let minText = RuuviLocalization.chartStatMin + ": " + - GlobalHelpers().formattedString(from: min.round(to: roundedTo)) - let maxText = RuuviLocalization.chartStatMax + ": " + - GlobalHelpers().formattedString(from: max.round(to: roundedTo)) - let avgText = RuuviLocalization.chartStatAvg + ": " + - GlobalHelpers().formattedString(from: avg.round(to: roundedTo)) - + let ( + minText, + maxText, + avgText + ) = createMeasurementStrings( + type: type, + min: min, + max: max, + avg: avg, + measurementService: measurementService + ) chartMinMaxAvgLabel.text = minText + " " + maxText + " " + avgText } @@ -355,3 +361,72 @@ extension TagChartsView { return min(leftAxis.axisMaximum, Double(pt.y)) } } + +extension TagChartsView { + + private func createMeasurementStrings( + type: MeasurementType, + min: Double?, + max: Double?, + avg: Double?, + measurementService: RuuviServiceMeasurement + ) -> + // swiftlint:disable:next large_tuple + ( + String, + String, + String + ) { + let minValue = formattedMeasurementString( + for: type, + value: min, + measurementService: measurementService + ) + let minText = RuuviLocalization.chartStatMin + ": " + minValue + + let maxValue = formattedMeasurementString( + for: type, + value: max, + measurementService: measurementService + ) + let maxText = RuuviLocalization.chartStatMax + ": " + maxValue + + let avgValue = formattedMeasurementString( + for: type, + value: avg, + measurementService: measurementService + ) + let avgText = RuuviLocalization.chartStatAvg + ": " + avgValue + + return ( + minText, + maxText, + avgText + ) + } + + private func formattedMeasurementString( + for type: MeasurementType, + value: Double?, + measurementService: RuuviServiceMeasurement + ) -> String { + switch type { + case .temperature: + return measurementService.stringWithoutSign( + temperature: value + ) + case .humidity: + return measurementService.stringWithoutSign( + humidity: value + ) + case .pressure: + return measurementService.stringWithoutSign( + pressure: value + ) + default: + return "" + } + } +} + +// swiftlint:enable file_length diff --git a/Apps/RuuviStation/Sources/Classes/Presentation/Modules/Dashboard/Charts/View/UI/TagChartsViewController.swift b/Apps/RuuviStation/Sources/Classes/Presentation/Modules/Dashboard/Charts/View/UI/TagChartsViewController.swift index 1ccbd72de..63da2d92f 100644 --- a/Apps/RuuviStation/Sources/Classes/Presentation/Modules/Dashboard/Charts/View/UI/TagChartsViewController.swift +++ b/Apps/RuuviStation/Sources/Classes/Presentation/Modules/Dashboard/Charts/View/UI/TagChartsViewController.swift @@ -1260,7 +1260,8 @@ extension TagChartsViewController { min: minVisibleYValue, max: maxVisibleYValue, avg: averageYValue, - type: type + type: type, + measurementService: measurementService ) } } diff --git a/Apps/RuuviStation/Sources/Extensions/Structs/GlobalHelpers.swift b/Apps/RuuviStation/Sources/Extensions/Structs/GlobalHelpers.swift index 2bed572a4..6930604a0 100644 --- a/Apps/RuuviStation/Sources/Extensions/Structs/GlobalHelpers.swift +++ b/Apps/RuuviStation/Sources/Extensions/Structs/GlobalHelpers.swift @@ -30,10 +30,12 @@ struct GlobalHelpers { } } - func formattedString(from double: Double) -> String { + func formattedString(from double: Double, toPlace: Int = 2) -> String { let formatter = NumberFormatter() formatter.locale = Locale.autoupdatingCurrent formatter.numberStyle = .decimal + formatter.minimumFractionDigits = toPlace + formatter.maximumFractionDigits = toPlace return formatter.string(from: NSNumber(value: double)) ?? "0" } } diff --git a/station.localization b/station.localization index b50d8d2ba..e33920d23 160000 --- a/station.localization +++ b/station.localization @@ -1 +1 @@ -Subproject commit b50d8d2ba1da64c345087d3be4225eea479d2511 +Subproject commit e33920d237b172eaf9eb2008b7b94a63b9dd1a00