I have value in Percentage from 0
to 100%
which is in Float
type . I am drawing vertical lines, I am using Offset
which value is also in Float
type. So how can I convert values in pixel values?
Values are
Pixel in size 996.0
2023-02-12 19:02:01.063 13417-13417 MainActivity com.example.queueapplication E name Low --++-- startPoint 0.0 --++-- endPoint 16.666666
2023-02-12 19:02:01.064 13417-13417 MainActivity com.example.queueapplication E name Normal --++-- startPoint 16.666666 --++-- endPoint 33.333332
2023-02-12 19:02:01.064 13417-13417 MainActivity com.example.queueapplication E name Elevated --++-- startPoint 33.333332 --++-- endPoint 50.0
2023-02-12 19:02:01.064 13417-13417 MainActivity com.example.queueapplication E name High --++-- startPoint 50.0 --++-- endPoint 66.666664
2023-02-12 19:02:01.064 13417-13417 MainActivity com.example.queueapplication E name Very High --++-- startPoint 66.666664 --++-- endPoint 83.33333
2023-02-12 19:02:01.064 13417-13417 MainActivity com.example.queueapplication E name Extremely High --++-- startPoint 83.33333 --++-- endPoint 100.0
I tried this pieced of code
@Composable
fun DrawProgressBar() {
val activity = LocalContext.current as AppCompatActivity
val rangeComposition = RangeComposition()
val itemLst = rangeComposition.bpExplained
val boxSize = 30.dp
Box(
modifier = Modifier
.background(Color.LightGray)
.height(height = boxSize)
) {
Canvas(
modifier = Modifier
.fillMaxWidth()
) {
val canvasWidth = size.width
drawLine(
start = Offset(x = 0f, y = (boxSize / 2).toPx()),
end = Offset(x = canvasWidth, y = (boxSize / 2).toPx()),
color = Color.Black,
strokeWidth = 8.dp.toPx(),
)
activity.logE("Pixel in size $canvasWidth")
itemLst.forEach { rangeItem ->
val endPointInPixel = rangeItem.endPoint
activity.logE("name ${rangeItem.name} --++-- startPoint ${rangeItem.startPoint} --++-- endPoint ${rangeItem.endPoint} ")
drawLine(
start = Offset(x = endPointInPixel, y = 0F),
end = Offset(x = endPointInPixel, y = boxSize.toPx()),
color = Color.Black,
strokeWidth = 4.dp.toPx(),
)
}
}
}
}
Actual Output
My all lines is taking Float value and draw very close to each other.
Expected Output