@@ -26,17 +26,13 @@ import androidx.compose.foundation.text.KeyboardOptions
2626import androidx.compose.foundation.verticalScroll
2727import androidx.compose.material.icons.Icons
2828import androidx.compose.material.icons.filled.Add
29- import androidx.compose.material.icons.filled.ArrowDropDown
3029import androidx.compose.material.icons.filled.Home
3130import androidx.compose.material.icons.filled.Person
3231import androidx.compose.material3.Button
3332import androidx.compose.material3.ButtonDefaults
3433import androidx.compose.material3.CenterAlignedTopAppBar
3534import androidx.compose.material3.DropdownMenuItem
3635import androidx.compose.material3.ExperimentalMaterial3Api
37- import androidx.compose.material3.ExposedDropdownMenuBox
38- import androidx.compose.material3.ExposedDropdownMenuDefaults
39- import androidx.compose.material3.HorizontalDivider
4036import androidx.compose.material3.Icon
4137import androidx.compose.material3.MaterialTheme
4238import androidx.compose.material3.NavigationBar
@@ -49,7 +45,6 @@ import androidx.compose.material3.SnackbarDuration
4945import androidx.compose.material3.SnackbarHost
5046import androidx.compose.material3.SnackbarHostState
5147import androidx.compose.material3.Text
52- import androidx.compose.material3.TextField
5348import androidx.compose.material3.TopAppBarDefaults
5449import androidx.compose.runtime.Composable
5550import androidx.compose.runtime.LaunchedEffect
@@ -71,9 +66,7 @@ import androidx.compose.ui.unit.dp
7166import androidx.lifecycle.compose.collectAsStateWithLifecycle
7267import androidx.lifecycle.viewmodel.MutableCreationExtras
7368import androidx.lifecycle.viewmodel.compose.viewModel
74- import androidx.lifecycle.lifecycleScope
7569import com.patrykandpatrick.vico.compose.cartesian.CartesianChartHost
76- import com.patrykandpatrick.vico.compose.cartesian.axis.rememberAxisTickComponent
7770import com.patrykandpatrick.vico.compose.cartesian.axis.rememberBottom
7871import com.patrykandpatrick.vico.compose.cartesian.axis.rememberStart
7972import com.patrykandpatrick.vico.compose.cartesian.layer.rememberLineCartesianLayer
@@ -90,18 +83,14 @@ import com.waldo121.pongstats.domain.DailyWinRateUseCase
9083import com.waldo121.pongstats.ui.theme.PingPongBlack
9184import com.waldo121.pongstats.ui.theme.PingPongDarkGrey
9285import com.waldo121.pongstats.ui.theme.PingPongDarkRed
93- import com.waldo121.pongstats.ui.theme.PingPongLightWood
9486import com.waldo121.pongstats.ui.theme.PingPongRed
9587import com.waldo121.pongstats.ui.theme.PingPongWood
9688import com.waldo121.pongstats.ui.theme.PongStatsTheme
9789import com.waldo121.pongstats.viewModel.MatchRecordViewModel
9890import com.waldo121.pongstats.viewModel.StatisticsViewModel
9991import kotlinx.coroutines.Dispatchers
10092import kotlinx.coroutines.launch
101- import kotlinx.coroutines.withContext
102- import java.time.LocalDate
10393import java.time.ZoneId
104- import java.time.format.DateTimeFormatter
10594import kotlin.math.round
10695import com.patrykandpatrick.vico.core.cartesian.layer.LineCartesianLayer
10796import java.time.Instant
@@ -124,12 +113,14 @@ import androidx.compose.foundation.clickable
124113import androidx.compose.foundation.layout.fillMaxSize
125114import androidx.compose.foundation.text.KeyboardActions
126115import androidx.compose.material3.DropdownMenu
127- import androidx.compose.material3.DropdownMenuItem
128116import androidx.compose.ui.unit.DpOffset
129117import androidx.compose.foundation.lazy.LazyColumn
130118import androidx.compose.foundation.lazy.items
131119import androidx.compose.foundation.layout.heightIn
132- import android.widget.Toast
120+ import com.patrykandpatrick.vico.compose.cartesian.VicoScrollState
121+ import com.patrykandpatrick.vico.compose.cartesian.rememberVicoScrollState
122+ import com.patrykandpatrick.vico.core.cartesian.Scroll
123+ import com.waldo121.pongstats.ui.components.xLabelFormatter
133124
134125
135126class MainActivity : ComponentActivity () {
@@ -345,10 +336,6 @@ fun HomeScreen(
345336 // Collect all unique x-values in order
346337 val allXValues = (singleSeriesX + doubleSeriesX).distinct().sorted()
347338
348- // Dynamically calculate labelEvery so that at most maxLabels are shown
349- val maxLabels = 7
350- val labelEvery = if (allXValues.size <= maxLabels) 1 else (allXValues.size + maxLabels - 1 ) / maxLabels
351-
352339 // Determine which series are present and in what order
353340 val presentSeries = mutableListOf<String >()
354341 if (singleSeriesY.isNotEmpty()) presentSeries.add(" singles" )
@@ -441,12 +428,11 @@ fun HomeScreen(
441428 if (singleData.isNotEmpty() || doubleData.isNotEmpty()) {
442429 WinRateChart (
443430 modelProducer = combinedModelProducer,
444- modifier = Modifier .padding(vertical = 8 .dp),
431+ modifier = Modifier .padding(vertical = 8 .dp).fillMaxWidth() ,
445432 title = stringResource(R .string.daily_win_rate),
446433 showLegend = true ,
447434 presentSeries = presentSeries,
448435 allXValues = allXValues,
449- labelEvery = labelEvery
450436 )
451437 } else {
452438 EmptyChartPlaceholder (
@@ -488,11 +474,10 @@ private fun WinRateChart(
488474 showLegend : Boolean = false,
489475 presentSeries : List <String >,
490476 allXValues : List <Float >,
491- labelEvery : Int = 5
492477) {
493478 val singlesColor = PingPongRed
494479 val doublesColor = PingPongDarkRed
495-
480+ val scrollState = rememberVicoScrollState(scrollEnabled = false )
496481 val lines = presentSeries.map { series ->
497482 when (series) {
498483 " singles" -> LineCartesianLayer .Line (
@@ -535,19 +520,11 @@ private fun WinRateChart(
535520 }
536521 ),
537522 bottomAxis = HorizontalAxis .rememberBottom(
538- itemPlacer = HorizontalAxis .ItemPlacer .aligned(),
539- valueFormatter = { _, value, _ ->
540- val index = allXValues.indexOf(value.toFloat())
541- if (index >= 0 && index % labelEvery == 0 ) {
542- val date = LocalDate .ofEpochDay(value.toLong())
543- date.format(DateTimeFormatter .ofPattern(" MMM, YYYY" ))
544- } else {
545- " "
546- }
547- },
548- labelRotationDegrees = 30f
523+ valueFormatter = xLabelFormatter(allXValues),
524+ labelRotationDegrees = 40f ,
549525 ),
550526 ),
527+ scrollState = scrollState,
551528 modelProducer = modelProducer,
552529 modifier = Modifier
553530 .fillMaxWidth()
0 commit comments