diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BarDataSet.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BarDataSet.kt index 57e572c7d..59ea04915 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BarDataSet.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BarDataSet.kt @@ -4,12 +4,11 @@ import android.graphics.Color import com.github.mikephil.charting.interfaces.datasets.IBarDataSet import com.github.mikephil.charting.utils.Fill import java.lang.Float -import kotlin.Array import kotlin.Boolean import kotlin.Deprecated import kotlin.Int import kotlin.String -import kotlin.arrayOf +import kotlin.let open class BarDataSet(yVals: MutableList, label: String = "") : BarLineScatterCandleBubbleDataSet(yVals, label), IBarDataSet { /** @@ -44,14 +43,14 @@ open class BarDataSet(yVals: MutableList, label: String = "") : BarLin /** * array of labels used to describe the different values of the stacked bars */ - private var mStackLabels: Array? = arrayOf() + private var mStackLabels: MutableList = mutableListOf() /** * This method is deprecated. * Use getFills() instead. */ @get:Deprecated("") - var gradients: MutableList? = null + var gradients: MutableList = mutableListOf() protected set init { @@ -82,12 +81,14 @@ open class BarDataSet(yVals: MutableList, label: String = "") : BarLin barDataSet.mHighLightAlpha = mHighLightAlpha } - override fun getFills(): MutableList? { - return this.gradients - } + override var fills: MutableList + get() = this.gradients + set(value) { + this.gradients = value + } override fun getFill(index: Int): Fill? { - return gradients!![index % gradients!!.size] + return gradients[index % gradients.size] } @Deprecated("Use getFill(...) instead") @@ -99,22 +100,15 @@ open class BarDataSet(yVals: MutableList, label: String = "") : BarLin * Sets the start and end color for gradient color, ONLY color that should be used for this DataSet. */ fun setGradientColor(startColor: Int, endColor: Int) { - gradients?.clear() - gradients?.add(Fill(startColor, endColor)) + gradients.clear() + gradients.add(Fill(startColor, endColor)) } @Deprecated("Use setFills(...) instead") - fun setGradientColors(gradientColors: MutableList?) { + fun setGradientColors(gradientColors: MutableList) { this.gradients = gradientColors } - /** - * Sets the fills for the bars in this dataset. - */ - fun setFills(fills: MutableList?) { - this.gradients = fills - } - /** * Calculates the total number of entries this DataSet represents, including * stacks. All values belonging to a stack are calculated separately. @@ -158,79 +152,60 @@ open class BarDataSet(yVals: MutableList, label: String = "") : BarLin } } - override fun getStackSize(): Int { - return mStackSize - } + override var stackSize: Int + get() = mStackSize + set(value) { + mStackSize = value + } - override fun isStacked(): Boolean { - return mStackSize > 1 - } + override val isStacked: Boolean + get() = mStackSize > 1 /** * Sets the color used for drawing the bar-shadows. The bar shadows is a * surface behind the bar that indicates the maximum value. Don't for get to * use getResources().getColor(...) to set this. Or Color.rgb(...). */ - fun setBarShadowColor(color: Int) { - mBarShadowColor = color - } - - override fun getBarShadowColor(): Int { - return mBarShadowColor - } + override var barShadowColor: Int + get() = mBarShadowColor + set(value) { + mBarShadowColor = value + } - /** - * Sets the width used for drawing borders around the bars. - * If borderWidth == 0, no border will be drawn. - */ - fun setBarBorderWidth(width: kotlin.Float) { - mBarBorderWidth = width - } + override var barBorderColor: Int + get() = mBarBorderColor + set(value) { + mBarBorderColor = value + } /** - * Returns the width used for drawing borders around the bars. + * The width used for drawing borders around the bars. * If borderWidth == 0, no border will be drawn. */ - override fun getBarBorderWidth(): kotlin.Float { - return mBarBorderWidth - } - - /** - * Sets the color drawing borders around the bars. - */ - fun setBarBorderColor(color: Int) { - mBarBorderColor = color - } - - /** - * Returns the color drawing borders around the bars. - */ - override fun getBarBorderColor(): Int { - return mBarBorderColor - } + override var barBorderWidth: kotlin.Float + get() = mBarBorderWidth + set(value) { + mBarBorderWidth = value + } /** * Set the alpha value (transparency) that is used for drawing the highlight * indicator bar. min = 0 (fully transparent), max = 255 (fully opaque) */ - fun setHighLightAlpha(alpha: Int) { - mHighLightAlpha = alpha - } - - override fun getHighLightAlpha(): Int { - return mHighLightAlpha - } + override var highLightAlpha: Int + get() = mHighLightAlpha + set(value) { + mHighLightAlpha = value + } /** * Sets labels for different values of bar-stacks, in case there are one. */ - fun setStackLabels(labels: Array?) { - mStackLabels = labels - } - - override fun getStackLabels(): Array? { - return mStackLabels - } + override var stackLabels: MutableList + get() = mStackLabels + set(value) { + mStackLabels = value + } override fun getEntryIndex(entry: BarEntry): Int { return this.getEntryIndex(entry) diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/BarHighlighter.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/BarHighlighter.kt index 9be546a73..de40a2a9d 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/BarHighlighter.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/BarHighlighter.kt @@ -14,7 +14,7 @@ open class BarHighlighter(barDataProvider: BarDataProvider) : ChartHighlighter barData.getDataSetByIndex(high.dataSetIndex)?.let { set -> - if (set.isStacked()) { + if (set.isStacked) { return getStackedHighlight( high, set, diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/HorizontalBarHighlighter.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/HorizontalBarHighlighter.kt index bea245f05..680ddbc90 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/HorizontalBarHighlighter.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/HorizontalBarHighlighter.kt @@ -16,7 +16,7 @@ class HorizontalBarHighlighter(dataProvider: BarDataProvider) : BarHighlighter(d val high = getHighlightForX(pos.y.toFloat(), y, x) ?: return null val set = barData.getDataSetByIndex(high.dataSetIndex) - if (set != null && set.isStacked()) { + if (set != null && set.isStacked) { return getStackedHighlight( high, set, diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IBarDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IBarDataSet.kt similarity index 57% rename from MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IBarDataSet.java rename to MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IBarDataSet.kt index e1674fe5f..f91776bd4 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IBarDataSet.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IBarDataSet.kt @@ -1,57 +1,50 @@ -package com.github.mikephil.charting.interfaces.datasets; +package com.github.mikephil.charting.interfaces.datasets -import com.github.mikephil.charting.data.BarEntry; -import com.github.mikephil.charting.utils.Fill; +import com.github.mikephil.charting.data.BarEntry +import com.github.mikephil.charting.utils.Fill -import java.util.List; +interface IBarDataSet : IBarLineScatterCandleBubbleDataSet { + var fills: MutableList -/** - * Created by philipp on 21/10/15. - */ -public interface IBarDataSet extends IBarLineScatterCandleBubbleDataSet { - - List getFills(); - - Fill getFill(int index); + fun getFill(index: Int): Fill? /** - * Returns true if this DataSet is stacked (stacksize > 1) or not. + * Returns true if this DataSet is stacked (stackSize > 1) or not. */ - boolean isStacked(); + val isStacked: Boolean /** * Returns the maximum number of bars that can be stacked upon another in * this DataSet. This should return 1 for non stacked bars, and > 1 for stacked bars. */ - int getStackSize(); + var stackSize: Int /** * Returns the color used for drawing the bar-shadows. The bar shadows is a * surface behind the bar that indicates the maximum value. */ - int getBarShadowColor(); + var barShadowColor: Int /** * Returns the width used for drawing borders around the bars. * If borderWidth == 0, no border will be drawn. */ - float getBarBorderWidth(); + var barBorderWidth: Float /** * Returns the color drawing borders around the bars. */ - int getBarBorderColor(); + var barBorderColor: Int /** * Returns the alpha value (transparency) that is used for drawing the * highlight indicator. */ - int getHighLightAlpha(); - + var highLightAlpha: Int /** * Returns the labels used for the different value-stacks in the legend. * This is only relevant for stacked bar entries. */ - String[] getStackLabels(); + var stackLabels: MutableList } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarChartRenderer.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarChartRenderer.kt index 593e9f058..8a64ba96e 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarChartRenderer.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarChartRenderer.kt @@ -170,7 +170,7 @@ open class BarChartRenderer( } trans!!.pointValuesToPixel(buffer.buffer) - val isCustomFill = dataSet.fills != null && dataSet.fills.isNotEmpty() + val isCustomFill = dataSet.fills.isNotEmpty() val isSingleColor = dataSet.colors.size == 1 val isInverted = dataProvider.isInverted(dataSet.axisDependency) @@ -197,16 +197,15 @@ open class BarChartRenderer( } if (isCustomFill) { - dataSet.getFill(pos) - .fillRect( - canvas, paintRender, - buffer.buffer[j], - buffer.buffer[j + 1], - buffer.buffer[j + 2], - buffer.buffer[j + 3], - if (isInverted) Fill.Direction.DOWN else Fill.Direction.UP, - roundedBarRadius - ) + dataSet.getFill(pos)?.fillRect( + canvas, paintRender, + buffer.buffer[j], + buffer.buffer[j + 1], + buffer.buffer[j + 2], + buffer.buffer[j + 3], + if (isInverted) Fill.Direction.DOWN else Fill.Direction.UP, + roundedBarRadius + ) } else { if (drawRoundedBars) { canvas.drawRoundRect( diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/HorizontalBarChartRenderer.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/HorizontalBarChartRenderer.kt index fa88343b1..5c38011ef 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/HorizontalBarChartRenderer.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/HorizontalBarChartRenderer.kt @@ -108,7 +108,7 @@ open class HorizontalBarChartRenderer( trans!!.pointValuesToPixel(buffer.buffer) - val isCustomFill = dataSet.fills != null && dataSet.fills.isNotEmpty() + val isCustomFill = dataSet.fills.isNotEmpty() val isSingleColor = dataSet.colors.size == 1 val isInverted = dataProvider.isInverted(dataSet.axisDependency) @@ -136,8 +136,7 @@ open class HorizontalBarChartRenderer( } if (isCustomFill) { - dataSet.getFill(pos) - .fillRect( + dataSet.getFill(pos)?.fillRect( canvas, paintRender, buffer.buffer[j], buffer.buffer[j + 1], diff --git a/app/src/main/kotlin/info/appdev/chartexample/CombinedChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/CombinedChartActivity.kt index 97049bce9..a37f0ea07 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/CombinedChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/CombinedChartActivity.kt @@ -137,7 +137,7 @@ class CombinedChartActivity : DemoBase() { set1.axisDependency = YAxis.AxisDependency.LEFT val set2 = BarDataSet(entries2, "") - set2.stackLabels = arrayOf("Stack 1", "Stack 2") + set2.stackLabels = mutableListOf("Stack 1", "Stack 2") set2.setColors(Color.rgb(61, 165, 255), Color.rgb(23, 197, 255)) set2.setSingleValueTextColor(Color.rgb(61, 165, 255)) set2.valueTextSize = 10f diff --git a/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivity.kt index bc223b3a6..049a5c4fc 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivity.kt @@ -119,7 +119,7 @@ class StackedBarActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSele set1 = BarDataSet(values, "Statistics Vienna 2014") set1.isDrawIcons = false set1.setColors(*this.colors) - set1.stackLabels = arrayOf("Births", "Divorces", "Marriages") + set1.stackLabels = mutableListOf("Births", "Divorces", "Marriages") val dataSets = ArrayList() dataSets.add(set1) diff --git a/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivityNegative.kt b/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivityNegative.kt index 09c5f9ec3..9bd6786ae 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivityNegative.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivityNegative.kt @@ -106,7 +106,7 @@ class StackedBarActivityNegative : DemoBase(), OnChartValueSelectedListener { set.valueTextSize = 7f set.axisDependency = YAxis.AxisDependency.RIGHT set.setColors(Color.rgb(67, 67, 72), Color.rgb(124, 181, 236)) - set.stackLabels = arrayOf("Men", "Women") + set.stackLabels = mutableListOf("Men", "Women") val data = BarData(set) data.barWidth = 8.5f