Skip to content

Commit bc1fcd4

Browse files
Correct connector line in lens! for non-linear scales (#5055)
* fix date time access * fix connector line for logscales * remove comments
1 parent 52447a1 commit bc1fcd4

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

src/recipes.jl

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -993,16 +993,21 @@ export lens!
993993
xscale = sp[:xaxis][:scale]
994994
yscale = sp[:yaxis][:scale]
995995
xl1, xl2 = xlims(sp)
996-
bbx1 = xl1 + left(inset_bbox).value * (xl2 - xl1)
997-
bbx2 = bbx1 + width(inset_bbox).value * (xl2 - xl1)
996+
xls1, xls2 = RecipesPipeline.scale_func(xscale).((xl1, xl2))
997+
bbx1 = xls1 + left(inset_bbox).value * (xls2 - xls1)
998+
bbx2 = bbx1 + width(inset_bbox).value * (xls2 - xls1)
998999
yl1, yl2 = ylims(sp)
999-
bby1 = yl1 + (1 - bottom(inset_bbox).value) * (yl2 - yl1)
1000-
bby2 = bby1 + height(inset_bbox).value * (yl2 - yl1)
1001-
bbx = bbx1 + width(inset_bbox).value * (xl2 - xl1) / 2 * (sp[:xaxis][:flip] ? -1 : 1)
1002-
bby = bby1 + height(inset_bbox).value * (yl2 - yl1) / 2 * (sp[:yaxis][:flip] ? -1 : 1)
1000+
yls1, yls2 = RecipesPipeline.scale_func(yscale).((yl1, yl2))
1001+
bby1 = yls1 + (1 - bottom(inset_bbox).value) * (yls2 - yls1)
1002+
bby2 = bby1 + height(inset_bbox).value * (yls2 - yls1)
1003+
bbx = bbx1 + width(inset_bbox).value * (xls2 - xls1) / 2 * (sp[:xaxis][:flip] ? -1 : 1)
1004+
bby = bby1 + height(inset_bbox).value * (yls2 - yls1) / 2 * (sp[:yaxis][:flip] ? -1 : 1)
10031005
lens_index = last(plt.subplots)[:subplot_index] + 1
1004-
x1, x2 = RecipesPipeline.inverse_scale_func(xscale).(plotattributes[:x])
1005-
y1, y2 = RecipesPipeline.inverse_scale_func(yscale).(plotattributes[:y])
1006+
x1, x2 = plotattributes[:x]
1007+
y1, y2 = plotattributes[:y]
1008+
xs1, xs2 = RecipesPipeline.scale_func(xscale).((x1, x2))
1009+
ys1, ys2 = RecipesPipeline.scale_func(yscale).((y1, y2))
1010+
10061011
backup = copy(plotattributes)
10071012
empty!(plotattributes)
10081013

@@ -1016,28 +1021,30 @@ export lens!
10161021
if haskey(backup, :linewidth)
10171022
linewidth := backup[:linewidth]
10181023
end
1019-
bbx_mag = (x1 + x2) / 2
1020-
bby_mag = (y1 + y2) / 2
1024+
bbx_mag = (xs1 + xs2) / 2
1025+
bby_mag = (ys1 + ys2) / 2
10211026
xi_lens, yi_lens =
10221027
intersection_point(bbx_mag, bby_mag, bbx, bby, abs(bby2 - bby1), abs(bbx2 - bbx1))
10231028
xi_mag, yi_mag =
10241029
intersection_point(bbx, bby, bbx_mag, bby_mag, abs(y2 - y1), abs(x2 - x1))
1030+
xi_mag, xi_lens = RecipesPipeline.inverse_scale_func(xscale).((xi_mag, xi_lens))
1031+
yi_mag, yi_lens = RecipesPipeline.inverse_scale_func(yscale).((yi_mag, yi_lens))
10251032
# add lines
10261033
if xl1 < xi_lens < xl2 && yl1 < yi_lens < yl2
10271034
@series begin
10281035
primary := false
10291036
subplot := sp_index
1030-
x := RecipesPipeline.scale_func(xscale).([xi_mag, xi_lens])
1031-
y := RecipesPipeline.scale_func(yscale).([yi_mag, yi_lens])
1037+
x := [xi_mag, xi_lens]
1038+
y := [yi_mag, yi_lens]
10321039
()
10331040
end
10341041
end
10351042
# add magnification shape
10361043
@series begin
10371044
primary := false
10381045
subplot := sp_index
1039-
x := RecipesPipeline.scale_func(xscale).([x1, x1, x2, x2, x1])
1040-
y := RecipesPipeline.scale_func(yscale).([y1, y2, y2, y1, y1])
1046+
x := [x1, x1, x2, x2, x1]
1047+
y := [y1, y2, y2, y1, y1]
10411048
()
10421049
end
10431050
# add subplot
@@ -1046,8 +1053,8 @@ export lens!
10461053
plotattributes = merge(backup, copy(series.plotattributes))
10471054
subplot := lens_index
10481055
primary := false
1049-
xlims := RecipesPipeline.scale_func(xscale).((x1, x2))
1050-
ylims := RecipesPipeline.scale_func(yscale).((y1, y2))
1056+
xlims := (x1, x2)
1057+
ylims := (y1, y2)
10511058
()
10521059
end
10531060
end

0 commit comments

Comments
 (0)