return font from EachAnn; several annotation fixes; tests fixes

This commit is contained in:
Tom Breloff 2016-11-17 11:28:33 -05:00
parent fbeaa59f18
commit 000660b43a
6 changed files with 35 additions and 9 deletions

View File

@ -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])

View File

@ -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

View File

@ -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]

View File

@ -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

View File

@ -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

View File

@ -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)