diff --git a/app/src/main/kotlin/info/appdev/chartexample/AnotherBarActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/AnotherBarActivity.kt index f0cb980374..5db7c77a8c 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/AnotherBarActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/AnotherBarActivity.kt @@ -16,7 +16,7 @@ import info.appdev.chartexample.notimportant.DemoBase 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.BarEntryFloat import info.appdev.charting.interfaces.datasets.IBarDataSet import info.appdev.charting.utils.ColorTemplate @@ -62,13 +62,13 @@ class AnotherBarActivity : DemoBase(), OnSeekBarChangeListener { binding.tvXMax.text = binding.seekBarX.progress.toString() binding.tvYMax.text = binding.seekBarY.progress.toString() - val values = ArrayList() + val values = ArrayList() val sampleValues = getValues(100) for (i in 0..() + val values = ArrayList() val sampleValues = getValues(100) var i = start.toInt() @@ -130,9 +130,9 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect val `val` = (sampleValues[i]!!.toFloat() * (range + 1)) if (`val` * 100 < 25) { - values.add(BarEntry(i.toFloat(), `val`, ResourcesCompat.getDrawable(resources, R.drawable.star, null))) + values.add(BarEntryFloat(i.toFloat(), `val`, ResourcesCompat.getDrawable(resources, R.drawable.star, null))) } else { - values.add(BarEntry(i.toFloat(), `val`)) + values.add(BarEntryFloat(i.toFloat(), `val`)) } i++ } @@ -281,10 +281,10 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect private val onValueSelectedRectF = RectF() - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) { val bounds = onValueSelectedRectF - binding.chart1.getBarBounds(entry as BarEntry, bounds) - val position = binding.chart1.getPosition(entry, AxisDependency.LEFT) + binding.chart1.getBarBounds(entryFloat as BarEntryFloat, bounds) + val position = binding.chart1.getPosition(entryFloat, AxisDependency.LEFT) Timber.i("bounds $bounds") Timber.i("position = $position") diff --git a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt index 522a876def..eba9e3c41e 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt @@ -19,8 +19,8 @@ import info.appdev.charting.components.AxisBase 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.BarEntryFloat +import info.appdev.charting.data.EntryFloat import info.appdev.charting.formatter.IAxisValueFormatter import info.appdev.charting.formatter.LargeValueFormatter import info.appdev.charting.highlight.Highlight @@ -110,19 +110,19 @@ class BarChartActivityMultiDataset : DemoBase(), OnSeekBarChangeListener, OnChar binding.tvXMax.text = String.format(Locale.ENGLISH, "%d-%d", startYear, endYear) binding.tvYMax.text = binding.seekBarY.progress.toString() - val values1 = ArrayList() - val values2 = ArrayList() - val values3 = ArrayList() - val values4 = ArrayList() + val values1 = ArrayList() + val values2 = ArrayList() + val values3 = ArrayList() + val values4 = ArrayList() val randomMultiplier = binding.seekBarY.progress * 100000f val sampleValues = getValues(100 + 2) for (i in startYear.. + private lateinit var dataSinus: MutableList private lateinit var binding: ActivityBarchartSinusBinding @@ -87,7 +87,7 @@ class BarChartActivitySinus : DemoBase(), OnSeekBarChangeListener { } private fun setData(count: Int) { - val entries = ArrayList() + val entries = ArrayList() for (i in 0..) { - val values = ArrayList() + val values = ArrayList() val colors: MutableList = ArrayList() val green = Color.rgb(110, 190, 102) @@ -95,7 +95,7 @@ class BarChartPositiveNegative : DemoBase() { for (i in dataList.indices) { val d = dataList[i] - val entry = BarEntry(d.xValue, d.yValue) + val entry = BarEntryFloat(d.xValue, d.yValue) values.add(entry) // specific colors @@ -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, entryFloat: EntryFloat?, 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 a478a0f649..7207e77449 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/BubbleChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/BubbleChartActivity.kt @@ -19,8 +19,8 @@ import info.appdev.charting.components.Legend import info.appdev.charting.components.XAxis 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.data.BubbleEntryFloat +import info.appdev.charting.data.EntryFloat import info.appdev.charting.highlight.Highlight import info.appdev.charting.interfaces.datasets.IBubbleDataSet import info.appdev.charting.listener.OnChartValueSelectedListener @@ -82,14 +82,14 @@ class BubbleChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSel binding.tvXMax.text = count.toString() binding.tvYMax.text = range.toString() - val values1 = ArrayList() - val values2 = ArrayList() - val values3 = ArrayList() + val values1 = ArrayList() + val values2 = ArrayList() + val values3 = ArrayList() val sampleValues = getValues(100) for (i in 0..() + val values = ArrayList() val sampleValues = getValues(100) for (i in 0..() + val entries = ArrayList() - for (index in 0..() - val entries2 = ArrayList() + val entries1 = ArrayList() + val entries2 = ArrayList() for (index in 0..() + val entries = ArrayList() var index = 0f while (index < sampleCount) { - entries.add(Entry(index + 0.25f, values[(index * 2).roundToInt()]!!.toFloat() * 10 + 55)) + entries.add(EntryFloat(index + 0.25f, values[(index * 2).roundToInt()]!!.toFloat() * 10 + 55)) index += 0.5f } @@ -183,11 +183,11 @@ class CombinedChartActivity : DemoBase() { private fun generateCandleData(): CandleData { val d = CandleData() - val entries = ArrayList() + val entries = ArrayList() var index = 0 while (index < sampleCount) { - entries.add(CandleEntry(index + 1f, 90f, 70f, 85f, 75f)) + entries.add(CandleEntryFloat(index + 1f, 90f, 70f, 85f, 75f)) index += 2 } @@ -205,12 +205,12 @@ class CombinedChartActivity : DemoBase() { private fun generateBubbleData(): BubbleData { val bd = BubbleData() - val entries = ArrayList() + val entries = ArrayList() for (index in 0..() + val values = ArrayList() val sampleValues = getMuchValues(count) for (i in 0 until count) { val `val` = (sampleValues[i]!!.toFloat() * (range + 1)) + 20 - values.add(Entry(i.toFloat(), `val`)) + values.add(EntryFloat(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 +115,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<*>?, dataProvider: LineDataProvider): Float { return binding.chart1.axisLeft.axisMinimum } } diff --git a/app/src/main/kotlin/info/appdev/chartexample/DataTools.kt b/app/src/main/kotlin/info/appdev/chartexample/DataTools.kt index a3f09c0987..0ae78e9827 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/DataTools.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/DataTools.kt @@ -5,7 +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.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet import info.appdev.charting.formatter.IFillFormatter @@ -164,15 +164,15 @@ 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))) + values.add(EntryFloat(index.toFloat(), d.toFloat(), ContextCompat.getDrawable(context, R.drawable.star))) } } else { for (i in 0 until count) { val value = (Math.random() * range).toFloat() - 30 - values.add(Entry(i.toFloat(), value, ContextCompat.getDrawable(context, R.drawable.star))) + values.add(EntryFloat(i.toFloat(), value, ContextCompat.getDrawable(context, R.drawable.star))) } } lineChart.data?.let { @@ -190,7 +190,7 @@ class DataTools { } private fun createDataset( - values: ArrayList, + values: ArrayList, lineChart: LineChart, context: Context ) { @@ -226,7 +226,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<*>?, dataProvider: LineDataProvider): Float { return lineChart.axisLeft.axisMinimum } } @@ -239,7 +239,7 @@ class DataTools { } else { lineDataSet01.fillColor = Color.BLACK } - val dataSets = ArrayList() + val dataSets = ArrayList>() dataSets.add(lineDataSet01) // add the data sets // create a data object with the data sets diff --git a/app/src/main/kotlin/info/appdev/chartexample/DrawChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/DrawChartActivity.kt index 9194ee49cb..826c3c09bc 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/DrawChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/DrawChartActivity.kt @@ -10,7 +10,7 @@ import androidx.core.content.ContextCompat import info.appdev.chartexample.databinding.ActivityDrawChartBinding import info.appdev.chartexample.notimportant.DemoBase import info.appdev.charting.data.DataSet -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet import info.appdev.charting.highlight.Highlight @@ -57,7 +57,7 @@ class DrawChartActivity : DemoBase(), OnChartValueSelectedListener, OnDrawListen } private fun initWithDummyData() { - val values = ArrayList() + val values = ArrayList() // create a dataset and give it a type (0) val set1 = LineDataSet(values, "DataSet") @@ -116,15 +116,15 @@ class DrawChartActivity : DemoBase(), OnChartValueSelectedListener, OnDrawListen saveToGallery(binding.chart1, "DrawChartActivity") } - override fun onValueSelected(entry: Entry, highlight: Highlight) { - Timber.i(("Value: ${entry.y}, xIndex: ${entry.x}, DataSet index:${highlight.dataSetIndex}")) + override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) { + Timber.i(("Value: ${entryFloat.y}, xIndex: ${entryFloat.x}, DataSet index:${highlight.dataSetIndex}")) } override fun onNothingSelected() = Unit /** callback for each new entry drawn with the finger */ - override fun onEntryAdded(entry: Entry) { - Timber.i(entry.toString()) + override fun onEntryAdded(entryFloat: EntryFloat) { + Timber.i(entryFloat.toString()) } /** callback when a DataSet has been drawn (when lifting the finger) */ @@ -135,7 +135,7 @@ class DrawChartActivity : DemoBase(), OnChartValueSelectedListener, OnDrawListen binding.chart1.data?.let { binding.chart1.legendRenderer?.computeLegend(it) } } - override fun onEntryMoved(entry: Entry) { - Timber.i("Point moved $entry") + override fun onEntryMoved(entryFloat: EntryFloat) { + Timber.i("Point moved $entryFloat") } } diff --git a/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt index aa371611fa..e5a00dcc0f 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt @@ -14,7 +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.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet import info.appdev.charting.highlight.Highlight @@ -66,7 +66,7 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener { val value = (sampleValues[cycleValue]!!.toFloat() * 50) + 50f * (lastDataSetIndex + 1) - data.addEntry(Entry(lastSet.entryCount.toFloat(), value), lastDataSetIndex) + data.addEntry(EntryFloat(lastSet.entryCount.toFloat(), value), lastDataSetIndex) data.notifyDataChanged() // let the chart know it's data has changed @@ -109,12 +109,12 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener { val count = (data.dataSetCount + 1) val amount = data.getDataSetByIndex(0)?.entryCount ?: 0 - val values = ArrayList() + val values = ArrayList() for (i in 0.. { + val set = LineDataSet(label = "DataSet 1") set.lineWidth = 2.5f set.circleRadius = 4.5f set.color = Color.rgb(240, 99, 99) @@ -160,8 +160,8 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener { return set } - override fun onValueSelected(entry: Entry, highlight: Highlight) { - Toast.makeText(this, entry.toString(), Toast.LENGTH_SHORT).show() + override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) { + Toast.makeText(this, entryFloat.toString(), Toast.LENGTH_SHORT).show() } override fun onNothingSelected() {} diff --git a/app/src/main/kotlin/info/appdev/chartexample/FilledLineActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/FilledLineActivity.kt index 528f1b2e70..f8e0826379 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/FilledLineActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/FilledLineActivity.kt @@ -10,7 +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.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet import info.appdev.charting.formatter.IFillFormatter @@ -69,27 +69,27 @@ 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.. + val set2: LineDataSet 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 + set2 = binding.chart1.lineData.getDataSetByIndex(1) as LineDataSet set1.entries = valuesArray1 set2.entries = valuesArray2 binding.chart1.lineData.notifyDataChanged() @@ -109,7 +109,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<*>?, dataProvider: LineDataProvider): Float { // change the return value here to better understand the effect // return 0; return binding.chart1.axisLeft.axisMinimum @@ -129,14 +129,14 @@ 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<*>?, 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>() dataSets.add(set1) // add the data sets dataSets.add(set2) diff --git a/app/src/main/kotlin/info/appdev/chartexample/GradientActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/GradientActivity.kt index 2b314d38f6..c3fda989b0 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/GradientActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/GradientActivity.kt @@ -6,7 +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.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet import info.appdev.charting.formatter.IFillFormatter @@ -41,11 +41,11 @@ class GradientActivity : DemoBase() { // Linear function // y = k * x // ----------------------------- - val entries = kotlin.collections.ArrayList(200) + val entries = kotlin.collections.ArrayList(200) val k = 2.5f for (i in 0 until 200) { - entries.add(Entry(i.toFloat(), i * k)) + entries.add(EntryFloat(i.toFloat(), i * k)) } val dataSet = LineDataSet(entries, "Linear").apply { @@ -62,7 +62,7 @@ class GradientActivity : DemoBase() { fillFormatter = object : IFillFormatter { override fun getFillLinePosition( - dataSet: ILineDataSet?, + dataSet: ILineDataSet<*>?, dataProvider: LineDataProvider ): Float = binding.chart1.axisLeft.axisMinimum } diff --git a/app/src/main/kotlin/info/appdev/chartexample/HalfPieChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/HalfPieChartActivity.kt index ef11617bb0..41d041fa1e 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/HalfPieChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/HalfPieChartActivity.kt @@ -20,7 +20,7 @@ import info.appdev.charting.animation.Easing import info.appdev.charting.components.Legend import info.appdev.charting.data.PieData import info.appdev.charting.data.PieDataSet -import info.appdev.charting.data.PieEntry +import info.appdev.charting.data.PieEntryFloat import info.appdev.charting.formatter.PercentFormatter import info.appdev.charting.utils.ColorTemplate @@ -83,11 +83,11 @@ class HalfPieChartActivity : DemoBase() { private fun setData(range: Float) { val count = 4 - val values = ArrayList() + val values = ArrayList() val sampleValues = getValues(count) for (i in 0..() + val values = ArrayList() val sampleValues = getValues(100) for (i in 0.. 0 ) { set1 = binding.chart1.barData!!.getDataSetByIndex(0) as BarDataSet - set1.entries = values + @Suppress("UNCHECKED_CAST") + set1.entries = values as MutableList binding.chart1.barData?.notifyDataChanged() binding.chart1.notifyDataSetChanged() } else { - set1 = BarDataSet(values, "DataSet 1") + @Suppress("UNCHECKED_CAST") + set1 = BarDataSet(values as MutableList, "DataSet 1") set1.isDrawIcons = false @@ -229,12 +236,13 @@ class HorizontalBarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartV private val mOnValueSelectedRectF = RectF() - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) { + val barEntry = entryFloat as BarEntryDouble val bounds = mOnValueSelectedRectF - binding.chart1.getBarBounds(entry as BarEntry, bounds) + binding.chart1.getBarBounds(barEntry, bounds) val position = binding.chart1.getPosition( - entry, binding.chart1.barData!!.getDataSetByIndex(highlight.dataSetIndex)?.axisDependency + entryFloat, binding.chart1.barData!!.getDataSetByIndex(highlight.dataSetIndex)?.axisDependency ) Timber.i(bounds.toString()) diff --git a/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarNegativeChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarNegativeChartActivity.kt index fbeac36f83..af349ac06e 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarNegativeChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarNegativeChartActivity.kt @@ -19,8 +19,8 @@ import info.appdev.charting.components.Legend 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.BarEntryFloat +import info.appdev.charting.data.EntryFloat import info.appdev.charting.highlight.Highlight import info.appdev.charting.interfaces.datasets.IBarDataSet import info.appdev.charting.listener.OnChartValueSelectedListener @@ -97,13 +97,13 @@ class HorizontalBarNegativeChartActivity : DemoBase(), OnSeekBarChangeListener, private fun setData(count: Int, range: Float) { val barWidth = 9f val spaceForBar = 10f - val values = ArrayList() + val values = ArrayList() val sampleValues = getValues(count + 2) for (i in 0..() + val entries = ArrayList() val sampleValues = getValues(count + 2) for (i in 0.. { - 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,8 +256,8 @@ class LineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelec override fun onStartTrackingTouch(seekBar: SeekBar) = Unit override fun onStopTrackingTouch(seekBar: SeekBar) = Unit - override fun onValueSelected(entry: Entry, highlight: Highlight) { - Timber.i(entry.toString()) + override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) { + Timber.i(entryFloat.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 7025a8c386..aae6647b5c 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/LineChartActivityColored.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/LineChartActivityColored.kt @@ -11,7 +11,7 @@ import info.appdev.chartexample.DataTools.Companion.getValues import info.appdev.chartexample.databinding.ActivityColoredLinesBinding import info.appdev.chartexample.notimportant.DemoBase import info.appdev.charting.charts.LineChart -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet @@ -98,12 +98,12 @@ class LineChartActivityColored : DemoBase() { @Suppress("SameParameterValue") private fun getData(range: Float): LineData { val count = 36 - val values = ArrayList() + val values = ArrayList() val sampleValues = getValues(count) for (i in 0..() + 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.. + val set2: LineDataSet + val set3: LineDataSet 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 + set2 = binding.chart1.lineData.getDataSetByIndex(1) as LineDataSet + set3 = binding.chart1.lineData.getDataSetByIndex(2) as LineDataSet set1.entries = values1 set2.entries = values2 set3.entries = values3 @@ -315,11 +315,11 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa saveToGallery(binding.chart1, "LineChartActivity2") } - override fun onValueSelected(entry: Entry, highlight: Highlight) { - Timber.i(entry.toString()) + override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) { + Timber.i(entryFloat.toString()) binding.chart1.lineData.getDataSetByIndex(highlight.dataSetIndex)?.let { - binding.chart1.centerViewToAnimated(entry.x, entry.y, it.axisDependency, 500) + binding.chart1.centerViewToAnimated(entryFloat.x, entryFloat.y, it.axisDependency, 500) //chart.zoomAndCenterAnimated(2.5f, 2.5f, e.getX(), e.getY(), chart.getData().getDataSetByIndex(dataSetIndex) // .getAxisDependency(), 1000); //chart.zoomAndCenterAnimated(1.8f, 1.8f, e.getX(), e.getY(), chart.getData().getDataSetByIndex(dataSetIndex) diff --git a/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt index fdd99c2871..78738de1b4 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt @@ -18,7 +18,7 @@ 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.EntryFloat import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet import info.appdev.charting.formatter.IAxisValueFormatter @@ -105,7 +105,7 @@ 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() @@ -118,7 +118,7 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener { (valuesData[x.roundToInt()])!!.toFloat() * 50 + 50 else (Math.random() * 50 + 50).toFloat() // manually triggered - values.add(Entry(x, y)) // add one entry per hour + values.add(EntryFloat(x, y)) // add one entry per hour x++ } diff --git a/app/src/main/kotlin/info/appdev/chartexample/ListViewBarChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/ListViewBarChartActivity.kt index 08b1c2040e..af361132d9 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/ListViewBarChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/ListViewBarChartActivity.kt @@ -19,7 +19,7 @@ import info.appdev.charting.charts.BarChart 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.BarEntryFloat import info.appdev.charting.interfaces.datasets.IBarDataSet import info.appdev.charting.utils.ColorTemplate @@ -110,11 +110,11 @@ class ListViewBarChartActivity : DemoBase() { */ private fun generateData(cnt: Int): BarData { val count = 12 - val entries = ArrayList() + val entries = ArrayList() val sampleValues = getValues(count) for (i in 0..() + val values1 = ArrayList() val count = 12 val sampleValues = getValues(count) for (i in 0..() + val values2 = ArrayList() for (i in 0..() + val sets = ArrayList>() sets.add(d1) sets.add(d2) @@ -130,11 +130,11 @@ class ListViewMultiChartActivity : DemoBase() { */ private fun generateDataBar(cnt: Int): BarData { val count = 12 - val entries = ArrayList() + val entries = ArrayList() val sampleValues = getValues(count) for (i in 0..() + val entries = ArrayList() val sampleValues = getValues(cnt) for (i in 0..() + val dataSets = ArrayList>() for (datasetNumber in 0..2) { - val values = ArrayList() + val values = ArrayList() val sampleValues = when (datasetNumber) { 1 -> getValues(100).reversedArray() 2 -> generateSineWaves(3, 30).toTypedArray() @@ -96,7 +96,7 @@ class MultiLineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartGestu for (i in 0..).enableDashedLine(10f, 10f, 0f) val data = LineData(dataSets) binding.chart1.data = data @@ -268,8 +268,8 @@ class MultiLineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartGestu Timber.i("dX: $dX, dY: $dY") } - override fun onValueSelected(entry: Entry, highlight: Highlight) { - Timber.i("Value: ${entry.y}, xIndex: ${entry.x}, DataSet index: ${highlight.dataSetIndex}") + override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) { + Timber.i("Value: ${entryFloat.y}, xIndex: ${entryFloat.x}, DataSet index: ${highlight.dataSetIndex}") } override fun onNothingSelected() = Unit diff --git a/app/src/main/kotlin/info/appdev/chartexample/PerformanceLineChart.kt b/app/src/main/kotlin/info/appdev/chartexample/PerformanceLineChart.kt index b352fa1a82..28b9d5d528 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/PerformanceLineChart.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/PerformanceLineChart.kt @@ -11,7 +11,7 @@ import androidx.core.net.toUri import info.appdev.chartexample.DataTools.Companion.getMuchValues import info.appdev.chartexample.databinding.ActivityPerformanceLinechartBinding import info.appdev.chartexample.notimportant.DemoBase -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet @@ -53,12 +53,12 @@ class PerformanceLineChart : DemoBase(), OnSeekBarChangeListener { } private fun setData(count: Int, range: Float) { - val values = ArrayList() + val values = ArrayList() val sampleValues = getMuchValues(count) for (i in 0..() + val entries = ArrayList() val sampleValues = getValues(100) // NOTE: The order of the entries when being added to the entries array determines their position around the center of // the chart. for (i in 0..() + val entries = ArrayList() val sampleValues = getValues(100) // NOTE: The order of the entries when being added to the entries array determines their position around the center of // the chart. for (i in 0..() + val entries = ArrayList() // NOTE: The order of the entries when being added to the entries array determines their position around the center of // the chart. for (i in 0..() - val entries2 = ArrayList() + val entries1 = ArrayList() + val entries2 = ArrayList() // NOTE: The order of the entries when being added to the entries array determines their position around the center of // the chart. for (i in 0.. { + val set = LineDataSet(label = "Dynamic Data") set.axisDependency = AxisDependency.LEFT set.color = ColorTemplate.holoBlue set.setCircleColor(Color.WHITE) @@ -194,8 +194,8 @@ class RealtimeLineChartActivity : DemoBase(), OnChartValueSelectedListener { saveToGallery(binding.chart1, "RealtimeLineChartActivity") } - override fun onValueSelected(entry: Entry, highlight: Highlight) { - Timber.i(entry.toString()) + override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) { + Timber.i(entryFloat.toString()) } override fun onNothingSelected() = Unit diff --git a/app/src/main/kotlin/info/appdev/chartexample/ScatterChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/ScatterChartActivity.kt index bf4ba14c6d..e0cc925a30 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/ScatterChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/ScatterChartActivity.kt @@ -16,7 +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.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.data.ScatterData import info.appdev.charting.data.ScatterDataSet import info.appdev.charting.highlight.Highlight @@ -77,24 +77,24 @@ class ScatterChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSe binding.tvXMax.text = binding.seekBarX.progress.toString() binding.tvYMax.text = binding.seekBarY.progress.toString() - val values1 = ArrayList() - val values2 = ArrayList() - val values3 = ArrayList() + val values1 = ArrayList() + val values2 = ArrayList() + val values3 = ArrayList() val sampleValues = getValues(100 + 2) for (i in 0..() + val values = ArrayList() for (i in 0..() + val values = ArrayList() val sampleValues = getValues(100) for (i in 0 until count) { val `val` = (sampleValues[i]!!.toFloat() * range) + 3 - values.add(Entry(i.toFloat(), `val`)) + values.add(EntryFloat(i.toFloat(), `val`)) } binding.chart1.data?.let { if (it.dataSetCount > 0) { @@ -245,7 +245,7 @@ class SpecificPositionsLineChartActivity : DemoBase(), OnSeekBarChangeListener, } } - private fun createDataset(values: ArrayList) { + private fun createDataset(values: ArrayList) { // create a dataset and give it a type val set11 = LineDataSet(values, "DataSet 1") @@ -269,7 +269,7 @@ class SpecificPositionsLineChartActivity : DemoBase(), OnSeekBarChangeListener, } else { set11.fillColor = Color.BLACK } - val dataSets = ArrayList() + val dataSets = ArrayList>() dataSets.add(set11) // add the datasets // create a data object with the datasets @@ -316,8 +316,8 @@ class SpecificPositionsLineChartActivity : DemoBase(), OnSeekBarChangeListener, Timber.i("dX: $dX, dY: $dY") } - override fun onValueSelected(entry: Entry, highlight: Highlight) { - Timber.i(entry.toString()) + override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) { + Timber.i(entryFloat.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 443cc16ca3..b28b1ce4c3 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivity.kt @@ -21,8 +21,8 @@ import info.appdev.charting.components.Legend 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.BarEntryFloat +import info.appdev.charting.data.EntryFloat import info.appdev.charting.highlight.Highlight import info.appdev.charting.interfaces.datasets.IBarDataSet import info.appdev.charting.listener.OnChartValueSelectedListener @@ -91,7 +91,7 @@ class StackedBarActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSele binding.tvXMax.text = binding.seekBarX.progress.toString() binding.tvYMax.text = binding.seekBarY.progress.toString() - val values = ArrayList() + val values = ArrayList() val sampleValues = getValues(100 + 2) for (i in 0..() - values.add(BarEntry(5f, floatArrayOf(-10f, 10f))) - values.add(BarEntry(15f, floatArrayOf(-12f, 13f))) - values.add(BarEntry(25f, floatArrayOf(-15f, 15f))) - values.add(BarEntry(35f, floatArrayOf(-17f, 17f))) - values.add(BarEntry(45f, floatArrayOf(-19f, 20f))) - values.add(BarEntry(45f, floatArrayOf(-19f, 20f), ResourcesCompat.getDrawable(resources, R.drawable.star, null))) - values.add(BarEntry(55f, floatArrayOf(-19f, 19f))) - values.add(BarEntry(65f, floatArrayOf(-16f, 16f))) - values.add(BarEntry(75f, floatArrayOf(-13f, 14f))) - values.add(BarEntry(85f, floatArrayOf(-10f, 11f))) - values.add(BarEntry(95f, floatArrayOf(-5f, 6f))) - values.add(BarEntry(105f, floatArrayOf(-1f, 2f))) + val values = ArrayList() + values.add(BarEntryFloat(5f, floatArrayOf(-10f, 10f))) + values.add(BarEntryFloat(15f, floatArrayOf(-12f, 13f))) + values.add(BarEntryFloat(25f, floatArrayOf(-15f, 15f))) + values.add(BarEntryFloat(35f, floatArrayOf(-17f, 17f))) + values.add(BarEntryFloat(45f, floatArrayOf(-19f, 20f))) + values.add(BarEntryFloat(45f, floatArrayOf(-19f, 20f), ResourcesCompat.getDrawable(resources, R.drawable.star, null))) + values.add(BarEntryFloat(55f, floatArrayOf(-19f, 19f))) + values.add(BarEntryFloat(65f, floatArrayOf(-16f, 16f))) + values.add(BarEntryFloat(75f, floatArrayOf(-13f, 14f))) + values.add(BarEntryFloat(85f, floatArrayOf(-10f, 11f))) + values.add(BarEntryFloat(95f, floatArrayOf(-5f, 6f))) + values.add(BarEntryFloat(105f, floatArrayOf(-1f, 2f))) val set = BarDataSet(values, "Age Distribution") set.isDrawIcons = false @@ -194,8 +194,8 @@ class StackedBarActivityNegative : DemoBase(), OnChartValueSelectedListener { saveToGallery(binding.chart1, "StackedBarActivityNegative") } - override fun onValueSelected(entry: Entry, highlight: Highlight) { - val barEntry = entry as BarEntry + override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) { + val barEntry = entryFloat as BarEntryFloat 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, entryFloat: EntryFloat?, 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 7b71841fdc..9e29813ef6 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/TimeLineActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/TimeLineActivity.kt @@ -17,7 +17,8 @@ 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.Entry +import info.appdev.charting.data.EntryDouble +import info.appdev.charting.data.EntryFloat import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet import info.appdev.charting.formatter.IFillFormatter @@ -96,38 +97,43 @@ class TimeLineActivity : DemoBase() { val sampleEntries = if (sinus) generateSineWaves(3, 30).mapIndexed { index, data -> - val valueY = (data.toFloat() * range) + 50 - Entry(timeOffset + index.toFloat() * 1000, valueY) + val valueY = (data * range) + 50 + EntryDouble(timeOffset + index * 1000.0, valueY) } else { - var previousEntry: Entry? = null + var previousEntryDouble: EntryDouble? = null getSawtoothValues(14).mapIndexed { index, data -> - val valueY = data.toFloat() * 20 - val entry = previousEntry?.let { + val valueY = data * 20 + val entryFloat = previousEntryDouble?.let { // nay third value is 0, so we add here more than 1 second, otherwise we have a one-second entry if (index % 3 == 0) { - Entry(it.x + 3000, valueY) + EntryDouble(it.xDouble + 3000.0, valueY) } else - Entry(it.x + 1000, valueY) + EntryDouble(it.xDouble + 1000.0, valueY) } ?: run { - Entry(timeOffset + index.toFloat() * 1000, valueY) + EntryDouble(timeOffset + index.toFloat() * 1000.0, valueY) } - previousEntry = entry + previousEntryDouble = entryFloat // Now you can use 'prev' which holds the previous Entry - entry + entryFloat } } val simpleDateFormat = SimpleDateFormat("HH:mm:ss.sss", Locale.getDefault()) sampleEntries.forEach { entry -> - val entryText = "Entry: x=${simpleDateFormat.format(entry.x)} x=${entry.x}, y=${entry.y}" + val entryText = "Entry: x=${simpleDateFormat.format(entry.xDouble.toLong())} xDouble=${entry.xDouble}, y=${entry.y}" Timber.d(entryText) } - val set1: LineDataSet + val set1: LineDataSet + /*The @Suppress("UNCHECKED_CAST") cast is safe here because: + * JVM erases generics at runtime — both are just MutableList on the heap + * LineDataSet only reads entries from the list as EntryFloat, and EntryDouble IS a EntryFloat + * Nothing writes a plain EntryFloat back into the list through 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.toMutableList() if (sinus) set1.lineMode = LineDataSet.Mode.LINEAR @@ -153,15 +159,17 @@ 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<*>?, dataProvider: LineDataProvider): Float { // change the return value here to better understand the effect // return 0; return binding.chart1.axisLeft.axisMinimum } } - val dataSets = ArrayList() - dataSets.add(set1) // add the data sets + @Suppress("UNCHECKED_CAST") + val dataSets = ArrayList>() + @Suppress("UNCHECKED_CAST") + dataSets.add(set1 as ILineDataSet) // add the data sets // create a data object with the data sets val data = LineData(dataSets) @@ -209,9 +217,9 @@ class TimeLineActivity : DemoBase() { val first = this[0] val second = this[1] // needed to get time diff val last = this[size - 1] - val timeDiff = (second as Entry).x - (first as Entry).x + val timeDiff = (second as EntryDouble).xDouble - (first as EntryDouble).xDouble removeAt(0) - first.x = (last as Entry).x + timeDiff + (first as EntryDouble).xDouble = (last as EntryDouble).xDouble + timeDiff add(first) } 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 af8d6733d1..713bce7423 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/compose/HorizontalBarComposeActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/compose/HorizontalBarComposeActivity.kt @@ -44,8 +44,8 @@ import info.appdev.charting.components.Legend 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.BarEntryFloat +import info.appdev.charting.data.EntryFloat import info.appdev.charting.highlight.Highlight import info.appdev.charting.interfaces.datasets.IBarDataSet import info.appdev.charting.listener.OnChartValueSelectedListener @@ -268,14 +268,14 @@ class HorizontalBarComposeActivity : DemoBaseCompose() { private fun setupChart(chart: HorizontalBarChart) { chart.setOnChartValueSelectedListener(object : OnChartValueSelectedListener { - override fun onValueSelected(entry: Entry, highlight: Highlight) { + override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) { val bounds = RectF() - chart.getBarBounds(entry as BarEntry, bounds) + chart.getBarBounds(entryFloat as BarEntryFloat, bounds) val data = chart.barData if (data != null) { val position = chart.getPosition( - entry, data.getDataSetByIndex(highlight.dataSetIndex)?.axisDependency + entryFloat, data.getDataSetByIndex(highlight.dataSetIndex)?.axisDependency ) Timber.tag("bounds $bounds") @@ -335,12 +335,12 @@ class HorizontalBarComposeActivity : DemoBaseCompose() { val barWidth = 9f val spaceForBar = 10f - val values = ArrayList() + val values = ArrayList() val sampleValues = getValues(100) for (i in 0..() + val values = ArrayList() val sampleValues = getValues(100) for (i in 0..() + val dataSets = ArrayList>() for (datasetNumber in 0..2) { - val values = ArrayList() + val values = ArrayList() val sampleValues = when (datasetNumber) { 1 -> getValues(100).reversedArray() 2 -> generateSineWaves(3, 30).toTypedArray() @@ -338,7 +338,7 @@ class MultiLineComposeActivity : DemoBaseCompose() { for (i in 0.. })) } } diff --git a/app/src/main/kotlin/info/appdev/chartexample/custom/MyMarkerView.kt b/app/src/main/kotlin/info/appdev/chartexample/custom/MyMarkerView.kt index 850e2fb44d..341019a9c2 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/custom/MyMarkerView.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/custom/MyMarkerView.kt @@ -5,8 +5,8 @@ import android.content.Context import android.widget.TextView import info.appdev.chartexample.R import info.appdev.charting.components.MarkerView -import info.appdev.charting.data.CandleEntry -import info.appdev.charting.data.Entry +import info.appdev.charting.data.CandleEntryFloat +import info.appdev.charting.data.EntryFloat import info.appdev.charting.highlight.Highlight import info.appdev.charting.utils.PointF import info.appdev.charting.utils.formatNumber @@ -20,14 +20,14 @@ class MyMarkerView(context: Context?, layoutResource: Int) : MarkerView(context, // runs every time the MarkerView is redrawn, can be used to update the content (user-interface) - override fun refreshContent(entry: Entry, highlight: Highlight) { - if (entry is CandleEntry) { - tvContent.text = entry.high.formatNumber(0, true) + override fun refreshContent(entryFloat: EntryFloat, highlight: Highlight) { + if (entryFloat is CandleEntryFloat) { + tvContent.text = entryFloat.high.formatNumber(0, true) } else { - tvContent.text = entry.y.formatNumber(0, true) + tvContent.text = entryFloat.y.formatNumber(0, true) } - super.refreshContent(entry, highlight) + super.refreshContent(entryFloat, highlight) } override var offset: PointF = PointF() diff --git a/app/src/main/kotlin/info/appdev/chartexample/custom/RadarMarkerView.kt b/app/src/main/kotlin/info/appdev/chartexample/custom/RadarMarkerView.kt index 7c270133dd..2a0454b973 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/custom/RadarMarkerView.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/custom/RadarMarkerView.kt @@ -6,7 +6,7 @@ import android.graphics.Typeface import android.widget.TextView import info.appdev.chartexample.R import info.appdev.charting.components.MarkerView -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.highlight.Highlight import info.appdev.charting.utils.PointF import java.text.DecimalFormat @@ -25,10 +25,10 @@ class RadarMarkerView(context: Context, layoutResource: Int) : MarkerView(contex // runs every time the MarkerView is redrawn, can be used to update the // content (user-interface) - override fun refreshContent(entry: Entry, highlight: Highlight) { - tvContent.text = String.format("%s %%", format.format(entry.y.toDouble())) + override fun refreshContent(entryFloat: EntryFloat, highlight: Highlight) { + tvContent.text = String.format("%s %%", format.format(entryFloat.y.toDouble())) - super.refreshContent(entry, highlight) + super.refreshContent(entryFloat, highlight) } override var offset: PointF = PointF() diff --git a/app/src/main/kotlin/info/appdev/chartexample/custom/StackedBarsMarkerView.kt b/app/src/main/kotlin/info/appdev/chartexample/custom/StackedBarsMarkerView.kt index 62bd94cbcd..51a4c44176 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/custom/StackedBarsMarkerView.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/custom/StackedBarsMarkerView.kt @@ -5,8 +5,8 @@ import android.content.Context import android.widget.TextView import info.appdev.chartexample.R import info.appdev.charting.components.MarkerView -import info.appdev.charting.data.BarEntry -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BarEntryFloat +import info.appdev.charting.data.EntryFloat import info.appdev.charting.highlight.Highlight import info.appdev.charting.utils.PointF import info.appdev.charting.utils.formatNumber @@ -21,20 +21,20 @@ class StackedBarsMarkerView(context: Context?, layoutResource: Int) : MarkerView // runs every time the MarkerView is redrawn, can be used to update the // content (user-interface) - override fun refreshContent(entry: Entry, highlight: Highlight) { - if (entry is BarEntry) { + override fun refreshContent(entryFloat: EntryFloat, highlight: Highlight) { + if (entryFloat is BarEntryFloat) { - if (entry.yVals != null) { + if (entryFloat.yVals != null) { // draw the stack value - tvContent.text = entry.yVals!![highlight.stackIndex].formatNumber(0, true) + tvContent.text = entryFloat.yVals!![highlight.stackIndex].formatNumber(0, true) } else { - tvContent.text = entry.y.formatNumber(0, true) + tvContent.text = entryFloat.y.formatNumber(0, true) } } else { - tvContent.text = entry.y.formatNumber(0, true) + tvContent.text = entryFloat.y.formatNumber(0, true) } - super.refreshContent(entry, highlight) + super.refreshContent(entryFloat, highlight) } override var offset: PointF = PointF() diff --git a/app/src/main/kotlin/info/appdev/chartexample/custom/TimeMarkerView.kt b/app/src/main/kotlin/info/appdev/chartexample/custom/TimeMarkerView.kt index c4d99bb56f..59738a6031 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/custom/TimeMarkerView.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/custom/TimeMarkerView.kt @@ -5,7 +5,7 @@ import android.content.Context import android.widget.TextView import info.appdev.chartexample.R import info.appdev.charting.components.MarkerView -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.highlight.Highlight import info.appdev.charting.interfaces.datasets.IDataSet import info.appdev.charting.utils.PointF @@ -19,10 +19,10 @@ class TimeMarkerView(context: Context?, layoutResource: Int, val format: String private val tvContent: TextView = findViewById(R.id.tvContent) @SuppressLint("SetTextI18n") - override fun refreshContent(entry: Entry, highlight: Highlight) { + override fun refreshContent(entryFloat: EntryFloat, highlight: Highlight) { @Suppress("UNCHECKED_CAST") - val dataset = this.chartView?.data?.dataSets[0] as? IDataSet - val myIndex = dataset?.getEntryIndex(entry) + val dataset = this.chartView?.data?.dataSets[0] as? IDataSet + val myIndex = dataset?.getEntryIndex(entryFloat) val nextEntry = myIndex?.let { if (it < dataset.entryCount - 1) dataset.getEntryForIndex(myIndex + 1) @@ -30,9 +30,9 @@ class TimeMarkerView(context: Context?, layoutResource: Int, val format: String null } ?: run { null } - val duration = if (nextEntry != null) " - duration:${(nextEntry.x - entry.x)}" else "" - tvContent.text = "${simpleDateFormat.format(entry.x)}$duration" - super.refreshContent(entry, highlight) + val duration = if (nextEntry != null) " - duration:${(nextEntry.x - entryFloat.x)}" else "" + tvContent.text = "${simpleDateFormat.format(entryFloat.x)}$duration" + super.refreshContent(entryFloat, highlight) } override var offset: PointF = PointF() diff --git a/app/src/main/kotlin/info/appdev/chartexample/custom/XYMarkerView.kt b/app/src/main/kotlin/info/appdev/chartexample/custom/XYMarkerView.kt index ffc7ce814c..68a9ba4db2 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/custom/XYMarkerView.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/custom/XYMarkerView.kt @@ -5,7 +5,7 @@ import android.content.Context import android.widget.TextView import info.appdev.chartexample.R import info.appdev.charting.components.MarkerView -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.formatter.IAxisValueFormatter import info.appdev.charting.highlight.Highlight import info.appdev.charting.utils.PointF @@ -21,10 +21,10 @@ class XYMarkerView(context: Context?, private val xAxisValueFormatter: IAxisValu private val format: DecimalFormat = DecimalFormat("###.0") // runs every time the MarkerView is redrawn, can be used to update the content (user-interface) - override fun refreshContent(entry: Entry, highlight: Highlight) { - tvContent.text = String.format("x: %s, y: %s", xAxisValueFormatter.getFormattedValue(entry.x, null), format.format(entry.y.toDouble())) + override fun refreshContent(entryFloat: EntryFloat, highlight: Highlight) { + tvContent.text = String.format("x: %s, y: %s", xAxisValueFormatter.getFormattedValue(entryFloat.x, null), format.format(entryFloat.y.toDouble())) - super.refreshContent(entry, highlight) + super.refreshContent(entryFloat, highlight) } override var offset: PointF = PointF() 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 808db2daff..7f7b208527 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/formatter/MyFillFormatter.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/formatter/MyFillFormatter.kt @@ -6,7 +6,7 @@ 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<*>?, 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 a32ce54136..a61d8c58c2 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.EntryFloat 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, entryFloat: EntryFloat?, 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 6a9053ea57..5907041a97 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/fragments/SimpleFragment.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/fragments/SimpleFragment.kt @@ -11,13 +11,13 @@ import info.appdev.chartexample.DataTools.Companion.getValues 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.Entry +import info.appdev.charting.data.BarEntryFloat +import info.appdev.charting.data.EntryFloat import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet import info.appdev.charting.data.PieData import info.appdev.charting.data.PieDataSet -import info.appdev.charting.data.PieEntry +import info.appdev.charting.data.PieEntryFloat import info.appdev.charting.data.ScatterData import info.appdev.charting.data.ScatterDataSet import info.appdev.charting.interfaces.datasets.IBarDataSet @@ -41,10 +41,10 @@ abstract class SimpleFragment : Fragment() { val sets = ArrayList() for (i in 0..() + val entries = ArrayList() for (j in 0..() + val entries = ArrayList() for (j in 0..() + val entries1 = ArrayList() for (i in 0..() + val sets = ArrayList>() val ds1 = LineDataSet(requireContext().assets.loadEntriesFromAssets("sine.txt"), "Sine function") val ds2 = LineDataSet(requireContext().assets.loadEntriesFromAssets("cosine.txt"), "Cosine function") @@ -135,7 +135,7 @@ abstract class SimpleFragment : Fragment() { protected val complexity: LineData get() { - val sets = ArrayList() + val sets = ArrayList>() val ds1 = LineDataSet(requireContext().assets.loadEntriesFromAssets("n.txt"), "O(n)") val ds2 = LineDataSet(requireContext().assets.loadEntriesFromAssets("nlogn.txt"), "O(nlogn)") diff --git a/chartLib/src/main/kotlin/info/appdev/charting/charts/BarChart.kt b/chartLib/src/main/kotlin/info/appdev/charting/charts/BarChart.kt index d4930053bd..6175717565 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/charts/BarChart.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/charts/BarChart.kt @@ -5,7 +5,7 @@ import android.graphics.RectF import android.util.AttributeSet import info.appdev.charting.components.YAxis import info.appdev.charting.data.BarData -import info.appdev.charting.data.BarEntry +import info.appdev.charting.data.BarEntryFloat import info.appdev.charting.highlight.BarHighlighter import info.appdev.charting.highlight.Highlight import info.appdev.charting.interfaces.dataprovider.BarDataProvider @@ -146,7 +146,7 @@ open class BarChart : BarLineChartBase, BarDataProvider { * Returns the bounding box of the specified Entry in the specified DataSet. Returns null if the Entry could not be * found in the charts data. Performance-intensive code should use void getBarBounds(BarEntry, RectF) instead. */ - fun getBarBounds(barEntry: BarEntry): RectF { + fun getBarBounds(barEntry: BarEntryFloat): RectF { val bounds = RectF() getBarBounds(barEntry, bounds) @@ -157,7 +157,7 @@ open class BarChart : BarLineChartBase, BarDataProvider { * The passed outputRect will be assigned the values of the bounding box of the specified Entry in the specified DataSet. * The rect will be assigned Float.MIN_VALUE in all locations if the Entry could not be found in the charts data. */ - open fun getBarBounds(barEntry: BarEntry, outputRect: RectF) { + open fun getBarBounds(barEntry: BarEntryFloat, outputRect: RectF) { mData?.let { barData -> val set = barData.getDataSetForEntry(barEntry) 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 a4eab0f84b..350d7e1bf0 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/charts/BarLineChartBase.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/charts/BarLineChartBase.kt @@ -16,7 +16,8 @@ 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.Entry +import info.appdev.charting.data.BaseEntry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.highlight.ChartHighlighter import info.appdev.charting.interfaces.dataprovider.base.BarLineScatterCandleBubbleDataProvider import info.appdev.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet @@ -46,7 +47,7 @@ import kotlin.math.min */ @Suppress("unused") @SuppressLint("RtlHardcoded") -abstract class BarLineChartBase>> : Chart, +abstract class BarLineChartBase>> : Chart, BarLineScatterCandleBubbleDataProvider { /** * the maximum number of entries to which values will be drawn @@ -956,7 +957,7 @@ abstract class BarLineChartBase>> : ViewGroup, IBaseProvider { +abstract class Chart>> : ViewGroup, IBaseProvider { /** * Returns true if log-output is enabled for the chart, fals if not. */ @@ -527,7 +527,7 @@ abstract class Chart>> : ViewGroup, IBaseP */ fun highlightValue(high: Highlight?, callListener: Boolean) { var high = high - var entry: Entry? = null + var entryFloat: EntryFloat? = null if (high == null) { this.highlighted = null @@ -536,8 +536,8 @@ abstract class Chart>> : ViewGroup, IBaseP Timber.i("Highlighted: $high") } - entry = mData!!.getEntryForHighlight(high) - if (entry == null) { + entryFloat = mData!!.getEntryForHighlight(high) + if (entryFloat == null) { this.highlighted = null high = null } else { @@ -554,7 +554,7 @@ abstract class Chart>> : ViewGroup, IBaseP listener.onNothingSelected() } else { // notify the listener - listener.onValueSelected(entry!!, high!!) + listener.onValueSelected(entryFloat!!, high!!) } } // redraw the chart @@ -623,7 +623,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 val entryIndex = set.getEntryIndex(entry) if (entryIndex > set.entryCount * mAnimator.phaseX) { 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 013bfc8816..5a008d2346 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/charts/CombinedChart.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/charts/CombinedChart.kt @@ -7,7 +7,7 @@ import info.appdev.charting.data.BarData 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.EntryFloat 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 val entryIndex = set.getEntryIndex(entry) // make sure entry not null diff --git a/chartLib/src/main/kotlin/info/appdev/charting/charts/HorizontalBarChart.kt b/chartLib/src/main/kotlin/info/appdev/charting/charts/HorizontalBarChart.kt index 2ed51233dd..33506ae2f2 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/charts/HorizontalBarChart.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/charts/HorizontalBarChart.kt @@ -8,8 +8,8 @@ import info.appdev.charting.components.Legend.LegendOrientation import info.appdev.charting.components.Legend.LegendVerticalAlignment import info.appdev.charting.components.XAxis.XAxisPosition import info.appdev.charting.components.YAxis.AxisDependency -import info.appdev.charting.data.BarEntry -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BarEntryFloat +import info.appdev.charting.data.EntryFloat import info.appdev.charting.highlight.Highlight import info.appdev.charting.highlight.HorizontalBarHighlighter import info.appdev.charting.renderer.HorizontalBarChartRenderer @@ -206,7 +206,7 @@ open class HorizontalBarChart : BarChart { return floatArrayOf(high.drawY, high.drawX) } - override fun getBarBounds(barEntry: BarEntry, outputRect: RectF) { + override fun getBarBounds(barEntry: BarEntryFloat, outputRect: RectF) { mData?.let { data -> val set = data.getDataSetForEntry(barEntry) @@ -231,7 +231,7 @@ open class HorizontalBarChart : BarChart { /** * Returns a recyclable PointF instance. */ - override fun getPosition(e: Entry?, axis: AxisDependency?): PointF? { + override fun getPosition(e: EntryFloat?, axis: AxisDependency?): PointF? { if (e == null) { return 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 76b043d60b..a5d0d82f51 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/charts/PieRadarChartBase.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/charts/PieRadarChartBase.kt @@ -10,7 +10,7 @@ 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.ChartData -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat 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>> : Chart { /** * holds the normalized version of the current rotation angle of the chart diff --git a/chartLib/src/main/kotlin/info/appdev/charting/components/IMarker.kt b/chartLib/src/main/kotlin/info/appdev/charting/components/IMarker.kt index 61af265af9..52cc7dc8ab 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/components/IMarker.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/components/IMarker.kt @@ -1,7 +1,7 @@ package info.appdev.charting.components import android.graphics.Canvas -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.highlight.Highlight import info.appdev.charting.utils.PointF @@ -27,12 +27,12 @@ interface IMarker { /** * This method enables a specified custom IMarker to update it's content every time the IMarker is redrawn. * - * @param entry The Entry the IMarker belongs to. This can also be any subclass of Entry, like BarEntry or + * @param entryFloat The Entry the IMarker belongs to. This can also be any subclass of Entry, like BarEntry or * CandleEntry, simply cast it at runtime. * @param highlight The highlight object contains information about the highlighted value such as it's dataset-index, the * selected range or stack-index (only stacked bar entries). */ - fun refreshContent(entry: Entry, highlight: Highlight) + fun refreshContent(entryFloat: EntryFloat, highlight: Highlight) /** * Draws the IMarker on the given position on the screen with the given Canvas object. diff --git a/chartLib/src/main/kotlin/info/appdev/charting/components/MarkerImage.kt b/chartLib/src/main/kotlin/info/appdev/charting/components/MarkerImage.kt index c6ce670267..0db59d9b98 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/components/MarkerImage.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/components/MarkerImage.kt @@ -5,7 +5,7 @@ import android.graphics.Canvas import android.graphics.Rect import android.graphics.drawable.Drawable import info.appdev.charting.charts.Chart -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.highlight.Highlight import info.appdev.charting.utils.FSize import info.appdev.charting.utils.PointF @@ -94,7 +94,7 @@ class MarkerImage(private var mContext: Context, drawableResourceId: Int) : IMar return mOffset2 } - override fun refreshContent(entry: Entry, highlight: Highlight) = Unit + override fun refreshContent(entryFloat: EntryFloat, highlight: Highlight) = Unit override fun draw(canvas: Canvas, posX: Float, posY: Float) { if (drawable == null) diff --git a/chartLib/src/main/kotlin/info/appdev/charting/components/MarkerView.kt b/chartLib/src/main/kotlin/info/appdev/charting/components/MarkerView.kt index 7592d71e40..f7cf73ea0e 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/components/MarkerView.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/components/MarkerView.kt @@ -5,7 +5,7 @@ import android.graphics.Canvas import android.view.LayoutInflater import android.widget.RelativeLayout import info.appdev.charting.charts.Chart -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.highlight.Highlight import info.appdev.charting.utils.PointF import java.lang.ref.WeakReference @@ -74,7 +74,7 @@ open class MarkerView(context: Context?, layoutResource: Int) : RelativeLayout(c return mOffset2 } - override fun refreshContent(entry: Entry, highlight: Highlight) { + override fun refreshContent(entryFloat: EntryFloat, highlight: Highlight) { measure( MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED) 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 c4114435ee..1e94ef0ca8 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,8 +50,8 @@ open class BarDataSet(yVals: MutableList, label: String) : BarLineScat calcEntryCountIncludingStacks(yVals) } - override fun copy(): DataSet? { - val entries: MutableList = mutableListOf() + override fun copy(): DataSet? { + val entries: MutableList = mutableListOf() for (i in entriesInternal.indices) { entries.add(entriesInternal[i].copy()) } @@ -101,7 +101,7 @@ open class BarDataSet(yVals: MutableList, label: String) : BarLineScat * Calculates the total number of entries this DataSet represents, including * stacks. All values belonging to a stack are calculated separately. */ - private fun calcEntryCountIncludingStacks(yVals: MutableList) { + private fun calcEntryCountIncludingStacks(yVals: MutableList) { this.entryCountStacks = 0 for (i in yVals.indices) { @@ -115,7 +115,7 @@ open class BarDataSet(yVals: MutableList, label: String) : BarLineScat /** * calculates the maximum stackSize that occurs in the Entries array of this DataSet */ - private fun calcStackSize(yVals: MutableList) { + private fun calcStackSize(yVals: MutableList) { for (i in yVals.indices) { val vals = yVals[i].yVals @@ -123,7 +123,7 @@ open class BarDataSet(yVals: MutableList, label: String) : BarLineScat } } - override fun calcMinMax(entry: BarEntry) { + override fun calcMinMax(entry: BarEntryFloat) { if (!entry.y.isNaN()) { if (entry.yVals == null) { if (entry.y < yMin) yMin = entry.y diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/BarEntryDouble.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/BarEntryDouble.kt new file mode 100644 index 0000000000..6560d5d26d --- /dev/null +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/BarEntryDouble.kt @@ -0,0 +1,146 @@ +package info.appdev.charting.data + +import android.graphics.drawable.Drawable +import info.appdev.charting.highlight.RangeDouble +import kotlin.math.abs + +/** + * High-precision bar entry that stores x and y as Double, extending [BarEntryFloat] + * so it works seamlessly in the existing bar chart rendering pipeline. + * Use [xDouble] and [yDouble] for full-precision access. + * For stacked bars use [yValsDouble] and [rangesDouble]. + */ +open class BarEntryDouble : BarEntryFloat { + + var xDouble: Double = 0.0 + var yDouble: Double = 0.0 + + override var x: Float + get() = xDouble.toFloat() + set(value) { xDouble = value.toDouble() } + + /** + * Returns the double-precision stacked values, or null for simple bars. + */ + var yValsDouble: DoubleArray? = null + private set + + /** + * Double-precision ranges for stacked bars. + */ + var rangesDouble: Array = arrayOf() + private set + + var negativeDoubleSum: Double = 0.0 + private set + + var positiveDoubleSum: Double = 0.0 + private set + + // ── Simple bar constructors ────────────────────────────────────────────── + + constructor(x: Double, y: Double) : super(x.toFloat(), y.toFloat()) { + xDouble = x; yDouble = y + } + + constructor(x: Double, y: Double, data: Any?) : super(x.toFloat(), y.toFloat(), data) { + xDouble = x; yDouble = y + } + + constructor(x: Double, y: Double, icon: Drawable?) : super(x.toFloat(), y.toFloat(), icon) { + xDouble = x; yDouble = y + } + + constructor(x: Double, y: Double, icon: Drawable?, data: Any?) : super(x.toFloat(), y.toFloat(), icon, data) { + xDouble = x; yDouble = y + } + + // ── Stacked bar constructors ───────────────────────────────────────────── + + constructor(x: Double, vals: DoubleArray?) : super(x.toFloat(), calcDoubleSum(vals).toFloat()) { + xDouble = x + yDouble = calcDoubleSum(vals) + yValsDouble = vals + calcDoublePosNegSum() + calcDoubleRanges() + } + + constructor(x: Double, vals: DoubleArray?, data: Any?) : super(x.toFloat(), calcDoubleSum(vals).toFloat(), data) { + xDouble = x + yDouble = calcDoubleSum(vals) + yValsDouble = vals + calcDoublePosNegSum() + calcDoubleRanges() + } + + constructor(x: Double, vals: DoubleArray?, icon: Drawable?) : super(x.toFloat(), calcDoubleSum(vals).toFloat(), icon) { + xDouble = x + yDouble = calcDoubleSum(vals) + yValsDouble = vals + calcDoublePosNegSum() + calcDoubleRanges() + } + + // ── y override (always reflects yDouble) ──────────────────────────────── + + override var y: Float + get() = yDouble.toFloat() + set(value) { yDouble = value.toDouble() } + + // ── Stack helpers ──────────────────────────────────────────────────────── + + val isStackedDouble: Boolean get() = yValsDouble != null + + fun setValsDouble(vals: DoubleArray?) { + yDouble = calcDoubleSum(vals) + yValsDouble = vals + calcDoublePosNegSum() + calcDoubleRanges() + } + + fun getSumBelowDouble(stackIndex: Int): Double { + val vals = yValsDouble ?: return 0.0 + var remainder = 0.0 + var index = vals.size - 1 + while (index > stackIndex && index >= 0) { + remainder += vals[index] + index-- + } + return remainder + } + + private fun calcDoublePosNegSum() { + val vals = yValsDouble + if (vals == null) { negativeDoubleSum = 0.0; positiveDoubleSum = 0.0; return } + var sumNeg = 0.0; var sumPos = 0.0 + for (v in vals) { if (v <= 0.0) sumNeg += abs(v) else sumPos += v } + negativeDoubleSum = sumNeg; positiveDoubleSum = sumPos + } + + private fun calcDoubleRanges() { + val values = yValsDouble + if (values == null || values.isEmpty()) return + + rangesDouble = Array(values.size) { RangeDouble(0.0, 0.0) } + var negRemain = -negativeDoubleSum + var posRemain = 0.0 + + for (i in values.indices) { + val value = values[i] + if (value < 0) { + rangesDouble[i] = RangeDouble(negRemain, negRemain - value) + negRemain -= value + } else { + rangesDouble[i] = RangeDouble(posRemain, posRemain + value) + posRemain += value + } + } + } + + override fun toString(): String = "BarEntryDouble xDouble=$xDouble yDouble=$yDouble yValsDouble=${yValsDouble?.contentToString()}" + + companion object { + private fun calcDoubleSum(vals: DoubleArray?): Double = vals?.sum() ?: 0.0 + } +} + diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/BarEntry.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/BarEntryFloat.kt similarity index 97% rename from chartLib/src/main/kotlin/info/appdev/charting/data/BarEntry.kt rename to chartLib/src/main/kotlin/info/appdev/charting/data/BarEntryFloat.kt index 1e4f78b3d9..1ce910a01b 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/BarEntry.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/BarEntryFloat.kt @@ -9,7 +9,7 @@ import kotlin.math.abs * Entry class for the BarChart. (especially stacked bars) */ @SuppressLint("ParcelCreator") -open class BarEntry : Entry { +open class BarEntryFloat : EntryFloat { /** * Returns the stacked values this BarEntry represents, or null, if only a single value is represented (then, use * getY()). @@ -123,8 +123,8 @@ open class BarEntry : Entry { /** * Returns an exact copy of the BarEntry. */ - override fun copy(): BarEntry { - val copied = BarEntry(x, y, data) + override fun copy(): BarEntryFloat { + val copied = BarEntryFloat(x, y, data) copied.setVals(this.yVals) return copied } 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 96c08ef04b..f58db38602 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, + T : IBarLineScatterCandleBubbleDataSet { 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 fbc22d82ee..2751e47033 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 10208d61fd..110ae26cb0 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. Its 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 d553eb652d..fcc4bf3f1c 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/BaseEntry.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/BaseEntry.kt @@ -2,10 +2,17 @@ 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 + protected lateinit var xBase: T + open var x: T + get() = xBase + set(value) { + xBase = value + } + + protected lateinit var yBase: T + open var y: T get() = yBase set(value) { yBase = value @@ -17,19 +24,37 @@ abstract class BaseEntry { constructor() - constructor(y: Float) { + constructor(y: T) { + this.yBase = y + } + + constructor(x: T, y: T) { + this.xBase = x this.yBase = y } - constructor(y: Float, data: Any?) : this(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 = y) { + this.icon = icon + this.data = data + } + + constructor(x: T, y: T, data: Any?) : this(x = x, y = y) { this.data = data } - constructor(y: Float, icon: Drawable?) : this(y) { + constructor(x: T, y: T, icon: Drawable?) : this(x = x, y = y) { this.icon = icon } - constructor(y: Float, icon: Drawable?, data: Any?) : this(y) { + constructor(x: T, y: T, icon: Drawable?, data: Any?) : this(x = x, y = y) { this.icon = icon this.data = data } 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 05c8183c6a..4bf3132830 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/BubbleDataSet.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/BubbleDataSet.kt @@ -3,13 +3,13 @@ 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 private var mHighlightCircleWidth = 2.5f - override fun calcMinMax(entry: BubbleEntry) { + override fun calcMinMax(entry: BubbleEntryFloat) { super.calcMinMax(entry) val size = entry.size @@ -19,8 +19,8 @@ open class BubbleDataSet(yVals: MutableList, label: String) : BarLi } } - override fun copy(): DataSet { - val entries: MutableList = ArrayList() + override fun copy(): DataSet { + val entries: MutableList = ArrayList() for (i in entriesInternal.indices) { entries.add(entriesInternal[i].copy()) } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/BubbleEntry.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/BubbleEntryFloat.kt similarity index 90% rename from chartLib/src/main/kotlin/info/appdev/charting/data/BubbleEntry.kt rename to chartLib/src/main/kotlin/info/appdev/charting/data/BubbleEntryFloat.kt index 0ea928773e..8cba5b64ea 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/BubbleEntry.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/BubbleEntryFloat.kt @@ -8,7 +8,7 @@ import android.graphics.drawable.Drawable * chart implementation: Copyright 2015 Pierre-Marc Airoldi Licensed under Apache License 2.0 */ @SuppressLint("ParcelCreator") -class BubbleEntry : Entry { +class BubbleEntryFloat : EntryFloat { /** * Returns the size of this entry (the size of the bubble). */ @@ -49,7 +49,7 @@ class BubbleEntry : Entry { this.size = size } - override fun copy(): BubbleEntry { - return BubbleEntry(x, y, this.size, data) + override fun copy(): BubbleEntryFloat { + return BubbleEntryFloat(x, y, this.size, data) } } 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 685d9afacd..79e4d142df 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,8 +69,8 @@ open class CandleDataSet(yVals: MutableList, label: String = "") : @ColorInt protected var mShadowColor: Int = ColorTemplate.COLOR_SKIP - override fun copy(): DataSet { - val entries: MutableList = mutableListOf() + override fun copy(): DataSet { + val entries: MutableList = mutableListOf() for (i in entriesInternal.indices) { entries.add(entriesInternal[i].copy()) } @@ -95,7 +95,7 @@ open class CandleDataSet(yVals: MutableList, label: String = "") : candleDataSet.mShadowColor = mShadowColor } - override fun calcMinMax(entry: CandleEntry) { + override fun calcMinMax(entry: CandleEntryFloat) { entry.let { if (entry.low < yMin) yMin = entry.low @@ -104,7 +104,7 @@ open class CandleDataSet(yVals: MutableList, label: String = "") : calcMinMaxX(entry) } - override fun calcMinMaxY(entry: CandleEntry) { + override fun calcMinMaxY(entry: CandleEntryFloat) { entry.let { if (entry.high < yMin) yMin = entry.high diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/CandleEntry.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/CandleEntryFloat.kt similarity index 95% rename from chartLib/src/main/kotlin/info/appdev/charting/data/CandleEntry.kt rename to chartLib/src/main/kotlin/info/appdev/charting/data/CandleEntryFloat.kt index 82c07b47c4..a138d18811 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/CandleEntry.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/CandleEntryFloat.kt @@ -8,7 +8,7 @@ import kotlin.math.abs * Subclass of Entry that holds all values for one entry in a CandleStickChart. */ @SuppressLint("ParcelCreator") -class CandleEntry : Entry { +class CandleEntryFloat : EntryFloat { /** * Returns the upper shadows highest value. */ @@ -121,7 +121,7 @@ class CandleEntry : Entry { super.y = value } - override fun copy(): CandleEntry { - return CandleEntry(x, this.high, this.low, this.open, this.close, data) + override fun copy(): CandleEntryFloat { + return CandleEntryFloat(x, this.high, this.low, this.open, this.close, 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 698d142be0..84ee4ea1cf 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 { /** * maximum y-value in the value array across all axes */ @@ -52,7 +52,7 @@ abstract class ChartData> : Serializable { protected set constructor() { - this.dataSets = ArrayList() + this.dataSets = ArrayList() } constructor(vararg dataSets: T) { @@ -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): EntryFloat? { return if (highlight.dataSetIndex >= dataSets.size) { null } else { @@ -326,17 +326,17 @@ abstract class ChartData> : Serializable { * Entries are added to the end of the list. */ @Suppress("UNCHECKED_CAST") - fun addEntry(entry: Entry, dataSetIndex: Int) { + fun addEntry(entryFloat: EntryFloat, dataSetIndex: Int) { 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 - if (!dataSet.addEntry(entry)) { + val dataSet = set as IDataSet + if (!dataSet.addEntry(entryFloat)) { return } - calcMinMax(entry, set.axisDependency) + calcMinMax(entryFloat, set.axisDependency) } else { Timber.e("Cannot add Entry because dataSetIndex too high or too low.") } @@ -345,7 +345,7 @@ abstract class ChartData> : Serializable { /** * Adjusts the current minimum and maximum values based on the provided Entry object. */ - protected fun calcMinMax(e: Entry, axis: AxisDependency?) { + protected fun calcMinMax(e: EntryFloat, axis: AxisDependency?) { if (this.yMax < e.y) { this.yMax = e.y } @@ -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(entryFloat: EntryFloat, dataSetIndex: Int): Boolean { // entry null, out of bounds if (dataSetIndex >= dataSets.size) { return false @@ -425,8 +425,8 @@ abstract class ChartData> : Serializable { val set: T = dataSets[dataSetIndex] // remove the entry from the dataset - val dataSet = set as IDataSet - val removed: Boolean = dataSet.removeEntry(entry) + val dataSet = set as IDataSet + val removed: Boolean = dataSet.removeEntry(entryFloat) if (removed) { notifyDataChanged() @@ -446,15 +446,15 @@ abstract class ChartData> : Serializable { } val dataSet: IDataSet<*> = dataSets[dataSetIndex] - val entry: Entry = dataSet.getEntryForXValue(xValue, Float.NaN) ?: return false + val entryFloat: EntryFloat = dataSet.getEntryForXValue(xValue, Float.NaN) as? EntryFloat ?: return false - return removeEntry(entry, dataSetIndex) + return removeEntry(entryFloat, dataSetIndex) } /** * Returns the DataSet that contains the provided Entry, or null, if no DataSet contains this Entry. */ - fun getDataSetForEntry(e: Entry): T? { + fun getDataSetForEntry(e: EntryFloat): T? { for (i in dataSets.indices) { val set = dataSets[i] 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 f90fe2b56f..c2a18bd669 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>() { +class CombinedData : BarLineScatterCandleBubbleData>() { var lineData: LineData? = null private set var barData: BarData? = null @@ -130,7 +130,7 @@ class CombinedData : BarLineScatterCandleBubbleData= this.allData.size || highlight.dataIndex < 0) return null @@ -156,7 +156,7 @@ class CombinedData : BarLineScatterCandleBubbleData? { + fun getDataSetByHighlight(highlight: Highlight): IBarLineScatterCandleBubbleDataSet? { 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? } fun getDataIndex(data: ChartData<*>?): Int { return this.allData.indexOf(data) } - override fun removeDataSet(d: IBarLineScatterCandleBubbleDataSet?): Boolean { + override fun removeDataSet(d: IBarLineScatterCandleBubbleDataSet?): Boolean { val datas = this.allData var success = false @@ -195,7 +195,7 @@ class CombinedData : BarLineScatterCandleBubbleData( +abstract class DataSet>( protected var entriesInternal: MutableList, label: String = "" ) : BaseDataSet(label), Serializable { @@ -219,31 +219,22 @@ abstract class DataSet( while (low < high) { val m = low + (high - low) / 2 - val currentEntry: Entry = entriesInternal[m] + val current = entriesInternal[m] + val next = entriesInternal[m + 1] - val nextEntry: Entry = entriesInternal[m + 1] - - val d1 = currentEntry.x - xValue - val d2 = nextEntry.x - xValue + val d1 = current.x - xValue + val d2 = next.x - xValue val ad1 = abs(d1) val ad2 = abs(d2) if (ad2 < ad1) { - // [m + 1] is closer to xValue - // Search in a higher place low = m + 1 } else if (ad1 < ad2) { - // [m] is closer to xValue - // Search in a lower place high = m } else { - // We have multiple sequential x-value with same distance - if (d1 >= 0.0) { - // Search in a lower place high = m } else if (d1 < 0.0) { - // Search in a higher place low = m + 1 } } @@ -251,21 +242,18 @@ abstract class DataSet( closest = high } - val closestEntry: Entry = entriesInternal[closest] + val closestEntry = entriesInternal[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... if (closestXValue < xValue && closest < entriesInternal.size - 1) { ++closest } } else if (rounding == Rounding.DOWN) { - // If rounding down, and found x-value is upper than specified x, and we can go lower... if (closestXValue > xValue && closest > 0) { --closest } } - // Search by closest to y-value if (!closestToY.isNaN()) { while (closest > 0 && entriesInternal[closest - 1].x == closestXValue) { closest -= 1 @@ -276,15 +264,10 @@ abstract class DataSet( while (true) { closest += 1 - if (closest >= entriesInternal.size) { - break - } + if (closest >= entriesInternal.size) break val value: T = entriesInternal[closest] - - if (value.x != closestXValue) { - break - } + if (value.x != closestXValue) break if (abs(value.y - closestToY) <= abs(closestYValue - closestToY)) { closestYValue = closestToY 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 284880c978..31b3138a9c 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,82 @@ package info.appdev.charting.data -class EntryDouble(val xDouble: Double, y: Float) : Entry(xDouble.toFloat(), y) +import android.graphics.drawable.Drawable +import android.os.Build +import java.io.Serializable +import kotlin.math.abs +import info.appdev.charting.utils.Utils + +/** + * High-precision entry that stores x and y as Double, but extends EntryFloat + * so it works seamlessly in the existing chart rendering pipeline. + * Use [xDouble] and [yDouble] to access the full-precision values. + */ +open class EntryDouble : EntryFloat, Serializable { + + var xDouble: Double = 0.0 + var yDouble: Double = 0.0 + + /** + * Override x to store/return via xDouble for high precision; + * the base chart pipeline reads x.toFloat() transparently. + */ + override var x: Float + get() = xDouble.toFloat() + set(value) { + xDouble = value.toDouble() + } + + /** + * Override y to store/return via yDouble for high precision; + * the base chart pipeline reads y.toFloat() transparently. + */ + override var y: Float + get() = yDouble.toFloat() + set(value) { + yDouble = value.toDouble() + } + + constructor() : super() + + constructor(x: Double, y: Double) : super() { + this.xDouble = x + this.yDouble = y + } + + constructor(x: Double, y: Double, data: Any?) : super() { + this.xDouble = x + this.yDouble = y + this.data = data + } + + constructor(x: Double, y: Double, icon: Drawable?) : super() { + this.xDouble = x + this.yDouble = y + this.icon = icon + } + + constructor(x: Double, y: Double, icon: Drawable?, data: Any?) : super() { + this.xDouble = x + this.yDouble = y + this.icon = icon + this.data = data + } + + open fun copyDouble(): EntryDouble = EntryDouble(xDouble, yDouble, data) + + fun equalTo(other: EntryDouble?): Boolean { + if (other == null) return false + if (other.data !== this.data) return false + if (abs(other.xDouble - this.xDouble) > Utils.DOUBLE_EPSILON) return false + if (abs(other.yDouble - this.yDouble) > Utils.DOUBLE_EPSILON) return false + return true + } + + override fun toString(): String { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + "${this.javaClass.typeName.substringAfterLast(".")} xDouble=$xDouble yDouble=$yDouble" + } else { + "EntryDouble xDouble=$xDouble yDouble=$yDouble" + } + } +} diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/Entry.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/EntryFloat.kt similarity index 66% rename from chartLib/src/main/kotlin/info/appdev/charting/data/Entry.kt rename to chartLib/src/main/kotlin/info/appdev/charting/data/EntryFloat.kt index db85d860bc..f25202e989 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/Entry.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/EntryFloat.kt @@ -13,66 +13,55 @@ 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 { - - private var _x: Float = 0f - open var x: Float - get() = _x - set(value) { - _x = value - } +open class EntryFloat : BaseEntry, Parcelable, Serializable { constructor() /** - * A Entry represents one single entry in the chart. + * An EntryFloat 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(x: Float, y: Float) : super(x = x, y = y) /** - * A Entry represents one single entry in the chart. + * An EntryFloat 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(x: Float, y: Float, data: Any?) : super(x = x, y = y, data = data) /** - * A Entry represents one single entry in the chart. + * An EntryFloat 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(x: Float, y: Float, icon: Drawable?) : super(x = x, y = y, icon = icon) /** - * A Entry represents one single entry in the chart. + * An EntryFloat 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. + * @param data Spot for additional data this EntryFloat represents. */ - constructor(x: Float, y: Float, icon: Drawable?, data: Any?) : super(y, icon, data) { - this._x = x - } + constructor(x: Float, y: Float, icon: Drawable?, data: Any?) : super(x = x, y = y, icon = icon, data = data) /** * returns an exact copy of the entry */ - open fun copy(): Entry { - val e = Entry(x, y, data) + open fun copy(): EntryFloat { + val e = EntryFloat( + x = x, + y = y, + data = data + ) return e } @@ -81,17 +70,17 @@ open class Entry : BaseEntry, Parcelable, Serializable { * 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: Entry?): Boolean { - if (e == null) + fun equalTo(entryFloat: EntryFloat?): Boolean { + if (entryFloat == null) return false - if (e.data !== this.data) + if (entryFloat.data !== this.data) return false - if (abs((e.x - this.x).toDouble()) > Utils.FLOAT_EPSILON) + if (abs((entryFloat.x - this.x).toDouble()) > Utils.FLOAT_EPSILON) return false - if (abs((e.y - this.y).toDouble()) > Utils.FLOAT_EPSILON) + if (abs((entryFloat.y - this.y).toDouble()) > Utils.FLOAT_EPSILON) return false return true @@ -104,7 +93,7 @@ open class Entry : BaseEntry, Parcelable, Serializable { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { "${this.javaClass.typeName.substringAfterLast(".")} x=$x y=$y" } else { - "Entry x=$x y=$y" + "EntryFloat x=$x y=$y" } } @@ -120,7 +109,7 @@ open class Entry : BaseEntry, Parcelable, Serializable { dest.writeInt(1) dest.writeParcelable(data as Parcelable?, flags) } else { - throw ParcelFormatException("Cannot parcel an Entry with non-parcelable data") + throw ParcelFormatException("Cannot parcel an EntryFloat with non-parcelable data") } } else { dest.writeInt(0) @@ -128,10 +117,10 @@ open class Entry : BaseEntry, Parcelable, Serializable { } protected constructor(`in`: Parcel) { - this._x = `in`.readFloat() + this.x = `in`.readFloat() this.yBase = `in`.readFloat() if (`in`.readInt() == 1) { - this.data = if (android.os.Build.VERSION.SDK_INT >= 33) { + this.data = if (Build.VERSION.SDK_INT >= 33) { `in`.readParcelable(Any::class.java.classLoader, Any::class.java) } else { @Suppress("DEPRECATION") @@ -142,12 +131,12 @@ open class Entry : BaseEntry, Parcelable, Serializable { companion object { @JvmField - val CREATOR: Parcelable.Creator = object : Parcelable.Creator { - override fun createFromParcel(source: Parcel): Entry { - return Entry(source) + val CREATOR: Parcelable.Creator = object : Parcelable.Creator { + override fun createFromParcel(source: Parcel): EntryFloat { + return EntryFloat(source) } - override fun newArray(size: Int): Array { + override fun newArray(size: Int): Array { return arrayOfNulls(size) } } 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 4736b20213..eaf30862d8 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> { constructor() : super() - constructor(vararg dataSets: ILineDataSet) : super(*dataSets) + constructor(vararg dataSets: ILineDataSet) : super(*dataSets) - constructor(dataSets: MutableList) : super(dataSets) + constructor(dataSets: MutableList>) : 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 be22ee8e57..635c017d52 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,7 @@ 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 { /** * Drawing mode for this line dataset */ @@ -73,17 +73,18 @@ open class LineDataSet(yVals: MutableList = mutableListOf(), label: Strin circleColors.add(Color.rgb(140, 234, 255)) } - override fun copy(): DataSet { - val entries: MutableList = mutableListOf() + @Suppress("UNCHECKED_CAST") + override fun copy(): DataSet? { + val entries: MutableList = mutableListOf() for (i in entriesInternal.indices) { - entries.add(entriesInternal[i].copy()) + entries.add((entriesInternal[i] as EntryFloat).copy()) } - val copied = LineDataSet(entries, label) + val copied = LineDataSet(entries, label) copy(copied) - return copied + return copied as DataSet } - protected fun copy(lineDataSet: LineDataSet) { + protected fun copy(lineDataSet: LineDataSet<*>) { super.copy((lineDataSet as BaseDataSet<*>?)!!) lineDataSet.circleColors = this.circleColors lineDataSet.mCircleHoleColor = 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 db3e593324..c1b270955d 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 { +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 1f9535dff2..5a2a9a8111 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/data/PieData.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/PieData.kt index 3404885483..cdf80df625 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/PieData.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/PieData.kt @@ -58,7 +58,7 @@ class PieData : ChartData { null } - override fun getEntryForHighlight(highlight: Highlight): Entry? { + override fun getEntryForHighlight(highlight: Highlight): EntryFloat? { return this.dataSet.getEntryForIndex(highlight.x.toInt()) } 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 fd1f5ca4e3..aa0161ee4f 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,8 +29,8 @@ open class PieDataSet(yVals: MutableList, label: String) : DataSet { - val entries: MutableList = mutableListOf() + override fun copy(): DataSet { + val entries: MutableList = mutableListOf() for (i in entriesInternal.indices) { entries.add(entriesInternal[i].copy()) } @@ -42,7 +42,7 @@ open class PieDataSet(yVals: MutableList, label: String) : DataSet?)!!) } - override fun calcMinMax(entry: PieEntry) { + override fun calcMinMax(entry: PieEntryFloat) { calcMinMaxY(entry) } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/PieEntry.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/PieEntryFloat.kt similarity index 92% rename from chartLib/src/main/kotlin/info/appdev/charting/data/PieEntry.kt rename to chartLib/src/main/kotlin/info/appdev/charting/data/PieEntryFloat.kt index 172e62dcfa..4ed9dc5121 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/PieEntry.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/PieEntryFloat.kt @@ -5,7 +5,7 @@ import android.graphics.drawable.Drawable import timber.log.Timber @SuppressLint("ParcelCreator") -class PieEntry : Entry { +class PieEntryFloat : EntryFloat { var label: String? = null constructor(value: Float) : super(0f, value) @@ -50,7 +50,7 @@ class PieEntry : Entry { Timber.i("Pie entries do not have x values") } - override fun copy(): PieEntry { - return PieEntry(y, label, data) + override fun copy(): PieEntryFloat { + return PieEntryFloat(y, label, data) } } 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 fc5e4d8bbb..74427ee3a7 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/RadarData.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/RadarData.kt @@ -14,7 +14,7 @@ class RadarData : ChartData { constructor(dataSets: MutableList) : super(dataSets) - override fun getEntryForHighlight(highlight: Highlight): Entry? { + override fun getEntryForHighlight(highlight: Highlight): EntryFloat? { return getDataSetByIndex(highlight.dataSetIndex)!!.getEntryForIndex(highlight.x.toInt()) } } 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 8a93eebe26..d4d3ce2612 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,8 +58,8 @@ open class RadarDataSet(yVals: MutableList, label: String = "") : Li mHighlightCircleStrokeWidth = value } - override fun copy(): DataSet { - val entries: MutableList = mutableListOf() + override fun copy(): DataSet { + val entries: MutableList = mutableListOf() for (i in entriesInternal.indices) { entries.add(entriesInternal[i].copy()) } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/RadarEntry.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/RadarEntryFloat.kt similarity index 80% rename from chartLib/src/main/kotlin/info/appdev/charting/data/RadarEntry.kt rename to chartLib/src/main/kotlin/info/appdev/charting/data/RadarEntryFloat.kt index 0b6e6a3065..5b37a6769b 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/RadarEntry.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/RadarEntryFloat.kt @@ -3,7 +3,7 @@ package info.appdev.charting.data import android.annotation.SuppressLint @SuppressLint("ParcelCreator") -class RadarEntry : Entry { +class RadarEntryFloat : EntryFloat { constructor(value: Float) : super(0f, value) constructor(value: Float, data: Any?) : super(0f, value, data) @@ -14,8 +14,8 @@ class RadarEntry : Entry { val value: Float get() = y - override fun copy(): RadarEntry { - return RadarEntry(y, data) + override fun copy(): RadarEntryFloat { + return RadarEntryFloat(y, data) } @get:Deprecated("") 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 d9c1ef47f8..aadb8848eb 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,8 +38,8 @@ open class ScatterDataSet(yVals: MutableList, label: String = "") : LineS @ColorInt private var mScatterShapeHoleColor = ColorTemplate.COLOR_NONE - override fun copy(): DataSet { - val entries: MutableList = mutableListOf() + override fun copy(): DataSet { + val entries: MutableList = mutableListOf() for (i in entriesInternal.indices) { entries.add(entriesInternal[i].copy()) } 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 3293e103c0..b015dbed96 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/formatter/ColorFormatter.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/formatter/ColorFormatter.kt @@ -1,6 +1,6 @@ package info.appdev.charting.formatter -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.interfaces.datasets.IDataSet /** @@ -11,8 +11,8 @@ interface ColorFormatter { * Returns the color to be used for the given Entry at the given index (in the entries array) * * @param index index in the entries array - * @param entry the entry to color + * @param entryFloat 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, entryFloat: EntryFloat?, 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 cedd7eed51..6b403b6942 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/formatter/DefaultFillFormatter.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/formatter/DefaultFillFormatter.kt @@ -8,7 +8,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<*>?, 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 b722ff0843..1164c220a9 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.EntryFloat 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, entryFloat: EntryFloat?, 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 cef5444c8e..a929003063 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/formatter/IFillFormatter.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/formatter/IFillFormatter.kt @@ -14,5 +14,5 @@ interface IFillFormatter { * @param dataSet the ILineDataSet that is currently drawn * @param dataProvider */ - fun getFillLinePosition(dataSet: ILineDataSet?, dataProvider: LineDataProvider): Float + fun getFillLinePosition(dataSet: ILineDataSet<*>?, 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 8e05dedc0d..8275036a1e 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.EntryFloat import info.appdev.charting.utils.ViewPortHandler /** @@ -16,10 +16,10 @@ interface IValueFormatter { * and memory allocations inside this method. * * @param value the value to be formatted - * @param entry the entry the value belongs to - in e.g. BarChart, this is of class BarEntry + * @param entryFloat the entry the value belongs to - in e.g. BarChart, this is of class BarEntry * @param dataSetIndex the index of the DataSet the entry in focus belongs to * @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, entryFloat: EntryFloat?, 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 12692b54ca..4bdc969007 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.EntryFloat 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, entryFloat: EntryFloat?, 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 271fab7bfa..e785c9833c 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.EntryFloat 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, entryFloat: EntryFloat?, 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 957957acd1..606bfeb0c7 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.BarEntryFloat +import info.appdev.charting.data.EntryFloat import info.appdev.charting.utils.ViewPortHandler import java.text.DecimalFormat @@ -29,9 +29,9 @@ 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 { - if (!drawWholeStack && entry is BarEntry) { - val barEntry = entry + override fun getFormattedValue(value: Float, entryFloat: EntryFloat?, dataSetIndex: Int, viewPortHandler: ViewPortHandler?): String { + if (!drawWholeStack && entryFloat is BarEntryFloat) { + val barEntry = entryFloat val vals = barEntry.yVals if (vals != null) { 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 fb54b536d2..ddd7606482 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,7 @@ 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.data.EntryFloat import info.appdev.charting.interfaces.dataprovider.base.BarLineScatterCandleBubbleDataProvider import info.appdev.charting.interfaces.datasets.IDataSet import info.appdev.charting.utils.PointD @@ -122,12 +122,12 @@ open class ChartHighlighter>(prote ): MutableList { val highlights = ArrayList() - var entries = set.getEntriesForXValue(xVal) + var entries = set.getEntriesForXValue(xVal)?.map { it as EntryFloat }?.toMutableList() 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: EntryFloat? = set.getEntryForXValue(xVal, Float.NaN, rounding) as? EntryFloat if (closest != null) { - entries = set.getEntriesForXValue(closest.x) + entries = set.getEntriesForXValue(closest.x)?.map { it as EntryFloat }?.toMutableList() } } 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 9ac9af9629..8e61df89df 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,7 @@ package info.appdev.charting.highlight import info.appdev.charting.data.DataSet -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.interfaces.dataprovider.BarDataProvider import info.appdev.charting.interfaces.datasets.IDataSet import info.appdev.charting.utils.PointD @@ -35,12 +35,12 @@ class HorizontalBarHighlighter(dataProvider: BarDataProvider) : BarHighlighter(d override fun buildHighlights(set: IDataSet<*>, dataSetIndex: Int, xVal: Float, rounding: DataSet.Rounding?): MutableList { val highlights = ArrayList() - var entries = set.getEntriesForXValue(xVal) + var entries = set.getEntriesForXValue(xVal)?.map { it as EntryFloat }?.toMutableList() 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) - closestEntry?.let { closestE -> - entries = set.getEntriesForXValue(closestE.x) + val closestEntryFloat: EntryFloat? = set.getEntryForXValue(xVal, Float.NaN, rounding) as? EntryFloat + closestEntryFloat?.let { closestE -> + entries = set.getEntriesForXValue(closestE.x)?.map { it as EntryFloat }?.toMutableList() } } 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 d846dcf66f..388229271a 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/highlight/PieHighlighter.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/highlight/PieHighlighter.kt @@ -1,16 +1,16 @@ package info.appdev.charting.highlight import info.appdev.charting.charts.PieChart -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat open class PieHighlighter(chart: PieChart) : PieRadarHighlighter(chart) { override fun getClosestHighlight(index: Int, x: Float, y: Float): Highlight? { val pieDataSet = chartPieRadar.data?.dataSets[0] - val entry: Entry? = pieDataSet?.getEntryForIndex(index) + val entryFloat: EntryFloat? = pieDataSet?.getEntryForIndex(index) - entry?.let { - return Highlight(index.toFloat(), entry.y, x, y, 0, pieDataSet.axisDependency) + entryFloat?.let { + return Highlight(index.toFloat(), entryFloat.y, x, y, 0, pieDataSet.axisDependency) } return null } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/highlight/RadarHighlighter.kt b/chartLib/src/main/kotlin/info/appdev/charting/highlight/RadarHighlighter.kt index 7e7450be5c..5002eb762b 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/highlight/RadarHighlighter.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/highlight/RadarHighlighter.kt @@ -1,7 +1,7 @@ package info.appdev.charting.highlight import info.appdev.charting.charts.RadarChart -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.utils.PointF import info.appdev.charting.utils.changePosition import kotlin.math.abs @@ -47,16 +47,16 @@ open class RadarHighlighter(chart: RadarChart) : PieRadarHighlighter for (i in 0.. ranges are (-10 to 0, 0 to 5, 5 to 25). + */ +class RangeDouble(var from: Double, var to: Double) { + fun contains(value: Double): Boolean = value > from && value <= to + fun isLarger(value: Double): Boolean = value > to + fun isSmaller(value: Double): Boolean = value < from +} + 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 a29dc8da7d..ba4b668299 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 @@ -1,9 +1,9 @@ package info.appdev.charting.interfaces.datasets -import info.appdev.charting.data.BarEntry +import info.appdev.charting.data.BarEntryFloat 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 c547744254..620d555cb9 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/IBubbleDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IBubbleDataSet.kt index 43f8efb491..faa14a164c 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 @@ -1,8 +1,8 @@ package info.appdev.charting.interfaces.datasets -import info.appdev.charting.data.BubbleEntry +import info.appdev.charting.data.BubbleEntryFloat -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 366c783441..ce86fccf2b 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 +import info.appdev.charting.data.CandleEntryFloat -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 c401c661fd..d0f0ceef28 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 @@ -5,11 +5,11 @@ import android.graphics.Typeface import info.appdev.charting.components.Legend import info.appdev.charting.components.YAxis import info.appdev.charting.data.DataSet -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry 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/ILineDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/ILineDataSet.kt index 3f2ccd2dc7..e1465aa8cd 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 { /** * 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 d0ccfe7d96..31ebc9986f 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 56cb229508..8e1f2868e2 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/interfaces/datasets/IPieDataSet.kt b/chartLib/src/main/kotlin/info/appdev/charting/interfaces/datasets/IPieDataSet.kt index 658602dc72..13df4852b5 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 @@ -1,9 +1,9 @@ package info.appdev.charting.interfaces.datasets import info.appdev.charting.data.PieDataSet.ValuePosition -import info.appdev.charting.data.PieEntry +import info.appdev.charting.data.PieEntryFloat -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 986849fcf0..6406f1c89b 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 @@ -1,8 +1,8 @@ package info.appdev.charting.interfaces.datasets -import info.appdev.charting.data.RadarEntry +import info.appdev.charting.data.RadarEntryFloat -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 9e44a32511..796808a2eb 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 @@ -1,9 +1,9 @@ package info.appdev.charting.interfaces.datasets -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat 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 786af91c67..faaaeca8de 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.EntryFloat 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>>, touchMatrix: Matrix, dragTriggerDistance: Float ) : - ChartTouchListener>>>(chart) { + ChartTouchListener>>>(chart) { /** * the original touch-matrix from the chart */ 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 188ed5ea10..5e54d6db32 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.EntryFloat import info.appdev.charting.highlight.Highlight /** @@ -11,11 +11,11 @@ interface OnChartValueSelectedListener { /** * Called when a value has been selected inside the chart. * - * @param entry The selected Entry + * @param entryFloat The selected Entry * @param highlight The corresponding highlight object that contains information * about the highlighted position such as dataSetIndex, ... */ - fun onValueSelected(entry: Entry, highlight: Highlight) + fun onValueSelected(entryFloat: EntryFloat, 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 6e755a23e1..45b9af8ac7 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/listener/OnDrawListener.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/listener/OnDrawListener.kt @@ -1,7 +1,7 @@ package info.appdev.charting.listener import info.appdev.charting.data.DataSet -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat /** * Listener for callbacks when drawing on the chart. @@ -11,14 +11,14 @@ interface OnDrawListener { * Called whenever an entry is added with the finger. Note this is also called for entries that are generated by the * library, when the touch gesture is too fast and skips points. * - * @param entry the last drawn entry + * @param entryFloat the last drawn entry */ - fun onEntryAdded(entry: Entry) + fun onEntryAdded(entryFloat: EntryFloat) /** * Called whenever an entry is moved by the user after being highlighted */ - fun onEntryMoved(entry: Entry) + fun onEntryMoved(entryFloat: EntryFloat) /** * Called when drawing finger is lifted and the draw is finished. 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 d54b178d90..8b256869fc 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/BarLineScatterCandleBubbleRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/BarLineScatterCandleBubbleRenderer.kt @@ -2,7 +2,7 @@ package info.appdev.charting.renderer import info.appdev.charting.animation.ChartAnimator import info.appdev.charting.data.DataSet -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BaseEntry 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 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 09b1c3acdf..ba5e970ad3 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.EntryFloat import info.appdev.charting.formatter.IValueFormatter import info.appdev.charting.highlight.Highlight import info.appdev.charting.interfaces.dataprovider.base.IBaseProvider @@ -98,14 +98,14 @@ abstract class DataRenderer( * @param canvas canvas * @param formatter formatter for custom value-formatting * @param value the value to be drawn - * @param entry the entry the value belongs to + * @param entryFloat the entry the value belongs to * @param dataSetIndex the index of the DataSet the drawn Entry belongs to * @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, entryFloat: EntryFloat?, dataSetIndex: Int, x: Float, y: Float, color: Int) { paintValues.color = color - canvas.drawText(formatter.getFormattedValue(value, entry, dataSetIndex, viewPortHandler)!!, x, y, paintValues) + canvas.drawText(formatter.getFormattedValue(value, entryFloat, 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 9745460e60..14a528102a 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,12 @@ 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.EntryFloat 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 +87,7 @@ open class LineChartRenderer( canvas.drawBitmap(drawBitmapLocal, 0f, 0f, null) } - protected fun drawDataSet(canvas: Canvas, dataSet: ILineDataSet) { + protected fun drawDataSet(canvas: Canvas, dataSet: ILineDataSet<*>) { if (dataSet.entryCount < 1) return @@ -102,7 +104,7 @@ open class LineChartRenderer( paintRender.pathEffect = null } - protected fun drawHorizontalBezier(dataSet: ILineDataSet) { + protected fun drawHorizontalBezier(dataSet: ILineDataSet<*>) { val phaseY = animator.phaseY val trans = dataProvider.getTransformer(dataSet.axisDependency) @@ -152,7 +154,7 @@ open class LineChartRenderer( paintRender.pathEffect = null } - protected fun drawCubicBezier(dataSet: ILineDataSet) { + protected fun drawCubicBezier(dataSet: ILineDataSet<*>) { val phaseY = animator.phaseY val trans = dataProvider.getTransformer(dataSet.axisDependency) @@ -175,7 +177,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 +229,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<*>, spline: Path, trans: Transformer, bounds: XBounds) { val fillMin = dataSet.fillFormatter!!.getFillLinePosition(dataSet, dataProvider) dataSet.getEntryForIndex(bounds.min + bounds.range)?.let { @@ -251,7 +253,7 @@ open class LineChartRenderer( /** * Draws a normal line. */ - protected fun drawLinear(c: Canvas, dataSet: ILineDataSet) { + protected fun drawLinear(c: Canvas, dataSet: ILineDataSet<*>) { val entryCount = dataSet.entryCount val pointsPerEntryPair = if (dataSet.isDrawSteppedEnabled) 4 else 2 @@ -286,24 +288,24 @@ 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 + lineBuffer[0] = entryFloat.x + lineBuffer[1] = entryFloat.y * phaseY if (j < xBounds.max) { - entry = dataSet.getEntryForIndex(j + 1)!! + entryFloat = dataSet.getEntryForIndex(j + 1)!! if (dataSet.isDrawSteppedEnabled) { - lineBuffer[2] = entry.x + lineBuffer[2] = entryFloat.x lineBuffer[3] = lineBuffer[1] lineBuffer[4] = lineBuffer[2] lineBuffer[5] = lineBuffer[3] - lineBuffer[6] = entry.x - lineBuffer[7] = entry.y * phaseY + lineBuffer[6] = entryFloat.x + lineBuffer[7] = entryFloat.y * phaseY } else { - lineBuffer[2] = entry.x - lineBuffer[3] = entry.y * phaseY + lineBuffer[2] = entryFloat.x + lineBuffer[3] = entryFloat.y * phaseY } } else { lineBuffer[2] = lineBuffer[0] @@ -346,8 +348,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 +395,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<*>, trans: Transformer, bounds: XBounds) { val filled = mGenerateFilledPathBuffer val startingIndex = bounds.min @@ -435,7 +437,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<*>, 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,25 +450,25 @@ open class LineChartRenderer( outputPath.lineTo(entry.x, entry.y * phaseY) // create a new path - var currentEntry: Entry? = null + var currentEntryFloat: BaseEntry? = null var previousEntry = entry for (x in startIndex + 1..endIndex) { - currentEntry = dataSet.getEntryForIndex(x) + currentEntryFloat = dataSet.getEntryForIndex(x) - if (currentEntry != null) { + if (currentEntryFloat != null) { if (isDrawSteppedEnabled) { - outputPath.lineTo(currentEntry.x, previousEntry.y * phaseY) + outputPath.lineTo(currentEntryFloat.x, previousEntry.y * phaseY) } - outputPath.lineTo(currentEntry.x, currentEntry.y * phaseY) + outputPath.lineTo(currentEntryFloat.x, currentEntryFloat.y * phaseY) - previousEntry = currentEntry + previousEntry = currentEntryFloat } } // close up - if (currentEntry != null) { - outputPath.lineTo(currentEntry.x, fillMin) + if (currentEntryFloat != null) { + outputPath.lineTo(currentEntryFloat.x, fillMin) } } outputPath.close() @@ -650,7 +652,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>)) continue val pix = dataProvider.getTransformer(set.axisDependency)!!.getPixelForValues( @@ -686,7 +689,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<*>): Boolean { val size = set.circleColorCount var changeRequired = false @@ -708,7 +711,7 @@ open class LineChartRenderer( * @param drawCircleHole * @param drawTransparentCircleHole */ - fun fill(set: ILineDataSet, drawCircleHole: Boolean, drawTransparentCircleHole: Boolean) { + fun fill(set: ILineDataSet<*>, 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/PieChartRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt index c64c608948..0f2ab06aa2 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt @@ -554,7 +554,7 @@ open class PieChartRenderer( canvas = this, formatter = formatter, value = value, - entry = entry, + entryFloat = entry, dataSetIndex = 0, x = x, y = y, 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 b0f56d1148..4ff581e719 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/utils/AssetManagerUtils.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/utils/AssetManagerUtils.kt @@ -1,8 +1,8 @@ package info.appdev.charting.utils import android.content.res.AssetManager -import info.appdev.charting.data.BarEntry -import info.appdev.charting.data.Entry +import info.appdev.charting.data.BarEntryFloat +import info.appdev.charting.data.EntryFloat import timber.log.Timber import java.io.BufferedReader import java.io.IOException @@ -18,8 +18,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( @@ -31,7 +31,7 @@ fun AssetManager.loadEntriesFromAssets(path: String): MutableList { val split: Array = line.split("#".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() if (split.size <= 2) { - entries.add(Entry(split[1]!!.toFloat(), split[0]!!.toFloat())) + entries.add(EntryFloat(split[1]!!.toFloat(), split[0]!!.toFloat())) } else { val vals = FloatArray(split.size - 1) @@ -39,7 +39,7 @@ fun AssetManager.loadEntriesFromAssets(path: String): MutableList { vals[i] = split[i]!!.toFloat() } - entries.add(BarEntry(split[split.size - 1]!!.toInt().toFloat(), vals)) + entries.add(BarEntryFloat(split[split.size - 1]!!.toInt().toFloat(), vals)) } line = reader.readLine() } @@ -51,15 +51,15 @@ fun AssetManager.loadEntriesFromAssets(path: String): MutableList { return entries } -fun AssetManager.loadBarEntriesFromAssets(path: String): MutableList { - val entries: MutableList = ArrayList() +fun AssetManager.loadBarEntriesFromAssets(path: String): MutableList { + val entries: MutableList = ArrayList() try { BufferedReader(InputStreamReader(this.open(path), StandardCharsets.UTF_8)).use { reader -> var line = reader.readLine() while (line != null) { val split: Array = line.split("#".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() - entries.add(BarEntry(split[1]!!.toFloat(), split[0]!!.toFloat())) + entries.add(BarEntryFloat(split[1]!!.toFloat(), split[0]!!.toFloat())) line = reader.readLine() } } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/utils/EntryXComparator.kt b/chartLib/src/main/kotlin/info/appdev/charting/utils/EntryXComparator.kt index d380b4debb..3aaafeb5f2 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/utils/EntryXComparator.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/utils/EntryXComparator.kt @@ -1,13 +1,13 @@ package info.appdev.charting.utils -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat /** * Comparator for comparing Entry-objects by their x-value. */ -class EntryXComparator : Comparator { - override fun compare(entry1: Entry, entry2: Entry): Int { - val diff = entry1.x - entry2.x +class EntryXComparator : Comparator { + override fun compare(entryFloat1: EntryFloat, entryFloat2: EntryFloat): Int { + val diff = entryFloat1.x - entryFloat2.x return diff.compareTo(0f) } 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 e43e585822..e26be48d73 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/utils/Transformer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/utils/Transformer.kt @@ -3,7 +3,7 @@ package info.appdev.charting.utils import android.graphics.Matrix import android.graphics.Path import android.graphics.RectF -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.interfaces.datasets.IBubbleDataSet import info.appdev.charting.interfaces.datasets.ICandleDataSet import info.appdev.charting.interfaces.datasets.ILineDataSet @@ -118,7 +118,7 @@ open class Transformer(protected var viewPortHandler: ViewPortHandler) { var j = 0 while (j < count) { - val e: Entry? = data.getEntryForIndex(j / 2 + from) + val e: EntryFloat? = data.getEntryForIndex(j / 2 + from) if (e != null) { valuePoints[j] = e.x @@ -142,7 +142,7 @@ open class Transformer(protected var viewPortHandler: ViewPortHandler) { * y values transformed with all matrices for the LINECHART. */ fun generateTransformedValuesLine( - data: ILineDataSet, + data: ILineDataSet<*>, phaseX: Float, phaseY: Float, min: Int, max: Int ): FloatArray { diff --git a/chartLib/src/main/kotlin/info/appdev/charting/utils/Utils.kt b/chartLib/src/main/kotlin/info/appdev/charting/utils/Utils.kt index b9a2b0e008..f5cfd86142 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/utils/Utils.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/utils/Utils.kt @@ -7,6 +7,7 @@ import android.view.VelocityTracker import android.view.ViewConfiguration import info.appdev.charting.formatter.DefaultValueFormatter import info.appdev.charting.formatter.IValueFormatter +import java.lang.Float.intBitsToFloat import kotlin.math.abs import kotlin.math.cos import kotlin.math.sin @@ -23,6 +24,7 @@ object Utils { const val FDEG2RAD: Float = (Math.PI.toFloat() / 180f) val FLOAT_EPSILON: Float = java.lang.Float.intBitsToFloat(1) + val DOUBLE_EPSILON: Double = java.lang.Double.longBitsToDouble(1L) /** * initialize method, called inside the Chart.init() method. diff --git a/chartLib/src/test/kotlin/info/appdev/charting/test/BarDataTest.kt b/chartLib/src/test/kotlin/info/appdev/charting/test/BarDataTest.kt index 0869e638d6..51deb135a5 100644 --- a/chartLib/src/test/kotlin/info/appdev/charting/test/BarDataTest.kt +++ b/chartLib/src/test/kotlin/info/appdev/charting/test/BarDataTest.kt @@ -2,7 +2,7 @@ package info.appdev.charting.test import info.appdev.charting.data.BarData import info.appdev.charting.data.BarDataSet -import info.appdev.charting.data.BarEntry +import info.appdev.charting.data.BarEntryFloat import org.junit.Assert import org.junit.Test @@ -12,12 +12,12 @@ class BarDataTest { val groupSpace = 5f val barSpace = 1f - val values1: MutableList = ArrayList() - val values2: MutableList = ArrayList() + val values1: MutableList = ArrayList() + val values2: MutableList = ArrayList() for (i in 0..4) { - values1.add(BarEntry(i.toFloat(), 50f)) - values2.add(BarEntry(i.toFloat(), 60f)) + values1.add(BarEntryFloat(i.toFloat(), 50f)) + values2.add(BarEntryFloat(i.toFloat(), 60f)) } val barDataSet1 = BarDataSet(values1, "Set1") diff --git a/chartLib/src/test/kotlin/info/appdev/charting/test/ChartDataTest.kt b/chartLib/src/test/kotlin/info/appdev/charting/test/ChartDataTest.kt index 468aaf40b2..2f4b84cada 100644 --- a/chartLib/src/test/kotlin/info/appdev/charting/test/ChartDataTest.kt +++ b/chartLib/src/test/kotlin/info/appdev/charting/test/ChartDataTest.kt @@ -1,7 +1,7 @@ package info.appdev.charting.test import info.appdev.charting.components.YAxis -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet import info.appdev.charting.data.ScatterData @@ -12,17 +12,17 @@ import org.junit.Test class ChartDataTest { @Test fun testDynamicChartData() { - val entries1: MutableList = ArrayList() - entries1.add(Entry(10f, 10f)) - entries1.add(Entry(15f, -2f)) - entries1.add(Entry(21f, 50f)) + val entries1: MutableList = ArrayList() + entries1.add(EntryFloat(10f, 10f)) + entries1.add(EntryFloat(15f, -2f)) + entries1.add(EntryFloat(21f, 50f)) val set1 = ScatterDataSet(entries1, "") - val entries2: MutableList = ArrayList() - entries2.add(Entry(-1f, 10f)) - entries2.add(Entry(10f, 2f)) - entries2.add(Entry(20f, 5f)) + val entries2: MutableList = ArrayList() + entries2.add(EntryFloat(-1f, 10f)) + entries2.add(EntryFloat(10f, 2f)) + entries2.add(EntryFloat(20f, 5f)) val set2 = ScatterDataSet(entries2, "") @@ -42,7 +42,7 @@ class ChartDataTest { Assert.assertEquals(3, data.maxEntryCountSet?.entryCount) // now add and remove values - data.addEntry(Entry(-10f, -10f), 0) + data.addEntry(EntryFloat(-10f, -10f), 0) Assert.assertEquals(set1, data.maxEntryCountSet) Assert.assertEquals(4, data.maxEntryCountSet?.entryCount) @@ -56,8 +56,8 @@ class ChartDataTest { Assert.assertEquals(-10f, data.yMin, 0.01f) Assert.assertEquals(50f, data.yMax, 0.01f) - data.addEntry(Entry(-100f, 100f), 0) - data.addEntry(Entry(0f, -100f), 0) + data.addEntry(EntryFloat(-100f, 100f), 0) + data.addEntry(EntryFloat(0f, -100f), 0) Assert.assertEquals(-100f, data.getYMin(YAxis.AxisDependency.LEFT), 0.01f) Assert.assertEquals(100f, data.getYMax(YAxis.AxisDependency.LEFT), 0.01f) @@ -66,9 +66,9 @@ class ChartDataTest { Assert.assertEquals(-100f, data.getYMin(YAxis.AxisDependency.RIGHT), 0.01f) Assert.assertEquals(100f, data.getYMax(YAxis.AxisDependency.RIGHT), 0.01f) - val entries3: MutableList = ArrayList() - entries3.add(Entry(0f, 200f)) - entries3.add(Entry(0f, -50f)) + val entries3: MutableList = ArrayList() + entries3.add(EntryFloat(0f, 200f)) + entries3.add(EntryFloat(0f, -50f)) val set3 = ScatterDataSet(entries3, "") set3.axisDependency = YAxis.AxisDependency.RIGHT @@ -96,9 +96,9 @@ class ChartDataTest { Assert.assertEquals(0, lineData.dataSetCount) - val lineEntries1: MutableList = ArrayList() - lineEntries1.add(Entry(10f, 90f)) - lineEntries1.add(Entry(1000f, 1000f)) + val lineEntries1: MutableList = ArrayList() + lineEntries1.add(EntryFloat(10f, 90f)) + lineEntries1.add(EntryFloat(1000f, 1000f)) val lineSet1 = LineDataSet(lineEntries1, "") @@ -120,11 +120,11 @@ class ChartDataTest { Assert.assertEquals(90f, lineData.getYMin(YAxis.AxisDependency.RIGHT), 0.01f) Assert.assertEquals(1000f, lineData.getYMax(YAxis.AxisDependency.RIGHT), 0.01f) - val lineEntries2: MutableList = ArrayList() - lineEntries2.add(Entry(-1000f, 2000f)) - lineEntries2.add(Entry(2000f, -3000f)) + val lineEntries2: MutableList = ArrayList() + lineEntries2.add(EntryFloat(-1000f, 2000f)) + lineEntries2.add(EntryFloat(2000f, -3000f)) - val e = Entry(-1000f, 2500f) + val e = EntryFloat(-1000f, 2500f) lineEntries2.add(e) val lineSet2 = LineDataSet(lineEntries2, "") diff --git a/chartLib/src/test/kotlin/info/appdev/charting/test/DataSetTest.kt b/chartLib/src/test/kotlin/info/appdev/charting/test/DataSetTest.kt index 62b0b0efb9..482c1b9532 100644 --- a/chartLib/src/test/kotlin/info/appdev/charting/test/DataSetTest.kt +++ b/chartLib/src/test/kotlin/info/appdev/charting/test/DataSetTest.kt @@ -1,7 +1,7 @@ package info.appdev.charting.test import info.appdev.charting.data.DataSet -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.data.ScatterDataSet import org.junit.Assert import org.junit.Test @@ -9,10 +9,10 @@ import org.junit.Test class DataSetTest { @Test fun testCalcMinMax() { - val entries: MutableList = mutableListOf() - entries.add(Entry(10f, 10f)) - entries.add(Entry(15f, 2f)) - entries.add(Entry(21f, 5f)) + val entries: MutableList = mutableListOf() + entries.add(EntryFloat(10f, 10f)) + entries.add(EntryFloat(15f, 2f)) + entries.add(EntryFloat(21f, 5f)) val set = ScatterDataSet(entries, "") @@ -24,7 +24,7 @@ class DataSetTest { Assert.assertEquals(3, set.entryCount) - set.addEntry(Entry(25f, 1f)) + set.addEntry(EntryFloat(25f, 1f)) Assert.assertEquals(10f, set.xMin, 0.01f) Assert.assertEquals(25f, set.xMax, 0.01f) @@ -45,16 +45,16 @@ class DataSetTest { @Test fun testAddRemoveEntry() { - val entries: MutableList = mutableListOf() - entries.add(Entry(10f, 10f)) - entries.add(Entry(15f, 2f)) - entries.add(Entry(21f, 5f)) + val entries: MutableList = mutableListOf() + entries.add(EntryFloat(10f, 10f)) + entries.add(EntryFloat(15f, 2f)) + entries.add(EntryFloat(21f, 5f)) val set = ScatterDataSet(entries, "") Assert.assertEquals(3, set.entryCount) - set.addEntryOrdered(Entry(5f, 1f)) + set.addEntryOrdered(EntryFloat(5f, 1f)) Assert.assertEquals(4, set.entryCount) @@ -67,7 +67,7 @@ class DataSetTest { Assert.assertEquals(5f, set.getEntryForIndex(0)!!.x, 0.01f) Assert.assertEquals(1f, set.getEntryForIndex(0)!!.y, 0.01f) - set.addEntryOrdered(Entry(20f, 50f)) + set.addEntryOrdered(EntryFloat(20f, 50f)) Assert.assertEquals(5, set.entryCount) @@ -91,7 +91,7 @@ class DataSetTest { Assert.assertEquals(10f, set.getEntryForIndex(0)!!.x, 0.01f) Assert.assertEquals(10f, set.getEntryForIndex(0)!!.y, 0.01f) - set.addEntryOrdered(Entry(15f, 3f)) + set.addEntryOrdered(EntryFloat(15f, 3f)) Assert.assertEquals(4, set.entryCount) @@ -129,10 +129,10 @@ class DataSetTest { @Test fun testGetEntryForXValue() { - val entries: MutableList = mutableListOf() - entries.add(Entry(10f, 10f)) - entries.add(Entry(15f, 5f)) - entries.add(Entry(21f, 5f)) + val entries: MutableList = mutableListOf() + entries.add(EntryFloat(10f, 10f)) + entries.add(EntryFloat(15f, 5f)) + entries.add(EntryFloat(21f, 5f)) val set = ScatterDataSet(entries, "") @@ -169,19 +169,19 @@ class DataSetTest { fun testGetEntryForXValueWithDuplicates() { // sorted list of values (by x position) - val values: MutableList = ArrayList() - values.add(Entry(0f, 10f)) - values.add(Entry(1f, 20f)) - values.add(Entry(2f, 30f)) - values.add(Entry(3f, 40f)) - values.add(Entry(3f, 50f)) // duplicate - values.add(Entry(4f, 60f)) - values.add(Entry(4f, 70f)) // duplicate - values.add(Entry(5f, 80f)) - values.add(Entry(6f, 90f)) - values.add(Entry(7f, 100f)) - values.add(Entry(8f, 110f)) - values.add(Entry(8f, 120f)) // duplicate + val values: MutableList = ArrayList() + values.add(EntryFloat(0f, 10f)) + values.add(EntryFloat(1f, 20f)) + values.add(EntryFloat(2f, 30f)) + values.add(EntryFloat(3f, 40f)) + values.add(EntryFloat(3f, 50f)) // duplicate + values.add(EntryFloat(4f, 60f)) + values.add(EntryFloat(4f, 70f)) // duplicate + values.add(EntryFloat(5f, 80f)) + values.add(EntryFloat(6f, 90f)) + values.add(EntryFloat(7f, 100f)) + values.add(EntryFloat(8f, 110f)) + values.add(EntryFloat(8f, 120f)) // duplicate val set = ScatterDataSet(values, "") diff --git a/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/BarChartComposable.kt b/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/BarChartComposable.kt index 66541d4e85..a63a0f5643 100644 --- a/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/BarChartComposable.kt +++ b/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/BarChartComposable.kt @@ -14,7 +14,7 @@ import info.appdev.charting.components.Legend import info.appdev.charting.components.XAxis import info.appdev.charting.components.YAxis import info.appdev.charting.data.BarData -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.highlight.Highlight import info.appdev.charting.listener.OnChartValueSelectedListener @@ -53,7 +53,7 @@ fun BarChart( data: BarData?, modifier: Modifier = Modifier, state: BarChartState = rememberBarChartState(), - onValueSelected: ((Entry?, Highlight?) -> Unit)? = null, + onValueSelected: ((EntryFloat?, Highlight?) -> Unit)? = null, description: String? = null, legend: ((Legend) -> Unit)? = null, xAxisConfig: ((XAxis) -> Unit)? = null, @@ -140,8 +140,8 @@ fun BarChart( // Selection listener if (onValueSelected != null) { barChart.setOnChartValueSelectedListener(object : OnChartValueSelectedListener { - override fun onValueSelected(entry: Entry, highlight: Highlight) { - onValueSelected(entry, highlight) + override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) { + onValueSelected(entryFloat, highlight) } override fun onNothingSelected() { diff --git a/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/BubbleChartComposable.kt b/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/BubbleChartComposable.kt index 42134afa16..f2175a2810 100644 --- a/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/BubbleChartComposable.kt +++ b/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/BubbleChartComposable.kt @@ -14,7 +14,7 @@ import info.appdev.charting.components.Legend import info.appdev.charting.components.XAxis import info.appdev.charting.components.YAxis import info.appdev.charting.data.BubbleData -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.highlight.Highlight import info.appdev.charting.listener.OnChartValueSelectedListener @@ -26,7 +26,7 @@ fun BubbleChart( data: BubbleData?, modifier: Modifier = Modifier, state: BubbleChartState = rememberBubbleChartState(), - onValueSelected: ((Entry?, Highlight?) -> Unit)? = null, + onValueSelected: ((EntryFloat?, Highlight?) -> Unit)? = null, description: String? = null, legend: ((Legend) -> Unit)? = null, xAxisConfig: ((XAxis) -> Unit)? = null, @@ -92,7 +92,7 @@ fun BubbleChart( if (onValueSelected != null) { bubbleChart.setOnChartValueSelectedListener(object : OnChartValueSelectedListener { - override fun onValueSelected(entry: Entry, highlight: Highlight) = onValueSelected(entry, highlight) + override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) = onValueSelected(entryFloat, highlight) override fun onNothingSelected() = onValueSelected(null, null) }) } diff --git a/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/CandleStickChartComposable.kt b/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/CandleStickChartComposable.kt index 892d2fbf6b..de893eaf8b 100644 --- a/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/CandleStickChartComposable.kt +++ b/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/CandleStickChartComposable.kt @@ -14,7 +14,7 @@ import info.appdev.charting.components.Legend import info.appdev.charting.components.XAxis import info.appdev.charting.components.YAxis import info.appdev.charting.data.CandleData -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.highlight.Highlight import info.appdev.charting.listener.OnChartValueSelectedListener @@ -26,7 +26,7 @@ fun CandleStickChart( data: CandleData?, modifier: Modifier = Modifier, state: CandleStickChartState = rememberCandleStickChartState(), - onValueSelected: ((Entry?, Highlight?) -> Unit)? = null, + onValueSelected: ((EntryFloat?, Highlight?) -> Unit)? = null, description: String? = null, legend: ((Legend) -> Unit)? = null, xAxisConfig: ((XAxis) -> Unit)? = null, @@ -92,7 +92,7 @@ fun CandleStickChart( if (onValueSelected != null) { candleChart.setOnChartValueSelectedListener(object : OnChartValueSelectedListener { - override fun onValueSelected(entry: Entry, highlight: Highlight) = onValueSelected(entry, highlight) + override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) = onValueSelected(entryFloat, highlight) override fun onNothingSelected() = onValueSelected(null, null) }) } diff --git a/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/CombinedChartComposable.kt b/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/CombinedChartComposable.kt index 3c196f4718..e5a9d7fe4d 100644 --- a/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/CombinedChartComposable.kt +++ b/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/CombinedChartComposable.kt @@ -14,7 +14,7 @@ import info.appdev.charting.components.Legend import info.appdev.charting.components.XAxis import info.appdev.charting.components.YAxis import info.appdev.charting.data.CombinedData -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.highlight.Highlight import info.appdev.charting.listener.OnChartValueSelectedListener @@ -26,7 +26,7 @@ fun CombinedChart( data: CombinedData?, modifier: Modifier = Modifier, state: CombinedChartState = rememberCombinedChartState(), - onValueSelected: ((Entry?, Highlight?) -> Unit)? = null, + onValueSelected: ((EntryFloat?, Highlight?) -> Unit)? = null, description: String? = null, legend: ((Legend) -> Unit)? = null, xAxisConfig: ((XAxis) -> Unit)? = null, @@ -108,7 +108,7 @@ fun CombinedChart( if (onValueSelected != null) { combinedChart.setOnChartValueSelectedListener(object : OnChartValueSelectedListener { - override fun onValueSelected(entry: Entry, highlight: Highlight) = onValueSelected(entry, highlight) + override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) = onValueSelected(entryFloat, highlight) override fun onNothingSelected() = onValueSelected(null, null) }) } diff --git a/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/HorizontalBarChartComposable.kt b/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/HorizontalBarChartComposable.kt index d76bae0ff4..6a0a433203 100644 --- a/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/HorizontalBarChartComposable.kt +++ b/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/HorizontalBarChartComposable.kt @@ -14,7 +14,7 @@ import info.appdev.charting.components.Legend import info.appdev.charting.components.XAxis import info.appdev.charting.components.YAxis import info.appdev.charting.data.BarData -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.highlight.Highlight import info.appdev.charting.listener.OnChartValueSelectedListener @@ -26,7 +26,7 @@ fun HorizontalBarChart( data: BarData?, modifier: Modifier = Modifier, state: HorizontalBarChartState = rememberHorizontalBarChartState(), - onValueSelected: ((Entry?, Highlight?) -> Unit)? = null, + onValueSelected: ((EntryFloat?, Highlight?) -> Unit)? = null, description: String? = null, legend: ((Legend) -> Unit)? = null, xAxisConfig: ((XAxis) -> Unit)? = null, @@ -88,7 +88,7 @@ fun HorizontalBarChart( if (onValueSelected != null) { horizontalBarChart.setOnChartValueSelectedListener(object : OnChartValueSelectedListener { - override fun onValueSelected(entry: Entry, highlight: Highlight) = onValueSelected(entry, highlight) + override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) = onValueSelected(entryFloat, highlight) override fun onNothingSelected() = onValueSelected(null, null) }) } diff --git a/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/LineChartComposable.kt b/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/LineChartComposable.kt index 97c511ac92..fd7de38fdf 100644 --- a/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/LineChartComposable.kt +++ b/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/LineChartComposable.kt @@ -13,7 +13,7 @@ import info.appdev.charting.charts.LineChart import info.appdev.charting.components.Legend import info.appdev.charting.components.XAxis import info.appdev.charting.components.YAxis -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.data.LineData import info.appdev.charting.highlight.Highlight import info.appdev.charting.listener.OnChartValueSelectedListener @@ -54,7 +54,7 @@ fun LineChart( data: LineData?, modifier: Modifier = Modifier, state: LineChartState = rememberLineChartState(), - onValueSelected: ((Entry?, Highlight?) -> Unit)? = null, + onValueSelected: ((EntryFloat?, Highlight?) -> Unit)? = null, description: String? = null, legend: ((Legend) -> Unit)? = null, xAxisConfig: ((XAxis) -> Unit)? = null, @@ -145,8 +145,8 @@ fun LineChart( // Selection listener if (onValueSelected != null) { lineChart.setOnChartValueSelectedListener(object : OnChartValueSelectedListener { - override fun onValueSelected(entry: Entry, highlight: Highlight) { - onValueSelected(entry, highlight) + override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) { + onValueSelected(entryFloat, highlight) } override fun onNothingSelected() { diff --git a/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/PieChartComposable.kt b/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/PieChartComposable.kt index 987c4f27f9..bd89574331 100644 --- a/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/PieChartComposable.kt +++ b/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/PieChartComposable.kt @@ -11,7 +11,7 @@ import androidx.compose.ui.viewinterop.AndroidView import info.appdev.charting.animation.Easing import info.appdev.charting.charts.PieChart import info.appdev.charting.components.Legend -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.data.PieData import info.appdev.charting.highlight.Highlight import info.appdev.charting.listener.OnChartValueSelectedListener @@ -47,7 +47,7 @@ fun PieChart( data: PieData?, modifier: Modifier = Modifier, state: PieChartState = rememberPieChartState(), - onValueSelected: ((Entry?, Highlight?) -> Unit)? = null, + onValueSelected: ((EntryFloat?, Highlight?) -> Unit)? = null, description: String? = null, legend: ((Legend) -> Unit)? = null, backgroundColor: androidx.compose.ui.graphics.Color = androidx.compose.ui.graphics.Color.White, @@ -124,8 +124,8 @@ fun PieChart( // Selection listener if (onValueSelected != null) { pieChart.setOnChartValueSelectedListener(object : OnChartValueSelectedListener { - override fun onValueSelected(entry: Entry, highlight: Highlight) { - onValueSelected(entry, highlight) + override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) { + onValueSelected(entryFloat, highlight) } override fun onNothingSelected() { diff --git a/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/RadarChartComposable.kt b/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/RadarChartComposable.kt index 42b23c9635..c433742684 100644 --- a/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/RadarChartComposable.kt +++ b/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/RadarChartComposable.kt @@ -13,7 +13,7 @@ import info.appdev.charting.charts.RadarChart import info.appdev.charting.components.Legend import info.appdev.charting.components.XAxis import info.appdev.charting.components.YAxis -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.data.RadarData import info.appdev.charting.highlight.Highlight import info.appdev.charting.listener.OnChartValueSelectedListener @@ -26,7 +26,7 @@ fun RadarChart( data: RadarData?, modifier: Modifier = Modifier, state: RadarChartState = rememberRadarChartState(), - onValueSelected: ((Entry?, Highlight?) -> Unit)? = null, + onValueSelected: ((EntryFloat?, Highlight?) -> Unit)? = null, description: String? = null, legend: ((Legend) -> Unit)? = null, xAxisConfig: ((XAxis) -> Unit)? = null, @@ -82,7 +82,7 @@ fun RadarChart( if (onValueSelected != null) { radarChart.setOnChartValueSelectedListener(object : OnChartValueSelectedListener { - override fun onValueSelected(entry: Entry, highlight: Highlight) = onValueSelected(entry, highlight) + override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) = onValueSelected(entryFloat, highlight) override fun onNothingSelected() = onValueSelected(null, null) }) } diff --git a/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/ScatterChartComposable.kt b/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/ScatterChartComposable.kt index 0ec1bef766..7e84575c60 100644 --- a/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/ScatterChartComposable.kt +++ b/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/ScatterChartComposable.kt @@ -13,7 +13,7 @@ import info.appdev.charting.charts.ScatterChart import info.appdev.charting.components.Legend import info.appdev.charting.components.XAxis import info.appdev.charting.components.YAxis -import info.appdev.charting.data.Entry +import info.appdev.charting.data.EntryFloat import info.appdev.charting.data.ScatterData import info.appdev.charting.highlight.Highlight import info.appdev.charting.listener.OnChartValueSelectedListener @@ -26,7 +26,7 @@ fun ScatterChart( data: ScatterData?, modifier: Modifier = Modifier, state: ScatterChartState = rememberScatterChartState(), - onValueSelected: ((Entry?, Highlight?) -> Unit)? = null, + onValueSelected: ((EntryFloat?, Highlight?) -> Unit)? = null, description: String? = null, legend: ((Legend) -> Unit)? = null, xAxisConfig: ((XAxis) -> Unit)? = null, @@ -92,7 +92,7 @@ fun ScatterChart( if (onValueSelected != null) { scatterChart.setOnChartValueSelectedListener(object : OnChartValueSelectedListener { - override fun onValueSelected(entry: Entry, highlight: Highlight) = onValueSelected(entry, highlight) + override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) = onValueSelected(entryFloat, highlight) override fun onNothingSelected() = onValueSelected(null, null) }) } diff --git a/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/examples/ChartExamples.kt b/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/examples/ChartExamples.kt index df3e438487..7ffb5fbca0 100644 --- a/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/examples/ChartExamples.kt +++ b/chartLibCompose/src/main/kotlin/info/appdev/charting/compose/examples/ChartExamples.kt @@ -33,16 +33,16 @@ import info.appdev.charting.compose.ScatterChart import info.appdev.charting.compose.rememberLineChartState 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.BarEntryFloat +import info.appdev.charting.data.EntryFloat import info.appdev.charting.data.LineData import info.appdev.charting.data.LineDataSet import info.appdev.charting.data.PieData import info.appdev.charting.data.PieDataSet -import info.appdev.charting.data.PieEntry +import info.appdev.charting.data.PieEntryFloat import info.appdev.charting.data.RadarData import info.appdev.charting.data.RadarDataSet -import info.appdev.charting.data.RadarEntry +import info.appdev.charting.data.RadarEntryFloat import info.appdev.charting.data.ScatterData import info.appdev.charting.data.ScatterDataSet @@ -77,7 +77,7 @@ fun LineChartExample() { Spacer(modifier = Modifier.height(8.dp)) val entries = remember { - (0..10).map { Entry(it.toFloat(), (10..50).random().toFloat()) } + (0..10).map { EntryFloat(it.toFloat(), (10..50).random().toFloat()) } } val dataSet = remember(entries) { @@ -144,7 +144,7 @@ fun BarChartExample() { Spacer(modifier = Modifier.height(8.dp)) val entries = remember { - (0..5).map { BarEntry(it.toFloat(), (20..80).random().toFloat()) } + (0..5).map { BarEntryFloat(it.toFloat(), (20..80).random().toFloat()) } } val dataSet = remember(entries) { @@ -188,11 +188,11 @@ fun PieChartExample() { val entries = remember { listOf( - PieEntry(30f, "Product A"), - PieEntry(25f, "Product B"), - PieEntry(20f, "Product C"), - PieEntry(15f, "Product D"), - PieEntry(10f, "Product E") + PieEntryFloat(30f, "Product A"), + PieEntryFloat(25f, "Product B"), + PieEntryFloat(20f, "Product C"), + PieEntryFloat(15f, "Product D"), + PieEntryFloat(10f, "Product E") ) } @@ -247,7 +247,7 @@ fun ScatterChartExample() { val entries = remember { (0..20).map { - Entry(it.toFloat(), (10..50).random().toFloat()) + EntryFloat(it.toFloat(), (10..50).random().toFloat()) } } @@ -286,11 +286,11 @@ fun RadarChartExample() { val entries = remember { listOf( - RadarEntry(8f, "Speed"), - RadarEntry(7f, "Strength"), - RadarEntry(6f, "Defense"), - RadarEntry(9f, "Agility"), - RadarEntry(7f, "Intelligence") + RadarEntryFloat(8f, "Speed"), + RadarEntryFloat(7f, "Strength"), + RadarEntryFloat(6f, "Defense"), + RadarEntryFloat(9f, "Agility"), + RadarEntryFloat(7f, "Intelligence") ) } @@ -367,7 +367,7 @@ fun DynamicChartExample() { Button( onClick = { val entries = (0 until dataPoints).map { - Entry(it.toFloat(), (10..50).random().toFloat()) + EntryFloat(it.toFloat(), (10..50).random().toFloat()) } val dataSet = LineDataSet(entries.toMutableList(), "Random Data") state.data = LineData(dataSet) diff --git a/screenshotsToCompare9/StartTest_smokeTestStart-45-TimeLineActivity-Timeline-1SampleClick.png b/screenshotsToCompare9/StartTest_smokeTestStart-45-TimeLineActivity-Timeline-1SampleClick.png index b291c3f2fa..95aa7ac05e 100644 Binary files a/screenshotsToCompare9/StartTest_smokeTestStart-45-TimeLineActivity-Timeline-1SampleClick.png and b/screenshotsToCompare9/StartTest_smokeTestStart-45-TimeLineActivity-Timeline-1SampleClick.png differ