|
|
|
@ -11,31 +11,28 @@ 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_evograph.* |
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
|
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.calculus.* |
|
|
|
import net.pokeranalytics.android.calculus.ObjectIdentifier |
|
|
|
|
|
|
|
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.setStyle |
|
|
|
import net.pokeranalytics.android.ui.graph.setStyle |
|
|
|
import net.pokeranalytics.android.ui.view.LegendView |
|
|
|
import net.pokeranalytics.android.ui.view.LegendView |
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
import timber.log.Timber |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, CoroutineScope { |
|
|
|
class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { |
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create new instance |
|
|
|
* Create new instance |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun newInstance(report: Report? = null): GraphFragment { |
|
|
|
fun newInstance(dataSetList: List<DataSet<*>>): GraphFragment { |
|
|
|
val fragment = GraphFragment() |
|
|
|
val fragment = GraphFragment() |
|
|
|
|
|
|
|
fragment.dataSetList = dataSetList |
|
|
|
report?.let { |
|
|
|
|
|
|
|
fragment.selectedReport = it |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val bundle = Bundle() |
|
|
|
val bundle = Bundle() |
|
|
|
fragment.arguments = bundle |
|
|
|
fragment.arguments = bundle |
|
|
|
return fragment |
|
|
|
return fragment |
|
|
|
@ -43,16 +40,12 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private lateinit var parentActivity: PokerAnalyticsActivity |
|
|
|
private lateinit var parentActivity: PokerAnalyticsActivity |
|
|
|
private lateinit var selectedReport: Report |
|
|
|
|
|
|
|
private lateinit var legendView: LegendView |
|
|
|
private lateinit var legendView: LegendView |
|
|
|
|
|
|
|
private lateinit var dataSetList: List<DataSet<*>> |
|
|
|
private var chartView: BarLineChartBase<*>? = null |
|
|
|
private var chartView: BarLineChartBase<*>? = null |
|
|
|
|
|
|
|
|
|
|
|
private var stat: Stat = Stat.NET_RESULT |
|
|
|
private var stat: Stat = Stat.NET_RESULT |
|
|
|
private var aggregationType: AggregationType = AggregationType.SESSION |
|
|
|
private var axisFormatting: AxisFormatting = AxisFormatting.DEFAULT |
|
|
|
|
|
|
|
|
|
|
|
override val coroutineContext: CoroutineContext |
|
|
|
|
|
|
|
get() = Dispatchers.Main |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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_evograph, container, false) |
|
|
|
@ -67,11 +60,10 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set data |
|
|
|
* Set data |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun setData(report: Report, stat: Stat, aggregationType: AggregationType) { |
|
|
|
fun setData(dataSetList: List<DataSet<out Entry>>, stat: Stat, axisFormatting: AxisFormatting = AxisFormatting.DEFAULT) { |
|
|
|
|
|
|
|
this.dataSetList = dataSetList |
|
|
|
this.selectedReport = report |
|
|
|
|
|
|
|
this.aggregationType = aggregationType |
|
|
|
|
|
|
|
this.stat = stat |
|
|
|
this.stat = stat |
|
|
|
|
|
|
|
this.axisFormatting = axisFormatting |
|
|
|
|
|
|
|
|
|
|
|
if (isAdded && !isDetached) { |
|
|
|
if (isAdded && !isDetached) { |
|
|
|
loadGraph() |
|
|
|
loadGraph() |
|
|
|
@ -96,32 +88,20 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun loadGraph() { |
|
|
|
private fun loadGraph() { |
|
|
|
|
|
|
|
|
|
|
|
val ds = when (aggregationType) { |
|
|
|
Timber.d("loadGraph") |
|
|
|
AggregationType.SESSION -> selectedReport.results.firstOrNull()?.defaultStatEntries(stat, requireContext()) |
|
|
|
|
|
|
|
AggregationType.DURATION -> { |
|
|
|
|
|
|
|
selectedReport.results.firstOrNull()?.durationEntries(stat, requireContext()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
AggregationType.MONTH, AggregationType.YEAR -> { |
|
|
|
|
|
|
|
when (this.stat) { |
|
|
|
|
|
|
|
Stat.NUMBER_OF_GAMES, Stat.NUMBER_OF_SETS -> selectedReport.barEntries(this.stat) |
|
|
|
|
|
|
|
else -> selectedReport.lineEntries(this.stat, requireContext()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ds?.let { dataSet -> |
|
|
|
dataSetList.firstOrNull()?.let { dataSet -> |
|
|
|
|
|
|
|
|
|
|
|
this.legendView.prepareWithStat(this.stat, dataSet.entryCount) |
|
|
|
this.legendView.prepareWithStat(this.stat, dataSet.entryCount) |
|
|
|
|
|
|
|
|
|
|
|
// initialize chart |
|
|
|
// initialize chart |
|
|
|
if (this.chartView == null) { |
|
|
|
this.chartContainer.removeAllViews() |
|
|
|
this.chartView = when (dataSet) { |
|
|
|
this.chartView = when (dataSet) { |
|
|
|
is LineDataSet -> LineChart(context) |
|
|
|
is LineDataSet -> LineChart(context) |
|
|
|
is BarDataSet -> BarChart(context) |
|
|
|
is BarDataSet -> BarChart(context) |
|
|
|
else -> null |
|
|
|
else -> null |
|
|
|
} |
|
|
|
} |
|
|
|
this.chartContainer.addView(this.chartView) |
|
|
|
this.chartContainer.addView(this.chartView) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
when (dataSet) { |
|
|
|
when (dataSet) { |
|
|
|
is LineDataSet -> { |
|
|
|
is LineDataSet -> { |
|
|
|
@ -138,8 +118,6 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val axisFormatting = aggregationType.axisFormatting |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.chartView?.let { |
|
|
|
this.chartView?.let { |
|
|
|
it.setStyle(false, axisFormatting, requireContext()) |
|
|
|
it.setStyle(false, axisFormatting, requireContext()) |
|
|
|
it.setOnChartValueSelectedListener(this) |
|
|
|
it.setOnChartValueSelectedListener(this) |
|
|
|
@ -149,6 +127,7 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// OnChartValueSelectedListener |
|
|
|
// OnChartValueSelectedListener |
|
|
|
@ -180,7 +159,6 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co |
|
|
|
|
|
|
|
|
|
|
|
this.legendView.setItemData(this.stat, formattedDate, entryValue, totalStatValue) |
|
|
|
this.legendView.setItemData(this.stat, formattedDate, entryValue, totalStatValue) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |