mirror of
https://github.com/dzeiocom/OpenHealth.git
synced 2025-06-12 17:19:18 +00:00
feat: Scrollable/Zoomable/Customizable Chart
This commit is contained in:
@ -5,10 +5,15 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.dzeio.charts.Entry
|
||||
import com.dzeio.openhealth.adapters.StepsAdapter
|
||||
import com.dzeio.openhealth.core.BaseFragment
|
||||
import com.dzeio.openhealth.databinding.FragmentStepsHomeBinding
|
||||
import com.google.android.material.color.MaterialColors
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import java.text.DateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
@AndroidEntryPoint
|
||||
class StepsHomeFragment :
|
||||
@ -41,24 +46,38 @@ class StepsHomeFragment :
|
||||
|
||||
viewModel.items.observe(viewLifecycleOwner) { list ->
|
||||
adapter.set(list)
|
||||
chart.numberOfEntries = list.size
|
||||
// chart.numberOfEntries = list.size / 2
|
||||
chart.numberOfLabels = 2
|
||||
|
||||
val strings = ArrayList<String>()
|
||||
val values = ArrayList<Int>()
|
||||
// chart.animation.enabled = false
|
||||
chart.animation.refreshRate = 60
|
||||
chart.animation.duration = 500
|
||||
|
||||
list.forEach {
|
||||
strings.add(it.formatTimestamp())
|
||||
values.add(it.value)
|
||||
chart.xAxis.labels.color = MaterialColors.getColor(
|
||||
requireView(),
|
||||
com.google.android.material.R.attr.colorOnBackground
|
||||
)
|
||||
chart.xAxis.labels.size = 32f
|
||||
chart.yAxis.color = MaterialColors.getColor(
|
||||
requireView(),
|
||||
com.google.android.material.R.attr.colorPrimary
|
||||
)
|
||||
|
||||
chart.list = list.reversed().map {
|
||||
return@map Entry(it.timestamp.toDouble(), it.value.toFloat())
|
||||
} as ArrayList<Entry>
|
||||
|
||||
chart.xAxis.onValueFormat = onValueFormat@{
|
||||
val formatter = DateFormat.getDateTimeInstance(
|
||||
DateFormat.SHORT,
|
||||
DateFormat.SHORT,
|
||||
Locale.getDefault()
|
||||
)
|
||||
return@onValueFormat formatter.format(Date(it.toLong()))
|
||||
}
|
||||
|
||||
chart.yAxis.max = 10
|
||||
// chart.yAxis.max = (total / list.size).toInt()
|
||||
|
||||
|
||||
chart.setBottomTextList(strings)
|
||||
chart.setDataList(
|
||||
values
|
||||
)
|
||||
chart.refresh()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user