Skip to content

Commit d75a295

Browse files
committed
Kotlin DataSet
1 parent f47797d commit d75a295

26 files changed

+1051
-1176
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import kotlin.Int
1111
import kotlin.String
1212
import kotlin.arrayOf
1313

14-
open class BarDataSet(yVals: MutableList<BarEntry?>, label: String?) : BarLineScatterCandleBubbleDataSet<BarEntry>(yVals, label), IBarDataSet {
14+
open class BarDataSet(yVals: MutableList<BarEntry?>, label: String = "") : BarLineScatterCandleBubbleDataSet<BarEntry>(yVals, label), IBarDataSet {
1515
/**
1616
* the maximum number of bars that are stacked upon each other, this value
1717
* is calculated from the Entries that are added to the DataSet
@@ -61,14 +61,16 @@ open class BarDataSet(yVals: MutableList<BarEntry?>, label: String?) : BarLineSc
6161
calcEntryCountIncludingStacks(yVals)
6262
}
6363

64-
override fun copy(): BarDataSet {
64+
override fun copy(): DataSet<BarEntry?>? {
6565
val entries: MutableList<BarEntry?> = ArrayList()
66-
for (i in mEntries.indices) {
67-
entries.add(mEntries[i]!!.copy())
66+
mEntries?.let {
67+
for (i in it.indices) {
68+
entries.add(it[i]!!.copy())
69+
}
6870
}
6971
val copied = BarDataSet(entries, label)
7072
copy(copied)
71-
return copied
73+
return copied as DataSet<BarEntry?>?
7274
}
7375

7476
protected fun copy(barDataSet: BarDataSet) {
@@ -143,13 +145,13 @@ open class BarDataSet(yVals: MutableList<BarEntry?>, label: String?) : BarLineSc
143145
override fun calcMinMax(e: BarEntry?) {
144146
if (e != null && !Float.isNaN(e.y)) {
145147
if (e.yVals == null) {
146-
if (e.y < mYMin) mYMin = e.y
148+
if (e.y < yMin) yMin = e.y
147149

148-
if (e.y > mYMax) mYMax = e.y
150+
if (e.y > yMax) yMax = e.y
149151
} else {
150-
if (-e.negativeSum < mYMin) mYMin = -e.negativeSum
152+
if (-e.negativeSum < yMin) yMin = -e.negativeSum
151153

152-
if (e.positiveSum > mYMax) mYMax = e.positiveSum
154+
if (e.positiveSum > yMax) yMax = e.positiveSum
153155
}
154156

155157
calcMinMaxX(e)

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBub
66
/**
77
* Baseclass of all DataSets for Bar-, Line-, Scatter- and CandleStickChart.
88
*/
9-
10-
abstract class BarLineScatterCandleBubbleDataSet<T : Entry>(yVals: MutableList<T?>?, label: String?) :
11-
DataSet<T>(yVals, label), IBarLineScatterCandleBubbleDataSet<T> {
9+
abstract class BarLineScatterCandleBubbleDataSet<T : Entry?>(yVals: MutableList<T?>?, label: String = "") :
10+
DataSet<T>(yVals, label), IBarLineScatterCandleBubbleDataSet<T?> {
1211
/**
1312
* Sets the color that is used for drawing the highlight indicators. Dont
1413
* forget to resolve the color using getResources().getColor(...) or

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import com.github.mikephil.charting.utils.convertDpToPixel
1818
* This is the base dataset of all DataSets. It's purpose is to implement critical methods
1919
* provided by the IDataSet interface.
2020
*/
21-
abstract class BaseDataSet<T : Entry>() : IDataSet<T> {
21+
abstract class BaseDataSet<T : Entry?>() : IDataSet<T> {
2222
/**
2323
* List representing all colors that are used for this DataSet
2424
*/
@@ -236,12 +236,10 @@ abstract class BaseDataSet<T : Entry>() : IDataSet<T> {
236236
mColors.clear()
237237
}
238238

239-
override var label: String?
239+
override var label: String
240240
get() = mLabel
241241
set(value) {
242-
if (value != null) {
243-
mLabel = value
244-
}
242+
mLabel = value
245243
}
246244
override var axisDependency: AxisDependency
247245
get() = mAxisDependency

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

Lines changed: 0 additions & 263 deletions
This file was deleted.

0 commit comments

Comments
 (0)