diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/PieChart.java b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/PieChart.java index d240b446e5..2e46418280 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/PieChart.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/PieChart.java @@ -782,7 +782,7 @@ public String getAccessibilityDescription() { PieEntry entry = pieData.getDataSet().getEntryForIndex(i); float percentage = (entry.getValue() / pieData.getYValueSum()) * 100; builder.append(String.format(Locale.getDefault(), "%s has %.2f percent pie taken", - (TextUtils.isEmpty(entry.getLabel()) ? "No Label" : entry.getLabel()), + (TextUtils.isEmpty(entry.label) ? "No Label" : entry.label), percentage)); } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BarEntry.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BarEntry.kt index 8e9aeb9915..23040f8a5a 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BarEntry.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BarEntry.kt @@ -141,22 +141,19 @@ open class BarEntry : Entry { calcRanges() } + /** + * Returns the value of this BarEntry. If the entry is stacked, it returns the positive sum of all values. + */ override var y: Float = 0.0f - /** - * Returns the value of this BarEntry. If the entry is stacked, it returns the positive sum of all values. - */ get() = super.y + /** + * Returns true if this BarEntry is stacked (has a values array), false if not. + */ val isStacked: Boolean - /** - * Returns true if this BarEntry is stacked (has a values array), false if not. - */ get() = this.yVals != null - /** - * Use `getSumBelow(stackIndex)` instead. - */ - @Deprecated("") + @Deprecated("getSumBelow(stackIndex)` instead.") fun getBelowSum(stackIndex: Int): Float { return getSumBelow(stackIndex) } @@ -232,5 +229,3 @@ open class BarEntry : Entry { } } } - - diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BubbleEntry.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BubbleEntry.kt similarity index 54% rename from MPChartLib/src/main/java/com/github/mikephil/charting/data/BubbleEntry.java rename to MPChartLib/src/main/java/com/github/mikephil/charting/data/BubbleEntry.kt index 1d5d04f2ea..e766d790fd 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BubbleEntry.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BubbleEntry.kt @@ -1,21 +1,19 @@ +package com.github.mikephil.charting.data -package com.github.mikephil.charting.data; - -import android.annotation.SuppressLint; -import android.graphics.drawable.Drawable; +import android.annotation.SuppressLint +import android.graphics.drawable.Drawable /** * Subclass of Entry that holds a value for one entry in a BubbleChart. Bubble - * chart implementation: Copyright 2015 Pierre-Marc Airoldi Licensed under - * Apache License 2.0 - * - * @author Philipp Jahoda + * chart implementation: Copyright 2015 Pierre-Marc Airoldi Licensed under Apache License 2.0 */ @SuppressLint("ParcelCreator") -public class BubbleEntry extends Entry { - - /** size value */ - private float mSize; +class BubbleEntry : Entry { + /** + * Returns the size of this entry (the size of the bubble). + */ + /** size value */ + var size: Float /** * Constructor. @@ -24,9 +22,8 @@ public class BubbleEntry extends Entry { * @param y The value on the y-axis. * @param size The size of the bubble. */ - public BubbleEntry(float x, float y, float size) { - super(x, y); - this.mSize = size; + constructor(x: Float, y: Float, size: Float) : super(x, y) { + this.size = size } /** @@ -37,9 +34,8 @@ public BubbleEntry(float x, float y, float size) { * @param size The size of the bubble. * @param data Spot for additional data this Entry represents. */ - public BubbleEntry(float x, float y, float size, Object data) { - super(x, y, data); - this.mSize = size; + constructor(x: Float, y: Float, size: Float, data: Any?) : super(x, y, data) { + this.size = size } /** @@ -50,9 +46,8 @@ public BubbleEntry(float x, float y, float size, Object data) { * @param size The size of the bubble. * @param icon Icon image */ - public BubbleEntry(float x, float y, float size, Drawable icon) { - super(x, y, icon); - this.mSize = size; + constructor(x: Float, y: Float, size: Float, icon: Drawable?) : super(x, y, icon) { + this.size = size } /** @@ -64,25 +59,11 @@ public BubbleEntry(float x, float y, float size, Drawable icon) { * @param icon Icon image * @param data Spot for additional data this Entry represents. */ - public BubbleEntry(float x, float y, float size, Drawable icon, Object data) { - super(x, y, icon, data); - this.mSize = size; - } - - public BubbleEntry copy() { - - return new BubbleEntry(getX(), getY(), mSize, getData()); - } - - /** - * Returns the size of this entry (the size of the bubble). - */ - public float getSize() { - return mSize; + constructor(x: Float, y: Float, size: Float, icon: Drawable?, data: Any?) : super(x, y, icon, data) { + this.size = size } - public void setSize(float size) { - this.mSize = size; + override fun copy(): BubbleEntry { + return BubbleEntry(x, y, this.size, data) } - } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleEntry.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleEntry.java deleted file mode 100644 index 5f80edd6ed..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleEntry.java +++ /dev/null @@ -1,170 +0,0 @@ - -package com.github.mikephil.charting.data; - -import android.annotation.SuppressLint; -import android.graphics.drawable.Drawable; - -/** - * Subclass of Entry that holds all values for one entry in a CandleStickChart. - * - * @author Philipp Jahoda - */ -@SuppressLint("ParcelCreator") -public class CandleEntry extends Entry { - - /** shadow-high value */ - private float mShadowHigh; - - /** shadow-low value */ - private float mShadowLow; - - /** close value */ - private float mClose; - - /** open value */ - private float mOpen; - - /** - * Constructor. - * - * @param x The value on the x-axis - * @param shadowH The (shadow) high value - * @param shadowL The (shadow) low value - * @param open The open value - * @param close The close value - */ - public CandleEntry(float x, float shadowH, float shadowL, float open, float close) { - super(x, (shadowH + shadowL) / 2f); - - this.mShadowHigh = shadowH; - this.mShadowLow = shadowL; - this.mOpen = open; - this.mClose = close; - } - - /** - * Constructor. - * - * @param x The value on the x-axis - * @param shadowH The (shadow) high value - * @param shadowL The (shadow) low value - * @param data Spot for additional data this Entry represents - */ - public CandleEntry(float x, float shadowH, float shadowL, float open, float close, - Object data) { - super(x, (shadowH + shadowL) / 2f, data); - - this.mShadowHigh = shadowH; - this.mShadowLow = shadowL; - this.mOpen = open; - this.mClose = close; - } - - /** - * Constructor. - * - * @param x The value on the x-axis - * @param shadowH The (shadow) high value - * @param shadowL The (shadow) low value - * @param icon Icon image - */ - public CandleEntry(float x, float shadowH, float shadowL, float open, float close, - Drawable icon) { - super(x, (shadowH + shadowL) / 2f, icon); - - this.mShadowHigh = shadowH; - this.mShadowLow = shadowL; - this.mOpen = open; - this.mClose = close; - } - - /** - * Constructor. - * - * @param x The value on the x-axis - * @param shadowH The (shadow) high value - * @param shadowL The (shadow) low value - * @param icon Icon image - * @param data Spot for additional data this Entry represents - */ - public CandleEntry(float x, float shadowH, float shadowL, float open, float close, - Drawable icon, Object data) { - super(x, (shadowH + shadowL) / 2f, icon, data); - - this.mShadowHigh = shadowH; - this.mShadowLow = shadowL; - this.mOpen = open; - this.mClose = close; - } - - /** - * Returns the overall range (difference) between shadow-high and - * shadow-low. - */ - public float getShadowRange() { - return Math.abs(mShadowHigh - mShadowLow); - } - - /** - * Returns the body size (difference between open and close). - */ - public float getBodyRange() { - return Math.abs(mOpen - mClose); - } - - /** - * Returns the center value of the candle. (Middle value between high and low) - */ - @Override - public float getY() { - return super.getY(); - } - - public CandleEntry copy() { - return new CandleEntry(getX(), mShadowHigh, mShadowLow, mOpen, mClose, getData()); - } - - /** - * Returns the upper shadows highest value. - */ - public float getHigh() { - return mShadowHigh; - } - - public void setHigh(float mShadowHigh) { - this.mShadowHigh = mShadowHigh; - } - - /** - * Returns the lower shadows lowest value. - */ - public float getLow() { - return mShadowLow; - } - - public void setLow(float mShadowLow) { - this.mShadowLow = mShadowLow; - } - - /** - * Returns the bodies close value. - */ - public float getClose() { - return mClose; - } - - public void setClose(float mClose) { - this.mClose = mClose; - } - - /** - * Returns the bodies open value. - */ - public float getOpen() { - return mOpen; - } - - public void setOpen(float mOpen) { - this.mOpen = mOpen; - } -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleEntry.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleEntry.kt new file mode 100644 index 0000000000..62afbea6d9 --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleEntry.kt @@ -0,0 +1,132 @@ +package com.github.mikephil.charting.data + +import android.annotation.SuppressLint +import android.graphics.drawable.Drawable +import kotlin.math.abs + +/** + * Subclass of Entry that holds all values for one entry in a CandleStickChart. + */ +@SuppressLint("ParcelCreator") +class CandleEntry : Entry { + /** + * Returns the upper shadows highest value. + */ + /** shadow-high value */ + var high: Float + + /** + * Returns the lower shadows lowest value. + */ + /** shadow-low value */ + var low: Float + + /** + * Returns the bodies close value. + */ + /** close value */ + var close: Float + + /** + * Returns the bodies open value. + */ + /** open value */ + var open: Float + + /** + * Constructor. + * + * @param x The value on the x-axis + * @param shadowH The (shadow) high value + * @param shadowL The (shadow) low value + * @param open The open value + * @param close The close value + */ + constructor(x: Float, shadowH: Float, shadowL: Float, open: Float, close: Float) : super(x, (shadowH + shadowL) / 2f) { + this.high = shadowH + this.low = shadowL + this.open = open + this.close = close + } + + /** + * Constructor. + * + * @param x The value on the x-axis + * @param shadowH The (shadow) high value + * @param shadowL The (shadow) low value + * @param data Spot for additional data this Entry represents + */ + constructor( + x: Float, shadowH: Float, shadowL: Float, open: Float, close: Float, + data: Any? + ) : super(x, (shadowH + shadowL) / 2f, data) { + this.high = shadowH + this.low = shadowL + this.open = open + this.close = close + } + + /** + * Constructor. + * + * @param x The value on the x-axis + * @param shadowH The (shadow) high value + * @param shadowL The (shadow) low value + * @param icon Icon image + */ + constructor( + x: Float, shadowH: Float, shadowL: Float, open: Float, close: Float, + icon: Drawable? + ) : super(x, (shadowH + shadowL) / 2f, icon) { + this.high = shadowH + this.low = shadowL + this.open = open + this.close = close + } + + /** + * Constructor. + * + * @param x The value on the x-axis + * @param shadowH The (shadow) high value + * @param shadowL The (shadow) low value + * @param icon Icon image + * @param data Spot for additional data this Entry represents + */ + constructor( + x: Float, shadowH: Float, shadowL: Float, open: Float, close: Float, + icon: Drawable?, data: Any? + ) : super(x, (shadowH + shadowL) / 2f, icon, data) { + this.high = shadowH + this.low = shadowL + this.open = open + this.close = close + } + + /** + * Returns the overall range (difference) between shadow-high and + * shadow-low. + */ + val shadowRange: Float + get() = abs(this.high - this.low) + + /** + * Returns the body size (difference between open and close). + */ + val bodyRange: Float + get() = abs(this.open - this.close) + + /** + * Returns the center value of the candle. (Middle value between high and low) + */ + override var y: Float + get() = super.y + set(value) { + super.y = value + } + + override fun copy(): CandleEntry { + return CandleEntry(x, this.high, this.low, this.open, this.close, data) + } +} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/PieEntry.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/PieEntry.java deleted file mode 100644 index e35f4a11f2..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/PieEntry.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.github.mikephil.charting.data; - -import android.annotation.SuppressLint; -import android.graphics.drawable.Drawable; -import android.util.Log; - -import androidx.annotation.NonNull; - -/** - * @author Philipp Jahoda - */ -@SuppressLint("ParcelCreator") -public class PieEntry extends Entry { - - private String label; - - public PieEntry(float value) { - super(0f, value); - } - - public PieEntry(float value, Object data) { - super(0f, value, data); - } - - public PieEntry(float value, Drawable icon) { - super(0f, value, icon); - } - - public PieEntry(float value, Drawable icon, Object data) { - super(0f, value, icon, data); - } - - public PieEntry(float value, String label) { - super(0f, value); - this.label = label; - } - - public PieEntry(float value, String label, Object data) { - super(0f, value, data); - this.label = label; - } - - public PieEntry(float value, String label, Drawable icon) { - super(0f, value, icon); - this.label = label; - } - - public PieEntry(float value, String label, Drawable icon, Object data) { - super(0f, value, icon, data); - this.label = label; - } - - /** - * This is the same as getY(). Returns the value of the PieEntry. - */ - public float getValue() { - return getY(); - } - - public String getLabel() { - return label; - } - - public void setLabel(String label) { - this.label = label; - } - - @Deprecated - @Override - public void setX(float x) { - super.setX(x); - Log.i("DEPRECATED", "Pie entries do not have x values"); - } - - @Deprecated - @Override - public float getX() { - Log.i("DEPRECATED", "Pie entries do not have x values"); - return super.getX(); - } - - @NonNull - public PieEntry copy() { - return new PieEntry(getY(), label, getData()); - } -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/PieEntry.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/data/PieEntry.kt new file mode 100644 index 0000000000..ee5cdabbfa --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/PieEntry.kt @@ -0,0 +1,57 @@ +package com.github.mikephil.charting.data + +import android.annotation.SuppressLint +import android.graphics.drawable.Drawable +import android.util.Log + +@SuppressLint("ParcelCreator") +class PieEntry : Entry { + @JvmField + var label: String? = null + + constructor(value: Float) : super(0f, value) + + constructor(value: Float, data: Any?) : super(0f, value, data) + + constructor(value: Float, icon: Drawable?) : super(0f, value, icon) + + constructor(value: Float, icon: Drawable?, data: Any?) : super(0f, value, icon, data) + + constructor(value: Float, label: String?) : super(0f, value) { + this.label = label + } + + constructor(value: Float, label: String?, data: Any?) : super(0f, value, data) { + this.label = label + } + + constructor(value: Float, label: String?, icon: Drawable?) : super(0f, value, icon) { + this.label = label + } + + constructor(value: Float, label: String?, icon: Drawable?, data: Any?) : super(0f, value, icon, data) { + this.label = label + } + + val value: Float + /** + * This is the same as getY(). Returns the value of the PieEntry. + */ + get() = y + + @get:Deprecated("") + @set:Deprecated("") + override var x: Float + get() { + Log.i("DEPRECATED", "Pie entries do not have x values") + return super.x + } + set(x) { + super.x = x + Log.i("DEPRECATED", "Pie entries do not have x values") + } + + override fun copy(): PieEntry { + return PieEntry(y, label, data) + } +} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/RadarEntry.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/RadarEntry.java deleted file mode 100644 index 79f97eb79e..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/RadarEntry.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.github.mikephil.charting.data; - -import android.annotation.SuppressLint; - -import androidx.annotation.NonNull; - -/** - * Created by philipp on 13/06/16. - */ -@SuppressLint("ParcelCreator") -public class RadarEntry extends Entry { - - public RadarEntry(float value) { - super(0f, value); - } - - public RadarEntry(float value, Object data) { - super(0f, value, data); - } - - /** - * This is the same as getY(). Returns the value of the RadarEntry. - */ - public float getValue() { - return getY(); - } - - @NonNull - public RadarEntry copy() { - return new RadarEntry(getY(), getData()); - } - - @Deprecated - @Override - public void setX(float x) { - super.setX(x); - } - - @Deprecated - @Override - public float getX() { - return super.getX(); - } -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/RadarEntry.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/data/RadarEntry.kt new file mode 100644 index 0000000000..1a3a624b78 --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/RadarEntry.kt @@ -0,0 +1,28 @@ +package com.github.mikephil.charting.data + +import android.annotation.SuppressLint + +@SuppressLint("ParcelCreator") +class RadarEntry : Entry { + constructor(value: Float) : super(0f, value) + + constructor(value: Float, data: Any?) : super(0f, value, data) + + /** + * This is the same as getY(). Returns the value of the RadarEntry. + */ + val value: Float + get() = y + + override fun copy(): RadarEntry { + return RadarEntry(y, data) + } + + @get:Deprecated("") + @set:Deprecated("") + override var x: Float + get() = super.x + set(x) { + super.x = x + } +}