Skip to content
Open
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 @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading