fix extra series in lens!

This commit is contained in:
Simon Christ 2020-08-17 17:16:38 +02:00
parent 9d78772660
commit d4d05d9e36
2 changed files with 16 additions and 8 deletions

View File

@ -962,8 +962,12 @@ export lens!
lens_index = last(plt.subplots)[:subplot_index] + 1 lens_index = last(plt.subplots)[:subplot_index] + 1
x1, x2 = plotattributes[:x] x1, x2 = plotattributes[:x]
y1, y2 = plotattributes[:y] y1, y2 = plotattributes[:y]
backup = copy(plotattributes)
empty!(plotattributes)
series_plotindex := backup[:series_plotindex]
seriestype := :path seriestype := :path
label := "" primary := false
linecolor := :lightgray linecolor := :lightgray
bbx_mag = (x1 + x2) / 2 bbx_mag = (x1 + x2) / 2
bby_mag = (y1 + y2) / 2 bby_mag = (y1 + y2) / 2
@ -973,6 +977,7 @@ export lens!
if xl1 < xi_lens < xl2 && if xl1 < xi_lens < xl2 &&
yl1 < yi_lens < yl2 yl1 < yi_lens < yl2
@series begin @series begin
primary := false
subplot := sp_index subplot := sp_index
x := [xi_mag, xi_lens] x := [xi_mag, xi_lens]
y := [yi_mag, yi_lens] y := [yi_mag, yi_lens]
@ -981,6 +986,7 @@ export lens!
end end
# add magnification shape # add magnification shape
@series begin @series begin
primary := false
subplot := sp_index subplot := sp_index
x := [x1, x1, x2, x2, x1] x := [x1, x1, x2, x2, x1]
y := [y1, y2, y2, y1, y1] y := [y1, y2, y2, y1, y1]
@ -991,16 +997,13 @@ export lens!
@series begin @series begin
plotattributes = merge(plotattributes, copy(series.plotattributes)) plotattributes = merge(plotattributes, copy(series.plotattributes))
subplot := lens_index subplot := lens_index
label := "" primary := false
xlims := (x1, x2) xlims := (x1, x2)
ylims := (y1, y2) ylims := (y1, y2)
() ()
end end
end end
backup = copy(plotattributes) nothing
empty!(plotattributes)
seriestype := :path
series_plotindex := backup[:series_plotindex]
end end
function intersection_point(xA, yA, xB, yB, h, w) function intersection_point(xA, yA, xB, yB, h, w)
@ -1546,4 +1549,3 @@ julia> areaplot(1:3, [1 2 3; 7 8 9; 4 5 6], seriescolor = [:red :green :blue], f
end end
end end
end end

6
test/test_recipes.jl Normal file
View File

@ -0,0 +1,6 @@
using Plots, Test
@testset "lens!" begin
pl = plot(1:5)
lens!(pl, [1,2], [1,2], inset = (1, bbox(0.0,0.0,0.2,0.2)))
@test length(pl.series_list) == 4
end # testset