Skip to content

Commit

Permalink
Create mobile screen for QoS (#670)
Browse files Browse the repository at this point in the history
  • Loading branch information
MGaetan89 authored and StaehliJ committed Aug 28, 2024
1 parent 97a5468 commit e0bb884
Show file tree
Hide file tree
Showing 19 changed files with 1,676 additions and 63 deletions.
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "u
androidx-compose-ui-unit = { module = "androidx.compose.ui:ui-unit" }
androidx-compose-ui-util = { module = "androidx.compose.ui:ui-util" }
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" }
androidx-compose-material3-window-size = { module = "androidx.compose.material3:material3-window-size-class" }
androidx-compose-material-icons-core = { module = "androidx.compose.material:material-icons-core" }
androidx-compose-material-icons-extended = { module = "androidx.compose.material:material-icons-extended" }
androidx-compose-runtime = { module = "androidx.compose.runtime:runtime" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fun LineChart(
lineWidth: Dp = 2.dp,
lineCornerRadius: Dp = 6.dp,
stretchChartToPointsCount: Int? = null,
scaleItemsCount: Int = 4,
scaleItemsCount: Int = 5,
scaleTextFormatter: NumberFormat = NumberFormat.getIntegerInstance(),
scaleTextStyle: TextStyle = TextStyle.Default,
scaleTextHorizontalPadding: Dp = 8.dp,
Expand All @@ -78,21 +78,20 @@ fun LineChart(
Chart(
data = data,
modifier = modifier,
stretchChartToPointsCount = stretchChartToPointsCount,
scaleItemsCount = scaleItemsCount,
scaleTextFormatter = scaleTextFormatter,
scaleTextStyle = scaleTextStyle,
scaleTextHorizontalPadding = scaleTextHorizontalPadding,
scaleLineColor = scaleLineColor,
drawChart = { points, maxValue, bounds ->
drawChart = { maxValue, bounds ->
drawLineChart(
points = points,
points = data,
bounds = bounds,
maxValue = maxValue,
lineColor = lineColor,
lineWidth = lineWidth,
lineCornerRadius = lineCornerRadius,
maxPoints = stretchChartToPointsCount ?: points.size,
maxPoints = stretchChartToPointsCount ?: data.size,
)
},
)
Expand Down Expand Up @@ -123,7 +122,7 @@ fun BarChart(
barColor: Color = Color.Blue,
barSpacing: Dp = 1.dp,
stretchChartToPointsCount: Int? = null,
scaleItemsCount: Int = 4,
scaleItemsCount: Int = 5,
scaleTextFormatter: NumberFormat = NumberFormat.getIntegerInstance(),
scaleTextStyle: TextStyle = TextStyle.Default,
scaleTextHorizontalPadding: Dp = 8.dp,
Expand All @@ -132,20 +131,19 @@ fun BarChart(
Chart(
data = data,
modifier = modifier,
stretchChartToPointsCount = stretchChartToPointsCount,
scaleItemsCount = scaleItemsCount,
scaleTextFormatter = scaleTextFormatter,
scaleTextStyle = scaleTextStyle,
scaleTextHorizontalPadding = scaleTextHorizontalPadding,
scaleLineColor = scaleLineColor,
drawChart = { points, maxValue, bounds ->
drawChart = { maxValue, bounds ->
drawBarChart(
points = points,
points = data,
bounds = bounds,
maxValue = maxValue,
barColor = barColor,
barSpacing = barSpacing,
maxPoints = stretchChartToPointsCount ?: points.size,
maxPoints = stretchChartToPointsCount ?: data.size,
)
},
)
Expand All @@ -154,23 +152,17 @@ fun BarChart(
@Composable
private fun Chart(
data: List<Float>,
modifier: Modifier = Modifier,
stretchChartToPointsCount: Int? = null,
scaleItemsCount: Int = 4,
modifier: Modifier,
scaleItemsCount: Int,
scaleTextFormatter: NumberFormat,
scaleTextStyle: TextStyle = TextStyle.Default,
scaleTextHorizontalPadding: Dp = 8.dp,
scaleLineColor: Color = Color.LightGray,
drawChart: DrawScope.(points: List<Float>, maxValue: Int, bounds: Rect) -> Unit,
scaleTextStyle: TextStyle,
scaleTextHorizontalPadding: Dp,
scaleLineColor: Color,
drawChart: DrawScope.(maxValue: Int, bounds: Rect) -> Unit,
) {
val trimmedData = if (stretchChartToPointsCount != null) data.takeLast(stretchChartToPointsCount) else data
if (trimmedData.isEmpty()) {
return
}

val textMeasurer = rememberTextMeasurer()

val maxValue = trimmedData.max()
val maxValue = data.max()
val numberOfDigitsInMaxValue = log10(abs(maxValue.toDouble())).toInt()
val increment = 10.0.pow(numberOfDigitsInMaxValue).toInt()

Expand All @@ -189,8 +181,6 @@ private fun Chart(
),
)

drawChart(trimmedData, nextMaxMultipleOfScales, chartBounds)

drawScale(
textMeasurer = textMeasurer,
maxValue = nextMaxMultipleOfScales,
Expand All @@ -200,6 +190,8 @@ private fun Chart(
scaleTextHorizontalPadding = scaleTextHorizontalPadding,
scaleLineColor = scaleLineColor,
)

drawChart(nextMaxMultipleOfScales, chartBounds)
}
}

Expand Down Expand Up @@ -286,7 +278,7 @@ private fun DrawScope.drawScale(
val textX = lineXEnd + scaleTextHorizontalPadding.toPx()
val textY = (lineY - textSize.center.y).coerceIn(
minimumValue = 0f,
maximumValue = size.height - textSize.height,
maximumValue = (size.height - textSize.height).coerceAtLeast(0f),
)

drawLine(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/
package ch.srgssr.pillarbox.demo.shared.ui.player.metrics

/**
* Information about bit rates.
*
* @property data The list of recorded bit rates.
*/
data class BitRates(
val data: List<Float>,
) {
/**
* The unit in which the bit rates are expressed.
*/
val unit = "Mbps"

/**
* The current bit rate.
*/
val current: Float
get() = data.last()

/**
* The biggest recorded bit rate.
*/
val max: Float
get() = data.max()

/**
* The smallest recorded bit rate.
*/
val min: Float
get() = data.min()

companion object {
/**
* Empty [BitRates].
*/
val Empty = BitRates(
data = emptyList(),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/
package ch.srgssr.pillarbox.demo.shared.ui.player.metrics

/**
* Information about data volumes.
*
* @property data The list of recorded data volumes.
* @property total The formatted total volume.
*/
data class DataVolumes(
val data: List<Float>,
val total: String,
) {
/**
* The unit in which the volumes are expressed.
*/
val unit = "MByte"

companion object {
/**
* Empty [DataVolumes].
*/
val Empty = DataVolumes(
data = emptyList(),
total = "",
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/
package ch.srgssr.pillarbox.demo.shared.ui.player.metrics

/**
* Information about stalls.
*
* @property data The list of recorded stalls.
* @property total The formatted total of stalls.
*/
data class Stalls(
val data: List<Float>,
val total: String,
) {
companion object {
/**
* Empty [Stalls].
*/
val Empty = Stalls(
data = emptyList(),
total = "",
)
}
}
Loading

0 comments on commit e0bb884

Please sign in to comment.