fix axis flip in 3D plots

This commit is contained in:
t-bltg 2021-06-25 01:56:54 +02:00
parent 2b22dae757
commit 2a74f556c8

View File

@ -1282,12 +1282,22 @@ function gr_set_window(sp, viewport_plotarea)
gr_set_viewport_polar(viewport_plotarea) gr_set_viewport_polar(viewport_plotarea)
else else
xmin, xmax, ymin, ymax = gr_xy_axislims(sp) xmin, xmax, ymin, ymax = gr_xy_axislims(sp)
is3d = RecipesPipeline.is3d(sp)
if is3d
zmin, zmax = gr_z_axislims(sp)
zok = zmax > zmin
else
zok = true
end
scaleop = 0 scaleop = 0
if xmax > xmin && ymax > ymin if xmax > xmin && ymax > ymin && zok
sp[:xaxis][:scale] == :log10 && (scaleop |= GR.OPTION_X_LOG) sp[:xaxis][:scale] == :log10 && (scaleop |= GR.OPTION_X_LOG)
sp[:yaxis][:scale] == :log10 && (scaleop |= GR.OPTION_Y_LOG) sp[:yaxis][:scale] == :log10 && (scaleop |= GR.OPTION_Y_LOG)
is3d && sp[:zaxis][:scale] == :log10 && (scaleop |= GR.OPTION_Z_LOG)
sp[:xaxis][:flip] && (scaleop |= GR.OPTION_FLIP_X) sp[:xaxis][:flip] && (scaleop |= GR.OPTION_FLIP_X)
sp[:yaxis][:flip] && (scaleop |= GR.OPTION_FLIP_Y) sp[:yaxis][:flip] && (scaleop |= GR.OPTION_FLIP_Y)
is3d && sp[:zaxis][:flip] && (scaleop |= GR.OPTION_FLIP_Z)
# NOTE: setwindow sets the "data coordinate" limits of the current "viewport" # NOTE: setwindow sets the "data coordinate" limits of the current "viewport"
GR.setwindow(xmin, xmax, ymin, ymax) GR.setwindow(xmin, xmax, ymin, ymax)
GR.setscale(scaleop) GR.setscale(scaleop)
@ -1310,7 +1320,7 @@ function gr_draw_axes(sp, viewport_plotarea)
if RecipesPipeline.is3d(sp) if RecipesPipeline.is3d(sp)
# set space # set space
xmin, xmax, ymin, ymax = gr_xy_axislims(sp) xmin, xmax, ymin, ymax = gr_xy_axislims(sp)
zmin, zmax = axis_limits(sp, :z) zmin, zmax = gr_z_axislims(sp)
GR.setspace(zmin, zmax, round.(Int, sp[:camera])...) GR.setspace(zmin, zmax, round.(Int, sp[:camera])...)
# fill the plot area # fill the plot area
@ -1322,7 +1332,7 @@ function gr_draw_axes(sp, viewport_plotarea)
GR.fillarea(x_bg, y_bg) GR.fillarea(x_bg, y_bg)
for letter in (:x, :y, :z) for letter in (:x, :y, :z)
gr_draw_axis_3d(sp, letter) gr_draw_axis_3d(sp, letter, viewport_plotarea)
end end
elseif ispolar(sp) elseif ispolar(sp)
r = gr_set_viewport_polar(viewport_plotarea) r = gr_set_viewport_polar(viewport_plotarea)
@ -1352,7 +1362,7 @@ function gr_draw_axis(sp, letter, viewport_plotarea)
gr_label_axis(sp, letter, viewport_plotarea) gr_label_axis(sp, letter, viewport_plotarea)
end end
function gr_draw_axis_3d(sp, letter) function gr_draw_axis_3d(sp, letter, viewport_plotarea)
ax = axis_drawing_info_3d(sp, letter) ax = axis_drawing_info_3d(sp, letter)
axis = sp[Symbol(letter, :axis)] axis = sp[Symbol(letter, :axis)]
@ -1364,8 +1374,10 @@ function gr_draw_axis_3d(sp, letter)
gr_draw_ticks(sp, axis, ax.tick_segments, gr_polyline3d) gr_draw_ticks(sp, axis, ax.tick_segments, gr_polyline3d)
# labels # labels
GR.setscale(0)
gr_label_ticks_3d(sp, letter, ax.ticks) gr_label_ticks_3d(sp, letter, ax.ticks)
gr_label_axis_3d(sp, letter) gr_label_axis_3d(sp, letter)
gr_set_window(sp, viewport_plotarea)
end end
function gr_draw_grid(sp, axis, segments, func = gr_polyline) function gr_draw_grid(sp, axis, segments, func = gr_polyline)
@ -1440,13 +1452,14 @@ function gr_label_ticks(sp, letter, ticks)
oamin, oamax = axis_limits(sp, oletter) oamin, oamax = axis_limits(sp, oletter)
gr_set_tickfont(sp, letter) gr_set_tickfont(sp, letter)
out_factor = ifelse(axis[:tick_direction] === :out, 1.5, 1) out_factor = ifelse(axis[:tick_direction] === :out, 1.5, 1)
x_offset = isy ? (axis[:mirror] ? 1 : -1) * 1.5e-2 * out_factor : 0 x_offset = isy ? -1.5e-2 * out_factor : 0
y_offset = isy ? 0 : (axis[:mirror] ? 1 : -1) * 8e-3 * out_factor y_offset = isy ? 0 : -8e-3 * out_factor
ov = sp[:framestyle] == :origin ? 0 : xor(oaxis[:flip], axis[:mirror]) ? oamax : oamin ov = sp[:framestyle] == :origin ? 0 : xor(oaxis[:flip], axis[:mirror]) ? oamax : oamin
sgn = axis[:mirror] ? -1 : 1
for (cv, dv) in zip(ticks...) for (cv, dv) in zip(ticks...)
x, y = GR.wctondc(reverse_if((cv, ov), isy)...) x, y = GR.wctondc(reverse_if((cv, ov), isy)...)
gr_text(x + x_offset, y + y_offset, dv) gr_text(x + sgn * x_offset, y + sgn * y_offset, dv)
end end
end end
@ -1478,8 +1491,8 @@ function gr_label_ticks_3d(sp, letter, ticks)
xax, yax, zax = getindex.(Ref(sp), asyms) xax, yax, zax = getindex.(Ref(sp), asyms)
gr_set_tickfont(sp, letter) gr_set_tickfont(sp, letter)
nt = sp[:framestyle] == :origin ? 0 : xor(ax[:mirror], nax[:flip]) ? n1 : n0 nt = sp[:framestyle] == :origin ? 0 : ax[:mirror] ? n1 : n0
ft = sp[:framestyle] == :origin ? 0 : xor(ax[:mirror], fax[:flip]) ? famax : famin ft = sp[:framestyle] == :origin ? 0 : ax[:mirror] ? famax : famin
xoffset = if letter === :x xoffset = if letter === :x
(sp[:yaxis][:mirror] ? 1 : -1) * 1e-2 * (sp[:xaxis][:tick_direction] == :out ? 1.5 : 1) (sp[:yaxis][:mirror] ? 1 : -1) * 1e-2 * (sp[:xaxis][:tick_direction] == :out ? 1.5 : 1)
@ -1496,7 +1509,10 @@ function gr_label_ticks_3d(sp, letter, ticks)
0 0
end end
for (cv, dv) in zip(ticks...) cvs, dvs = ticks
ax[:flip] && reverse!(cvs)
for (cv, dv) in zip((cvs, dvs)...)
xi, yi = gr_w3tondc(sort_3d_axes(cv, nt, ft, letter)...) xi, yi = gr_w3tondc(sort_3d_axes(cv, nt, ft, letter)...)
gr_text(xi + xoffset, yi + yoffset, dv) gr_text(xi + xoffset, yi + yoffset, dv)
end end
@ -1565,8 +1581,8 @@ function gr_label_axis_3d(sp, letter)
# color = ax[:guidefontcolor], # color = ax[:guidefontcolor],
) )
ag = (amin + amax) / 2 ag = (amin + amax) / 2
ng = xor(ax[:mirror], nax[:flip]) ? n1 : n0 ng = ax[:mirror] ? n1 : n0
fg = xor(ax[:mirror], fax[:flip]) ? famax : famin fg = ax[:mirror] ? famax : famin
x, y = gr_w3tondc(sort_3d_axes(ag, ng, fg, letter)...) x, y = gr_w3tondc(sort_3d_axes(ag, ng, fg, letter)...)
if letter in (:x, :y) if letter in (:x, :y)
h = gr_axis_height(sp, ax) h = gr_axis_height(sp, ax)
@ -1577,7 +1593,8 @@ function gr_label_axis_3d(sp, letter)
y_offset = 0 y_offset = 0
end end
letter === :z && GR.setcharup(-1, 0) letter === :z && GR.setcharup(-1, 0)
gr_text(x + x_offset, y + y_offset, ax[:guide]) sgn = ax[:mirror] ? -1 : 1
gr_text(x + sgn * x_offset, y + sgn * y_offset, ax[:guide])
GR.restorestate() GR.restorestate()
end end
end end