Skip to content

Commit 65a1ece

Browse files
committed
Kotlin isDrawValues
1 parent ff7c650 commit 65a1ece

35 files changed

+54
-58
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
@@ -139,8 +139,11 @@ abstract class BaseDataSet<T : Entry>() : IDataSet<T> {
139139
mFormLineDashEffect = value
140140
}
141141

142-
override val isDrawValues: Boolean
142+
override var isDrawValues: Boolean
143143
get() = mIsDrawValues
144+
set(value) {
145+
mIsDrawValues = value
146+
}
144147

145148
override var isDrawIcons: Boolean
146149
get() = mIsDrawIcons
@@ -310,10 +313,6 @@ abstract class BaseDataSet<T : Entry>() : IDataSet<T> {
310313
mIsVisible = value
311314
}
312315

313-
override fun setDrawValues(enabled: Boolean) {
314-
this.mDrawValues = enabled
315-
}
316-
317316
override fun getIndexInEntries(xIndex: Int): Int {
318317
for (i in 0..<entryCount) {
319318
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
@@ -225,7 +225,7 @@ public void disableDashedLine() {
225225

226226
@Override
227227
public boolean isDashedLineEnabled() {
228-
return mDashPathEffect == null ? false : true;
228+
return mDashPathEffect != null;
229229
}
230230

231231
@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: 3 additions & 9 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.
@@ -125,7 +125,6 @@ interface IDataSet<T : Entry> {
125125
*/
126126
fun addEntry(entry: T): Boolean
127127

128-
129128
/**
130129
* Adds an Entry to the DataSet dynamically.
131130
* Entries are added to their appropriate index in the values array respective to their x-position.
@@ -273,16 +272,11 @@ interface IDataSet<T : Entry> {
273272
val formLineDashEffect: DashPathEffect?
274273

275274
/**
276-
* set this to true to draw y-values on the chart.
275+
* Returns true if y-value drawing is enabled, false if not
277276
* NOTE (for bar and line charts): if `maxVisibleCount` is reached, no values will be drawn even
278277
* if this is enabled
279278
*/
280-
fun setDrawValues(enabled: Boolean)
281-
282-
/**
283-
* Returns true if y-value drawing is enabled, false if not
284-
*/
285-
val isDrawValues: Boolean
279+
var isDrawValues: Boolean
286280

287281
/**
288282
* 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
@@ -96,7 +96,7 @@ class AnotherBarActivity : DemoBase(), OnSeekBarChangeListener {
9696
} else {
9797
set1 = BarDataSet(values, "Data Set")
9898
set1.setColors(*ColorTemplate.VORDIPLOM_COLORS)
99-
set1.setDrawValues(false)
99+
set1.isDrawValues = false
100100

101101
val dataSets = ArrayList<IBarDataSet?>()
102102
dataSets.add(set1)
@@ -124,7 +124,8 @@ class AnotherBarActivity : DemoBase(), OnSeekBarChangeListener {
124124
}
125125

126126
R.id.actionToggleValues -> {
127-
for (set in chart!!.data!!.dataSets) set.setDrawValues(!set.isDrawValues)
127+
for (set in chart?.data?.dataSets!!)
128+
set.isDrawValues = !set.isDrawValues
128129

129130
chart!!.invalidate()
130131
}

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

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

204204
R.id.actionToggleValues -> {
205205
for (set in chart!!.data!!.dataSets)
206-
set.setDrawValues(!set.isDrawValues)
206+
set.isDrawValues = !set.isDrawValues
207207

208208
chart!!.invalidate()
209209
}

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

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

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

198198
chart!!.invalidate()
199199
}

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

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

133133
R.id.actionToggleValues -> {
134-
for (set in binding.chart1.data!!.dataSets) set.setDrawValues(!set.isDrawValues)
134+
for (set in binding.chart1.data!!.dataSets) set.isDrawValues = !set.isDrawValues
135135

136136
binding.chart1.invalidate()
137137
}

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

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

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

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

139139
val dataSets = ArrayList<IBubbleDataSet?>()
140140
dataSets.add(set1) // add the data sets
@@ -167,7 +167,7 @@ class BubbleChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSel
167167
}
168168

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

172172
chart!!.invalidate()
173173
}

0 commit comments

Comments
 (0)