fix annotations
This commit is contained in:
parent
ae396ef576
commit
7bd97558dc
@ -352,17 +352,6 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
|||||||
series_index,
|
series_index,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
# add series annotations
|
|
||||||
anns = series[:series_annotations]
|
|
||||||
for (xi, yi, str, fnt) in EachAnn(anns, series[:x], series[:y])
|
|
||||||
pgfx_add_annotation!(
|
|
||||||
axis,
|
|
||||||
xi,
|
|
||||||
yi,
|
|
||||||
PlotText(str, fnt),
|
|
||||||
pgfx_thickness_scaling(series),
|
|
||||||
)
|
|
||||||
end
|
|
||||||
# add to legend?
|
# add to legend?
|
||||||
if sp[:legend] != :none
|
if sp[:legend] != :none
|
||||||
leg_entry = if opt[:label] isa AVec
|
leg_entry = if opt[:label] isa AVec
|
||||||
@ -388,15 +377,26 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end # for segments
|
end # for segments
|
||||||
# add subplot annotations
|
# add series annotations
|
||||||
for ann in sp[:annotations]
|
anns = series[:series_annotations]
|
||||||
|
for (xi, yi, str, fnt) in EachAnn(anns, series[:x], series[:y])
|
||||||
pgfx_add_annotation!(
|
pgfx_add_annotation!(
|
||||||
axis,
|
axis,
|
||||||
locate_annotation(sp, ann...)...,
|
xi,
|
||||||
pgfx_thickness_scaling(sp),
|
yi,
|
||||||
|
PlotText(str, fnt),
|
||||||
|
pgfx_thickness_scaling(series),
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end # for series
|
end # for series
|
||||||
|
# add subplot annotations
|
||||||
|
for ann in sp[:annotations]
|
||||||
|
pgfx_add_annotation!(
|
||||||
|
axis,
|
||||||
|
locate_annotation(sp, ann...)...,
|
||||||
|
pgfx_thickness_scaling(sp),
|
||||||
|
)
|
||||||
|
end
|
||||||
push!(the_plot, axis)
|
push!(the_plot, axis)
|
||||||
if length(plt.o.the_plot.elements) > 0
|
if length(plt.o.the_plot.elements) > 0
|
||||||
plt.o.the_plot.elements[1] = the_plot
|
plt.o.the_plot.elements[1] = the_plot
|
||||||
@ -405,6 +405,7 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
|||||||
end
|
end
|
||||||
end # for subplots
|
end # for subplots
|
||||||
pgfx_plot.is_created = true
|
pgfx_plot.is_created = true
|
||||||
|
pgfx_plot.was_shown = false
|
||||||
end # if
|
end # if
|
||||||
return pgfx_plot
|
return pgfx_plot
|
||||||
end
|
end
|
||||||
|
|||||||
@ -245,15 +245,39 @@ end
|
|||||||
end # testset
|
end # testset
|
||||||
@testset "Annotations" begin
|
@testset "Annotations" begin
|
||||||
y = rand(10)
|
y = rand(10)
|
||||||
plot(
|
pgfx_plot = plot(
|
||||||
y,
|
y,
|
||||||
annotations = (3, y[3], Plots.text("this is \\#3", :left)),
|
annotations = (3, y[3], Plots.text("this is \\#3", :left)),
|
||||||
leg = false,
|
leg = false,
|
||||||
)
|
)
|
||||||
|
Plots._update_plot_object(pgfx_plot)
|
||||||
|
axis_content = Plots.pgfx_axes(pgfx_plot.o)[1].contents
|
||||||
|
nodes = filter(x -> !isa(x, PGFPlotsX.Plot), axis_content)
|
||||||
|
@test length(nodes) == 1
|
||||||
|
mktempdir() do path
|
||||||
|
file_path =joinpath(path,"annotations.tex")
|
||||||
|
@test_nowarn savefig(pgfx_plot, file_path)
|
||||||
|
open(file_path) do io
|
||||||
|
lines = readlines(io)
|
||||||
|
@test count(s -> occursin("node", s), lines) == 1
|
||||||
|
end
|
||||||
|
end
|
||||||
annotate!([
|
annotate!([
|
||||||
(5, y[5], Plots.text("this is \\#5", 16, :red, :center)),
|
(5, y[5], Plots.text("this is \\#5", 16, :red, :center)),
|
||||||
(10, y[10], Plots.text("this is \\#10", :right, 20, "courier")),
|
(10, y[10], Plots.text("this is \\#10", :right, 20, "courier")),
|
||||||
])
|
])
|
||||||
|
Plots._update_plot_object(pgfx_plot)
|
||||||
|
axis_content = Plots.pgfx_axes(pgfx_plot.o)[1].contents
|
||||||
|
nodes = filter(x -> !isa(x, PGFPlotsX.Plot), axis_content)
|
||||||
|
@test length(nodes) == 3
|
||||||
|
mktempdir() do path
|
||||||
|
file_path =joinpath(path,"annotations.tex")
|
||||||
|
@test_nowarn savefig(pgfx_plot, file_path)
|
||||||
|
open(file_path) do io
|
||||||
|
lines = readlines(io)
|
||||||
|
@test count(s -> occursin("node", s), lines) == 3
|
||||||
|
end
|
||||||
|
end
|
||||||
annotation_plot = scatter!(
|
annotation_plot = scatter!(
|
||||||
range(2, stop = 8, length = 6),
|
range(2, stop = 8, length = 6),
|
||||||
rand(6),
|
rand(6),
|
||||||
@ -267,9 +291,18 @@ end
|
|||||||
Plots.text("data", :green),
|
Plots.text("data", :green),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
# mktempdir() do path
|
Plots._update_plot_object(annotation_plot)
|
||||||
# @test_nowarn savefig(annotation_plot, path*"annotation.pdf")
|
axis_content = Plots.pgfx_axes(annotation_plot.o)[1].contents
|
||||||
# end
|
nodes = filter(x -> !isa(x, PGFPlotsX.Plot), axis_content)
|
||||||
|
@test length(nodes) == 9
|
||||||
|
mktempdir() do path
|
||||||
|
file_path =joinpath(path,"annotations.tex")
|
||||||
|
@test_nowarn savefig(annotation_plot, file_path)
|
||||||
|
open(file_path) do io
|
||||||
|
lines = readlines(io)
|
||||||
|
@test count(s -> occursin("node", s), lines) == 9
|
||||||
|
end
|
||||||
|
end
|
||||||
end # testset
|
end # testset
|
||||||
@testset "Ribbon" begin
|
@testset "Ribbon" begin
|
||||||
aa = rand(10)
|
aa = rand(10)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user