Skip to content

Commit

Permalink
make tick finding more compatible with Float64 (#161)
Browse files Browse the repository at this point in the history
* adjust limit for fallback_ticks

* fix Integer inputs

* fix typo and add test

* Fix formatting

* Remove extra newline

---------

Co-authored-by: Anshul Singhvi <[email protected]>
  • Loading branch information
ffreyer and asinghvi17 authored Mar 5, 2024
1 parent 3af0e0e commit c03d790
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ticks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ function optimize_ticks(
span_buffer = nothing,
scale = nothing,
) where {T}
x_min x_max && return fallback_ticks(x_min, x_max, k_min, k_max, strict_span)
rtol = T <: AbstractFloat ? 1000.0 * eps(T) : Base.rtoldefault(x_min, x_max, 0)
if isapprox(x_min, x_max, rtol = rtol)
return fallback_ticks(x_min, x_max, k_min, k_max, strict_span)
end

F = float(T)
Qv = F[q[1] for q Q]
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ end
@testset "ticks" begin
@test optimize_ticks(-1, 2) == ([-1.0, 0.0, 1.0, 2.0], -1.0, 2.0)

# check if ticks still generate if max - min << abs(min) (i.e. for Float64 ranges)
@test optimize_ticks(1e11 - 1, 1e11 + 2) == (1e11 .+ (-1:2), 1e11 - 1.0, 1e11 + 2.0)

@testset "dates" begin
dt1, dt2 = Dates.value(DateTime(2000)), Dates.value(DateTime(2100))
@test optimize_datetime_ticks(dt1, dt2) == (
Expand Down

0 comments on commit c03d790

Please sign in to comment.