Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timeplot vectorized funcs, add test #307

Merged
merged 1 commit into from
Mar 21, 2021
Merged
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
2 changes: 1 addition & 1 deletion doc/fun/timeplot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Example

.. winston::

using Base.Dates
using Dates

t0 = DateTime(Year(2000), Month(3), Day(14), Hour(21), Minute(45))
t1 = DateTime(Year(2000), Month(3), Day(14), Hour(22), Minute(22))
Expand Down
8 changes: 4 additions & 4 deletions src/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -658,13 +658,13 @@ end
legend(lab::AbstractVector, args...; kvs...) = legend(_pwinston, lab, args...; kvs...)

function timeplot(p::FramedPlot, x::Vector{DateTime}, y::AbstractArray, args...; kvs...)
limits = datetime2unix([minimum(x), maximum(x)])
limits = datetime2unix.([minimum(x), maximum(x)])

ticks = collect(0.0:0.2:1.0)
ticklabels = x[round(Int64, ticks * (length(x) - 1) + 1)]
normalized_x = (datetime2unix(x) - limits[1]) / (limits[2] - limits[1])
ticklabels = x[round.(Int64, ticks .* (length(x) - 1) .+ 1)]
normalized_x = (datetime2unix.(x) .- limits[1]) ./ (limits[2] - limits[1])

span = Int(x[end] - x[1]) / 1000
span = Dates.value(x[end] - x[1]) / 1000
kvs = Dict(kvs)

if :format in keys(kvs)
Expand Down
2 changes: 1 addition & 1 deletion test/compare.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ImageComparisons
using Winston, Compat, Colors
using Printf, Random
using Dates, Printf, Random
include("examples.jl")
include("issues.jl")
include("plot.jl")
Expand Down
13 changes: 12 additions & 1 deletion test/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export
example04,
#example05,
example06,
example07
example07,
example08

function example01()
x = range(0, stop=3pi, length=100)
Expand Down Expand Up @@ -155,3 +156,13 @@ function example07()

t
end

function example08()
t0 = DateTime(Year(2000), Month(3), Day(14), Hour(21), Minute(45))
t1 = DateTime(Year(2000), Month(3), Day(14), Hour(22), Minute(22))

x = collect(t0:Second(1):t1)
y = randn(length(x))

timeplot(x, y, format="%x\n%X")
end