From 8f6176064a59b741dfa7b7536055a566139aa864 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 29 Apr 2019 10:32:15 +0200 Subject: [PATCH 1/3] Fixing distribution chart bar colors --- app/build.gradle | 2 +- .../java/net/pokeranalytics/android/calculus/Report.kt | 2 +- .../net/pokeranalytics/android/ui/graph/DataSetFactory.kt | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 758e8fb3..3da9bc75 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -28,7 +28,7 @@ android { applicationId "net.pokeranalytics.android" minSdkVersion 23 targetSdkVersion 28 - versionCode 19 + versionCode 22 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/net/pokeranalytics/android/calculus/Report.kt b/app/src/main/java/net/pokeranalytics/android/calculus/Report.kt index bac8ab34..c795e299 100644 --- a/app/src/main/java/net/pokeranalytics/android/calculus/Report.kt +++ b/app/src/main/java/net/pokeranalytics/android/calculus/Report.kt @@ -439,7 +439,7 @@ class ComputedResults(group: ComputableGroup, shouldManageMultiGroupProgressValu } } - return DataSetFactory.barDataSetInstance(entries, stat.name, context) + return DataSetFactory.barDataSetInstance(entries, stat.name, context, colors) } val isEmpty: Boolean diff --git a/app/src/main/java/net/pokeranalytics/android/ui/graph/DataSetFactory.kt b/app/src/main/java/net/pokeranalytics/android/ui/graph/DataSetFactory.kt index 4ca91b45..92da7ca9 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/graph/DataSetFactory.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/graph/DataSetFactory.kt @@ -24,10 +24,14 @@ class DataSetFactory { return lineDataSet } - fun barDataSetInstance(entries: List, label: String, context: Context) : BarDataSet { + fun barDataSetInstance(entries: List, label: String, context: Context, colors: MutableList? = null) : BarDataSet { val barDataSet = BarDataSet(entries, label) - barDataSet.color = context.getColor(R.color.chart_bar) + if (colors != null) { + barDataSet.colors = colors + } else { + barDataSet.color = context.getColor(R.color.chart_bar) + } barDataSet.highLightColor = context.getColor(R.color.chart_selected_bar) barDataSet.setDrawValues(false) return barDataSet From 1c2b5b55b5c8134d86d126e098a4ccaf59013781 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 29 Apr 2019 10:35:48 +0200 Subject: [PATCH 2/3] Fixing multilines legend width --- app/src/main/res/layout/layout_legend_color.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/res/layout/layout_legend_color.xml b/app/src/main/res/layout/layout_legend_color.xml index b51c93be..7fd49b54 100644 --- a/app/src/main/res/layout/layout_legend_color.xml +++ b/app/src/main/res/layout/layout_legend_color.xml @@ -55,8 +55,10 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="16dp" + android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@+id/stat2Value" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/stat2Name" tools:text="$2000" /> From 2892b9325dd94176d2e0d6a97b462609ae855c3d Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 29 Apr 2019 10:55:24 +0200 Subject: [PATCH 3/3] Changes the color of the circle in the multilines legend when changing dataset --- .../android/ui/fragment/GraphFragment.kt | 13 +++++++++---- .../android/ui/view/LegendView.kt | 2 +- .../android/ui/view/MultiLineLegendView.kt | 19 +++++++++++++++++-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/ui/fragment/GraphFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/fragment/GraphFragment.kt index 47646238..a0f86e45 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/fragment/GraphFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/fragment/GraphFragment.kt @@ -9,6 +9,7 @@ import com.github.mikephil.charting.charts.BarLineChartBase import com.github.mikephil.charting.charts.LineChart import com.github.mikephil.charting.data.* import com.github.mikephil.charting.highlight.Highlight +import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet import com.github.mikephil.charting.listener.OnChartValueSelectedListener import kotlinx.android.synthetic.main.fragment_graph.* import net.pokeranalytics.android.R @@ -132,7 +133,7 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { this.legendView.prepareWithStat(this.stat, dataSet.entryCount, this.style) if (dataSet.entryCount > 0) { val entry = dataSet.getEntryForIndex(dataSet.entryCount - 1) - this.selectValue(entry, dataSet.label) + this.selectValue(entry, dataSet) } } @@ -182,12 +183,14 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { } } + val dataSet = this.chartView?.data?.getDataSetForEntry(e) + e?.let { entry -> - this.selectValue(entry, groupName) + this.selectValue(entry, dataSet) } } - private fun selectValue(entry: Entry, groupName: String) { + private fun selectValue(entry: Entry, dataSet: IBarLineScatterCandleBubbleDataSet? = null) { val statEntry = when (entry.data) { is ObjectIdentifier -> { @@ -199,8 +202,10 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { } statEntry?.let { + val groupName = dataSet?.label ?: "" + val color = dataSet?.color val legendValue = it.legendValues(stat, entry, this.style, groupName, requireContext()) - this.legendView.setItemData(legendValue) + this.legendView.setItemData(legendValue, color) } } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/LegendView.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/LegendView.kt index 1a46c2a0..f00f98cc 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/view/LegendView.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/LegendView.kt @@ -100,7 +100,7 @@ open class LegendView : FrameLayout { /** * */ - open fun setItemData(content: LegendContent) { + open fun setItemData(content: LegendContent, color: Int?) { if (content is DefaultLegendValues) { diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/MultiLineLegendView.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/MultiLineLegendView.kt index 79c84b2c..53bc4237 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/view/MultiLineLegendView.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/MultiLineLegendView.kt @@ -1,7 +1,12 @@ package net.pokeranalytics.android.ui.view import android.content.Context -import kotlinx.android.synthetic.main.layout_legend_default.view.* +import android.graphics.drawable.GradientDrawable +import kotlinx.android.synthetic.main.layout_legend_color.view.* +import kotlinx.android.synthetic.main.layout_legend_default.view.stat1Name +import kotlinx.android.synthetic.main.layout_legend_default.view.stat1Value +import kotlinx.android.synthetic.main.layout_legend_default.view.stat2Name +import kotlinx.android.synthetic.main.layout_legend_default.view.stat2Value import net.pokeranalytics.android.R import net.pokeranalytics.android.calculus.Stat import net.pokeranalytics.android.calculus.TextFormat @@ -24,7 +29,7 @@ class MultiLineLegendView(context: Context) : LegendView(context = context) { override fun prepareWithStat(stat: Stat, counter: Int?, style: GraphFragment.Style) { } - override fun setItemData(content: LegendContent) { + override fun setItemData(content: LegendContent, color: Int?) { if (content is MultilineLegendValues) { @@ -33,6 +38,16 @@ class MultiLineLegendView(context: Context) : LegendView(context = context) { this.stat1Value.setTextFormat(content.leftFormat, context) this.stat2Value.setTextFormat(content.rightFormat, context) + + color?.let { + val drawable = this.coloredCircle.background + when (drawable) { + is GradientDrawable -> { + drawable.setColor(it) + } else -> {} + } + } + } }