health: show height chart in centimeters, not meters
- Commit
0b8c03d4f2d1e7abfa039f52efb16e33c64d96df- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 19:56 UTC (28 days ago)
- Parents
db60488
Symptom: the Height detail chart plotted ~1.75 against a 175 cm goal, so the goal line was off-chart and the header read "1.8 cm". Root cause: height is the one metric stored off its display unit: sync/write use meters (Length.meters / height.inMeters) while HealthMetricConfig.HEIGHT declares unit cm and goal 175. BodyPage and BodyLoggingDialog convert at their edges; the generic chart pipeline did not. Fix: scale height pairs m->cm in HealthChartData.queryChartPairs via the new pure scaleForDisplay, covering chart, history and averages. Storage and Health Connect formats unchanged. Verification: new HeightScaleTest (height scales, weight passes through); full test/compile run after all fixes.
Diff
health/src/main/java/com/vayunmathur/health/util/HealthChartData.kt
diff --git a/health/src/main/java/com/vayunmathur/health/util/HealthChartData.kt b/health/src/main/java/com/vayunmathur/health/util/HealthChartData.ktindex ed1577e5ee..c3cd31d42d 100644--- a/health/src/main/java/com/vayunmathur/health/util/HealthChartData.kt+++ b/health/src/main/java/com/vayunmathur/health/util/HealthChartData.kt@@ -101,7 +101,18 @@ internal object HealthChartData { } else { HealthAPI.getListOfSums(config.recordType, startTime, endTimeNow, periodType2) }- return rawPairs to rawPairsHistory+ // Height is stored in meters but its config/goal/unit are centimeters+ // (175 cm); every other metric stores in its display unit already.+ return scaleForDisplay(config, rawPairs) to scaleForDisplay(config, rawPairsHistory)+ }++ /** Converts stored values to the metric's display unit (height m -> cm only). */+ internal fun scaleForDisplay(+ config: HealthMetricConfig,+ pairs: List<Tuple3<Long, Double, Double>>,+ ): List<Tuple3<Long, Double, Double>> {+ if (config.recordType != com.vayunmathur.health.data.RecordType.Height) return pairs+ return pairs.map { Tuple3(it.first, it.second * 100.0, it.third * 100.0) } } /**
health/src/test/java/com/vayunmathur/health/util/HeightScaleTest.kt
diff --git a/health/src/test/java/com/vayunmathur/health/util/HeightScaleTest.kt b/health/src/test/java/com/vayunmathur/health/util/HeightScaleTest.ktnew file mode 100644index 0000000000..2357ef2d07--- /dev/null+++ b/health/src/test/java/com/vayunmathur/health/util/HeightScaleTest.kt@@ -0,0 +1,25 @@+package com.vayunmathur.health.util++import com.vayunmathur.health.ui.HealthMetricConfig+import com.vayunmathur.library.util.Tuple3+import kotlin.test.Test+import kotlin.test.assertEquals++/** Height is stored in meters but displayed in cm; other metrics pass through. */+class HeightScaleTest {+ @Test+ fun heightScalesMetersToCentimeters() {+ val out = HealthChartData.scaleForDisplay(+ HealthMetricConfig.HEIGHT,+ listOf(Tuple3(20000L, 1.75, 1.75)),+ )+ assertEquals(175.0, out.single().second)+ assertEquals(20000L, out.single().first)+ }++ @Test+ fun weightPassesThroughUnscaled() {+ val input = listOf(Tuple3(20000L, 75.0, 0.0))+ assertEquals(input, HealthChartData.scaleForDisplay(HealthMetricConfig.WEIGHT, input))+ }+}