add lens! shorthand

This commit is contained in:
Simon Christ 2020-01-31 23:25:27 +01:00
parent 53fc342f7a
commit fa4db319cf

View File

@ -901,6 +901,8 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# lens! - magnify a region of a plot # lens! - magnify a region of a plot
lens!(args...;kwargs...) = plot!(args...; seriestype=:lens, kwargs...)
export lens!
@recipe function f(::Type{Val{:lens}}, plt::AbstractPlot) @recipe function f(::Type{Val{:lens}}, plt::AbstractPlot)
# TODO: validate input # TODO: validate input
sp_index, inset_bbox = plotattributes[:inset_subplots] sp_index, inset_bbox = plotattributes[:inset_subplots]
@ -955,28 +957,23 @@ end
function intersection_point(xA, yA, xB, yB, h, w) function intersection_point(xA, yA, xB, yB, h, w)
s = (yA - yB) / (xA - xB) s = (yA - yB) / (xA - xB)
@show s, xA, yA, xB, yB, h, w
hh = h / 2 hh = h / 2
hw = w / 2 hw = w / 2
# left or right? # left or right?
if -hh <= s * hw <= hh if -hh <= s * hw <= hh
if xA > xB if xA > xB
# right # right
println("right")
return xB + hw, yB + s * hw return xB + hw, yB + s * hw
else # left else # left
println("left")
return xB - hw, yB - s * hw return xB - hw, yB - s * hw
end end
# top or bot? # top or bot?
elseif -hw <= hh/s <= hw elseif -hw <= hh/s <= hw
if yA > yB if yA > yB
# top # top
println("top")
return xB + hh/s, yB + hh return xB + hh/s, yB + hh
else else
# bottom # bottom
println("bottom")
return xB - hh/s, yB - hh return xB - hh/s, yB - hh
end end
end end