|
|
|
@ -17,7 +17,6 @@ import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.calculus.* |
|
|
|
import net.pokeranalytics.android.calculus.* |
|
|
|
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.PALineDataSet |
|
|
|
|
|
|
|
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 kotlin.coroutines.CoroutineContext |
|
|
|
@ -46,7 +45,7 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co |
|
|
|
private lateinit var parentActivity: PokerAnalyticsActivity |
|
|
|
private lateinit var parentActivity: PokerAnalyticsActivity |
|
|
|
private lateinit var selectedReport: Report |
|
|
|
private lateinit var selectedReport: Report |
|
|
|
private lateinit var legendView: LegendView |
|
|
|
private lateinit var legendView: LegendView |
|
|
|
private lateinit var chartView: BarLineChartBase<*> |
|
|
|
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 aggregationType: AggregationType = AggregationType.SESSION |
|
|
|
@ -65,33 +64,20 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co |
|
|
|
loadGraph() |
|
|
|
loadGraph() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// OnChartValueSelectedListener |
|
|
|
/** |
|
|
|
override fun onNothingSelected() { |
|
|
|
* Set data |
|
|
|
// nothing to do |
|
|
|
*/ |
|
|
|
} |
|
|
|
fun setData(report: Report, stat: Stat, aggregationType: AggregationType) { |
|
|
|
|
|
|
|
|
|
|
|
override fun onValueSelected(e: Entry?, h: Highlight?) { |
|
|
|
|
|
|
|
e?.let { entry -> |
|
|
|
|
|
|
|
val statEntry = when (entry.data) { |
|
|
|
|
|
|
|
is ObjectIdentifier -> { |
|
|
|
|
|
|
|
val identifier = entry.data as ObjectIdentifier |
|
|
|
|
|
|
|
getRealm().where(identifier.clazz).equalTo("id", identifier.id).findAll().firstOrNull() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
is StatEntry -> entry.data as StatEntry? |
|
|
|
|
|
|
|
else -> null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
statEntry?.let { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val formattedDate = it.entryTitle |
|
|
|
this.selectedReport = report |
|
|
|
val entryValue = it.formattedValue(this.stat, requireContext()) |
|
|
|
this.aggregationType = aggregationType |
|
|
|
val totalStatValue = this.stat.format(entry.y.toDouble(), currency = null) |
|
|
|
this.stat = stat |
|
|
|
|
|
|
|
|
|
|
|
this.legendView.setItemData(this.stat, formattedDate, entryValue, totalStatValue) |
|
|
|
if (isAdded && !isDetached) { |
|
|
|
} |
|
|
|
loadGraph() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Init UI |
|
|
|
* Init UI |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -103,14 +89,6 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co |
|
|
|
this.legendView = LegendView(requireContext()) |
|
|
|
this.legendView = LegendView(requireContext()) |
|
|
|
this.legendContainer.addView(this.legendView) |
|
|
|
this.legendContainer.addView(this.legendView) |
|
|
|
|
|
|
|
|
|
|
|
this.chartView = when (stat.graphType) { |
|
|
|
|
|
|
|
GraphType.LINE -> LineChart(context) |
|
|
|
|
|
|
|
GraphType.BAR -> BarChart(context) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val axisFormatting = aggregationType.axisFormatting |
|
|
|
|
|
|
|
this.chartView.setStyle(false, axisFormatting, requireContext()) |
|
|
|
|
|
|
|
this.chartContainer.addView(this.chartView) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -118,38 +96,41 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun loadGraph() { |
|
|
|
private fun loadGraph() { |
|
|
|
|
|
|
|
|
|
|
|
val graphEntries = when (aggregationType) { |
|
|
|
val ds = when (aggregationType) { |
|
|
|
AggregationType.SESSION -> selectedReport.results.firstOrNull()?.defaultStatEntries(stat) |
|
|
|
AggregationType.SESSION -> selectedReport.results.firstOrNull()?.defaultStatEntries(stat, requireContext()) |
|
|
|
AggregationType.DURATION -> { |
|
|
|
AggregationType.DURATION -> { |
|
|
|
selectedReport.results.firstOrNull()?.durationEntries(stat) |
|
|
|
selectedReport.results.firstOrNull()?.durationEntries(stat, requireContext()) |
|
|
|
} |
|
|
|
} |
|
|
|
AggregationType.MONTH, AggregationType.YEAR -> { |
|
|
|
AggregationType.MONTH, AggregationType.YEAR -> { |
|
|
|
when (this.stat) { |
|
|
|
when (this.stat) { |
|
|
|
Stat.NUMBER_OF_GAMES, Stat.NUMBER_OF_SETS -> selectedReport.barEntries(this.stat) |
|
|
|
Stat.NUMBER_OF_GAMES, Stat.NUMBER_OF_SETS -> selectedReport.barEntries(this.stat) |
|
|
|
else -> selectedReport.lineEntries(this.stat) |
|
|
|
else -> selectedReport.lineEntries(this.stat, requireContext()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
graphEntries?.let { entries -> |
|
|
|
ds?.let { dataSet -> |
|
|
|
|
|
|
|
|
|
|
|
this.legendView.prepareWithStat(this.stat, entries.size) |
|
|
|
this.legendView.prepareWithStat(this.stat, dataSet.entryCount) |
|
|
|
|
|
|
|
|
|
|
|
when (stat.graphType) { |
|
|
|
// initialize chart |
|
|
|
GraphType.LINE -> { |
|
|
|
if (this.chartView == null) { |
|
|
|
val lineChart: LineChart = this.chartView as LineChart |
|
|
|
this.chartView = when (dataSet) { |
|
|
|
|
|
|
|
is LineDataSet -> LineChart(context) |
|
|
|
|
|
|
|
is BarDataSet -> BarChart(context) |
|
|
|
|
|
|
|
else -> null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.chartContainer.addView(this.chartView) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val dataSet = PALineDataSet(entries, this.stat.name, requireContext()) |
|
|
|
when (dataSet) { |
|
|
|
val colors = arrayOf(R.color.green_light).toIntArray() |
|
|
|
is LineDataSet -> { |
|
|
|
dataSet.setColors(colors, context) |
|
|
|
val lineChart: LineChart = this.chartView as LineChart |
|
|
|
dataSet.setDrawCircles(false) |
|
|
|
|
|
|
|
val lineData = LineData(listOf(dataSet)) |
|
|
|
val lineData = LineData(listOf(dataSet)) |
|
|
|
|
|
|
|
|
|
|
|
lineChart.data = lineData |
|
|
|
lineChart.data = lineData |
|
|
|
} |
|
|
|
} |
|
|
|
GraphType.BAR -> { |
|
|
|
is BarDataSet -> { |
|
|
|
val barChart = this.chartView as BarChart |
|
|
|
val barChart = this.chartView as BarChart |
|
|
|
val dataSet = BarDataSet(entries as List<BarEntry>, this.stat.name) |
|
|
|
|
|
|
|
val colors = arrayOf(R.color.green_light).toIntArray() |
|
|
|
val colors = arrayOf(R.color.green_light).toIntArray() |
|
|
|
dataSet.setColors(colors, context) |
|
|
|
dataSet.setColors(colors, context) |
|
|
|
val barData = BarData(listOf(dataSet)) |
|
|
|
val barData = BarData(listOf(dataSet)) |
|
|
|
@ -158,26 +139,48 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val axisFormatting = aggregationType.axisFormatting |
|
|
|
val axisFormatting = aggregationType.axisFormatting |
|
|
|
this.chartView.setStyle(false, axisFormatting, requireContext()) |
|
|
|
|
|
|
|
this.chartView.setOnChartValueSelectedListener(this) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.chartView.highlightValue((entries.size - 1).toFloat(), 0) |
|
|
|
this.chartView?.let { |
|
|
|
|
|
|
|
it.setStyle(false, axisFormatting, requireContext()) |
|
|
|
|
|
|
|
it.setOnChartValueSelectedListener(this) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.selectValue(dataSet.getEntryForIndex(dataSet.entryCount - 1)) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
// OnChartValueSelectedListener |
|
|
|
* Set data |
|
|
|
override fun onNothingSelected() { |
|
|
|
*/ |
|
|
|
// nothing to do |
|
|
|
fun setData(report: Report, stat: Stat, aggregationType: AggregationType) { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.selectedReport = report |
|
|
|
override fun onValueSelected(e: Entry?, h: Highlight?) { |
|
|
|
this.aggregationType = aggregationType |
|
|
|
e?.let { entry -> |
|
|
|
this.stat = stat |
|
|
|
this.selectValue(entry) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isAdded && !isDetached) { |
|
|
|
private fun selectValue(entry: Entry) { |
|
|
|
loadGraph() |
|
|
|
|
|
|
|
|
|
|
|
val statEntry = when (entry.data) { |
|
|
|
|
|
|
|
is ObjectIdentifier -> { |
|
|
|
|
|
|
|
val identifier = entry.data as ObjectIdentifier |
|
|
|
|
|
|
|
getRealm().where(identifier.clazz).equalTo("id", identifier.id).findAll().firstOrNull() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
is StatEntry -> entry.data as StatEntry? |
|
|
|
|
|
|
|
else -> null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
statEntry?.let { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val formattedDate = it.entryTitle |
|
|
|
|
|
|
|
val entryValue = it.formattedValue(this.stat, requireContext()) |
|
|
|
|
|
|
|
val totalStatValue = this.stat.format(entry.y.toDouble(), currency = null) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.legendView.setItemData(this.stat, formattedDate, entryValue, totalStatValue) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |