fix: show minutes when hour count is 0 on graph vertical axis
Closes: #62
This commit is contained in:
@@ -34,6 +34,7 @@ import com.patrykandpatrick.vico.core.cartesian.layer.ColumnCartesianLayer
|
|||||||
import com.patrykandpatrick.vico.core.common.Fill
|
import com.patrykandpatrick.vico.core.common.Fill
|
||||||
import com.patrykandpatrick.vico.core.common.shape.CorneredShape
|
import com.patrykandpatrick.vico.core.common.shape.CorneredShape
|
||||||
import org.nsh07.pomodoro.utils.millisecondsToHours
|
import org.nsh07.pomodoro.utils.millisecondsToHours
|
||||||
|
import org.nsh07.pomodoro.utils.millisecondsToMinutes
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -43,8 +44,12 @@ internal fun TimeColumnChart(
|
|||||||
thickness: Dp = 40.dp,
|
thickness: Dp = 40.dp,
|
||||||
columnCollectionSpacing: Dp = 4.dp,
|
columnCollectionSpacing: Dp = 4.dp,
|
||||||
xValueFormatter: CartesianValueFormatter = CartesianValueFormatter.Default,
|
xValueFormatter: CartesianValueFormatter = CartesianValueFormatter.Default,
|
||||||
yValueFormatter: CartesianValueFormatter = CartesianValueFormatter { measuringContext, value, _ ->
|
yValueFormatter: CartesianValueFormatter = CartesianValueFormatter { _, value, _ ->
|
||||||
millisecondsToHours(value.toLong())
|
if (value >= 60 * 60 * 1000) {
|
||||||
|
millisecondsToHours(value.toLong())
|
||||||
|
} else {
|
||||||
|
millisecondsToMinutes(value.toLong())
|
||||||
|
}
|
||||||
},
|
},
|
||||||
animationSpec: AnimationSpec<Float>? = motionScheme.slowEffectsSpec()
|
animationSpec: AnimationSpec<Float>? = motionScheme.slowEffectsSpec()
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -30,6 +30,15 @@ fun millisecondsToHours(t: Long): String {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun millisecondsToMinutes(t: Long): String {
|
||||||
|
require(t >= 0L)
|
||||||
|
return String.format(
|
||||||
|
Locale.getDefault(),
|
||||||
|
"%dm",
|
||||||
|
TimeUnit.MILLISECONDS.toMinutes(t)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun millisecondsToHoursMinutes(t: Long): String {
|
fun millisecondsToHoursMinutes(t: Long): String {
|
||||||
require(t >= 0L)
|
require(t >= 0L)
|
||||||
return String.format(
|
return String.format(
|
||||||
|
|||||||
Reference in New Issue
Block a user