better linking

This commit is contained in:
Simon Christ 2020-01-31 23:18:44 +01:00
parent bf619eecbd
commit 53fc342f7a

View File

@ -909,15 +909,37 @@ end
bbx1 = xl1 + left(inset_bbox).value * (xl2 - xl1) bbx1 = xl1 + left(inset_bbox).value * (xl2 - xl1)
bbx2 = bbx1 + width(inset_bbox).value * (xl2 - xl1) bbx2 = bbx1 + width(inset_bbox).value * (xl2 - xl1)
yl1, yl2 = ylims(plt.subplots[sp_index]) yl1, yl2 = ylims(plt.subplots[sp_index])
bby1 = yl1 + bottom(inset_bbox).value * (yl2 - yl1) bby1 = yl1 + (1 - bottom(inset_bbox).value) * (yl2 - yl1)
bby2 = bby1 + height(inset_bbox).value * (yl2 - yl1) bby2 = bby1 + height(inset_bbox).value * (yl2 - yl1)
bbx = bbx1 + width(inset_bbox).value * (xl2 - xl1) / 2 bbx = bbx1 + width(inset_bbox).value * (xl2 - xl1) / 2
bby = bby1 + height(inset_bbox).value * (yl2 - yl1) / 2
lens_index = last(plt.subplots)[:subplot_index] + 1 lens_index = last(plt.subplots)[:subplot_index] + 1
@show plotattributes[:plot_object].subplots
@show inset_bbox
@show sp[:left_margin]
x1, x2 = plotattributes[:x] x1, x2 = plotattributes[:x]
y1, y2 = plotattributes[:y] y1, y2 = plotattributes[:y]
seriestype := :path
label := ""
linecolor := :lightgray
bbx_mag = (x1 + x2) / 2
bby_mag = (y1 + y2) / 2
xi_lens, yi_lens = intersection_point(bbx_mag, bby_mag, bbx, bby, abs(bby2 - bby1), abs(bbx2 - bbx1))
xi_mag, yi_mag = intersection_point(bbx, bby, bbx_mag, bby_mag, abs(y2 - y1), abs(x2 - x1))
# add lines
if xl1 < xi_lens < xl2 &&
yl1 < yi_lens < yl2
@series begin
subplot := sp_index
x := [xi_mag, xi_lens]
y := [yi_mag, yi_lens]
()
end
end
# add magnification shape
@series begin
subplot := sp_index
x := [x1, x1, x2, x2, x1]
y := [y1, y2, y2, y1, y1]
()
end
# add subplot # add subplot
for series in sp.series_list for series in sp.series_list
@series begin @series begin
@ -929,26 +951,34 @@ end
() ()
end end
end end
# TODO: compute better linking end
seriestype := :path
label := "" function intersection_point(xA, yA, xB, yB, h, w)
linecolor := :lightgray s = (yA - yB) / (xA - xB)
# add lines @show s, xA, yA, xB, yB, h, w
if xl1 < bbx < xl2 && hh = h / 2
yl1 < bby1 < yl2 hw = w / 2
@series begin # left or right?
subplot := sp_index if -hh <= s * hw <= hh
x := [(x1 + x2) / 2, bbx] if xA > xB
y := [y2, bby1] # right
() println("right")
return xB + hw, yB + s * hw
else # left
println("left")
return xB - hw, yB - s * hw
end end
# top or bot?
elseif -hw <= hh/s <= hw
if yA > yB
# top
println("top")
return xB + hh/s, yB + hh
else
# bottom
println("bottom")
return xB - hh/s, yB - hh
end end
# add magnification shape
@series begin
subplot := sp_index
x := [x1, x1, x2, x2, x1]
y := [y1, y2, y2, y1, y1]
()
end end
end end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------