1
0
mirror of https://github.com/dzeiocom/OpenHealth.git synced 2025-06-12 17:19:18 +00:00

feat(charts): Add back the XAxis/YAxis/Scrolling

This commit is contained in:
2022-08-23 00:59:10 +02:00
parent 07d150968e
commit 39f6e7cbef
17 changed files with 331 additions and 447 deletions

View File

@ -13,6 +13,9 @@ 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 :
@ -61,10 +64,10 @@ class StepsHomeFragment :
chart.apply {
series = arrayListOf(serie)
debug = true
// debug = true
yAxis.apply {
setYMin(0f)
setYMax(500f)
textLabel.color = MaterialColors.getColor(
requireView(),
com.google.android.material.R.attr.colorOnPrimaryContainer
@ -79,27 +82,34 @@ class StepsHomeFragment :
xAxis.apply {
increment = 3600000.0
displayCount = 168
// displayCount = 24
// displayCount = 168
displayCount = 10
textPaint.color = MaterialColors.getColor(
requireView(),
com.google.android.material.R.attr.colorOnPrimaryContainer
)
textPaint.textSize = 32f
onValueFormat = onValueFormat@{
val formatter = DateFormat.getDateTimeInstance(
DateFormat.SHORT,
DateFormat.SHORT,
Locale.getDefault()
)
return@onValueFormat formatter.format(Date(it.toLong()))
}
}
}
viewModel.items.observe(viewLifecycleOwner) { list ->
adapter.set(list)
chart.debug = true
// chart.animation.enabled = false
// chart.animation.refreshRate = 60
// chart.animation.duration = 300
// chart.scroller.zoomEnabled = false
// chart.xAxis.labels.color = MaterialColors.getColor(
// requireView(),
// com.google.android.material.R.attr.colorOnBackground
// )
// chart.xAxis.labels.size = 32f
serie.entries = list.reversed().map {
@ -108,32 +118,8 @@ class StepsHomeFragment :
chart.xAxis.x = serie.entries.first().x
// chart.xAxis.onValueFormat = onValueFormat@{
// val formatter = DateFormat.getDateTimeInstance(
// DateFormat.SHORT,
// DateFormat.SHORT,
// Locale.getDefault()
// )
// return@onValueFormat formatter.format(Date(it.toLong()))
// }
chart.refresh()
}
// val scrollView = requireActivity().findViewById<NestedScrollView>(R.id.scrollView)
// var scrollEnabled = false
// scrollView.setOnTouchListener { view, _ ->
// view.performClick()
// if (scrollEnabled) {
// } else {
// return@setOnTouchListener !scrollEnabled
// }
// return@setOnTouchListener true
// }
// binding.chart.setOnToggleScroll {
// Log.d(TAG, it.toString())
// scrollEnabled = it
// }
}
}