refactor: Line breaks for time separations linked to TimeFrame (#1502)

pull/1508/head
Robert-0410 2024-12-23 02:34:22 -08:00 zatwierdzone przez GitHub
rodzic 45e50b829a
commit 16a8503207
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
3 zmienionych plików z 19 dodań i 5 usunięć

Wyświetl plik

@ -147,6 +147,20 @@ enum class TimeFrame(
}
}
/**
* Used to detect a significant time separation between [Telemetry]s.
*/
fun timeThreshold(): Long {
return when (this.ordinal) {
TWENTY_FOUR_HOURS.ordinal ->
TimeUnit.HOURS.toSeconds(6)
FORTY_EIGHT_HOURS.ordinal ->
TimeUnit.HOURS.toSeconds(12)
else ->
TimeUnit.DAYS.toSeconds(1)
}
}
/**
* Calculates the needed [Dp] depending on the amount of time being plotted.
*

Wyświetl plik

@ -234,7 +234,8 @@ private fun DeviceMetricsChart(
path = path,
oldestTime = oldest.time,
timeRange = timeDiff,
width = width
width = width,
timeThreshold = selectedTime.timeThreshold()
) { i ->
val telemetry = telemetries.getOrNull(i) ?: telemetries.last()
val ratio = telemetry.deviceMetrics.batteryLevel / MAX_PERCENT_VALUE

Wyświetl plik

@ -22,9 +22,6 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawContext
import com.geeksville.mesh.TelemetryProtos.Telemetry
import java.util.concurrent.TimeUnit
private const val TIME_SEPARATION_THRESHOLD = 2L
object GraphUtil {
@ -59,6 +56,7 @@ object GraphUtil {
* @param path [Path] that will be used to draw
* @param timeRange The time range for the data set
* @param width of the [DrawContext]
* @param timeThreshold to determine significant breaks in time between [Telemetry]s
* @param calculateY (`index`) -> `y` coordinate
*/
fun createPath(
@ -68,6 +66,7 @@ object GraphUtil {
oldestTime: Int,
timeRange: Int,
width: Float,
timeThreshold: Long,
calculateY: (Int) -> Float
): Int {
var i = index
@ -78,7 +77,7 @@ object GraphUtil {
val nextTelemetry = telemetries.getOrNull(i + 1) ?: telemetries.last()
/* Check to see if we have a significant time break between telemetries. */
if (nextTelemetry.time - telemetry.time > TimeUnit.HOURS.toSeconds(TIME_SEPARATION_THRESHOLD)) {
if (nextTelemetry.time - telemetry.time > timeThreshold) {
i++
break
}