Adjust distance traveled graph.

This commit is contained in:
Danila Fedorin 2020-05-13 16:55:23 -07:00
parent 9ab9377201
commit 1cb22bf4a0

View File

@ -12,6 +12,7 @@ import com.android.volley.toolbox.Volley
import com.danilafe.fencelessgrazing.model.CollarDistance import com.danilafe.fencelessgrazing.model.CollarDistance
import com.danilafe.fencelessgrazing.requests.DistanceTraveledRequest import com.danilafe.fencelessgrazing.requests.DistanceTraveledRequest
import com.github.mikephil.charting.charts.BarChart import com.github.mikephil.charting.charts.BarChart
import com.github.mikephil.charting.components.XAxis
import com.github.mikephil.charting.data.BarData import com.github.mikephil.charting.data.BarData
import com.github.mikephil.charting.data.BarDataSet import com.github.mikephil.charting.data.BarDataSet
import com.github.mikephil.charting.data.BarEntry import com.github.mikephil.charting.data.BarEntry
@ -42,6 +43,7 @@ class DistanceTraveledGraph() : Fragment() {
): View? { ): View? {
val view = inflater.inflate(R.layout.distance_traveled_layoyt, container, false) val view = inflater.inflate(R.layout.distance_traveled_layoyt, container, false)
distanceTraveledChart = view.findViewById(R.id.distanceTraveledChart) distanceTraveledChart = view.findViewById(R.id.distanceTraveledChart)
setupChart()
return view return view
} }
@ -49,7 +51,6 @@ class DistanceTraveledGraph() : Fragment() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
queue = Volley.newRequestQueue(requireActivity().applicationContext) queue = Volley.newRequestQueue(requireActivity().applicationContext)
setupChart()
triggerRefresh() triggerRefresh()
} }
@ -83,19 +84,20 @@ class DistanceTraveledGraph() : Fragment() {
val dataSet = BarDataSet(entries, "Distance Traveled") val dataSet = BarDataSet(entries, "Distance Traveled")
dataSet.colors = ColorTemplate.PASTEL_COLORS.toList() dataSet.colors = ColorTemplate.PASTEL_COLORS.toList()
val data = BarData(dataSet) val data = BarData(dataSet)
data.barWidth = 0.9f data.barWidth = 0.8f
distanceTraveledChart.data = data distanceTraveledChart.data = data
distanceTraveledChart.xAxis.valueFormatter = IndexAxisValueFormatter(labels) distanceTraveledChart.xAxis.valueFormatter = IndexAxisValueFormatter(labels)
distanceTraveledChart.invalidate()
} }
/** /**
* Configure the [distanceTraveledChart] with the proper visual settings. * Configure the [distanceTraveledChart] with the proper visual settings.
*/ */
private fun setupChart() { private fun setupChart() {
distanceTraveledChart.legend.textSize = 20.0f
distanceTraveledChart.setFitBars(true) distanceTraveledChart.setFitBars(true)
distanceTraveledChart.xAxis.granularity = 1.0f distanceTraveledChart.xAxis.granularity = 1.0f
distanceTraveledChart.xAxis.isGranularityEnabled = true distanceTraveledChart.xAxis.isGranularityEnabled = true
distanceTraveledChart.xAxis.position = XAxis.XAxisPosition.BOTTOM
distanceTraveledChart.invalidate() distanceTraveledChart.invalidate()
} }
} }