From ce1c06e6b2517af1efa25be49080a7241cf9b3ca Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Tue, 6 Jan 2026 10:07:48 +0100 Subject: [PATCH] Datasets are not nullable --- .../chartexample/CubicLineChartActivity.kt | 12 +- .../chartexample/InvertedLineChartActivity.kt | 2 +- .../appdev/chartexample/LineChartActivity.kt | 2 +- .../chartexample/LineChartTimeActivity.kt | 2 +- .../chartexample/MultiLineChartActivity.kt | 2 +- .../appdev/chartexample/TimeLineActivity.kt | 2 +- .../info/appdev/charting/charts/Chart.kt | 2 +- .../info/appdev/charting/charts/PieChart.kt | 2 +- .../info/appdev/charting/data/BarData.kt | 29 +- .../info/appdev/charting/data/BubbleData.kt | 6 +- .../info/appdev/charting/data/ChartData.kt | 118 ++++--- .../info/appdev/charting/data/CombinedData.kt | 9 +- .../info/appdev/charting/data/PieData.kt | 28 +- .../info/appdev/charting/data/ScatterData.kt | 14 +- .../charting/highlight/PieHighlighter.kt | 2 +- .../charting/renderer/BubbleChartRenderer.kt | 112 ++++--- .../renderer/CandleStickChartRenderer.kt | 109 ++++--- .../charting/renderer/LineChartRenderer.kt | 2 +- .../charting/renderer/PieChartRenderer.kt | 290 +++++++++--------- .../charting/renderer/RadarChartRenderer.kt | 2 +- .../charting/renderer/ScatterChartRenderer.kt | 4 +- 21 files changed, 358 insertions(+), 393 deletions(-) diff --git a/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt index 8e793e9b1..8c6428ab9 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt @@ -145,7 +145,7 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener { } R.id.actionToggleValues -> { - binding.chart1.lineData.dataSets?.forEach { + binding.chart1.lineData.dataSets.forEach { it.isDrawValues = !it.isDrawValues } binding.chart1.invalidate() @@ -159,7 +159,7 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener { } R.id.actionToggleFilled -> { - binding.chart1.lineData.dataSets?.forEach { + binding.chart1.lineData.dataSets.forEach { val set = it as LineDataSet set.isDrawFilledEnabled = !set.isDrawFilledEnabled } @@ -167,7 +167,7 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener { } R.id.actionToggleCircles -> { - binding.chart1.lineData.dataSets?.forEach { + binding.chart1.lineData.dataSets.forEach { val set = it as LineDataSet set.isDrawCirclesEnabled = !set.isDrawCirclesEnabled } @@ -175,7 +175,7 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener { } R.id.actionToggleCubic -> { - binding.chart1.lineData.dataSets?.forEach { + binding.chart1.lineData.dataSets.forEach { val set = it as LineDataSet set.lineMode = if (set.lineMode == LineDataSet.Mode.CUBIC_BEZIER) LineDataSet.Mode.LINEAR @@ -186,7 +186,7 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener { } R.id.actionToggleStepped -> { - binding.chart1.lineData.dataSets?.forEach { + binding.chart1.lineData.dataSets.forEach { val set = it as LineDataSet set.lineMode = if (set.lineMode == LineDataSet.Mode.STEPPED) LineDataSet.Mode.LINEAR @@ -197,7 +197,7 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener { } R.id.actionToggleHorizontalCubic -> { - binding.chart1.lineData.dataSets?.forEach { + binding.chart1.lineData.dataSets.forEach { val set = it as LineDataSet set.lineMode = if (set.lineMode == LineDataSet.Mode.HORIZONTAL_BEZIER) LineDataSet.Mode.LINEAR diff --git a/app/src/main/kotlin/info/appdev/chartexample/InvertedLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/InvertedLineChartActivity.kt index f2757140f..0f558ad12 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/InvertedLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/InvertedLineChartActivity.kt @@ -132,7 +132,7 @@ class InvertedLineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa } R.id.actionToggleValues -> { - binding.chart1.lineData.dataSets?.forEach { + binding.chart1.lineData.dataSets.forEach { it.isDrawValues = !it.isDrawValues } binding.chart1.invalidate() diff --git a/app/src/main/kotlin/info/appdev/chartexample/LineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/LineChartActivity.kt index c89a83c42..c4a4c71a1 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/LineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/LineChartActivity.kt @@ -153,7 +153,7 @@ class LineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelec } R.id.actionToggleValues -> { - binding.chart1.lineData.dataSets?.forEach { set -> + binding.chart1.lineData.dataSets.forEach { set -> set.isDrawValues = !set.isDrawValues } binding.chart1.invalidate() diff --git a/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt index cbda5d3cc..2e97ebf67 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt @@ -159,7 +159,7 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener { } R.id.actionToggleValues -> { - binding.chart1.lineData.dataSets?.forEach { + binding.chart1.lineData.dataSets.forEach { it.isDrawValues = !it.isDrawValues } binding.chart1.invalidate() diff --git a/app/src/main/kotlin/info/appdev/chartexample/MultiLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/MultiLineChartActivity.kt index 9179971c7..bcf0dc45a 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/MultiLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/MultiLineChartActivity.kt @@ -130,7 +130,7 @@ class MultiLineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartGestu } R.id.actionToggleValues -> { - binding.chart1.lineData.dataSets?.forEach { set -> + binding.chart1.lineData.dataSets.forEach { set -> set.isDrawValues = !set.isDrawValues } binding.chart1.invalidate() diff --git a/app/src/main/kotlin/info/appdev/chartexample/TimeLineActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/TimeLineActivity.kt index c73084611..eee73b0a8 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/TimeLineActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/TimeLineActivity.kt @@ -159,7 +159,7 @@ class TimeLineActivity : DemoBase() { withContext(Dispatchers.Default) { while (menuItemMove!!.isChecked) { withContext(Dispatchers.Main) { - binding.chart1.lineData.dataSets?.get(0)?.let { set -> + binding.chart1.lineData.dataSets.get(0)?.let { set -> (set as LineDataSet).entries.moveFirstToLast() set.notifyDataChanged() binding.chart1.lineData.notifyDataChanged() 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 3a8e8ea46..1d2125e6f 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/charts/Chart.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/charts/Chart.kt @@ -1042,7 +1042,7 @@ abstract class Chart>> : ViewGroup, IBaseP // calculate how many digits are needed setupDefaultFormatter(value.yMin, value.yMax) - for (set in mData!!.dataSets!!) { + for (set in mData!!.dataSets) { if (set.needsFormatter() || set.valueFormatter === mDefaultValueFormatter) { set.valueFormatter = mDefaultValueFormatter } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/charts/PieChart.kt b/chartLib/src/main/kotlin/info/appdev/charting/charts/PieChart.kt index e12489ab7..032864a51 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/charts/PieChart.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/charts/PieChart.kt @@ -268,7 +268,7 @@ open class PieChart : PieRadarChartBase { var diff = 0f for (i in 0.. { */ fun groupBars(fromX: Float, groupSpace: Float, barSpace: Float) { var fromX = fromX - val setCount = dataSets?.size ?: 0 + val setCount = dataSets.size if (setCount <= 1) { throw RuntimeException("BarData needs to hold at least 2 BarDataSets to allow grouping.") } @@ -50,22 +50,20 @@ class BarData : BarLineScatterCandleBubbleData { val start = fromX fromX += groupSpaceWidthHalf - dataSets?.let { - for (set in dataSets) { - fromX += barSpaceHalf - fromX += barWidthHalf + for (set in dataSets) { + fromX += barSpaceHalf + fromX += barWidthHalf - if (i < set.entryCount) { - val entry = set.getEntryForIndex(i) + if (i < set.entryCount) { + val entry = set.getEntryForIndex(i) - if (entry != null) { - entry.x = fromX - } + if (entry != null) { + entry.x = fromX } - - fromX += barWidthHalf - fromX += barSpaceHalf } + + fromX += barWidthHalf + fromX += barSpaceHalf } fromX += groupSpaceWidthHalf val end = fromX @@ -85,9 +83,6 @@ class BarData : BarLineScatterCandleBubbleData { * In case of grouped bars, this method returns the space an individual group of bar needs on the x-axis. */ fun getGroupWidth(groupSpace: Float, barSpace: Float): Float { - return if (dataSets == null) - 0f - else - dataSets!!.size * (this.barWidth + barSpace) + groupSpace + return dataSets.size * (this.barWidth + barSpace) + groupSpace } } 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 9b1e66e2c..4af8a60bb 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/BubbleData.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/BubbleData.kt @@ -12,10 +12,8 @@ class BubbleData : BarLineScatterCandleBubbleData { * for all DataSet objects this data object contains, in dp. */ fun setHighlightCircleWidth(width: Float) { - if (dataSets != null) { - for (set in dataSets) { - set.highlightCircleWidth = width - } + for (set in dataSets) { + set.highlightCircleWidth = width } } } 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 b025e411c..8e66d784b 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/ChartData.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/ChartData.kt @@ -48,7 +48,7 @@ abstract class ChartData> : Serializable { /** * all DataSets the ChartData object represents */ - open var dataSets: MutableList? = null + open var dataSets: MutableList = mutableListOf() protected set constructor() { @@ -82,7 +82,7 @@ abstract class ChartData> : Serializable { * @param toX the x-value to which the calculation should be performed */ fun calcMinMaxY(fromX: Float, toX: Float) { - for (set in this.dataSets!!) { + for (set in this.dataSets) { set.calcMinMaxY(fromX, toX) } @@ -94,10 +94,6 @@ abstract class ChartData> : Serializable { * Calc minimum and maximum values (both x and y) over all DataSets. */ open fun calcMinMax() { - if (this.dataSets == null) { - return - } - this.yMax = -Float.MAX_VALUE this.yMin = Float.MAX_VALUE this.xMax = -Float.MAX_VALUE @@ -113,7 +109,7 @@ abstract class ChartData> : Serializable { mRightAxisMin = Float.MAX_VALUE // left axis - val firstLeft = getFirstLeft(this.dataSets!!) + val firstLeft = getFirstLeft(this.dataSets) if (firstLeft != null) { mLeftAxisMax = firstLeft.yMax @@ -133,7 +129,7 @@ abstract class ChartData> : Serializable { } // right axis - val firstRight = getFirstRight(this.dataSets!!) + val firstRight = getFirstRight(this.dataSets) if (firstRight != null) { mRightAxisMax = firstRight.yMax @@ -158,10 +154,7 @@ abstract class ChartData> : Serializable { */ val dataSetCount: Int get() { - if (this.dataSets == null) { - return 0 - } - return dataSets!!.size + return dataSets.size } /** @@ -237,10 +230,10 @@ abstract class ChartData> : Serializable { */ val dataSetLabels: Array get() { - val types = arrayOfNulls(dataSets!!.size) + val types = arrayOfNulls(dataSets.size) - for (i in dataSets!!.indices) { - types[i] = dataSets!![i].label + for (i in dataSets.indices) { + types[i] = dataSets[i].label } return types @@ -251,10 +244,10 @@ abstract class ChartData> : Serializable { * @return the entry that is highlighted */ open fun getEntryForHighlight(highlight: Highlight): Entry? { - return if (highlight.dataSetIndex >= dataSets!!.size) { + return if (highlight.dataSetIndex >= dataSets.size) { null } else { - dataSets!![highlight.dataSetIndex].getEntryForXValue(highlight.x, highlight.y) + dataSets[highlight.dataSetIndex].getEntryForXValue(highlight.x, highlight.y) } } @@ -264,21 +257,21 @@ abstract class ChartData> : Serializable { * Use with care in performance critical situations. */ open fun getDataSetByLabel(label: String, ignoreCase: Boolean): T? { - val index = getDataSetIndexByLabel(this.dataSets!!, label, ignoreCase) + val index = getDataSetIndexByLabel(this.dataSets, label, ignoreCase) - return if (index < 0 || index >= dataSets!!.size) { + return if (index < 0 || index >= dataSets.size) { null } else { - dataSets!![index] + dataSets[index] } } open fun getDataSetByIndex(index: Int): T? { - if (this.dataSets == null || index < 0 || index >= dataSets!!.size) { + if (index < 0 || index >= dataSets.size) { return null } - return dataSets!![index] + return dataSets[index] } /** @@ -291,7 +284,7 @@ abstract class ChartData> : Serializable { calcMinMax(d) - dataSets!!.add(d) + dataSets.add(d) } /** @@ -304,7 +297,7 @@ abstract class ChartData> : Serializable { return false } - val removed = dataSets!!.remove(d) + val removed = dataSets.remove(d) // if a DataSet was removed if (removed) { @@ -320,11 +313,11 @@ abstract class ChartData> : Serializable { * a DataSet was removed, false if no DataSet could be removed. */ open fun removeDataSet(index: Int): Boolean { - if (index >= dataSets!!.size || index < 0) { + if (index >= dataSets.size || index < 0) { return false } - val set = dataSets!![index] + val set = dataSets[index] return removeDataSet(set) } @@ -334,8 +327,8 @@ abstract class ChartData> : Serializable { */ @Suppress("UNCHECKED_CAST") fun addEntry(entry: Entry, dataSetIndex: Int) { - if (dataSets!!.size > dataSetIndex && dataSetIndex >= 0) { - val set: T = dataSets!![dataSetIndex] + if (dataSets.size > dataSetIndex && dataSetIndex >= 0) { + 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 @@ -425,11 +418,11 @@ abstract class ChartData> : Serializable { @Suppress("UNCHECKED_CAST") open fun removeEntry(entry: Entry, dataSetIndex: Int): Boolean { // entry null, out of bounds - if (dataSetIndex >= dataSets!!.size) { + if (dataSetIndex >= dataSets.size) { return false } - val set: T = dataSets!![dataSetIndex] + val set: T = dataSets[dataSetIndex] // remove the entry from the dataset val dataSet = set as IDataSet @@ -448,11 +441,11 @@ abstract class ChartData> : Serializable { * was found that meets the specified requirements. */ open fun removeEntry(xValue: Float, dataSetIndex: Int): Boolean { - if (dataSetIndex >= dataSets!!.size) { + if (dataSetIndex >= dataSets.size) { return false } - val dataSet: IDataSet<*> = dataSets!![dataSetIndex] + val dataSet: IDataSet<*> = dataSets[dataSetIndex] val entry: Entry = dataSet.getEntryForXValue(xValue, Float.NaN) ?: return false return removeEntry(entry, dataSetIndex) @@ -462,8 +455,8 @@ abstract class ChartData> : Serializable { * Returns the DataSet that contains the provided Entry, or null, if no DataSet contains this Entry. */ fun getDataSetForEntry(e: Entry): T? { - for (i in dataSets!!.indices) { - val set = dataSets!![i] + for (i in dataSets.indices) { + val set = dataSets[i] for (j in 0..> : Serializable { /** * All colors used across all DataSet objects this object represents. */ - val colors: IntArray? + val colors: IntArray get() { - val colorArray: IntArray? = null - dataSets?.let { - var clrCount = 0 + var clrCount = 0 - for (i in it.indices) { - clrCount += it[i].colors.size - } + for (i in dataSets.indices) { + clrCount += dataSets[i].colors.size + } - val colorArray = IntArray(clrCount) - var cnt = 0 + val colorArray = IntArray(clrCount) + var cnt = 0 - for (i in it.indices) { - val clrs = it[i].colors + for (i in dataSets.indices) { + val clrs = dataSets[i].colors - for (clr in clrs) { - colorArray[cnt] = clr - cnt++ - } + for (clr in clrs) { + colorArray[cnt] = clr + cnt++ } } return colorArray @@ -507,7 +497,7 @@ abstract class ChartData> : Serializable { * Returns the index of the provided DataSet in the DataSet array of this data object, or -1 if it does not exist. */ fun getIndexOfDataSet(dataSet: @UnsafeVariance T?): Int { - return dataSets!!.indexOf(dataSet) + return dataSets.indexOf(dataSet) } /** @@ -540,7 +530,7 @@ abstract class ChartData> : Serializable { * Sets a custom IValueFormatter for all DataSets this data object contains. */ fun setValueFormatter(f: IValueFormatter) { - for (set in this.dataSets!!) { + for (set in this.dataSets) { set.valueFormatter = f } } @@ -550,7 +540,7 @@ abstract class ChartData> : Serializable { * drawn) for all DataSets this data object contains. */ fun setValueTextColor(color: Int) { - for (set in this.dataSets!!) { + for (set in this.dataSets) { set.valueTextColor = color } } @@ -560,7 +550,7 @@ abstract class ChartData> : Serializable { * data object contains. */ fun setValueTextColors(colors: MutableList) { - for (set in this.dataSets!!) { + for (set in this.dataSets) { set.valueTextColors = colors } } @@ -569,7 +559,7 @@ abstract class ChartData> : Serializable { * Sets the Typeface for all value-labels for all DataSets this data object contains. */ fun setValueTypeface(tf: Typeface?) { - for (set in this.dataSets!!) { + for (set in this.dataSets) { set.valueTypeface = tf } } @@ -578,7 +568,7 @@ abstract class ChartData> : Serializable { * Sets the size (in dp) of the value-text for all DataSets this data object contains. */ fun setValueTextSize(size: Float) { - for (set in this.dataSets!!) { + for (set in this.dataSets) { set.valueTextSize = size } } @@ -587,7 +577,7 @@ abstract class ChartData> : Serializable { * Enables / disables drawing values (value-text) for all DataSets this data object contains. */ fun setDrawValues(enabled: Boolean) { - for (set in this.dataSets!!) { + for (set in this.dataSets) { set.isDrawValues = enabled } } @@ -598,7 +588,7 @@ abstract class ChartData> : Serializable { */ var isHighlightEnabled: Boolean get() { - for (set in this.dataSets!!) { + for (set in this.dataSets) { if (!set.isHighlightEnabled) { return false } @@ -606,7 +596,7 @@ abstract class ChartData> : Serializable { return true } set(value) { - for (set in this.dataSets!!) { + for (set in this.dataSets) { set.isHighlightEnabled = value } } @@ -616,9 +606,7 @@ abstract class ChartData> : Serializable { * Don't forget to invalidate the chart after this. */ fun clearValues() { - if (this.dataSets != null) { - dataSets!!.clear() - } + dataSets.clear() notifyDataChanged() } @@ -627,7 +615,7 @@ abstract class ChartData> : Serializable { * if so, false if not. */ fun contains(dataSet: @UnsafeVariance T?): Boolean { - for (set in this.dataSets!!) { + for (set in this.dataSets) { if (set == dataSet) { return true } @@ -643,7 +631,7 @@ abstract class ChartData> : Serializable { get() { var count = 0 - for (set in this.dataSets!!) { + for (set in this.dataSets) { count += set.entryCount } @@ -655,11 +643,11 @@ abstract class ChartData> : Serializable { */ val maxEntryCountSet: T? get() { - if (this.dataSets == null || dataSets!!.isEmpty()) { + if (dataSets.isEmpty()) { return null } - var max = dataSets!![0] + var max = dataSets[0] for (set in this.dataSets) { if (set.entryCount > max.entryCount) { 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 149ed1a4c..e4b7fac73 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/CombinedData.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/CombinedData.kt @@ -47,10 +47,7 @@ class CombinedData : BarLineScatterCandleBubbleData>() - } - dataSets!!.clear() + dataSets.clear() yMax = -Float.MAX_VALUE yMin = Float.MAX_VALUE @@ -68,7 +65,7 @@ class CombinedData : BarLineScatterCandleBubbleData yMax) yMax = data.yMax @@ -168,7 +165,7 @@ class CombinedData : BarLineScatterCandleBubbleData= data.dataSetCount) return null - return data.dataSets!![highlight.dataSetIndex] as IBarLineScatterCandleBubbleDataSet? + return data.dataSets[highlight.dataSetIndex] as IBarLineScatterCandleBubbleDataSet? } fun getDataIndex(data: ChartData<*>?): Int { 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 f315aaf4b..340488548 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/PieData.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/PieData.kt @@ -14,24 +14,20 @@ class PieData : ChartData { constructor(dataSet: IPieDataSet) : super(dataSet) + /** + * Returns the DataSet this PieData object represents. A PieData object can only contain one DataSet. + */ var dataSet: IPieDataSet - /** - * Returns the DataSet this PieData object represents. A PieData object can - * only contain one DataSet. - */ - get() = dataSets!![0] - /** - * Sets the PieDataSet this data object should represent. - */ + get() = dataSets[0] set(dataSet) { - dataSets?.clear() - dataSets?.add(dataSet) + dataSets.clear() + dataSets.add(dataSet) notifyDataChanged() } - override var dataSets: MutableList? + override var dataSets: MutableList get() { - super.dataSets?.let { + super.dataSets.let { if (it.isEmpty()) { Timber.e("Found multiple data sets while pie chart only allows one") } @@ -53,11 +49,11 @@ class PieData : ChartData { } override fun getDataSetByLabel(label: String, ignoreCase: Boolean): IPieDataSet? { - return if (ignoreCase) if (label.equals(dataSets!![0].label, ignoreCase = true)) - dataSets!![0] + return if (ignoreCase) if (label.equals(dataSets[0].label, ignoreCase = true)) + dataSets[0] else - null else if (label == dataSets!![0].label) - dataSets!![0] + null else if (label == dataSets[0].label) + dataSets[0] else null } 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 c09890df2..e77b023fb 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/ScatterData.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/ScatterData.kt @@ -9,19 +9,17 @@ class ScatterData : BarLineScatterCandleBubbleData { constructor(vararg dataSets: IScatterDataSet) : super(*dataSets) + /** + * Returns the maximum shape-size across all DataSets. + */ val greatestShapeSize: Float - /** - * Returns the maximum shape-size across all DataSets. - */ get() { var max = 0f - if (dataSets != null) { - for (set in dataSets) { - val size = set.scatterShapeSize + for (set in dataSets) { + val size = set.scatterShapeSize - if (size > max) max = size - } + if (size > max) max = size } return max diff --git a/chartLib/src/main/kotlin/info/appdev/charting/highlight/PieHighlighter.kt b/chartLib/src/main/kotlin/info/appdev/charting/highlight/PieHighlighter.kt index 4db963900..ea4bdc9df 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/highlight/PieHighlighter.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/highlight/PieHighlighter.kt @@ -5,7 +5,7 @@ import info.appdev.charting.data.Entry open class PieHighlighter(chart: PieChart) : PieRadarHighlighter(chart) { override fun getClosestHighlight(index: Int, x: Float, y: Float): Highlight? { - val pieDataSet = chartPieRadar.data!!.dataSets!![0] + val pieDataSet = chartPieRadar.data!!.dataSets[0] val entry: Entry? = pieDataSet.getEntryForIndex(index) diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/BubbleChartRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/BubbleChartRenderer.kt index 2d2c7b463..ad828050d 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/BubbleChartRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/BubbleChartRenderer.kt @@ -107,80 +107,78 @@ open class BubbleChartRenderer( val lineHeight = paintValues.calcTextHeight("1").toFloat() - dataSets?.let { - for (i in it.indices) { - val dataSet = it[i] - if (dataSet.entryCount == 0) { - continue - } - if (!shouldDrawValues(dataSet) || dataSet.entryCount < 1) { - continue - } + for (i in dataSets.indices) { + val dataSet = dataSets[i] + if (dataSet.entryCount == 0) { + continue + } + if (!shouldDrawValues(dataSet) || dataSet.entryCount < 1) { + continue + } - // apply the text-styling defined by the DataSet - applyValueTextStyle(dataSet) + // apply the text-styling defined by the DataSet + applyValueTextStyle(dataSet) - val phaseX = max(0.0, min(1.0, animator.phaseX.toDouble())).toFloat() - val phaseY = animator.phaseY + val phaseX = max(0.0, min(1.0, animator.phaseX.toDouble())).toFloat() + val phaseY = animator.phaseY - xBounds.set(dataProvider, dataSet) + xBounds.set(dataProvider, dataSet) - dataProvider.getTransformer(dataSet.axisDependency)?.let { transformer -> - val positions = transformer.generateTransformedValuesBubble(dataSet, phaseY, xBounds.min, xBounds.max) + dataProvider.getTransformer(dataSet.axisDependency)?.let { transformer -> + val positions = transformer.generateTransformedValuesBubble(dataSet, phaseY, xBounds.min, xBounds.max) - val alpha = if (phaseX == 1f) - phaseY - else - phaseX + val alpha = if (phaseX == 1f) + phaseY + else + phaseX - val iconsOffset = PointF.getInstance(dataSet.iconsOffset) - iconsOffset.x = iconsOffset.x.convertDpToPixel() - iconsOffset.y = iconsOffset.y.convertDpToPixel() + val iconsOffset = PointF.getInstance(dataSet.iconsOffset) + iconsOffset.x = iconsOffset.x.convertDpToPixel() + iconsOffset.y = iconsOffset.y.convertDpToPixel() - var j = 0 - while (j < positions.size) { - var valueTextColor = dataSet.getValueTextColor(j / 2 + xBounds.min) - valueTextColor = Color.argb( - (255f * alpha).roundToInt(), Color.red(valueTextColor), - Color.green(valueTextColor), Color.blue(valueTextColor) - ) + var j = 0 + while (j < positions.size) { + var valueTextColor = dataSet.getValueTextColor(j / 2 + xBounds.min) + valueTextColor = Color.argb( + (255f * alpha).roundToInt(), Color.red(valueTextColor), + Color.green(valueTextColor), Color.blue(valueTextColor) + ) - val x = positions[j] - val y = positions[j + 1] + val x = positions[j] + val y = positions[j + 1] - if (!viewPortHandler.isInBoundsRight(x)) break + if (!viewPortHandler.isInBoundsRight(x)) break - if ((!viewPortHandler.isInBoundsLeft(x) || !viewPortHandler.isInBoundsY(y))) { - j += 2 - continue - } + if ((!viewPortHandler.isInBoundsLeft(x) || !viewPortHandler.isInBoundsY(y))) { + j += 2 + continue + } - val bubbleEntry = dataSet.getEntryForIndex(j / 2 + xBounds.min) - bubbleEntry?.let { - if (dataSet.isDrawValues) { - drawValue( - canvas, dataSet.valueFormatter, bubbleEntry.size, bubbleEntry, i, x, - y + (0.5f * lineHeight), valueTextColor - ) - } + val bubbleEntry = dataSet.getEntryForIndex(j / 2 + xBounds.min) + bubbleEntry?.let { + if (dataSet.isDrawValues) { + drawValue( + canvas, dataSet.valueFormatter, bubbleEntry.size, bubbleEntry, i, x, + y + (0.5f * lineHeight), valueTextColor + ) + } - if (bubbleEntry.icon != null && dataSet.isDrawIcons) { - val icon = bubbleEntry.icon + if (bubbleEntry.icon != null && dataSet.isDrawIcons) { + val icon = bubbleEntry.icon - icon?.let { ico -> - canvas.drawImage( - ico, - (x + iconsOffset.x).toInt(), - (y + iconsOffset.y).toInt() - ) - } + icon?.let { ico -> + canvas.drawImage( + ico, + (x + iconsOffset.x).toInt(), + (y + iconsOffset.y).toInt() + ) } } - j += 2 } - - PointF.recycleInstance(iconsOffset) + j += 2 } + + PointF.recycleInstance(iconsOffset) } } } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/CandleStickChartRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/CandleStickChartRenderer.kt index 9d38d1530..38782ebe0 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/CandleStickChartRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/CandleStickChartRenderer.kt @@ -210,77 +210,74 @@ open class CandleStickChartRenderer( // if values are drawn if (isDrawingValuesAllowed(dataProvider)) { dataProvider.candleData?.let { + for (i in it.dataSets.indices) { + val dataSet = it.dataSets[i] + if (dataSet.entryCount == 0) { + continue + } + if (!shouldDrawValues(dataSet) || dataSet.entryCount < 1) { + continue + } - it.dataSets?.let { it1 -> - for (i in it1.indices) { - val dataSet = it.dataSets!![i] - if (dataSet.entryCount == 0) { - continue - } - if (!shouldDrawValues(dataSet) || dataSet.entryCount < 1) { - continue - } - - // apply the text-styling defined by the DataSet - applyValueTextStyle(dataSet) + // apply the text-styling defined by the DataSet + applyValueTextStyle(dataSet) - val trans = dataProvider.getTransformer(dataSet.axisDependency) + val trans = dataProvider.getTransformer(dataSet.axisDependency) - xBounds.set(dataProvider, dataSet) + xBounds.set(dataProvider, dataSet) - val positions = trans!!.generateTransformedValuesCandle( - dataSet, animator.phaseX, animator.phaseY, xBounds.min, xBounds.max - ) + val positions = trans!!.generateTransformedValuesCandle( + dataSet, animator.phaseX, animator.phaseY, xBounds.min, xBounds.max + ) - val yOffset = 5f.convertDpToPixel() + val yOffset = 5f.convertDpToPixel() - val iconsOffset = PointF.getInstance(dataSet.iconsOffset) - iconsOffset.x = iconsOffset.x.convertDpToPixel() - iconsOffset.y = iconsOffset.y.convertDpToPixel() + val iconsOffset = PointF.getInstance(dataSet.iconsOffset) + iconsOffset.x = iconsOffset.x.convertDpToPixel() + iconsOffset.y = iconsOffset.y.convertDpToPixel() - var j = 0 - while (j < positions.size) { - val x = positions[j] - val y = positions[j + 1] + var j = 0 + while (j < positions.size) { + val x = positions[j] + val y = positions[j + 1] - if (!viewPortHandler.isInBoundsRight(x)) break + if (!viewPortHandler.isInBoundsRight(x)) break - if (!viewPortHandler.isInBoundsLeft(x) || !viewPortHandler.isInBoundsY(y)) { - j += 2 - continue - } + if (!viewPortHandler.isInBoundsLeft(x) || !viewPortHandler.isInBoundsY(y)) { + j += 2 + continue + } - val entry = dataSet.getEntryForIndex(j / 2 + xBounds.min)!! - - if (dataSet.isDrawValues) { - drawValue( - canvas, - dataSet.valueFormatter, - entry.high, - entry, - i, - x, - y - yOffset, - dataSet.getValueTextColor(j / 2) - ) - } + val entry = dataSet.getEntryForIndex(j / 2 + xBounds.min)!! + + if (dataSet.isDrawValues) { + drawValue( + canvas, + dataSet.valueFormatter, + entry.high, + entry, + i, + x, + y - yOffset, + dataSet.getValueTextColor(j / 2) + ) + } - if (entry.icon != null && dataSet.isDrawIcons) { - val icon = entry.icon + if (entry.icon != null && dataSet.isDrawIcons) { + val icon = entry.icon - icon?.let { ico -> - canvas.drawImage( - ico, - (x + iconsOffset.x).toInt(), - (y + iconsOffset.y).toInt() - ) - } + icon?.let { ico -> + canvas.drawImage( + ico, + (x + iconsOffset.x).toInt(), + (y + iconsOffset.y).toInt() + ) } - j += 2 } - - PointF.recycleInstance(iconsOffset) + j += 2 } + + PointF.recycleInstance(iconsOffset) } } } 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 c8a6ee482..9340a0deb 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/LineChartRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/LineChartRenderer.kt @@ -77,7 +77,7 @@ open class LineChartRenderer( drawBitmapLocal.eraseColor(Color.TRANSPARENT) dataProvider.lineData?.let { lineData -> - lineData.dataSets?.forEach { set -> + lineData.dataSets.forEach { set -> if (set.isVisible) drawDataSet(canvas, set) } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt index 8c4038fcf..e1d3f1fdb 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt @@ -390,199 +390,197 @@ open class PieChartRenderer( canvas.withSave { val offset = 5f.convertDpToPixel() - dataSets?.let { - for (i in it.indices) { - val dataSet = dataSets[i] - if (dataSet.entryCount == 0) { - continue - } - val drawValues = dataSet.isDrawValues - if (!drawValues && !drawEntryLabels) { - continue - } + for (i in dataSets.indices) { + val dataSet = dataSets[i] + if (dataSet.entryCount == 0) { + continue + } + val drawValues = dataSet.isDrawValues + if (!drawValues && !drawEntryLabels) { + continue + } - val xValuePosition = dataSet.xValuePosition - val yValuePosition = dataSet.yValuePosition + val xValuePosition = dataSet.xValuePosition + val yValuePosition = dataSet.yValuePosition - // apply the text-styling defined by the DataSet - applyValueTextStyle(dataSet) + // apply the text-styling defined by the DataSet + applyValueTextStyle(dataSet) - val lineHeight = (paintValues.calcTextHeight("Q") - + 4f.convertDpToPixel()) + val lineHeight = (paintValues.calcTextHeight("Q") + + 4f.convertDpToPixel()) - val formatter = dataSet.valueFormatter + val formatter = dataSet.valueFormatter - val entryCount = dataSet.entryCount + val entryCount = dataSet.entryCount - val isUseValueColorForLineEnabled = dataSet.isUseValueColorForLineEnabled - val valueLineColor = dataSet.valueLineColor + val isUseValueColorForLineEnabled = dataSet.isUseValueColorForLineEnabled + val valueLineColor = dataSet.valueLineColor - valueLinePaint.strokeWidth = dataSet.valueLineWidth.convertDpToPixel() + valueLinePaint.strokeWidth = dataSet.valueLineWidth.convertDpToPixel() - val sliceSpace = getSliceSpace(dataSet) + val sliceSpace = getSliceSpace(dataSet) - val iconsOffset = PointF.getInstance(dataSet.iconsOffset) - iconsOffset.x = iconsOffset.x.convertDpToPixel() - iconsOffset.y = iconsOffset.y.convertDpToPixel() + val iconsOffset = PointF.getInstance(dataSet.iconsOffset) + iconsOffset.x = iconsOffset.x.convertDpToPixel() + iconsOffset.y = iconsOffset.y.convertDpToPixel() - for (j in 0.. + for (j in 0.. - angle = if (xIndex == 0) 0f - else absoluteAngles[xIndex - 1] * phaseX + angle = if (xIndex == 0) 0f + else absoluteAngles[xIndex - 1] * phaseX - val sliceAngle = drawAngles[xIndex] - val sliceSpaceMiddleAngle = sliceSpace / (Utils.FDEG2RAD * labelRadius) + val sliceAngle = drawAngles[xIndex] + val sliceSpaceMiddleAngle = sliceSpace / (Utils.FDEG2RAD * labelRadius) - // offset needed to center the drawn text in the slice - val angleOffset = (sliceAngle - sliceSpaceMiddleAngle / 2f) / 2f + // offset needed to center the drawn text in the slice + val angleOffset = (sliceAngle - sliceSpaceMiddleAngle / 2f) / 2f - angle += angleOffset + angle += angleOffset - val transformedAngle = rotationAngle + angle * phaseY + val transformedAngle = rotationAngle + angle * phaseY - val value = if (chart.isUsePercentValuesEnabled) (entry.y / yValueSum * 100f) else entry.y - val entryLabel = entry.label + val value = if (chart.isUsePercentValuesEnabled) (entry.y / yValueSum * 100f) else entry.y + val entryLabel = entry.label - val sliceXBase = cos((transformedAngle * Utils.FDEG2RAD).toDouble()).toFloat() - val sliceYBase = sin((transformedAngle * Utils.FDEG2RAD).toDouble()).toFloat() + val sliceXBase = cos((transformedAngle * Utils.FDEG2RAD).toDouble()).toFloat() + val sliceYBase = sin((transformedAngle * Utils.FDEG2RAD).toDouble()).toFloat() - val drawXOutside = drawEntryLabels && xValuePosition == ValuePosition.OUTSIDE_SLICE - val drawYOutside = drawValues && yValuePosition == ValuePosition.OUTSIDE_SLICE - val drawXInside = drawEntryLabels && xValuePosition == ValuePosition.INSIDE_SLICE - val drawYInside = drawValues && yValuePosition == ValuePosition.INSIDE_SLICE + val drawXOutside = drawEntryLabels && xValuePosition == ValuePosition.OUTSIDE_SLICE + val drawYOutside = drawValues && yValuePosition == ValuePosition.OUTSIDE_SLICE + val drawXInside = drawEntryLabels && xValuePosition == ValuePosition.INSIDE_SLICE + val drawYInside = drawValues && yValuePosition == ValuePosition.INSIDE_SLICE - if (drawXOutside || drawYOutside) { - val valueLineLength1 = dataSet.valueLinePart1Length - val valueLineLength2 = dataSet.valueLinePart2Length - val valueLinePart1OffsetPercentage = dataSet.valueLinePart1OffsetPercentage / 100f + if (drawXOutside || drawYOutside) { + val valueLineLength1 = dataSet.valueLinePart1Length + val valueLineLength2 = dataSet.valueLinePart2Length + val valueLinePart1OffsetPercentage = dataSet.valueLinePart1OffsetPercentage / 100f - val pt2x: Float - val pt2y: Float - val labelPtx: Float - val labelPty: Float + val pt2x: Float + val pt2y: Float + val labelPtx: Float + val labelPty: Float - val line1Radius = - if (chart.isDrawHoleEnabled) ((radius - (radius * holeRadiusPercent)) * valueLinePart1OffsetPercentage + (radius * holeRadiusPercent)) - else radius * valueLinePart1OffsetPercentage + val line1Radius = + if (chart.isDrawHoleEnabled) ((radius - (radius * holeRadiusPercent)) * valueLinePart1OffsetPercentage + (radius * holeRadiusPercent)) + else radius * valueLinePart1OffsetPercentage - val polyline2Width = if (dataSet.isValueLineVariableLength) labelRadius * valueLineLength2 * abs( - sin( - (transformedAngle * Utils.FDEG2RAD).toDouble() - ) - ).toFloat() - else labelRadius * valueLineLength2 + val polyline2Width = if (dataSet.isValueLineVariableLength) labelRadius * valueLineLength2 * abs( + sin( + (transformedAngle * Utils.FDEG2RAD).toDouble() + ) + ).toFloat() + else labelRadius * valueLineLength2 - val pt0x = line1Radius * sliceXBase + center.x - val pt0y = line1Radius * sliceYBase + center.y + val pt0x = line1Radius * sliceXBase + center.x + val pt0y = line1Radius * sliceYBase + center.y - val pt1x = labelRadius * (1 + valueLineLength1) * sliceXBase + center.x - val pt1y = labelRadius * (1 + valueLineLength1) * sliceYBase + center.y + val pt1x = labelRadius * (1 + valueLineLength1) * sliceXBase + center.x + val pt1y = labelRadius * (1 + valueLineLength1) * sliceYBase + center.y - if (transformedAngle % 360.0 in 90.0..270.0) { - pt2x = pt1x - polyline2Width - pt2y = pt1y + if (transformedAngle % 360.0 in 90.0..270.0) { + pt2x = pt1x - polyline2Width + pt2y = pt1y - paintValues.textAlign = Align.RIGHT + paintValues.textAlign = Align.RIGHT - if (drawXOutside) paintEntryLabels.textAlign = Align.RIGHT + if (drawXOutside) paintEntryLabels.textAlign = Align.RIGHT - labelPtx = pt2x - offset - labelPty = pt2y - } else { - pt2x = pt1x + polyline2Width - pt2y = pt1y - paintValues.textAlign = Align.LEFT + labelPtx = pt2x - offset + labelPty = pt2y + } else { + pt2x = pt1x + polyline2Width + pt2y = pt1y + paintValues.textAlign = Align.LEFT - if (drawXOutside) paintEntryLabels.textAlign = Align.LEFT + if (drawXOutside) paintEntryLabels.textAlign = Align.LEFT - labelPtx = pt2x + offset - labelPty = pt2y - } + labelPtx = pt2x + offset + labelPty = pt2y + } - var lineColor = ColorTemplate.COLOR_NONE + var lineColor = ColorTemplate.COLOR_NONE - if (isUseValueColorForLineEnabled) lineColor = dataSet.getColorByIndex(j) - else if (valueLineColor != ColorTemplate.COLOR_NONE) lineColor = valueLineColor + if (isUseValueColorForLineEnabled) lineColor = dataSet.getColorByIndex(j) + else if (valueLineColor != ColorTemplate.COLOR_NONE) lineColor = valueLineColor - if (lineColor != ColorTemplate.COLOR_NONE) { - valueLinePaint.color = lineColor - drawLine(pt0x, pt0y, pt1x, pt1y, valueLinePaint) - drawLine(pt1x, pt1y, pt2x, pt2y, valueLinePaint) - } + if (lineColor != ColorTemplate.COLOR_NONE) { + valueLinePaint.color = lineColor + drawLine(pt0x, pt0y, pt1x, pt1y, valueLinePaint) + drawLine(pt1x, pt1y, pt2x, pt2y, valueLinePaint) + } + + // draw everything, depending on settings + if (drawXOutside && drawYOutside) { + drawValue( + this, formatter, value, entry, 0, labelPtx, labelPty, dataSet.getValueTextColor(j) + ) - // draw everything, depending on settings - if (drawXOutside && drawYOutside) { - drawValue( - this, formatter, value, entry, 0, labelPtx, labelPty, dataSet.getValueTextColor(j) - ) - - if (j < data.entryCount && entryLabel != null) { - drawEntryLabel(this, entryLabel, labelPtx, labelPty + lineHeight) - } - } else if (drawXOutside) { - if (j < data.entryCount && entryLabel != null) { - drawEntryLabel(this, entryLabel, labelPtx, labelPty + lineHeight / 2f) - } - } else if (drawYOutside) { - drawValue( - this, - formatter, - value, - entry, - 0, - labelPtx, - labelPty + lineHeight / 2f, - dataSet.getValueTextColor(j) - ) + if (j < data.entryCount && entryLabel != null) { + drawEntryLabel(this, entryLabel, labelPtx, labelPty + lineHeight) } + } else if (drawXOutside) { + if (j < data.entryCount && entryLabel != null) { + drawEntryLabel(this, entryLabel, labelPtx, labelPty + lineHeight / 2f) + } + } else if (drawYOutside) { + drawValue( + this, + formatter, + value, + entry, + 0, + labelPtx, + labelPty + lineHeight / 2f, + dataSet.getValueTextColor(j) + ) } + } + + + if (drawXInside || drawYInside) { + // calculate the text position + val x = labelRadius * sliceXBase + center.x + val y = labelRadius * sliceYBase + center.y + + paintValues.textAlign = Align.CENTER + // draw everything, depending on settings + if (drawXInside && drawYInside) { + drawValue( + this, formatter, value, entry, 0, x, y, dataSet.getValueTextColor(j) + ) - if (drawXInside || drawYInside) { - // calculate the text position - val x = labelRadius * sliceXBase + center.x - val y = labelRadius * sliceYBase + center.y - - paintValues.textAlign = Align.CENTER - - // draw everything, depending on settings - if (drawXInside && drawYInside) { - drawValue( - this, formatter, value, entry, 0, x, y, dataSet.getValueTextColor(j) - ) - - if (j < data.entryCount && entryLabel != null) { - drawEntryLabel(this, entryLabel, x, y + lineHeight) - } - } else if (drawXInside) { - if (j < data.entryCount && entryLabel != null) { - drawEntryLabel(this, entryLabel, x, y + lineHeight / 2f) - } - } else if (drawYInside) { - drawValue(this, formatter, value, entry, 0, x, y + lineHeight / 2f, dataSet.getValueTextColor(j)) + if (j < data.entryCount && entryLabel != null) { + drawEntryLabel(this, entryLabel, x, y + lineHeight) } + } else if (drawXInside) { + if (j < data.entryCount && entryLabel != null) { + drawEntryLabel(this, entryLabel, x, y + lineHeight / 2f) + } + } else if (drawYInside) { + drawValue(this, formatter, value, entry, 0, x, y + lineHeight / 2f, dataSet.getValueTextColor(j)) } + } - if (entry.icon != null && dataSet.isDrawIcons) { - val icon = entry.icon + if (entry.icon != null && dataSet.isDrawIcons) { + val icon = entry.icon - val x = (labelRadius + iconsOffset.y) * sliceXBase + center.x - var y = (labelRadius + iconsOffset.y) * sliceYBase + center.y - y += iconsOffset.x + val x = (labelRadius + iconsOffset.y) * sliceXBase + center.x + var y = (labelRadius + iconsOffset.y) * sliceYBase + center.y + y += iconsOffset.x - icon?.let { - this.drawImage( - it, x.toInt(), y.toInt() - ) - } + icon?.let { + this.drawImage( + it, x.toInt(), y.toInt() + ) } } - xIndex++ } - - PointF.recycleInstance(iconsOffset) + xIndex++ } + + PointF.recycleInstance(iconsOffset) } PointF.recycleInstance(center) } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/RadarChartRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/RadarChartRenderer.kt index 6304b084d..d49e290d0 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/RadarChartRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/RadarChartRenderer.kt @@ -38,7 +38,7 @@ open class RadarChartRenderer( val mostEntries = radarData.maxEntryCountSet?.entryCount ?: 0 - radarData.dataSets?.forEach { set -> + radarData.dataSets.forEach { set -> if (set.isVisible) { drawDataSet(canvas, set, mostEntries) } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/ScatterChartRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/ScatterChartRenderer.kt index 85ac4674a..afb879666 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/ScatterChartRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/ScatterChartRenderer.kt @@ -24,7 +24,7 @@ open class ScatterChartRenderer( val scatterData = dataProvider.scatterData scatterData?.let { - for (set in it.dataSets!!) { + for (set in it.dataSets) { if (set.isVisible) drawDataSet(canvas, set) } @@ -82,7 +82,7 @@ open class ScatterChartRenderer( if (isDrawingValuesAllowed(dataProvider)) { dataProvider.scatterData?.let { scatterData -> for (i in 0..