Skip to content

Commit

Permalink
Merge pull request #80 from daschw/32bit
Browse files Browse the repository at this point in the history
Fix optimize_datetime_ticks on 32bit systems
  • Loading branch information
daschw authored Feb 6, 2020
2 parents a9c3ba3 + fb48f3d commit f7cb47d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ os:
julia:
- 0.7
- 1.0
- 1.3
- nightly
notifications:
email: true
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "PlotUtils"
uuid = "995b91a9-d308-5afd-9ec6-746e21dbc043"
version = "0.6.2"
version = "0.6.3"

[deps]
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Expand All @@ -10,9 +10,9 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"

[compat]
julia = "0.7, 1"
Colors = "0"
Reexport = "0"
julia = "0.7, 1"

[extras]
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ environment:
matrix:
- julia_version: 0.7
- julia_version: 1
- julia_version: 1.3
- julia_version: nightly

platform:
Expand Down
15 changes: 6 additions & 9 deletions src/ticks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ optimize_ticks() = Any[]
coverage_weight::Float64=1/3, niceness_weight::Float64=1/4,
strict_span=true, span_buffer = nothing
)
Find some reasonable values for tick marks.
This is basically Wilkinson's ad-hoc scoring method that tries to balance
Expand Down Expand Up @@ -104,7 +104,7 @@ tight fit around the data, optimal number of ticks, and simple numbers.
## Returns:
`(ticklocations::Vector{Float64}, x_min, x_max)`
## Mathematical details
Wilkinson’s optimization function is defined as the sum of three
Expand Down Expand Up @@ -423,12 +423,9 @@ end

# Choose "round" (full seconds/minutes/hours/days/months/years) DateTime ticks
# between x_min and x_max:
function optimize_datetime_ticks(a_min::Real, a_max::Real;
k_min::Integer = 2,
k_max::Integer = 4)

x_min = DateTime(Dates.UTM(Int(round(a_min))))
x_max = DateTime(Dates.UTM(Int(round(a_max))))
function optimize_datetime_ticks(a_min, a_max; k_min = 2, k_max = 4)
x_min = DateTime(Dates.UTM(Int64(round(a_min))))
x_max = DateTime(Dates.UTM(Int64(round(a_max))))

Δt = x_max - x_min
if Δt > Dates.Day(365 * k_min)
Expand All @@ -453,7 +450,7 @@ function optimize_datetime_ticks(a_min::Real, a_max::Real;
P = Dates.Millisecond
steplength = Δt / (k_max * Dates.Millisecond(1))
end
steplength = P(max(1, Integer(round(steplength))))
steplength = P(max(1, Int(round(steplength))))

period_hierarchy = [Dates.Millisecond, Dates.Second, Dates.Minute,
Dates.Hour, Dates.Day, Dates.Month, Dates.Year]
Expand Down
3 changes: 0 additions & 3 deletions test/Project.toml

This file was deleted.

8 changes: 7 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using PlotUtils
using Test
using Statistics: mean
using Dates

# TODO: real tests

Expand Down Expand Up @@ -86,7 +87,12 @@ end

@testset "ticks" begin
@test optimize_ticks(-1,2) == ([-1.0,0.0,1.0,2.0],-1.0,2.0)

dt1, dt2 = Dates.value(DateTime(2000)), Dates.value(DateTime(2100))
@test optimize_datetime_ticks(dt1, dt2) == (
[63113990400000, 63902908800000, 64691827200000, 65480745600000],
["2001-01-01", "2026-01-01", "2051-01-01", "2076-01-01"]
)

@testset "small range $x, $(i)ϵ" for x in exp10.(-12:12), i in -5:5
y = x + i*eps(x)
x,y = minmax(x,y)
Expand Down

2 comments on commit f7cb47d

@daschw
Copy link
Member Author

@daschw daschw commented on f7cb47d Feb 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/8984

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.3 -m "<description of version>" f7cb47de0f0aac8ccc8e623221720e375836e53a
git push origin v0.6.3

Please sign in to comment.