diff --git a/src/args.jl b/src/args.jl index de05dcd8..ab27323b 100644 --- a/src/args.jl +++ b/src/args.jl @@ -1044,8 +1044,14 @@ end # ----------------------------------------------------------------------------- function _update_subplot_periphery(sp::Subplot, anns::AVec) - # extend annotations - sp.attr[:annotations] = vcat(anns, sp[:annotations]) + # extend annotations, and ensure we always have a (x,y,PlotText) tuple + newanns = vcat(anns, sp[:annotations]) + for (i,ann) in enumerate(newanns) + x,y,tmp = ann + ptxt = isa(tmp, PlotText) ? tmp : text(tmp) + newanns[i] = (x,y,ptxt) + end + sp.attr[:annotations] = newanns # handle legend/colorbar sp.attr[:legend] = convertLegendValue(sp.attr[:legend]) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index ac08d15f..ad85090c 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -957,8 +957,8 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # this is all we need to add the series_annotations text anns = series[:series_annotations] - for (xi,yi,str) in EachAnn(anns, x, y) - gr_set_font(anns.font) + for (xi,yi,str,fnt) in EachAnn(anns, x, y) + gr_set_font(fnt) gr_text(GR.wctondc(xi, yi)..., str) end diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 3ad993f3..83a56f84 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -304,6 +304,18 @@ function plotly_layout(plt::Plot) # annotations append!(d_out[:annotations], KW[plotly_annotation_dict(ann...; xref = "x$spidx", yref = "y$spidx") for ann in sp[:annotations]]) + # series_annotations + for series in series_list(sp) + anns = series[:series_annotations] + for (xi,yi,str,fnt) in EachAnn(anns, series[:x], series[:y]) + push!(d_out[:annotations], plotly_annotation_dict( + xi, + yi, + PlotText(str,fnt); xref = "x$spidx", yref = "y$spidx") + ) + end + end + # # arrows # for sargs in seriesargs # a = sargs[:arrow] diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 25a95ab3..a5263c4c 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -875,8 +875,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) # this is all we need to add the series_annotations text anns = series[:series_annotations] - for (xi,yi,str) in EachAnn(anns, x, y) - py_add_annotations(sp, xi, yi, PlotText(str, anns.font)) + for (xi,yi,str,fnt) in EachAnn(anns, x, y) + py_add_annotations(sp, xi, yi, PlotText(str, fnt)) end end diff --git a/src/components.jl b/src/components.jl index 55ce10f8..8aa10e0b 100644 --- a/src/components.jl +++ b/src/components.jl @@ -476,7 +476,15 @@ type EachAnn end Base.start(ea::EachAnn) = 1 Base.done(ea::EachAnn, i) = ea.anns == nothing || isempty(ea.anns.strs) || i > length(ea.y) -Base.next(ea::EachAnn, i) = ((cycle(ea.x,i), cycle(ea.y,i), cycle(ea.anns.strs,i)), i+1) +function Base.next(ea::EachAnn, i) + tmp = cycle(ea.anns.strs,i) + str,fnt = if isa(tmp, PlotText) + tmp.str, tmp.font + else + tmp, ea.anns.font + end + ((cycle(ea.x,i), cycle(ea.y,i), str, fnt), i+1) +end annotations(::Void) = [] annotations(anns::AVec) = anns diff --git a/test/runtests.jl b/test/runtests.jl index eee6acbf..ca7f5e3e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -67,7 +67,7 @@ facts("UnicodePlots") do @fact backend() --> Plots.UnicodePlotsBackend() # lets just make sure it runs without error - @fact isa(plot(rand(10)), Plot) --> true + @fact isa(plot(rand(10)), Plots.Plot) --> true end @@ -75,7 +75,7 @@ end facts("Axes") do p = plot() axis = p.subplots[1][:xaxis] - @fact typeof(axis) --> Axis + @fact typeof(axis) --> Plots.Axis @fact Plots.discrete_value!(axis, "HI") --> (0.5, 1) @fact Plots.discrete_value!(axis, :yo) --> (1.5, 2) @fact extrema(axis) --> (0.5,1.5)