Skip to content

Commit 42d06c5

Browse files
authored
Merge pull request #634 from AppDevNext/ReworkValueTextColor
Rework ValueTextColor
2 parents 56dcc78 + 2483f4d commit 42d06c5

File tree

8 files changed

+24
-18
lines changed

8 files changed

+24
-18
lines changed

app/src/main/kotlin/info/appdev/chartexample/CombinedChartActivity.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class CombinedChartActivity : DemoBase() {
112112
set.lineMode = LineDataSet.Mode.CUBIC_BEZIER
113113
set.isDrawValues = true
114114
set.valueTextSize = 10f
115-
set.setSingleValueTextColor(Color.rgb(240, 238, 70))
115+
set.valueTextColor = Color.rgb(240, 238, 70)
116116

117117
set.axisDependency = YAxis.AxisDependency.LEFT
118118
d.addDataSet(set)
@@ -133,14 +133,14 @@ class CombinedChartActivity : DemoBase() {
133133

134134
val set1 = BarDataSet(entries1, "Bar 1")
135135
set1.color = Color.rgb(60, 220, 78)
136-
set1.setSingleValueTextColor(Color.rgb(60, 220, 78))
136+
set1.valueTextColor = Color.rgb(60, 220, 78)
137137
set1.valueTextSize = 10f
138138
set1.axisDependency = YAxis.AxisDependency.LEFT
139139

140140
val set2 = BarDataSet(entries2, "")
141141
set2.stackLabels = mutableListOf("Stack 1", "Stack 2")
142142
set2.setColors(Color.rgb(61, 165, 255), Color.rgb(23, 197, 255))
143-
set2.setSingleValueTextColor(Color.rgb(61, 165, 255))
143+
set2.valueTextColor = Color.rgb(61, 165, 255)
144144
set2.valueTextSize = 10f
145145
set2.axisDependency = YAxis.AxisDependency.LEFT
146146

@@ -215,7 +215,7 @@ class CombinedChartActivity : DemoBase() {
215215
val set = BubbleDataSet(entries, "Bubble DataSet")
216216
set.setColors(*ColorTemplate.VORDIPLOM_COLORS)
217217
set.valueTextSize = 10f
218-
set.setSingleValueTextColor(Color.WHITE)
218+
set.valueTextColor = Color.WHITE
219219
set.highlightCircleWidth = 1.5f
220220
set.isDrawValues = true
221221
bd.addDataSet(set)

app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener {
127127
set.setCircleColor(color)
128128
set.highLightColor = color
129129
set.valueTextSize = 10f
130-
set.setSingleValueTextColor(color)
130+
set.valueTextColor = color
131131

132132
data.addDataSet(set)
133133
data.notifyDataChanged()

app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener {
126126
val set1 = LineDataSet(values, "DataSet 1")
127127
set1.axisDependency = AxisDependency.LEFT
128128
set1.color = holoBlue
129-
set1.setSingleValueTextColor(holoBlue)
129+
set1.valueTextColor = holoBlue
130130
set1.lineWidth = 1.5f
131131
set1.isDrawCirclesEnabled = false
132132
set1.isDrawValues = false

app/src/main/kotlin/info/appdev/chartexample/RealtimeLineChartActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class RealtimeLineChartActivity : DemoBase(), OnChartValueSelectedListener {
122122
set.fillAlpha = 65
123123
set.fillColor = ColorTemplate.holoBlue
124124
set.highLightColor = Color.rgb(244, 117, 117)
125-
set.setSingleValueTextColor(Color.WHITE)
125+
set.valueTextColor = Color.WHITE
126126
set.valueTextSize = 9f
127127
set.isDrawValues = false
128128
return set

app/src/main/kotlin/info/appdev/chartexample/fragments/SimpleFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ abstract class SimpleFragment : Fragment() {
101101
val ds1 = PieDataSet(entries1, "Quarterly Revenues 2015")
102102
ds1.setColors(*ColorTemplate.VORDIPLOM_COLORS)
103103
ds1.sliceSpace = 2f
104-
ds1.setSingleValueTextColor(Color.WHITE)
104+
ds1.valueTextColor = Color.WHITE
105105
ds1.valueTextSize = 12f
106106

107107
val d = PieData(ds1)

chartLib/src/main/kotlin/info/appdev/charting/data/BaseDataSet.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,19 +266,24 @@ abstract class BaseDataSet<T : Entry>() : IDataSet<T> {
266266
return mValueFormatter == null
267267
}
268268

269-
override fun setSingleValueTextColor(value: Int) {
270-
mValueColors.clear()
271-
mValueColors.add(value)
272-
}
273-
274269
override var valueTextColors: MutableList<Int>
275270
get() = mValueColors
276271
set(value) {
277272
mValueColors = value
278273
}
279274

280-
override fun getValueTextColor(index: Int): Int {
281-
return mValueColors[index % mValueColors.size]
275+
override var valueTextColor: Int
276+
get() = if (mValueColors.isEmpty())
277+
0
278+
else
279+
mValueColors[0]
280+
set(value) {
281+
mValueColors.clear()
282+
mValueColors.add(value)
283+
}
284+
285+
override fun getValueTextColor(value: Int): Int {
286+
return mValueColors[value % mValueColors.size]
282287
}
283288

284289
override var valueTypeface: Typeface?

chartLib/src/main/kotlin/info/appdev/charting/data/ChartData.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ abstract class ChartData<T : IDataSet<out Entry>> : Serializable {
551551
*/
552552
fun setValueTextColor(color: Int) {
553553
for (set in this.dataSets!!) {
554-
set.setSingleValueTextColor(color)
554+
set.valueTextColor = color
555555
}
556556
}
557557

chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IDataSet.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,12 @@ interface IDataSet<T : Entry> {
225225
*/
226226
fun needsFormatter(): Boolean
227227

228-
fun setSingleValueTextColor(value: Int)
229228
/**
230229
* Sets the color the value-labels of this DataSet should have.
231230
*/
232-
fun getValueTextColor(index: Int): Int
231+
var valueTextColor: Int
232+
// This getter is necessary because of the parameter value
233+
fun getValueTextColor(value: Int): Int
233234

234235
var valueTextColors: MutableList<Int>
235236

0 commit comments

Comments
 (0)