recreate plot if it was shown
This commit is contained in:
parent
da60b47af5
commit
bb8e62769f
@ -75,7 +75,7 @@ function Base.push!(pgfx_plot::PGFPlotsXPlot, item)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
||||||
if !pgfx_plot.is_created
|
if !pgfx_plot.is_created || pgfx_plot.was_shown
|
||||||
the_plot = PGFPlotsX.TikzPicture(PGFPlotsX.Options())
|
the_plot = PGFPlotsX.TikzPicture(PGFPlotsX.Options())
|
||||||
bgc = plt.attr[:background_color_outside] == :match ?
|
bgc = plt.attr[:background_color_outside] == :match ?
|
||||||
plt.attr[:background_color] : plt.attr[:background_color_outside]
|
plt.attr[:background_color] : plt.attr[:background_color_outside]
|
||||||
@ -129,8 +129,7 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
|||||||
) => nothing,
|
) => nothing,
|
||||||
"fill" => cstr,
|
"fill" => cstr,
|
||||||
"fill opacity" => a,
|
"fill opacity" => a,
|
||||||
"text opacity" =>
|
"text opacity" => alpha(plot_color(sp[:legendfontcolor])),
|
||||||
alpha(plot_color(sp[:legendfontcolor])),
|
|
||||||
"font" => pgfx_font(
|
"font" => pgfx_font(
|
||||||
sp[:legendfontsize],
|
sp[:legendfontsize],
|
||||||
pgfx_thickness_scaling(sp),
|
pgfx_thickness_scaling(sp),
|
||||||
@ -254,9 +253,6 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
|||||||
end
|
end
|
||||||
for (i, rng) in enumerate(segments)
|
for (i, rng) in enumerate(segments)
|
||||||
segment_opt = PGFPlotsX.Options()
|
segment_opt = PGFPlotsX.Options()
|
||||||
if opt[:label] == ""
|
|
||||||
push!(segment_opt, "forget plot" => nothing)
|
|
||||||
end
|
|
||||||
segment_opt = merge(segment_opt, pgfx_linestyle(opt, i))
|
segment_opt = merge(segment_opt, pgfx_linestyle(opt, i))
|
||||||
if opt[:markershape] != :none
|
if opt[:markershape] != :none
|
||||||
marker = opt[:markershape]
|
marker = opt[:markershape]
|
||||||
@ -302,12 +298,11 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
|||||||
rng,
|
rng,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
if i == 1 && sp[:legend] != :none && pgfx_should_add_to_legend(series)
|
if i == 1 &&
|
||||||
|
sp[:legend] != :none && pgfx_should_add_to_legend(series)
|
||||||
pgfx_filllegend!(series_opt, opt)
|
pgfx_filllegend!(series_opt, opt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# series
|
|
||||||
#
|
|
||||||
coordinates =
|
coordinates =
|
||||||
pgfx_series_coordinates!(sp, series, segment_opt, opt, rng)
|
pgfx_series_coordinates!(sp, series, segment_opt, opt, rng)
|
||||||
segment_plot =
|
segment_plot =
|
||||||
@ -339,15 +334,6 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
|||||||
series_index,
|
series_index,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
# add to legend?
|
|
||||||
if i == 1 && sp[:legend] != :none && pgfx_should_add_to_legend(series)
|
|
||||||
leg_opt = PGFPlotsX.Options()
|
|
||||||
if ribbon !== nothing
|
|
||||||
pgfx_filllegend!(axis.contents[end - 3].options, opt)
|
|
||||||
end
|
|
||||||
legend = PGFPlotsX.LegendEntry(leg_opt, opt[:label], false)
|
|
||||||
push!(axis, legend)
|
|
||||||
end
|
|
||||||
# add series annotations
|
# add series annotations
|
||||||
anns = series[:series_annotations]
|
anns = series[:series_annotations]
|
||||||
for (xi, yi, str, fnt) in EachAnn(anns, series[:x], series[:y])
|
for (xi, yi, str, fnt) in EachAnn(anns, series[:x], series[:y])
|
||||||
@ -359,7 +345,31 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
|||||||
pgfx_thickness_scaling(series),
|
pgfx_thickness_scaling(series),
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
# add to legend?
|
||||||
|
if sp[:legend] != :none && pgfx_should_add_to_legend(series)
|
||||||
|
leg_entry = if opt[:label] isa AVec
|
||||||
|
get(opt[:label], i, "")
|
||||||
|
elseif opt[:label] isa AbstractString
|
||||||
|
if i == 1
|
||||||
|
opt[:label]
|
||||||
|
else
|
||||||
|
""
|
||||||
|
end
|
||||||
|
else
|
||||||
|
throw(ArgumentError("Malformed label. label = $(opt[:label])"))
|
||||||
|
end
|
||||||
|
if leg_entry == ""
|
||||||
|
push!(segment_plot.options, "forget plot" => nothing)
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
leg_opt = PGFPlotsX.Options()
|
||||||
|
if ribbon !== nothing
|
||||||
|
pgfx_filllegend!(axis.contents[end - 3].options, opt)
|
||||||
|
end
|
||||||
|
legend = PGFPlotsX.LegendEntry(leg_opt, leg_entry, false)
|
||||||
|
push!(axis, legend)
|
||||||
|
end
|
||||||
|
end # for segments
|
||||||
# add subplot annotations
|
# add subplot annotations
|
||||||
for ann in sp[:annotations]
|
for ann in sp[:annotations]
|
||||||
pgfx_add_annotation!(
|
pgfx_add_annotation!(
|
||||||
@ -534,8 +544,7 @@ function pgfx_series_coordinates!(
|
|||||||
|
|
||||||
cs = join(
|
cs = join(
|
||||||
[
|
[
|
||||||
join(["($x, $y) [$(zs[j, i])]" for (j, x) in enumerate(xs)], " ")
|
join(["($x, $y) [$(zs[j, i])]" for (j, x) in enumerate(xs)], " ") for (i, y) in enumerate(ys)
|
||||||
for (i, y) in enumerate(ys)
|
|
||||||
],
|
],
|
||||||
"\n\n",
|
"\n\n",
|
||||||
)
|
)
|
||||||
@ -726,8 +735,8 @@ function pgfx_marker(plotattributes, i = 1)
|
|||||||
"fill" => cstr,
|
"fill" => cstr,
|
||||||
"fill opacity" => a,
|
"fill opacity" => a,
|
||||||
"line width" =>
|
"line width" =>
|
||||||
pgfx_thickness_scaling(plotattributes) *
|
pgfx_thickness_scaling(plotattributes) *
|
||||||
_cycle(plotattributes[:markerstrokewidth], i),
|
_cycle(plotattributes[:markerstrokewidth], i),
|
||||||
"rotate" => if shape == :dtriangle
|
"rotate" => if shape == :dtriangle
|
||||||
180
|
180
|
||||||
elseif shape == :rtriangle
|
elseif shape == :rtriangle
|
||||||
@ -882,8 +891,7 @@ function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter)
|
|||||||
opt,
|
opt,
|
||||||
string(letter, "label style") => PGFPlotsX.Options(
|
string(letter, "label style") => PGFPlotsX.Options(
|
||||||
labelpos => nothing,
|
labelpos => nothing,
|
||||||
"font" =>
|
"font" => pgfx_font(axis[:guidefontsize], pgfx_thickness_scaling(sp)),
|
||||||
pgfx_font(axis[:guidefontsize], pgfx_thickness_scaling(sp)),
|
|
||||||
"color" => cstr,
|
"color" => cstr,
|
||||||
"draw opacity" => α,
|
"draw opacity" => α,
|
||||||
"rotate" => axis[:guidefontrotation],
|
"rotate" => axis[:guidefontrotation],
|
||||||
@ -969,7 +977,7 @@ function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter)
|
|||||||
opt,
|
opt,
|
||||||
string(letter, "ticklabel style") => PGFPlotsX.Options(
|
string(letter, "ticklabel style") => PGFPlotsX.Options(
|
||||||
"font" =>
|
"font" =>
|
||||||
pgfx_font(axis[:tickfontsize], pgfx_thickness_scaling(sp)),
|
pgfx_font(axis[:tickfontsize], pgfx_thickness_scaling(sp)),
|
||||||
"color" => cstr,
|
"color" => cstr,
|
||||||
"draw opacity" => α,
|
"draw opacity" => α,
|
||||||
"rotate" => axis[:tickfontrotation],
|
"rotate" => axis[:tickfontrotation],
|
||||||
@ -988,8 +996,7 @@ function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter)
|
|||||||
|
|
||||||
# framestyle
|
# framestyle
|
||||||
if framestyle in (:axes, :origin)
|
if framestyle in (:axes, :origin)
|
||||||
axispos = axis[:mirror] ? "right" :
|
axispos = axis[:mirror] ? "right" : framestyle == :axes ? "left" : "middle"
|
||||||
framestyle == :axes ? "left" : "middle"
|
|
||||||
|
|
||||||
if axis[:draw_arrow]
|
if axis[:draw_arrow]
|
||||||
push!(opt, string("axis ", letter, " line") => axispos)
|
push!(opt, string("axis ", letter, " line") => axispos)
|
||||||
@ -1062,6 +1069,7 @@ for mime in ("application/pdf", "image/png", "image/svg+xml")
|
|||||||
mime::MIME{Symbol($mime)},
|
mime::MIME{Symbol($mime)},
|
||||||
plt::Plot{PGFPlotsXBackend},
|
plt::Plot{PGFPlotsXBackend},
|
||||||
)
|
)
|
||||||
|
plt.o.was_shown = true
|
||||||
show(io, mime, plt.o.the_plot)
|
show(io, mime, plt.o.the_plot)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1071,6 +1079,7 @@ function _show(
|
|||||||
mime::MIME{Symbol("application/x-tex")},
|
mime::MIME{Symbol("application/x-tex")},
|
||||||
plt::Plot{PGFPlotsXBackend},
|
plt::Plot{PGFPlotsXBackend},
|
||||||
)
|
)
|
||||||
|
plt.o.was_shown = true
|
||||||
PGFPlotsX.print_tex(
|
PGFPlotsX.print_tex(
|
||||||
io,
|
io,
|
||||||
plt.o.the_plot,
|
plt.o.the_plot,
|
||||||
@ -1079,5 +1088,6 @@ function _show(
|
|||||||
end
|
end
|
||||||
|
|
||||||
function _display(plt::Plot{PGFPlotsXBackend})
|
function _display(plt::Plot{PGFPlotsXBackend})
|
||||||
|
plt.o.was_shown = true
|
||||||
display(PGFPlotsX.PGFPlotsXDisplay(), plt.o.the_plot)
|
display(PGFPlotsX.PGFPlotsXDisplay(), plt.o.the_plot)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user