Skip to content

Commit

Permalink
graph
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorVorOK committed Nov 23, 2024
1 parent 83fe537 commit 65d8464
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 60 deletions.
61 changes: 2 additions & 59 deletions app/src/main/java/com/chillrate/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,21 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.animation.core.AnimationSpec
import androidx.compose.animation.core.EaseInOutCubic
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.SolidColor

import androidx.compose.ui.unit.dp
import com.chillrate.ui.theme.AppTheme
import ir.ehsannarmani.compose_charts.LineChart
import ir.ehsannarmani.compose_charts.models.AnimationMode
import ir.ehsannarmani.compose_charts.models.DrawStyle
import ir.ehsannarmani.compose_charts.models.Line
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -68,8 +53,8 @@ class MainActivity : ComponentActivity() {

LineChart(
modifier = Modifier
.fillMaxSize()
.padding(100.dp),
.padding(horizontal = 40.dp)
.height(200.dp),
data = data,
maxValue = 200.0,
minValue = 0.0
Expand All @@ -86,46 +71,4 @@ class MainActivity : ComponentActivity() {
}
}
}

}

@Composable
fun EcgGraph(ecgData: List<Float>) {
Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Box(
modifier = Modifier
.fillMaxWidth()
.height(200.dp)
) {
Canvas(
modifier = Modifier
.fillMaxSize()
.horizontalScroll(rememberScrollState())
) {
val width = size.width
val height = size.height
val dataPoints = ecgData.size
val xScale = width / dataPoints.toFloat()

if (dataPoints > 0) {
val yScale = height / (ecgData.maxOrNull()?.toDouble()
?: 1.0) // Prevents division by zero.
val path = Path()
path.moveTo(0f, height / 2f) // Start at the middle of the graph.
for (i in 0 until dataPoints) {
val x = i * xScale
val y = (ecgData[i].toDouble() * yScale).toFloat()
path.lineTo(x, height / 2f - y)
}
drawPath(path, Color.Red)
}
}
}

Text("ECG Data") // Add some labeling.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fun RoomView(
val sheetProvider = LocalSheetProvider.current

val sensorConnected by callibriRepository.controller.sensorConnected.collectAsState()

val data by callibriRepository.data.collectAsState()
sheetProvider.setContent(SensorConnect)

LaunchedEffect(sensorConnected) {
Expand Down

0 comments on commit 65d8464

Please sign in to comment.