|
|
|
@ -10,28 +10,36 @@ import com.github.mikephil.charting.charts.LineChart |
|
|
|
import com.github.mikephil.charting.data.* |
|
|
|
import com.github.mikephil.charting.data.* |
|
|
|
import com.github.mikephil.charting.highlight.Highlight |
|
|
|
import com.github.mikephil.charting.highlight.Highlight |
|
|
|
import com.github.mikephil.charting.listener.OnChartValueSelectedListener |
|
|
|
import com.github.mikephil.charting.listener.OnChartValueSelectedListener |
|
|
|
import kotlinx.android.synthetic.main.fragment_evograph.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_graph.* |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.calculus.ObjectIdentifier |
|
|
|
import net.pokeranalytics.android.calculus.ObjectIdentifier |
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
import net.pokeranalytics.android.calculus.StatEntry |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
|
|
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
|
|
|
import net.pokeranalytics.android.ui.graph.AxisFormatting |
|
|
|
import net.pokeranalytics.android.ui.graph.AxisFormatting |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.graph.GraphUnderlyingEntry |
|
|
|
import net.pokeranalytics.android.ui.graph.setStyle |
|
|
|
import net.pokeranalytics.android.ui.graph.setStyle |
|
|
|
import net.pokeranalytics.android.ui.view.LegendView |
|
|
|
import net.pokeranalytics.android.ui.view.LegendView |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.view.MultiLineLegendView |
|
|
|
import timber.log.Timber |
|
|
|
import timber.log.Timber |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { |
|
|
|
class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum class LegendType { |
|
|
|
|
|
|
|
DEFAULT, |
|
|
|
|
|
|
|
DEFAULT_BAR, |
|
|
|
|
|
|
|
MULTILINE, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create new instance |
|
|
|
* Create new instance |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun newInstance(lineDataSets: List<LineDataSet>? = null, barDataSets: List<BarDataSet>? = null): GraphFragment { |
|
|
|
fun newInstance(lineDataSets: List<LineDataSet>? = null, barDataSets: List<BarDataSet>? = null, legendType: LegendType = LegendType.DEFAULT): GraphFragment { |
|
|
|
val fragment = GraphFragment() |
|
|
|
val fragment = GraphFragment() |
|
|
|
|
|
|
|
fragment.legendType = legendType |
|
|
|
fragment.lineDataSetList = lineDataSets |
|
|
|
fragment.lineDataSetList = lineDataSets |
|
|
|
fragment.barDataSetList = barDataSets |
|
|
|
fragment.barDataSetList = barDataSets |
|
|
|
val bundle = Bundle() |
|
|
|
val bundle = Bundle() |
|
|
|
@ -42,6 +50,8 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private lateinit var parentActivity: PokerAnalyticsActivity |
|
|
|
private lateinit var parentActivity: PokerAnalyticsActivity |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private var legendType: LegendType = LegendType.DEFAULT |
|
|
|
private lateinit var legendView: LegendView |
|
|
|
private lateinit var legendView: LegendView |
|
|
|
|
|
|
|
|
|
|
|
private var lineDataSetList: List<LineDataSet>? = null |
|
|
|
private var lineDataSetList: List<LineDataSet>? = null |
|
|
|
@ -53,7 +63,7 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { |
|
|
|
private var axisFormatting: AxisFormatting = AxisFormatting.DEFAULT |
|
|
|
private var axisFormatting: AxisFormatting = AxisFormatting.DEFAULT |
|
|
|
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|
|
|
return inflater.inflate(R.layout.fragment_evograph, container, false) |
|
|
|
return inflater.inflate(R.layout.fragment_graph, container, false) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
@ -93,9 +103,12 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { |
|
|
|
parentActivity = activity as PokerAnalyticsActivity |
|
|
|
parentActivity = activity as PokerAnalyticsActivity |
|
|
|
parentActivity.title = stat.localizedTitle(requireContext()) |
|
|
|
parentActivity.title = stat.localizedTitle(requireContext()) |
|
|
|
|
|
|
|
|
|
|
|
this.legendView = LegendView(requireContext()) |
|
|
|
this.legendView = when (this.legendType) { |
|
|
|
this.legendContainer.addView(this.legendView) |
|
|
|
LegendType.MULTILINE -> MultiLineLegendView(requireContext()) |
|
|
|
|
|
|
|
else -> LegendView(requireContext()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.legendContainer.addView(this.legendView) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -108,6 +121,7 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { |
|
|
|
this.chartContainer.removeAllViews() |
|
|
|
this.chartContainer.removeAllViews() |
|
|
|
|
|
|
|
|
|
|
|
var lastEntry: Entry? = null |
|
|
|
var lastEntry: Entry? = null |
|
|
|
|
|
|
|
var groupName: String? = null |
|
|
|
|
|
|
|
|
|
|
|
this.lineDataSetList?.let { dataSets -> |
|
|
|
this.lineDataSetList?.let { dataSets -> |
|
|
|
|
|
|
|
|
|
|
|
@ -118,15 +132,16 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { |
|
|
|
this.chartView = lineChart |
|
|
|
this.chartView = lineChart |
|
|
|
|
|
|
|
|
|
|
|
dataSets.firstOrNull()?.let { |
|
|
|
dataSets.firstOrNull()?.let { |
|
|
|
this.legendView.prepareWithStat(this.stat, it.entryCount) |
|
|
|
this.legendView.prepareWithStat(this.stat, it.entryCount, this.legendType) |
|
|
|
lastEntry = it.getEntryForIndex(it.entryCount - 1) |
|
|
|
lastEntry = it.getEntryForIndex(it.entryCount - 1) |
|
|
|
|
|
|
|
groupName = it.label |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.barDataSetList?.let { dataSets -> |
|
|
|
this.barDataSetList?.let { dataSets -> |
|
|
|
|
|
|
|
|
|
|
|
this.legendView.prepareWithStat(this.stat) |
|
|
|
this.legendView.prepareWithStat(this.stat, legendType = this.legendType) |
|
|
|
val barChart = BarChart(context) |
|
|
|
val barChart = BarChart(context) |
|
|
|
if (stat.showXAxisZero) { |
|
|
|
if (stat.showXAxisZero) { |
|
|
|
barChart.xAxis.axisMinimum = 0.0f |
|
|
|
barChart.xAxis.axisMinimum = 0.0f |
|
|
|
@ -141,6 +156,7 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { |
|
|
|
|
|
|
|
|
|
|
|
dataSets.firstOrNull()?.let { |
|
|
|
dataSets.firstOrNull()?.let { |
|
|
|
lastEntry = it.getEntryForIndex(it.entryCount - 1) |
|
|
|
lastEntry = it.getEntryForIndex(it.entryCount - 1) |
|
|
|
|
|
|
|
groupName = it.label |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -152,7 +168,7 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
lastEntry?.let { |
|
|
|
lastEntry?.let { |
|
|
|
this.selectValue(it) |
|
|
|
this.selectValue(it, groupName ?: "") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
@ -163,23 +179,32 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onValueSelected(e: Entry?, h: Highlight?) { |
|
|
|
override fun onValueSelected(e: Entry?, h: Highlight?) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var groupName = "" |
|
|
|
|
|
|
|
h?.let { highlight -> |
|
|
|
|
|
|
|
this.chartView?.data?.getDataSetByIndex(highlight.dataSetIndex)?.let { |
|
|
|
|
|
|
|
groupName = it.label |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
e?.let { entry -> |
|
|
|
e?.let { entry -> |
|
|
|
this.selectValue(entry) |
|
|
|
this.selectValue(entry, groupName) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun selectValue(entry: Entry) { |
|
|
|
private fun selectValue(entry: Entry, groupName: String) { |
|
|
|
|
|
|
|
|
|
|
|
val statEntry = when (entry.data) { |
|
|
|
val statEntry = when (entry.data) { |
|
|
|
is ObjectIdentifier -> { |
|
|
|
is ObjectIdentifier -> { |
|
|
|
val identifier = entry.data as ObjectIdentifier |
|
|
|
val identifier = entry.data as ObjectIdentifier |
|
|
|
getRealm().where(identifier.clazz).equalTo("id", identifier.id).findAll().firstOrNull() |
|
|
|
getRealm().where(identifier.clazz).equalTo("id", identifier.id).findAll().firstOrNull() |
|
|
|
} |
|
|
|
} |
|
|
|
is StatEntry -> entry.data as StatEntry? |
|
|
|
is GraphUnderlyingEntry -> entry.data as GraphUnderlyingEntry? |
|
|
|
else -> null |
|
|
|
else -> null |
|
|
|
} |
|
|
|
} |
|
|
|
statEntry?.let { |
|
|
|
statEntry?.let { |
|
|
|
this.legendView.setItemData(it.legendValues(stat, entry)) |
|
|
|
val legendValue = it.legendValues(stat, entry, this.legendType, groupName, requireContext()) |
|
|
|
|
|
|
|
this.legendView.setItemData(legendValue) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|