add ghost subplot

This commit is contained in:
Simon Christ 2020-01-30 23:05:53 +01:00
parent 00f1fed2d1
commit b886207677

View File

@ -904,6 +904,7 @@ end
@recipe function f(::Type{Val{:lens}}, plt::AbstractPlot) @recipe function f(::Type{Val{:lens}}, plt::AbstractPlot)
# TODO: validate input # TODO: validate input
sp_index, sp_bbox = plotattributes[:inset_subplots] sp_index, sp_bbox = plotattributes[:inset_subplots]
sp = plt.subplots[sp_index]
xl1, xl2 = xlims(plt.subplots[sp_index]) xl1, xl2 = xlims(plt.subplots[sp_index])
bbx1 = xl1 + left(sp_bbox).value * (xl2 - xl1) bbx1 = xl1 + left(sp_bbox).value * (xl2 - xl1)
bbx2 = bbx1 + width(sp_bbox).value * (xl2 - xl1) bbx2 = bbx1 + width(sp_bbox).value * (xl2 - xl1)
@ -911,38 +912,57 @@ end
bby1 = yl1 + bottom(sp_bbox).value * (yl2 - yl1) bby1 = yl1 + bottom(sp_bbox).value * (yl2 - yl1)
bby2 = bby1 + height(sp_bbox).value * (yl2 - yl1) bby2 = bby1 + height(sp_bbox).value * (yl2 - yl1)
bbx = bbx1 + width(sp_bbox).value * (xl2 - xl1) / 2 bbx = bbx1 + width(sp_bbox).value * (xl2 - xl1) / 2
@show plotattributes ghost_index = last(plt.subplots)[:subplot_index] + 1
lens_index = ghost_index + 1
ghost_sp = Subplot{typeof(backend())}(sp, Series[], sp.minpad, defaultbox, sp.plotarea,
merge(sp.attr, KW(
:subplot_index => ghost_index,
:relative_bbox => bbox(0.0,0.0,1.0,1.0),
:background_color_subplot => RGBA(1.,0.,1.,0.),
)),
nothing, plt
)
push!(plt.inset_subplots, ghost_sp)
push!(plt.subplots, ghost_sp)
@show plotattributes[:plot_object].subplots
@show plt.subplots[1].plotarea
x1, x2 = plotattributes[:x] x1, x2 = plotattributes[:x]
y1, y2 = plotattributes[:y] y1, y2 = plotattributes[:y]
# add subplot # add subplot
for series in plt.series_list for series in sp.series_list
@series begin @series begin
inset_index = plotattributes[:series_plotindex]
plotattributes = copy(series.plotattributes) plotattributes = copy(series.plotattributes)
subplot := inset_index subplot := lens_index
label := "" label := ""
xlims := (x1, x2) xlims := (x1, x2)
ylims := (y1, y2) ylims := (y1, y2)
() ()
end end
end end
# add lines
# TODO: compute better linking # TODO: compute better linking
seriestype := :path seriestype := :path
label := "" label := ""
linecolor := :lightgray linecolor := :lightgray
subplot := 1 # add lines
@series begin @series begin
plotattributes[:x] = [(x1 + x2) / 2, bbx] # inset_subplots := (sp_index, bbox(0., 0., 1.0,1.0))
plotattributes[:y] = [y2, bby1] grid := :none
framestyle := :none
subplot := ghost_index
x := [(x1 + x2) / 2, bbx]
y := [y2, bby1]
() ()
end end
# add magnification shape # add magnification shape
# seriestype := plt.series_list[end][:seriestype] @series begin
plotattributes[:x] = [x1, x1, x2, x2, x1] subplot := sp_index
plotattributes[:y] = [y1, y2, y2, y1, y1] grid := true
framestyle := :box
x := [x1, x1, x2, x2, x1]
y := [y1, y2, y2, y1, y1]
() ()
end end
end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# contourf - filled contours # contourf - filled contours