Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<BarEntry>, label: String = "") : BarLineScatterCandleBubbleDataSet<BarEntry>(yVals, label), IBarDataSet {
/**
Expand Down Expand Up @@ -44,14 +43,14 @@ open class BarDataSet(yVals: MutableList<BarEntry>, label: String = "") : BarLin
/**
* array of labels used to describe the different values of the stacked bars
*/
private var mStackLabels: Array<String?>? = arrayOf<String?>()
private var mStackLabels: MutableList<String> = mutableListOf()

/**
* This method is deprecated.
* Use getFills() instead.
*/
@get:Deprecated("")
var gradients: MutableList<Fill>? = null
var gradients: MutableList<Fill> = mutableListOf()
protected set

init {
Expand Down Expand Up @@ -82,12 +81,14 @@ open class BarDataSet(yVals: MutableList<BarEntry>, label: String = "") : BarLin
barDataSet.mHighLightAlpha = mHighLightAlpha
}

override fun getFills(): MutableList<Fill>? {
return this.gradients
}
override var fills: MutableList<Fill>
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")
Expand All @@ -99,22 +100,15 @@ open class BarDataSet(yVals: MutableList<BarEntry>, 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<Fill>?) {
fun setGradientColors(gradientColors: MutableList<Fill>) {
this.gradients = gradientColors
}

/**
* Sets the fills for the bars in this dataset.
*/
fun setFills(fills: MutableList<Fill>?) {
this.gradients = fills
}

/**
* Calculates the total number of entries this DataSet represents, including
* stacks. All values belonging to a stack are calculated separately.
Expand Down Expand Up @@ -158,79 +152,60 @@ open class BarDataSet(yVals: MutableList<BarEntry>, 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<String?>?) {
mStackLabels = labels
}

override fun getStackLabels(): Array<String?>? {
return mStackLabels
}
override var stackLabels: MutableList<String>
get() = mStackLabels
set(value) {
mStackLabels = value
}

override fun getEntryIndex(entry: BarEntry): Int {
return this.getEntryIndex(entry)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ open class BarHighlighter(barDataProvider: BarDataProvider) : ChartHighlighter<B

provider.barData?.let { barData ->
barData.getDataSetByIndex(high.dataSetIndex)?.let { set ->
if (set.isStacked()) {
if (set.isStacked) {
return getStackedHighlight(
high,
set,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<BarEntry> {
var fills: MutableList<Fill>

/**
* Created by philipp on 21/10/15.
*/
public interface IBarDataSet extends IBarLineScatterCandleBubbleDataSet<BarEntry> {

List<Fill> 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<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IBarDataSet>()
dataSets.add(set1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading