From 3e5ebf7ee2a6b6d05a8e6e46170d9342fa9b1d88 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Sun, 4 Jan 2026 20:23:14 +0100 Subject: [PATCH 1/5] Entry with double --- .../data/BarLineScatterCandleBubbleDataSet.kt | 2 +- .../info/appdev/charting/data/BaseDataSet.kt | 2 +- .../info/appdev/charting/data/BaseEntry.kt | 76 ++++++++++-- .../info/appdev/charting/data/ChartData.kt | 2 +- .../info/appdev/charting/data/DataSet.kt | 8 +- .../kotlin/info/appdev/charting/data/Entry.kt | 63 +++------- .../info/appdev/charting/data/EntryDouble.kt | 109 +++++++++++++++++- .../appdev/charting/data/LineRadarDataSet.kt | 3 +- .../data/LineScatterCandleRadarDataSet.kt | 2 +- .../charting/highlight/ChartHighlighter.kt | 3 +- .../highlight/HorizontalBarHighlighter.kt | 3 +- .../IBarLineScatterCandleBubbleDataSet.kt | 4 +- .../charting/interfaces/datasets/IDataSet.kt | 3 +- .../interfaces/datasets/ILineRadarDataSet.kt | 4 +- .../ILineScatterCandleRadarDataSet.kt | 4 +- .../BarLineScatterCandleBubbleRenderer.kt | 6 +- 16 files changed, 213 insertions(+), 81 deletions(-) diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleDataSet.kt index fbc22d82e..2751e4703 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleDataSet.kt @@ -7,7 +7,7 @@ import info.appdev.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataS /** * Baseclass of all DataSets for Bar-, Line-, Scatter- and CandleStickChart. */ -abstract class BarLineScatterCandleBubbleDataSet(yVals: MutableList, label: String) : +abstract class BarLineScatterCandleBubbleDataSet>(yVals: MutableList, label: String) : DataSet(yVals, label), IBarLineScatterCandleBubbleDataSet { /** * Sets the color that is used for drawing the highlight indicators. diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/BaseDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/BaseDataSet.kt index a186c6eb3..a743b0d3b 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/BaseDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/BaseDataSet.kt @@ -19,7 +19,7 @@ import info.appdev.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 */ diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/BaseEntry.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/BaseEntry.kt index d553eb652..d2ab4739e 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/BaseEntry.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/BaseEntry.kt @@ -2,34 +2,94 @@ package info.appdev.charting.data import android.graphics.drawable.Drawable -abstract class BaseEntry { +abstract class BaseEntry where T : Number, T : Comparable { - protected var yBase: Float = 0f - open var y: Float - get() = yBase + protected var yBase: T? = null + protected var xBase: T? = null + + open var y: T + get() = yBase ?: throw IllegalStateException("y not initialized") set(value) { yBase = value } + open var x: T + get() = xBase ?: throw IllegalStateException("x not initialized") + set(value) { + xBase = value + } + var data: Any? = null var icon: Drawable? = null constructor() - constructor(y: Float) { + constructor(y: T) { + this.yBase = y + } + + constructor(y: T, data: Any?) : this(y) { + this.data = data + } + + constructor(y: T, icon: Drawable?) : this(y) { + this.icon = icon + } + + constructor(y: T, icon: Drawable?, data: Any?) : this(y) { + this.icon = icon + this.data = data + } + + /** + * A Entry represents one single entry in the chart. + * + * @param x the x value + * @param y the y value (the actual value of the entry) + */ + constructor(x: T, y: T) { + this.xBase = x this.yBase = y } - constructor(y: Float, data: Any?) : this(y) { + /** + * A Entry represents one single entry in the chart. + * + * @param x the x value + * @param y the y value (the actual value of the entry) + * @param data Spot for additional data this Entry represents. + */ + constructor(x: T, y: T, data: Any?) { + this.xBase = x + this.yBase = y this.data = data } - constructor(y: Float, icon: Drawable?) : this(y) { + /** + * A Entry represents one single entry in the chart. + * + * @param x the x value + * @param y the y value (the actual value of the entry) + * @param icon icon image + */ + constructor(x: T, y: T, icon: Drawable?) { + this.xBase = x + this.yBase = y this.icon = icon } - constructor(y: Float, icon: Drawable?, data: Any?) : this(y) { + /** + * A Entry represents one single entry in the chart. + * + * @param x the x value + * @param y the y value (the actual value of the entry) + * @param icon icon image + * @param data Spot for additional data this Entry represents. + */ + constructor(x: T, y: T, icon: Drawable?, data: Any?) { + this.xBase = x + this.yBase = y this.icon = icon this.data = data } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/ChartData.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/ChartData.kt index bb4565974..44dc7203a 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/ChartData.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/ChartData.kt @@ -446,7 +446,7 @@ abstract class ChartData> : Serializable { } val dataSet: IDataSet<*> = dataSets[dataSetIndex] - val entry: Entry = dataSet.getEntryForXValue(xValue, Float.NaN) ?: return false + val entry = dataSet.getEntryForXValue(xValue, Float.NaN) as? Entry ?: return false return removeEntry(entry, dataSetIndex) } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/DataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/DataSet.kt index 12188cd9a..49db36fea 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/DataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/DataSet.kt @@ -10,7 +10,7 @@ import kotlin.math.abs * 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( +abstract class DataSet>( protected var mEntries: MutableList, label: String = "" ) : BaseDataSet(label), Serializable { @@ -219,9 +219,9 @@ abstract class DataSet( while (low < high) { val m = low + (high - low) / 2 - val currentEntry: Entry = mEntries[m] + val currentEntry: T = mEntries[m] - val nextEntry: Entry = mEntries[m + 1] + val nextEntry: T = mEntries[m + 1] val d1 = currentEntry.x - xValue val d2 = nextEntry.x - xValue @@ -251,7 +251,7 @@ abstract class DataSet( closest = high } - val closestEntry: Entry = mEntries[closest] + val closestEntry: T = mEntries[closest] 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... diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/Entry.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/Entry.kt index b285d89dc..885868c0b 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/Entry.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/Entry.kt @@ -12,60 +12,25 @@ import kotlin.math.abs * Class representing one entry in the chart. Might contain multiple values. * Might only contain a single value depending on the used constructor. */ -open class Entry : BaseEntry, Parcelable, Serializable { +open class Entry : BaseEntry, Parcelable, Serializable { - private var _x: Float = 0f - open var x: Float - get() = _x - set(value) { - _x = value - } + constructor() : super() - constructor() + constructor(y: Float) : super(y) - /** - * A Entry represents one single entry in the chart. - * - * @param x the x value - * @param y the y value (the actual value of the entry) - */ - constructor(x: Float, y: Float) : super(y) { - this._x = x - } + constructor(y: Float, data: Any?) : super(y, data) - /** - * A Entry represents one single entry in the chart. - * - * @param x the x value - * @param y the y value (the actual value of the entry) - * @param data Spot for additional data this Entry represents. - */ - constructor(x: Float, y: Float, data: Any?) : super(y, data) { - this._x = x - } + constructor(y: Float, icon: Drawable?) : super(y, icon) - /** - * A Entry represents one single entry in the chart. - * - * @param x the x value - * @param y the y value (the actual value of the entry) - * @param icon icon image - */ - constructor(x: Float, y: Float, icon: Drawable?) : super(y, icon) { - this._x = x - } + constructor(y: Float, icon: Drawable?, data: Any?) : super(y, icon, data) - /** - * A Entry represents one single entry in the chart. - * - * @param x the x value - * @param y the y value (the actual value of the entry) - * @param icon icon image - * @param data Spot for additional data this Entry represents. - */ - constructor(x: Float, y: Float, icon: Drawable?, data: Any?) : super(y, icon, data) { - this._x = x - } + constructor(x: Float, y: Float) : super(x, y) + + constructor(x: Float, y: Float, data: Any?) : super(x, y, data) + + constructor(x: Float, y: Float, icon: Drawable?) : super(x, y, icon) + + constructor(x: Float, y: Float, icon: Drawable?, data: Any?) : super(x, y, icon, data) /** * returns an exact copy of the entry @@ -123,7 +88,7 @@ open class Entry : BaseEntry, Parcelable, Serializable { } protected constructor(`in`: Parcel) { - this._x = `in`.readFloat() + this.xBase = `in`.readFloat() this.yBase = `in`.readFloat() if (`in`.readInt() == 1) { this.data = `in`.readParcelable(Any::class.java.classLoader) diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/EntryDouble.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/EntryDouble.kt index 284880c97..fd550c755 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/EntryDouble.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/EntryDouble.kt @@ -1,3 +1,110 @@ package info.appdev.charting.data -class EntryDouble(val xDouble: Double, y: Float) : Entry(xDouble.toFloat(), y) +import android.graphics.drawable.Drawable +import android.os.Parcel +import android.os.ParcelFormatException +import android.os.Parcelable +import info.appdev.charting.utils.Utils +import java.io.Serializable +import kotlin.math.abs + +/** + * Class representing one entry in the chart. Might contain multiple values. + * Might only contain a single value depending on the used constructor. + */ +open class EntryDouble : BaseEntry, Parcelable, Serializable { + + constructor() : super() + + constructor(y: Double) : super(y) + + constructor(y: Double, data: Any?) : super(y, data) + + constructor(y: Double, icon: Drawable?) : super(y, icon) + + constructor(y: Double, icon: Drawable?, data: Any?) : super(y, icon, data) + + constructor(x: Double, y: Double) : super(x, y) + + constructor(x: Double, y: Double, data: Any?) : super(x, y, data) + + constructor(x: Double, y: Double, icon: Drawable?) : super(x, y, icon) + + constructor(x: Double, y: Double, icon: Drawable?, data: Any?) : super(x, y, icon, data) + + /** + * returns an exact copy of the entry + */ + open fun copy(): EntryDouble { + val e = EntryDouble(x, y, data) + return e + } + + /** + * Compares value, xIndex and data of the entries. Returns true if entries + * are equal in those points, false if not. Does not check by hash-code like + * it's done by the "equals" method. + */ + fun equalTo(e: EntryDouble?): Boolean { + if (e == null) + return false + + if (e.data !== this.data) + return false + + if (abs((e.x - this.x).toDouble()) > Utils.FLOAT_EPSILON) + return false + + if (abs((e.y - this.y).toDouble()) > Utils.FLOAT_EPSILON) + return false + + return true + } + + /** + * returns a string representation of the entry containing x-index and value + */ + override fun toString(): String { + return "Entry x=$x y=$y" + } + + override fun describeContents(): Int { + return 0 + } + + override fun writeToParcel(dest: Parcel, flags: Int) { + dest.writeDouble(this.x) + dest.writeDouble(this.y) + if (data != null) { + if (data is Parcelable) { + dest.writeInt(1) + dest.writeParcelable(data as Parcelable?, flags) + } else { + throw ParcelFormatException("Cannot parcel an Entry with non-parcelable data") + } + } else { + dest.writeInt(0) + } + } + + protected constructor(`in`: Parcel) { + this.xBase = `in`.readDouble() + this.yBase = `in`.readDouble() + if (`in`.readInt() == 1) { + this.data = `in`.readParcelable(Any::class.java.classLoader) + } + } + + companion object { + @JvmField + val CREATOR: Parcelable.Creator = object : Parcelable.Creator { + override fun createFromParcel(source: Parcel): EntryDouble { + return EntryDouble(source) + } + + override fun newArray(size: Int): Array { + return arrayOfNulls(size) + } + } + } +} diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/LineRadarDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/LineRadarDataSet.kt index db3e59332..93e97e80f 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/LineRadarDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/LineRadarDataSet.kt @@ -9,7 +9,8 @@ import info.appdev.charting.utils.convertDpToPixel /** * Base dataset for line and radar DataSets. */ -abstract class LineRadarDataSet(yVals: MutableList, label: String) : LineScatterCandleRadarDataSet(yVals, label), ILineRadarDataSet { +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 diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/LineScatterCandleRadarDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/LineScatterCandleRadarDataSet.kt index 1f9535dff..5a2a9a811 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/LineScatterCandleRadarDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/LineScatterCandleRadarDataSet.kt @@ -4,7 +4,7 @@ import android.graphics.DashPathEffect import info.appdev.charting.interfaces.datasets.ILineScatterCandleRadarDataSet import info.appdev.charting.utils.convertDpToPixel -abstract class LineScatterCandleRadarDataSet(yVals: MutableList, label: String) : BarLineScatterCandleBubbleDataSet(yVals, label), +abstract class LineScatterCandleRadarDataSet>(yVals: MutableList, label: String) : BarLineScatterCandleBubbleDataSet(yVals, label), ILineScatterCandleRadarDataSet { override var isVerticalHighlightIndicator: Boolean = true override var isHorizontalHighlightIndicator: Boolean = true diff --git a/chartLib/src/main/kotlin/info/appdev/charting/highlight/ChartHighlighter.kt b/chartLib/src/main/kotlin/info/appdev/charting/highlight/ChartHighlighter.kt index a49a5a5ef..713bff52f 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/highlight/ChartHighlighter.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/highlight/ChartHighlighter.kt @@ -3,7 +3,6 @@ package info.appdev.charting.highlight import info.appdev.charting.components.YAxis.AxisDependency import info.appdev.charting.data.ChartData import info.appdev.charting.data.DataSet -import info.appdev.charting.data.Entry import info.appdev.charting.interfaces.dataprovider.base.BarLineScatterCandleBubbleDataProvider import info.appdev.charting.interfaces.datasets.IDataSet import info.appdev.charting.utils.PointD @@ -125,7 +124,7 @@ open class ChartHighlighter>(prote var entries = set.getEntriesForXValue(xVal) if (entries != null && entries.isEmpty()) { // Try to find closest x-value and take all entries for that x-value - val closest: Entry? = set.getEntryForXValue(xVal, Float.NaN, rounding) + val closest = set.getEntryForXValue(xVal, Float.NaN, rounding) if (closest != null) { entries = set.getEntriesForXValue(closest.x) } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/highlight/HorizontalBarHighlighter.kt b/chartLib/src/main/kotlin/info/appdev/charting/highlight/HorizontalBarHighlighter.kt index 9ac9af962..f2ab13581 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/highlight/HorizontalBarHighlighter.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/highlight/HorizontalBarHighlighter.kt @@ -1,7 +1,6 @@ package info.appdev.charting.highlight import info.appdev.charting.data.DataSet -import info.appdev.charting.data.Entry import info.appdev.charting.interfaces.dataprovider.BarDataProvider import info.appdev.charting.interfaces.datasets.IDataSet import info.appdev.charting.utils.PointD @@ -38,7 +37,7 @@ class HorizontalBarHighlighter(dataProvider: BarDataProvider) : BarHighlighter(d var entries = set.getEntriesForXValue(xVal) if (entries != null && entries.isEmpty()) { // Try to find closest x-value and take all entries for that x-value - val closestEntry: Entry? = set.getEntryForXValue(xVal, Float.NaN, rounding) + val closestEntry = set.getEntryForXValue(xVal, Float.NaN, rounding) closestEntry?.let { closestE -> entries = set.getEntriesForXValue(closestE.x) } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.kt index c54774425..620d555cb 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.kt @@ -1,8 +1,8 @@ package info.appdev.charting.interfaces.datasets -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry -interface IBarLineScatterCandleBubbleDataSet : IDataSet { +interface IBarLineScatterCandleBubbleDataSet> : IDataSet { val highLightColor: Int } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IDataSet.kt index 2b2a75a6c..ade87f73e 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IDataSet.kt @@ -4,12 +4,13 @@ import android.graphics.DashPathEffect import android.graphics.Typeface import info.appdev.charting.components.Legend import info.appdev.charting.components.YAxis +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.DataSet import info.appdev.charting.data.Entry import info.appdev.charting.formatter.IValueFormatter import info.appdev.charting.utils.PointF -interface IDataSet { +interface IDataSet> { /** * returns the minimum y-value this DataSet holds */ diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineRadarDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineRadarDataSet.kt index d0ccfe7d9..31ebc9986 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineRadarDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineRadarDataSet.kt @@ -1,9 +1,9 @@ package info.appdev.charting.interfaces.datasets import android.graphics.drawable.Drawable -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry -interface ILineRadarDataSet : ILineScatterCandleRadarDataSet { +interface ILineRadarDataSet> : ILineScatterCandleRadarDataSet { /** * Returns the color that is used for filling the line surface area. */ diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineScatterCandleRadarDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineScatterCandleRadarDataSet.kt index 56cb22950..8e1f2868e 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineScatterCandleRadarDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineScatterCandleRadarDataSet.kt @@ -1,9 +1,9 @@ package info.appdev.charting.interfaces.datasets import android.graphics.DashPathEffect -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry -interface ILineScatterCandleRadarDataSet : IBarLineScatterCandleBubbleDataSet { +interface ILineScatterCandleRadarDataSet> : IBarLineScatterCandleBubbleDataSet { /** * Returns true if vertical highlight indicator lines are enabled (drawn) */ diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/BarLineScatterCandleBubbleRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/BarLineScatterCandleBubbleRenderer.kt index d54b178d9..1634e8264 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/BarLineScatterCandleBubbleRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/BarLineScatterCandleBubbleRenderer.kt @@ -1,8 +1,8 @@ package info.appdev.charting.renderer import info.appdev.charting.animation.ChartAnimator +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.DataSet -import info.appdev.charting.data.Entry import info.appdev.charting.interfaces.dataprovider.base.BarLineScatterCandleBubbleDataProvider import info.appdev.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet import info.appdev.charting.interfaces.datasets.IDataSet @@ -29,7 +29,7 @@ abstract class BarLineScatterCandleBubbleRenderer( /** * Checks if the provided entry object is in bounds for drawing considering the current animation phase. */ - protected fun isInBoundsX(entry: T, set: IBarLineScatterCandleBubbleDataSet): Boolean { + protected fun > isInBoundsX(entry: T, set: IBarLineScatterCandleBubbleDataSet): Boolean { val entryIndex = set.getEntryIndex(entry).toFloat() return if (entryIndex >= set.entryCount * animator.phaseX) { @@ -61,7 +61,7 @@ abstract class BarLineScatterCandleBubbleRenderer( /** * Calculates the minimum and maximum x values as well as the range between them. */ - fun set(chart: BarLineScatterCandleBubbleDataProvider<*>, dataSet: IBarLineScatterCandleBubbleDataSet) { + fun > set(chart: BarLineScatterCandleBubbleDataProvider<*>, dataSet: IBarLineScatterCandleBubbleDataSet) { val phaseX = max(0f, min(1f, animator.phaseX)) val low = chart.lowestVisibleX From 168424c659337dcb39cb38de7a8d0ff4ab46d4a0 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Sun, 18 Jan 2026 19:15:42 +0100 Subject: [PATCH 2/5] More --- app/build.gradle.kts | 2 +- .../appdev/chartexample/BarChartActivity.kt | 4 +- .../BarChartActivityMultiDataset.kt | 4 +- .../chartexample/BarChartPositiveNegative.kt | 4 +- .../chartexample/BubbleChartActivity.kt | 4 +- .../chartexample/CubicLineChartActivity.kt | 17 +++--- .../info/appdev/chartexample/DataTools.kt | 14 ++--- .../appdev/chartexample/DrawChartActivity.kt | 5 +- .../chartexample/DynamicalAddingActivity.kt | 7 +-- .../appdev/chartexample/FilledLineActivity.kt | 21 ++++---- .../appdev/chartexample/GradientActivity.kt | 3 +- .../HorizontalBarChartActivity.kt | 4 +- .../HorizontalBarNegativeChartActivity.kt | 4 +- .../chartexample/InvertedLineChartActivity.kt | 3 +- .../appdev/chartexample/LineChartActivity.kt | 12 ++--- .../chartexample/LineChartActivityColored.kt | 2 +- .../chartexample/LineChartDualAxisActivity.kt | 22 ++++---- .../ListViewMultiChartActivity.kt | 3 +- .../chartexample/MultiLineChartActivity.kt | 14 +++-- .../appdev/chartexample/PieChartActivity.kt | 4 +- .../chartexample/PieChartRoundedActivity.kt | 4 +- .../chartexample/PiePolylineChartActivity.kt | 4 +- .../chartexample/RealtimeLineChartActivity.kt | 7 +-- .../chartexample/ScatterChartActivity.kt | 3 +- .../SpecificPositionsLineChartActivity.kt | 23 +++++--- .../appdev/chartexample/StackedBarActivity.kt | 4 +- .../StackedBarActivityNegative.kt | 6 +-- .../appdev/chartexample/TimeLineActivity.kt | 19 ++++--- .../compose/HorizontalBarComposeActivity.kt | 4 +- .../chartexample/formatter/MyFillFormatter.kt | 3 +- .../formatter/MyValueFormatter.kt | 4 +- .../chartexample/fragments/SimpleFragment.kt | 10 ++-- .../charting/charts/BarLineChartBase.kt | 7 +-- .../info/appdev/charting/charts/Chart.kt | 13 ++--- .../appdev/charting/charts/CombinedChart.kt | 4 +- .../charting/charts/PieRadarChartBase.kt | 4 +- .../info/appdev/charting/data/BarDataSet.kt | 6 +-- .../data/BarLineScatterCandleBubbleData.kt | 4 +- .../data/BarLineScatterCandleBubbleDataSet.kt | 8 +-- .../info/appdev/charting/data/BaseDataSet.kt | 4 +- .../appdev/charting/data/BubbleDataSet.kt | 4 +- .../appdev/charting/data/CandleDataSet.kt | 6 +-- .../info/appdev/charting/data/ChartData.kt | 14 ++--- .../info/appdev/charting/data/CombinedData.kt | 12 ++--- .../info/appdev/charting/data/DataSet.kt | 52 ++++++++++--------- .../info/appdev/charting/data/LineData.kt | 6 +-- .../info/appdev/charting/data/LineDataSet.kt | 33 ++++++------ .../appdev/charting/data/LineRadarDataSet.kt | 7 ++- .../data/LineScatterCandleRadarDataSet.kt | 8 +-- .../info/appdev/charting/data/PieDataSet.kt | 6 +-- .../info/appdev/charting/data/RadarDataSet.kt | 6 +-- .../appdev/charting/data/ScatterDataSet.kt | 6 +-- .../charting/formatter/ColorFormatter.kt | 2 +- .../formatter/DefaultFillFormatter.kt | 3 +- .../formatter/DefaultValueFormatter.kt | 4 +- .../charting/formatter/IFillFormatter.kt | 3 +- .../charting/formatter/IValueFormatter.kt | 4 +- .../charting/formatter/LargeValueFormatter.kt | 4 +- .../charting/formatter/PercentFormatter.kt | 4 +- .../formatter/StackedValueFormatter.kt | 4 +- .../charting/highlight/ChartHighlighter.kt | 10 ++-- .../highlight/HorizontalBarHighlighter.kt | 8 +-- .../interfaces/datasets/IBarDataSet.kt | 2 +- .../IBarLineScatterCandleBubbleDataSet.kt | 2 +- .../interfaces/datasets/IBubbleDataSet.kt | 2 +- .../interfaces/datasets/ICandleDataSet.kt | 3 +- .../charting/interfaces/datasets/IDataSet.kt | 3 +- .../interfaces/datasets/ILineDataSet.kt | 4 +- .../interfaces/datasets/ILineRadarDataSet.kt | 2 +- .../ILineScatterCandleRadarDataSet.kt | 2 +- .../interfaces/datasets/IPieDataSet.kt | 2 +- .../interfaces/datasets/IRadarDataSet.kt | 2 +- .../interfaces/datasets/IScatterDataSet.kt | 2 +- .../listener/BarLineChartTouchListener.kt | 13 ++--- .../listener/OnChartValueSelectedListener.kt | 4 +- .../charting/listener/OnDrawListener.kt | 3 +- .../BarLineScatterCandleBubbleRenderer.kt | 6 +-- .../appdev/charting/renderer/DataRenderer.kt | 6 +-- .../charting/renderer/LineChartRenderer.kt | 36 +++++++------ .../LineScatterCandleRadarRenderer.kt | 2 +- .../charting/utils/AssetManagerUtils.kt | 5 +- .../info/appdev/charting/utils/Transformer.kt | 3 +- 82 files changed, 319 insertions(+), 285 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 97162135d..a9d36b4df 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -12,7 +12,7 @@ android { namespace = "info.appdev.chartexample" defaultConfig { applicationId = "info.appdev.chartexample" - minSdk = 23 + minSdk = 24 compileSdk = 36 targetSdk = 36 versionCode = getGitCommitCount() diff --git a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivity.kt index bf660256e..353f40682 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivity.kt @@ -26,7 +26,7 @@ import info.appdev.charting.components.YAxis.YAxisLabelPosition import info.appdev.charting.data.BarData import info.appdev.charting.data.BarDataSet import info.appdev.charting.data.BarEntry -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.formatter.IAxisValueFormatter import info.appdev.charting.highlight.Highlight import info.appdev.charting.interfaces.datasets.IBarDataSet @@ -281,7 +281,7 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect private val onValueSelectedRectF = RectF() - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entry: BaseEntry, highlight: Highlight) { val bounds = onValueSelectedRectF binding.chart1.getBarBounds(entry as BarEntry, bounds) val position = binding.chart1.getPosition(entry, AxisDependency.LEFT) diff --git a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt index efad124f7..17227d037 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt @@ -20,7 +20,7 @@ import info.appdev.charting.components.Legend import info.appdev.charting.data.BarData import info.appdev.charting.data.BarDataSet import info.appdev.charting.data.BarEntry -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.formatter.IAxisValueFormatter import info.appdev.charting.formatter.LargeValueFormatter import info.appdev.charting.highlight.Highlight @@ -247,7 +247,7 @@ class BarChartActivityMultiDataset : DemoBase(), OnSeekBarChangeListener, OnChar override fun onStopTrackingTouch(seekBar: SeekBar?) = Unit - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entry: BaseEntry, highlight: Highlight) { Timber.i("Selected: $entry, dataSet: ${highlight.dataSetIndex}") } diff --git a/app/src/main/kotlin/info/appdev/chartexample/BarChartPositiveNegative.kt b/app/src/main/kotlin/info/appdev/chartexample/BarChartPositiveNegative.kt index 04e6e370d..9bca46d63 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/BarChartPositiveNegative.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/BarChartPositiveNegative.kt @@ -13,7 +13,7 @@ import info.appdev.charting.components.XAxis.XAxisPosition import info.appdev.charting.data.BarData import info.appdev.charting.data.BarDataSet import info.appdev.charting.data.BarEntry -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.formatter.IAxisValueFormatter import info.appdev.charting.formatter.IValueFormatter import info.appdev.charting.utils.ViewPortHandler @@ -136,7 +136,7 @@ class BarChartPositiveNegative : DemoBase() { private class ValueFormatter : IValueFormatter { private val mFormat: DecimalFormat = DecimalFormat("######.0") - override fun getFormattedValue(value: Float, entry: Entry?, dataSetIndex: Int, viewPortHandler: ViewPortHandler?): String { + override fun getFormattedValue(value: Float, entry: BaseEntry?, dataSetIndex: Int, viewPortHandler: ViewPortHandler?): String { return mFormat.format(value.toDouble()) } } diff --git a/app/src/main/kotlin/info/appdev/chartexample/BubbleChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/BubbleChartActivity.kt index a478a0f64..f38f8a734 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/BubbleChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/BubbleChartActivity.kt @@ -17,10 +17,10 @@ import info.appdev.chartexample.databinding.ActivityBubblechartBinding import info.appdev.chartexample.notimportant.DemoBase import info.appdev.charting.components.Legend import info.appdev.charting.components.XAxis +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.BubbleData import info.appdev.charting.data.BubbleDataSet import info.appdev.charting.data.BubbleEntry -import info.appdev.charting.data.Entry import info.appdev.charting.highlight.Highlight import info.appdev.charting.interfaces.datasets.IBubbleDataSet import info.appdev.charting.listener.OnChartValueSelectedListener @@ -211,7 +211,7 @@ class BubbleChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSel saveToGallery(binding.chart1, "BubbleChartActivity") } - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entry: BaseEntry, highlight: Highlight) { Timber.i("Value: ${entry.y}, xIndex: ${entry.x}, DataSet index: ${highlight.dataSetIndex}") } diff --git a/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt index 7e478b5ea..513c8dddc 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt @@ -16,6 +16,7 @@ import info.appdev.chartexample.DataTools.Companion.getMuchValues import info.appdev.chartexample.databinding.ActivityLinechartBinding import info.appdev.chartexample.notimportant.DemoBase import info.appdev.charting.components.YAxis +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.Entry import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet @@ -91,10 +92,10 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener { values.add(Entry(i.toFloat(), `val`)) } - val set1: LineDataSet + val set1: LineDataSet if (binding.chart1.lineData.dataSetCount > 0) { - set1 = binding.chart1.lineData.getDataSetByIndex(0) as LineDataSet + set1 = binding.chart1.lineData.getDataSetByIndex(0) as LineDataSet set1.entries = values binding.chart1.lineData.notifyDataChanged() binding.chart1.notifyDataSetChanged() @@ -115,7 +116,7 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener { set1.fillAlpha = 100 set1.isHorizontalHighlightIndicator = false set1.fillFormatter = object : IFillFormatter { - override fun getFillLinePosition(dataSet: ILineDataSet?, dataProvider: LineDataProvider): Float { + override fun getFillLinePosition(dataSet: ILineDataSet, Float>?, dataProvider: LineDataProvider): Float { return binding.chart1.axisLeft.axisMinimum } } @@ -160,7 +161,7 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener { R.id.actionToggleFilled -> { binding.chart1.lineData.dataSets.forEach { - val set = it as LineDataSet + val set = it as LineDataSet<*, *> set.isDrawFilled = !set.isDrawFilled } binding.chart1.invalidate() @@ -168,7 +169,7 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener { R.id.actionToggleCircles -> { binding.chart1.lineData.dataSets.forEach { - val set = it as LineDataSet + val set = it as LineDataSet<*, *> set.isDrawCircles = !set.isDrawCircles } binding.chart1.invalidate() @@ -176,7 +177,7 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener { R.id.actionToggleCubic -> { binding.chart1.lineData.dataSets.forEach { - val set = it as LineDataSet + val set = it as LineDataSet<*, *> set.lineMode = if (set.lineMode == LineDataSet.Mode.CUBIC_BEZIER) LineDataSet.Mode.LINEAR else @@ -187,7 +188,7 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener { R.id.actionToggleStepped -> { binding.chart1.lineData.dataSets.forEach { - val set = it as LineDataSet + val set = it as LineDataSet<*, *> set.lineMode = if (set.lineMode == LineDataSet.Mode.STEPPED) LineDataSet.Mode.LINEAR else @@ -198,7 +199,7 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener { R.id.actionToggleHorizontalCubic -> { binding.chart1.lineData.dataSets.forEach { - val set = it as LineDataSet + val set = it as LineDataSet<*, *> set.lineMode = if (set.lineMode == LineDataSet.Mode.HORIZONTAL_BEZIER) LineDataSet.Mode.LINEAR else diff --git a/app/src/main/kotlin/info/appdev/chartexample/DataTools.kt b/app/src/main/kotlin/info/appdev/chartexample/DataTools.kt index 84c7deb04..e6e6b35bf 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/DataTools.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/DataTools.kt @@ -5,6 +5,7 @@ import android.graphics.Color import android.graphics.DashPathEffect import androidx.core.content.ContextCompat import info.appdev.charting.charts.LineChart +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.Entry import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet @@ -13,6 +14,7 @@ import info.appdev.charting.interfaces.dataprovider.LineDataProvider import info.appdev.charting.interfaces.datasets.ILineDataSet import info.appdev.charting.utils.getSDKInt import timber.log.Timber +import kotlin.Float import kotlin.math.PI import kotlin.math.sin @@ -160,7 +162,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))) @@ -173,7 +175,7 @@ class DataTools { } lineChart.data?.let { if (it.dataSetCount > 0) { - val lineDataSet0 = it.getDataSetByIndex(0) as LineDataSet + val lineDataSet0 = it.getDataSetByIndex(0) as LineDataSet, Float> lineDataSet0.entries = values lineDataSet0.notifyDataChanged() it.notifyDataChanged() @@ -186,7 +188,7 @@ class DataTools { } private fun createDataset( - values: ArrayList, + values: ArrayList>, lineChart: LineChart, context: Context ) { @@ -222,7 +224,7 @@ class DataTools { // set the filled area lineDataSet01.isDrawFilled = true lineDataSet01.fillFormatter = object : IFillFormatter { - override fun getFillLinePosition(dataSet: ILineDataSet?, dataProvider: LineDataProvider): Float { + override fun getFillLinePosition(dataSet: ILineDataSet, Float>?, dataProvider: LineDataProvider): Float { return lineChart.axisLeft.axisMinimum } } @@ -235,11 +237,11 @@ class DataTools { } else { lineDataSet01.fillColor = Color.BLACK } - val dataSets = ArrayList() + val dataSets = ArrayList, Float>>() dataSets.add(lineDataSet01) // add the data sets // create a data object with the data sets - val data = LineData(dataSets) + val data = LineData(dataSets.toMutableList()) lineChart.data = data } diff --git a/app/src/main/kotlin/info/appdev/chartexample/DrawChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/DrawChartActivity.kt index 9194ee49c..0a082459d 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/DrawChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/DrawChartActivity.kt @@ -9,6 +9,7 @@ import android.view.MenuItem import androidx.core.content.ContextCompat import info.appdev.chartexample.databinding.ActivityDrawChartBinding import info.appdev.chartexample.notimportant.DemoBase +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.DataSet import info.appdev.charting.data.Entry import info.appdev.charting.data.LineData @@ -116,7 +117,7 @@ class DrawChartActivity : DemoBase(), OnChartValueSelectedListener, OnDrawListen saveToGallery(binding.chart1, "DrawChartActivity") } - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entry: BaseEntry, highlight: Highlight) { Timber.i(("Value: ${entry.y}, xIndex: ${entry.x}, DataSet index:${highlight.dataSetIndex}")) } @@ -128,7 +129,7 @@ class DrawChartActivity : DemoBase(), OnChartValueSelectedListener, OnDrawListen } /** callback when a DataSet has been drawn (when lifting the finger) */ - override fun onDrawFinished(dataSet: DataSet<*>) { + override fun onDrawFinished(dataSet: DataSet, Float>) { Timber.i("DataSet drawn. ${dataSet.toSimpleString()}") // prepare the legend again diff --git a/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt index aa371611f..73c7d4bbe 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt @@ -14,6 +14,7 @@ import info.appdev.chartexample.DataTools.Companion.getValues import info.appdev.chartexample.databinding.ActivityLinechartNoseekbarBinding import info.appdev.chartexample.notimportant.DemoBase import info.appdev.charting.components.YAxis.AxisDependency +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.Entry import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet @@ -147,8 +148,8 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener { } } - private fun createSet(): LineDataSet { - val set = LineDataSet(label = "DataSet 1") + private fun createSet(): LineDataSet, Float> { + val set = LineDataSet, Float>(label = "DataSet 1") set.lineWidth = 2.5f set.circleRadius = 4.5f set.color = Color.rgb(240, 99, 99) @@ -160,7 +161,7 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener { return set } - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entry: BaseEntry, highlight: Highlight) { Toast.makeText(this, entry.toString(), Toast.LENGTH_SHORT).show() } diff --git a/app/src/main/kotlin/info/appdev/chartexample/FilledLineActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/FilledLineActivity.kt index 528f1b2e7..8dfdc36d9 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/FilledLineActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/FilledLineActivity.kt @@ -10,6 +10,7 @@ import info.appdev.chartexample.DataTools.Companion.getValues import info.appdev.chartexample.databinding.ActivityLinechartNoseekbarBinding import info.appdev.chartexample.notimportant.DemoBase import info.appdev.charting.components.YAxis +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.Entry import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet @@ -69,7 +70,7 @@ class FilledLineActivity : DemoBase() { private fun setData(@Suppress("SameParameterValue") range: Float) { val count = 100 - val valuesArray1 = ArrayList() + val valuesArray1 = ArrayList>() val sampleValues = getValues(count + 2) for (i in 0..() + val valuesArray2 = ArrayList>() for (i in 0.., Float> + val set2: LineDataSet, Float> if (binding.chart1.lineData.dataSetCount > 0) { - set1 = binding.chart1.lineData.getDataSetByIndex(0) as LineDataSet - set2 = binding.chart1.lineData.getDataSetByIndex(1) as LineDataSet + set1 = binding.chart1.lineData.getDataSetByIndex(0) as LineDataSet, Float> + set2 = binding.chart1.lineData.getDataSetByIndex(1) as LineDataSet, Float> set1.entries = valuesArray1 set2.entries = valuesArray2 binding.chart1.lineData.notifyDataChanged() @@ -109,7 +110,7 @@ class FilledLineActivity : DemoBase() { set1.highLightColor = Color.rgb(244, 117, 117) set1.isDrawCircleHoleEnabled = false set1.fillFormatter = object : IFillFormatter { - override fun getFillLinePosition(dataSet: ILineDataSet?, dataProvider: LineDataProvider): Float { + override fun getFillLinePosition(dataSet: ILineDataSet, Float>?, dataProvider: LineDataProvider): Float { // change the return value here to better understand the effect // return 0; return binding.chart1.axisLeft.axisMinimum @@ -129,19 +130,19 @@ class FilledLineActivity : DemoBase() { set2.isDrawCircleHoleEnabled = false set2.highLightColor = Color.rgb(244, 117, 117) set2.fillFormatter = object : IFillFormatter { - override fun getFillLinePosition(dataSet: ILineDataSet?, dataProvider: LineDataProvider): Float { + override fun getFillLinePosition(dataSet: ILineDataSet, Float>?, dataProvider: LineDataProvider): Float { // change the return value here to better understand the effect // return 600; return binding.chart1.axisLeft.axisMaximum } } - val dataSets = ArrayList() + val dataSets = ArrayList, Float>>() dataSets.add(set1) // add the data sets dataSets.add(set2) // create a data object with the data sets - val data = LineData(dataSets) + val data = LineData(dataSets.toMutableList()) data.setDrawValues(false) binding.chart1.data = data diff --git a/app/src/main/kotlin/info/appdev/chartexample/GradientActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/GradientActivity.kt index 2b314d38f..39e8a4add 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/GradientActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/GradientActivity.kt @@ -6,6 +6,7 @@ import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat import info.appdev.chartexample.databinding.ActivityGradientBinding import info.appdev.chartexample.notimportant.DemoBase +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.Entry import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet @@ -62,7 +63,7 @@ class GradientActivity : DemoBase() { fillFormatter = object : IFillFormatter { override fun getFillLinePosition( - dataSet: ILineDataSet?, + dataSet: ILineDataSet, Float>?, dataProvider: LineDataProvider ): Float = binding.chart1.axisLeft.axisMinimum } diff --git a/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarChartActivity.kt index 6fd38ad15..60eea57d3 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarChartActivity.kt @@ -20,7 +20,7 @@ import info.appdev.charting.components.XAxis.XAxisPosition import info.appdev.charting.data.BarData import info.appdev.charting.data.BarDataSet import info.appdev.charting.data.BarEntry -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.highlight.Highlight import info.appdev.charting.interfaces.datasets.IBarDataSet import info.appdev.charting.listener.OnChartValueSelectedListener @@ -233,7 +233,7 @@ class HorizontalBarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartV private val mOnValueSelectedRectF = RectF() - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entry: BaseEntry, highlight: Highlight) { val bounds = mOnValueSelectedRectF binding.chart1.getBarBounds(entry as BarEntry, bounds) diff --git a/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarNegativeChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarNegativeChartActivity.kt index fbeac36f8..3f8f12f53 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarNegativeChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarNegativeChartActivity.kt @@ -20,7 +20,7 @@ import info.appdev.charting.components.XAxis.XAxisPosition import info.appdev.charting.data.BarData import info.appdev.charting.data.BarDataSet import info.appdev.charting.data.BarEntry -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.highlight.Highlight import info.appdev.charting.interfaces.datasets.IBarDataSet import info.appdev.charting.listener.OnChartValueSelectedListener @@ -229,7 +229,7 @@ class HorizontalBarNegativeChartActivity : DemoBase(), OnSeekBarChangeListener, private val mOnValueSelectedRectF = RectF() - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entry: BaseEntry, highlight: Highlight) { val bounds = mOnValueSelectedRectF binding.chart1.getBarBounds(entry as BarEntry, bounds) diff --git a/app/src/main/kotlin/info/appdev/chartexample/InvertedLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/InvertedLineChartActivity.kt index f3191f4f5..bb6ce68ed 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/InvertedLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/InvertedLineChartActivity.kt @@ -15,6 +15,7 @@ import info.appdev.chartexample.custom.MyMarkerView import info.appdev.chartexample.databinding.ActivityLinechartBinding import info.appdev.chartexample.notimportant.DemoBase import info.appdev.charting.components.Legend.LegendForm +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.Entry import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet @@ -206,7 +207,7 @@ class InvertedLineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa saveToGallery(binding.chart1, "InvertedLineChartActivity") } - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entry: BaseEntry, highlight: Highlight) { Timber.i("Value: ${entry.y}, xIndex: ${entry.x}, DataSet index: ${highlight.dataSetIndex}") } diff --git a/app/src/main/kotlin/info/appdev/chartexample/LineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/LineChartActivity.kt index a828b8b35..6c8f057d7 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/LineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/LineChartActivity.kt @@ -20,7 +20,7 @@ import info.appdev.charting.components.Legend.LegendForm import info.appdev.charting.components.LimitLine import info.appdev.charting.components.LimitLine.LimitLabelPosition import info.appdev.charting.components.LimitRange -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.LineDataSet import info.appdev.charting.highlight.Highlight import info.appdev.charting.listener.OnChartValueSelectedListener @@ -181,14 +181,14 @@ class LineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelec } R.id.actionToggleCircles -> { - binding.chart1.data?.dataSets?.map { it as LineDataSet }?.forEach { set -> + binding.chart1.data?.dataSets?.map { it as LineDataSet<*, *> }?.forEach { set -> set.isDrawCircles = !set.isDrawCircles } binding.chart1.invalidate() } R.id.actionToggleCubic -> { - binding.chart1.data?.dataSets?.map { it as LineDataSet }?.forEach { set -> + binding.chart1.data?.dataSets?.map { it as LineDataSet<*, *> }?.forEach { set -> set.lineMode = if (set.lineMode == LineDataSet.Mode.CUBIC_BEZIER) LineDataSet.Mode.LINEAR else @@ -198,7 +198,7 @@ class LineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelec } R.id.actionToggleStepped -> { - binding.chart1.data?.dataSets?.map { it as LineDataSet }?.forEach { set -> + binding.chart1.data?.dataSets?.map { it as LineDataSet<*, *> }?.forEach { set -> set.lineMode = if (set.lineMode == LineDataSet.Mode.STEPPED) LineDataSet.Mode.LINEAR else @@ -208,7 +208,7 @@ class LineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelec } R.id.actionToggleHorizontalCubic -> { - binding.chart1.data?.dataSets?.map { it as LineDataSet }?.forEach { set -> + binding.chart1.data?.dataSets?.map { it as LineDataSet<*, *> }?.forEach { set -> set.lineMode = if (set.lineMode == LineDataSet.Mode.HORIZONTAL_BEZIER) LineDataSet.Mode.LINEAR else @@ -256,7 +256,7 @@ class LineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelec override fun onStartTrackingTouch(seekBar: SeekBar) {} override fun onStopTrackingTouch(seekBar: SeekBar) {} - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entry: BaseEntry, highlight: Highlight) { Timber.i(entry.toString()) Timber.i("LOW HIGH low:${binding.chart1.lowestVisibleX}, high:${binding.chart1.highestVisibleX}") Timber.i("MIN MAX xMin:${binding.chart1.xChartMin}, xMax:${binding.chart1.xChartMax}, yMin:${binding.chart1.yChartMin}, yMax:${binding.chart1.yChartMax}") diff --git a/app/src/main/kotlin/info/appdev/chartexample/LineChartActivityColored.kt b/app/src/main/kotlin/info/appdev/chartexample/LineChartActivityColored.kt index 7025a8c38..63d1d79a1 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/LineChartActivityColored.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/LineChartActivityColored.kt @@ -49,7 +49,7 @@ class LineChartActivityColored : DemoBase() { ) private fun setupChart(chart: LineChart, data: LineData, color: Int) { - (data.getDataSetByIndex(0) as LineDataSet).circleHoleColor = color + (data.getDataSetByIndex(0) as LineDataSet<*, *>).circleHoleColor = color // no description text chart.description.isEnabled = false diff --git a/app/src/main/kotlin/info/appdev/chartexample/LineChartDualAxisActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/LineChartDualAxisActivity.kt index 4a56bf880..cf1ebdfc8 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/LineChartDualAxisActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/LineChartDualAxisActivity.kt @@ -18,6 +18,7 @@ import info.appdev.charting.charts.LineChart import info.appdev.charting.components.Legend import info.appdev.charting.components.Legend.LegendForm import info.appdev.charting.components.YAxis.AxisDependency +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.Entry import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet @@ -108,7 +109,7 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa } private fun setData(count: Int, range: Float) { - val values1 = ArrayList() + val values1 = ArrayList>() val sampleValues = getValues(count) for (i in 0..() + val values2 = ArrayList>() for (i in 0..() + val values3 = ArrayList>() for (i in 0.., Float> + val set2: LineDataSet, Float> + val set3: LineDataSet, Float> if (binding.chart1.lineData.dataSetCount > 0) { - set1 = binding.chart1.lineData.getDataSetByIndex(0) as LineDataSet - set2 = binding.chart1.lineData.getDataSetByIndex(1) as LineDataSet - set3 = binding.chart1.lineData.getDataSetByIndex(2) as LineDataSet + set1 = binding.chart1.lineData.getDataSetByIndex(0) as LineDataSet, Float> + set2 = binding.chart1.lineData.getDataSetByIndex(1) as LineDataSet, Float> + set3 = binding.chart1.lineData.getDataSetByIndex(2) as LineDataSet, Float> set1.entries = values1 set2.entries = values2 set3.entries = values3 @@ -315,7 +315,7 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa saveToGallery(binding.chart1, "LineChartActivity2") } - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entry: BaseEntry, highlight: Highlight) { Timber.i(entry.toString()) binding.chart1.lineData.getDataSetByIndex(highlight.dataSetIndex)?.let { diff --git a/app/src/main/kotlin/info/appdev/chartexample/ListViewMultiChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/ListViewMultiChartActivity.kt index dca2a35e8..8d20112b7 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/ListViewMultiChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/ListViewMultiChartActivity.kt @@ -20,6 +20,7 @@ import info.appdev.chartexample.notimportant.DemoBase import info.appdev.charting.data.BarData import info.appdev.charting.data.BarDataSet import info.appdev.charting.data.BarEntry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.Entry import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet @@ -116,7 +117,7 @@ class ListViewMultiChartActivity : DemoBase() { d2.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[0]) d2.isDrawValues = false - val sets = ArrayList() + val sets = ArrayList, Float>>() sets.add(d1) sets.add(d2) diff --git a/app/src/main/kotlin/info/appdev/chartexample/MultiLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/MultiLineChartActivity.kt index 38b89d9fd..a4e0ff6b4 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/MultiLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/MultiLineChartActivity.kt @@ -15,6 +15,7 @@ import info.appdev.chartexample.DataTools.Companion.getValues import info.appdev.chartexample.databinding.ActivityLinechartBinding import info.appdev.chartexample.notimportant.DemoBase import info.appdev.charting.components.Legend +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.Entry import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet @@ -83,7 +84,7 @@ class MultiLineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartGestu binding.tvXMax.text = binding.seekBarX.progress.toString() binding.tvYMax.text = binding.seekBarY.progress.toString() - val dataSets = ArrayList() + val dataSets = ArrayList, Float>>() for (datasetNumber in 0..2) { val values = ArrayList() @@ -105,9 +106,12 @@ class MultiLineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartGestu } // make the first DataSet dashed - (dataSets[0] as LineDataSet).enableDashedLine(10f, 10f, 0f) - (dataSets[0] as LineDataSet).setColors(*ColorTemplate.VORDIPLOM_COLORS) - (dataSets[0] as LineDataSet).setCircleColors(*ColorTemplate.VORDIPLOM_COLORS) + @Suppress("UNCHECKED_CAST") + (dataSets[0] as LineDataSet).enableDashedLine(10f, 10f, 0f) + @Suppress("UNCHECKED_CAST") + (dataSets[0] as LineDataSet).setColors(*ColorTemplate.VORDIPLOM_COLORS) + @Suppress("UNCHECKED_CAST") + (dataSets[0] as LineDataSet).setCircleColors(*ColorTemplate.VORDIPLOM_COLORS) val data = LineData(dataSets) binding.chart1.data = data @@ -264,7 +268,7 @@ class MultiLineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartGestu Timber.i("dX: $dX, dY: $dY") } - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entry: BaseEntry, highlight: Highlight) { Timber.i("Value: ${entry.y}, xIndex: ${entry.x}, DataSet index: ${highlight.dataSetIndex}") } diff --git a/app/src/main/kotlin/info/appdev/chartexample/PieChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/PieChartActivity.kt index 79ce3a361..09d1161af 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/PieChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/PieChartActivity.kt @@ -22,7 +22,7 @@ import info.appdev.chartexample.databinding.ActivityPiechartBinding import info.appdev.chartexample.notimportant.DemoBase import info.appdev.charting.animation.Easing import info.appdev.charting.components.Legend -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.PieData import info.appdev.charting.data.PieDataSet import info.appdev.charting.data.PieEntry @@ -271,7 +271,7 @@ class PieChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect return s } - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entry: BaseEntry, highlight: Highlight) { Timber.i("Value: ${entry.y}, xIndex: ${entry.x}, DataSet index: ${highlight.dataSetIndex}") } diff --git a/app/src/main/kotlin/info/appdev/chartexample/PieChartRoundedActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/PieChartRoundedActivity.kt index db9de95ef..77b90c7f2 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/PieChartRoundedActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/PieChartRoundedActivity.kt @@ -22,7 +22,7 @@ import info.appdev.chartexample.databinding.ActivityPiechartBinding import info.appdev.chartexample.notimportant.DemoBase import info.appdev.charting.animation.Easing import info.appdev.charting.components.Legend -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.PieData import info.appdev.charting.data.PieDataSet import info.appdev.charting.data.PieEntry @@ -275,7 +275,7 @@ class PieChartRoundedActivity : DemoBase(), OnSeekBarChangeListener, OnChartValu return s } - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entry: BaseEntry, highlight: Highlight) { Timber.i("Value: ${entry.y}, xIndex: ${entry.x}, DataSet index: ${highlight.dataSetIndex}") } diff --git a/app/src/main/kotlin/info/appdev/chartexample/PiePolylineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/PiePolylineChartActivity.kt index f3cf3b781..662c8cc41 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/PiePolylineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/PiePolylineChartActivity.kt @@ -21,7 +21,7 @@ import info.appdev.chartexample.databinding.ActivityPiechartBinding import info.appdev.chartexample.notimportant.DemoBase import info.appdev.charting.animation.Easing import info.appdev.charting.components.Legend -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.PieData import info.appdev.charting.data.PieDataSet import info.appdev.charting.data.PieEntry @@ -257,7 +257,7 @@ class PiePolylineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartVal return s } - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entry: BaseEntry, highlight: Highlight) { Timber.i("Value: ${entry.y}, xIndex: ${entry.x}, DataSet index: ${highlight.dataSetIndex}") } diff --git a/app/src/main/kotlin/info/appdev/chartexample/RealtimeLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/RealtimeLineChartActivity.kt index 765581ca6..d2cd3a86b 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/RealtimeLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/RealtimeLineChartActivity.kt @@ -15,6 +15,7 @@ import info.appdev.chartexample.databinding.ActivityRealtimeLinechartBinding import info.appdev.chartexample.notimportant.DemoBase import info.appdev.charting.components.Legend.LegendForm import info.appdev.charting.components.YAxis.AxisDependency +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.Entry import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet @@ -112,8 +113,8 @@ class RealtimeLineChartActivity : DemoBase(), OnChartValueSelectedListener { // AxisDependency.LEFT); } - private fun createSet(): LineDataSet { - val set = LineDataSet(label = "Dynamic Data") + private fun createSet(): LineDataSet, Float> { + val set = LineDataSet, Float>(label = "Dynamic Data") set.axisDependency = AxisDependency.LEFT set.color = ColorTemplate.holoBlue set.setCircleColor(Color.WHITE) @@ -194,7 +195,7 @@ class RealtimeLineChartActivity : DemoBase(), OnChartValueSelectedListener { saveToGallery(binding.chart1, "RealtimeLineChartActivity") } - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entry: BaseEntry, highlight: Highlight) { Timber.i(entry.toString()) } diff --git a/app/src/main/kotlin/info/appdev/chartexample/ScatterChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/ScatterChartActivity.kt index bf4ba14c6..9f6699d33 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/ScatterChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/ScatterChartActivity.kt @@ -16,6 +16,7 @@ import info.appdev.chartexample.databinding.ActivityScatterchartBinding import info.appdev.chartexample.notimportant.DemoBase import info.appdev.charting.charts.ScatterChart import info.appdev.charting.components.Legend +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.Entry import info.appdev.charting.data.ScatterData import info.appdev.charting.data.ScatterDataSet @@ -191,7 +192,7 @@ class ScatterChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSe saveToGallery(binding.chart1, "ScatterChartActivity") } - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entry: BaseEntry, highlight: Highlight) { Timber.i("Value: ${entry.y}, xIndex: ${entry.x}, DataSet index: ${highlight.dataSetIndex}") } diff --git a/app/src/main/kotlin/info/appdev/chartexample/SpecificPositionsLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/SpecificPositionsLineChartActivity.kt index a5fa1ef75..90107a026 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/SpecificPositionsLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/SpecificPositionsLineChartActivity.kt @@ -20,6 +20,7 @@ import info.appdev.charting.animation.Easing import info.appdev.charting.components.Legend.LegendForm import info.appdev.charting.components.LimitLine import info.appdev.charting.components.LimitLine.LimitLabelPosition +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.Entry import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet @@ -143,7 +144,8 @@ class SpecificPositionsLineChartActivity : DemoBase(), OnSeekBarChangeListener, R.id.actionToggleFilled -> { binding.chart1.data?.dataSets?.forEach { - val set = it as LineDataSet + @Suppress("UNCHECKED_CAST") + val set = it as LineDataSet set.isDrawFilled = !set.isDrawFilled } binding.chart1.invalidate() @@ -151,7 +153,8 @@ class SpecificPositionsLineChartActivity : DemoBase(), OnSeekBarChangeListener, R.id.actionToggleCircles -> { binding.chart1.data?.dataSets?.forEach { - val set = it as LineDataSet + @Suppress("UNCHECKED_CAST") + val set = it as LineDataSet set.isDrawCircles = !set.isDrawCircles } binding.chart1.invalidate() @@ -159,7 +162,8 @@ class SpecificPositionsLineChartActivity : DemoBase(), OnSeekBarChangeListener, R.id.actionToggleCubic -> { binding.chart1.data?.dataSets?.forEach { - val set = it as LineDataSet + @Suppress("UNCHECKED_CAST") + val set = it as LineDataSet set.lineMode = if (set.lineMode == LineDataSet.Mode.CUBIC_BEZIER) LineDataSet.Mode.LINEAR else LineDataSet.Mode.CUBIC_BEZIER } binding.chart1.invalidate() @@ -167,7 +171,8 @@ class SpecificPositionsLineChartActivity : DemoBase(), OnSeekBarChangeListener, R.id.actionToggleStepped -> { binding.chart1.data?.dataSets?.forEach { - val set = it as LineDataSet + @Suppress("UNCHECKED_CAST") + val set = it as LineDataSet set.lineMode = if (set.lineMode == LineDataSet.Mode.STEPPED) LineDataSet.Mode.LINEAR else LineDataSet.Mode.STEPPED } binding.chart1.invalidate() @@ -175,7 +180,8 @@ class SpecificPositionsLineChartActivity : DemoBase(), OnSeekBarChangeListener, R.id.actionToggleHorizontalCubic -> { binding.chart1.data?.dataSets?.forEach { - val set = it as LineDataSet + @Suppress("UNCHECKED_CAST") + val set = it as LineDataSet set.lineMode = if (set.lineMode == LineDataSet.Mode.HORIZONTAL_BEZIER) LineDataSet.Mode.LINEAR else LineDataSet.Mode.HORIZONTAL_BEZIER } binding.chart1.invalidate() @@ -234,7 +240,8 @@ class SpecificPositionsLineChartActivity : DemoBase(), OnSeekBarChangeListener, } binding.chart1.data?.let { if (it.dataSetCount > 0) { - val set1 = it.getDataSetByIndex(0) as LineDataSet + @Suppress("UNCHECKED_CAST") + val set1 = it.getDataSetByIndex(0) as LineDataSet set1.entries = values it.notifyDataChanged() binding.chart1.notifyDataSetChanged() @@ -269,7 +276,7 @@ class SpecificPositionsLineChartActivity : DemoBase(), OnSeekBarChangeListener, } else { set11.fillColor = Color.BLACK } - val dataSets = ArrayList() + val dataSets = ArrayList, Float>>() dataSets.add(set11) // add the datasets // create a data object with the datasets @@ -316,7 +323,7 @@ class SpecificPositionsLineChartActivity : DemoBase(), OnSeekBarChangeListener, Timber.i("dX: $dX, dY: $dY") } - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entry: BaseEntry, highlight: Highlight) { Timber.i(entry.toString()) Timber.i("LOWHIGH low: ${binding.chart1.lowestVisibleX}, high: ${binding.chart1.highestVisibleX}") Timber.i("MIN MAX xmin: ${binding.chart1.xChartMin}, xmax: ${binding.chart1.xChartMax}, ymin: ${binding.chart1.yChartMin}, ymax: ${binding.chart1.yChartMax}") diff --git a/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivity.kt index 21c5bcbfe..0056212a2 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivity.kt @@ -22,7 +22,7 @@ import info.appdev.charting.components.XAxis.XAxisPosition import info.appdev.charting.data.BarData import info.appdev.charting.data.BarDataSet import info.appdev.charting.data.BarEntry -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.highlight.Highlight import info.appdev.charting.interfaces.datasets.IBarDataSet import info.appdev.charting.listener.OnChartValueSelectedListener @@ -219,7 +219,7 @@ class StackedBarActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSele override fun onStopTrackingTouch(seekBar: SeekBar?) = Unit - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entry: BaseEntry, highlight: Highlight) { val barEntry = entry as BarEntry if (barEntry.yVals != null) diff --git a/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivityNegative.kt b/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivityNegative.kt index accf2d40b..b8ae53168 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivityNegative.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivityNegative.kt @@ -19,7 +19,7 @@ import info.appdev.charting.components.YAxis import info.appdev.charting.data.BarData import info.appdev.charting.data.BarDataSet import info.appdev.charting.data.BarEntry -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.formatter.IAxisValueFormatter import info.appdev.charting.formatter.IValueFormatter import info.appdev.charting.highlight.Highlight @@ -194,7 +194,7 @@ class StackedBarActivityNegative : DemoBase(), OnChartValueSelectedListener { saveToGallery(binding.chart1, "StackedBarActivityNegative") } - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entry: BaseEntry, highlight: Highlight) { val barEntry = entry as BarEntry Timber.i("Value: ${abs(barEntry.yVals!![highlight.stackIndex])}") } @@ -205,7 +205,7 @@ class StackedBarActivityNegative : DemoBase(), OnChartValueSelectedListener { private val decimalFormat: DecimalFormat = DecimalFormat("###") // data - override fun getFormattedValue(value: Float, entry: Entry?, dataSetIndex: Int, viewPortHandler: ViewPortHandler?): String { + override fun getFormattedValue(value: Float, entry: BaseEntry?, dataSetIndex: Int, viewPortHandler: ViewPortHandler?): String { return decimalFormat.format(abs(value).toDouble()) + "m" } diff --git a/app/src/main/kotlin/info/appdev/chartexample/TimeLineActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/TimeLineActivity.kt index 3da017b75..f67192e41 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/TimeLineActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/TimeLineActivity.kt @@ -15,6 +15,7 @@ import info.appdev.charting.components.Description import info.appdev.charting.components.Legend.LegendForm import info.appdev.charting.components.XAxis.XAxisPosition import info.appdev.charting.components.YAxis +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.Entry import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet @@ -87,14 +88,15 @@ class TimeLineActivity : DemoBase() { val sampleEntries = generateSineWaves(3, 30) .mapIndexed { index, data -> - val valueY = (data.toFloat() * range) + 50 - Entry(timeOffset + index.toFloat() * 1000, valueY) + val valueY = (data * range) + 50 + Entry((timeOffset + index * 1000.0).toFloat(), valueY.toFloat()) }.toMutableList() - val set1: LineDataSet + var set1: LineDataSet if (binding.chart1.lineData.dataSetCount > 0) { - set1 = binding.chart1.lineData.getDataSetByIndex(0) as LineDataSet + @Suppress("UNCHECKED_CAST") + set1 = binding.chart1.lineData.getDataSetByIndex(0) as LineDataSet set1.entries = sampleEntries binding.chart1.lineData.notifyDataChanged() binding.chart1.notifyDataSetChanged() @@ -113,14 +115,14 @@ class TimeLineActivity : DemoBase() { set1.highLightColor = Color.rgb(244, 117, 117) set1.isDrawCircleHoleEnabled = false set1.fillFormatter = object : IFillFormatter { - override fun getFillLinePosition(dataSet: ILineDataSet?, dataProvider: LineDataProvider): Float { + override fun getFillLinePosition(dataSet: ILineDataSet, Float>?, dataProvider: LineDataProvider): Float { // change the return value here to better understand the effect // return 0; return binding.chart1.axisLeft.axisMinimum } } - val dataSets = ArrayList() + val dataSets = ArrayList, Float>>() dataSets.add(set1) // add the data sets // create a data object with the data sets @@ -159,8 +161,9 @@ class TimeLineActivity : DemoBase() { withContext(Dispatchers.Default) { while (menuItemMove!!.isChecked) { withContext(Dispatchers.Main) { - binding.chart1.lineData.dataSets.get(0)?.let { set -> - (set as LineDataSet).entries.moveFirstToLast() + binding.chart1.lineData.dataSets[0].let { set -> + @Suppress("UNCHECKED_CAST") + (set as LineDataSet).entries.moveFirstToLast() set.notifyDataChanged() binding.chart1.lineData.notifyDataChanged() binding.chart1.notifyDataSetChanged() diff --git a/app/src/main/kotlin/info/appdev/chartexample/compose/HorizontalBarComposeActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/compose/HorizontalBarComposeActivity.kt index af8d6733d..8c93ef31c 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/compose/HorizontalBarComposeActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/compose/HorizontalBarComposeActivity.kt @@ -45,7 +45,7 @@ import info.appdev.charting.components.XAxis.XAxisPosition import info.appdev.charting.data.BarData import info.appdev.charting.data.BarDataSet import info.appdev.charting.data.BarEntry -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.highlight.Highlight import info.appdev.charting.interfaces.datasets.IBarDataSet import info.appdev.charting.listener.OnChartValueSelectedListener @@ -268,7 +268,7 @@ class HorizontalBarComposeActivity : DemoBaseCompose() { private fun setupChart(chart: HorizontalBarChart) { chart.setOnChartValueSelectedListener(object : OnChartValueSelectedListener { - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entry: BaseEntry, highlight: Highlight) { val bounds = RectF() chart.getBarBounds(entry as BarEntry, bounds) diff --git a/app/src/main/kotlin/info/appdev/chartexample/formatter/MyFillFormatter.kt b/app/src/main/kotlin/info/appdev/chartexample/formatter/MyFillFormatter.kt index 808db2daf..11766efd7 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/formatter/MyFillFormatter.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/formatter/MyFillFormatter.kt @@ -1,12 +1,13 @@ package info.appdev.chartexample.formatter +import info.appdev.charting.data.BaseEntry import info.appdev.charting.formatter.IFillFormatter import info.appdev.charting.interfaces.dataprovider.LineDataProvider import info.appdev.charting.interfaces.datasets.ILineDataSet @Suppress("unused") class MyFillFormatter(private val fillPos: Float) : IFillFormatter { - override fun getFillLinePosition(dataSet: ILineDataSet?, dataProvider: LineDataProvider): Float { + override fun getFillLinePosition(dataSet: ILineDataSet, Float>?, dataProvider: LineDataProvider): Float { // your logic could be here return fillPos } diff --git a/app/src/main/kotlin/info/appdev/chartexample/formatter/MyValueFormatter.kt b/app/src/main/kotlin/info/appdev/chartexample/formatter/MyValueFormatter.kt index a32ce5413..f9335ae2e 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/formatter/MyValueFormatter.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/formatter/MyValueFormatter.kt @@ -1,6 +1,6 @@ package info.appdev.chartexample.formatter -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.formatter.IValueFormatter import info.appdev.charting.utils.ViewPortHandler import java.text.DecimalFormat @@ -8,7 +8,7 @@ import java.text.DecimalFormat class MyValueFormatter : IValueFormatter { private val decimalFormat = DecimalFormat("###,###,###,##0.0") - override fun getFormattedValue(value: Float, entry: Entry?, dataSetIndex: Int, viewPortHandler: ViewPortHandler?): String { + override fun getFormattedValue(value: Float, entry: BaseEntry?, dataSetIndex: Int, viewPortHandler: ViewPortHandler?): String { return decimalFormat.format(value.toDouble()) + " $" } } 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 6a9053ea5..0dc3d9d1d 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/fragments/SimpleFragment.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/fragments/SimpleFragment.kt @@ -12,6 +12,7 @@ import info.appdev.charting.charts.ScatterChart.ScatterShape import info.appdev.charting.data.BarData import info.appdev.charting.data.BarDataSet import info.appdev.charting.data.BarEntry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.Entry import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet @@ -21,7 +22,6 @@ import info.appdev.charting.data.PieEntry import info.appdev.charting.data.ScatterData import info.appdev.charting.data.ScatterDataSet import info.appdev.charting.interfaces.datasets.IBarDataSet -import info.appdev.charting.interfaces.datasets.ILineDataSet import info.appdev.charting.interfaces.datasets.IScatterDataSet import info.appdev.charting.utils.ColorTemplate import info.appdev.charting.utils.loadEntriesFromAssets @@ -111,7 +111,7 @@ abstract class SimpleFragment : Fragment() { } protected fun generateLineData(): LineData { - val sets = ArrayList() + val sets = ArrayList, Float>>() val ds1 = LineDataSet(requireContext().assets.loadEntriesFromAssets("sine.txt"), "Sine function") val ds2 = LineDataSet(requireContext().assets.loadEntriesFromAssets("cosine.txt"), "Cosine function") @@ -128,14 +128,14 @@ abstract class SimpleFragment : Fragment() { sets.add(ds1) sets.add(ds2) - val d = LineData(sets) + val d = LineData(sets.toMutableList()) d.setValueTypeface(tf) return d } protected val complexity: LineData get() { - val sets = ArrayList() + val sets = ArrayList, Float>>() val ds1 = LineDataSet(requireContext().assets.loadEntriesFromAssets("n.txt"), "O(n)") val ds2 = LineDataSet(requireContext().assets.loadEntriesFromAssets("nlogn.txt"), "O(nlogn)") @@ -168,7 +168,7 @@ abstract class SimpleFragment : Fragment() { sets.add(ds3) sets.add(ds4) - val d = LineData(sets) + val d = LineData(sets.toMutableList()) d.setValueTypeface(tf) return d } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/charts/BarLineChartBase.kt b/chartLib/src/main/kotlin/info/appdev/charting/charts/BarLineChartBase.kt index 7d9f37ca9..d57f16da6 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/charts/BarLineChartBase.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/charts/BarLineChartBase.kt @@ -16,6 +16,7 @@ import info.appdev.charting.components.XAxis.XAxisPosition import info.appdev.charting.components.YAxis import info.appdev.charting.components.YAxis.AxisDependency import info.appdev.charting.data.BarLineScatterCandleBubbleData +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.Entry import info.appdev.charting.highlight.ChartHighlighter import info.appdev.charting.interfaces.dataprovider.base.BarLineScatterCandleBubbleDataProvider @@ -46,7 +47,7 @@ import kotlin.math.min */ @Suppress("unused") @SuppressLint("RtlHardcoded") -abstract class BarLineChartBase>> : Chart, +abstract class BarLineChartBase, Float>>> : Chart, BarLineScatterCandleBubbleDataProvider { /** * the maximum number of entries to which values will be drawn @@ -1083,7 +1084,7 @@ abstract class BarLineChartBase? { val highlight = getHighlightByTouchPoint(x, y) if (highlight != null) { return mData!!.getEntryForHighlight(highlight) @@ -1094,7 +1095,7 @@ abstract class BarLineChartBase? { + fun getDataSetByTouchPoint(x: Float, y: Float): IBarLineScatterCandleBubbleDataSet<*, *>? { val highlight = getHighlightByTouchPoint(x, y) if (highlight != null) { return mData!!.getDataSetByIndex(highlight.dataSetIndex) diff --git a/chartLib/src/main/kotlin/info/appdev/charting/charts/Chart.kt b/chartLib/src/main/kotlin/info/appdev/charting/charts/Chart.kt index 88c08fc3b..fa0521a7b 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/charts/Chart.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/charts/Chart.kt @@ -22,6 +22,7 @@ import info.appdev.charting.components.Description import info.appdev.charting.components.IMarker import info.appdev.charting.components.Legend import info.appdev.charting.components.XAxis +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.ChartData import info.appdev.charting.data.Entry import info.appdev.charting.formatter.DefaultValueFormatter @@ -49,7 +50,7 @@ import kotlin.math.abs import kotlin.math.max @Suppress("unused") -abstract class Chart>> : ViewGroup, IBaseProvider { +abstract class Chart, Float>>> : ViewGroup, IBaseProvider { /** * Returns true if log-output is enabled for the chart, fals if not. */ @@ -527,7 +528,7 @@ abstract class Chart>> : ViewGroup, IBaseP */ fun highlightValue(high: Highlight?, callListener: Boolean) { var high = high - var entry: Entry? = null + var entry: BaseEntry? = null if (high == null) { this.highlighted = null @@ -554,7 +555,7 @@ abstract class Chart>> : ViewGroup, IBaseP mSelectionListener!!.onNothingSelected() } else { // notify the listener - mSelectionListener!!.onValueSelected(entry!!, high!!) + mSelectionListener!!.onValueSelected(entry!! as Entry, high!!) } } @@ -613,7 +614,7 @@ abstract class Chart>> : ViewGroup, IBaseP // When changing data sets and calling animation functions, sometimes an erroneous highlight is generated // on the dataset that is removed. Null check to prevent crash - val dataset: IDataSet<*>? = mData!!.getDataSetByIndex(highlight.dataSetIndex) + val dataset: IDataSet<*, *>? = mData!!.getDataSetByIndex(highlight.dataSetIndex) if (dataset == null || !dataset.isVisible) { continue } @@ -624,7 +625,7 @@ abstract class Chart>> : ViewGroup, IBaseP // Cast to non-star-projected type to allow calling getEntryIndex @Suppress("UNCHECKED_CAST") - val set = dataset as IDataSet + val set = dataset as IDataSet, Float> val entryIndex = set.getEntryIndex(e) if (entryIndex > set.entryCount * mAnimator.phaseX) { @@ -642,7 +643,7 @@ abstract class Chart>> : ViewGroup, IBaseP if (!marker.isEmpty()) { val markerIndex = i % marker.size val markerItem = marker[markerIndex] - markerItem.refreshContent(e, highlight) + markerItem.refreshContent(e as Entry, highlight) // draw the marker markerItem.draw(canvas, pos[0], pos[1]) diff --git a/chartLib/src/main/kotlin/info/appdev/charting/charts/CombinedChart.kt b/chartLib/src/main/kotlin/info/appdev/charting/charts/CombinedChart.kt index 013bfc881..d20f570fd 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/charts/CombinedChart.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/charts/CombinedChart.kt @@ -4,10 +4,10 @@ import android.content.Context import android.graphics.Canvas import android.util.AttributeSet import info.appdev.charting.data.BarData +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.BubbleData import info.appdev.charting.data.CandleData import info.appdev.charting.data.CombinedData -import info.appdev.charting.data.Entry import info.appdev.charting.data.LineData import info.appdev.charting.data.ScatterData import info.appdev.charting.highlight.CombinedHighlighter @@ -488,7 +488,7 @@ open class CombinedChart : BarLineChartBase, CombinedDataProvider } @Suppress("UNCHECKED_CAST") - val set = dataset as IDataSet + val set = dataset as IDataSet, Float> val entryIndex = set.getEntryIndex(entry) // make sure entry not null diff --git a/chartLib/src/main/kotlin/info/appdev/charting/charts/PieRadarChartBase.kt b/chartLib/src/main/kotlin/info/appdev/charting/charts/PieRadarChartBase.kt index 0ba8785fd..433c95c5c 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/charts/PieRadarChartBase.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/charts/PieRadarChartBase.kt @@ -9,8 +9,8 @@ import info.appdev.charting.animation.Easing.EasingFunction import info.appdev.charting.components.Legend.LegendHorizontalAlignment import info.appdev.charting.components.Legend.LegendOrientation import info.appdev.charting.components.Legend.LegendVerticalAlignment +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.ChartData -import info.appdev.charting.data.Entry import info.appdev.charting.interfaces.datasets.IDataSet import info.appdev.charting.listener.PieRadarChartTouchListener import info.appdev.charting.utils.PointF @@ -30,7 +30,7 @@ import kotlin.math.sqrt /** * Baseclass of PieChart and RadarChart. */ -abstract class PieRadarChartBase>> +abstract class PieRadarChartBase, Float>>> : Chart { /** * holds the normalized version of the current rotation angle of the chart diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/BarDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/BarDataSet.kt index db79610ff..022b359c2 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/BarDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/BarDataSet.kt @@ -5,7 +5,7 @@ import androidx.annotation.ColorInt import info.appdev.charting.interfaces.datasets.IBarDataSet import info.appdev.charting.utils.Fill -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 @@ -50,7 +50,7 @@ open class BarDataSet(yVals: MutableList, label: String) : BarLineScat calcEntryCountIncludingStacks(yVals) } - override fun copy(): DataSet? { + override fun copy(): DataSet? { val entries: MutableList = mutableListOf() for (i in mEntries.indices) { entries.add(mEntries[i].copy()) @@ -61,7 +61,7 @@ open class BarDataSet(yVals: MutableList, label: String) : BarLineScat } protected fun copy(barDataSet: BarDataSet) { - super.copy((barDataSet as BaseDataSet<*>?)!!) + super.copy((barDataSet as BaseDataSet<*, *>?)!!) barDataSet.mStackSize = mStackSize barDataSet.mBarShadowColor = mBarShadowColor barDataSet.mBarBorderWidth = mBarBorderWidth diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleData.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleData.kt index 96c08ef04..f50c7b44d 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleData.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleData.kt @@ -7,8 +7,8 @@ import info.appdev.charting.interfaces.datasets.IDataSet * Baseclass for all Line, Bar, Scatter, Candle and Bubble data. */ abstract class BarLineScatterCandleBubbleData : ChartData<@UnsafeVariance T> - where T : IDataSet, - T : IBarLineScatterCandleBubbleDataSet { + where T : IDataSet, Float>, + T : IBarLineScatterCandleBubbleDataSet, Float> { constructor() : super() diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleDataSet.kt index 2751e4703..cc6d8b32c 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleDataSet.kt @@ -7,16 +7,16 @@ import info.appdev.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataS /** * Baseclass of all DataSets for Bar-, Line-, Scatter- and CandleStickChart. */ -abstract class BarLineScatterCandleBubbleDataSet>(yVals: MutableList, label: String) : - DataSet(yVals, label), IBarLineScatterCandleBubbleDataSet { +abstract class BarLineScatterCandleBubbleDataSet(yVals: MutableList, label: String) : + DataSet(yVals, label), IBarLineScatterCandleBubbleDataSet where T : BaseEntry, N : Number, N : Comparable { /** * Sets the color that is used for drawing the highlight indicators. */ @ColorInt override var highLightColor: Int = Color.rgb(255, 187, 115) - protected fun copy(barLineScatterCandleBubbleDataSet: BarLineScatterCandleBubbleDataSet<*>) { - super.copy((barLineScatterCandleBubbleDataSet as BaseDataSet<*>?)!!) + protected fun copy(barLineScatterCandleBubbleDataSet: BarLineScatterCandleBubbleDataSet<*, *>) { + super.copy((barLineScatterCandleBubbleDataSet as BaseDataSet<*, *>?)!!) barLineScatterCandleBubbleDataSet.highLightColor = this.highLightColor } } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/BaseDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/BaseDataSet.kt index a743b0d3b..0c6943e7f 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/BaseDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/BaseDataSet.kt @@ -19,7 +19,7 @@ import info.appdev.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 where T : BaseEntry, N : Number, N : Comparable { /** * List representing all colors that are used for this DataSet */ @@ -351,7 +351,7 @@ abstract class BaseDataSet>() : IDataSet { return false } - protected fun copy(baseDataSet: BaseDataSet<*>) { + protected fun copy(baseDataSet: BaseDataSet<*, *>) { baseDataSet.mAxisDependency = mAxisDependency baseDataSet.mColors = mColors baseDataSet.mDrawIcons = mDrawIcons diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/BubbleDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/BubbleDataSet.kt index 07f229a2c..8426a6797 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/BubbleDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/BubbleDataSet.kt @@ -3,7 +3,7 @@ package info.appdev.charting.data import info.appdev.charting.interfaces.datasets.IBubbleDataSet import info.appdev.charting.utils.convertDpToPixel -open class BubbleDataSet(yVals: MutableList, label: String) : BarLineScatterCandleBubbleDataSet(yVals, label), IBubbleDataSet { +open class BubbleDataSet(yVals: MutableList, label: String) : BarLineScatterCandleBubbleDataSet(yVals, label), IBubbleDataSet { protected var mMaxSize: Float = 0f protected var mNormalizeSize: Boolean = true @@ -19,7 +19,7 @@ open class BubbleDataSet(yVals: MutableList, label: String) : BarLi } } - override fun copy(): DataSet { + override fun copy(): DataSet { val entries: MutableList = ArrayList() for (i in mEntries.indices) { entries.add(mEntries[i].copy()) diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/CandleDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/CandleDataSet.kt index 85e5b8bf1..5667d29db 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/CandleDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/CandleDataSet.kt @@ -9,7 +9,7 @@ import info.appdev.charting.utils.convertDpToPixel /** * DataSet for the CandleStickChart. */ -open class CandleDataSet(yVals: MutableList, label: String = "") : LineScatterCandleRadarDataSet(yVals, label), ICandleDataSet { +open class CandleDataSet(yVals: MutableList, label: String = "") : LineScatterCandleRadarDataSet(yVals, label), ICandleDataSet { /** * the width of the shadow of the candle */ @@ -69,7 +69,7 @@ open class CandleDataSet(yVals: MutableList, label: String = "") : @ColorInt protected var mShadowColor: Int = ColorTemplate.COLOR_SKIP - override fun copy(): DataSet { + override fun copy(): DataSet { val entries: MutableList = mutableListOf() for (i in mEntries.indices) { entries.add(mEntries[i].copy()) @@ -81,7 +81,7 @@ open class CandleDataSet(yVals: MutableList, label: String = "") : } protected fun copy(candleDataSet: CandleDataSet) { - super.copy((candleDataSet as BaseDataSet<*>?)!!) + super.copy((candleDataSet as BaseDataSet<*, *>?)!!) candleDataSet.mShadowWidth = mShadowWidth candleDataSet.mShowCandleBar = mShowCandleBar candleDataSet.mBarSpace = mBarSpace diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/ChartData.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/ChartData.kt index 44dc7203a..b3ff63df0 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/ChartData.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/ChartData.kt @@ -12,7 +12,7 @@ import java.io.Serializable * Class that holds all relevant data that represents the chart. That involves at least one (or more) DataSets, and an array of x-values. */ @Suppress("unused") -abstract class ChartData> : Serializable { +abstract class ChartData : Serializable where T : IDataSet, Float> { /** * maximum y-value in the value array across all axes */ @@ -243,7 +243,7 @@ abstract class ChartData> : Serializable { * Get the Entry for a corresponding highlight object * @return the entry that is highlighted */ - open fun getEntryForHighlight(highlight: Highlight): Entry? { + open fun getEntryForHighlight(highlight: Highlight): BaseEntry? { return if (highlight.dataSetIndex >= dataSets.size) { null } else { @@ -331,7 +331,7 @@ abstract class ChartData> : Serializable { val set: T = dataSets[dataSetIndex] // add the entry to the dataset // We need to cast here because T is covariant (out) but addEntry needs to consume T - val dataSet = set as IDataSet + val dataSet = set as IDataSet if (!dataSet.addEntry(entry)) { return } @@ -416,7 +416,7 @@ abstract class ChartData> : Serializable { * Removes the given Entry object from the DataSet at the specified index. */ @Suppress("UNCHECKED_CAST") - open fun removeEntry(entry: Entry, dataSetIndex: Int): Boolean { + open fun removeEntry(entry: BaseEntry, dataSetIndex: Int): Boolean { // entry null, out of bounds if (dataSetIndex >= dataSets.size) { return false @@ -425,7 +425,7 @@ abstract class ChartData> : Serializable { val set: T = dataSets[dataSetIndex] // remove the entry from the dataset - val dataSet = set as IDataSet + val dataSet = set as IDataSet, Float> val removed: Boolean = dataSet.removeEntry(entry) if (removed) { @@ -445,7 +445,7 @@ abstract class ChartData> : Serializable { return false } - val dataSet: IDataSet<*> = dataSets[dataSetIndex] + val dataSet: IDataSet<*, *> = dataSets[dataSetIndex] val entry = dataSet.getEntryForXValue(xValue, Float.NaN) as? Entry ?: return false return removeEntry(entry, dataSetIndex) @@ -459,7 +459,7 @@ abstract class ChartData> : Serializable { val set = dataSets[i] for (j in 0..>() { +class CombinedData : BarLineScatterCandleBubbleData, Float>>() { var lineData: LineData? = null private set var barData: BarData? = null @@ -145,7 +145,7 @@ class CombinedData : BarLineScatterCandleBubbleData? { + fun getDataSetByHighlight(highlight: Highlight): IBarLineScatterCandleBubbleDataSet, Float>? { if (highlight.dataIndex >= this.allData.size) return null @@ -165,14 +165,14 @@ class CombinedData : BarLineScatterCandleBubbleData= data.dataSetCount) return null - return data.dataSets[highlight.dataSetIndex] as IBarLineScatterCandleBubbleDataSet? + return data.dataSets[highlight.dataSetIndex] as IBarLineScatterCandleBubbleDataSet, Float>? } fun getDataIndex(data: ChartData<*>?): Int { return this.allData.indexOf(data) } - override fun removeDataSet(d: IBarLineScatterCandleBubbleDataSet?): Boolean { + override fun removeDataSet(d: IBarLineScatterCandleBubbleDataSet, Float>?): Boolean { val datas = this.allData var success = false @@ -195,7 +195,7 @@ class CombinedData : BarLineScatterCandleBubbleData, dataSetIndex: Int): Boolean { Timber.e("removeEntry(...) not supported for CombinedData") return false } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/DataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/DataSet.kt index 49db36fea..a17c82755 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/DataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/DataSet.kt @@ -10,10 +10,10 @@ import kotlin.math.abs * 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>( +abstract class DataSet( protected var mEntries: MutableList, label: String = "" -) : BaseDataSet(label), Serializable { +) : BaseDataSet(label), Serializable where T : BaseEntry, N : Number, N : Comparable { /** * maximum y-value in the value array */ @@ -93,22 +93,24 @@ abstract class DataSet>( } protected fun calcMinMaxX(entry: T) { - if (entry.x < this.xMin) { - this.xMin = entry.x + val entryX = entry.x.toFloat() + if (entryX < this.xMin) { + this.xMin = entryX } - if (entry.x > this.xMax) { - this.xMax = entry.x + if (entryX > this.xMax) { + this.xMax = entryX } } protected open fun calcMinMaxY(entry: T) { - if (entry.y < this.yMin) { - this.yMin = entry.y + val entryY = entry.y.toFloat() + if (entryY < this.yMin) { + this.yMin = entryY } - if (entry.y > this.yMax) { - this.yMax = entry.y + if (entryY > this.yMax) { + this.yMax = entryY } } @@ -128,9 +130,9 @@ abstract class DataSet>( /** * Provides an exact copy of the DataSet this method is used on. */ - abstract fun copy(): DataSet? + abstract fun copy(): DataSet? - protected fun copy(dataSet: DataSet<*>) { + protected fun copy(dataSet: DataSet<*, *>) { super.copy(dataSet) } @@ -151,8 +153,8 @@ abstract class DataSet>( override fun addEntryOrdered(entry: T) { calcMinMax(entry) - if (!mEntries.isEmpty() && mEntries[mEntries.size - 1].x > entry.x) { - val closestIndex = getEntryIndex(entry.x, entry.y, Rounding.UP) + if (!mEntries.isEmpty() && mEntries[mEntries.size - 1].x.toFloat() > entry.x.toFloat()) { + val closestIndex = getEntryIndex(entry.x.toFloat(), entry.y.toFloat(), Rounding.UP) mEntries.add(closestIndex, entry) } else { mEntries.add(entry) @@ -223,8 +225,8 @@ abstract class DataSet>( val nextEntry: T = mEntries[m + 1] - val d1 = currentEntry.x - xValue - val d2 = nextEntry.x - xValue + val d1 = currentEntry.x.toFloat() - xValue + val d2 = nextEntry.x.toFloat() - xValue val ad1 = abs(d1) val ad2 = abs(d2) @@ -252,7 +254,7 @@ abstract class DataSet>( } val closestEntry: T = mEntries[closest] - val closestXValue = closestEntry.x + val closestXValue = closestEntry.x.toFloat() 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) { @@ -267,11 +269,11 @@ abstract class DataSet>( // Search by closest to y-value if (!closestToY.isNaN()) { - while (closest > 0 && mEntries[closest - 1].x == closestXValue) { + while (closest > 0 && mEntries[closest - 1].x.toFloat() == closestXValue) { closest -= 1 } - var closestYValue = closestEntry.y + var closestYValue = closestEntry.y.toFloat() var closestYIndex = closest while (true) { @@ -282,11 +284,11 @@ abstract class DataSet>( val value: T = mEntries[closest] - if (value.x != closestXValue) { + if (value.x.toFloat() != closestXValue) { break } - if (abs(value.y - closestToY) <= abs(closestYValue - closestToY)) { + if (abs(value.y.toFloat() - closestToY) <= abs(closestYValue - closestToY)) { closestYValue = closestToY closestYIndex = closest } @@ -308,8 +310,8 @@ abstract class DataSet>( var entry = mEntries[m] // if we have a match - if (xValue == entry.x) { - while (m > 0 && mEntries[m - 1].x == xValue) { + if (xValue == entry.x.toFloat()) { + while (m > 0 && mEntries[m - 1].x.toFloat() == xValue) { m-- } @@ -318,7 +320,7 @@ abstract class DataSet>( // loop over all "equal" entries while (m < high) { entry = mEntries[m] - if (entry.x == xValue) { + if (entry.x.toFloat() == xValue) { entries.add(entry) } else { break @@ -328,7 +330,7 @@ abstract class DataSet>( break } else { - if (xValue > entry.x) { + if (xValue > entry.x.toFloat()) { low = m + 1 } else { high = m - 1 diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/LineData.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/LineData.kt index 4736b2021..6453823eb 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/LineData.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/LineData.kt @@ -5,10 +5,10 @@ import info.appdev.charting.interfaces.datasets.ILineDataSet /** * Data object that encapsulates all data associated with a LineChart. */ -class LineData : BarLineScatterCandleBubbleData { +class LineData : BarLineScatterCandleBubbleData, Float>> { constructor() : super() - constructor(vararg dataSets: ILineDataSet) : super(*dataSets) + constructor(vararg dataSets: ILineDataSet, Float>) : super(*dataSets) - constructor(dataSets: MutableList) : super(dataSets) + constructor(dataSets: MutableList, Float>>) : super(dataSets) } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/LineDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/LineDataSet.kt index b8584b36b..51d03d233 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/LineDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/LineDataSet.kt @@ -12,7 +12,8 @@ import info.appdev.charting.utils.ColorTemplate import info.appdev.charting.utils.convertDpToPixel import timber.log.Timber -open class LineDataSet(yVals: MutableList = mutableListOf(), label: String = "") : LineRadarDataSet(yVals, label), ILineDataSet { +open class LineDataSet(yVals: MutableList = mutableListOf(), label: String = "") : LineRadarDataSet(yVals, label), ILineDataSet + where T : BaseEntry, N : Number, N : Comparable { /** * Drawing mode for this line dataset */ @@ -73,28 +74,26 @@ open class LineDataSet(yVals: MutableList = mutableListOf(), label: Strin circleColors.add(Color.rgb(140, 234, 255)) } - override fun copy(): DataSet { - val entries: MutableList = mutableListOf() - for (i in mEntries.indices) { - entries.add(mEntries[i].copy()) - } + override fun copy(): DataSet? { + val entries: MutableList = mutableListOf() + entries.addAll(mEntries) val copied = LineDataSet(entries, label) copy(copied) return copied } - protected fun copy(lineDataSet: LineDataSet) { - super.copy((lineDataSet as BaseDataSet<*>?)!!) + protected fun copy(lineDataSet: LineDataSet) { + super.copy(lineDataSet) 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 + lineDataSet.mCircleHoleColor = this.mCircleHoleColor + lineDataSet.mCircleHoleRadius = this.mCircleHoleRadius + lineDataSet.mCircleRadius = this.mCircleRadius + lineDataSet.mCubicIntensity = this.mCubicIntensity + lineDataSet.mDashPathEffect = this.mDashPathEffect + lineDataSet.mDrawCircleHole = this.mDrawCircleHole + lineDataSet.mDrawCircles = this.mDrawCircleHole + lineDataSet.mFillFormatter = this.mFillFormatter + lineDataSet.mLineDataSetMode = this.mLineDataSetMode } /** diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/LineRadarDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/LineRadarDataSet.kt index 93e97e80f..8c04703ab 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/LineRadarDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/LineRadarDataSet.kt @@ -9,8 +9,7 @@ import info.appdev.charting.utils.convertDpToPixel /** * Base dataset for line and radar DataSets. */ -abstract class LineRadarDataSet>(yVals: MutableList, label: String) : LineScatterCandleRadarDataSet(yVals, label), - ILineRadarDataSet { +abstract class LineRadarDataSet(yVals: MutableList, label: String) : LineScatterCandleRadarDataSet(yVals, label), ILineRadarDataSet where T : BaseEntry, N : Number, N : Comparable { // TODO: Move to using `Fill` class /** * the color that is used for filling the line surface @@ -69,8 +68,8 @@ abstract class LineRadarDataSet>(yVals: MutableList, lab mLineWidth = width.convertDpToPixel() } - protected fun copy(lineRadarDataSet: LineRadarDataSet<*>) { - super.copy((lineRadarDataSet as BaseDataSet<*>?)!!) + protected fun copy(lineRadarDataSet: LineRadarDataSet<*, *>) { + super.copy((lineRadarDataSet as BaseDataSet<*, *>?)!!) lineRadarDataSet.isDrawFilled = this.isDrawFilled lineRadarDataSet.fillAlpha = this.fillAlpha lineRadarDataSet.mFillColor = mFillColor diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/LineScatterCandleRadarDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/LineScatterCandleRadarDataSet.kt index 5a2a9a811..f4acdbff5 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/LineScatterCandleRadarDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/LineScatterCandleRadarDataSet.kt @@ -4,8 +4,8 @@ import android.graphics.DashPathEffect import info.appdev.charting.interfaces.datasets.ILineScatterCandleRadarDataSet import info.appdev.charting.utils.convertDpToPixel -abstract class LineScatterCandleRadarDataSet>(yVals: MutableList, label: String) : BarLineScatterCandleBubbleDataSet(yVals, label), - ILineScatterCandleRadarDataSet { +abstract class LineScatterCandleRadarDataSet(yVals: MutableList, label: String) : BarLineScatterCandleBubbleDataSet(yVals, label), + ILineScatterCandleRadarDataSet where T : BaseEntry, N : Number, N : Comparable { override var isVerticalHighlightIndicator: Boolean = true override var isHorizontalHighlightIndicator: Boolean = true @@ -78,8 +78,8 @@ abstract class LineScatterCandleRadarDataSet>(yVals: Mutabl val isDashedHighlightLineEnabled: Boolean get() = this.dashPathEffectHighlight != null - protected fun copy(lineScatterCandleRadarDataSet: LineScatterCandleRadarDataSet<*>) { - super.copy((lineScatterCandleRadarDataSet as BaseDataSet<*>?)!!) + protected fun copy(lineScatterCandleRadarDataSet: LineScatterCandleRadarDataSet<*, *>) { + super.copy((lineScatterCandleRadarDataSet as BaseDataSet<*, *>?)!!) lineScatterCandleRadarDataSet.isHorizontalHighlightIndicator = this.isHorizontalHighlightIndicator lineScatterCandleRadarDataSet.isVerticalHighlightIndicator = this.isVerticalHighlightIndicator lineScatterCandleRadarDataSet.mHighlightLineWidth = mHighlightLineWidth diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/PieDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/PieDataSet.kt index 717f9d6f7..167143647 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/PieDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/PieDataSet.kt @@ -4,7 +4,7 @@ import androidx.annotation.ColorInt import info.appdev.charting.interfaces.datasets.IPieDataSet import info.appdev.charting.utils.convertDpToPixel -open class PieDataSet(yVals: MutableList, label: String) : DataSet(yVals, label), IPieDataSet { +open class PieDataSet(yVals: MutableList, label: String) : DataSet(yVals, label), IPieDataSet { /** * the space in pixels between the chart-slices, default 0f */ @@ -29,7 +29,7 @@ open class PieDataSet(yVals: MutableList, label: String) : DataSet { + override fun copy(): DataSet { val entries: MutableList = mutableListOf() for (i in mEntries.indices) { entries.add(mEntries[i].copy()) @@ -39,7 +39,7 @@ open class PieDataSet(yVals: MutableList, label: String) : DataSet?)!!) + super.copy((pieDataSet as BaseDataSet<*, *>?)!!) } override fun calcMinMax(entry: PieEntry) { diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/RadarDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/RadarDataSet.kt index 5457390ce..8a4d63094 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/RadarDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/RadarDataSet.kt @@ -5,7 +5,7 @@ import androidx.annotation.ColorInt import info.appdev.charting.interfaces.datasets.IRadarDataSet import info.appdev.charting.utils.ColorTemplate -open class RadarDataSet(yVals: MutableList, label: String = "") : LineRadarDataSet(yVals, label), IRadarDataSet { +open class RadarDataSet(yVals: MutableList, label: String = "") : LineRadarDataSet(yVals, label), IRadarDataSet { /** flag indicating whether highlight circle should be drawn or not */ protected var mIsDrawHighlightCircle: Boolean = false @@ -58,7 +58,7 @@ open class RadarDataSet(yVals: MutableList, label: String = "") : Li mHighlightCircleStrokeWidth = value } - override fun copy(): DataSet { + override fun copy(): DataSet { val entries: MutableList = mutableListOf() for (i in mEntries.indices) { entries.add(mEntries[i].copy()) @@ -69,7 +69,7 @@ open class RadarDataSet(yVals: MutableList, label: String = "") : Li } protected fun copy(radarDataSet: RadarDataSet) { - super.copy((radarDataSet as BaseDataSet<*>?)!!) + super.copy((radarDataSet as BaseDataSet<*, *>?)!!) radarDataSet.mIsDrawHighlightCircle = mIsDrawHighlightCircle radarDataSet.mHighlightCircleFillColor = mHighlightCircleFillColor radarDataSet.mHighlightCircleInnerRadius = mHighlightCircleInnerRadius diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/ScatterDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/ScatterDataSet.kt index 0b1b5dcbb..6e73f57e9 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/ScatterDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/ScatterDataSet.kt @@ -13,7 +13,7 @@ import info.appdev.charting.renderer.scatter.TriangleShapeRenderer import info.appdev.charting.renderer.scatter.XShapeRenderer import info.appdev.charting.utils.ColorTemplate -open class ScatterDataSet(yVals: MutableList, label: String = "") : LineScatterCandleRadarDataSet(yVals, label), IScatterDataSet { +open class ScatterDataSet(yVals: MutableList, label: String = "") : LineScatterCandleRadarDataSet(yVals, label), IScatterDataSet { /** * the size the scatterShape will have, in density pixels */ @@ -38,7 +38,7 @@ open class ScatterDataSet(yVals: MutableList, label: String = "") : LineS @ColorInt private var mScatterShapeHoleColor = ColorTemplate.COLOR_NONE - override fun copy(): DataSet { + override fun copy(): DataSet { val entries: MutableList = mutableListOf() for (i in mEntries.indices) { entries.add(mEntries[i].copy()) @@ -49,7 +49,7 @@ open class ScatterDataSet(yVals: MutableList, label: String = "") : LineS } protected fun copy(scatterDataSet: ScatterDataSet) { - super.copy((scatterDataSet as BaseDataSet<*>?)!!) + super.copy((scatterDataSet as BaseDataSet<*, *>?)!!) scatterDataSet.shapeSize = shapeSize scatterDataSet.mShapeRenderer = mShapeRenderer scatterDataSet.mScatterShapeHoleRadius = mScatterShapeHoleRadius diff --git a/chartLib/src/main/kotlin/info/appdev/charting/formatter/ColorFormatter.kt b/chartLib/src/main/kotlin/info/appdev/charting/formatter/ColorFormatter.kt index 3293e103c..bfab39bcc 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/formatter/ColorFormatter.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/formatter/ColorFormatter.kt @@ -14,5 +14,5 @@ interface ColorFormatter { * @param entry the entry to color * @param set the DataSet the entry belongs to */ - fun getColor(index: Int, entry: Entry?, set: IDataSet<*>?): Int + fun getColor(index: Int, entry: Entry?, set: IDataSet<*, *>?): Int } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/formatter/DefaultFillFormatter.kt b/chartLib/src/main/kotlin/info/appdev/charting/formatter/DefaultFillFormatter.kt index cedd7eed5..22d75595d 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/formatter/DefaultFillFormatter.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/formatter/DefaultFillFormatter.kt @@ -1,5 +1,6 @@ package info.appdev.charting.formatter +import info.appdev.charting.data.BaseEntry import info.appdev.charting.interfaces.dataprovider.LineDataProvider import info.appdev.charting.interfaces.datasets.ILineDataSet @@ -8,7 +9,7 @@ import info.appdev.charting.interfaces.datasets.ILineDataSet */ open class DefaultFillFormatter : IFillFormatter { - override fun getFillLinePosition(dataSet: ILineDataSet?, dataProvider: LineDataProvider): Float { + override fun getFillLinePosition(dataSet: ILineDataSet, Float>?, dataProvider: LineDataProvider): Float { val fillMin: Float val chartMaxY = dataProvider.yChartMax val chartMinY = dataProvider.yChartMin diff --git a/chartLib/src/main/kotlin/info/appdev/charting/formatter/DefaultValueFormatter.kt b/chartLib/src/main/kotlin/info/appdev/charting/formatter/DefaultValueFormatter.kt index b722ff084..da36416f6 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/formatter/DefaultValueFormatter.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/formatter/DefaultValueFormatter.kt @@ -1,6 +1,6 @@ package info.appdev.charting.formatter -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.utils.ViewPortHandler import java.text.DecimalFormat @@ -42,7 +42,7 @@ open class DefaultValueFormatter(digits: Int) : IValueFormatter { decimalFormat = DecimalFormat("###,###,###,##0$b") } - override fun getFormattedValue(value: Float, entry: Entry?, dataSetIndex: Int, viewPortHandler: ViewPortHandler?): String? { + override fun getFormattedValue(value: Float, entry: BaseEntry?, dataSetIndex: Int, viewPortHandler: ViewPortHandler?): String? { // put more logic here ... // avoid memory allocations here (for performance reasons) diff --git a/chartLib/src/main/kotlin/info/appdev/charting/formatter/IFillFormatter.kt b/chartLib/src/main/kotlin/info/appdev/charting/formatter/IFillFormatter.kt index cef5444c8..e1d5f44bd 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/formatter/IFillFormatter.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/formatter/IFillFormatter.kt @@ -1,5 +1,6 @@ package info.appdev.charting.formatter +import info.appdev.charting.data.BaseEntry import info.appdev.charting.interfaces.dataprovider.LineDataProvider import info.appdev.charting.interfaces.datasets.ILineDataSet @@ -14,5 +15,5 @@ interface IFillFormatter { * @param dataSet the ILineDataSet that is currently drawn * @param dataProvider */ - fun getFillLinePosition(dataSet: ILineDataSet?, dataProvider: LineDataProvider): Float + fun getFillLinePosition(dataSet: ILineDataSet, Float>?, dataProvider: LineDataProvider): Float } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/formatter/IValueFormatter.kt b/chartLib/src/main/kotlin/info/appdev/charting/formatter/IValueFormatter.kt index 8e05dedc0..e607edd9a 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/formatter/IValueFormatter.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/formatter/IValueFormatter.kt @@ -1,6 +1,6 @@ package info.appdev.charting.formatter -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.utils.ViewPortHandler /** @@ -21,5 +21,5 @@ interface IValueFormatter { * @param viewPortHandler provides information about the current chart state (scale, translation, ...) * @return the formatted label ready for being drawn */ - fun getFormattedValue(value: Float, entry: Entry?, dataSetIndex: Int, viewPortHandler: ViewPortHandler?): String? + fun getFormattedValue(value: Float, entry: BaseEntry?, dataSetIndex: Int, viewPortHandler: ViewPortHandler?): String? } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/formatter/LargeValueFormatter.kt b/chartLib/src/main/kotlin/info/appdev/charting/formatter/LargeValueFormatter.kt index 12692b54c..1f3fdd3ab 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/formatter/LargeValueFormatter.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/formatter/LargeValueFormatter.kt @@ -1,7 +1,7 @@ package info.appdev.charting.formatter import info.appdev.charting.components.AxisBase -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.utils.ViewPortHandler import java.text.DecimalFormat @@ -32,7 +32,7 @@ open class LargeValueFormatter() : IValueFormatter, IAxisValueFormatter { } // IValueFormatter - override fun getFormattedValue(value: Float, entry: Entry?, dataSetIndex: Int, viewPortHandler: ViewPortHandler?): String { + override fun getFormattedValue(value: Float, entry: BaseEntry?, dataSetIndex: Int, viewPortHandler: ViewPortHandler?): String { return makePretty(value.toDouble()) + text } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/formatter/PercentFormatter.kt b/chartLib/src/main/kotlin/info/appdev/charting/formatter/PercentFormatter.kt index 271fab7bf..fa746b3f1 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/formatter/PercentFormatter.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/formatter/PercentFormatter.kt @@ -1,7 +1,7 @@ package info.appdev.charting.formatter import info.appdev.charting.components.AxisBase -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.utils.ViewPortHandler import java.text.DecimalFormat @@ -23,7 +23,7 @@ open class PercentFormatter : IValueFormatter, IAxisValueFormatter { } // IValueFormatter - override fun getFormattedValue(value: Float, entry: Entry?, dataSetIndex: Int, viewPortHandler: ViewPortHandler?): String? { + override fun getFormattedValue(value: Float, entry: BaseEntry?, dataSetIndex: Int, viewPortHandler: ViewPortHandler?): String? { return decimalFormat.format(value.toDouble()) + " %" } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/formatter/StackedValueFormatter.kt b/chartLib/src/main/kotlin/info/appdev/charting/formatter/StackedValueFormatter.kt index 957957acd..521c5a350 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/formatter/StackedValueFormatter.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/formatter/StackedValueFormatter.kt @@ -1,7 +1,7 @@ package info.appdev.charting.formatter import info.appdev.charting.data.BarEntry -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.utils.ViewPortHandler import java.text.DecimalFormat @@ -29,7 +29,7 @@ open class StackedValueFormatter(private val drawWholeStack: Boolean, private va this.decimalFormat = DecimalFormat("###,###,###,##0$b") } - override fun getFormattedValue(value: Float, entry: Entry?, dataSetIndex: Int, viewPortHandler: ViewPortHandler?): String { + override fun getFormattedValue(value: Float, entry: BaseEntry?, dataSetIndex: Int, viewPortHandler: ViewPortHandler?): String { if (!drawWholeStack && entry is BarEntry) { val barEntry = entry val vals = barEntry.yVals diff --git a/chartLib/src/main/kotlin/info/appdev/charting/highlight/ChartHighlighter.kt b/chartLib/src/main/kotlin/info/appdev/charting/highlight/ChartHighlighter.kt index 713bff52f..b4c6fcd6c 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/highlight/ChartHighlighter.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/highlight/ChartHighlighter.kt @@ -114,7 +114,7 @@ open class ChartHighlighter>(prote */ @Suppress("SameParameterValue") protected open fun buildHighlights( - set: IDataSet<*>, + set: IDataSet<*, *>, dataSetIndex: Int, xVal: Float, rounding: DataSet.Rounding? @@ -126,7 +126,7 @@ open class ChartHighlighter>(prote // Try to find closest x-value and take all entries for that x-value val closest = set.getEntryForXValue(xVal, Float.NaN, rounding) if (closest != null) { - entries = set.getEntriesForXValue(closest.x) + entries = set.getEntriesForXValue(closest.x.toFloat()) } } @@ -135,12 +135,12 @@ open class ChartHighlighter>(prote if (entries != null) for (e in entries) { - val pixels = provider.getTransformer(set.axisDependency)!!.getPixelForValues(e.x, e.y) + val pixels = provider.getTransformer(set.axisDependency)!!.getPixelForValues(e.x.toFloat(), e.y.toFloat()) highlights.add( Highlight( - x = e.x, - y = e.y, + x = e.x.toFloat(), + y = e.y.toFloat(), xPx = pixels.x.toFloat(), yPx = pixels.y.toFloat(), dataSetIndex = dataSetIndex, diff --git a/chartLib/src/main/kotlin/info/appdev/charting/highlight/HorizontalBarHighlighter.kt b/chartLib/src/main/kotlin/info/appdev/charting/highlight/HorizontalBarHighlighter.kt index f2ab13581..66e45c503 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/highlight/HorizontalBarHighlighter.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/highlight/HorizontalBarHighlighter.kt @@ -31,7 +31,7 @@ class HorizontalBarHighlighter(dataProvider: BarDataProvider) : BarHighlighter(d return null } - override fun buildHighlights(set: IDataSet<*>, dataSetIndex: Int, xVal: Float, rounding: DataSet.Rounding?): MutableList { + override fun buildHighlights(set: IDataSet<*, *>, dataSetIndex: Int, xVal: Float, rounding: DataSet.Rounding?): MutableList { val highlights = ArrayList() var entries = set.getEntriesForXValue(xVal) @@ -39,7 +39,7 @@ class HorizontalBarHighlighter(dataProvider: BarDataProvider) : BarHighlighter(d // Try to find closest x-value and take all entries for that x-value val closestEntry = set.getEntryForXValue(xVal, Float.NaN, rounding) closestEntry?.let { closestE -> - entries = set.getEntriesForXValue(closestE.x) + entries = set.getEntriesForXValue(closestE.x.toFloat()) } } @@ -48,11 +48,11 @@ class HorizontalBarHighlighter(dataProvider: BarDataProvider) : BarHighlighter(d if (entries != null) for (entry in entries) { - val pixels = provider.getTransformer(set.axisDependency)!!.getPixelForValues(entry.y, entry.x) + val pixels = provider.getTransformer(set.axisDependency)!!.getPixelForValues(entry.y.toFloat(), entry.x.toFloat()) highlights.add( Highlight( - entry.x, entry.y, + entry.x.toFloat(), entry.y.toFloat(), pixels.x.toFloat(), pixels.y.toFloat(), dataSetIndex, set.axisDependency ) diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IBarDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IBarDataSet.kt index a29dc8da7..26470e3e9 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IBarDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IBarDataSet.kt @@ -3,7 +3,7 @@ package info.appdev.charting.interfaces.datasets import info.appdev.charting.data.BarEntry import info.appdev.charting.utils.Fill -interface IBarDataSet : IBarLineScatterCandleBubbleDataSet { +interface IBarDataSet : IBarLineScatterCandleBubbleDataSet { var fills: MutableList fun getFill(index: Int): Fill? diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.kt index 620d555cb..a442a6e28 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.kt @@ -2,7 +2,7 @@ package info.appdev.charting.interfaces.datasets import info.appdev.charting.data.BaseEntry -interface IBarLineScatterCandleBubbleDataSet> : IDataSet { +interface IBarLineScatterCandleBubbleDataSet : IDataSet where T : BaseEntry, N : Number, N : Comparable { val highLightColor: Int } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IBubbleDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IBubbleDataSet.kt index 43f8efb49..3334b064d 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IBubbleDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IBubbleDataSet.kt @@ -2,7 +2,7 @@ package info.appdev.charting.interfaces.datasets import info.appdev.charting.data.BubbleEntry -interface IBubbleDataSet : IBarLineScatterCandleBubbleDataSet { +interface IBubbleDataSet : IBarLineScatterCandleBubbleDataSet { val maxSize: Float val isNormalizeSizeEnabled: Boolean diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ICandleDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ICandleDataSet.kt index 366c78344..5d3dc43d3 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ICandleDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ICandleDataSet.kt @@ -1,10 +1,9 @@ package info.appdev.charting.interfaces.datasets import android.graphics.Paint -import androidx.annotation.ColorInt import info.appdev.charting.data.CandleEntry -interface ICandleDataSet : ILineScatterCandleRadarDataSet { +interface ICandleDataSet : ILineScatterCandleRadarDataSet { /** * Returns the space that is left out on the left and right side of each candle. */ diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IDataSet.kt index ade87f73e..0e8808c01 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IDataSet.kt @@ -6,11 +6,10 @@ import info.appdev.charting.components.Legend import info.appdev.charting.components.YAxis import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.DataSet -import info.appdev.charting.data.Entry import info.appdev.charting.formatter.IValueFormatter import info.appdev.charting.utils.PointF -interface IDataSet> { +interface IDataSet where T : BaseEntry, N : Number, N : Comparable { /** * returns the minimum y-value this DataSet holds */ diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineDataSet.kt index 3f2ccd2dc..b1232eb72 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineDataSet.kt @@ -1,11 +1,11 @@ package info.appdev.charting.interfaces.datasets import android.graphics.DashPathEffect -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.LineDataSet import info.appdev.charting.formatter.IFillFormatter -interface ILineDataSet : ILineRadarDataSet { +interface ILineDataSet : ILineRadarDataSet where T : BaseEntry, N : Number, N : Comparable { /** * Returns the drawing mode for this line dataset */ diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineRadarDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineRadarDataSet.kt index 31ebc9986..ab845c46e 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineRadarDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineRadarDataSet.kt @@ -3,7 +3,7 @@ package info.appdev.charting.interfaces.datasets import android.graphics.drawable.Drawable import info.appdev.charting.data.BaseEntry -interface ILineRadarDataSet> : ILineScatterCandleRadarDataSet { +interface ILineRadarDataSet : ILineScatterCandleRadarDataSet where T : BaseEntry, N : Number, N : Comparable { /** * Returns the color that is used for filling the line surface area. */ diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineScatterCandleRadarDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineScatterCandleRadarDataSet.kt index 8e1f2868e..d12a8d936 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineScatterCandleRadarDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineScatterCandleRadarDataSet.kt @@ -3,7 +3,7 @@ package info.appdev.charting.interfaces.datasets import android.graphics.DashPathEffect import info.appdev.charting.data.BaseEntry -interface ILineScatterCandleRadarDataSet> : IBarLineScatterCandleBubbleDataSet { +interface ILineScatterCandleRadarDataSet : IBarLineScatterCandleBubbleDataSet where T : BaseEntry, N : Number, N : Comparable { /** * Returns true if vertical highlight indicator lines are enabled (drawn) */ diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IPieDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IPieDataSet.kt index 658602dc7..0ea7e68bb 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IPieDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IPieDataSet.kt @@ -3,7 +3,7 @@ package info.appdev.charting.interfaces.datasets import info.appdev.charting.data.PieDataSet.ValuePosition import info.appdev.charting.data.PieEntry -interface IPieDataSet : IDataSet { +interface IPieDataSet : IDataSet { /** * Returns the space that is set to be between the PieChart-slices of this DataSet, in pixels. */ diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IRadarDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IRadarDataSet.kt index 986849fcf..5f9c86be7 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IRadarDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IRadarDataSet.kt @@ -2,7 +2,7 @@ package info.appdev.charting.interfaces.datasets import info.appdev.charting.data.RadarEntry -interface IRadarDataSet : ILineRadarDataSet { +interface IRadarDataSet : ILineRadarDataSet { /** flag indicating whether highlight circle should be drawn or not */ /** Sets whether highlight circle should be drawn or not */ var isDrawHighlightCircle: Boolean diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IScatterDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IScatterDataSet.kt index 9e44a3251..30b91b455 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IScatterDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IScatterDataSet.kt @@ -3,7 +3,7 @@ package info.appdev.charting.interfaces.datasets import info.appdev.charting.data.Entry import info.appdev.charting.renderer.scatter.IShapeRenderer -interface IScatterDataSet : ILineScatterCandleRadarDataSet { +interface IScatterDataSet : ILineScatterCandleRadarDataSet { /** * the currently set scatter shape size */ diff --git a/chartLib/src/main/kotlin/info/appdev/charting/listener/BarLineChartTouchListener.kt b/chartLib/src/main/kotlin/info/appdev/charting/listener/BarLineChartTouchListener.kt index 786af91c6..f83ebad87 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/listener/BarLineChartTouchListener.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/listener/BarLineChartTouchListener.kt @@ -9,7 +9,7 @@ import android.view.animation.AnimationUtils import info.appdev.charting.charts.BarLineChartBase import info.appdev.charting.charts.HorizontalBarChart import info.appdev.charting.data.BarLineScatterCandleBubbleData -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet import info.appdev.charting.interfaces.datasets.IDataSet import info.appdev.charting.utils.PointF @@ -25,11 +25,11 @@ import kotlin.math.sqrt */ @Suppress("MemberVisibilityCanBePrivate") class BarLineChartTouchListener( - chart: BarLineChartBase>>, + chart: BarLineChartBase, Float>>>, touchMatrix: Matrix, dragTriggerDistance: Float ) : - ChartTouchListener>>>(chart) { + ChartTouchListener, Float>>>>(chart) { /** * the original touch-matrix from the chart */ @@ -55,7 +55,7 @@ class BarLineChartTouchListener( private var savedYDist = 1f private var savedDist = 1f - private var closestDataSetToTouch: IDataSet<*>? = null + private var closestDataSetToTouch: IDataSet<*, *>? = null /** * used for tracking velocity of dragging @@ -471,8 +471,9 @@ class BarLineChartTouchListener( * Returns true if the current touch situation should be interpreted as inverted, false if not. */ private fun inverted(): Boolean { - return (closestDataSetToTouch == null && chart.isAnyAxisInverted) || (closestDataSetToTouch != null - && chart.isInverted(closestDataSetToTouch!!.axisDependency)) + val dataSet = closestDataSetToTouch + return (dataSet == null && chart.isAnyAxisInverted) || (dataSet != null + && chart.isInverted(dataSet.axisDependency)) } /** diff --git a/chartLib/src/main/kotlin/info/appdev/charting/listener/OnChartValueSelectedListener.kt b/chartLib/src/main/kotlin/info/appdev/charting/listener/OnChartValueSelectedListener.kt index 188ed5ea1..27a6b55c1 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/listener/OnChartValueSelectedListener.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/listener/OnChartValueSelectedListener.kt @@ -1,6 +1,6 @@ package info.appdev.charting.listener -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.highlight.Highlight /** @@ -15,7 +15,7 @@ interface OnChartValueSelectedListener { * @param highlight The corresponding highlight object that contains information * about the highlighted position such as dataSetIndex, ... */ - fun onValueSelected(entry: Entry, highlight: Highlight) + fun onValueSelected(entry: BaseEntry, highlight: Highlight) /** * Called when nothing has been selected or an "un-select" has been made. diff --git a/chartLib/src/main/kotlin/info/appdev/charting/listener/OnDrawListener.kt b/chartLib/src/main/kotlin/info/appdev/charting/listener/OnDrawListener.kt index 6e755a23e..d7d1c02d9 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/listener/OnDrawListener.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/listener/OnDrawListener.kt @@ -1,5 +1,6 @@ package info.appdev.charting.listener +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.DataSet import info.appdev.charting.data.Entry @@ -25,5 +26,5 @@ interface OnDrawListener { * * @param dataSet the last drawn DataSet */ - fun onDrawFinished(dataSet: DataSet<*>) + fun onDrawFinished(dataSet: DataSet, Float>) } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/BarLineScatterCandleBubbleRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/BarLineScatterCandleBubbleRenderer.kt index 1634e8264..3164eea62 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/BarLineScatterCandleBubbleRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/BarLineScatterCandleBubbleRenderer.kt @@ -22,14 +22,14 @@ abstract class BarLineScatterCandleBubbleRenderer( /** * Returns true if the DataSet values should be drawn, false if not. */ - protected fun shouldDrawValues(set: IDataSet<*>): Boolean { + protected fun shouldDrawValues(set: IDataSet<*, *>): Boolean { return set.isVisible && (set.isDrawValues || set.isDrawIcons) } /** * Checks if the provided entry object is in bounds for drawing considering the current animation phase. */ - protected fun > isInBoundsX(entry: T, set: IBarLineScatterCandleBubbleDataSet): Boolean { + protected fun isInBoundsX(entry: T, set: IBarLineScatterCandleBubbleDataSet): Boolean where T : BaseEntry, N : Number, N : Comparable { val entryIndex = set.getEntryIndex(entry).toFloat() return if (entryIndex >= set.entryCount * animator.phaseX) { @@ -61,7 +61,7 @@ abstract class BarLineScatterCandleBubbleRenderer( /** * Calculates the minimum and maximum x values as well as the range between them. */ - fun > set(chart: BarLineScatterCandleBubbleDataProvider<*>, dataSet: IBarLineScatterCandleBubbleDataSet) { + fun set(chart: BarLineScatterCandleBubbleDataProvider<*>, dataSet: IBarLineScatterCandleBubbleDataSet) where T : BaseEntry, N : Number, N : Comparable { val phaseX = max(0f, min(1f, animator.phaseX)) val low = chart.lowestVisibleX diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/DataRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/DataRenderer.kt index 09b1c3acd..6ccd54665 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/DataRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/DataRenderer.kt @@ -5,7 +5,7 @@ import android.graphics.Color import android.graphics.Paint import android.graphics.Paint.Align import info.appdev.charting.animation.ChartAnimator -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.formatter.IValueFormatter import info.appdev.charting.highlight.Highlight import info.appdev.charting.interfaces.dataprovider.base.IBaseProvider @@ -70,7 +70,7 @@ abstract class DataRenderer( * Applies the required styling (provided by the DataSet) to the value-paint * object. */ - protected fun applyValueTextStyle(set: IDataSet<*>) { + protected fun applyValueTextStyle(set: IDataSet<*, *>) { paintValues.typeface = set.valueTypeface paintValues.textSize = set.valueTextSize } @@ -103,7 +103,7 @@ abstract class DataRenderer( * @param x position * @param y position */ - fun drawValue(canvas: Canvas, formatter: IValueFormatter, value: Float, entry: Entry?, dataSetIndex: Int, x: Float, y: Float, color: Int) { + fun drawValue(canvas: Canvas, formatter: IValueFormatter, value: Float, entry: BaseEntry?, dataSetIndex: Int, x: Float, y: Float, color: Int) { paintValues.color = color canvas.drawText(formatter.getFormattedValue(value, entry, dataSetIndex, viewPortHandler)!!, x, y, paintValues) } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/LineChartRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/LineChartRenderer.kt index 9745460e6..b724966e4 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/LineChartRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/LineChartRenderer.kt @@ -7,10 +7,11 @@ import android.graphics.Color import android.graphics.Paint import android.graphics.Path import info.appdev.charting.animation.ChartAnimator -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.LineDataSet import info.appdev.charting.highlight.Highlight import info.appdev.charting.interfaces.dataprovider.LineDataProvider +import info.appdev.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet import info.appdev.charting.interfaces.datasets.IDataSet import info.appdev.charting.interfaces.datasets.ILineDataSet import info.appdev.charting.utils.ColorTemplate @@ -85,7 +86,7 @@ open class LineChartRenderer( canvas.drawBitmap(drawBitmapLocal, 0f, 0f, null) } - protected fun drawDataSet(canvas: Canvas, dataSet: ILineDataSet) { + protected fun drawDataSet(canvas: Canvas, dataSet: ILineDataSet, Float>) { if (dataSet.entryCount < 1) return @@ -102,7 +103,7 @@ open class LineChartRenderer( paintRender.pathEffect = null } - protected fun drawHorizontalBezier(dataSet: ILineDataSet) { + protected fun drawHorizontalBezier(dataSet: ILineDataSet, Float>) { val phaseY = animator.phaseY val trans = dataProvider.getTransformer(dataSet.axisDependency) @@ -152,7 +153,7 @@ open class LineChartRenderer( paintRender.pathEffect = null } - protected fun drawCubicBezier(dataSet: ILineDataSet) { + protected fun drawCubicBezier(dataSet: ILineDataSet, Float>) { val phaseY = animator.phaseY val trans = dataProvider.getTransformer(dataSet.axisDependency) @@ -175,7 +176,7 @@ open class LineChartRenderer( // And in the `lastIndex`, add +1 val firstIndex = xBounds.min + 1 - var prevPrev: Entry? + var prevPrev: BaseEntry? var prev = dataSet.getEntryForIndex(max((firstIndex - 2).toDouble(), 0.0).toInt()) var cur = dataSet.getEntryForIndex(max((firstIndex - 1).toDouble(), 0.0).toInt()) var next = cur @@ -227,7 +228,7 @@ open class LineChartRenderer( paintRender.pathEffect = null } - protected fun drawCubicFill(canvas: Canvas, dataSet: ILineDataSet, spline: Path, trans: Transformer, bounds: XBounds) { + protected fun drawCubicFill(canvas: Canvas, dataSet: ILineDataSet, Float>, spline: Path, trans: Transformer, bounds: XBounds) { val fillMin = dataSet.fillFormatter!!.getFillLinePosition(dataSet, dataProvider) dataSet.getEntryForIndex(bounds.min + bounds.range)?.let { @@ -251,7 +252,7 @@ open class LineChartRenderer( /** * Draws a normal line. */ - protected fun drawLinear(c: Canvas, dataSet: ILineDataSet) { + protected fun drawLinear(c: Canvas, dataSet: ILineDataSet, Float>) { val entryCount = dataSet.entryCount val pointsPerEntryPair = if (dataSet.isDrawSteppedEnabled) 4 else 2 @@ -286,7 +287,7 @@ open class LineChartRenderer( val max = xBounds.min + xBounds.range for (j in xBounds.min.. = dataSet.getEntryForIndex(j) ?: continue lineBuffer[0] = entry.x lineBuffer[1] = entry.y * phaseY @@ -346,8 +347,8 @@ open class LineChartRenderer( (max(((entryCount) * pointsPerEntryPair).toDouble(), pointsPerEntryPair.toDouble()) * 4).toInt() ) - var e1: Entry? - var e2: Entry? + var e1: BaseEntry? + var e2: BaseEntry? e1 = dataSet.getEntryForIndex(xBounds.min) @@ -393,7 +394,7 @@ open class LineChartRenderer( /** * Draws a filled linear path on the canvas. */ - protected fun drawLinearFill(canvas: Canvas, dataSet: ILineDataSet, trans: Transformer, bounds: XBounds) { + protected fun drawLinearFill(canvas: Canvas, dataSet: ILineDataSet, Float>, trans: Transformer, bounds: XBounds) { val filled = mGenerateFilledPathBuffer val startingIndex = bounds.min @@ -435,7 +436,7 @@ open class LineChartRenderer( * @param endIndex The index from which to stop reading the dataset * @param outputPath The path object that will be assigned the chart data. */ - private fun generateFilledPath(dataSet: ILineDataSet, startIndex: Int, endIndex: Int, outputPath: Path) { + private fun generateFilledPath(dataSet: ILineDataSet, Float>, startIndex: Int, endIndex: Int, outputPath: Path) { val fillMin = dataSet.fillFormatter!!.getFillLinePosition(dataSet, dataProvider) val phaseY = animator.phaseY val isDrawSteppedEnabled = dataSet.lineMode == LineDataSet.Mode.STEPPED @@ -448,7 +449,7 @@ open class LineChartRenderer( outputPath.lineTo(entry.x, entry.y * phaseY) // create a new path - var currentEntry: Entry? = null + var currentEntry: BaseEntry? = null var previousEntry = entry for (x in startIndex + 1..endIndex) { currentEntry = dataSet.getEntryForIndex(x) @@ -558,7 +559,7 @@ open class LineChartRenderer( /** * cache for the circle bitmaps of all datasets */ - private val mImageCaches = HashMap, DataSetImageCache>() + private val mImageCaches = HashMap, DataSetImageCache>() /** * buffer for drawing the circles @@ -650,7 +651,8 @@ open class LineChartRenderer( set.getEntryForXValue(high.x, high.y)?.let { entry -> - if (!isInBoundsX(entry, set)) + @Suppress("UNCHECKED_CAST") + if (!isInBoundsX(entry, set as IBarLineScatterCandleBubbleDataSet, Float>)) continue val pix = dataProvider.getTransformer(set.axisDependency)!!.getPixelForValues( @@ -686,7 +688,7 @@ open class LineChartRenderer( /** * Sets up the cache, returns true if a change of cache was required. */ - fun init(set: ILineDataSet): Boolean { + fun init(set: ILineDataSet, Float>): Boolean { val size = set.circleColorCount var changeRequired = false @@ -708,7 +710,7 @@ open class LineChartRenderer( * @param drawCircleHole * @param drawTransparentCircleHole */ - fun fill(set: ILineDataSet, drawCircleHole: Boolean, drawTransparentCircleHole: Boolean) { + fun fill(set: ILineDataSet, Float>, drawCircleHole: Boolean, drawTransparentCircleHole: Boolean) { val colorCount = set.circleColorCount val circleRadius = set.circleRadius val circleHoleRadius = set.circleHoleRadius diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/LineScatterCandleRadarRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/LineScatterCandleRadarRenderer.kt index 9cfe7bc7b..fe983f4ef 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/LineScatterCandleRadarRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/LineScatterCandleRadarRenderer.kt @@ -23,7 +23,7 @@ abstract class LineScatterCandleRadarRenderer( * @param y y-position of the highlight line intersection * @param set the currently drawn dataset */ - protected fun drawHighlightLines(canvas: Canvas, x: Float, y: Float, set: ILineScatterCandleRadarDataSet<*>) { + protected fun drawHighlightLines(canvas: Canvas, x: Float, y: Float, set: ILineScatterCandleRadarDataSet<*, *>) { // set color and stroke-width paintHighlight.color = set.highLightColor diff --git a/chartLib/src/main/kotlin/info/appdev/charting/utils/AssetManagerUtils.kt b/chartLib/src/main/kotlin/info/appdev/charting/utils/AssetManagerUtils.kt index b0f56d114..bbaf3e289 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/utils/AssetManagerUtils.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/utils/AssetManagerUtils.kt @@ -2,6 +2,7 @@ package info.appdev.charting.utils import android.content.res.AssetManager import info.appdev.charting.data.BarEntry +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.Entry import timber.log.Timber import java.io.BufferedReader @@ -18,8 +19,8 @@ import java.nio.charset.StandardCharsets * * @param path the name of the file in the assets folder (+ path if needed) */ -fun AssetManager.loadEntriesFromAssets(path: String): MutableList { - val entries: MutableList = ArrayList() +fun AssetManager.loadEntriesFromAssets(path: String): MutableList> { + val entries: MutableList> = ArrayList() try { BufferedReader( diff --git a/chartLib/src/main/kotlin/info/appdev/charting/utils/Transformer.kt b/chartLib/src/main/kotlin/info/appdev/charting/utils/Transformer.kt index e43e58582..556eaab8d 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/utils/Transformer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/utils/Transformer.kt @@ -3,6 +3,7 @@ package info.appdev.charting.utils import android.graphics.Matrix import android.graphics.Path import android.graphics.RectF +import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.Entry import info.appdev.charting.interfaces.datasets.IBubbleDataSet import info.appdev.charting.interfaces.datasets.ICandleDataSet @@ -142,7 +143,7 @@ open class Transformer(protected var viewPortHandler: ViewPortHandler) { * y values transformed with all matrices for the LINECHART. */ fun generateTransformedValuesLine( - data: ILineDataSet, + data: ILineDataSet, Float>, phaseX: Float, phaseY: Float, min: Int, max: Int ): FloatArray { From c4423c14bb8ef49bb5708713e62c5a1eb29004b5 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Mon, 19 Jan 2026 08:23:10 +0100 Subject: [PATCH 3/5] RenameGenericXAxis --- .../charting/data/BarLineScatterCandleBubbleDataSet.kt | 4 ++-- .../main/kotlin/info/appdev/charting/data/BaseDataSet.kt | 2 +- .../src/main/kotlin/info/appdev/charting/data/DataSet.kt | 6 +++--- .../main/kotlin/info/appdev/charting/data/LineDataSet.kt | 8 ++++---- .../kotlin/info/appdev/charting/data/LineRadarDataSet.kt | 2 +- .../appdev/charting/data/LineScatterCandleRadarDataSet.kt | 4 ++-- .../datasets/IBarLineScatterCandleBubbleDataSet.kt | 2 +- .../info/appdev/charting/interfaces/datasets/IDataSet.kt | 2 +- .../appdev/charting/interfaces/datasets/ILineDataSet.kt | 2 +- .../charting/interfaces/datasets/ILineRadarDataSet.kt | 2 +- .../interfaces/datasets/ILineScatterCandleRadarDataSet.kt | 2 +- .../renderer/BarLineScatterCandleBubbleRenderer.kt | 4 ++-- screenShotScript | 2 +- 13 files changed, 21 insertions(+), 21 deletions(-) diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleDataSet.kt index cc6d8b32c..b3eb2c9cc 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleDataSet.kt @@ -7,8 +7,8 @@ import info.appdev.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataS /** * Baseclass of all DataSets for Bar-, Line-, Scatter- and CandleStickChart. */ -abstract class BarLineScatterCandleBubbleDataSet(yVals: MutableList, label: String) : - DataSet(yVals, label), IBarLineScatterCandleBubbleDataSet where T : BaseEntry, N : Number, N : Comparable { +abstract class BarLineScatterCandleBubbleDataSet(yVals: MutableList, label: String) : + DataSet(yVals, label), IBarLineScatterCandleBubbleDataSet where T : BaseEntry, N_XAxis : Number, N_XAxis : Comparable { /** * Sets the color that is used for drawing the highlight indicators. */ diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/BaseDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/BaseDataSet.kt index 0c6943e7f..cc1e3b029 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/BaseDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/BaseDataSet.kt @@ -19,7 +19,7 @@ import info.appdev.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 where T : BaseEntry, N : Number, N : Comparable { +abstract class BaseDataSet() : IDataSet where T : BaseEntry, N_XAxis : Number, N_XAxis : Comparable { /** * List representing all colors that are used for this DataSet */ diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/DataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/DataSet.kt index a17c82755..d6267b88d 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/DataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/DataSet.kt @@ -10,10 +10,10 @@ import kotlin.math.abs * 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( +abstract class DataSet( protected var mEntries: MutableList, label: String = "" -) : BaseDataSet(label), Serializable where T : BaseEntry, N : Number, N : Comparable { +) : BaseDataSet(label), Serializable where T : BaseEntry, N_XAxis : Number, N_XAxis : Comparable { /** * maximum y-value in the value array */ @@ -130,7 +130,7 @@ abstract class DataSet( /** * Provides an exact copy of the DataSet this method is used on. */ - abstract fun copy(): DataSet? + abstract fun copy(): DataSet? protected fun copy(dataSet: DataSet<*, *>) { super.copy(dataSet) diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/LineDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/LineDataSet.kt index 51d03d233..3b975a20b 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/LineDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/LineDataSet.kt @@ -12,8 +12,8 @@ import info.appdev.charting.utils.ColorTemplate import info.appdev.charting.utils.convertDpToPixel import timber.log.Timber -open class LineDataSet(yVals: MutableList = mutableListOf(), label: String = "") : LineRadarDataSet(yVals, label), ILineDataSet - where T : BaseEntry, N : Number, N : Comparable { +open class LineDataSet(yVals: MutableList = mutableListOf(), label: String = "") : LineRadarDataSet(yVals, label), ILineDataSet + where T : BaseEntry, N_XAxis : Number, N_XAxis : Comparable { /** * Drawing mode for this line dataset */ @@ -74,7 +74,7 @@ open class LineDataSet(yVals: MutableList = mutableListOf(), label: Str circleColors.add(Color.rgb(140, 234, 255)) } - override fun copy(): DataSet? { + override fun copy(): DataSet? { val entries: MutableList = mutableListOf() entries.addAll(mEntries) val copied = LineDataSet(entries, label) @@ -82,7 +82,7 @@ open class LineDataSet(yVals: MutableList = mutableListOf(), label: Str return copied } - protected fun copy(lineDataSet: LineDataSet) { + protected fun copy(lineDataSet: LineDataSet) { super.copy(lineDataSet) lineDataSet.circleColors = this.circleColors lineDataSet.mCircleHoleColor = this.mCircleHoleColor diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/LineRadarDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/LineRadarDataSet.kt index 8c04703ab..e2afaaf02 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/LineRadarDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/LineRadarDataSet.kt @@ -9,7 +9,7 @@ import info.appdev.charting.utils.convertDpToPixel /** * Base dataset for line and radar DataSets. */ -abstract class LineRadarDataSet(yVals: MutableList, label: String) : LineScatterCandleRadarDataSet(yVals, label), ILineRadarDataSet where T : BaseEntry, N : Number, N : Comparable { +abstract class LineRadarDataSet(yVals: MutableList, label: String) : LineScatterCandleRadarDataSet(yVals, label), ILineRadarDataSet where T : BaseEntry, N_XAxis : Number, N_XAxis : Comparable { // TODO: Move to using `Fill` class /** * the color that is used for filling the line surface diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/LineScatterCandleRadarDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/LineScatterCandleRadarDataSet.kt index f4acdbff5..e8151a964 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/LineScatterCandleRadarDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/LineScatterCandleRadarDataSet.kt @@ -4,8 +4,8 @@ import android.graphics.DashPathEffect import info.appdev.charting.interfaces.datasets.ILineScatterCandleRadarDataSet import info.appdev.charting.utils.convertDpToPixel -abstract class LineScatterCandleRadarDataSet(yVals: MutableList, label: String) : BarLineScatterCandleBubbleDataSet(yVals, label), - ILineScatterCandleRadarDataSet where T : BaseEntry, N : Number, N : Comparable { +abstract class LineScatterCandleRadarDataSet(yVals: MutableList, label: String) : BarLineScatterCandleBubbleDataSet(yVals, label), + ILineScatterCandleRadarDataSet where T : BaseEntry, N_XAxis : Number, N_XAxis : Comparable { override var isVerticalHighlightIndicator: Boolean = true override var isHorizontalHighlightIndicator: Boolean = true diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.kt index a442a6e28..d49b93203 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.kt @@ -2,7 +2,7 @@ package info.appdev.charting.interfaces.datasets import info.appdev.charting.data.BaseEntry -interface IBarLineScatterCandleBubbleDataSet : IDataSet where T : BaseEntry, N : Number, N : Comparable { +interface IBarLineScatterCandleBubbleDataSet : IDataSet where T : BaseEntry, N_XAxis : Number, N_XAxis : Comparable { val highLightColor: Int } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IDataSet.kt index 0e8808c01..a0f75cf1d 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IDataSet.kt @@ -9,7 +9,7 @@ import info.appdev.charting.data.DataSet import info.appdev.charting.formatter.IValueFormatter import info.appdev.charting.utils.PointF -interface IDataSet where T : BaseEntry, N : Number, N : Comparable { +interface IDataSet where T : BaseEntry, N_XAxis : Number, N_XAxis : Comparable { /** * returns the minimum y-value this DataSet holds */ diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineDataSet.kt index b1232eb72..cdfb6876f 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineDataSet.kt @@ -5,7 +5,7 @@ import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.LineDataSet import info.appdev.charting.formatter.IFillFormatter -interface ILineDataSet : ILineRadarDataSet where T : BaseEntry, N : Number, N : Comparable { +interface ILineDataSet : ILineRadarDataSet where T : BaseEntry, N_XAxis : Number, N_XAxis : Comparable { /** * Returns the drawing mode for this line dataset */ diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineRadarDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineRadarDataSet.kt index ab845c46e..d9750157c 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineRadarDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineRadarDataSet.kt @@ -3,7 +3,7 @@ package info.appdev.charting.interfaces.datasets import android.graphics.drawable.Drawable import info.appdev.charting.data.BaseEntry -interface ILineRadarDataSet : ILineScatterCandleRadarDataSet where T : BaseEntry, N : Number, N : Comparable { +interface ILineRadarDataSet : ILineScatterCandleRadarDataSet where T : BaseEntry, N_XAxis : Number, N_XAxis : Comparable { /** * Returns the color that is used for filling the line surface area. */ diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineScatterCandleRadarDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineScatterCandleRadarDataSet.kt index d12a8d936..3ccfa796f 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineScatterCandleRadarDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineScatterCandleRadarDataSet.kt @@ -3,7 +3,7 @@ package info.appdev.charting.interfaces.datasets import android.graphics.DashPathEffect import info.appdev.charting.data.BaseEntry -interface ILineScatterCandleRadarDataSet : IBarLineScatterCandleBubbleDataSet where T : BaseEntry, N : Number, N : Comparable { +interface ILineScatterCandleRadarDataSet : IBarLineScatterCandleBubbleDataSet where T : BaseEntry, N_XAxis : Number, N_XAxis : Comparable { /** * Returns true if vertical highlight indicator lines are enabled (drawn) */ diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/BarLineScatterCandleBubbleRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/BarLineScatterCandleBubbleRenderer.kt index 3164eea62..42d4aab4a 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/BarLineScatterCandleBubbleRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/BarLineScatterCandleBubbleRenderer.kt @@ -29,7 +29,7 @@ abstract class BarLineScatterCandleBubbleRenderer( /** * Checks if the provided entry object is in bounds for drawing considering the current animation phase. */ - protected fun isInBoundsX(entry: T, set: IBarLineScatterCandleBubbleDataSet): Boolean where T : BaseEntry, N : Number, N : Comparable { + protected fun isInBoundsX(entry: T, set: IBarLineScatterCandleBubbleDataSet): Boolean where T : BaseEntry, N_XAxis : Number, N_XAxis : Comparable { val entryIndex = set.getEntryIndex(entry).toFloat() return if (entryIndex >= set.entryCount * animator.phaseX) { @@ -61,7 +61,7 @@ abstract class BarLineScatterCandleBubbleRenderer( /** * Calculates the minimum and maximum x values as well as the range between them. */ - fun set(chart: BarLineScatterCandleBubbleDataProvider<*>, dataSet: IBarLineScatterCandleBubbleDataSet) where T : BaseEntry, N : Number, N : Comparable { + fun set(chart: BarLineScatterCandleBubbleDataProvider<*>, dataSet: IBarLineScatterCandleBubbleDataSet) where T : BaseEntry, N_XAxis : Number, N_XAxis : Comparable { val phaseX = max(0f, min(1f, animator.phaseX)) val low = chart.lowestVisibleX diff --git a/screenShotScript b/screenShotScript index 80bd9ac62..2bd3ed9fa 160000 --- a/screenShotScript +++ b/screenShotScript @@ -1 +1 @@ -Subproject commit 80bd9ac62359db716803f3375968d5be93dbdc76 +Subproject commit 2bd3ed9facbe372e78747528088d19b63255a9fc From d4bebd6a8937c650f733f6d0e1c74defb4e2b900 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Mon, 19 Jan 2026 08:40:00 +0100 Subject: [PATCH 4/5] Use EntryDouble --- .../chartexample/CubicLineChartActivity.kt | 8 ++++---- .../chartexample/LineChartTimeActivity.kt | 18 +++++++++-------- .../BarLineScatterCandleBubbleDataDouble.kt | 20 +++++++++++++++++++ .../appdev/charting/data/LineDataDouble.kt | 14 +++++++++++++ 4 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleDataDouble.kt create mode 100644 chartLib/src/main/kotlin/info/appdev/charting/data/LineDataDouble.kt diff --git a/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt index 513c8dddc..def8138b4 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt @@ -84,7 +84,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) { @@ -92,11 +92,11 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener { values.add(Entry(i.toFloat(), `val`)) } - val set1: LineDataSet + val set1: LineDataSet, Float> if (binding.chart1.lineData.dataSetCount > 0) { - set1 = binding.chart1.lineData.getDataSetByIndex(0) as LineDataSet - set1.entries = values + set1 = binding.chart1.lineData.getDataSetByIndex(0) as LineDataSet, Float> + set1.entries = values.toMutableList() binding.chart1.lineData.notifyDataChanged() binding.chart1.notifyDataSetChanged() } else { diff --git a/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt index fd1a1bb72..0bbf3b38f 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt @@ -19,7 +19,9 @@ import info.appdev.charting.components.XAxis import info.appdev.charting.components.YAxis import info.appdev.charting.components.YAxis.AxisDependency import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryDouble import info.appdev.charting.data.LineData +import info.appdev.charting.data.LineDataDouble import info.appdev.charting.data.LineDataSet import info.appdev.charting.formatter.IAxisValueFormatter import info.appdev.charting.utils.ColorTemplate.holoBlue @@ -105,20 +107,20 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener { val now: Long = 0 //470044; //TimeUnit.MILLISECONDS.toHours(System.currentTimeMillis()); - val values = ArrayList() + val values = ArrayList() // count = hours - val to = (now + count).toFloat() + val to = (now + count).toDouble() val valuesData = getValues(to.roundToInt()) // increment by 1 hour - var x = now.toFloat() + var x = now.toDouble() while (x < to) { - val y: Float = if (count == 100) // initial - (valuesData[x.roundToInt()])!!.toFloat() * 50 + 50 - else (Math.random() * 50 + 50).toFloat() // manually triggered + val y: Double = if (count == 100) // initial + (valuesData[x.roundToInt()])!! * 50 + 50 + else (Math.random() * 50 + 50) // manually triggered - values.add(Entry(x, y)) // add one entry per hour + values.add(EntryDouble(x, y)) // add one entry per hour x++ } @@ -136,7 +138,7 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener { set1.isDrawCircleHoleEnabled = false // create a data object with the data sets - val data = LineData(set1) + val data = LineDataDouble(set1) data.setValueTextColor(Color.WHITE) data.setValueTextSize(9f) diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleDataDouble.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleDataDouble.kt new file mode 100644 index 000000000..efcd9513b --- /dev/null +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleDataDouble.kt @@ -0,0 +1,20 @@ +package info.appdev.charting.data + +import info.appdev.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet +import info.appdev.charting.interfaces.datasets.IDataSet + +/** + * Baseclass for all Line, Bar, Scatter, Candle and Bubble data. + */ +abstract class BarLineScatterCandleBubbleDataDouble : ChartData<@UnsafeVariance T> + where T : IDataSet, Double>, + T : IBarLineScatterCandleBubbleDataSet, Double> { + + constructor() : super() + + @Suppress("UNCHECKED_CAST") + constructor(vararg sets: @UnsafeVariance T) : super(*sets) + + @Suppress("UNCHECKED_CAST") + constructor(sets: MutableList<@UnsafeVariance T>) : super(sets) +} diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/LineDataDouble.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/LineDataDouble.kt new file mode 100644 index 000000000..2eef76b8a --- /dev/null +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/LineDataDouble.kt @@ -0,0 +1,14 @@ +package info.appdev.charting.data + +import info.appdev.charting.interfaces.datasets.ILineDataSet + +/** + * Data object that encapsulates all data associated with a LineChart. + */ +class LineDataDouble : BarLineScatterCandleBubbleDataDouble, Double>> { + constructor() : super() + + constructor(vararg dataSets: ILineDataSet, Double>) : super(*dataSets) + + constructor(dataSets: MutableList, Double>>) : super(dataSets) +} From 947b546f5f9d6b12377505644f10d711520a519f Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Tue, 20 Jan 2026 20:18:46 +0100 Subject: [PATCH 5/5] Next --- .../chartexample/LineChartTimeActivity.kt | 27 ++++++----- .../chartexample/listviewitems/ChartItem.kt | 2 +- .../charting/charts/BarLineChartBase.kt | 2 +- .../info/appdev/charting/charts/Chart.kt | 2 +- .../info/appdev/charting/charts/LineChart.kt | 22 ++++----- .../charting/charts/PieRadarChartBase.kt | 6 +-- .../info/appdev/charting/data/BarData.kt | 2 +- .../data/BarLineScatterCandleBubbleData.kt | 8 ++-- .../BarLineScatterCandleBubbleDataDouble.kt | 4 +- .../info/appdev/charting/data/BubbleData.kt | 2 +- .../info/appdev/charting/data/CandleData.kt | 2 +- .../info/appdev/charting/data/ChartData.kt | 47 +++++++++++-------- .../info/appdev/charting/data/CombinedData.kt | 16 ++++--- .../info/appdev/charting/data/LineData.kt | 2 +- .../info/appdev/charting/data/PieData.kt | 2 +- .../info/appdev/charting/data/RadarData.kt | 2 +- .../info/appdev/charting/data/ScatterData.kt | 2 +- .../charting/highlight/ChartHighlighter.kt | 4 +- .../charting/highlight/CombinedHighlighter.kt | 2 +- .../dataprovider/LineDataProvider.kt | 6 +-- .../BarLineScatterCandleBubbleDataProvider.kt | 2 +- .../dataprovider/base/IBaseProvider.kt | 2 +- .../listener/BarLineChartTouchListener.kt | 4 +- .../renderer/CombinedChartRenderer.kt | 2 +- .../charting/renderer/LegendRenderer.kt | 2 +- .../charting/renderer/LineChartRenderer.kt | 18 ++++--- 26 files changed, 104 insertions(+), 88 deletions(-) diff --git a/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt index 0bbf3b38f..adbc281a8 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt @@ -18,12 +18,11 @@ import info.appdev.charting.components.AxisBase import info.appdev.charting.components.XAxis import info.appdev.charting.components.YAxis import info.appdev.charting.components.YAxis.AxisDependency -import info.appdev.charting.data.Entry import info.appdev.charting.data.EntryDouble -import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataDouble import info.appdev.charting.data.LineDataSet import info.appdev.charting.formatter.IAxisValueFormatter +import info.appdev.charting.interfaces.datasets.ILineDataSet import info.appdev.charting.utils.ColorTemplate.holoBlue import java.text.SimpleDateFormat import java.util.Date @@ -161,7 +160,7 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener { } R.id.actionToggleValues -> { - binding.chart1.lineData.dataSets.forEach { + binding.chart1.data?.dataSets?.forEach { it.isDrawValues = !it.isDrawValues } binding.chart1.invalidate() @@ -176,34 +175,40 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener { R.id.actionToggleFilled -> { binding.chart1.data?.dataSets?.forEach { set -> - set.isDrawFilled = !set.isDrawFilled + @Suppress("UNCHECKED_CAST") + (set as ILineDataSet<*, *>).isDrawFilled = !set.isDrawFilled } binding.chart1.invalidate() } R.id.actionToggleCircles -> { binding.chart1.data?.dataSets?.forEach { set -> - set.isDrawCircles = !set.isDrawCircles + @Suppress("UNCHECKED_CAST") + (set as ILineDataSet<*, *>).isDrawCircles = !set.isDrawCircles } binding.chart1.invalidate() } R.id.actionToggleCubic -> { binding.chart1.data?.dataSets?.forEach { set -> - if (set.lineMode == LineDataSet.Mode.CUBIC_BEZIER) - set.lineMode = LineDataSet.Mode.LINEAR + @Suppress("UNCHECKED_CAST") + val lineSet = set as ILineDataSet<*, *> + if (lineSet.lineMode == LineDataSet.Mode.CUBIC_BEZIER) + lineSet.lineMode = LineDataSet.Mode.LINEAR else - set.lineMode = LineDataSet.Mode.CUBIC_BEZIER + lineSet.lineMode = LineDataSet.Mode.CUBIC_BEZIER } binding.chart1.invalidate() } R.id.actionToggleStepped -> { binding.chart1.data?.dataSets?.forEach { set -> - if (set.lineMode == LineDataSet.Mode.STEPPED) - set.lineMode = LineDataSet.Mode.LINEAR + @Suppress("UNCHECKED_CAST") + val lineSet = set as ILineDataSet<*, *> + if (lineSet.lineMode == LineDataSet.Mode.STEPPED) + lineSet.lineMode = LineDataSet.Mode.LINEAR else - set.lineMode = LineDataSet.Mode.STEPPED + lineSet.lineMode = LineDataSet.Mode.STEPPED } binding.chart1.invalidate() } diff --git a/app/src/main/kotlin/info/appdev/chartexample/listviewitems/ChartItem.kt b/app/src/main/kotlin/info/appdev/chartexample/listviewitems/ChartItem.kt index 2a3f5b4c7..54d936a8a 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/listviewitems/ChartItem.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/listviewitems/ChartItem.kt @@ -8,7 +8,7 @@ import info.appdev.charting.data.ChartData * Base class of the Chart ListView items */ @Suppress("unused") -abstract class ChartItem> internal constructor(var chartData: T) { +abstract class ChartItem> internal constructor(var chartData: T) { abstract val itemType: Int abstract fun getView(position: Int, convertView: View?, context: Context?): View? diff --git a/chartLib/src/main/kotlin/info/appdev/charting/charts/BarLineChartBase.kt b/chartLib/src/main/kotlin/info/appdev/charting/charts/BarLineChartBase.kt index d57f16da6..be4d1d693 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/charts/BarLineChartBase.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/charts/BarLineChartBase.kt @@ -47,7 +47,7 @@ import kotlin.math.min */ @Suppress("unused") @SuppressLint("RtlHardcoded") -abstract class BarLineChartBase, Float>>> : Chart, +abstract class BarLineChartBase> : Chart, BarLineScatterCandleBubbleDataProvider { /** * the maximum number of entries to which values will be drawn diff --git a/chartLib/src/main/kotlin/info/appdev/charting/charts/Chart.kt b/chartLib/src/main/kotlin/info/appdev/charting/charts/Chart.kt index fa0521a7b..b758d1c54 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/charts/Chart.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/charts/Chart.kt @@ -50,7 +50,7 @@ import kotlin.math.abs import kotlin.math.max @Suppress("unused") -abstract class Chart, Float>>> : ViewGroup, IBaseProvider { +abstract class Chart> : ViewGroup, IBaseProvider { /** * Returns true if log-output is enabled for the chart, fals if not. */ diff --git a/chartLib/src/main/kotlin/info/appdev/charting/charts/LineChart.kt b/chartLib/src/main/kotlin/info/appdev/charting/charts/LineChart.kt index 86e53df5a..044d924b3 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/charts/LineChart.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/charts/LineChart.kt @@ -2,12 +2,12 @@ package info.appdev.charting.charts import android.content.Context import android.util.AttributeSet -import info.appdev.charting.data.LineData +import info.appdev.charting.data.BarLineScatterCandleBubbleData import info.appdev.charting.interfaces.dataprovider.LineDataProvider import info.appdev.charting.renderer.LineChartRenderer import java.util.Locale -open class LineChart : BarLineChartBase, LineDataProvider { +open class LineChart : BarLineChartBase>, LineDataProvider { constructor(context: Context?) : super(context) constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) @@ -18,12 +18,8 @@ open class LineChart : BarLineChartBase, LineDataProvider { dataRenderer = LineChartRenderer(this, mAnimator, viewPortHandler) } - override var lineData: LineData - get() { - return mData ?: run { - LineData() - } - } + override var lineData: BarLineScatterCandleBubbleData<*, *>? + get() = mData set(value) { mData = value notifyDataSetChanged() @@ -40,17 +36,17 @@ open class LineChart : BarLineChartBase, LineDataProvider { override val accessibilityDescription: String get() { val lineData = lineData - val numberOfPoints = lineData.entryCount + val numberOfPoints = lineData?.entryCount ?: 0 // Min and max values... val yAxisValueFormatter = axisLeft.valueFormatter - val minVal = yAxisValueFormatter?.getFormattedValue(lineData.yMin, null) - val maxVal = yAxisValueFormatter?.getFormattedValue(lineData.yMax, null) + val minVal = yAxisValueFormatter?.getFormattedValue(lineData?.yMin ?: 0f, null) + val maxVal = yAxisValueFormatter?.getFormattedValue(lineData?.yMax ?: 0f, null) // Data range... val xAxisValueFormatter = xAxis.valueFormatter - val minRange = xAxisValueFormatter?.getFormattedValue(lineData.xMin, null) - val maxRange = xAxisValueFormatter?.getFormattedValue(lineData.xMax, null) + val minRange = xAxisValueFormatter?.getFormattedValue(lineData?.xMin ?: 0f, null) + val maxRange = xAxisValueFormatter?.getFormattedValue(lineData?.xMax ?: 0f, null) val entries = if (numberOfPoints == 1) "entry" else "entries" return String.format( Locale.getDefault(), "The line chart has %d %s. " + diff --git a/chartLib/src/main/kotlin/info/appdev/charting/charts/PieRadarChartBase.kt b/chartLib/src/main/kotlin/info/appdev/charting/charts/PieRadarChartBase.kt index 433c95c5c..7dd66c709 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/charts/PieRadarChartBase.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/charts/PieRadarChartBase.kt @@ -9,9 +9,7 @@ import info.appdev.charting.animation.Easing.EasingFunction import info.appdev.charting.components.Legend.LegendHorizontalAlignment import info.appdev.charting.components.Legend.LegendOrientation import info.appdev.charting.components.Legend.LegendVerticalAlignment -import info.appdev.charting.data.BaseEntry import info.appdev.charting.data.ChartData -import info.appdev.charting.interfaces.datasets.IDataSet import info.appdev.charting.listener.PieRadarChartTouchListener import info.appdev.charting.utils.PointF import info.appdev.charting.utils.PointF.Companion.getInstance @@ -28,9 +26,9 @@ import kotlin.math.sin import kotlin.math.sqrt /** - * Baseclass of PieChart and RadarChart. + * Baseclass of PieChart and yyRadarChart. */ -abstract class PieRadarChartBase, Float>>> +abstract class PieRadarChartBase> : Chart { /** * holds the normalized version of the current rotation angle of the chart diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/BarData.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/BarData.kt index 73cf0a7db..47843c75e 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/BarData.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/BarData.kt @@ -5,7 +5,7 @@ import info.appdev.charting.interfaces.datasets.IBarDataSet /** * Data object that represents all data for the BarChart. */ -class BarData : BarLineScatterCandleBubbleData { +class BarData : BarLineScatterCandleBubbleData { /** * Sets the width each bar should have on the x-axis (in values, not pixels). * Default 0.85f diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleData.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleData.kt index f50c7b44d..8ed9e57b1 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleData.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleData.kt @@ -6,9 +6,11 @@ import info.appdev.charting.interfaces.datasets.IDataSet /** * Baseclass for all Line, Bar, Scatter, Candle and Bubble data. */ -abstract class BarLineScatterCandleBubbleData : ChartData<@UnsafeVariance T> - where T : IDataSet, Float>, - T : IBarLineScatterCandleBubbleDataSet, Float> { +abstract class BarLineScatterCandleBubbleData : ChartData<@UnsafeVariance T, N> + where T : IDataSet, N>, + T : IBarLineScatterCandleBubbleDataSet, N>, + N : Number, + N : Comparable { constructor() : super() diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleDataDouble.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleDataDouble.kt index efcd9513b..b8afed296 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleDataDouble.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleDataDouble.kt @@ -4,9 +4,9 @@ import info.appdev.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataS import info.appdev.charting.interfaces.datasets.IDataSet /** - * Baseclass for all Line, Bar, Scatter, Candle and Bubble data. + * Baseclass for all Line, Bar, Scatter, Candle and Bubble data with Double precision. */ -abstract class BarLineScatterCandleBubbleDataDouble : ChartData<@UnsafeVariance T> +abstract class BarLineScatterCandleBubbleDataDouble : ChartData<@UnsafeVariance T, Double> where T : IDataSet, Double>, T : IBarLineScatterCandleBubbleDataSet, Double> { diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/BubbleData.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/BubbleData.kt index 4af8a60bb..6f8aec966 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/BubbleData.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/BubbleData.kt @@ -2,7 +2,7 @@ package info.appdev.charting.data import info.appdev.charting.interfaces.datasets.IBubbleDataSet -class BubbleData : BarLineScatterCandleBubbleData { +class BubbleData : BarLineScatterCandleBubbleData { constructor() : super() constructor(dataSets: MutableList) : super(dataSets) diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/CandleData.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/CandleData.kt index 01bc47201..2283a34cf 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/CandleData.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/CandleData.kt @@ -2,7 +2,7 @@ package info.appdev.charting.data import info.appdev.charting.interfaces.datasets.ICandleDataSet -class CandleData : BarLineScatterCandleBubbleData { +class CandleData : BarLineScatterCandleBubbleData { constructor() : super() constructor(vararg dataSets: ICandleDataSet) : super(*dataSets) diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/ChartData.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/ChartData.kt index b3ff63df0..5caeabb30 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/ChartData.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/ChartData.kt @@ -12,7 +12,10 @@ import java.io.Serializable * Class that holds all relevant data that represents the chart. That involves at least one (or more) DataSets, and an array of x-values. */ @Suppress("unused") -abstract class ChartData : Serializable where T : IDataSet, Float> { +abstract class ChartData : Serializable + where T : IDataSet, N>, + N : Number, + N : Comparable { /** * maximum y-value in the value array across all axes */ @@ -243,7 +246,7 @@ abstract class ChartData : Serializable where T : IDataSet? { + open fun getEntryForHighlight(highlight: Highlight): BaseEntry? { return if (highlight.dataSetIndex >= dataSets.size) { null } else { @@ -336,7 +339,8 @@ abstract class ChartData : Serializable where T : IDataSet, set.axisDependency) } else { Timber.e("Cannot add Entry because dataSetIndex too high or too low.") } @@ -345,34 +349,37 @@ abstract class ChartData : Serializable where T : IDataSet, axis: AxisDependency?) { + val yFloat = e.y.toFloat() + val xFloat = e.x.toFloat() + + if (this.yMax < yFloat) { + this.yMax = yFloat } - if (this.yMin > e.y) { - this.yMin = e.y + if (this.yMin > yFloat) { + this.yMin = yFloat } - if (this.xMax < e.x) { - this.xMax = e.x + if (this.xMax < xFloat) { + this.xMax = xFloat } - if (this.xMin > e.x) { - this.xMin = e.x + if (this.xMin > xFloat) { + this.xMin = xFloat } if (axis == AxisDependency.LEFT) { - if (mLeftAxisMax < e.y) { - mLeftAxisMax = e.y + if (mLeftAxisMax < yFloat) { + mLeftAxisMax = yFloat } - if (mLeftAxisMin > e.y) { - mLeftAxisMin = e.y + if (mLeftAxisMin > yFloat) { + mLeftAxisMin = yFloat } } else { - if (mRightAxisMax < e.y) { - mRightAxisMax = e.y + if (mRightAxisMax < yFloat) { + mRightAxisMax = yFloat } - if (mRightAxisMin > e.y) { - mRightAxisMin = e.y + if (mRightAxisMin > yFloat) { + mRightAxisMin = yFloat } } } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/CombinedData.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/CombinedData.kt index 7f7d030a3..e7ef5aa6e 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/CombinedData.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/CombinedData.kt @@ -9,7 +9,7 @@ import timber.log.Timber * Data object that allows the combination of Line-, Bar-, Scatter-, Bubble- and * CandleData. Used in the CombinedChart class. */ -class CombinedData : BarLineScatterCandleBubbleData, Float>>() { +class CombinedData : BarLineScatterCandleBubbleData, Float>, Float>() { var lineData: LineData? = null private set var barData: BarData? = null @@ -65,7 +65,8 @@ class CombinedData : BarLineScatterCandleBubbleData, Float>>) if (data.yMax > yMax) yMax = data.yMax @@ -97,12 +98,12 @@ class CombinedData : BarLineScatterCandleBubbleData> + val allData: MutableList> /** * Returns all data objects in row: line-bar-scatter-candle-bubble if not null. */ get() { - val data: MutableList> = ArrayList>() + val data: MutableList> = ArrayList>() if (this.lineData != null) data.add(this.lineData!!) if (this.barData != null) data.add(this.barData!!) if (this.scatterData != null) data.add(this.scatterData!!) @@ -112,7 +113,7 @@ class CombinedData : BarLineScatterCandleBubbleData { + fun getDataByIndex(index: Int): BarLineScatterCandleBubbleData<*, *> { return this.allData[index] } @@ -134,7 +135,7 @@ class CombinedData : BarLineScatterCandleBubbleData= this.allData.size || highlight.dataIndex < 0) return null - val data: ChartData<*> = getDataByIndex(highlight.dataIndex) + val data: ChartData<*, *> = getDataByIndex(highlight.dataIndex) if (highlight.dataSetIndex >= data.dataSetCount) return null @@ -165,10 +166,11 @@ class CombinedData : BarLineScatterCandleBubbleData= data.dataSetCount) return null + @Suppress("UNCHECKED_CAST") return data.dataSets[highlight.dataSetIndex] as IBarLineScatterCandleBubbleDataSet, Float>? } - fun getDataIndex(data: ChartData<*>?): Int { + fun getDataIndex(data: ChartData<*, *>?): Int { return this.allData.indexOf(data) } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/LineData.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/LineData.kt index 6453823eb..a0721c8c5 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/LineData.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/LineData.kt @@ -5,7 +5,7 @@ import info.appdev.charting.interfaces.datasets.ILineDataSet /** * Data object that encapsulates all data associated with a LineChart. */ -class LineData : BarLineScatterCandleBubbleData, Float>> { +class LineData : BarLineScatterCandleBubbleData, Float>, Float> { constructor() : super() constructor(vararg dataSets: ILineDataSet, Float>) : super(*dataSets) diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/PieData.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/PieData.kt index 340488548..85fe77146 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/PieData.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/PieData.kt @@ -10,7 +10,7 @@ import timber.log.Timber * from the DataSet labels. Each PieData object can only represent one * PieDataSet (multiple PieDataSets inside a single PieChart are not possible). */ -class PieData : ChartData { +class PieData : ChartData { constructor(dataSet: IPieDataSet) : super(dataSet) diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/RadarData.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/RadarData.kt index fc5e4d8bb..6e57382c8 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/RadarData.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/RadarData.kt @@ -6,7 +6,7 @@ import info.appdev.charting.interfaces.datasets.IRadarDataSet /** * Data container for the RadarChart. */ -class RadarData : ChartData { +class RadarData : ChartData { /** * Sets the labels that should be drawn around the RadarChart at the end of each web line. */ diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/ScatterData.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/ScatterData.kt index e77b023fb..632a16283 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/ScatterData.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/ScatterData.kt @@ -2,7 +2,7 @@ package info.appdev.charting.data import info.appdev.charting.interfaces.datasets.IScatterDataSet -class ScatterData : BarLineScatterCandleBubbleData { +class ScatterData : BarLineScatterCandleBubbleData { constructor() : super() constructor(dataSets: MutableList) : super(dataSets) diff --git a/chartLib/src/main/kotlin/info/appdev/charting/highlight/ChartHighlighter.kt b/chartLib/src/main/kotlin/info/appdev/charting/highlight/ChartHighlighter.kt index b4c6fcd6c..b997dff6c 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/highlight/ChartHighlighter.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/highlight/ChartHighlighter.kt @@ -192,6 +192,6 @@ open class ChartHighlighter>(prote return hypot((x1 - x2).toDouble(), (y1 - y2).toDouble()).toFloat() } - protected open val data: ChartData<*>? - get() = provider.data + protected open val data: ChartData<*, *>? + get() = provider.data as ChartData<*, *>? } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/highlight/CombinedHighlighter.kt b/chartLib/src/main/kotlin/info/appdev/charting/highlight/CombinedHighlighter.kt index 989c25a73..740122aed 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/highlight/CombinedHighlighter.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/highlight/CombinedHighlighter.kt @@ -19,7 +19,7 @@ open class CombinedHighlighter(combinedDataProvider: CombinedDataProvider, barDa val dataObjects = provider.combinedData!!.allData for (i in dataObjects.indices) { - val dataObject: ChartData<*> = dataObjects[i] + val dataObject: ChartData<*, *> = dataObjects[i] // in case of BarData, let the BarHighlighter take over if (barHighlighter != null && dataObject is BarData) { diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/dataprovider/LineDataProvider.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/dataprovider/LineDataProvider.kt index aed4a98a2..1e239c78e 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/dataprovider/LineDataProvider.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/dataprovider/LineDataProvider.kt @@ -1,8 +1,8 @@ package info.appdev.charting.interfaces.dataprovider -import info.appdev.charting.data.LineData +import info.appdev.charting.data.BarLineScatterCandleBubbleData import info.appdev.charting.interfaces.dataprovider.base.BarLineScatterCandleBubbleDataProvider -interface LineDataProvider : BarLineScatterCandleBubbleDataProvider { - val lineData: LineData? +interface LineDataProvider : BarLineScatterCandleBubbleDataProvider> { + val lineData: BarLineScatterCandleBubbleData<*, *>? } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/dataprovider/base/BarLineScatterCandleBubbleDataProvider.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/dataprovider/base/BarLineScatterCandleBubbleDataProvider.kt index c07d33977..1ed4af345 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/dataprovider/base/BarLineScatterCandleBubbleDataProvider.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/dataprovider/base/BarLineScatterCandleBubbleDataProvider.kt @@ -4,7 +4,7 @@ import info.appdev.charting.components.YAxis import info.appdev.charting.data.BarLineScatterCandleBubbleData import info.appdev.charting.utils.Transformer -interface BarLineScatterCandleBubbleDataProvider> : IBaseProvider { +interface BarLineScatterCandleBubbleDataProvider> : IBaseProvider { fun getTransformer(axis: YAxis.AxisDependency?): Transformer? fun isInverted(axis: YAxis.AxisDependency?): Boolean val lowestVisibleX: Float diff --git a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/dataprovider/base/IBaseProvider.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/dataprovider/base/IBaseProvider.kt index 1c1ca0e1b..d2641ee13 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/interfaces/dataprovider/base/IBaseProvider.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/dataprovider/base/IBaseProvider.kt @@ -9,7 +9,7 @@ import info.appdev.charting.utils.PointF * Interface that provides everything there is to know about the dimensions, * bounds, and range of the chart. */ -interface IBaseProvider> { +interface IBaseProvider> { /** * Returns the minimum x value of the chart, regardless of zoom or translation. */ diff --git a/chartLib/src/main/kotlin/info/appdev/charting/listener/BarLineChartTouchListener.kt b/chartLib/src/main/kotlin/info/appdev/charting/listener/BarLineChartTouchListener.kt index f83ebad87..e3e59c038 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/listener/BarLineChartTouchListener.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/listener/BarLineChartTouchListener.kt @@ -25,11 +25,11 @@ import kotlin.math.sqrt */ @Suppress("MemberVisibilityCanBePrivate") class BarLineChartTouchListener( - chart: BarLineChartBase, Float>>>, + chart: BarLineChartBase, Float>, Float>>, touchMatrix: Matrix, dragTriggerDistance: Float ) : - ChartTouchListener, Float>>>>(chart) { + ChartTouchListener, Float>, Float>>>(chart) { /** * the original touch-matrix from the chart */ diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/CombinedChartRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/CombinedChartRenderer.kt index ad8c1cb9e..4fb2c5221 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/CombinedChartRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/CombinedChartRenderer.kt @@ -81,7 +81,7 @@ open class CombinedChartRenderer( val chart = weakChart.get() ?: return dataRenderers.forEach { renderer -> - var data: ChartData<*>? = null + var data: ChartData<*, *>? = null when (renderer) { is BarChartRenderer -> data = renderer.dataProvider.barData diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/LegendRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/LegendRenderer.kt index 408f57dbb..32bb3ba29 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/LegendRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/LegendRenderer.kt @@ -45,7 +45,7 @@ open class LegendRenderer( /** * Prepares the legend and calculates all needed forms, labels and colors. */ - fun computeLegend(data: ChartData<*>) { + fun computeLegend(data: ChartData<*, *>) { if (!legend.isLegendCustom) { computedEntries.clear() diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/LineChartRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/LineChartRenderer.kt index b724966e4..713f6794c 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/LineChartRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/LineChartRenderer.kt @@ -14,6 +14,7 @@ import info.appdev.charting.interfaces.dataprovider.LineDataProvider import info.appdev.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet import info.appdev.charting.interfaces.datasets.IDataSet import info.appdev.charting.interfaces.datasets.ILineDataSet +import info.appdev.charting.interfaces.datasets.ILineScatterCandleRadarDataSet import info.appdev.charting.utils.ColorTemplate import info.appdev.charting.utils.PointF import info.appdev.charting.utils.Transformer @@ -79,8 +80,10 @@ open class LineChartRenderer( dataProvider.lineData?.let { lineData -> lineData.dataSets.forEach { set -> - if (set.isVisible) - drawDataSet(canvas, set) + if (set.isVisible) { + @Suppress("UNCHECKED_CAST") + drawDataSet(canvas, set as ILineDataSet, Float>) + } } } canvas.drawBitmap(drawBitmapLocal, 0f, 0f, null) @@ -479,7 +482,8 @@ open class LineChartRenderer( dataSets?.let { for (i in it.indices) { - val dataSet = dataSets[i] + @Suppress("UNCHECKED_CAST") + val dataSet = dataSets[i] as ILineDataSet, Float> if (dataSet.entryCount == 0) { continue } @@ -583,7 +587,8 @@ open class LineChartRenderer( dataSets?.let { for (i in it.indices) { - val dataSet = dataSets[i] + @Suppress("UNCHECKED_CAST") + val dataSet = dataSets[i] as ILineDataSet, Float> if (!dataSet.isVisible || !dataSet.isDrawCircles || dataSet.entryCount == 0) continue circlePaintInner.color = dataSet.circleHoleColor @@ -652,7 +657,7 @@ open class LineChartRenderer( set.getEntryForXValue(high.x, high.y)?.let { entry -> @Suppress("UNCHECKED_CAST") - if (!isInBoundsX(entry, set as IBarLineScatterCandleBubbleDataSet, Float>)) + if (!isInBoundsX(entry as BaseEntry, set as IBarLineScatterCandleBubbleDataSet, Float>)) continue val pix = dataProvider.getTransformer(set.axisDependency)!!.getPixelForValues( @@ -661,7 +666,8 @@ open class LineChartRenderer( high.setDraw(pix.x.toFloat(), pix.y.toFloat()) // draw the lines - drawHighlightLines(canvas, pix.x.toFloat(), pix.y.toFloat(), set) + @Suppress("UNCHECKED_CAST") + drawHighlightLines(canvas, pix.x.toFloat(), pix.y.toFloat(), set as ILineScatterCandleRadarDataSet<*, *>) } } }