Skip to content

Commit a7d8ee4

Browse files
committed
Next
1 parent 3394538 commit a7d8ee4

26 files changed

+106
-87
lines changed

app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ import info.appdev.charting.components.AxisBase
1818
import info.appdev.charting.components.XAxis
1919
import info.appdev.charting.components.YAxis
2020
import info.appdev.charting.components.YAxis.AxisDependency
21-
import info.appdev.charting.data.Entry
2221
import info.appdev.charting.data.EntryDouble
23-
import info.appdev.charting.data.LineData
2422
import info.appdev.charting.data.LineDataDouble
2523
import info.appdev.charting.data.LineDataSet
2624
import info.appdev.charting.formatter.IAxisValueFormatter
25+
import info.appdev.charting.interfaces.datasets.ILineDataSet
2726
import info.appdev.charting.utils.ColorTemplate.holoBlue
2827
import java.text.SimpleDateFormat
2928
import java.util.Date
@@ -161,7 +160,7 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener {
161160
}
162161

163162
R.id.actionToggleValues -> {
164-
binding.chart1.lineData.dataSets.forEach {
163+
binding.chart1.data?.dataSets?.forEach {
165164
it.isDrawValues = !it.isDrawValues
166165
}
167166
binding.chart1.invalidate()
@@ -176,34 +175,40 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener {
176175

177176
R.id.actionToggleFilled -> {
178177
binding.chart1.data?.dataSets?.forEach { set ->
179-
set.isDrawFilled = !set.isDrawFilled
178+
@Suppress("UNCHECKED_CAST")
179+
(set as ILineDataSet<*, *>).isDrawFilled = !set.isDrawFilled
180180
}
181181
binding.chart1.invalidate()
182182
}
183183

184184
R.id.actionToggleCircles -> {
185185
binding.chart1.data?.dataSets?.forEach { set ->
186-
set.isDrawCircles = !set.isDrawCircles
186+
@Suppress("UNCHECKED_CAST")
187+
(set as ILineDataSet<*, *>).isDrawCircles = !set.isDrawCircles
187188
}
188189
binding.chart1.invalidate()
189190
}
190191

191192
R.id.actionToggleCubic -> {
192193
binding.chart1.data?.dataSets?.forEach { set ->
193-
if (set.lineMode == LineDataSet.Mode.CUBIC_BEZIER)
194-
set.lineMode = LineDataSet.Mode.LINEAR
194+
@Suppress("UNCHECKED_CAST")
195+
val lineSet = set as ILineDataSet<*, *>
196+
if (lineSet.lineMode == LineDataSet.Mode.CUBIC_BEZIER)
197+
lineSet.lineMode = LineDataSet.Mode.LINEAR
195198
else
196-
set.lineMode = LineDataSet.Mode.CUBIC_BEZIER
199+
lineSet.lineMode = LineDataSet.Mode.CUBIC_BEZIER
197200
}
198201
binding.chart1.invalidate()
199202
}
200203

201204
R.id.actionToggleStepped -> {
202205
binding.chart1.data?.dataSets?.forEach { set ->
203-
if (set.lineMode == LineDataSet.Mode.STEPPED)
204-
set.lineMode = LineDataSet.Mode.LINEAR
206+
@Suppress("UNCHECKED_CAST")
207+
val lineSet = set as ILineDataSet<*, *>
208+
if (lineSet.lineMode == LineDataSet.Mode.STEPPED)
209+
lineSet.lineMode = LineDataSet.Mode.LINEAR
205210
else
206-
set.lineMode = LineDataSet.Mode.STEPPED
211+
lineSet.lineMode = LineDataSet.Mode.STEPPED
207212
}
208213
binding.chart1.invalidate()
209214
}

app/src/main/kotlin/info/appdev/chartexample/listviewitems/ChartItem.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import info.appdev.charting.data.ChartData
88
* Base class of the Chart ListView items
99
*/
1010
@Suppress("unused")
11-
abstract class ChartItem<T : ChartData<*>> internal constructor(var chartData: T) {
11+
abstract class ChartItem<T : ChartData<*, *>> internal constructor(var chartData: T) {
1212
abstract val itemType: Int
1313

1414
abstract fun getView(position: Int, convertView: View?, context: Context?): View?

chartLib/src/main/kotlin/info/appdev/charting/charts/BarLineChartBase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import kotlin.math.min
4747
*/
4848
@Suppress("unused")
4949
@SuppressLint("RtlHardcoded")
50-
abstract class BarLineChartBase<T : BarLineScatterCandleBubbleData<IBarLineScatterCandleBubbleDataSet<out BaseEntry<Float>, Float>>> : Chart<T>,
50+
abstract class BarLineChartBase<T : BarLineScatterCandleBubbleData<*, *>> : Chart<T>,
5151
BarLineScatterCandleBubbleDataProvider<T> {
5252
/**
5353
* the maximum number of entries to which values will be drawn

chartLib/src/main/kotlin/info/appdev/charting/charts/Chart.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import kotlin.math.abs
5050
import kotlin.math.max
5151

5252
@Suppress("unused")
53-
abstract class Chart<T : ChartData<out IDataSet<out BaseEntry<Float>, Float>>> : ViewGroup, IBaseProvider<T> {
53+
abstract class Chart<T : ChartData<*, *>> : ViewGroup, IBaseProvider<T> {
5454
/**
5555
* Returns true if log-output is enabled for the chart, fals if not.
5656
*/

chartLib/src/main/kotlin/info/appdev/charting/charts/LineChart.kt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package info.appdev.charting.charts
22

33
import android.content.Context
44
import android.util.AttributeSet
5-
import info.appdev.charting.data.LineData
5+
import info.appdev.charting.data.BarLineScatterCandleBubbleData
66
import info.appdev.charting.interfaces.dataprovider.LineDataProvider
77
import info.appdev.charting.renderer.LineChartRenderer
88

9-
open class LineChart : BarLineChartBase<LineData>, LineDataProvider {
9+
open class LineChart : BarLineChartBase<BarLineScatterCandleBubbleData<*, *>>, LineDataProvider {
1010

1111
constructor(context: Context?) : super(context)
1212
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
@@ -17,12 +17,8 @@ open class LineChart : BarLineChartBase<LineData>, LineDataProvider {
1717
dataRenderer = LineChartRenderer(this, mAnimator, viewPortHandler)
1818
}
1919

20-
override var lineData: LineData
21-
get() {
22-
return mData ?: run {
23-
LineData()
24-
}
25-
}
20+
override var lineData: BarLineScatterCandleBubbleData<*, *>?
21+
get() = mData
2622
set(value) {
2723
mData = value
2824
notifyDataSetChanged()
@@ -38,15 +34,18 @@ open class LineChart : BarLineChartBase<LineData>, LineDataProvider {
3834

3935
override val accessibilityDescription: String
4036
get() {
37+
val lineData = lineData
38+
val numberOfPoints = lineData?.entryCount ?: 0
39+
4140
// Min and max values...
4241
val yAxisValueFormatter = axisLeft.valueFormatter
43-
val minVal = yAxisValueFormatter?.getFormattedValue(lineData.yMin, null)
44-
val maxVal = yAxisValueFormatter?.getFormattedValue(lineData.yMax, null)
42+
val minVal = yAxisValueFormatter?.getFormattedValue(lineData?.yMin ?: 0f, null)
43+
val maxVal = yAxisValueFormatter?.getFormattedValue(lineData?.yMax ?: 0f, null)
4544

4645
// Data range...
4746
val xAxisValueFormatter = xAxis.valueFormatter
48-
val minRange = xAxisValueFormatter?.getFormattedValue(lineData.xMin, null)
49-
val maxRange = xAxisValueFormatter?.getFormattedValue(lineData.xMax, null)
47+
val minRange = xAxisValueFormatter?.getFormattedValue(lineData?.xMin ?: 0f, null)
48+
val maxRange = xAxisValueFormatter?.getFormattedValue(lineData?.xMax ?: 0f, null)
5049
val pluralOrSingular = if (lineData.entryCount == 1) "entry" else "entries"
5150
return "The line chart has ${lineData.entryCount} $pluralOrSingular. " +
5251
"The minimum value is $minVal and maximum value is $maxVal." +

chartLib/src/main/kotlin/info/appdev/charting/charts/PieRadarChartBase.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import info.appdev.charting.animation.Easing.EasingFunction
99
import info.appdev.charting.components.Legend.LegendHorizontalAlignment
1010
import info.appdev.charting.components.Legend.LegendOrientation
1111
import info.appdev.charting.components.Legend.LegendVerticalAlignment
12-
import info.appdev.charting.data.BaseEntry
1312
import info.appdev.charting.data.ChartData
14-
import info.appdev.charting.interfaces.datasets.IDataSet
1513
import info.appdev.charting.listener.PieRadarChartTouchListener
1614
import info.appdev.charting.utils.PointF
1715
import info.appdev.charting.utils.PointF.Companion.getInstance
@@ -28,9 +26,9 @@ import kotlin.math.sin
2826
import kotlin.math.sqrt
2927

3028
/**
31-
* Baseclass of PieChart and RadarChart.
29+
* Baseclass of PieChart and yyRadarChart.
3230
*/
33-
abstract class PieRadarChartBase<T : ChartData<out IDataSet<out BaseEntry<Float>, Float>>>
31+
abstract class PieRadarChartBase<T : ChartData<*, *>>
3432
: Chart<T> {
3533
/**
3634
* holds the normalized version of the current rotation angle of the chart

chartLib/src/main/kotlin/info/appdev/charting/data/BarData.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import info.appdev.charting.interfaces.datasets.IBarDataSet
55
/**
66
* Data object that represents all data for the BarChart.
77
*/
8-
class BarData : BarLineScatterCandleBubbleData<IBarDataSet> {
8+
class BarData : BarLineScatterCandleBubbleData<IBarDataSet, Float> {
99
/**
1010
* Sets the width each bar should have on the x-axis (in values, not pixels).
1111
* Default 0.85f

chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleData.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import info.appdev.charting.interfaces.datasets.IDataSet
66
/**
77
* Baseclass for all Line, Bar, Scatter, Candle and Bubble data.
88
*/
9-
abstract class BarLineScatterCandleBubbleData<out T> : ChartData<@UnsafeVariance T>
10-
where T : IDataSet<out BaseEntry<Float>, Float>,
11-
T : IBarLineScatterCandleBubbleDataSet<out BaseEntry<Float>, Float> {
9+
abstract class BarLineScatterCandleBubbleData<out T, N> : ChartData<@UnsafeVariance T, N>
10+
where T : IDataSet<out BaseEntry<N>, N>,
11+
T : IBarLineScatterCandleBubbleDataSet<out BaseEntry<N>, N>,
12+
N : Number,
13+
N : Comparable<N> {
1214

1315
constructor() : super()
1416

chartLib/src/main/kotlin/info/appdev/charting/data/BarLineScatterCandleBubbleDataDouble.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import info.appdev.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataS
44
import info.appdev.charting.interfaces.datasets.IDataSet
55

66
/**
7-
* Baseclass for all Line, Bar, Scatter, Candle and Bubble data.
7+
* Baseclass for all Line, Bar, Scatter, Candle and Bubble data with Double precision.
88
*/
9-
abstract class BarLineScatterCandleBubbleDataDouble<out T> : ChartData<@UnsafeVariance T>
9+
abstract class BarLineScatterCandleBubbleDataDouble<out T> : ChartData<@UnsafeVariance T, Double>
1010
where T : IDataSet<out BaseEntry<Double>, Double>,
1111
T : IBarLineScatterCandleBubbleDataSet<out BaseEntry<Double>, Double> {
1212

chartLib/src/main/kotlin/info/appdev/charting/data/BubbleData.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package info.appdev.charting.data
22

33
import info.appdev.charting.interfaces.datasets.IBubbleDataSet
44

5-
class BubbleData : BarLineScatterCandleBubbleData<IBubbleDataSet> {
5+
class BubbleData : BarLineScatterCandleBubbleData<IBubbleDataSet, Float> {
66
constructor() : super()
77

88
constructor(dataSets: MutableList<IBubbleDataSet>) : super(dataSets)

0 commit comments

Comments
 (0)