Skip to content

Commit 28cc6c4

Browse files
authored
Merge pull request #648 from AppDevNext/getFormattedValueNonNull
getFormattedValue non null
2 parents 71907fc + cb5f66e commit 28cc6c4

File tree

10 files changed

+24
-20
lines changed

10 files changed

+24
-20
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,16 @@ class BarChartPositiveNegative : DemoBase() {
7070
binding.chart1.legend.isEnabled = false
7171

7272
// THIS IS THE ORIGINAL DATA YOU WANT TO PLOT
73-
val data: MutableList<Data> = ArrayList()
73+
val data: MutableList<Data> = mutableListOf()
7474
data.add(Data(0f, -224.1f, "12-29"))
7575
data.add(Data(1f, 238.5f, "12-30"))
7676
data.add(Data(2f, 1280.1f, "12-31"))
7777
data.add(Data(3f, -442.3f, "01-01"))
7878
data.add(Data(4f, -2280.1f, "01-02"))
7979

8080
xAxis.valueFormatter = object : IAxisValueFormatter {
81-
override fun getFormattedValue(value: Float, axis: AxisBase?): String? {
82-
return data[min(max(value.toInt(), 0), data.size - 1)].xAxisValue
81+
override fun getFormattedValue(value: Float, axis: AxisBase?): String {
82+
return data[min(max(value.toInt(), 0), data.size - 1)].xAxisValue.toString()
8383
}
8484
}
8585

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener {
7777
xAxis.setCenterAxisLabels(true)
7878
xAxis.granularity = 1f // one hour
7979
xAxis.valueFormatter = object : IAxisValueFormatter {
80-
private val mFormat = SimpleDateFormat("dd MMM HH:mm", Locale.ENGLISH)
80+
private val simpleDateFormat = SimpleDateFormat("dd MMM HH:mm", Locale.ENGLISH)
8181

82-
override fun getFormattedValue(value: Float, axis: AxisBase?): String? {
82+
override fun getFormattedValue(value: Float, axis: AxisBase?): String {
8383
val millis = TimeUnit.HOURS.toMillis(value.toLong())
84-
return mFormat.format(Date(millis))
84+
return simpleDateFormat.format(Date(millis))
8585
}
8686
}
8787

app/src/main/kotlin/info/appdev/chartexample/custom/CustomScatterShapeRenderer.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ import info.appdev.charting.utils.convertDpToPixel
1212
*/
1313
class CustomScatterShapeRenderer : IShapeRenderer {
1414
override fun renderShape(
15-
canvas: Canvas, dataSet: IScatterDataSet, viewPortHandler: ViewPortHandler?,
16-
posX: Float, posY: Float, renderPaint: Paint
15+
canvas: Canvas,
16+
dataSet: IScatterDataSet,
17+
viewPortHandler: ViewPortHandler?,
18+
posX: Float,
19+
posY: Float,
20+
renderPaint: Paint
1721
) {
1822
val shapeHalf = dataSet.scatterShapeSize.convertDpToPixel() / 2f
1923

app/src/main/kotlin/info/appdev/chartexample/custom/MyMarkerView.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import info.appdev.charting.utils.formatNumber
1818
class MyMarkerView(context: Context?, layoutResource: Int) : MarkerView(context, layoutResource) {
1919
private val tvContent: TextView = findViewById(R.id.tvContent)
2020

21-
// runs every time the MarkerView is redrawn, can be used to update the
22-
// content (user-interface)
21+
// runs every time the MarkerView is redrawn, can be used to update the content (user-interface)
2322

2423
override fun refreshContent(entry: Entry, highlight: Highlight) {
2524
if (entry is CandleEntry) {

app/src/main/kotlin/info/appdev/chartexample/formatter/DayAxisValueFormatter.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class DayAxisValueFormatter(private val chart: BarLineChartBase<*>) : IAxisValue
2323
return "$monthName $yearName"
2424
} else {
2525
val dayOfMonth = determineDayOfMonth(days, month + 12 * (year - 2016))
26-
2726
var appendix = "th"
2827

2928
when (dayOfMonth) {
@@ -51,8 +50,10 @@ class DayAxisValueFormatter(private val chart: BarLineChartBase<*>) : IAxisValue
5150
return if (is29Feb) 29 else 28
5251
}
5352

54-
return if (month == 3 || month == 5 || month == 8 || month == 10) 30
55-
else 31
53+
return if (month == 3 || month == 5 || month == 8 || month == 10)
54+
30
55+
else
56+
31
5657
}
5758

5859
private fun determineMonth(dayOfYear: Int): Int {

app/src/main/kotlin/info/appdev/chartexample/formatter/MyAxisValueFormatter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import info.appdev.charting.formatter.IAxisValueFormatter
55
import java.text.DecimalFormat
66

77
class MyAxisValueFormatter : IAxisValueFormatter {
8-
private val mFormat = DecimalFormat("###,###,###,##0.0")
8+
private val decimalFormat = DecimalFormat("###,###,###,##0.0")
99

1010
override fun getFormattedValue(value: Float, axis: AxisBase?): String {
11-
return mFormat.format(value.toDouble()) + " $"
11+
return decimalFormat.format(value.toDouble()) + " $"
1212
}
1313
}

app/src/main/kotlin/info/appdev/chartexample/formatter/UnixTimeAxisValueFormatter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import java.util.Locale
77

88
class UnixTimeAxisValueFormatter(val format: String = "yyyy-MM-dd'T'HH:mm:ss'Z'") : IAxisValueFormatter {
99

10-
val sdf = SimpleDateFormat(format, Locale.getDefault())
10+
val simpleDateFormat = SimpleDateFormat(format, Locale.getDefault())
1111

1212
override fun getFormattedValue(value: Float, axis: AxisBase?): String {
13-
return sdf.format(value * 1000L)
13+
return simpleDateFormat.format(value * 1000L)
1414
}
1515

1616
}

chartLib/src/main/kotlin/info/appdev/charting/formatter/DefaultAxisValueFormatter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ open class DefaultAxisValueFormatter(digits: Int) : IAxisValueFormatter {
2525
decimalFormat = DecimalFormat("###,###,###,##0$stringBuffer")
2626
}
2727

28-
override fun getFormattedValue(value: Float, axis: AxisBase?): String? {
28+
override fun getFormattedValue(value: Float, axis: AxisBase?): String {
2929
// avoid memory allocations here (for performance)
3030
return decimalFormat.format(value.toDouble())
3131
}

chartLib/src/main/kotlin/info/appdev/charting/formatter/IAxisValueFormatter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ interface IAxisValueFormatter {
1414
* @param value the value to be formatted
1515
* @param axis the axis the value belongs to
1616
*/
17-
fun getFormattedValue(value: Float, axis: AxisBase?): String?
17+
fun getFormattedValue(value: Float, axis: AxisBase?): String
1818
}

chartLib/src/main/kotlin/info/appdev/charting/formatter/PercentFormatter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ open class PercentFormatter : IValueFormatter, IAxisValueFormatter {
2828
}
2929

3030
// IAxisValueFormatter
31-
override fun getFormattedValue(value: Float, axis: AxisBase?): String? {
31+
override fun getFormattedValue(value: Float, axis: AxisBase?): String {
3232
return decimalFormat.format(value.toDouble()) + " %"
3333
}
3434

0 commit comments

Comments
 (0)