feat(stats): add placeholders for 0 durations

This commit is contained in:
Nishant Mishra
2025-12-13 19:44:11 +05:30
parent 8ab06d8d7e
commit 29873cea77

View File

@@ -21,7 +21,7 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme.colorScheme import androidx.compose.material3.MaterialTheme.colorScheme
@@ -34,7 +34,6 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@@ -74,42 +73,53 @@ fun HorizontalStackedBar(
val firstNonZeroIndex = remember(values) { values.indexOfFirst { it > 0L } } val firstNonZeroIndex = remember(values) { values.indexOfFirst { it > 0L } }
val lastNonZeroIndex = remember(values) { values.indexOfLast { it > 0L } } val lastNonZeroIndex = remember(values) { values.indexOfLast { it > 0L } }
Row( if (firstNonZeroIndex != -1)
horizontalArrangement = Arrangement.spacedBy(gap), Row(
modifier = modifier.height(height) horizontalArrangement = Arrangement.spacedBy(gap),
) { modifier = modifier.height(height)
values.fastForEachIndexed { index, item -> ) {
if (item > 0L) { values.fastForEachIndexed { index, item ->
val shape = if (item > 0L) {
if (firstNonZeroIndex == lastNonZeroIndex) shapes.large val shape =
else when (index) { if (firstNonZeroIndex == lastNonZeroIndex) shapes.large
firstNonZeroIndex -> shapes.large.copy( else when (index) {
topEnd = shapes.extraSmall.topEnd, firstNonZeroIndex -> shapes.large.copy(
bottomEnd = shapes.extraSmall.bottomEnd topEnd = shapes.extraSmall.topEnd,
) bottomEnd = shapes.extraSmall.bottomEnd
lastNonZeroIndex -> shapes.large.copy(
topStart = shapes.extraSmall.topStart,
bottomStart = shapes.extraSmall.bottomStart
)
else -> shapes.extraSmall
}
Spacer(
Modifier
.weight(item.toFloat())
.height(height)
.clip(shape)
.background(colorScheme.primaryContainer)
.background(
colorScheme.primary.copy(
(1f - (rankList.getOrNull(index) ?: 0) * 0.1f).coerceAtLeast(0.1f)
) )
)
) lastNonZeroIndex -> shapes.large.copy(
topStart = shapes.extraSmall.topStart,
bottomStart = shapes.extraSmall.bottomStart
)
else -> shapes.extraSmall
}
Spacer(
Modifier
.weight(item.toFloat())
.height(height)
.clip(shape)
.background(colorScheme.primaryContainer)
.background(
colorScheme.primary.copy(
(1f - (rankList.getOrNull(index) ?: 0) * 0.1f).coerceAtLeast(
0.1f
)
)
)
)
}
} }
} }
} else
Spacer(
Modifier
.fillMaxWidth()
.height(height)
.clip(shapes.large)
.background(colorScheme.outlineVariant)
)
} }
@Composable @Composable
@@ -166,12 +176,12 @@ fun FocusBreakRatioVisualization(
) )
} }
} else { } else {
Text( Spacer(
text = "Not enough data", Modifier
style = typography.bodyLarge, .fillMaxWidth()
color = colorScheme.outline, .height(height)
textAlign = TextAlign.Center, .clip(shapes.large)
modifier = Modifier.fillMaxSize() .background(colorScheme.outlineVariant)
) )
} }
} }