Skip to content

Commit b429506

Browse files
committed
roundToNextSignificant with Double
1 parent 50c59f1 commit b429506

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

chartLib/src/main/kotlin/info/appdev/charting/renderer/AxisRenderer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ abstract class AxisRenderer(
121121

122122
// Find out how much spacing (in y value space) between axis values
123123
val rawInterval = range / labelCount
124-
var interval = rawInterval.roundToNextSignificant().toDouble()
124+
var interval = rawInterval.roundToNextSignificant()
125125

126126
// If granularity is enabled, then do not allow the interval to go below specified granularity.
127127
// This is used to avoid repeated values when rounding values for display.
128128
if (axis.isGranularityEnabled) interval = if (interval < axis.granularity) axis.granularity.toDouble() else interval
129129

130130
// Normalize interval
131-
val intervalMagnitude = 10.0.pow(log10(interval).toInt().toDouble()).roundToNextSignificant().toDouble()
131+
val intervalMagnitude = 10.0.pow(log10(interval).toInt().toDouble()).roundToNextSignificant()
132132
val intervalSigDigit = (interval / intervalMagnitude).toInt()
133133
if (intervalSigDigit > 5) {
134134
// Use one order of magnitude higher, to avoid intervals like 0.9 or 90

chartLib/src/main/kotlin/info/appdev/charting/renderer/YAxisRendererRadarChart.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ class YAxisRendererRadarChart(
3737

3838
// Find out how much spacing (in y value space) between axis values
3939
val rawInterval = range / labelCount
40-
var interval = rawInterval.roundToNextSignificant().toDouble()
40+
var interval = rawInterval.roundToNextSignificant()
4141

4242
// If granularity is enabled, then do not allow the interval to go below specified granularity.
4343
// This is used to avoid repeated values when rounding values for display.
4444
if (axis.isGranularityEnabled) interval = if (interval < axis.granularity) axis.granularity.toDouble() else interval
4545

4646
// Normalize interval
47-
val intervalMagnitude = 10.0.pow(log10(interval).toInt().toDouble()).roundToNextSignificant().toDouble()
47+
val intervalMagnitude = 10.0.pow(log10(interval).toInt().toDouble()).roundToNextSignificant()
4848
val intervalSigDigit = (interval / intervalMagnitude).toInt()
4949
if (intervalSigDigit > 5) {
5050
// Use one order of magnitude higher, to avoid intervals like 0.9 or 90

chartLib/src/main/kotlin/info/appdev/charting/utils/NumberUtils.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ fun Float.getDecimals(): Int {
1616
return 0
1717
}
1818

19-
return ceil(-log10(i.toDouble())).toInt() + 2
19+
return ceil(-log10(i)).toInt() + 2
2020
}
2121

2222
/**
2323
* rounds the given number to the next significant number
2424
*/
25-
fun Double.roundToNextSignificant(): Float {
25+
fun Double.roundToNextSignificant(): Double {
2626
if (this.isInfinite() ||
2727
this.isNaN() || this == 0.0
2828
) {
29-
return 0f
29+
return 0.0
3030
}
3131

32-
val d = ceil(log10(if (this < 0) -this else this).toFloat().toDouble()).toFloat()
32+
val d = ceil(log10(if (this < 0) -this else this).toFloat().toDouble())
3333
val pw = 1 - d.toInt()
34-
val magnitude = 10.0.pow(pw.toDouble()).toFloat()
34+
val magnitude = 10.0.pow(pw.toDouble())
3535
val shifted = (this * magnitude).roundToInt()
3636
return shifted / magnitude
3737
}

0 commit comments

Comments
 (0)