Skip to content

Commit 8f0e0da

Browse files
committed
Kotlin isDrawValues
1 parent 2108c44 commit 8f0e0da

34 files changed

+54
-59
lines changed

MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,11 @@ abstract class BaseDataSet<T : Entry>() : IDataSet<T> {
138138
mFormLineDashEffect = value
139139
}
140140

141-
override val isDrawValues: Boolean
141+
override var isDrawValues: Boolean
142142
get() = mIsDrawValues
143+
set(value) {
144+
mIsDrawValues = value
145+
}
143146

144147
override var isDrawIcons: Boolean
145148
get() = mIsDrawIcons
@@ -309,10 +312,6 @@ abstract class BaseDataSet<T : Entry>() : IDataSet<T> {
309312
mIsVisible = value
310313
}
311314

312-
override fun setDrawValues(enabled: Boolean) {
313-
this.mDrawValues = enabled
314-
}
315-
316315
override fun getIndexInEntries(xIndex: Int): Int {
317316
for (i in 0..<entryCount) {
318317
if (xIndex.toFloat() == getEntryForIndex(i)!!.x) return i

MPChartLib/src/main/java/com/github/mikephil/charting/data/DataSet.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.util.ArrayList;
88
import java.util.List;
99

10+
import androidx.annotation.NonNull;
11+
1012
/**
1113
* The DataSet class represents one group or type of entries (Entry) in the
1214
* Chart that belong together. It is designed to logically separate different
@@ -254,7 +256,7 @@ public void clear() {
254256
}
255257

256258
@Override
257-
public boolean addEntry(T entry) {
259+
public boolean addEntry(@NonNull T entry) {
258260
List<T> values = getEntries();
259261
if (values == null) {
260262
values = new ArrayList<>();

MPChartLib/src/main/java/com/github/mikephil/charting/data/LineDataSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public void disableDashedLine() {
224224

225225
@Override
226226
public boolean isDashedLineEnabled() {
227-
return mDashPathEffect == null ? false : true;
227+
return mDashPathEffect != null;
228228
}
229229

230230
@Override

MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/dataprovider/ChartInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public interface ChartInterface {
5656
IValueFormatter getDefaultValueFormatter();
5757

5858
@Nullable
59-
ChartData getData();
59+
ChartData getData();
6060

6161
int getMaxVisibleCount();
6262
}

MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IDataSet.kt

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ interface IDataSet<T : Entry> {
8181
* INFORMATION: This method does calculations at runtime. Do
8282
* not over-use in performance critical situations.
8383
*/
84-
fun getEntriesForXValue(xValue: Float): MutableList<T?>?
84+
fun getEntriesForXValue(xValue: Float): MutableList<T>?
8585

8686
/**
8787
* Returns the Entry object found at the given index (NOT xIndex) in the values array.
@@ -107,8 +107,7 @@ interface IDataSet<T : Entry> {
107107
* Returns the position of the provided entry in the DataSets Entry array.
108108
* Returns -1 if doesn't exist.
109109
*/
110-
int getEntryIndex(T entry);
111-
110+
fun getEntryIndex(entry: T): Int
112111

113112
/**
114113
* This method returns the actual
@@ -126,7 +125,6 @@ interface IDataSet<T : Entry> {
126125
*/
127126
fun addEntry(entry: T): Boolean
128127

129-
130128
/**
131129
* Adds an Entry to the DataSet dynamically.
132130
* Entries are added to their appropriate index in the values array respective to their x-position.
@@ -274,16 +272,11 @@ interface IDataSet<T : Entry> {
274272
val formLineDashEffect: DashPathEffect?
275273

276274
/**
277-
* set this to true to draw y-values on the chart.
275+
* Returns true if y-value drawing is enabled, false if not
278276
* NOTE (for bar and line charts): if `maxVisibleCount` is reached, no values will be drawn even
279277
* if this is enabled
280278
*/
281-
fun setDrawValues(enabled: Boolean)
282-
283-
/**
284-
* Returns true if y-value drawing is enabled, false if not
285-
*/
286-
val isDrawValues: Boolean
279+
var isDrawValues: Boolean
287280

288281
/**
289282
* Returns true if y-icon drawing is enabled, false if not

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class AnotherBarActivity : DemoBase(), OnSeekBarChangeListener {
9898
} else {
9999
set1 = BarDataSet(values, "Data Set")
100100
set1.setColors(*ColorTemplate.VORDIPLOM_COLORS)
101-
set1.setDrawValues(false)
101+
set1.isDrawValues = false
102102

103103
val dataSets = ArrayList<IBarDataSet?>()
104104
dataSets.add(set1)
@@ -126,7 +126,8 @@ class AnotherBarActivity : DemoBase(), OnSeekBarChangeListener {
126126
}
127127

128128
R.id.actionToggleValues -> {
129-
for (set in chart!!.data!!.dataSets) set.setDrawValues(!set.isDrawValues)
129+
for (set in chart?.data?.dataSets!!)
130+
set.isDrawValues = !set.isDrawValues
130131

131132
chart!!.invalidate()
132133
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect
205205

206206
R.id.actionToggleValues -> {
207207
for (set in chart!!.data!!.dataSets)
208-
set.setDrawValues(!set.isDrawValues)
208+
set.isDrawValues = !set.isDrawValues
209209

210210
chart!!.invalidate()
211211
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class BarChartActivityMultiDataset : DemoBase(), OnSeekBarChangeListener, OnChar
195195
}
196196

197197
R.id.actionToggleValues -> {
198-
for (set in chart!!.data!!.dataSets) set.setDrawValues(!set.isDrawValues)
198+
for (set in chart!!.data!!.dataSets) set.isDrawValues = !set.isDrawValues
199199

200200
chart!!.invalidate()
201201
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class BarChartActivitySinus : DemoBase(), OnSeekBarChangeListener {
140140
}
141141

142142
R.id.actionToggleValues -> {
143-
for (set in chart!!.data!!.dataSets) set.setDrawValues(!set.isDrawValues)
143+
for (set in chart!!.data!!.dataSets) set.isDrawValues = !set.isDrawValues
144144

145145
chart!!.invalidate()
146146
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,17 @@ class BubbleChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSel
126126
val set1 = BubbleDataSet(values1, "DS 1")
127127
set1.isDrawIcons = false
128128
set1.setColor(ColorTemplate.COLORFUL_COLORS[0], 130)
129-
set1.setDrawValues(true)
129+
set1.isDrawValues = true
130130

131131
val set2 = BubbleDataSet(values2, "DS 2")
132132
set2.isDrawIcons = false
133133
set2.iconsOffset = MPPointF(0f, 15f)
134134
set2.setColor(ColorTemplate.COLORFUL_COLORS[1], 130)
135-
set2.setDrawValues(true)
135+
set2.isDrawValues = true
136136

137137
val set3 = BubbleDataSet(values3, "DS 3")
138138
set3.setColor(ColorTemplate.COLORFUL_COLORS[2], 130)
139-
set3.setDrawValues(true)
139+
set3.isDrawValues = true
140140

141141
val dataSets = ArrayList<IBubbleDataSet?>()
142142
dataSets.add(set1) // add the data sets
@@ -169,7 +169,7 @@ class BubbleChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSel
169169
}
170170

171171
R.id.actionToggleValues -> {
172-
for (set in chart!!.data!!.dataSets) set.setDrawValues(!set.isDrawValues)
172+
for (set in chart!!.data!!.dataSets) set.isDrawValues = !set.isDrawValues
173173

174174
chart!!.invalidate()
175175
}

0 commit comments

Comments
 (0)