Treat types without length as single element

Fixes #2350
Workaround for types like Dates.Date which can be used for coordinates
but doesn't have Base.length defined.
This commit is contained in:
O01eg 2020-01-20 13:49:10 +03:00
parent 745189981b
commit 2ede388c15
No known key found for this signature in database
GPG Key ID: DB49D45C128F6BB2
2 changed files with 19 additions and 1 deletions

View File

@ -591,7 +591,9 @@ annotations(sa::SeriesAnnotations) = sa
function process_annotation(sp::Subplot, xs, ys, labs, font = font()) function process_annotation(sp::Subplot, xs, ys, labs, font = font())
anns = [] anns = []
labs = makevec(labs) labs = makevec(labs)
for i in 1:max(length(xs), length(ys), length(labs)) xlength = length(methods(length, (typeof(xs),))) == 0 ? 1 : length(xs)
ylength = length(methods(length, (typeof(ys),))) == 0 ? 1 : length(ys)
for i in 1:max(xlength, ylength, length(labs))
x, y, lab = _cycle(xs, i), _cycle(ys, i), _cycle(labs, i) x, y, lab = _cycle(xs, i), _cycle(ys, i), _cycle(labs, i)
if lab == :auto if lab == :auto
alphabet = "abcdefghijklmnopqrstuvwxyz" alphabet = "abcdefghijklmnopqrstuvwxyz"

View File

@ -7,6 +7,7 @@ using FileIO
using Gtk using Gtk
using LibGit2 using LibGit2
using GeometryTypes using GeometryTypes
using Dates
include("test_pgfplotsx.jl") include("test_pgfplotsx.jl")
@ -67,6 +68,21 @@ img_tol = is_ci() ? 10e-2 : 10e-2
p = bar(randn(10)) p = bar(randn(10))
@test isa(p, Plots.Plot) == true @test isa(p, Plots.Plot) == true
@test isa(display(p), Nothing) == true @test isa(display(p), Nothing) == true
p = plot([1, 2], [3, 4])
annotate!(p, [(1.5, 3.2, Plots.text("Test", :red, :center))])
hline!(p, [3.1])
@test isa(p, Plots.Plot) == true
@test isa(display(p), Nothing) == true
p = plot([Dates.Date(2019, 1, 1), Dates.Date(2019, 2, 1)], [3, 4])
hline!(p, [3.1])
annotate!(p, [(Dates.Date(2019, 1, 15), 3.2, Plots.text("Test", :red, :center))])
@test isa(p, Plots.Plot) == true
@test isa(display(p), Nothing) == true
p = plot([Dates.Date(2019, 1, 1), Dates.Date(2019, 2, 1)], [3, 4])
annotate!(p, [(Dates.Date(2019, 1, 15), 3.2, Plots.text("Test", :red, :center))])
hline!(p, [3.1])
@test isa(p, Plots.Plot) == true
@test isa(display(p), Nothing) == true
end end
end end