11/*
22 * Copyright (c) 2025 Nishant Mishra
33 *
4- * You should have received a copy of the GNU General Public License
5- * along with this program. If not, see <https://www.gnu.org/licenses/>.
4+ * This file is part of Tomato - a minimalist pomodoro timer for Android.
5+ *
6+ * Tomato is free software: you can redistribute it and/or modify it under the terms of the GNU
7+ * General Public License as published by the Free Software Foundation, either version 3 of the
8+ * License, or (at your option) any later version.
9+ *
10+ * Tomato is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
11+ * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
12+ * Public License for more details.
13+ *
14+ * You should have received a copy of the GNU General Public License along with Tomato.
15+ * If not, see <https://www.gnu.org/licenses/>.
616 */
717
818package org.nsh07.pomodoro.ui.statsScreen
919
1020import androidx.compose.animation.core.AnimationSpec
21+ import androidx.compose.foundation.layout.height
1122import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
23+ import androidx.compose.material3.MaterialTheme.colorScheme
1224import androidx.compose.material3.MaterialTheme.motionScheme
25+ import androidx.compose.material3.MaterialTheme.typography
1326import androidx.compose.material3.Surface
1427import androidx.compose.runtime.Composable
1528import androidx.compose.runtime.LaunchedEffect
1629import androidx.compose.runtime.remember
1730import androidx.compose.ui.Modifier
31+ import androidx.compose.ui.graphics.toArgb
1832import androidx.compose.ui.tooling.preview.Preview
1933import androidx.compose.ui.unit.Dp
2034import androidx.compose.ui.unit.dp
@@ -37,10 +51,16 @@ import com.patrykandpatrick.vico.core.cartesian.data.CartesianChartModelProducer
3751import com.patrykandpatrick.vico.core.cartesian.data.CartesianValueFormatter
3852import com.patrykandpatrick.vico.core.cartesian.data.columnSeries
3953import com.patrykandpatrick.vico.core.cartesian.layer.ColumnCartesianLayer
54+ import com.patrykandpatrick.vico.core.cartesian.marker.ColumnCartesianLayerMarkerTarget
55+ import com.patrykandpatrick.vico.core.cartesian.marker.DefaultCartesianMarker
4056import com.patrykandpatrick.vico.core.common.Fill
57+ import com.patrykandpatrick.vico.core.common.Insets
58+ import com.patrykandpatrick.vico.core.common.component.ShapeComponent
59+ import com.patrykandpatrick.vico.core.common.component.TextComponent
4160import com.patrykandpatrick.vico.core.common.shape.CorneredShape
4261import org.nsh07.pomodoro.ui.theme.TomatoTheme
4362import org.nsh07.pomodoro.utils.millisecondsToHours
63+ import org.nsh07.pomodoro.utils.millisecondsToHoursMinutes
4464import org.nsh07.pomodoro.utils.millisecondsToMinutes
4565
4666@OptIn(ExperimentalMaterial3ExpressiveApi ::class )
@@ -58,6 +78,18 @@ fun TimeColumnChart(
5878 millisecondsToMinutes(value.toLong())
5979 }
6080 },
81+ markerValueFormatter : DefaultCartesianMarker .ValueFormatter = DefaultCartesianMarker .ValueFormatter { _, targets ->
82+ val first = targets.firstOrNull()
83+ val value = if (first is ColumnCartesianLayerMarkerTarget ) {
84+ first.columns.sumOf { it.entry.y.toLong() }
85+ } else 0L
86+
87+ if (value >= 60 * 60 * 1000) {
88+ millisecondsToHoursMinutes(value)
89+ } else {
90+ millisecondsToMinutes(value)
91+ }
92+ },
6193 animationSpec : AnimationSpec <Float >? = motionScheme.slowEffectsSpec()
6294) {
6395 ProvideVicoTheme (rememberM3VicoTheme()) {
@@ -88,6 +120,20 @@ fun TimeColumnChart(
88120 guideline = rememberLineComponent(Fill .Transparent ),
89121 valueFormatter = xValueFormatter
90122 ),
123+ marker = DefaultCartesianMarker (
124+ TextComponent (
125+ color = colorScheme.surface.toArgb(),
126+ background = ShapeComponent (
127+ fill = fill(colorScheme.onSurface),
128+ shape = CorneredShape .Pill
129+ ),
130+ textSizeSp = typography.labelSmall.fontSize.value,
131+ lineHeightSp = typography.labelSmall.fontSize.value,
132+ padding = Insets (verticalDp = 4f , horizontalDp = 8f ),
133+ margins = Insets (bottomDp = 2f )
134+ ),
135+ valueFormatter = markerValueFormatter
136+ ),
91137 fadingEdges = FadingEdges ()
92138 ),
93139 modelProducer = modelProducer,
@@ -97,7 +143,7 @@ fun TimeColumnChart(
97143 minZoom = Zoom .min(Zoom .Content , Zoom .fixed())
98144 ),
99145 animationSpec = animationSpec,
100- modifier = modifier,
146+ modifier = modifier.height( 224 .dp) ,
101147 )
102148 }
103149}
0 commit comments