From e7e5e42e58440dc57185a5e8c1121f788c4a53a0 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Wed, 17 Dec 2025 17:02:01 +0100 Subject: [PATCH 1/2] Kotlin BarLineScatterCandleBubbleDataSet Property access highLightColor Kotlin DataSet Fix tests --- .../mikephil/charting/data/BarDataSet.kt | 40 +- .../BarLineScatterCandleBubbleDataSet.java | 46 -- .../data/BarLineScatterCandleBubbleDataSet.kt | 22 + .../mikephil/charting/data/BaseDataSet.kt | 8 +- .../mikephil/charting/data/CandleDataSet.java | 263 ---------- .../mikephil/charting/data/CandleDataSet.kt | 234 +++++++++ .../mikephil/charting/data/DataSet.java | 479 ------------------ .../github/mikephil/charting/data/DataSet.kt | 423 ++++++++++++++++ .../mikephil/charting/data/LineDataSet.java | 391 -------------- .../mikephil/charting/data/LineDataSet.kt | 353 +++++++++++++ .../mikephil/charting/data/PieDataSet.java | 1 - .../IBarLineScatterCandleBubbleDataSet.kt | 2 +- .../charting/interfaces/datasets/IDataSet.kt | 6 +- .../mikephil/charting/test/ChartDataTest.kt | 10 +- .../mikephil/charting/test/DataSetTest.kt | 14 +- .../appdev/chartexample/AnotherBarActivity.kt | 2 +- .../appdev/chartexample/BarChartActivity.kt | 2 +- .../BarChartActivityMultiDataset.kt | 8 +- .../chartexample/BarChartActivitySinus.kt | 2 +- .../chartexample/BarChartPositiveNegative.kt | 2 +- .../chartexample/CubicLineChartActivity.kt | 4 +- .../info/appdev/chartexample/DataTools.kt | 4 +- .../appdev/chartexample/DrawChartActivity.kt | 2 +- .../chartexample/DynamicalAddingActivity.kt | 4 +- .../appdev/chartexample/FilledLineActivity.kt | 8 +- .../HorizontalBarChartActivity.kt | 2 +- .../HorizontalBarNegativeChartActivity.kt | 2 +- .../chartexample/LineChartActivityColored.kt | 2 +- .../chartexample/LineChartDualAxisActivity.kt | 12 +- .../chartexample/LineChartTimeActivity.kt | 2 +- .../ListViewMultiChartActivity.kt | 4 +- .../chartexample/RealtimeLineChartActivity.kt | 2 +- .../SpecificPositionsLineChartActivity.kt | 4 +- .../appdev/chartexample/StackedBarActivity.kt | 2 +- 34 files changed, 1103 insertions(+), 1259 deletions(-) delete mode 100644 MPChartLib/src/main/java/com/github/mikephil/charting/data/BarLineScatterCandleBubbleDataSet.java create mode 100644 MPChartLib/src/main/java/com/github/mikephil/charting/data/BarLineScatterCandleBubbleDataSet.kt delete mode 100644 MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleDataSet.java create mode 100644 MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleDataSet.kt delete mode 100644 MPChartLib/src/main/java/com/github/mikephil/charting/data/DataSet.java create mode 100644 MPChartLib/src/main/java/com/github/mikephil/charting/data/DataSet.kt delete mode 100644 MPChartLib/src/main/java/com/github/mikephil/charting/data/LineDataSet.java create mode 100644 MPChartLib/src/main/java/com/github/mikephil/charting/data/LineDataSet.kt 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 c164fcde37..6860b30a15 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 @@ -11,7 +11,7 @@ import kotlin.Int import kotlin.String import kotlin.arrayOf -open class BarDataSet(yVals: MutableList, label: String?) : BarLineScatterCandleBubbleDataSet(yVals, label), IBarDataSet { +open class BarDataSet(yVals: MutableList, label: String = "") : BarLineScatterCandleBubbleDataSet(yVals, label), IBarDataSet { /** * the maximum number of bars that are stacked upon each other, this value * is calculated from the Entries that are added to the DataSet @@ -55,20 +55,22 @@ open class BarDataSet(yVals: MutableList, label: String?) : BarLineSc protected set init { - mHighLightColor = Color.rgb(0, 0, 0) + highLightColor = Color.rgb(0, 0, 0) calcStackSize(yVals) calcEntryCountIncludingStacks(yVals) } - override fun copy(): DataSet { + override fun copy(): DataSet? { val entries: MutableList = ArrayList() - for (i in mEntries.indices) { - entries.add(mEntries[i]!!.copy()) + mEntries?.let { + for (i in it.indices) { + entries.add(it[i]!!.copy()) + } } val copied = BarDataSet(entries, label) copy(copied) - return copied + return copied as DataSet? } protected fun copy(barDataSet: BarDataSet) { @@ -85,14 +87,10 @@ open class BarDataSet(yVals: MutableList, label: String?) : BarLineSc } override fun getFill(index: Int): Fill? { - return gradients!!.get(index % gradients!!.size) + return gradients!![index % gradients!!.size] } - /** - * This method is deprecated. - * Use getFill(...) instead. - */ - @Deprecated("") + @Deprecated("Use getFill(...) instead") fun getGradient(index: Int): Fill? { return getFill(index) } @@ -105,11 +103,7 @@ open class BarDataSet(yVals: MutableList, label: String?) : BarLineSc gradients!!.add(Fill(startColor, endColor)) } - /** - * This method is deprecated. - * Use setFills(...) instead. - */ - @Deprecated("") + @Deprecated("Use setFills(...) instead") fun setGradientColors(gradientColors: MutableList?) { this.gradients = gradientColors } @@ -137,7 +131,7 @@ open class BarDataSet(yVals: MutableList, label: String?) : BarLineSc } /** - * calculates the maximum stacksize that occurs in the Entries array of this + * calculates the maximum stackSize that occurs in the Entries array of this * DataSet */ private fun calcStackSize(yVals: MutableList) { @@ -151,13 +145,13 @@ open class BarDataSet(yVals: MutableList, label: String?) : BarLineSc override fun calcMinMax(e: BarEntry?) { if (e != null && !Float.isNaN(e.y)) { if (e.yVals == null) { - if (e.y < mYMin) mYMin = e.y + if (e.y < yMin) yMin = e.y - if (e.y > mYMax) mYMax = e.y + if (e.y > yMax) yMax = e.y } else { - if (-e.negativeSum < mYMin) mYMin = -e.negativeSum + if (-e.negativeSum < yMin) yMin = -e.negativeSum - if (e.positiveSum > mYMax) mYMax = e.positiveSum + if (e.positiveSum > yMax) yMax = e.positiveSum } calcMinMaxX(e) @@ -238,7 +232,7 @@ open class BarDataSet(yVals: MutableList, label: String?) : BarLineSc return mStackLabels } - override fun getEntryIndex(entry: BarEntry?): Int { + override fun getEntryIndex(entry: BarEntry): Int { return this.getEntryIndex(entry) } } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BarLineScatterCandleBubbleDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BarLineScatterCandleBubbleDataSet.java deleted file mode 100644 index f4422e8c4a..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BarLineScatterCandleBubbleDataSet.java +++ /dev/null @@ -1,46 +0,0 @@ - -package com.github.mikephil.charting.data; - -import android.graphics.Color; - -import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet; - -import java.util.List; - -/** - * Baseclass of all DataSets for Bar-, Line-, Scatter- and CandleStickChart. - * - * @author Philipp Jahoda - */ -public abstract class BarLineScatterCandleBubbleDataSet - extends DataSet - implements IBarLineScatterCandleBubbleDataSet { - - /** - * default highlight color - */ - protected int mHighLightColor = Color.rgb(255, 187, 115); - - public BarLineScatterCandleBubbleDataSet(List yVals, String label) { - super(yVals, label); - } - - /** - * Sets the color that is used for drawing the highlight indicators. Dont - * forget to resolve the color using getResources().getColor(...) or - * Color.rgb(...). - */ - public void setHighLightColor(int color) { - mHighLightColor = color; - } - - @Override - public int getHighLightColor() { - return mHighLightColor; - } - - protected void copy(BarLineScatterCandleBubbleDataSet barLineScatterCandleBubbleDataSet) { - super.copy((BaseDataSet) barLineScatterCandleBubbleDataSet); - barLineScatterCandleBubbleDataSet.mHighLightColor = mHighLightColor; - } -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BarLineScatterCandleBubbleDataSet.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BarLineScatterCandleBubbleDataSet.kt new file mode 100644 index 0000000000..016da24200 --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BarLineScatterCandleBubbleDataSet.kt @@ -0,0 +1,22 @@ +package com.github.mikephil.charting.data + +import android.graphics.Color +import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet + +/** + * Baseclass of all DataSets for Bar-, Line-, Scatter- and CandleStickChart. + */ +abstract class BarLineScatterCandleBubbleDataSet(yVals: MutableList?, label: String = "") : + DataSet(yVals, label), IBarLineScatterCandleBubbleDataSet { + /** + * Sets the color that is used for drawing the highlight indicators. Dont + * forget to resolve the color using getResources().getColor(...) or + * Color.rgb(...). + */ + override var highLightColor: Int = Color.rgb(255, 187, 115) + + protected fun copy(barLineScatterCandleBubbleDataSet: BarLineScatterCandleBubbleDataSet<*>) { + super.copy((barLineScatterCandleBubbleDataSet as BaseDataSet<*>?)!!) + barLineScatterCandleBubbleDataSet.highLightColor = this.highLightColor + } +} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.kt index 9f8eb2546f..5b79ed31da 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.kt @@ -18,7 +18,7 @@ import com.github.mikephil.charting.utils.convertDpToPixel * This is the base dataset of all DataSets. It's purpose is to implement critical methods * provided by the IDataSet interface. */ -abstract class BaseDataSet() : IDataSet { +abstract class BaseDataSet() : IDataSet { /** * List representing all colors that are used for this DataSet */ @@ -236,12 +236,10 @@ abstract class BaseDataSet() : IDataSet { mColors.clear() } - override var label: String? + override var label: String get() = mLabel set(value) { - if (value != null) { - mLabel = value - } + mLabel = value } override var axisDependency: AxisDependency get() = mAxisDependency diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleDataSet.java deleted file mode 100644 index 95ff582ee6..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleDataSet.java +++ /dev/null @@ -1,263 +0,0 @@ - -package com.github.mikephil.charting.data; - -import android.graphics.Paint; - -import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet; -import com.github.mikephil.charting.utils.ColorTemplate; -import com.github.mikephil.charting.utils.UtilsKtKt; - -import java.util.ArrayList; -import java.util.List; - -/** - * DataSet for the CandleStickChart. - * - * @author Philipp Jahoda - */ -public class CandleDataSet extends LineScatterCandleRadarDataSet implements ICandleDataSet { - - /** - * the width of the shadow of the candle - */ - private float mShadowWidth = 3f; - - /** - * should the candle bars show? - * when false, only "ticks" will show - *

- * - default: true - */ - private boolean mShowCandleBar = true; - - /** - * the space between the candle entries, default 0.1f (10%) - */ - private float mBarSpace = 0.1f; - - /** - * use candle color for the shadow - */ - private boolean mShadowColorSameAsCandle = false; - - /** - * paint style when open < close - * increasing candlesticks are traditionally hollow - */ - protected Paint.Style mIncreasingPaintStyle = Paint.Style.STROKE; - - /** - * paint style when open > close - * descreasing candlesticks are traditionally filled - */ - protected Paint.Style mDecreasingPaintStyle = Paint.Style.FILL; - - /** - * color for open == close - */ - protected int mNeutralColor = ColorTemplate.COLOR_SKIP; - - /** - * color for open < close - */ - protected int mIncreasingColor = ColorTemplate.COLOR_SKIP; - - /** - * color for open > close - */ - protected int mDecreasingColor = ColorTemplate.COLOR_SKIP; - - /** - * shadow line color, set -1 for backward compatibility and uses default - * color - */ - protected int mShadowColor = ColorTemplate.COLOR_SKIP; - - public CandleDataSet(List yVals, String label) { - super(yVals, label); - } - - @Override - public DataSet copy() { - List entries = new ArrayList<>(); - for (int i = 0; i < mEntries.size(); i++) { - entries.add(mEntries.get(i).copy()); - } - CandleDataSet copied = new CandleDataSet(entries, getLabel()); - copy(copied); - return copied; - } - - protected void copy(CandleDataSet candleDataSet) { - super.copy((BaseDataSet) candleDataSet); - candleDataSet.mShadowWidth = mShadowWidth; - candleDataSet.mShowCandleBar = mShowCandleBar; - candleDataSet.mBarSpace = mBarSpace; - candleDataSet.mShadowColorSameAsCandle = mShadowColorSameAsCandle; - candleDataSet.mHighLightColor = mHighLightColor; - candleDataSet.mIncreasingPaintStyle = mIncreasingPaintStyle; - candleDataSet.mDecreasingPaintStyle = mDecreasingPaintStyle; - candleDataSet.mNeutralColor = mNeutralColor; - candleDataSet.mIncreasingColor = mIncreasingColor; - candleDataSet.mDecreasingColor = mDecreasingColor; - candleDataSet.mShadowColor = mShadowColor; - } - - @Override - protected void calcMinMax(CandleEntry e) { - - if (e.getLow() < mYMin) - mYMin = e.getLow(); - - if (e.getHigh() > mYMax) - mYMax = e.getHigh(); - - calcMinMaxX(e); - } - - @Override - protected void calcMinMaxY(CandleEntry entry) { - - if (entry.getHigh() < mYMin) - mYMin = entry.getHigh(); - - if (entry.getHigh() > mYMax) - mYMax = entry.getHigh(); - - if (entry.getLow() < mYMin) - mYMin = entry.getLow(); - - if (entry.getLow() > mYMax) - mYMax = entry.getLow(); - } - - /** - * Sets the space that is left out on the left and right side of each - * candle, default 0.1f (10%), max 0.45f, min 0f - */ - public void setBarSpace(float space) { - - if (space < 0f) - space = 0f; - if (space > 0.45f) - space = 0.45f; - - mBarSpace = space; - } - - @Override - public float getBarSpace() { - return mBarSpace; - } - - /** - * Sets the width of the candle-shadow-line in pixels. Default 3f. - */ - public void setShadowWidth(float width) { - mShadowWidth = UtilsKtKt.convertDpToPixel(width); - } - - @Override - public float getShadowWidth() { - return mShadowWidth; - } - - /** - * Sets whether the candle bars should show? - */ - public void setShowCandleBar(boolean showCandleBar) { - mShowCandleBar = showCandleBar; - } - - @Override - public boolean getShowCandleBar() { - return mShowCandleBar; - } - - /** - * Sets the one and ONLY color that should be used for this DataSet when - * open == close. - */ - public void setNeutralColor(int color) { - mNeutralColor = color; - } - - @Override - public int getNeutralColor() { - return mNeutralColor; - } - - /** - * Sets the one and ONLY color that should be used for this DataSet when - * open <= close. - */ - public void setIncreasingColor(int color) { - mIncreasingColor = color; - } - - @Override - public int getIncreasingColor() { - return mIncreasingColor; - } - - /** - * Sets the one and ONLY color that should be used for this DataSet when - * open > close. - */ - public void setDecreasingColor(int color) { - mDecreasingColor = color; - } - - @Override - public int getDecreasingColor() { - return mDecreasingColor; - } - - @Override - public Paint.Style getIncreasingPaintStyle() { - return mIncreasingPaintStyle; - } - - /** - * Sets paint style when open < close - */ - public void setIncreasingPaintStyle(Paint.Style paintStyle) { - this.mIncreasingPaintStyle = paintStyle; - } - - @Override - public Paint.Style getDecreasingPaintStyle() { - return mDecreasingPaintStyle; - } - - /** - * Sets paint style when open > close - */ - public void setDecreasingPaintStyle(Paint.Style decreasingPaintStyle) { - this.mDecreasingPaintStyle = decreasingPaintStyle; - } - - @Override - public int getShadowColor() { - return mShadowColor; - } - - /** - * Sets shadow color for all entries - */ - public void setShadowColor(int shadowColor) { - this.mShadowColor = shadowColor; - } - - @Override - public boolean getShadowColorSameAsCandle() { - return mShadowColorSameAsCandle; - } - - /** - * Sets shadow color to be the same color as the candle color - */ - public void setShadowColorSameAsCandle(boolean shadowColorSameAsCandle) { - this.mShadowColorSameAsCandle = shadowColorSameAsCandle; - } -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleDataSet.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleDataSet.kt new file mode 100644 index 0000000000..24d1f6dc8e --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleDataSet.kt @@ -0,0 +1,234 @@ +package com.github.mikephil.charting.data + +import android.graphics.Paint +import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet +import com.github.mikephil.charting.utils.ColorTemplate +import com.github.mikephil.charting.utils.convertDpToPixel + +/** + * DataSet for the CandleStickChart. + * + * @author Philipp Jahoda + */ +class CandleDataSet(yVals: MutableList?, label: String?) : LineScatterCandleRadarDataSet(yVals, label), ICandleDataSet { + /** + * the width of the shadow of the candle + */ + private var mShadowWidth = 3f + + /** + * should the candle bars show? + * when false, only "ticks" will show + * + * + * - default: true + */ + private var mShowCandleBar = true + + /** + * the space between the candle entries, default 0.1f (10%) + */ + private var mBarSpace = 0.1f + + /** + * use candle color for the shadow + */ + private var mShadowColorSameAsCandle = false + + /** + * paint style when open < close + * increasing candlesticks are traditionally hollow + */ + protected var mIncreasingPaintStyle: Paint.Style? = Paint.Style.STROKE + + /** + * paint style when open > close + * descreasing candlesticks are traditionally filled + */ + protected var mDecreasingPaintStyle: Paint.Style? = Paint.Style.FILL + + /** + * color for open == close + */ + protected var mNeutralColor: Int = ColorTemplate.COLOR_SKIP + + /** + * color for open < close + */ + protected var mIncreasingColor: Int = ColorTemplate.COLOR_SKIP + + /** + * color for open > close + */ + protected var mDecreasingColor: Int = ColorTemplate.COLOR_SKIP + + /** + * shadow line color, set -1 for backward compatibility and uses default + * color + */ + protected var mShadowColor: Int = ColorTemplate.COLOR_SKIP + + override fun copy(): DataSet { + val entries: MutableList = ArrayList() + for (i in mEntries!!.indices) { + entries.add(mEntries!!.get(i)!!.copy()) + } + val copied = CandleDataSet(entries, label) + copy(copied) + return copied + } + + protected fun copy(candleDataSet: CandleDataSet) { + super.copy((candleDataSet as BaseDataSet<*>?)!!) + candleDataSet.mShadowWidth = mShadowWidth + candleDataSet.mShowCandleBar = mShowCandleBar + candleDataSet.mBarSpace = mBarSpace + candleDataSet.mShadowColorSameAsCandle = mShadowColorSameAsCandle + candleDataSet.highLightColor = highLightColor + candleDataSet.mIncreasingPaintStyle = mIncreasingPaintStyle + candleDataSet.mDecreasingPaintStyle = mDecreasingPaintStyle + candleDataSet.mNeutralColor = mNeutralColor + candleDataSet.mIncreasingColor = mIncreasingColor + candleDataSet.mDecreasingColor = mDecreasingColor + candleDataSet.mShadowColor = mShadowColor + } + + override fun calcMinMax(entry: CandleEntry?) { + entry?.let { + if (entry.low < yMin) yMin = entry.low + + if (entry.high > yMax) yMax = entry.high + } + calcMinMaxX(entry) + } + + override fun calcMinMaxY(entry: CandleEntry?) { + entry?.let { + if (entry.high < yMin) yMin = entry.high + + if (entry.high > yMax) yMax = entry.high + + if (entry.low < yMin) yMin = entry.low + + if (entry.low > yMax) yMax = entry.low + } + } + + /** + * Sets the space that is left out on the left and right side of each + * candle, default 0.1f (10%), max 0.45f, min 0f + */ + fun setBarSpace(space: Float) { + var space = space + if (space < 0f) space = 0f + if (space > 0.45f) space = 0.45f + + mBarSpace = space + } + + override fun getBarSpace(): Float { + return mBarSpace + } + + /** + * Sets the width of the candle-shadow-line in pixels. Default 3f. + */ + fun setShadowWidth(width: Float) { + mShadowWidth = width.convertDpToPixel() + } + + override fun getShadowWidth(): Float { + return mShadowWidth + } + + /** + * Sets whether the candle bars should show? + */ + fun setShowCandleBar(showCandleBar: Boolean) { + mShowCandleBar = showCandleBar + } + + override fun getShowCandleBar(): Boolean { + return mShowCandleBar + } + + /** + * Sets the one and ONLY color that should be used for this DataSet when + * open == close. + */ + fun setNeutralColor(color: Int) { + mNeutralColor = color + } + + override fun getNeutralColor(): Int { + return mNeutralColor + } + + /** + * Sets the one and ONLY color that should be used for this DataSet when + * open <= close. + */ + fun setIncreasingColor(color: Int) { + mIncreasingColor = color + } + + override fun getIncreasingColor(): Int { + return mIncreasingColor + } + + /** + * Sets the one and ONLY color that should be used for this DataSet when + * open > close. + */ + fun setDecreasingColor(color: Int) { + mDecreasingColor = color + } + + override fun getDecreasingColor(): Int { + return mDecreasingColor + } + + override fun getIncreasingPaintStyle(): Paint.Style? { + return mIncreasingPaintStyle + } + + /** + * Sets paint style when open < close + */ + fun setIncreasingPaintStyle(paintStyle: Paint.Style?) { + this.mIncreasingPaintStyle = paintStyle + } + + override fun getDecreasingPaintStyle(): Paint.Style? { + return mDecreasingPaintStyle + } + + /** + * Sets paint style when open > close + */ + fun setDecreasingPaintStyle(decreasingPaintStyle: Paint.Style?) { + this.mDecreasingPaintStyle = decreasingPaintStyle + } + + override fun getShadowColor(): Int { + return mShadowColor + } + + /** + * Sets shadow color for all entries + */ + fun setShadowColor(shadowColor: Int) { + this.mShadowColor = shadowColor + } + + override fun getShadowColorSameAsCandle(): Boolean { + return mShadowColorSameAsCandle + } + + /** + * Sets shadow color to be the same color as the candle color + */ + fun setShadowColorSameAsCandle(shadowColorSameAsCandle: Boolean) { + this.mShadowColorSameAsCandle = shadowColorSameAsCandle + } +} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/DataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/DataSet.java deleted file mode 100644 index daf33dbf09..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/DataSet.java +++ /dev/null @@ -1,479 +0,0 @@ - -package com.github.mikephil.charting.data; - -import android.util.Log; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -import androidx.annotation.NonNull; - -/** - * The DataSet class represents one group or type of entries (Entry) in the - * Chart that belong together. It is designed to logically separate different - * groups of values inside the Chart (e.g. the values for a specific line in the - * LineChart, or the values of a specific group of bars in the BarChart). - * - * @author Philipp Jahoda - */ -public abstract class DataSet extends BaseDataSet implements Serializable { - - /** - * the entries that this DataSet represents / holds together - */ - protected List mEntries; - - /** - * maximum y-value in the value array - */ - protected float mYMax = -Float.MAX_VALUE; - - /** - * minimum y-value in the value array - */ - protected float mYMin = Float.MAX_VALUE; - - /** - * maximum x-value in the value array - */ - protected float mXMax = -Float.MAX_VALUE; - - /** - * minimum x-value in the value array - */ - protected float mXMin = Float.MAX_VALUE; - - - /** - * Creates a new DataSet object with the given values (entries) it represents. Also, a - * label that describes the DataSet can be specified. The label can also be - * used to retrieve the DataSet from a ChartData object. - */ - - public DataSet(List entries, String label) { - super(label); - this.mEntries = entries; - - if (mEntries == null) { - mEntries = new ArrayList<>(); - } - - calcMinMax(); - } - - @Override - public void calcMinMax() { - - mYMax = -Float.MAX_VALUE; - mYMin = Float.MAX_VALUE; - mXMax = -Float.MAX_VALUE; - mXMin = Float.MAX_VALUE; - - if (mEntries == null || mEntries.isEmpty()) { - return; - } - - for (T e : mEntries) { - calcMinMax(e); - } - } - - @Override - public void calcMinMaxY(float fromX, float toX) { - mYMax = -Float.MAX_VALUE; - mYMin = Float.MAX_VALUE; - - if (mEntries == null || mEntries.isEmpty()) { - return; - } - - int indexFrom = getEntryIndex(fromX, Float.NaN, Rounding.DOWN); - int indexTo = getEntryIndex(toX, Float.NaN, Rounding.UP); - - if (indexTo < indexFrom) { - return; - } - - for (int i = indexFrom; i <= indexTo; i++) { - - // only recalculate y - calcMinMaxY(mEntries.get(i)); - } - } - - /** - * Updates the min and max x and y value of this DataSet based on the given Entry. - */ - - protected void calcMinMax(T entry) { - - if (entry == null) { - return; - } - - calcMinMaxX(entry); - calcMinMaxY(entry); - } - - protected void calcMinMaxX(T entry) { - - if (entry.getX() < mXMin) { - mXMin = entry.getX(); - } - - if (entry.getX() > mXMax) { - mXMax = entry.getX(); - } - } - - protected void calcMinMaxY(T entry) { - - if (entry.getY() < mYMin) { - mYMin = entry.getY(); - } - - if (entry.getY() > mYMax) { - mYMax = entry.getY(); - } - } - - @Override - public int getEntryCount() { - return mEntries.size(); - } - - /** - * This method is deprecated. - * Use getEntries() instead. - */ - - @Deprecated - public List getValues() { - return mEntries; - } - - /** - * Returns the array of entries that this DataSet represents. - */ - - public List getEntries() { - return mEntries; - } - - /** - * This method is deprecated. - * Use setEntries(...) instead. - */ - - @Deprecated - public void setValues(List values) { - setEntries(values); - } - - /** - * Sets the array of entries that this DataSet represents, and calls notifyDataSetChanged() - */ - - public void setEntries(List entries) { - mEntries = entries; - notifyDataSetChanged(); - } - - /** - * Provides an exact copy of the DataSet this method is used on. - */ - - public abstract DataSet copy(); - - - protected void copy(DataSet dataSet) { - super.copy(dataSet); - } - - @NonNull - @Override - public String toString() { - StringBuilder buffer = new StringBuilder(); - buffer.append(toSimpleString()); - for (int i = 0; i < mEntries.size(); i++) { - buffer.append(mEntries.get(i).toString() ).append( " "); - } - return buffer.toString(); - } - - /** - * Returns a simple string representation of the DataSet with the type and - * the number of Entries. - */ - - public String toSimpleString() { - return "DataSet, label: " + - (getLabel() == null ? "" : getLabel()) + - ", entries: " + - mEntries.size() + - "\n"; - } - - @Override - public float getYMin() { - return mYMin; - } - - @Override - public float getYMax() { - return mYMax; - } - - @Override - public float getXMin() { - return mXMin; - } - - @Override - public float getXMax() { - return mXMax; - } - - @Override - public void addEntryOrdered(@NonNull T entry) { - - if (mEntries == null) { - mEntries = new ArrayList<>(); - } - - calcMinMax(entry); - - if (!mEntries.isEmpty() && mEntries.get(mEntries.size() - 1).getX() > entry.getX()) { - int closestIndex = getEntryIndex(entry.getX(), entry.getY(), Rounding.UP); - mEntries.add(closestIndex, entry); - } else { - mEntries.add(entry); - } - } - - @Override - public void clear() { - mEntries.clear(); - notifyDataSetChanged(); - } - - @Override - public boolean addEntry(@NonNull T entry) { - List values = getEntries(); - if (values == null) { - values = new ArrayList<>(); - } - - calcMinMax(entry); - - // add the entry - return values.add(entry); - } - - @Override - public boolean removeEntry(@NonNull T entry) { - - if (mEntries == null) - return false; - - // remove the entry - boolean removed = mEntries.remove(entry); - - if (removed) { - calcMinMax(); - } - - return removed; - } - - @Override - public int getEntryIndex(@NonNull Entry entry) { - return mEntries.indexOf(entry); - } - - @Override - public T getEntryForXValue(float xValue, float closestToY, Rounding rounding) { - - int index = getEntryIndex(xValue, closestToY, rounding); - if (index > -1) { - return mEntries.get(index); - } - return null; - } - - @Override - public T getEntryForXValue(float xValue, float closestToY) { - return getEntryForXValue(xValue, closestToY, Rounding.CLOSEST); - } - - @Override - public T getEntryForIndex(int index) { - if (index < 0) { - Log.e("DataSet", "index " + index + " is < 0 for getEntryForIndex"); - return null; - } else if (index >= mEntries.size()) { - Log.e("DataSet", "index " + index + "/" + mEntries.size() + " is out of range for getEntryForIndex"); - return null; - } - return mEntries.get(index); - } - - @Override - public int getEntryIndex(float xValue, float closestToY, Rounding rounding) { - - if (mEntries == null || mEntries.isEmpty()) { - return -1; - } - - int low = 0; - int high = mEntries.size() - 1; - int closest = high; - - while (low < high) { - int m = low + (high - low) / 2; - - Entry currentEntry = mEntries.get(m); - - if (currentEntry != null) { - Entry nextEntry = mEntries.get(m + 1); - - if (nextEntry != null) { - final float d1 = currentEntry.getX() - xValue, - d2 = nextEntry.getX() - xValue, - ad1 = Math.abs(d1), - ad2 = Math.abs(d2); - - if (ad2 < ad1) { - // [m + 1] is closer to xValue - // Search in an higher place - low = m + 1; - } else if (ad1 < ad2) { - // [m] is closer to xValue - // Search in a lower place - high = m; - } else { - // We have multiple sequential x-value with same distance - - if (d1 >= 0.0) { - // Search in a lower place - high = m; - } else if (d1 < 0.0) { - // Search in an higher place - low = m + 1; - } - } - - closest = high; - } - } - } - - if (closest != -1) { - Entry closestEntry = mEntries.get(closest); - if (closestEntry != null) { - float closestXValue = closestEntry.getX(); - if (rounding == Rounding.UP) { - // If rounding up, and found x-value is lower than specified x, and we can go upper... - if (closestXValue < xValue && closest < mEntries.size() - 1) { - ++closest; - } - } else if (rounding == Rounding.DOWN) { - // If rounding down, and found x-value is upper than specified x, and we can go lower... - if (closestXValue > xValue && closest > 0) { - --closest; - } - } - - // Search by closest to y-value - if (!Float.isNaN(closestToY)) { - while (closest > 0 && mEntries.get(closest - 1).getX() == closestXValue) { - closest -= 1; - } - - float closestYValue = closestEntry.getY(); - int closestYIndex = closest; - - while (true) { - closest += 1; - if (closest >= mEntries.size()) { - break; - } - - final Entry value = mEntries.get(closest); - - if (value == null) { - continue; - } - - if (value.getX() != closestXValue) { - break; - } - - if (Math.abs(value.getY() - closestToY) <= Math.abs(closestYValue - closestToY)) { - closestYValue = closestToY; - closestYIndex = closest; - } - } - - closest = closestYIndex; - } - } - } - return closest; - } - - @Override - public List getEntriesForXValue(float xValue) { - - List entries = new ArrayList<>(); - - int low = 0; - int high = mEntries.size() - 1; - - while (low <= high) { - int m = (high + low) / 2; - T entry = mEntries.get(m); - - // if we have a match - if (xValue == entry.getX()) { - while (m > 0 && mEntries.get(m - 1).getX() == xValue) { - m--; - } - - high = mEntries.size(); - - // loop over all "equal" entries - for (; m < high; m++) { - entry = mEntries.get(m); - if (entry.getX() == xValue) { - entries.add(entry); - } else { - break; - } - } - - break; - } else { - if (xValue > entry.getX()) { - low = m + 1; - } else { - high = m - 1; - } - } - } - - return entries; - } - - /** - * Determines how to round DataSet index values for - * {@link DataSet#getEntryIndex(float, float, Rounding)} DataSet.getEntryIndex()} - * when an exact x-index is not found. - */ - public enum Rounding { - UP, - DOWN, - CLOSEST, - } -} \ No newline at end of file diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/DataSet.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/data/DataSet.kt new file mode 100644 index 0000000000..548ed8967d --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/DataSet.kt @@ -0,0 +1,423 @@ +package com.github.mikephil.charting.data + +import android.util.Log +import java.io.Serializable +import java.lang.Float +import kotlin.Boolean +import kotlin.Deprecated +import kotlin.Int +import kotlin.String +import kotlin.math.abs +import kotlin.toString + +/** + * The DataSet class represents one group or type of entries (Entry) in the + * Chart that belong together. It is designed to logically separate different + * groups of values inside the Chart (e.g. the values for a specific line in the + * LineChart, or the values of a specific group of bars in the BarChart). + */ +abstract class DataSet( + /** + * the entries that this DataSet represents / holds together + */ + @JvmField protected var mEntries: MutableList?, label: String = "" +) : BaseDataSet(label), Serializable { + /** + * maximum y-value in the value array + */ + override var yMax: kotlin.Float = -Float.MAX_VALUE + protected set + + /** + * minimum y-value in the value array + */ + override var yMin: kotlin.Float = Float.MAX_VALUE + protected set + + /** + * maximum x-value in the value array + */ + override var xMax: kotlin.Float = -Float.MAX_VALUE + protected set + + /** + * minimum x-value in the value array + */ + override var xMin: kotlin.Float = Float.MAX_VALUE + protected set + + + /** + * Creates a new DataSet object with the given values (entries) it represents. Also, a + * label that describes the DataSet can be specified. The label can also be + * used to retrieve the DataSet from a ChartData object. + */ + init { + if (mEntries == null) { + mEntries = ArrayList() + } + + calcMinMax() + } + + override fun calcMinMax() { + this.yMax = -Float.MAX_VALUE + this.yMin = Float.MAX_VALUE + this.xMax = -Float.MAX_VALUE + this.xMin = Float.MAX_VALUE + + if (mEntries == null || mEntries!!.isEmpty()) { + return + } + + for (e in mEntries) { + calcMinMax(e) + } + } + + override fun calcMinMaxY(fromX: kotlin.Float, toX: kotlin.Float) { + this.yMax = -Float.MAX_VALUE + this.yMin = Float.MAX_VALUE + + if (mEntries == null || mEntries!!.isEmpty()) { + return + } + + val indexFrom = getEntryIndex(fromX, Float.NaN, Rounding.DOWN) + val indexTo = getEntryIndex(toX, Float.NaN, Rounding.UP) + + if (indexTo < indexFrom) { + return + } + + for (i in indexFrom..indexTo) { + // only recalculate y + + calcMinMaxY(mEntries!!.get(i)) + } + } + + /** + * Updates the min and max x and y value of this DataSet based on the given Entry. + */ + protected open fun calcMinMax(entry: T?) { + if (entry == null) { + return + } + + calcMinMaxX(entry) + calcMinMaxY(entry) + } + + protected fun calcMinMaxX(entry: T?) { + if (entry!!.x < this.xMin) { + this.xMin = entry.x + } + + if (entry.x > this.xMax) { + this.xMax = entry.x + } + } + + protected open fun calcMinMaxY(entry: T?) { + if (entry!!.y < this.yMin) { + this.yMin = entry.y + } + + if (entry.y > this.yMax) { + this.yMax = entry.y + } + } + + override val entryCount: Int + get() = mEntries!!.size + + @get:Deprecated("") + @set:Deprecated("") + var values: MutableList? + /** + * This method is deprecated. + * Use getEntries() instead. + */ + get() = mEntries + /** + * This method is deprecated. + * Use setEntries(...) instead. + */ + set(values) { + this.entries = values + } + + var entries: MutableList? + /** + * Returns the array of entries that this DataSet represents. + */ + get() = mEntries + /** + * Sets the array of entries that this DataSet represents, and calls notifyDataSetChanged() + */ + set(entries) { + mEntries = entries + notifyDataSetChanged() + } + + /** + * Provides an exact copy of the DataSet this method is used on. + */ + abstract fun copy(): DataSet? + + + protected fun copy(dataSet: DataSet<*>) { + super.copy(dataSet) + } + + override fun toString(): String { + val buffer = StringBuilder() + buffer.append(toSimpleString()) + for (i in mEntries!!.indices) { + buffer.append(mEntries!!.get(i).toString()).append(" ") + } + return buffer.toString() + } + + /** + * Returns a simple string representation of the DataSet with the type and + * the number of Entries. + */ + fun toSimpleString(): String { + return "DataSet, label: " + + (if (label == null) "" else label) + + ", entries: " + + mEntries!!.size + + "\n" + } + + override fun addEntryOrdered(entry: T?) { + if (mEntries == null) { + mEntries = ArrayList() + } + + calcMinMax(entry) + + if (!mEntries!!.isEmpty() && mEntries!!.get(mEntries!!.size - 1)!!.x > entry!!.x) { + val closestIndex = getEntryIndex(entry.x, entry.y, Rounding.UP) + mEntries!!.add(closestIndex, entry) + } else { + mEntries!!.add(entry) + } + } + + override fun clear() { + mEntries!!.clear() + notifyDataSetChanged() + } + + override fun addEntry(entry: T?): Boolean { + var values = this.entries + if (values == null) { + values = ArrayList() + } + + calcMinMax(entry) + + // add the entry + return values.add(entry) + } + + override fun removeEntry(entry: T?): Boolean { + if (mEntries == null) return false + + // remove the entry + val removed = mEntries!!.remove(entry) + + if (removed) { + calcMinMax() + } + + return removed + } + + override fun getEntryIndex(entry: T?): Int { +// return getEntryIndex(entry) + return mEntries!!.indexOf(entry) + } + + + override fun getEntryForXValue(xValue: kotlin.Float, closestToY: kotlin.Float, rounding: DataSet.Rounding?): T? { + val index = getEntryIndex(xValue, closestToY, rounding) + if (index > -1) { + return mEntries!!.get(index) + } + return null + } + + override fun getEntryForXValue(xValue: kotlin.Float, closestToY: kotlin.Float): T? { + return getEntryForXValue(xValue, closestToY, Rounding.CLOSEST) + } + + override fun getEntryForIndex(index: Int): T? { + if (index < 0) { + Log.e("DataSet", "index $index is < 0 for getEntryForIndex") + return null + } else if (index >= mEntries!!.size) { + Log.e("DataSet", "index " + index + "/" + mEntries!!.size + " is out of range for getEntryForIndex") + return null + } + return mEntries!!.get(index) + } + + override fun getEntryIndex(xValue: kotlin.Float, closestToY: kotlin.Float, rounding: Rounding?): Int { + if (mEntries == null || mEntries!!.isEmpty()) { + return -1 + } + + var low = 0 + var high = mEntries!!.size - 1 + var closest = high + + while (low < high) { + val m = low + (high - low) / 2 + + val currentEntry: Entry? = mEntries!!.get(m) + + if (currentEntry != null) { + val nextEntry: Entry? = mEntries!!.get(m + 1) + + if (nextEntry != null) { + val d1 = currentEntry.x - xValue + val d2 = nextEntry.x - xValue + val ad1 = abs(d1) + val ad2 = abs(d2) + + if (ad2 < ad1) { + // [m + 1] is closer to xValue + // Search in an higher place + low = m + 1 + } else if (ad1 < ad2) { + // [m] is closer to xValue + // Search in a lower place + high = m + } else { + // We have multiple sequential x-value with same distance + + if (d1 >= 0.0) { + // Search in a lower place + high = m + } else if (d1 < 0.0) { + // Search in an higher place + low = m + 1 + } + } + + closest = high + } + } + } + + if (closest != -1) { + val closestEntry: Entry? = mEntries!!.get(closest) + if (closestEntry != null) { + val closestXValue = closestEntry.x + if (rounding == Rounding.UP) { + // If rounding up, and found x-value is lower than specified x, and we can go upper... + if (closestXValue < xValue && closest < mEntries!!.size - 1) { + ++closest + } + } else if (rounding == Rounding.DOWN) { + // If rounding down, and found x-value is upper than specified x, and we can go lower... + if (closestXValue > xValue && closest > 0) { + --closest + } + } + + // Search by closest to y-value + if (!Float.isNaN(closestToY)) { + while (closest > 0 && mEntries!!.get(closest - 1)!!.x == closestXValue) { + closest -= 1 + } + + var closestYValue = closestEntry.y + var closestYIndex = closest + + while (true) { + closest += 1 + if (closest >= mEntries!!.size) { + break + } + + val value: Entry? = mEntries!!.get(closest) + + if (value == null) { + continue + } + + if (value.x != closestXValue) { + break + } + + if (abs(value.y - closestToY) <= abs(closestYValue - closestToY)) { + closestYValue = closestToY + closestYIndex = closest + } + } + + closest = closestYIndex + } + } + } + return closest + } + + override fun getEntriesForXValue(xValue: kotlin.Float): MutableList { + val entries: MutableList = ArrayList() + + var low = 0 + var high = mEntries!!.size - 1 + + while (low <= high) { + var m = (high + low) / 2 + var entry = mEntries!!.get(m) + + // if we have a match + if (xValue == entry!!.x) { + while (m > 0 && mEntries!!.get(m - 1)!!.x == xValue) { + m-- + } + + high = mEntries!!.size + + // loop over all "equal" entries + while (m < high) { + entry = mEntries!!.get(m) + if (entry!!.x == xValue) { + entries.add(entry) + } else { + break + } + m++ + } + + break + } else { + if (xValue > entry.x) { + low = m + 1 + } else { + high = m - 1 + } + } + } + + return entries + } + + /** + * Determines how to round DataSet index values for + * [DataSet.getEntryIndex] DataSet.getEntryIndex()} + * when an exact x-index is not found. + */ + enum class Rounding { + UP, + DOWN, + CLOSEST, + } +} \ No newline at end of file diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineDataSet.java deleted file mode 100644 index a20e0a2e87..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineDataSet.java +++ /dev/null @@ -1,391 +0,0 @@ - -package com.github.mikephil.charting.data; - -import android.content.Context; -import android.graphics.Color; -import android.graphics.DashPathEffect; -import android.util.Log; - -import com.github.mikephil.charting.components.YAxis; -import com.github.mikephil.charting.formatter.DefaultFillFormatter; -import com.github.mikephil.charting.formatter.IFillFormatter; -import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; -import com.github.mikephil.charting.utils.ColorTemplate; -import com.github.mikephil.charting.utils.UtilsKtKt; - -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; - -public class LineDataSet extends LineRadarDataSet implements ILineDataSet { - - /** - * Drawing mode for this line dataset - **/ - private LineDataSet.Mode mLineDataSetMode = Mode.LINEAR; - - /** - * List representing all colors that are used for the circles - */ - private List mCircleColors = null; - - /** - * the color of the inner circles - */ - private int mCircleHoleColor = Color.WHITE; - - /** - * the radius of the circle-shaped value indicators - */ - private float mCircleRadius = 8f; - - /** - * the hole radius of the circle-shaped value indicators - */ - private float mCircleHoleRadius = 4f; - - /** - * sets the intensity of the cubic lines - */ - private float mCubicIntensity = 0.2f; - - /** - * the path effect of this DataSet that makes dashed lines possible - */ - private DashPathEffect mDashPathEffect = null; - - /** - * formatter for customizing the position of the fill-line - */ - private IFillFormatter mFillFormatter = new DefaultFillFormatter(); - - /** - * if true, drawing circles is enabled - */ - private boolean mDrawCircles = true; - - private boolean mDrawCircleHole = true; - - - public LineDataSet(List yVals, String label) { - super(yVals, label); - - // mCircleRadius = UtilsKtKt.convertDpToPixel(4f); - // mLineWidth = UtilsKtKt.convertDpToPixel(1f); - - if (mCircleColors == null) { - mCircleColors = new ArrayList<>(); - } - mCircleColors.clear(); - - // default colors - // mColors.add(Color.rgb(192, 255, 140)); - // mColors.add(Color.rgb(255, 247, 140)); - mCircleColors.add(Color.rgb(140, 234, 255)); - } - - @Override - public DataSet copy() { - List entries = new ArrayList<>(); - for (int i = 0; i < mEntries.size(); i++) { - entries.add(mEntries.get(i).copy()); - } - LineDataSet copied = new LineDataSet(entries, getLabel()); - copy(copied); - return copied; - } - - protected void copy(LineDataSet lineDataSet) { - super.copy((BaseDataSet) lineDataSet); - lineDataSet.mCircleColors = mCircleColors; - lineDataSet.mCircleHoleColor = mCircleHoleColor; - lineDataSet.mCircleHoleRadius = mCircleHoleRadius; - lineDataSet.mCircleRadius = mCircleRadius; - lineDataSet.mCubicIntensity = mCubicIntensity; - lineDataSet.mDashPathEffect = mDashPathEffect; - lineDataSet.mDrawCircleHole = mDrawCircleHole; - lineDataSet.mDrawCircles = mDrawCircleHole; - lineDataSet.mFillFormatter = mFillFormatter; - lineDataSet.mLineDataSetMode = mLineDataSetMode; - } - - /** - * Returns the drawing mode for this line dataset - */ - @Override - public LineDataSet.Mode getLineMode() { - return mLineDataSetMode; - } - - /** - * Returns the drawing mode for this LineDataSet - */ - public void setLineMode(LineDataSet.Mode mode) { - mLineDataSetMode = mode; - } - - /** - * Sets the intensity for cubic lines (if enabled). Max = 1f = very cubic, - * Min = 0.05f = low cubic effect, Default: 0.2f - */ - public void setCubicIntensity(float intensity) { - - if (intensity > 1f) { - intensity = 1f; - } - if (intensity < 0.05f) { - intensity = 0.05f; - } - - mCubicIntensity = intensity; - } - - @Override - public float getCubicIntensity() { - return mCubicIntensity; - } - - - /** - * Sets the radius of the drawn circles. - * Default radius = 4f, Min = 1f - */ - public void setCircleRadius(float radius) { - - if (radius >= 1f) { - mCircleRadius = UtilsKtKt.convertDpToPixel(radius); - } else { - Log.e("LineDataSet", "Circle radius cannot be < 1"); - } - } - - @Override - public float getCircleRadius() { - return mCircleRadius; - } - - /** - * Sets the hole radius of the drawn circles. - * Default radius = 2f, Min = 0.5f - */ - public void setCircleHoleRadius(float holeRadius) { - - if (holeRadius >= 0.5f) { - mCircleHoleRadius = UtilsKtKt.convertDpToPixel(holeRadius); - } else { - Log.e("LineDataSet", "Circle radius cannot be < 0.5"); - } - } - - @Override - public float getCircleHoleRadius() { - return mCircleHoleRadius; - } - - /** - * sets the size (radius) of the circle shpaed value indicators, - * default size = 4f - *

- * This method is deprecated because of unclarity. Use setCircleRadius instead. - */ - @Deprecated - public void setCircleSize(float size) { - setCircleRadius(size); - } - - /** - * This function is deprecated because of unclarity. Use getCircleRadius instead. - */ - @Deprecated - public float getCircleSize() { - return getCircleRadius(); - } - - /** - * Enables the line to be drawn in dashed mode, e.g. like this - * "- - - - - -". THIS ONLY WORKS IF HARDWARE-ACCELERATION IS TURNED OFF. - * Keep in mind that hardware acceleration boosts performance. - * - * @param lineLength the length of the line pieces - * @param spaceLength the length of space in between the pieces - * @param phase offset, in degrees (normally, use 0) - */ - public void enableDashedLine(float lineLength, float spaceLength, float phase) { - mDashPathEffect = new DashPathEffect(new float[]{ - lineLength, spaceLength - }, phase); - } - - /** - * Disables the line to be drawn in dashed mode. - */ - public void disableDashedLine() { - mDashPathEffect = null; - } - - @Override - public boolean isDashedLineEnabled() { - return mDashPathEffect != null; - } - - @Override - public DashPathEffect getDashPathEffect() { - return mDashPathEffect; - } - - /** - * set this to true to enable the drawing of circle indicators for this - * DataSet, default true - */ - public void setDrawCircles(boolean enabled) { - this.mDrawCircles = enabled; - } - - @Override - public boolean isDrawCirclesEnabled() { - return mDrawCircles; - } - - @Deprecated - @Override - public boolean isDrawCubicEnabled() { - return mLineDataSetMode == Mode.CUBIC_BEZIER; - } - - @Deprecated - @Override - public boolean isDrawSteppedEnabled() { - return mLineDataSetMode == Mode.STEPPED; - } - - /** - * returns all colors specified for the circles - */ - public List getCircleColors() { - return mCircleColors; - } - - @Override - public int getCircleColor(int index) { - return mCircleColors.get(index); - } - - @Override - public int getCircleColorCount() { - return mCircleColors.size(); - } - - /** - * Sets the colors that should be used for the circles of this DataSet. - * Colors are reused as soon as the number of Entries the DataSet represents - * is higher than the size of the colors array. Make sure that the colors - * are already prepared (by calling getResources().getColor(...)) before - * adding them to the DataSet. - */ - public void setCircleColors(List colors) { - mCircleColors = colors; - } - - /** - * Sets the colors that should be used for the circles of this DataSet. - * Colors are reused as soon as the number of Entries the DataSet represents - * is higher than the size of the colors array. Make sure that the colors - * are already prepared (by calling getResources().getColor(...)) before - * adding them to the DataSet. - */ - public void setCircleColors(int... colors) { - this.mCircleColors = ColorTemplate.createColors(colors); - } - - /** - * ets the colors that should be used for the circles of this DataSet. - * Colors are reused as soon as the number of Entries the DataSet represents - * is higher than the size of the colors array. You can use - * "new String[] { R.color.red, R.color.green, ... }" to provide colors for - * this method. Internally, the colors are resolved using - * getResources().getColor(...) - */ - public void setCircleColors(int[] colors, Context c) { - - List clrs = mCircleColors; - if (clrs == null) { - clrs = new ArrayList<>(); - } - clrs.clear(); - - for (int color : colors) { - clrs.add(c.getResources().getColor(color)); - } - - mCircleColors = clrs; - } - - /** - * Sets the one and ONLY color that should be used for this DataSet. - * Internally, this recreates the colors array and adds the specified color. - */ - public void setCircleColor(int color) { - resetCircleColors(); - mCircleColors.add(color); - } - - /** - * resets the circle-colors array and creates a new one - */ - public void resetCircleColors() { - if (mCircleColors == null) { - mCircleColors = new ArrayList<>(); - } - mCircleColors.clear(); - } - - /** - * Sets the color of the inner circle of the line-circles. - */ - public void setCircleHoleColor(int color) { - mCircleHoleColor = color; - } - - @Override - public int getCircleHoleColor() { - return mCircleHoleColor; - } - - /** - * Set this to true to allow drawing a hole in each data circle. - */ - public void setDrawCircleHole(boolean enabled) { - mDrawCircleHole = enabled; - } - - @Override - public boolean isDrawCircleHoleEnabled() { - return mDrawCircleHole; - } - - /** - * Sets a custom IFillFormatter to the chart that handles the position of the - * filled-line for each DataSet. Set this to null to use the default logic. - */ - public void setFillFormatter(IFillFormatter formatter) { - - if (formatter == null) { - mFillFormatter = new DefaultFillFormatter(); - } else { - mFillFormatter = formatter; - } - } - - @Override - public IFillFormatter getFillFormatter() { - return mFillFormatter; - } - - public enum Mode { - LINEAR, - STEPPED, - CUBIC_BEZIER, - HORIZONTAL_BEZIER - } -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineDataSet.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineDataSet.kt new file mode 100644 index 0000000000..2928ae46ac --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineDataSet.kt @@ -0,0 +1,353 @@ +package com.github.mikephil.charting.data + +import android.content.Context +import android.graphics.Color +import android.graphics.DashPathEffect +import android.util.Log +import com.github.mikephil.charting.formatter.DefaultFillFormatter +import com.github.mikephil.charting.formatter.IFillFormatter +import com.github.mikephil.charting.interfaces.datasets.ILineDataSet +import com.github.mikephil.charting.utils.ColorTemplate +import com.github.mikephil.charting.utils.convertDpToPixel + +class LineDataSet(yVals: MutableList?, label: String?) : LineRadarDataSet(yVals, label), ILineDataSet { + /** + * Drawing mode for this line dataset + */ + private var mLineDataSetMode: Mode? = Mode.LINEAR + + /** + * returns all colors specified for the circles + */ + /** + * Sets the colors that should be used for the circles of this DataSet. + * Colors are reused as soon as the number of Entries the DataSet represents + * is higher than the size of the colors array. Make sure that the colors + * are already prepared (by calling getResources().getColor(...)) before + * adding them to the DataSet. + */ + /** + * List representing all colors that are used for the circles + */ + var circleColors: MutableList? = null + + /** + * the color of the inner circles + */ + private var mCircleHoleColor = Color.WHITE + + /** + * the radius of the circle-shaped value indicators + */ + private var mCircleRadius = 8f + + /** + * the hole radius of the circle-shaped value indicators + */ + private var mCircleHoleRadius = 4f + + /** + * sets the intensity of the cubic lines + */ + private var mCubicIntensity = 0.2f + + /** + * the path effect of this DataSet that makes dashed lines possible + */ + private var mDashPathEffect: DashPathEffect? = null + + /** + * formatter for customizing the position of the fill-line + */ + private var mFillFormatter: IFillFormatter? = DefaultFillFormatter() + + /** + * if true, drawing circles is enabled + */ + private var mDrawCircles = true + + private var mDrawCircleHole = true + + + init { + // mCircleRadius = UtilsKtKt.convertDpToPixel(4f); + // mLineWidth = UtilsKtKt.convertDpToPixel(1f); + if (this.circleColors == null) { + this.circleColors = ArrayList() + } + circleColors!!.clear() + + // default colors + // mColors.add(Color.rgb(192, 255, 140)); + // mColors.add(Color.rgb(255, 247, 140)); + circleColors!!.add(Color.rgb(140, 234, 255)) + } + + override fun copy(): DataSet { + val entries: MutableList = ArrayList() + for (i in mEntries!!.indices) { + entries.add(mEntries!![i]!!.copy()) + } + val copied = LineDataSet(entries, label) + copy(copied) + return copied + } + + protected fun copy(lineDataSet: LineDataSet) { + super.copy((lineDataSet as BaseDataSet<*>?)!!) + lineDataSet.circleColors = this.circleColors + lineDataSet.mCircleHoleColor = mCircleHoleColor + lineDataSet.mCircleHoleRadius = mCircleHoleRadius + lineDataSet.mCircleRadius = mCircleRadius + lineDataSet.mCubicIntensity = mCubicIntensity + lineDataSet.mDashPathEffect = mDashPathEffect + lineDataSet.mDrawCircleHole = mDrawCircleHole + lineDataSet.mDrawCircles = mDrawCircleHole + lineDataSet.mFillFormatter = mFillFormatter + lineDataSet.mLineDataSetMode = mLineDataSetMode + } + + /** + * Returns the drawing mode for this line dataset + */ + override fun getLineMode(): Mode? { + return mLineDataSetMode + } + + /** + * Returns the drawing mode for this LineDataSet + */ + fun setLineMode(mode: Mode?) { + mLineDataSetMode = mode + } + + /** + * Sets the intensity for cubic lines (if enabled). Max = 1f = very cubic, + * Min = 0.05f = low cubic effect, Default: 0.2f + */ + fun setCubicIntensity(intensity: Float) { + var intensity = intensity + if (intensity > 1f) { + intensity = 1f + } + if (intensity < 0.05f) { + intensity = 0.05f + } + + mCubicIntensity = intensity + } + + override fun getCubicIntensity(): Float { + return mCubicIntensity + } + + + /** + * Sets the radius of the drawn circles. + * Default radius = 4f, Min = 1f + */ + fun setCircleRadius(radius: Float) { + if (radius >= 1f) { + mCircleRadius = radius.convertDpToPixel() + } else { + Log.e("LineDataSet", "Circle radius cannot be < 1") + } + } + + override fun getCircleRadius(): Float { + return mCircleRadius + } + + /** + * Sets the hole radius of the drawn circles. + * Default radius = 2f, Min = 0.5f + */ + fun setCircleHoleRadius(holeRadius: Float) { + if (holeRadius >= 0.5f) { + mCircleHoleRadius = holeRadius.convertDpToPixel() + } else { + Log.e("LineDataSet", "Circle radius cannot be < 0.5") + } + } + + override fun getCircleHoleRadius(): Float { + return mCircleHoleRadius + } + + @get:Deprecated("") + @set:Deprecated("") + var circleSize: Float + /** + * This function is deprecated because of unclarity. Use getCircleRadius instead. + */ + get() = circleRadius + /** + * sets the size (radius) of the circle shpaed value indicators, + * default size = 4f + * + * + * This method is deprecated because of unclarity. Use setCircleRadius instead. + */ + set(size) { + setCircleRadius(size) + } + + /** + * Enables the line to be drawn in dashed mode, e.g. like this + * "- - - - - -". THIS ONLY WORKS IF HARDWARE-ACCELERATION IS TURNED OFF. + * Keep in mind that hardware acceleration boosts performance. + * + * @param lineLength the length of the line pieces + * @param spaceLength the length of space in between the pieces + * @param phase offset, in degrees (normally, use 0) + */ + fun enableDashedLine(lineLength: Float, spaceLength: Float, phase: Float) { + mDashPathEffect = DashPathEffect( + floatArrayOf( + lineLength, spaceLength + ), phase + ) + } + + /** + * Disables the line to be drawn in dashed mode. + */ + fun disableDashedLine() { + mDashPathEffect = null + } + + override fun isDashedLineEnabled(): Boolean { + return mDashPathEffect != null + } + + override fun getDashPathEffect(): DashPathEffect? { + return mDashPathEffect + } + + /** + * set this to true to enable the drawing of circle indicators for this + * DataSet, default true + */ + fun setDrawCircles(enabled: Boolean) { + this.mDrawCircles = enabled + } + + override fun isDrawCirclesEnabled(): Boolean { + return mDrawCircles + } + + @Deprecated("") + override fun isDrawCubicEnabled(): Boolean { + return mLineDataSetMode == Mode.CUBIC_BEZIER + } + + @Deprecated("") + override fun isDrawSteppedEnabled(): Boolean { + return mLineDataSetMode == Mode.STEPPED + } + + override fun getCircleColor(index: Int): Int { + return circleColors!!.get(index)!! + } + + override fun getCircleColorCount(): Int { + return circleColors!!.size + } + + /** + * Sets the colors that should be used for the circles of this DataSet. + * Colors are reused as soon as the number of Entries the DataSet represents + * is higher than the size of the colors array. Make sure that the colors + * are already prepared (by calling getResources().getColor(...)) before + * adding them to the DataSet. + */ + fun setCircleColors(vararg colors: Int) { + this.circleColors = ColorTemplate.createColors(colors) + } + + /** + * ets the colors that should be used for the circles of this DataSet. + * Colors are reused as soon as the number of Entries the DataSet represents + * is higher than the size of the colors array. You can use + * "new String[] { R.color.red, R.color.green, ... }" to provide colors for + * this method. Internally, the colors are resolved using + * getResources().getColor(...) + */ + fun setCircleColors(colors: IntArray, c: Context) { + var clrs = this.circleColors + if (clrs == null) { + clrs = ArrayList() + } + clrs.clear() + + for (color in colors) { + clrs.add(c.resources.getColor(color)) + } + + this.circleColors = clrs + } + + /** + * Sets the one and ONLY color that should be used for this DataSet. + * Internally, this recreates the colors array and adds the specified color. + */ + fun setCircleColor(color: Int) { + resetCircleColors() + circleColors!!.add(color) + } + + /** + * resets the circle-colors array and creates a new one + */ + fun resetCircleColors() { + if (this.circleColors == null) { + this.circleColors = ArrayList() + } + circleColors!!.clear() + } + + /** + * Sets the color of the inner circle of the line-circles. + */ + fun setCircleHoleColor(color: Int) { + mCircleHoleColor = color + } + + override fun getCircleHoleColor(): Int { + return mCircleHoleColor + } + + /** + * Set this to true to allow drawing a hole in each data circle. + */ + fun setDrawCircleHole(enabled: Boolean) { + mDrawCircleHole = enabled + } + + override fun isDrawCircleHoleEnabled(): Boolean { + return mDrawCircleHole + } + + /** + * Sets a custom IFillFormatter to the chart that handles the position of the + * filled-line for each DataSet. Set this to null to use the default logic. + */ + fun setFillFormatter(formatter: IFillFormatter?) { + if (formatter == null) { + mFillFormatter = DefaultFillFormatter() + } else { + mFillFormatter = formatter + } + } + + override fun getFillFormatter(): IFillFormatter? { + return mFillFormatter + } + + enum class Mode { + LINEAR, + STEPPED, + CUBIC_BEZIER, + HORIZONTAL_BEZIER + } +} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/PieDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/PieDataSet.java index 40b894714c..77c06b607a 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/PieDataSet.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/PieDataSet.java @@ -4,7 +4,6 @@ import androidx.annotation.Nullable; import com.github.mikephil.charting.interfaces.datasets.IPieDataSet; -import com.github.mikephil.charting.utils.Utils; import com.github.mikephil.charting.utils.UtilsKtKt; import java.util.ArrayList; diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.kt index 75318c3a81..ee7395256b 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.kt @@ -2,7 +2,7 @@ package com.github.mikephil.charting.interfaces.datasets import com.github.mikephil.charting.data.Entry -interface IBarLineScatterCandleBubbleDataSet : IDataSet { +interface IBarLineScatterCandleBubbleDataSet : IDataSet { val highLightColor: Int } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IDataSet.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IDataSet.kt index 25affa43d4..4eddea6f88 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IDataSet.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IDataSet.kt @@ -9,7 +9,7 @@ import com.github.mikephil.charting.data.Entry import com.github.mikephil.charting.formatter.IValueFormatter import com.github.mikephil.charting.utils.MPPointF -interface IDataSet { +interface IDataSet { /** * returns the minimum y-value this DataSet holds */ @@ -107,7 +107,7 @@ interface IDataSet { * Returns the position of the provided entry in the DataSets Entry array. * Returns -1 if doesn't exist. */ - fun getEntryIndex(e: T): Int + fun getEntryIndex(entry: T): Int /** * This method returns the actual @@ -181,7 +181,7 @@ interface IDataSet { /** * Sets the label string that describes the DataSet. */ - var label: String? + var label: String /** * Set the y-axis this DataSet should be plotted against (either LEFT or RIGHT). Default: LEFT diff --git a/MPChartLib/src/test/kotlin/com/github/mikephil/charting/test/ChartDataTest.kt b/MPChartLib/src/test/kotlin/com/github/mikephil/charting/test/ChartDataTest.kt index 2658ee6a14..f70a53b675 100644 --- a/MPChartLib/src/test/kotlin/com/github/mikephil/charting/test/ChartDataTest.kt +++ b/MPChartLib/src/test/kotlin/com/github/mikephil/charting/test/ChartDataTest.kt @@ -12,14 +12,14 @@ import org.junit.Test class ChartDataTest { @Test fun testDynamicChartData() { - val entries1: MutableList = ArrayList() + val entries1: MutableList = ArrayList() entries1.add(Entry(10f, 10f)) entries1.add(Entry(15f, -2f)) entries1.add(Entry(21f, 50f)) val set1 = ScatterDataSet(entries1, "") - val entries2: MutableList = ArrayList() + val entries2: MutableList = ArrayList() entries2.add(Entry(-1f, 10f)) entries2.add(Entry(10f, 2f)) entries2.add(Entry(20f, 5f)) @@ -66,7 +66,7 @@ class ChartDataTest { Assert.assertEquals(-100f, data.getYMin(YAxis.AxisDependency.RIGHT), 0.01f) Assert.assertEquals(100f, data.getYMax(YAxis.AxisDependency.RIGHT), 0.01f) - val entries3: MutableList = ArrayList() + val entries3: MutableList = ArrayList() entries3.add(Entry(0f, 200f)) entries3.add(Entry(0f, -50f)) @@ -96,7 +96,7 @@ class ChartDataTest { Assert.assertEquals(0, lineData.dataSetCount) - val lineEntries1: MutableList = ArrayList() + val lineEntries1: MutableList = ArrayList() lineEntries1.add(Entry(10f, 90f)) lineEntries1.add(Entry(1000f, 1000f)) @@ -120,7 +120,7 @@ class ChartDataTest { Assert.assertEquals(90f, lineData.getYMin(YAxis.AxisDependency.RIGHT), 0.01f) Assert.assertEquals(1000f, lineData.getYMax(YAxis.AxisDependency.RIGHT), 0.01f) - val lineEntries2: MutableList = ArrayList() + val lineEntries2: MutableList = ArrayList() lineEntries2.add(Entry(-1000f, 2000f)) lineEntries2.add(Entry(2000f, -3000f)) diff --git a/MPChartLib/src/test/kotlin/com/github/mikephil/charting/test/DataSetTest.kt b/MPChartLib/src/test/kotlin/com/github/mikephil/charting/test/DataSetTest.kt index c89fb1054d..574f5d782b 100644 --- a/MPChartLib/src/test/kotlin/com/github/mikephil/charting/test/DataSetTest.kt +++ b/MPChartLib/src/test/kotlin/com/github/mikephil/charting/test/DataSetTest.kt @@ -9,7 +9,7 @@ import org.junit.Test class DataSetTest { @Test fun testCalcMinMax() { - val entries: MutableList = ArrayList() + val entries: MutableList = ArrayList() entries.add(Entry(10f, 10f)) entries.add(Entry(15f, 2f)) entries.add(Entry(21f, 5f)) @@ -45,7 +45,7 @@ class DataSetTest { @Test fun testAddRemoveEntry() { - val entries: MutableList = ArrayList() + val entries: MutableList = ArrayList() entries.add(Entry(10f, 10f)) entries.add(Entry(15f, 2f)) entries.add(Entry(21f, 5f)) @@ -129,7 +129,7 @@ class DataSetTest { @Test fun testGetEntryForXValue() { - val entries: MutableList = ArrayList() + val entries: MutableList = ArrayList() entries.add(Entry(10f, 10f)) entries.add(Entry(15f, 5f)) entries.add(Entry(21f, 5f)) @@ -169,7 +169,7 @@ class DataSetTest { fun testGetEntryForXValueWithDuplicates() { // sorted list of values (by x position) - val values: MutableList = ArrayList() + val values: MutableList = ArrayList() values.add(Entry(0f, 10f)) values.add(Entry(1f, 20f)) values.add(Entry(2f, 30f)) @@ -210,15 +210,15 @@ class DataSetTest { Assert.assertEquals(60f, closest.y, 0.01f) var entries = set.getEntriesForXValue(4f) - Assert.assertEquals(2, entries!!.size) + Assert.assertEquals(2, entries.size) Assert.assertEquals(60f, entries[0]!!.y, 0.01f) Assert.assertEquals(70f, entries[1]!!.y, 0.01f) entries = set.getEntriesForXValue(3.5f) - Assert.assertEquals(0, entries!!.size) + Assert.assertEquals(0, entries.size) entries = set.getEntriesForXValue(2f) - Assert.assertEquals(1, entries!!.size) + Assert.assertEquals(1, entries.size) Assert.assertEquals(30f, entries[0]!!.y, 0.01f) } } diff --git a/app/src/main/kotlin/info/appdev/chartexample/AnotherBarActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/AnotherBarActivity.kt index b7844bc4f5..50bc0f1009 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/AnotherBarActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/AnotherBarActivity.kt @@ -90,7 +90,7 @@ class AnotherBarActivity : DemoBase(), OnSeekBarChangeListener { chart!!.data!!.getDataSetCount() > 0 ) { set1 = chart!!.data!!.getDataSetByIndex(0) as BarDataSet - set1.setEntries(values) + set1.entries = values chart!!.data!!.notifyDataChanged() chart!!.notifyDataSetChanged() } else { diff --git a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivity.kt index 3e9b76dcda..755cb0862f 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivity.kt @@ -148,7 +148,7 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect chart!!.data!!.getDataSetCount() > 0 ) { set1 = chart!!.data!!.getDataSetByIndex(0) as BarDataSet - set1.setEntries(values) + set1.entries = values chart!!.data!!.notifyDataChanged() chart!!.notifyDataSetChanged() } else { diff --git a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt index d13fc3bf12..498ee8f7f3 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt @@ -142,10 +142,10 @@ class BarChartActivityMultiDataset : DemoBase(), OnSeekBarChangeListener, OnChar set2 = chart!!.data!!.getDataSetByIndex(1) as BarDataSet set3 = chart!!.data!!.getDataSetByIndex(2) as BarDataSet set4 = chart!!.data!!.getDataSetByIndex(3) as BarDataSet - set1.setEntries(values1) - set2.setEntries(values2) - set3.setEntries(values3) - set4.setEntries(values4) + set1.entries = values1 + set2.entries = values2 + set3.entries = values3 + set4.entries = values4 chart!!.data!!.notifyDataChanged() chart!!.notifyDataSetChanged() } else { diff --git a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivitySinus.kt b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivitySinus.kt index 098a5190c1..99f68d2c0c 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivitySinus.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivitySinus.kt @@ -100,7 +100,7 @@ class BarChartActivitySinus : DemoBase(), OnSeekBarChangeListener { binding.chart1.data!!.getDataSetCount() > 0 ) { set = binding.chart1.data!!.getDataSetByIndex(0) as BarDataSet - set.setEntries(entries) + set.entries = entries binding.chart1.data!!.notifyDataChanged() binding.chart1.notifyDataSetChanged() } else { diff --git a/app/src/main/kotlin/info/appdev/chartexample/BarChartPositiveNegative.kt b/app/src/main/kotlin/info/appdev/chartexample/BarChartPositiveNegative.kt index a4d4fa00b4..b619396b5c 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/BarChartPositiveNegative.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/BarChartPositiveNegative.kt @@ -108,7 +108,7 @@ class BarChartPositiveNegative : DemoBase() { chart!!.data!!.getDataSetCount() > 0 ) { set = chart!!.data!!.getDataSetByIndex(0) as BarDataSet - set.setEntries(values) + set.entries = values chart!!.data!!.notifyDataChanged() chart!!.notifyDataSetChanged() } else { diff --git a/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt index 95d3552299..4fb5484adc 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt @@ -90,7 +90,7 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener { } private fun setData(count: Int, range: Float) { - val values = ArrayList() + val values = ArrayList() val sampleValues = getMuchValues(count) for (i in 0 until count) { @@ -118,7 +118,7 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener { set1.setLineWidth(1.8f) set1.circleRadius = 4f set1.setCircleColor(Color.WHITE) - set1.setHighLightColor(Color.rgb(244, 117, 117)) + set1.highLightColor = Color.rgb(244, 117, 117) set1.color = Color.WHITE set1.setFillColor(Color.WHITE) set1.setFillAlpha(100) diff --git a/app/src/main/kotlin/info/appdev/chartexample/DataTools.kt b/app/src/main/kotlin/info/appdev/chartexample/DataTools.kt index e5cd57ff69..31a1b99510 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/DataTools.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/DataTools.kt @@ -144,7 +144,7 @@ class DataTools { fun setData(context: Context, lineChart: LineChart, count: Int = VAL_COUNT, range: Float = VAL_RANGE) { Timber.d("count=$count range=$range") - val values = ArrayList() + val values = ArrayList() if (count == VAL_COUNT) { VAL_FIX.forEachIndexed { index, d -> values.add(Entry(index.toFloat(), d.toFloat(), ContextCompat.getDrawable(context, R.drawable.star))) @@ -170,7 +170,7 @@ class DataTools { } private fun createDataset( - values: ArrayList, + values: ArrayList, lineChart: LineChart, context: Context ) { diff --git a/app/src/main/kotlin/info/appdev/chartexample/DrawChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/DrawChartActivity.kt index 76b5eec1e6..f9d78e241e 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/DrawChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/DrawChartActivity.kt @@ -58,7 +58,7 @@ class DrawChartActivity : DemoBase(), OnChartValueSelectedListener, OnDrawListen } private fun initWithDummyData() { - val values = ArrayList() + val values = ArrayList() // create a dataset and give it a type (0) val set1 = LineDataSet(values, "DataSet") diff --git a/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt index 0beccbf3d7..e7125fe7f7 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt @@ -122,7 +122,7 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener { set.color = color set.setCircleColor(color) - set.setHighLightColor(color) + set.highLightColor = color set.valueTextSize = 10f set.setSingleValueTextColor(color) @@ -150,7 +150,7 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener { set.circleRadius = 4.5f set.color = Color.rgb(240, 99, 99) set.setCircleColor(Color.rgb(240, 99, 99)) - set.setHighLightColor(Color.rgb(190, 190, 190)) + set.highLightColor = Color.rgb(190, 190, 190) set.axisDependency = AxisDependency.LEFT set.valueTextSize = 10f diff --git a/app/src/main/kotlin/info/appdev/chartexample/FilledLineActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/FilledLineActivity.kt index a0bb5b7965..e72209e327 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/FilledLineActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/FilledLineActivity.kt @@ -92,8 +92,8 @@ class FilledLineActivity : DemoBase() { ) { set1 = binding.chart1.data!!.getDataSetByIndex(0) as LineDataSet set2 = binding.chart1.data!!.getDataSetByIndex(1) as LineDataSet - set1.setEntries(valuesArray1) - set2.setEntries(valuesArray2) + set1.entries = valuesArray1 + set2.entries = valuesArray2 binding.chart1.data!!.notifyDataChanged() binding.chart1.notifyDataSetChanged() } else { @@ -108,7 +108,7 @@ class FilledLineActivity : DemoBase() { set1.setFillAlpha(255) set1.setDrawFilled(true) set1.setFillColor(Color.WHITE) - set1.setHighLightColor(Color.rgb(244, 117, 117)) + set1.highLightColor = Color.rgb(244, 117, 117) set1.setDrawCircleHole(false) set1.fillFormatter = object : IFillFormatter { override fun getFillLinePosition(dataSet: ILineDataSet?, dataProvider: LineDataProvider?): Float { @@ -129,7 +129,7 @@ class FilledLineActivity : DemoBase() { set2.setDrawFilled(true) set2.setFillColor(Color.WHITE) set2.setDrawCircleHole(false) - set2.setHighLightColor(Color.rgb(244, 117, 117)) + set2.highLightColor = Color.rgb(244, 117, 117) set2.fillFormatter = object : IFillFormatter { override fun getFillLinePosition(dataSet: ILineDataSet?, dataProvider: LineDataProvider?): Float { // change the return value here to better understand the effect diff --git a/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarChartActivity.kt index fa0ec6fcc3..9e321fb09c 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarChartActivity.kt @@ -119,7 +119,7 @@ class HorizontalBarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartV binding.chart1.data!!.getDataSetCount() > 0 ) { set1 = binding.chart1.data!!.getDataSetByIndex(0) as BarDataSet - set1.setEntries(values) + set1.entries = values binding.chart1.data!!.notifyDataChanged() binding.chart1.notifyDataSetChanged() } else { diff --git a/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarNegativeChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarNegativeChartActivity.kt index bbf03ba397..1536d43e3d 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarNegativeChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarNegativeChartActivity.kt @@ -126,7 +126,7 @@ class HorizontalBarNegativeChartActivity : DemoBase(), OnSeekBarChangeListener, chart!!.data!!.getDataSetCount() > 0 ) { set1 = chart!!.data!!.getDataSetByIndex(0) as BarDataSet - set1.setEntries(values) + set1.entries = values chart!!.data!!.notifyDataChanged() chart!!.notifyDataSetChanged() } else { diff --git a/app/src/main/kotlin/info/appdev/chartexample/LineChartActivityColored.kt b/app/src/main/kotlin/info/appdev/chartexample/LineChartActivityColored.kt index 66b84d3517..491a3078ff 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/LineChartActivityColored.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/LineChartActivityColored.kt @@ -110,7 +110,7 @@ class LineChartActivityColored : DemoBase() { set1.circleHoleRadius = 2.5f set1.color = Color.WHITE set1.setCircleColor(Color.WHITE) - set1.setHighLightColor(Color.WHITE) + set1.highLightColor = Color.WHITE set1.isDrawValues = false // create a data object with the data sets diff --git a/app/src/main/kotlin/info/appdev/chartexample/LineChartDualAxisActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/LineChartDualAxisActivity.kt index c841275013..a2e8d8d1ec 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/LineChartDualAxisActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/LineChartDualAxisActivity.kt @@ -153,9 +153,9 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa set1 = chart!!.data!!.getDataSetByIndex(0) as LineDataSet set2 = chart!!.data!!.getDataSetByIndex(1) as LineDataSet set3 = chart!!.data!!.getDataSetByIndex(2) as LineDataSet - set1.setEntries(values1) - set2.setEntries(values2) - set3.setEntries(values3) + set1.entries = values1 + set2.entries = values2 + set3.entries = values3 chart!!.data!!.notifyDataChanged() chart!!.notifyDataSetChanged() } else { @@ -169,7 +169,7 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa set1.circleRadius = 3f set1.setFillAlpha(65) set1.setFillColor(ColorTemplate.getHoloBlue()) - set1.setHighLightColor(Color.rgb(244, 117, 117)) + set1.highLightColor = Color.rgb(244, 117, 117) set1.setDrawCircleHole(false) //set1.setFillFormatter(new MyFillFormatter(0f)); @@ -187,7 +187,7 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa set2.setFillAlpha(65) set2.setFillColor(Color.BLUE) set2.setDrawCircleHole(false) - set2.setHighLightColor(Color.rgb(244, 117, 117)) + set2.highLightColor = Color.rgb(244, 117, 117) //set2.setFillFormatter(new MyFillFormatter(900f)); set3 = LineDataSet(values3, "DataSet 3") @@ -199,7 +199,7 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa set3.setFillAlpha(65) set3.setFillColor(ColorTemplate.colorWithAlpha(Color.YELLOW, 200)) set3.setDrawCircleHole(false) - set3.setHighLightColor(Color.rgb(244, 117, 117)) + set3.highLightColor = Color.rgb(244, 117, 117) // create a data object with the data sets val data = LineData(set1, set2, set3) diff --git a/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt index 84c1c194c6..1adff9746b 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt @@ -137,7 +137,7 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener { set1.isDrawValues = false set1.setFillAlpha(65) set1.setFillColor(ColorTemplate.getHoloBlue()) - set1.setHighLightColor(Color.rgb(244, 117, 117)) + set1.highLightColor = Color.rgb(244, 117, 117) set1.setDrawCircleHole(false) // create a data object with the data sets diff --git a/app/src/main/kotlin/info/appdev/chartexample/ListViewMultiChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/ListViewMultiChartActivity.kt index 884f6241a2..d0bf6e3534 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/ListViewMultiChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/ListViewMultiChartActivity.kt @@ -91,7 +91,7 @@ class ListViewMultiChartActivity : DemoBase() { val d1 = LineDataSet(values1, "New DataSet $cnt, (1)") d1.setLineWidth(2.5f) d1.circleRadius = 4.5f - d1.setHighLightColor(Color.rgb(244, 117, 117)) + d1.highLightColor = Color.rgb(244, 117, 117) d1.isDrawValues = false val values2 = ArrayList() @@ -103,7 +103,7 @@ class ListViewMultiChartActivity : DemoBase() { val d2 = LineDataSet(values2, "New DataSet $cnt, (2)") d2.setLineWidth(2.5f) d2.circleRadius = 4.5f - d2.setHighLightColor(Color.rgb(244, 117, 117)) + d2.highLightColor = Color.rgb(244, 117, 117) d2.color = ColorTemplate.VORDIPLOM_COLORS[0] d2.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[0]) d2.isDrawValues = false diff --git a/app/src/main/kotlin/info/appdev/chartexample/RealtimeLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/RealtimeLineChartActivity.kt index dcbbbe1a02..f46d14f871 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/RealtimeLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/RealtimeLineChartActivity.kt @@ -125,7 +125,7 @@ class RealtimeLineChartActivity : DemoBase(), OnChartValueSelectedListener { set.circleRadius = 4f set.setFillAlpha(65) set.setFillColor(ColorTemplate.getHoloBlue()) - set.setHighLightColor(Color.rgb(244, 117, 117)) + set.highLightColor = Color.rgb(244, 117, 117) set.setSingleValueTextColor(Color.WHITE) set.valueTextSize = 9f set.isDrawValues = false diff --git a/app/src/main/kotlin/info/appdev/chartexample/SpecificPositionsLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/SpecificPositionsLineChartActivity.kt index 5212f980c3..63cb625014 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/SpecificPositionsLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/SpecificPositionsLineChartActivity.kt @@ -236,7 +236,7 @@ class SpecificPositionsLineChartActivity : DemoBase(), OnSeekBarChangeListener, } private fun setData(count: Int, range: Float) { - val values = ArrayList() + val values = ArrayList() val sampleValues = getValues(100) for (i in 0 until count) { val `val` = (sampleValues[i]!!.toFloat() * range) + 3 @@ -255,7 +255,7 @@ class SpecificPositionsLineChartActivity : DemoBase(), OnSeekBarChangeListener, } } - private fun createDataset(values: ArrayList) { + private fun createDataset(values: ArrayList) { // create a dataset and give it a type val set11 = LineDataSet(values, "DataSet 1") diff --git a/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivity.kt index e883cb741f..1cd2ba1ecb 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivity.kt @@ -123,7 +123,7 @@ class StackedBarActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSele chart!!.data!!.getDataSetCount() > 0 ) { set1 = chart!!.data!!.getDataSetByIndex(0) as BarDataSet - set1.setEntries(values) + set1.entries = values chart!!.data!!.notifyDataChanged() chart!!.notifyDataSetChanged() } else { From 7ea5184407ac37313b62a079a7006fc0b3918c60 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Thu, 18 Dec 2025 10:03:15 +0100 Subject: [PATCH 2/2] Kotlin several Datasets --- .../mikephil/charting/data/CandleDataSet.kt | 4 +- .../mikephil/charting/data/LineDataSet.kt | 2 +- .../charting/data/LineRadarDataSet.java | 125 --------- .../charting/data/LineRadarDataSet.kt | 81 ++++++ .../data/LineScatterCandleRadarDataSet.java | 114 -------- .../data/LineScatterCandleRadarDataSet.kt | 93 +++++++ .../mikephil/charting/data/PieDataSet.java | 252 ------------------ .../mikephil/charting/data/PieDataSet.kt | 213 +++++++++++++++ .../mikephil/charting/data/RadarDataSet.java | 122 --------- .../mikephil/charting/data/RadarDataSet.kt | 77 ++++++ .../charting/data/ScatterDataSet.java | 147 ---------- .../mikephil/charting/data/ScatterDataSet.kt | 125 +++++++++ .../interfaces/datasets/ILineRadarDataSet.kt | 2 +- .../ILineScatterCandleRadarDataSet.kt | 2 +- .../chartexample/CombinedChartActivity.kt | 4 +- .../chartexample/CubicLineChartActivity.kt | 6 +- .../info/appdev/chartexample/DataTools.kt | 6 +- .../appdev/chartexample/DrawChartActivity.kt | 2 +- .../chartexample/DynamicalAddingActivity.kt | 4 +- .../appdev/chartexample/FilledLineActivity.kt | 12 +- .../chartexample/InvertedLineChartActivity.kt | 2 +- .../chartexample/LineChartActivityColored.kt | 2 +- .../chartexample/LineChartDualAxisActivity.kt | 18 +- .../chartexample/LineChartTimeActivity.kt | 6 +- .../ListViewMultiChartActivity.kt | 4 +- .../chartexample/MultiLineChartActivity.kt | 2 +- .../chartexample/PerformanceLineChart.kt | 2 +- .../appdev/chartexample/RadarChartActivity.kt | 12 +- .../chartexample/RealtimeLineChartActivity.kt | 6 +- .../SpecificPositionsLineChartActivity.kt | 6 +- .../chartexample/fragments/SimpleFragment.kt | 12 +- 31 files changed, 646 insertions(+), 819 deletions(-) delete mode 100644 MPChartLib/src/main/java/com/github/mikephil/charting/data/LineRadarDataSet.java create mode 100644 MPChartLib/src/main/java/com/github/mikephil/charting/data/LineRadarDataSet.kt delete mode 100644 MPChartLib/src/main/java/com/github/mikephil/charting/data/LineScatterCandleRadarDataSet.java create mode 100644 MPChartLib/src/main/java/com/github/mikephil/charting/data/LineScatterCandleRadarDataSet.kt delete mode 100644 MPChartLib/src/main/java/com/github/mikephil/charting/data/PieDataSet.java create mode 100644 MPChartLib/src/main/java/com/github/mikephil/charting/data/PieDataSet.kt delete mode 100644 MPChartLib/src/main/java/com/github/mikephil/charting/data/RadarDataSet.java create mode 100644 MPChartLib/src/main/java/com/github/mikephil/charting/data/RadarDataSet.kt delete mode 100644 MPChartLib/src/main/java/com/github/mikephil/charting/data/ScatterDataSet.java create mode 100644 MPChartLib/src/main/java/com/github/mikephil/charting/data/ScatterDataSet.kt diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleDataSet.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleDataSet.kt index 24d1f6dc8e..0e0c079f30 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleDataSet.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleDataSet.kt @@ -7,10 +7,8 @@ import com.github.mikephil.charting.utils.convertDpToPixel /** * DataSet for the CandleStickChart. - * - * @author Philipp Jahoda */ -class CandleDataSet(yVals: MutableList?, label: String?) : LineScatterCandleRadarDataSet(yVals, label), ICandleDataSet { +class CandleDataSet(yVals: MutableList?, label: String = "") : LineScatterCandleRadarDataSet(yVals, label), ICandleDataSet { /** * the width of the shadow of the candle */ diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineDataSet.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineDataSet.kt index 2928ae46ac..62993e2ae7 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineDataSet.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineDataSet.kt @@ -10,7 +10,7 @@ import com.github.mikephil.charting.interfaces.datasets.ILineDataSet import com.github.mikephil.charting.utils.ColorTemplate import com.github.mikephil.charting.utils.convertDpToPixel -class LineDataSet(yVals: MutableList?, label: String?) : LineRadarDataSet(yVals, label), ILineDataSet { +class LineDataSet(yVals: MutableList?, label: String = "") : LineRadarDataSet(yVals, label), ILineDataSet { /** * Drawing mode for this line dataset */ diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineRadarDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineRadarDataSet.java deleted file mode 100644 index 8643f53278..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineRadarDataSet.java +++ /dev/null @@ -1,125 +0,0 @@ - -package com.github.mikephil.charting.data; - -import android.graphics.Color; -import android.graphics.drawable.Drawable; - -import com.github.mikephil.charting.interfaces.datasets.ILineRadarDataSet; -import com.github.mikephil.charting.utils.UtilsKtKt; - -import java.util.List; - -/** - * Base dataset for line and radar DataSets. - * - * @author Philipp Jahoda - */ -public abstract class LineRadarDataSet extends LineScatterCandleRadarDataSet implements ILineRadarDataSet { - - // TODO: Move to using `Fill` class - /** - * the color that is used for filling the line surface - */ - private int mFillColor = Color.rgb(140, 234, 255); - - /** - * the drawable to be used for filling the line surface - */ - protected Drawable mFillDrawable; - - /** - * transparency used for filling line surface - */ - private int mFillAlpha = 85; - - /** - * the width of the drawn data lines - */ - private float mLineWidth = 2.5f; - - /** - * if true, the data will also be drawn filled - */ - private boolean mDrawFilled = false; - - - public LineRadarDataSet(List yVals, String label) { - super(yVals, label); - } - - @Override - public int getFillColor() { - return mFillColor; - } - - /** - * Sets the color that is used for filling the area below the line. - * Resets an eventually set "fillDrawable". - */ - public void setFillColor(int color) { - mFillColor = color; - mFillDrawable = null; - } - - @Override - public Drawable getFillDrawable() { - return mFillDrawable; - } - - /** - * Sets the drawable to be used to fill the area below the line. - */ - public void setFillDrawable(Drawable drawable) { - this.mFillDrawable = drawable; - } - - @Override - public int getFillAlpha() { - return mFillAlpha; - } - - /** - * sets the alpha value (transparency) that is used for filling the line - * surface (0-255), default: 85 - */ - public void setFillAlpha(int alpha) { - mFillAlpha = alpha; - } - - /** - * set the line width of the chart (min = 0.2f, max = 10f); default 1f NOTE: - * thinner line == better performance, thicker line == worse performance - */ - public void setLineWidth(float width) { - - if (width < 0.0f) - width = 0.0f; - if (width > 10.0f) - width = 10.0f; - mLineWidth = UtilsKtKt.convertDpToPixel(width); - } - - @Override - public float getLineWidth() { - return mLineWidth; - } - - @Override - public void setDrawFilled(boolean filled) { - mDrawFilled = filled; - } - - @Override - public boolean isDrawFilledEnabled() { - return mDrawFilled; - } - - protected void copy(LineRadarDataSet lineRadarDataSet) { - super.copy((BaseDataSet) lineRadarDataSet); - lineRadarDataSet.mDrawFilled = mDrawFilled; - lineRadarDataSet.mFillAlpha = mFillAlpha; - lineRadarDataSet.mFillColor = mFillColor; - lineRadarDataSet.mFillDrawable = mFillDrawable; - lineRadarDataSet.mLineWidth = mLineWidth; - } -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineRadarDataSet.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineRadarDataSet.kt new file mode 100644 index 0000000000..a1925cd422 --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineRadarDataSet.kt @@ -0,0 +1,81 @@ +package com.github.mikephil.charting.data + +import android.graphics.Color +import android.graphics.drawable.Drawable +import com.github.mikephil.charting.interfaces.datasets.ILineRadarDataSet +import com.github.mikephil.charting.utils.convertDpToPixel + +/** + * Base dataset for line and radar DataSets. + */ +abstract class LineRadarDataSet(yVals: MutableList?, label: String) : LineScatterCandleRadarDataSet(yVals, label), ILineRadarDataSet { + // TODO: Move to using `Fill` class + /** + * the color that is used for filling the line surface + */ + private var mFillColor = Color.rgb(140, 234, 255) + + /** + * Sets the drawable to be used to fill the area below the line. + */ + /** + * the drawable to be used for filling the line surface + */ + override var fillDrawable: Drawable? = null + + /** + * sets the alpha value (transparency) that is used for filling the line + * surface (0-255), default: 85 + */ + /** + * transparency used for filling line surface + */ + override var fillAlpha: Int = 85 + + /** + * the width of the drawn data lines + */ + private var mLineWidth = 2.5f + + /** + * if true, the data will also be drawn filled + */ + override var isDrawFilledEnabled: Boolean = false + + override var fillColor: Int + get() = mFillColor + /** + * Sets the color that is used for filling the area below the line. + * Resets an eventually set "fillDrawable". + */ + set(color) { + mFillColor = color + this.fillDrawable = null + } + + override var lineWidth: Float + get() = mLineWidth + /** + * set the line width of the chart (min = 0.2f, max = 10f); default 1f NOTE: + * thinner line == better performance, thicker line == worse performance + */ + set(width) { + var width = width + if (width < 0.0f) width = 0.0f + if (width > 10.0f) width = 10.0f + mLineWidth = width.convertDpToPixel() + } + + override fun setDrawFilled(enabled: Boolean) { + this.isDrawFilledEnabled = enabled + } + + protected fun copy(lineRadarDataSet: LineRadarDataSet<*>) { + super.copy((lineRadarDataSet as BaseDataSet<*>?)!!) + lineRadarDataSet.isDrawFilledEnabled = this.isDrawFilledEnabled + lineRadarDataSet.fillAlpha = this.fillAlpha + lineRadarDataSet.mFillColor = mFillColor + lineRadarDataSet.fillDrawable = this.fillDrawable + lineRadarDataSet.mLineWidth = mLineWidth + } +} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineScatterCandleRadarDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineScatterCandleRadarDataSet.java deleted file mode 100644 index 71162716f3..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineScatterCandleRadarDataSet.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.github.mikephil.charting.data; - -import android.graphics.DashPathEffect; - -import com.github.mikephil.charting.interfaces.datasets.ILineScatterCandleRadarDataSet; -import com.github.mikephil.charting.utils.UtilsKtKt; - -import java.util.List; - -/** - * Created by Philipp Jahoda on 11/07/15. - */ -public abstract class LineScatterCandleRadarDataSet extends BarLineScatterCandleBubbleDataSet implements ILineScatterCandleRadarDataSet { - - protected boolean mDrawVerticalHighlightIndicator = true; - protected boolean mDrawHorizontalHighlightIndicator = true; - - /** the width of the highlight indicator lines */ - protected float mHighlightLineWidth; - - /** the path effect for dashed highlight-lines */ - protected DashPathEffect mHighlightDashPathEffect = null; - - - public LineScatterCandleRadarDataSet(List yVals, String label) { - super(yVals, label); - mHighlightLineWidth = UtilsKtKt.convertDpToPixel(0.5f); - } - - /** - * Enables / disables the horizontal highlight-indicator. If disabled, the indicator is not drawn. - */ - public void setDrawHorizontalHighlightIndicator(boolean enabled) { - this.mDrawHorizontalHighlightIndicator = enabled; - } - - /** - * Enables / disables the vertical highlight-indicator. If disabled, the indicator is not drawn. - */ - public void setDrawVerticalHighlightIndicator(boolean enabled) { - this.mDrawVerticalHighlightIndicator = enabled; - } - - /** - * Enables / disables both vertical and horizontal highlight-indicators. - */ - public void setDrawHighlightIndicators(boolean enabled) { - setDrawVerticalHighlightIndicator(enabled); - setDrawHorizontalHighlightIndicator(enabled); - } - - @Override - public boolean isVerticalHighlightIndicatorEnabled() { - return mDrawVerticalHighlightIndicator; - } - - @Override - public boolean isHorizontalHighlightIndicatorEnabled() { - return mDrawHorizontalHighlightIndicator; - } - - /** - * Sets the width of the highlight line in dp. - */ - public void setHighlightLineWidth(float width) { - mHighlightLineWidth = UtilsKtKt.convertDpToPixel(width); - } - - @Override - public float getHighlightLineWidth() { - return mHighlightLineWidth; - } - - /** - * Enables the highlight-line to be drawn in dashed mode, e.g. like this "- - - - - -" - * - * @param lineLength the length of the line pieces - * @param spaceLength the length of space inbetween the line-pieces - * @param phase offset, in degrees (normally, use 0) - */ - public void enableDashedHighlightLine(float lineLength, float spaceLength, float phase) { - mHighlightDashPathEffect = new DashPathEffect(new float[] { - lineLength, spaceLength - }, phase); - } - - /** - * Disables the highlight-line to be drawn in dashed mode. - */ - public void disableDashedHighlightLine() { - mHighlightDashPathEffect = null; - } - - /** - * Returns true if the dashed-line effect is enabled for highlight lines, false if not. - * Default: disabled - */ - public boolean isDashedHighlightLineEnabled() { - return mHighlightDashPathEffect == null ? false : true; - } - - @Override - public DashPathEffect getDashPathEffectHighlight() { - return mHighlightDashPathEffect; - } - - protected void copy(LineScatterCandleRadarDataSet lineScatterCandleRadarDataSet) { - super.copy((BaseDataSet) lineScatterCandleRadarDataSet); - lineScatterCandleRadarDataSet.mDrawHorizontalHighlightIndicator = mDrawHorizontalHighlightIndicator; - lineScatterCandleRadarDataSet.mDrawVerticalHighlightIndicator = mDrawVerticalHighlightIndicator; - lineScatterCandleRadarDataSet.mHighlightLineWidth = mHighlightLineWidth; - lineScatterCandleRadarDataSet.mHighlightDashPathEffect = mHighlightDashPathEffect; - } -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineScatterCandleRadarDataSet.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineScatterCandleRadarDataSet.kt new file mode 100644 index 0000000000..d6b48e4b0f --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineScatterCandleRadarDataSet.kt @@ -0,0 +1,93 @@ +package com.github.mikephil.charting.data + +import android.graphics.DashPathEffect +import com.github.mikephil.charting.interfaces.datasets.ILineScatterCandleRadarDataSet +import com.github.mikephil.charting.utils.convertDpToPixel + +abstract class LineScatterCandleRadarDataSet(yVals: MutableList?, label: String) : BarLineScatterCandleBubbleDataSet(yVals, label), + ILineScatterCandleRadarDataSet { + override var isVerticalHighlightIndicatorEnabled: Boolean = true + protected set + override var isHorizontalHighlightIndicatorEnabled: Boolean = true + protected set + + /** the width of the highlight indicator lines */ + protected var mHighlightLineWidth: Float + + /** the path effect for dashed highlight-lines */ + override var dashPathEffectHighlight: DashPathEffect? = null + protected set + + + init { + mHighlightLineWidth = 0.5f.convertDpToPixel() + } + + /** + * Enables / disables the horizontal highlight-indicator. If disabled, the indicator is not drawn. + */ + fun setDrawHorizontalHighlightIndicator(enabled: Boolean) { + this.isHorizontalHighlightIndicatorEnabled = enabled + } + + /** + * Enables / disables the vertical highlight-indicator. If disabled, the indicator is not drawn. + */ + fun setDrawVerticalHighlightIndicator(enabled: Boolean) { + this.isVerticalHighlightIndicatorEnabled = enabled + } + + /** + * Enables / disables both vertical and horizontal highlight-indicators. + */ + fun setDrawHighlightIndicators(enabled: Boolean) { + setDrawVerticalHighlightIndicator(enabled) + setDrawHorizontalHighlightIndicator(enabled) + } + + override var highlightLineWidth: Float + get() = mHighlightLineWidth + /** + * Sets the width of the highlight line in dp. + */ + set(width) { + mHighlightLineWidth = width.convertDpToPixel() + } + + /** + * Enables the highlight-line to be drawn in dashed mode, e.g. like this "- - - - - -" + * + * @param lineLength the length of the line pieces + * @param spaceLength the length of space inbetween the line-pieces + * @param phase offset, in degrees (normally, use 0) + */ + fun enableDashedHighlightLine(lineLength: Float, spaceLength: Float, phase: Float) { + this.dashPathEffectHighlight = DashPathEffect( + floatArrayOf( + lineLength, spaceLength + ), phase + ) + } + + /** + * Disables the highlight-line to be drawn in dashed mode. + */ + fun disableDashedHighlightLine() { + this.dashPathEffectHighlight = null + } + + val isDashedHighlightLineEnabled: Boolean + /** + * Returns true if the dashed-line effect is enabled for highlight lines, false if not. + * Default: disabled + */ + get() = if (this.dashPathEffectHighlight == null) false else true + + protected fun copy(lineScatterCandleRadarDataSet: LineScatterCandleRadarDataSet<*>) { + super.copy((lineScatterCandleRadarDataSet as BaseDataSet<*>?)!!) + lineScatterCandleRadarDataSet.isHorizontalHighlightIndicatorEnabled = this.isHorizontalHighlightIndicatorEnabled + lineScatterCandleRadarDataSet.isVerticalHighlightIndicatorEnabled = this.isVerticalHighlightIndicatorEnabled + lineScatterCandleRadarDataSet.mHighlightLineWidth = mHighlightLineWidth + lineScatterCandleRadarDataSet.dashPathEffectHighlight = this.dashPathEffectHighlight + } +} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/PieDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/PieDataSet.java deleted file mode 100644 index 77c06b607a..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/PieDataSet.java +++ /dev/null @@ -1,252 +0,0 @@ - -package com.github.mikephil.charting.data; - -import androidx.annotation.Nullable; - -import com.github.mikephil.charting.interfaces.datasets.IPieDataSet; -import com.github.mikephil.charting.utils.UtilsKtKt; - -import java.util.ArrayList; -import java.util.List; - -public class PieDataSet extends DataSet implements IPieDataSet { - - /** - * the space in pixels between the chart-slices, default 0f - */ - private float mSliceSpace = 0f; - private boolean mAutomaticallyDisableSliceSpacing; - - /** - * indicates the selection distance of a pie slice - */ - private float mShift = 18f; - - private ValuePosition mXValuePosition = ValuePosition.INSIDE_SLICE; - private ValuePosition mYValuePosition = ValuePosition.INSIDE_SLICE; - private int mValueLineColor = 0xff000000; - private boolean mUseValueColorForLine = false; - private float mValueLineWidth = 1.0f; - private float mValueLinePart1OffsetPercentage = 75.f; - private float mValueLinePart1Length = 0.3f; - private float mValueLinePart2Length = 0.4f; - private boolean mValueLineVariableLength = true; - private Integer mHighlightColor = null; - - public PieDataSet(List yVals, String label) { - super(yVals, label); -// mShift = UtilsKtKt.convertDpToPixel(12f); - } - - @Override - public DataSet copy() { - List entries = new ArrayList<>(); - for (int i = 0; i < mEntries.size(); i++) { - entries.add(mEntries.get(i).copy()); - } - PieDataSet copied = new PieDataSet(entries, getLabel()); - copy(copied); - return copied; - } - - protected void copy(PieDataSet pieDataSet) { - super.copy((BaseDataSet) pieDataSet); - } - - @Override - protected void calcMinMax(PieEntry e) { - - if (e == null) - return; - - calcMinMaxY(e); - } - - /** - * Sets the space that is left out between the piechart-slices in dp. - * Default: 0 --> no space, maximum 20f - */ - public void setSliceSpace(float spaceDp) { - - if (spaceDp > 20) - spaceDp = 20f; - if (spaceDp < 0) - spaceDp = 0f; - - mSliceSpace = UtilsKtKt.convertDpToPixel(spaceDp); - } - - @Override - public float getSliceSpace() { - return mSliceSpace; - } - - /** - * When enabled, slice spacing will be 0.0 when the smallest value is going to be - * smaller than the slice spacing itself. - */ - public void setAutomaticallyDisableSliceSpacing(boolean autoDisable) { - mAutomaticallyDisableSliceSpacing = autoDisable; - } - - /** - * When enabled, slice spacing will be 0.0 when the smallest value is going to be - * smaller than the slice spacing itself. - */ - @Override - public boolean isAutomaticallyDisableSliceSpacingEnabled() { - return mAutomaticallyDisableSliceSpacing; - } - - /** - * sets the distance the highlighted piechart-slice of this DataSet is - * "shifted" away from the center of the chart, default 12f - */ - public void setSelectionShift(float shift) { - mShift = UtilsKtKt.convertDpToPixel(shift); - } - - @Override - public float getSelectionShift() { - return mShift; - } - - @Override - public ValuePosition getXValuePosition() { - return mXValuePosition; - } - - public void setXValuePosition(ValuePosition xValuePosition) { - this.mXValuePosition = xValuePosition; - } - - @Override - public ValuePosition getYValuePosition() { - return mYValuePosition; - } - - public void setYValuePosition(ValuePosition yValuePosition) { - this.mYValuePosition = yValuePosition; - } - - /** - * This method is deprecated. - * Use isUseValueColorForLineEnabled() instead. - */ - @Deprecated - public boolean isUsingSliceColorAsValueLineColor() { - return isUseValueColorForLineEnabled(); - } - - /** - * This method is deprecated. - * Use setUseValueColorForLine(...) instead. - */ - @Deprecated - public void setUsingSliceColorAsValueLineColor(boolean enabled) { - setUseValueColorForLine(enabled); - } - - /** - * When valuePosition is OutsideSlice, indicates line color - */ - @Override - public int getValueLineColor() { - return mValueLineColor; - } - - public void setValueLineColor(int valueLineColor) { - this.mValueLineColor = valueLineColor; - } - - @Override - public boolean isUseValueColorForLineEnabled() - { - return mUseValueColorForLine; - } - - public void setUseValueColorForLine(boolean enabled) - { - mUseValueColorForLine = enabled; - } - - /** - * When valuePosition is OutsideSlice, indicates line width - */ - @Override - public float getValueLineWidth() { - return mValueLineWidth; - } - - public void setValueLineWidth(float valueLineWidth) { - this.mValueLineWidth = valueLineWidth; - } - - /** - * When valuePosition is OutsideSlice, indicates offset as percentage out of the slice size - */ - @Override - public float getValueLinePart1OffsetPercentage() { - return mValueLinePart1OffsetPercentage; - } - - public void setValueLinePart1OffsetPercentage(float valueLinePart1OffsetPercentage) { - this.mValueLinePart1OffsetPercentage = valueLinePart1OffsetPercentage; - } - - /** - * When valuePosition is OutsideSlice, indicates length of first half of the line - */ - @Override - public float getValueLinePart1Length() { - return mValueLinePart1Length; - } - - public void setValueLinePart1Length(float valueLinePart1Length) { - this.mValueLinePart1Length = valueLinePart1Length; - } - - /** - * When valuePosition is OutsideSlice, indicates length of second half of the line - */ - @Override - public float getValueLinePart2Length() { - return mValueLinePart2Length; - } - - public void setValueLinePart2Length(float valueLinePart2Length) { - this.mValueLinePart2Length = valueLinePart2Length; - } - - /** - * When valuePosition is OutsideSlice, this allows variable line length - */ - @Override - public boolean isValueLineVariableLength() { - return mValueLineVariableLength; - } - - public void setValueLineVariableLength(boolean valueLineVariableLength) { - this.mValueLineVariableLength = valueLineVariableLength; - } - - /** Gets the color for the highlighted sector */ - @Override - @Nullable - public Integer getHighlightColor() - { - return mHighlightColor; - } - - /** Sets the color for the highlighted sector (null for using entry color) */ - public void setHighlightColor(@Nullable Integer color) - { - this.mHighlightColor = color; - } - - - public enum ValuePosition { - INSIDE_SLICE, - OUTSIDE_SLICE - } -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/PieDataSet.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/data/PieDataSet.kt new file mode 100644 index 0000000000..2e1b9eb885 --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/PieDataSet.kt @@ -0,0 +1,213 @@ +package com.github.mikephil.charting.data + +import com.github.mikephil.charting.interfaces.datasets.IPieDataSet +import com.github.mikephil.charting.utils.convertDpToPixel + +class PieDataSet(yVals: MutableList?, label: String) : DataSet(yVals, label), IPieDataSet { + /** + * the space in pixels between the chart-slices, default 0f + */ + private var mSliceSpace = 0f + private var mAutomaticallyDisableSliceSpacing = false + + /** + * indicates the selection distance of a pie slice + */ + private var mShift = 18f + + private var mXValuePosition: ValuePosition? = ValuePosition.INSIDE_SLICE + private var mYValuePosition: ValuePosition? = ValuePosition.INSIDE_SLICE + private var mValueLineColor = -0x1000000 + private var mUseValueColorForLine = false + private var mValueLineWidth = 1.0f + private var mValueLinePart1OffsetPercentage = 75f + private var mValueLinePart1Length = 0.3f + private var mValueLinePart2Length = 0.4f + private var mValueLineVariableLength = true + private var mHighlightColor: Int? = null + + override fun copy(): DataSet { + val entries: MutableList = ArrayList() + for (i in mEntries!!.indices) { + entries.add(mEntries!!.get(i)!!.copy()) + } + val copied = PieDataSet(entries, label) + return copied + } + + protected fun copy(pieDataSet: PieDataSet?) { + super.copy((pieDataSet as BaseDataSet<*>?)!!) + } + + override fun calcMinMax(entry: PieEntry?) { + if (entry == null) return + + calcMinMaxY(entry) + } + + /** + * Sets the space that is left out between the piechart-slices in dp. + * Default: 0 --> no space, maximum 20f + */ + fun setSliceSpace(spaceDp: Float) { + var spaceDp = spaceDp + if (spaceDp > 20) spaceDp = 20f + if (spaceDp < 0) spaceDp = 0f + + mSliceSpace = spaceDp.convertDpToPixel() + } + + override fun getSliceSpace(): Float { + return mSliceSpace + } + + /** + * When enabled, slice spacing will be 0.0 when the smallest value is going to be + * smaller than the slice spacing itself. + */ + fun setAutomaticallyDisableSliceSpacing(autoDisable: Boolean) { + mAutomaticallyDisableSliceSpacing = autoDisable + } + + /** + * When enabled, slice spacing will be 0.0 when the smallest value is going to be + * smaller than the slice spacing itself. + */ + override fun isAutomaticallyDisableSliceSpacingEnabled(): Boolean { + return mAutomaticallyDisableSliceSpacing + } + + /** + * sets the distance the highlighted piechart-slice of this DataSet is + * "shifted" away from the center of the chart, default 12f + */ + fun setSelectionShift(shift: Float) { + mShift = shift.convertDpToPixel() + } + + override fun getSelectionShift(): Float { + return mShift + } + + override fun getXValuePosition(): ValuePosition? { + return mXValuePosition + } + + fun setXValuePosition(xValuePosition: ValuePosition?) { + this.mXValuePosition = xValuePosition + } + + override fun getYValuePosition(): ValuePosition? { + return mYValuePosition + } + + fun setYValuePosition(yValuePosition: ValuePosition?) { + this.mYValuePosition = yValuePosition + } + + @get:Deprecated("") + @set:Deprecated("") + var isUsingSliceColorAsValueLineColor: Boolean + /** + * This method is deprecated. + * Use isUseValueColorForLineEnabled() instead. + */ + get() = isUseValueColorForLineEnabled + /** + * This method is deprecated. + * Use setUseValueColorForLine(...) instead. + */ + set(enabled) { + setUseValueColorForLine(enabled) + } + + /** + * When valuePosition is OutsideSlice, indicates line color + */ + override fun getValueLineColor(): Int { + return mValueLineColor + } + + fun setValueLineColor(valueLineColor: Int) { + this.mValueLineColor = valueLineColor + } + + override fun isUseValueColorForLineEnabled(): Boolean { + return mUseValueColorForLine + } + + fun setUseValueColorForLine(enabled: Boolean) { + mUseValueColorForLine = enabled + } + + /** + * When valuePosition is OutsideSlice, indicates line width + */ + override fun getValueLineWidth(): Float { + return mValueLineWidth + } + + fun setValueLineWidth(valueLineWidth: Float) { + this.mValueLineWidth = valueLineWidth + } + + /** + * When valuePosition is OutsideSlice, indicates offset as percentage out of the slice size + */ + override fun getValueLinePart1OffsetPercentage(): Float { + return mValueLinePart1OffsetPercentage + } + + fun setValueLinePart1OffsetPercentage(valueLinePart1OffsetPercentage: Float) { + this.mValueLinePart1OffsetPercentage = valueLinePart1OffsetPercentage + } + + /** + * When valuePosition is OutsideSlice, indicates length of first half of the line + */ + override fun getValueLinePart1Length(): Float { + return mValueLinePart1Length + } + + fun setValueLinePart1Length(valueLinePart1Length: Float) { + this.mValueLinePart1Length = valueLinePart1Length + } + + /** + * When valuePosition is OutsideSlice, indicates length of second half of the line + */ + override fun getValueLinePart2Length(): Float { + return mValueLinePart2Length + } + + fun setValueLinePart2Length(valueLinePart2Length: Float) { + this.mValueLinePart2Length = valueLinePart2Length + } + + /** + * When valuePosition is OutsideSlice, this allows variable line length + */ + override fun isValueLineVariableLength(): Boolean { + return mValueLineVariableLength + } + + fun setValueLineVariableLength(valueLineVariableLength: Boolean) { + this.mValueLineVariableLength = valueLineVariableLength + } + + /** Gets the color for the highlighted sector */ + override fun getHighlightColor(): Int? { + return mHighlightColor + } + + /** Sets the color for the highlighted sector (null for using entry color) */ + fun setHighlightColor(color: Int?) { + this.mHighlightColor = color + } + + + enum class ValuePosition { + INSIDE_SLICE, + OUTSIDE_SLICE + } +} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/RadarDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/RadarDataSet.java deleted file mode 100644 index a01604b8c3..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/RadarDataSet.java +++ /dev/null @@ -1,122 +0,0 @@ - -package com.github.mikephil.charting.data; - -import android.graphics.Color; - -import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet; -import com.github.mikephil.charting.utils.ColorTemplate; - -import java.util.ArrayList; -import java.util.List; - -public class RadarDataSet extends LineRadarDataSet implements IRadarDataSet { - - /// flag indicating whether highlight circle should be drawn or not - protected boolean mDrawHighlightCircleEnabled = false; - - protected int mHighlightCircleFillColor = Color.WHITE; - - /// The stroke color for highlight circle. - /// If Utils.COLOR_NONE, the color of the dataset is taken. - protected int mHighlightCircleStrokeColor = ColorTemplate.COLOR_NONE; - - protected int mHighlightCircleStrokeAlpha = (int) (0.3 * 255); - protected float mHighlightCircleInnerRadius = 3.0f; - protected float mHighlightCircleOuterRadius = 4.0f; - protected float mHighlightCircleStrokeWidth = 2.0f; - - public RadarDataSet(List yVals, String label) { - super(yVals, label); - } - - /// Returns true if highlight circle should be drawn, false if not - @Override - public boolean isDrawHighlightCircleEnabled() { - return mDrawHighlightCircleEnabled; - } - - /// Sets whether highlight circle should be drawn or not - @Override - public void setDrawHighlightCircleEnabled(boolean enabled) { - mDrawHighlightCircleEnabled = enabled; - } - - @Override - public int getHighlightCircleFillColor() { - return mHighlightCircleFillColor; - } - - public void setHighlightCircleFillColor(int color) { - mHighlightCircleFillColor = color; - } - - /// Returns the stroke color for highlight circle. - /// If Utils.COLOR_NONE, the color of the dataset is taken. - @Override - public int getHighlightCircleStrokeColor() { - return mHighlightCircleStrokeColor; - } - - /// Sets the stroke color for highlight circle. - /// Set to Utils.COLOR_NONE in order to use the color of the dataset; - public void setHighlightCircleStrokeColor(int color) { - mHighlightCircleStrokeColor = color; - } - - @Override - public int getHighlightCircleStrokeAlpha() { - return mHighlightCircleStrokeAlpha; - } - - public void setHighlightCircleStrokeAlpha(int alpha) { - mHighlightCircleStrokeAlpha = alpha; - } - - @Override - public float getHighlightCircleInnerRadius() { - return mHighlightCircleInnerRadius; - } - - public void setHighlightCircleInnerRadius(float radius) { - mHighlightCircleInnerRadius = radius; - } - - @Override - public float getHighlightCircleOuterRadius() { - return mHighlightCircleOuterRadius; - } - - public void setHighlightCircleOuterRadius(float radius) { - mHighlightCircleOuterRadius = radius; - } - - @Override - public float getHighlightCircleStrokeWidth() { - return mHighlightCircleStrokeWidth; - } - - public void setHighlightCircleStrokeWidth(float strokeWidth) { - mHighlightCircleStrokeWidth = strokeWidth; - } - - @Override - public DataSet copy() { - List entries = new ArrayList(); - for (int i = 0; i < mEntries.size(); i++) { - entries.add(mEntries.get(i).copy()); - } - RadarDataSet copied = new RadarDataSet(entries, getLabel()); - copy(copied); - return copied; - } - - protected void copy(RadarDataSet radarDataSet) { - super.copy((BaseDataSet) radarDataSet); - radarDataSet.mDrawHighlightCircleEnabled = mDrawHighlightCircleEnabled; - radarDataSet.mHighlightCircleFillColor = mHighlightCircleFillColor; - radarDataSet.mHighlightCircleInnerRadius = mHighlightCircleInnerRadius; - radarDataSet.mHighlightCircleStrokeAlpha = mHighlightCircleStrokeAlpha; - radarDataSet.mHighlightCircleStrokeColor = mHighlightCircleStrokeColor; - radarDataSet.mHighlightCircleStrokeWidth = mHighlightCircleStrokeWidth; - } -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/RadarDataSet.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/data/RadarDataSet.kt new file mode 100644 index 0000000000..a02b547176 --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/RadarDataSet.kt @@ -0,0 +1,77 @@ +package com.github.mikephil.charting.data + +import android.graphics.Color +import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet +import com.github.mikephil.charting.utils.ColorTemplate + +open class RadarDataSet(yVals: MutableList?, label: String = "") : LineRadarDataSet(yVals, label), IRadarDataSet { + /** flag indicating whether highlight circle should be drawn or not */ + protected var mDrawHighlightCircleEnabled: Boolean = false + + protected var mHighlightCircleFillColor: Int = Color.WHITE + + /** The stroke color for highlight circle. + * If Utils.COLOR_NONE, the color of the dataset is taken. */ + protected var mHighlightCircleStrokeColor: Int = ColorTemplate.COLOR_NONE + + protected var mHighlightCircleStrokeAlpha: Int = (0.3 * 255).toInt() + protected var mHighlightCircleInnerRadius: Float = 3.0f + protected var mHighlightCircleOuterRadius: Float = 4.0f + protected var mHighlightCircleStrokeWidth: Float = 2.0f + + /** Returns true if highlight circle should be drawn, false if not */ + override fun isDrawHighlightCircleEnabled(): Boolean { + return mDrawHighlightCircleEnabled + } + + /** Sets whether highlight circle should be drawn or not */ + override fun setDrawHighlightCircleEnabled(enabled: Boolean) { + mDrawHighlightCircleEnabled = enabled + } + + override fun getHighlightCircleFillColor(): Int { + return mHighlightCircleFillColor + } + + /** Returns the stroke color for highlight circle. + * If Utils.COLOR_NONE, the color of the dataset is taken. */ + override fun getHighlightCircleStrokeColor(): Int { + return mHighlightCircleStrokeColor + } + + override fun getHighlightCircleStrokeAlpha(): Int { + return mHighlightCircleStrokeAlpha + } + + override fun getHighlightCircleInnerRadius(): Float { + return mHighlightCircleInnerRadius + } + + override fun getHighlightCircleOuterRadius(): Float { + return mHighlightCircleOuterRadius + } + + override fun getHighlightCircleStrokeWidth(): Float { + return mHighlightCircleStrokeWidth + } + + override fun copy(): DataSet { + val entries: MutableList = ArrayList() + for (i in mEntries!!.indices) { + entries.add(mEntries!![i]!!.copy()) + } + val copied = RadarDataSet(entries, label) + copy(copied) + return copied + } + + protected fun copy(radarDataSet: RadarDataSet) { + super.copy((radarDataSet as BaseDataSet<*>?)!!) + radarDataSet.mDrawHighlightCircleEnabled = mDrawHighlightCircleEnabled + radarDataSet.mHighlightCircleFillColor = mHighlightCircleFillColor + radarDataSet.mHighlightCircleInnerRadius = mHighlightCircleInnerRadius + radarDataSet.mHighlightCircleStrokeAlpha = mHighlightCircleStrokeAlpha + radarDataSet.mHighlightCircleStrokeColor = mHighlightCircleStrokeColor + radarDataSet.mHighlightCircleStrokeWidth = mHighlightCircleStrokeWidth + } +} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/ScatterDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/ScatterDataSet.java deleted file mode 100644 index da7ec1d3c2..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/ScatterDataSet.java +++ /dev/null @@ -1,147 +0,0 @@ - -package com.github.mikephil.charting.data; - -import com.github.mikephil.charting.charts.ScatterChart; -import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet; -import com.github.mikephil.charting.renderer.scatter.ChevronDownShapeRenderer; -import com.github.mikephil.charting.renderer.scatter.ChevronUpShapeRenderer; -import com.github.mikephil.charting.renderer.scatter.CircleShapeRenderer; -import com.github.mikephil.charting.renderer.scatter.CrossShapeRenderer; -import com.github.mikephil.charting.renderer.scatter.IShapeRenderer; -import com.github.mikephil.charting.renderer.scatter.SquareShapeRenderer; -import com.github.mikephil.charting.renderer.scatter.TriangleShapeRenderer; -import com.github.mikephil.charting.renderer.scatter.XShapeRenderer; -import com.github.mikephil.charting.utils.ColorTemplate; - -import java.util.ArrayList; -import java.util.List; - -public class ScatterDataSet extends LineScatterCandleRadarDataSet implements IScatterDataSet { - - /** - * the size the scattershape will have, in density pixels - */ - private float mShapeSize = 15f; - - /** - * Renderer responsible for rendering this DataSet, default: square - */ - protected IShapeRenderer mShapeRenderer = new SquareShapeRenderer(); - - /** - * The radius of the hole in the shape (applies to Square, Circle and Triangle) - * - default: 0.0 - */ - private float mScatterShapeHoleRadius = 0f; - - /** - * Color for the hole in the shape. - * Setting to `ColorTemplate.COLOR_NONE` will behave as transparent. - * - default: ColorTemplate.COLOR_NONE - */ - private int mScatterShapeHoleColor = ColorTemplate.COLOR_NONE; - - public ScatterDataSet(List yVals, String label) { - super(yVals, label); - } - - @Override - public DataSet copy() { - List entries = new ArrayList<>(); - for (int i = 0; i < mEntries.size(); i++) { - entries.add(mEntries.get(i).copy()); - } - ScatterDataSet copied = new ScatterDataSet(entries, getLabel()); - copy(copied); - return copied; - } - - protected void copy(ScatterDataSet scatterDataSet) { - super.copy((BaseDataSet) scatterDataSet); - scatterDataSet.mShapeSize = mShapeSize; - scatterDataSet.mShapeRenderer = mShapeRenderer; - scatterDataSet.mScatterShapeHoleRadius = mScatterShapeHoleRadius; - scatterDataSet.mScatterShapeHoleColor = mScatterShapeHoleColor; - } - - /** - * Sets the size in density pixels the drawn scattershape will have. This - * only applies for non custom shapes. - */ - public void setScatterShapeSize(float size) { - mShapeSize = size; - } - - @Override - public float getScatterShapeSize() { - return mShapeSize; - } - - /** - * Sets the ScatterShape this DataSet should be drawn with. This will search for an available IShapeRenderer and set this - * renderer for the DataSet. - */ - public void setScatterShape(ScatterChart.ScatterShape shape) { - mShapeRenderer = getRendererForShape(shape); - } - - /** - * Sets a new IShapeRenderer responsible for drawing this DataSet. - * This can also be used to set a custom IShapeRenderer aside from the default ones. - */ - public void setShapeRenderer(IShapeRenderer shapeRenderer) { - mShapeRenderer = shapeRenderer; - } - - @Override - public IShapeRenderer getShapeRenderer() { - return mShapeRenderer; - } - - /** - * Sets the radius of the hole in the shape (applies to Square, Circle and Triangle) - * Set this to <= 0 to remove holes. - */ - public void setScatterShapeHoleRadius(float holeRadius) { - mScatterShapeHoleRadius = holeRadius; - } - - @Override - public float getScatterShapeHoleRadius() { - return mScatterShapeHoleRadius; - } - - /** - * Sets the color for the hole in the shape. - */ - public void setScatterShapeHoleColor(int holeColor) { - mScatterShapeHoleColor = holeColor; - } - - @Override - public int getScatterShapeHoleColor() { - return mScatterShapeHoleColor; - } - - public static IShapeRenderer getRendererForShape(ScatterChart.ScatterShape shape) { - - switch (shape) { - case SQUARE: - return new SquareShapeRenderer(); - case CIRCLE: - return new CircleShapeRenderer(); - case TRIANGLE: - return new TriangleShapeRenderer(); - case CROSS: - return new CrossShapeRenderer(); - case X: - return new XShapeRenderer(); - case CHEVRON_UP: - return new ChevronUpShapeRenderer(); - case CHEVRON_DOWN: - return new ChevronDownShapeRenderer(); - } - - return null; - } -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/ScatterDataSet.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/data/ScatterDataSet.kt new file mode 100644 index 0000000000..ebd112c09c --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/ScatterDataSet.kt @@ -0,0 +1,125 @@ +package com.github.mikephil.charting.data + +import com.github.mikephil.charting.charts.ScatterChart.ScatterShape +import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet +import com.github.mikephil.charting.renderer.scatter.ChevronDownShapeRenderer +import com.github.mikephil.charting.renderer.scatter.ChevronUpShapeRenderer +import com.github.mikephil.charting.renderer.scatter.CircleShapeRenderer +import com.github.mikephil.charting.renderer.scatter.CrossShapeRenderer +import com.github.mikephil.charting.renderer.scatter.IShapeRenderer +import com.github.mikephil.charting.renderer.scatter.SquareShapeRenderer +import com.github.mikephil.charting.renderer.scatter.TriangleShapeRenderer +import com.github.mikephil.charting.renderer.scatter.XShapeRenderer +import com.github.mikephil.charting.utils.ColorTemplate + +open class ScatterDataSet(yVals: MutableList?, label: String = "") : LineScatterCandleRadarDataSet(yVals, label), IScatterDataSet { + /** + * the size the scattershape will have, in density pixels + */ + private var shapeSize = 15f + + /** + * Renderer responsible for rendering this DataSet, default: square + */ + protected var mShapeRenderer: IShapeRenderer? = SquareShapeRenderer() + + /** + * The radius of the hole in the shape (applies to Square, Circle and Triangle) + * - default: 0.0 + */ + private var mScatterShapeHoleRadius = 0f + + /** + * Color for the hole in the shape. + * Setting to `ColorTemplate.COLOR_NONE` will behave as transparent. + * - default: ColorTemplate.COLOR_NONE + */ + private var mScatterShapeHoleColor = ColorTemplate.COLOR_NONE + + override fun copy(): DataSet { + val entries: MutableList = ArrayList() + for (i in mEntries!!.indices) { + entries.add(mEntries!![i]!!.copy()) + } + val copied = ScatterDataSet(entries, label) + copy(copied) + return copied + } + + protected fun copy(scatterDataSet: ScatterDataSet) { + super.copy((scatterDataSet as BaseDataSet<*>?)!!) + scatterDataSet.shapeSize = shapeSize + scatterDataSet.mShapeRenderer = mShapeRenderer + scatterDataSet.mScatterShapeHoleRadius = mScatterShapeHoleRadius + scatterDataSet.mScatterShapeHoleColor = mScatterShapeHoleColor + } + + /** + * Sets the size in density pixels the drawn scattershape will have. This + * only applies for non custom shapes. + */ + fun setScatterShapeSize(size: Float) { + shapeSize = size + } + + override fun getScatterShapeSize(): Float { + return shapeSize + } + + /** + * Sets the ScatterShape this DataSet should be drawn with. This will search for an available IShapeRenderer and set this + * renderer for the DataSet. + */ + fun setScatterShape(shape: ScatterShape) { + mShapeRenderer = getRendererForShape(shape) + } + + /** + * Sets a new IShapeRenderer responsible for drawing this DataSet. + * This can also be used to set a custom IShapeRenderer aside from the default ones. + */ + fun setShapeRenderer(shape: IShapeRenderer?) { + mShapeRenderer = shape + } + + override fun getShapeRenderer(): IShapeRenderer? { + return mShapeRenderer + } + + /** + * Sets the radius of the hole in the shape (applies to Square, Circle and Triangle) + * Set this to <= 0 to remove holes. + */ + fun setScatterShapeHoleRadius(holeRadius: Float) { + mScatterShapeHoleRadius = holeRadius + } + + override fun getScatterShapeHoleRadius(): Float { + return mScatterShapeHoleRadius + } + + /** + * Sets the color for the hole in the shape. + */ + fun setScatterShapeHoleColor(holeColor: Int) { + mScatterShapeHoleColor = holeColor + } + + override fun getScatterShapeHoleColor(): Int { + return mScatterShapeHoleColor + } + + companion object { + fun getRendererForShape(shape: ScatterShape): IShapeRenderer? { + return when (shape) { + ScatterShape.SQUARE -> SquareShapeRenderer() + ScatterShape.CIRCLE -> CircleShapeRenderer() + ScatterShape.TRIANGLE -> TriangleShapeRenderer() + ScatterShape.CROSS -> CrossShapeRenderer() + ScatterShape.X -> XShapeRenderer() + ScatterShape.CHEVRON_UP -> ChevronUpShapeRenderer() + ScatterShape.CHEVRON_DOWN -> ChevronDownShapeRenderer() + } + } + } +} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/ILineRadarDataSet.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/ILineRadarDataSet.kt index 50b153e3f6..a7703baf14 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/ILineRadarDataSet.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/ILineRadarDataSet.kt @@ -3,7 +3,7 @@ package com.github.mikephil.charting.interfaces.datasets import android.graphics.drawable.Drawable import com.github.mikephil.charting.data.Entry -interface ILineRadarDataSet : ILineScatterCandleRadarDataSet { +interface ILineRadarDataSet : ILineScatterCandleRadarDataSet { /** * Returns the color that is used for filling the line surface area. */ diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/ILineScatterCandleRadarDataSet.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/ILineScatterCandleRadarDataSet.kt index 3c847bf42e..5fe6a17c8f 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/ILineScatterCandleRadarDataSet.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/ILineScatterCandleRadarDataSet.kt @@ -3,7 +3,7 @@ package com.github.mikephil.charting.interfaces.datasets import android.graphics.DashPathEffect import com.github.mikephil.charting.data.Entry -interface ILineScatterCandleRadarDataSet : IBarLineScatterCandleBubbleDataSet { +interface ILineScatterCandleRadarDataSet : IBarLineScatterCandleBubbleDataSet { /** * Returns true if vertical highlight indicator lines are enabled (drawn) */ diff --git a/app/src/main/kotlin/info/appdev/chartexample/CombinedChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/CombinedChartActivity.kt index 70cf25de2e..a1f01c375a 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/CombinedChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/CombinedChartActivity.kt @@ -105,10 +105,10 @@ class CombinedChartActivity : DemoBase() { val set = LineDataSet(entries, "Line DataSet") set.color = Color.rgb(240, 238, 70) - set.setLineWidth(2.5f) + set.lineWidth = 2.5f set.setCircleColor(Color.rgb(240, 238, 70)) set.circleRadius = 5f - set.setFillColor(Color.rgb(240, 238, 70)) + set.fillColor = Color.rgb(240, 238, 70) set.lineMode = LineDataSet.Mode.CUBIC_BEZIER set.isDrawValues = true set.valueTextSize = 10f diff --git a/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt index 4fb5484adc..83f75f67d6 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt @@ -115,13 +115,13 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener { set1.cubicIntensity = 0.2f set1.setDrawFilled(true) set1.setDrawCircles(false) - set1.setLineWidth(1.8f) + set1.lineWidth= 1.8f set1.circleRadius = 4f set1.setCircleColor(Color.WHITE) set1.highLightColor = Color.rgb(244, 117, 117) set1.color = Color.WHITE - set1.setFillColor(Color.WHITE) - set1.setFillAlpha(100) + set1.fillColor = Color.WHITE + set1.fillAlpha = 100 set1.setDrawHorizontalHighlightIndicator(false) set1.fillFormatter = object : IFillFormatter { override fun getFillLinePosition(dataSet: ILineDataSet?, dataProvider: LineDataProvider?): Float { diff --git a/app/src/main/kotlin/info/appdev/chartexample/DataTools.kt b/app/src/main/kotlin/info/appdev/chartexample/DataTools.kt index 31a1b99510..b2c14974d1 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/DataTools.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/DataTools.kt @@ -186,7 +186,7 @@ class DataTools { lineDataSet01.setCircleColor(Color.BLACK) // line thickness and point size - lineDataSet01.setLineWidth(1f) + lineDataSet01.lineWidth = 1f lineDataSet01.circleRadius = 3f // draw points as solid circles @@ -215,9 +215,9 @@ class DataTools { if (getSDKInt() >= 18) { // drawables only supported on api level 18 and above val drawable = ContextCompat.getDrawable(context, R.drawable.fade_blue) - lineDataSet01.setFillDrawable(drawable) + lineDataSet01.fillDrawable = drawable } else { - lineDataSet01.setFillColor(Color.BLACK) + lineDataSet01.fillColor = Color.BLACK } val dataSets = ArrayList() dataSets.add(lineDataSet01) // add the data sets diff --git a/app/src/main/kotlin/info/appdev/chartexample/DrawChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/DrawChartActivity.kt index f9d78e241e..f34dab97e5 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/DrawChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/DrawChartActivity.kt @@ -62,7 +62,7 @@ class DrawChartActivity : DemoBase(), OnChartValueSelectedListener, OnDrawListen // create a dataset and give it a type (0) val set1 = LineDataSet(values, "DataSet") - set1.setLineWidth(3f) + set1.lineWidth = 3f set1.circleRadius = 5f // create a data object with the data sets diff --git a/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt index e7125fe7f7..907b87557f 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt @@ -115,7 +115,7 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener { } val set = LineDataSet(values, "DataSet $count") - set.setLineWidth(2.5f) + set.lineWidth = 2.5f set.circleRadius = 4.5f val color = colors[count % colors.size] @@ -146,7 +146,7 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener { private fun createSet(): LineDataSet { val set = LineDataSet(null, "DataSet 1") - set.setLineWidth(2.5f) + set.lineWidth = 2.5f set.circleRadius = 4.5f set.color = Color.rgb(240, 99, 99) set.setCircleColor(Color.rgb(240, 99, 99)) diff --git a/app/src/main/kotlin/info/appdev/chartexample/FilledLineActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/FilledLineActivity.kt index e72209e327..153022b207 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/FilledLineActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/FilledLineActivity.kt @@ -103,11 +103,11 @@ class FilledLineActivity : DemoBase() { set1.axisDependency = YAxis.AxisDependency.LEFT set1.color = Color.rgb(255, 241, 46) set1.setDrawCircles(false) - set1.setLineWidth(2f) + set1.lineWidth = 2f set1.circleRadius = 3f - set1.setFillAlpha(255) + set1.fillAlpha = 255 set1.setDrawFilled(true) - set1.setFillColor(Color.WHITE) + set1.fillColor = Color.WHITE set1.highLightColor = Color.rgb(244, 117, 117) set1.setDrawCircleHole(false) set1.fillFormatter = object : IFillFormatter { @@ -123,11 +123,11 @@ class FilledLineActivity : DemoBase() { set2.axisDependency = YAxis.AxisDependency.LEFT set2.color = Color.rgb(255, 241, 46) set2.setDrawCircles(false) - set2.setLineWidth(2f) + set2.lineWidth = 2f set2.circleRadius = 3f - set2.setFillAlpha(255) + set2.fillAlpha = 255 set2.setDrawFilled(true) - set2.setFillColor(Color.WHITE) + set2.fillColor = Color.WHITE set2.setDrawCircleHole(false) set2.highLightColor = Color.rgb(244, 117, 117) set2.fillFormatter = object : IFillFormatter { diff --git a/app/src/main/kotlin/info/appdev/chartexample/InvertedLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/InvertedLineChartActivity.kt index 8c3a5e8f7e..744543c8a1 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/InvertedLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/InvertedLineChartActivity.kt @@ -118,7 +118,7 @@ class InvertedLineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa // create a dataset and give it a type val set1 = LineDataSet(entries, "DataSet 1") - set1.setLineWidth(1.5f) + set1.lineWidth = 1.5f set1.circleRadius = 4f // create a data object with the data sets diff --git a/app/src/main/kotlin/info/appdev/chartexample/LineChartActivityColored.kt b/app/src/main/kotlin/info/appdev/chartexample/LineChartActivityColored.kt index 491a3078ff..cd9f5a0106 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/LineChartActivityColored.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/LineChartActivityColored.kt @@ -105,7 +105,7 @@ class LineChartActivityColored : DemoBase() { // set1.setFillAlpha(110); // set1.setFillColor(Color.RED); - set1.setLineWidth(1.75f) + set1.lineWidth = 1.75f set1.circleRadius = 5f set1.circleHoleRadius = 2.5f set1.color = Color.WHITE diff --git a/app/src/main/kotlin/info/appdev/chartexample/LineChartDualAxisActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/LineChartDualAxisActivity.kt index a2e8d8d1ec..d9d697bace 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/LineChartDualAxisActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/LineChartDualAxisActivity.kt @@ -165,10 +165,10 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa set1.axisDependency = AxisDependency.LEFT set1.color = ColorTemplate.getHoloBlue() set1.setCircleColor(Color.WHITE) - set1.setLineWidth(2f) + set1.lineWidth = 2f set1.circleRadius = 3f - set1.setFillAlpha(65) - set1.setFillColor(ColorTemplate.getHoloBlue()) + set1.fillAlpha = 65 + set1.fillColor = ColorTemplate.getHoloBlue() set1.highLightColor = Color.rgb(244, 117, 117) set1.setDrawCircleHole(false) @@ -182,10 +182,10 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa set2.axisDependency = AxisDependency.RIGHT set2.color = Color.MAGENTA set2.setCircleColor(Color.WHITE) - set2.setLineWidth(2f) + set2.lineWidth = 2f set2.circleRadius = 3f - set2.setFillAlpha(65) - set2.setFillColor(Color.BLUE) + set2.fillAlpha = 65 + set2.fillColor = Color.BLUE set2.setDrawCircleHole(false) set2.highLightColor = Color.rgb(244, 117, 117) @@ -194,10 +194,10 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa set3.axisDependency = AxisDependency.RIGHT set3.color = Color.YELLOW set3.setCircleColor(Color.WHITE) - set3.setLineWidth(2f) + set3.lineWidth = 2f set3.circleRadius = 3f - set3.setFillAlpha(65) - set3.setFillColor(ColorTemplate.colorWithAlpha(Color.YELLOW, 200)) + set3.fillAlpha = 65 + set3.fillColor = ColorTemplate.colorWithAlpha(Color.YELLOW, 200) set3.setDrawCircleHole(false) set3.highLightColor = Color.rgb(244, 117, 117) diff --git a/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt index 1adff9746b..50f6c4402d 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt @@ -132,11 +132,11 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener { set1.axisDependency = AxisDependency.LEFT set1.color = ColorTemplate.getHoloBlue() set1.setSingleValueTextColor(ColorTemplate.getHoloBlue()) - set1.setLineWidth(1.5f) + set1.lineWidth = 1.5f set1.setDrawCircles(false) set1.isDrawValues = false - set1.setFillAlpha(65) - set1.setFillColor(ColorTemplate.getHoloBlue()) + set1.fillAlpha = 65 + set1.fillColor = ColorTemplate.getHoloBlue() set1.highLightColor = Color.rgb(244, 117, 117) set1.setDrawCircleHole(false) diff --git a/app/src/main/kotlin/info/appdev/chartexample/ListViewMultiChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/ListViewMultiChartActivity.kt index d0bf6e3534..5733c6c9c6 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/ListViewMultiChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/ListViewMultiChartActivity.kt @@ -89,7 +89,7 @@ class ListViewMultiChartActivity : DemoBase() { } val d1 = LineDataSet(values1, "New DataSet $cnt, (1)") - d1.setLineWidth(2.5f) + d1.lineWidth = 2.5f d1.circleRadius = 4.5f d1.highLightColor = Color.rgb(244, 117, 117) d1.isDrawValues = false @@ -101,7 +101,7 @@ class ListViewMultiChartActivity : DemoBase() { } val d2 = LineDataSet(values2, "New DataSet $cnt, (2)") - d2.setLineWidth(2.5f) + d2.lineWidth = 2.5f d2.circleRadius = 4.5f d2.highLightColor = Color.rgb(244, 117, 117) d2.color = ColorTemplate.VORDIPLOM_COLORS[0] diff --git a/app/src/main/kotlin/info/appdev/chartexample/MultiLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/MultiLineChartActivity.kt index 60c6dcf187..973541cc43 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/MultiLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/MultiLineChartActivity.kt @@ -96,7 +96,7 @@ class MultiLineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartGestu } val lineDataSet = LineDataSet(values, "DataSet " + (datasetNumber + 1)) - lineDataSet.setLineWidth(2.5f) + lineDataSet.lineWidth = 2.5f lineDataSet.circleRadius = 4f val color = colors[datasetNumber % colors.size] diff --git a/app/src/main/kotlin/info/appdev/chartexample/PerformanceLineChart.kt b/app/src/main/kotlin/info/appdev/chartexample/PerformanceLineChart.kt index 9e25a88043..9912d30bc2 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/PerformanceLineChart.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/PerformanceLineChart.kt @@ -69,7 +69,7 @@ class PerformanceLineChart : DemoBase(), OnSeekBarChangeListener { val set1 = LineDataSet(values, "DataSet 1") set1.color = Color.BLACK - set1.setLineWidth(0.5f) + set1.lineWidth = 0.5f set1.isDrawValues = false set1.setDrawCircles(false) set1.lineMode = LineDataSet.Mode.LINEAR diff --git a/app/src/main/kotlin/info/appdev/chartexample/RadarChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/RadarChartActivity.kt index a5f5d25e6b..cef6094c83 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/RadarChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/RadarChartActivity.kt @@ -105,19 +105,19 @@ class RadarChartActivity : DemoBase() { val set1 = RadarDataSet(entries1, "Last Week") set1.color = Color.rgb(103, 110, 129) - set1.setFillColor(Color.rgb(103, 110, 129)) + set1.fillColor = Color.rgb(103, 110, 129) set1.setDrawFilled(true) - set1.setFillAlpha(180) - set1.setLineWidth(2f) + set1.fillAlpha = 180 + set1.lineWidth = 2f set1.isDrawHighlightCircleEnabled = true set1.setDrawHighlightIndicators(false) val set2 = RadarDataSet(entries2, "This Week") set2.color = Color.rgb(121, 162, 175) - set2.setFillColor(Color.rgb(121, 162, 175)) + set2.fillColor = Color.rgb(121, 162, 175) set2.setDrawFilled(true) - set2.setFillAlpha(180) - set2.setLineWidth(2f) + set2.fillAlpha = 180 + set2.lineWidth = 2f set2.isDrawHighlightCircleEnabled = true set2.setDrawHighlightIndicators(false) diff --git a/app/src/main/kotlin/info/appdev/chartexample/RealtimeLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/RealtimeLineChartActivity.kt index f46d14f871..95ac35894f 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/RealtimeLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/RealtimeLineChartActivity.kt @@ -121,10 +121,10 @@ class RealtimeLineChartActivity : DemoBase(), OnChartValueSelectedListener { set.axisDependency = AxisDependency.LEFT set.color = ColorTemplate.getHoloBlue() set.setCircleColor(Color.WHITE) - set.setLineWidth(2f) + set.lineWidth = 2f set.circleRadius = 4f - set.setFillAlpha(65) - set.setFillColor(ColorTemplate.getHoloBlue()) + set.fillAlpha = 65 + set.fillColor = ColorTemplate.getHoloBlue() set.highLightColor = Color.rgb(244, 117, 117) set.setSingleValueTextColor(Color.WHITE) set.valueTextSize = 9f diff --git a/app/src/main/kotlin/info/appdev/chartexample/SpecificPositionsLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/SpecificPositionsLineChartActivity.kt index 63cb625014..7970619c8c 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/SpecificPositionsLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/SpecificPositionsLineChartActivity.kt @@ -264,7 +264,7 @@ class SpecificPositionsLineChartActivity : DemoBase(), OnSeekBarChangeListener, set11.enableDashedHighlightLine(10f, 5f, 0f) set11.color = Color.BLACK set11.setCircleColor(Color.BLACK) - set11.setLineWidth(1f) + set11.lineWidth = 1f set11.circleRadius = 3f set11.setDrawCircleHole(false) set11.valueTextSize = 9f @@ -275,9 +275,9 @@ class SpecificPositionsLineChartActivity : DemoBase(), OnSeekBarChangeListener, if (getSDKInt() >= 18) { // fill drawable only supported on api level 18 and above val drawable = ContextCompat.getDrawable(this, R.drawable.fade_blue) - set11.setFillDrawable(drawable) + set11.fillDrawable = drawable } else { - set11.setFillColor(Color.BLACK) + set11.fillColor = Color.BLACK } val dataSets = ArrayList() dataSets.add(set11) // add the datasets diff --git a/app/src/main/kotlin/info/appdev/chartexample/fragments/SimpleFragment.kt b/app/src/main/kotlin/info/appdev/chartexample/fragments/SimpleFragment.kt index 740880e69f..74f0e03e73 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/fragments/SimpleFragment.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/fragments/SimpleFragment.kt @@ -113,8 +113,8 @@ abstract class SimpleFragment : Fragment() { val ds1 = LineDataSet(FileUtils.loadEntriesFromAssets(requireContext().assets, "sine.txt"), "Sine function") val ds2 = LineDataSet(FileUtils.loadEntriesFromAssets(requireContext().assets, "cosine.txt"), "Cosine function") - ds1.setLineWidth(2f) - ds2.setLineWidth(2f) + ds1.lineWidth = 2f + ds2.lineWidth = 2f ds1.setDrawCircles(false) ds2.setDrawCircles(false) @@ -154,13 +154,13 @@ abstract class SimpleFragment : Fragment() { ds3.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[2]) ds4.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[3]) - ds1.setLineWidth(2.5f) + ds1.lineWidth = 2.5f ds1.circleRadius = 3f - ds2.setLineWidth(2.5f) + ds2.lineWidth = 2.5f ds2.circleRadius = 3f - ds3.setLineWidth(2.5f) + ds3.lineWidth = 2.5f ds3.circleRadius = 3f - ds4.setLineWidth(2.5f) + ds4.lineWidth = 2.5f ds4.circleRadius = 3f