Skip to content

Commit

Permalink
Fix #1246
Browse files Browse the repository at this point in the history
  • Loading branch information
IKupriyanov-HORIS committed Nov 15, 2024
1 parent 883f4c5 commit c90515b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion future_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
- Formatting when type='g' for large values throws exception [[#1239](https://github.com/JetBrains/lets-plot/issues/1239)].
- Wrong formatting when type='s' with explicit precision [[#1240](https://github.com/JetBrains/lets-plot/issues/1240)].
- Extra trim in formatted number when type='g' [[#1241](https://github.com/JetBrains/lets-plot/issues/1241)].
- Axis breaks are badly formatted if explicitly set [[#1245](https://github.com/JetBrains/lets-plot/issues/1245)].
- Axis breaks are badly formatted if explicitly set [[#1245](https://github.com/JetBrains/lets-plot/issues/1245)].
- Badly formatted zero break for the "~g" format [[#1246](https://github.com/JetBrains/lets-plot/issues/1246)].
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.jetbrains.letsPlot.commons.geometry.DoubleVector
import org.jetbrains.letsPlot.commons.intern.gcommon.collect.Iterables
import org.jetbrains.letsPlot.commons.intern.gcommon.collect.Ordering
import org.jetbrains.letsPlot.commons.interval.DoubleSpan
import kotlin.math.absoluteValue
import kotlin.math.log10
import kotlin.math.max
import kotlin.math.min
Expand All @@ -20,6 +21,23 @@ object SeriesUtil {

private val REAL_NUMBER = { it: Double? -> isFinite(it) }


// Looks like zero when in v >= 0 and v < 1, and the first non-zero digit
// is at least 6 orders of magnitude smaller than step
fun isLooksLikeZero(v: Double, step: Double): Boolean {
if (v == 0.0) {
return true
}

if (v.absoluteValue >= 1.0) {
return false
}

val vPower = log10(v.absoluteValue)
val stepPower = log10(step)
return (vPower - stepPower) < -6
}

fun isBeyondPrecision(range: DoubleSpan): Boolean {
val delta = range.length
return delta < TINY || // ??
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ internal class LinearBreaksHelper(
// don't allow ticks to go beyond the range
tick = min(tick, end)

breaks.add(tick)
if (SeriesUtil.isLooksLikeZero(tick, step)) {
breaks.add(0.0)
} else {
breaks.add(tick)
}

tick += step
}

Expand Down

0 comments on commit c90515b

Please sign in to comment.