Graph styling + restricting for proper stats

feature/top10
Laurent 7 years ago
parent d7a2f100af
commit 44202dc50b
  1. 11
      app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt
  2. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/GraphFragment.kt
  3. 2
      app/src/main/java/net/pokeranalytics/android/ui/fragment/StatsFragment.kt
  4. 93
      app/src/main/java/net/pokeranalytics/android/ui/graph/GraphExtensions.kt
  5. 7
      app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt

@ -203,7 +203,16 @@ enum class Stat : RowRepresentable {
get() { get() {
return when (this) { return when (this) {
NETRESULT -> listOf(AggregationType.SESSION, AggregationType.MONTH, AggregationType.YEAR, AggregationType.DURATION) NETRESULT -> listOf(AggregationType.SESSION, AggregationType.MONTH, AggregationType.YEAR, AggregationType.DURATION)
else -> listOf(AggregationType.SESSION, AggregationType.MONTH, AggregationType.YEAR, AggregationType.DURATION) NUMBER_OF_GAMES, NUMBER_OF_SETS -> listOf(AggregationType.MONTH, AggregationType.YEAR)
else -> listOf(AggregationType.SESSION, AggregationType.MONTH, AggregationType.YEAR)
}
}
val hasEvolutionGraph: Boolean
get() {
return when (this) {
DURATION, AVERAGE_DURATION -> false
else -> true
} }
} }

@ -96,9 +96,11 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener {
this.chartContainer.addView(this.chartView) this.chartContainer.addView(this.chartView)
this.chartView.setStyle(requireContext()) this.chartView.setStyle(false, requireContext())
this.chartView.setOnChartValueSelectedListener(this) this.chartView.setOnChartValueSelectedListener(this)
this.chartView.highlightValue((this.entries.size - 1).toFloat(), 0)
this.stat.aggregationTypes.forEach { type -> this.stat.aggregationTypes.forEach { type ->
val chip = Chip(requireContext()) val chip = Chip(requireContext())
chip.id = type.ordinal chip.id = type.ordinal

@ -199,7 +199,7 @@ class StatsFragment : SessionObserverFragment(), StaticRowRepresentableDataSourc
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) {
if (row is StatRepresentable) { if (row is StatRepresentable && row.stat.hasEvolutionGraph) {
// filter groups // filter groups
val groupResults = this.report?.results?.filter { val groupResults = this.report?.results?.filter {

@ -1,76 +1,63 @@
package net.pokeranalytics.android.ui.graph package net.pokeranalytics.android.ui.graph
import android.content.Context import android.content.Context
import android.graphics.Typeface
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import com.github.mikephil.charting.charts.BarLineChartBase import com.github.mikephil.charting.charts.BarLineChartBase
import com.github.mikephil.charting.components.XAxis import com.github.mikephil.charting.components.XAxis
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.util.extensions.px import net.pokeranalytics.android.util.extensions.px
//fun BarChart.setStyle(context: Context) { fun BarLineChartBase<*>.setStyle(small: Boolean, context: Context) {
// GraphHelper.setStyle(this, context)
//}
fun BarLineChartBase<*>.setStyle(context: Context) { // X Axis
GraphHelper.setStyle(this, context) this.xAxis.axisLineColor = ContextCompat.getColor(context, R.color.chart_default)
} this.xAxis.enableGridDashedLine(3.0f.px, 5.0f.px, 1.0f.px)
this.xAxis.textColor = ContextCompat.getColor(context, R.color.chart_default)
this.xAxis.labelCount = 4
this.xAxis.position = XAxis.XAxisPosition.BOTTOM
class GraphHelper { this.xAxis.enableGridDashedLine(3.0f.px, 5.0f.px, 1.0f.px)
companion object { this.xAxis.textColor = ContextCompat.getColor(context, R.color.chart_default)
this.xAxis.typeface = Typeface.DEFAULT
this.xAxis.labelCount = 4
this.xAxis.position = XAxis.XAxisPosition.BOTTOM
fun setStyle(chart: BarLineChartBase<*>, context: Context) { this.xAxis.setDrawLabels(true)
this.xAxis.setDrawGridLines(true)
this.xAxis.granularity = 1.0f
this.xAxis.isGranularityEnabled = true
this.xAxis.isEnabled = true
chart.xAxis.axisLineColor = ContextCompat.getColor(context, R.color.chart_default) // Y Axis
chart.xAxis.enableGridDashedLine(3.0f.px, 5.0f.px, 1.0f.px) this.axisLeft.setDrawAxisLine(false)
chart.xAxis.textColor = ContextCompat.getColor(context, R.color.chart_default) this.axisLeft.setDrawGridLines(true)
chart.xAxis.labelCount = 4 this.axisLeft.enableGridDashedLine(3.0f.px, 5.0f.px, 1.0f.px)
chart.xAxis.position = XAxis.XAxisPosition.BOTTOM
chart.axisLeft.enableGridDashedLine(3.0f.px, 5.0f.px, 1.0f.px) this.axisLeft.setDrawZeroLine(true)
// this.axisLeft.zeroLineWidth = 1.0f.px
this.axisLeft.zeroLineColor = ContextCompat.getColor(context, R.color.chart_default)
// this.xAxis.axisLineWidth = ChartAppearance.lineWidth this.axisLeft.isGranularityEnabled = true
// this.xAxis.enableGridDashedLine(3.0f, 5.0f, 1.0f) this.axisLeft.granularity = 1.0f
//
// this.xAxis.labelTextColor = ChartAppearance.defaultColor this.axisLeft.textColor = ContextCompat.getColor(context, R.color.chart_default)
// this.xAxis.labelFont = Fonts.graphAxis this.axisLeft.typeface = Typeface.DEFAULT
// this.xAxis.labelCount = 4 this.axisLeft.labelCount =
// this.xAxis.labelPosition = .bottom if (small) 1 else 7 // @todo not great if interval is [0..2] for number of records as we get decimals
//
// this.xAxis.drawLabelsEnabled = true this.axisRight.isEnabled = false
// this.xAxis.drawGridLinesEnabled = true this.legend.isEnabled = false
// this.xAxis.granularity = 1.0
// this.xAxis.granularityEnabled = true
// this.xAxis.enabled = true // @todo
//
// // Y Axis
// this.leftAxis.drawAxisLineEnabled = false
// this.leftAxis.drawGridLinesEnabled = true
// this.leftAxis.gridLineDashLengths = [3.0, 5.0]
//
// this.leftAxis.drawZeroLineEnabled = true
// this.leftAxis.zeroLineWidth = ChartAppearance.lineWidth
// this.leftAxis.zeroLineColor = ChartAppearance.defaultColor
//
// this.leftAxis.granularityEnabled = true
// this.leftAxis.granularity = 1.0
//
// this.leftAxis.labelTextColor = ChartAppearance.defaultColor
// this.leftAxis.labelFont = Fonts.graphAxis
// this.leftAxis.labelCount = small ? 1 : 7 // @todo not great if interval is [0..2] for number of records as we get decimals
//
// if timeYAxis { // if timeYAxis {
// this.leftAxis.valueFormatter = HourValueFormatter() // this.axisLeft.valueFormatter = HourValueFormatter()
// } else { // } else {
// this.leftAxis.valueFormatter = LargeNumberFormatter() // this.axisLeft.valueFormatter = LargeNumberFormatter()
// } // }
// //
// this.rightAxis.enabled = false
//
// this.legend.enabled = false
}
}
} }

@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.row_history_session.view.* import kotlinx.android.synthetic.main.row_history_session.view.*
import kotlinx.android.synthetic.main.row_transaction.view.* import kotlinx.android.synthetic.main.row_transaction.view.*
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.StatRepresentable
import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.model.realm.Transaction import net.pokeranalytics.android.model.realm.Transaction
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter
@ -232,11 +233,13 @@ enum class RowViewType(private var layoutRes: Int) {
itemView.findViewById<AppCompatTextView?>(R.id.value)?.let { view -> itemView.findViewById<AppCompatTextView?>(R.id.value)?.let { view ->
adapter.dataSource.contentDescriptorForRow(row)?.textFormat?.let { adapter.dataSource.contentDescriptorForRow(row)?.textFormat?.let {
view.setTextFormat(it, itemView.context) view.setTextFormat(it, itemView.context)
// view.text = it.text
// view.setTextColor(it.getColor(itemView.context))
} }
} }
if (row is StatRepresentable) {
itemView.findViewById<AppCompatImageView?>(R.id.nextArrow)?.isVisible = row.stat.hasEvolutionGraph
}
// Listener // Listener
val listener = View.OnClickListener { val listener = View.OnClickListener {
adapter.delegate?.onRowSelected(position, row) adapter.delegate?.onRowSelected(position, row)

Loading…
Cancel
Save