Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class BarChartActivityMultiDataset : DemoBase(), OnSeekBarChangeListener, OnChar
override fun getFormattedValue(value: Float, axis: AxisBase?): String {
return value.toInt().toString()
}

override fun getFormattedValue(value: Long, axis: AxisBase?): String {
return value.toString()
}
}

val leftAxis = binding.chart1.axisLeft
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ class BarChartPositiveNegative : DemoBase() {
override fun getFormattedValue(value: Float, axis: AxisBase?): String? {
return data[min(max(value.toInt(), 0), data.size - 1)].xAxisValue
}

override fun getFormattedValue(value: Long, axis: AxisBase?): String {
val ma = max(value, 0)
val mi = min(ma, (data.size - 1).toLong()).toInt()
return data[mi].xAxisValue!!
}
}

setData(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class CombinedChartActivity : DemoBase() {
override fun getFormattedValue(value: Float, axis: AxisBase?): String {
return months[value.toInt() % months.size]
}

override fun getFormattedValue(value: Long, axis: AxisBase?): String {
return months[(value % months.size).toInt()]
}
}

val data = CombinedData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener {
val millis = TimeUnit.HOURS.toMillis(value.toLong())
return mFormat.format(Date(millis))
}

override fun getFormattedValue(value: Long, axis: AxisBase?): String {
val millis = TimeUnit.HOURS.toMillis(value)
return mFormat.format(Date(millis))
}
}

val leftAxis = binding.chart1.axisLeft
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class RadarChartActivity : DemoBase() {
override fun getFormattedValue(value: Float, axis: AxisBase?): String {
return mActivities[value.toInt() % mActivities.size]
}

override fun getFormattedValue(value: Long, axis: AxisBase?): String {
return mActivities[(value % mActivities.size).toInt()]
}
}
xAxis.textColor = Color.WHITE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class StackedBarActivityNegative : DemoBase(), OnChartValueSelectedListener {
override fun getFormattedValue(value: Float, axis: AxisBase?): String {
return format.format(value.toDouble()) + "-" + format.format((value + 10).toDouble())
}

override fun getFormattedValue(value: Long, axis: AxisBase?): String {
return format.format(value) + "-" + format.format((value + 10).toDouble())
}
}

binding.chart1.legend.apply {
Expand Down Expand Up @@ -218,5 +222,9 @@ class StackedBarActivityNegative : DemoBase(), OnChartValueSelectedListener {
override fun getFormattedValue(value: Float, axis: AxisBase?): String {
return decimalFormat.format(abs(value).toDouble()) + "m"
}

override fun getFormattedValue(value: Long, axis: AxisBase?): String {
return decimalFormat.format(abs(value)) + "m"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class DayAxisValueFormatter(private val chart: BarLineChartBase<*>) : IAxisValue
}
}

override fun getFormattedValue(value: Long, axis: AxisBase?): String {
return getFormattedValue(value.toFloat(), axis)
}

private fun getDaysForMonth(month: Int, year: Int): Int {
// month is 0-based

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ class MyAxisValueFormatter : IAxisValueFormatter {
override fun getFormattedValue(value: Float, axis: AxisBase?): String {
return mFormat.format(value.toDouble()) + " $"
}

override fun getFormattedValue(value: Long, axis: AxisBase?): String {
return mFormat.format(value) + " $"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ class YearXAxisFormatter : IAxisValueFormatter {
val percent = value / axis!!.mAxisRange
return months[(months.size * percent).toInt()]
}

override fun getFormattedValue(value: Long, axis: AxisBase?): String {
return getFormattedValue(value.toFloat(), axis)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ open class DefaultAxisValueFormatter(digits: Int) : IAxisValueFormatter {
// avoid memory allocations here (for performance)
return decimalFormat.format(value.toDouble())
}

override fun getFormattedValue(value: Long, axis: AxisBase?): String {
return decimalFormat.format(value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ interface IAxisValueFormatter {
* @param axis the axis the value belongs to
*/
fun getFormattedValue(value: Float, axis: AxisBase?): String?

fun getFormattedValue(value: Long, axis: AxisBase?): String
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ open class IndexAxisValueFormatter : IAxisValueFormatter {
values[index]
}

override fun getFormattedValue(value: Long, axis: AxisBase?): String {
return if (value < 0 || value >= values.size)
""
else
values[value.toInt()]
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ open class LargeValueFormatter() : IValueFormatter, IAxisValueFormatter {
return makePretty(value.toDouble()) + text
}

override fun getFormattedValue(value: Long, axis: AxisBase?): String {
return makePretty(value) + text
}

/**
* Set an appendix text to be added at the end of the formatted value.
*/
Expand Down Expand Up @@ -78,4 +82,16 @@ open class LargeValueFormatter() : IValueFormatter, IAxisValueFormatter {
return decimalFormat
}

private fun makePretty(number: Long): String {
var decimalFormat = decimalFormat.format(number)
val numericValue1 = Character.getNumericValue(decimalFormat[decimalFormat.length - 1])
val numericValue2 = Character.getNumericValue(decimalFormat[decimalFormat.length - 2])
val combined = Integer.valueOf(numericValue2.toString() + "" + numericValue1)
decimalFormat = decimalFormat.replace("E[0-9][0-9]".toRegex(), suffix[combined / 3])
while (decimalFormat.length > maxLength || decimalFormat.matches("[0-9]+\\.[a-z]".toRegex())) {
decimalFormat = decimalFormat.substring(0, decimalFormat.length - 2) + decimalFormat.substring(decimalFormat.length - 1)
}
return decimalFormat
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ open class PercentFormatter : IValueFormatter, IAxisValueFormatter {
return decimalFormat.format(value.toDouble()) + " %"
}

val decimalDigits: Int
get() = 1
override fun getFormattedValue(value: Long, axis: AxisBase?): String {
return decimalFormat.format(value) + " %"
}

}
Loading