diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/AxisRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/AxisRenderer.kt index 2f0dfecbc..4c552d521 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/AxisRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/AxisRenderer.kt @@ -121,14 +121,14 @@ abstract class AxisRenderer( // Find out how much spacing (in y value space) between axis values val rawInterval = range / labelCount - var interval = rawInterval.roundToNextSignificant().toDouble() + var interval = rawInterval.roundToNextSignificant() // If granularity is enabled, then do not allow the interval to go below specified granularity. // This is used to avoid repeated values when rounding values for display. if (axis.isGranularityEnabled) interval = if (interval < axis.granularity) axis.granularity.toDouble() else interval // Normalize interval - val intervalMagnitude = 10.0.pow(log10(interval).toInt().toDouble()).roundToNextSignificant().toDouble() + val intervalMagnitude = 10.0.pow(log10(interval).toInt().toDouble()).roundToNextSignificant() val intervalSigDigit = (interval / intervalMagnitude).toInt() if (intervalSigDigit > 5) { // Use one order of magnitude higher, to avoid intervals like 0.9 or 90 diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/YAxisRendererRadarChart.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/YAxisRendererRadarChart.kt index ec983b54a..07489bc20 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/YAxisRendererRadarChart.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/YAxisRendererRadarChart.kt @@ -37,14 +37,14 @@ class YAxisRendererRadarChart( // Find out how much spacing (in y value space) between axis values val rawInterval = range / labelCount - var interval = rawInterval.roundToNextSignificant().toDouble() + var interval = rawInterval.roundToNextSignificant() // If granularity is enabled, then do not allow the interval to go below specified granularity. // This is used to avoid repeated values when rounding values for display. if (axis.isGranularityEnabled) interval = if (interval < axis.granularity) axis.granularity.toDouble() else interval // Normalize interval - val intervalMagnitude = 10.0.pow(log10(interval).toInt().toDouble()).roundToNextSignificant().toDouble() + val intervalMagnitude = 10.0.pow(log10(interval).toInt().toDouble()).roundToNextSignificant() val intervalSigDigit = (interval / intervalMagnitude).toInt() if (intervalSigDigit > 5) { // Use one order of magnitude higher, to avoid intervals like 0.9 or 90 diff --git a/chartLib/src/main/kotlin/info/appdev/charting/utils/NumberUtils.kt b/chartLib/src/main/kotlin/info/appdev/charting/utils/NumberUtils.kt index 3eeaaa1ae..93dedbffc 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/utils/NumberUtils.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/utils/NumberUtils.kt @@ -16,22 +16,22 @@ fun Float.getDecimals(): Int { return 0 } - return ceil(-log10(i.toDouble())).toInt() + 2 + return ceil(-log10(i)).toInt() + 2 } /** * rounds the given number to the next significant number */ -fun Double.roundToNextSignificant(): Float { +fun Double.roundToNextSignificant(): Double { if (this.isInfinite() || this.isNaN() || this == 0.0 ) { - return 0f + return 0.0 } - val d = ceil(log10(if (this < 0) -this else this).toFloat().toDouble()).toFloat() + val d = ceil(log10(if (this < 0) -this else this).toFloat().toDouble()) val pw = 1 - d.toInt() - val magnitude = 10.0.pow(pw.toDouble()).toFloat() + val magnitude = 10.0.pow(pw.toDouble()) val shifted = (this * magnitude).roundToInt() return shifted / magnitude }