Skip to content

Commit 484b5fa

Browse files
authored
Merge pull request #497 from AppDevNext/KotlinBarLineScatterCandleBubbleDataSet
Kotlin BarLineScatterCandleBubbleDataSet
2 parents a4abdcf + 7ea5184 commit 484b5fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1745
-2074
lines changed

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

Lines changed: 17 additions & 23 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
@@ -55,20 +55,22 @@ open class BarDataSet(yVals: MutableList<BarEntry?>, label: String?) : BarLineSc
5555
protected set
5656

5757
init {
58-
mHighLightColor = Color.rgb(0, 0, 0)
58+
highLightColor = Color.rgb(0, 0, 0)
5959

6060
calcStackSize(yVals)
6161
calcEntryCountIncludingStacks(yVals)
6262
}
6363

64-
override fun copy(): DataSet<BarEntry?> {
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) {
@@ -85,14 +87,10 @@ open class BarDataSet(yVals: MutableList<BarEntry?>, label: String?) : BarLineSc
8587
}
8688

8789
override fun getFill(index: Int): Fill? {
88-
return gradients!!.get(index % gradients!!.size)
90+
return gradients!![index % gradients!!.size]
8991
}
9092

91-
/**
92-
* This method is deprecated.
93-
* Use getFill(...) instead.
94-
*/
95-
@Deprecated("")
93+
@Deprecated("Use getFill(...) instead")
9694
fun getGradient(index: Int): Fill? {
9795
return getFill(index)
9896
}
@@ -105,11 +103,7 @@ open class BarDataSet(yVals: MutableList<BarEntry?>, label: String?) : BarLineSc
105103
gradients!!.add(Fill(startColor, endColor))
106104
}
107105

108-
/**
109-
* This method is deprecated.
110-
* Use setFills(...) instead.
111-
*/
112-
@Deprecated("")
106+
@Deprecated("Use setFills(...) instead")
113107
fun setGradientColors(gradientColors: MutableList<Fill?>?) {
114108
this.gradients = gradientColors
115109
}
@@ -137,7 +131,7 @@ open class BarDataSet(yVals: MutableList<BarEntry?>, label: String?) : BarLineSc
137131
}
138132

139133
/**
140-
* calculates the maximum stacksize that occurs in the Entries array of this
134+
* calculates the maximum stackSize that occurs in the Entries array of this
141135
* DataSet
142136
*/
143137
private fun calcStackSize(yVals: MutableList<BarEntry?>) {
@@ -151,13 +145,13 @@ open class BarDataSet(yVals: MutableList<BarEntry?>, label: String?) : BarLineSc
151145
override fun calcMinMax(e: BarEntry?) {
152146
if (e != null && !Float.isNaN(e.y)) {
153147
if (e.yVals == null) {
154-
if (e.y < mYMin) mYMin = e.y
148+
if (e.y < yMin) yMin = e.y
155149

156-
if (e.y > mYMax) mYMax = e.y
150+
if (e.y > yMax) yMax = e.y
157151
} else {
158-
if (-e.negativeSum < mYMin) mYMin = -e.negativeSum
152+
if (-e.negativeSum < yMin) yMin = -e.negativeSum
159153

160-
if (e.positiveSum > mYMax) mYMax = e.positiveSum
154+
if (e.positiveSum > yMax) yMax = e.positiveSum
161155
}
162156

163157
calcMinMaxX(e)
@@ -238,7 +232,7 @@ open class BarDataSet(yVals: MutableList<BarEntry?>, label: String?) : BarLineSc
238232
return mStackLabels
239233
}
240234

241-
override fun getEntryIndex(entry: BarEntry?): Int {
235+
override fun getEntryIndex(entry: BarEntry): Int {
242236
return this.getEntryIndex(entry)
243237
}
244238
}

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

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.github.mikephil.charting.data
2+
3+
import android.graphics.Color
4+
import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet
5+
6+
/**
7+
* Baseclass of all DataSets for Bar-, Line-, Scatter- and CandleStickChart.
8+
*/
9+
abstract class BarLineScatterCandleBubbleDataSet<T : Entry?>(yVals: MutableList<T?>?, label: String = "") :
10+
DataSet<T>(yVals, label), IBarLineScatterCandleBubbleDataSet<T?> {
11+
/**
12+
* Sets the color that is used for drawing the highlight indicators. Dont
13+
* forget to resolve the color using getResources().getColor(...) or
14+
* Color.rgb(...).
15+
*/
16+
override var highLightColor: Int = Color.rgb(255, 187, 115)
17+
18+
protected fun copy(barLineScatterCandleBubbleDataSet: BarLineScatterCandleBubbleDataSet<*>) {
19+
super.copy((barLineScatterCandleBubbleDataSet as BaseDataSet<*>?)!!)
20+
barLineScatterCandleBubbleDataSet.highLightColor = this.highLightColor
21+
}
22+
}

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

0 commit comments

Comments
 (0)