Merge pull request #1112 from daschw/tick-orientation

Implement new tick_direction attribute for GR, Plotly(JS), PyPlot, GLVisualize and PGFPlots
This commit is contained in:
Daniel Schwabeneder 2017-09-29 09:08:52 +02:00 committed by GitHub
commit de12915eba
8 changed files with 24 additions and 13 deletions

View File

@ -115,4 +115,5 @@ const _arg_desc = KW(
:gridalpha => "Number in [0,1]. The alpha/opacity override for the grid lines.", :gridalpha => "Number in [0,1]. The alpha/opacity override for the grid lines.",
:gridstyle => "Symbol. Style of the grid lines. Choose from $(_allStyles)", :gridstyle => "Symbol. Style of the grid lines. Choose from $(_allStyles)",
:gridlinewidth => "Number. Width of the grid lines (in pixels)", :gridlinewidth => "Number. Width of the grid lines (in pixels)",
:tick_direction => "Symbol. Direction of the ticks. `:in` or `:out`"
) )

View File

@ -322,6 +322,7 @@ const _axis_defaults = KW(
:gridalpha => 0.1, :gridalpha => 0.1,
:gridstyle => :solid, :gridstyle => :solid,
:gridlinewidth => 0.5, :gridlinewidth => 0.5,
:tick_direction => :in,
) )
const _suppress_warnings = Set{Symbol}([ const _suppress_warnings = Set{Symbol}([
@ -511,7 +512,7 @@ add_aliases(:stride, :wirefame_stride, :surface_stride, :surf_str, :str)
add_aliases(:gridlinewidth, :gridwidth, :grid_linewidth, :grid_width, :gridlw, :grid_lw) add_aliases(:gridlinewidth, :gridwidth, :grid_linewidth, :grid_width, :gridlw, :grid_lw)
add_aliases(:gridstyle, :grid_style, :gridlinestyle, :grid_linestyle, :grid_ls, :gridls) add_aliases(:gridstyle, :grid_style, :gridlinestyle, :grid_linestyle, :grid_ls, :gridls)
add_aliases(:framestyle, :frame_style, :frame, :axesstyle, :axes_style, :boxstyle, :box_style, :box, :borderstyle, :border_style, :border) add_aliases(:framestyle, :frame_style, :frame, :axesstyle, :axes_style, :boxstyle, :box_style, :box, :borderstyle, :border_style, :border)
add_aliases(:tick_direction, :tickdirection, :tick_dir, :tickdir, :tick_orientation, :tickorientation, :tick_or, :tickor)
# add all pluralized forms to the _keyAliases dict # add all pluralized forms to the _keyAliases dict
for arg in keys(_series_defaults) for arg in keys(_series_defaults)

View File

@ -530,13 +530,14 @@ function axis_drawing_info(sp::Subplot)
if !(xaxis[:ticks] in (nothing, false)) if !(xaxis[:ticks] in (nothing, false))
f = scalefunc(yaxis[:scale]) f = scalefunc(yaxis[:scale])
invf = invscalefunc(yaxis[:scale]) invf = invscalefunc(yaxis[:scale])
t1 = invf(f(ymin) + 0.015*(f(ymax)-f(ymin))) ticks_in = xaxis[:tick_direction] == :out ? -1 : 1
t2 = invf(f(ymax) - 0.015*(f(ymax)-f(ymin))) t1 = invf(f(ymin) + 0.015 * (f(ymax) - f(ymin)) * ticks_in)
t3 = invf(f(0) - 0.015*(f(ymax)-f(ymin))) t2 = invf(f(ymax) - 0.015 * (f(ymax) - f(ymin)) * ticks_in)
t3 = invf(f(0) + 0.015 * (f(ymax) - f(ymin)) * ticks_in)
for xtick in xticks[1] for xtick in xticks[1]
tick_start, tick_stop = if sp[:framestyle] == :origin tick_start, tick_stop = if sp[:framestyle] == :origin
(0, xaxis[:mirror] ? -t3 : t3) (0, t3)
else else
xaxis[:mirror] ? (ymax, t2) : (ymin, t1) xaxis[:mirror] ? (ymax, t2) : (ymin, t1)
end end
@ -560,13 +561,14 @@ function axis_drawing_info(sp::Subplot)
if !(yaxis[:ticks] in (nothing, false)) if !(yaxis[:ticks] in (nothing, false))
f = scalefunc(xaxis[:scale]) f = scalefunc(xaxis[:scale])
invf = invscalefunc(xaxis[:scale]) invf = invscalefunc(xaxis[:scale])
t1 = invf(f(xmin) + 0.015*(f(xmax)-f(xmin))) ticks_in = yaxis[:tick_direction] == :out ? -1 : 1
t2 = invf(f(xmax) - 0.015*(f(xmax)-f(xmin))) t1 = invf(f(xmin) + 0.015 * (f(xmax) - f(xmin)) * ticks_in)
t3 = invf(f(0) - 0.015*(f(xmax)-f(xmin))) t2 = invf(f(xmax) - 0.015 * (f(xmax) - f(xmin)) * ticks_in)
t3 = invf(f(0) + 0.015 * (f(xmax) - f(xmin)) * ticks_in)
for ytick in yticks[1] for ytick in yticks[1]
tick_start, tick_stop = if sp[:framestyle] == :origin tick_start, tick_stop = if sp[:framestyle] == :origin
(0, yaxis[:mirror] ? -t3 : t3) (0, t3)
else else
yaxis[:mirror] ? (xmax, t2) : (xmin, t1) yaxis[:mirror] ? (xmax, t2) : (xmin, t1)
end end

View File

@ -41,6 +41,7 @@ const _glvisualize_attr = merge_with_base_supported([
:dpi, :dpi,
:hover, :hover,
:framestyle, :framestyle,
:tick_direction,
]) ])
const _glvisualize_seriestype = [ const _glvisualize_seriestype = [
:path, :shape, :path, :shape,

View File

@ -33,6 +33,7 @@ const _gr_attr = merge_with_base_supported([
:bar_width, :bar_width,
:arrow, :arrow,
:framestyle, :framestyle,
:tick_direction,
]) ])
const _gr_seriestype = [ const _gr_seriestype = [
:path, :scatter, :path, :scatter,
@ -827,7 +828,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
# use xor ($) to get the right y coords # use xor ($) to get the right y coords
xi, yi = GR.wctondc(cv, sp[:framestyle] == :origin ? 0 : xor(flip, mirror) ? ymax : ymin) xi, yi = GR.wctondc(cv, sp[:framestyle] == :origin ? 0 : xor(flip, mirror) ? ymax : ymin)
# @show cv dv ymin xi yi flip mirror (flip $ mirror) # @show cv dv ymin xi yi flip mirror (flip $ mirror)
gr_text(xi, yi + (mirror ? 1 : -1) * 5e-3, string(dv)) gr_text(xi, yi + (mirror ? 1 : -1) * 5e-3 * (xaxis[:tick_direction] == :out ? 1.5 : 1.0), string(dv))
end end
end end
@ -838,7 +839,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
# use xor ($) to get the right y coords # use xor ($) to get the right y coords
xi, yi = GR.wctondc(sp[:framestyle] == :origin ? 0 : xor(flip, mirror) ? xmax : xmin, cv) xi, yi = GR.wctondc(sp[:framestyle] == :origin ? 0 : xor(flip, mirror) ? xmax : xmin, cv)
# @show cv dv xmin xi yi # @show cv dv xmin xi yi
gr_text(xi + (mirror ? 1 : -1) * 1e-2, yi, string(dv)) gr_text(xi + (mirror ? 1 : -1) * 1e-2 * (yaxis[:tick_direction] == :out ? 1.5 : 1.0), yi, string(dv))
end end
end end

View File

@ -31,6 +31,7 @@ const _pgfplots_attr = merge_with_base_supported([
# :normalize, :weights, :contours, # :normalize, :weights, :contours,
:aspect_ratio, :aspect_ratio,
# :match_dimensions, # :match_dimensions,
:tick_direction,
]) ])
const _pgfplots_seriestype = [:path, :path3d, :scatter, :steppre, :stepmid, :steppost, :histogram2d, :ysticks, :xsticks, :contour, :shape] const _pgfplots_seriestype = [:path, :path3d, :scatter, :steppre, :stepmid, :steppost, :histogram2d, :ysticks, :xsticks, :contour, :shape]
const _pgfplots_style = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] const _pgfplots_style = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
@ -279,10 +280,11 @@ function pgf_axis(sp::Subplot, letter)
kw[Symbol(letter,:max)] = lims[2] kw[Symbol(letter,:max)] = lims[2]
end end
if !(axis[:ticks] in (nothing, false, :none, :auto)) if !(axis[:ticks] in (nothing, false, :none))
ticks = get_ticks(axis) ticks = get_ticks(axis)
push!(style, string(letter, "tick = {", join(ticks[1],","), "}")) push!(style, string(letter, "tick = {", join(ticks[1],","), "}"))
push!(style, string(letter, "ticklabels = {", join(ticks[2],","), "}")) push!(style, string(letter, "ticklabels = {", join(ticks[2],","), "}"))
push!(style, string(letter, "tick align = ", (axis[:tick_direction] == :out ? "outside" : "inside")))
end end
# return the style list and KW args # return the style list and KW args

View File

@ -34,6 +34,7 @@ const _plotly_attr = merge_with_base_supported([
:bar_width, :bar_width,
:clims, :clims,
:framestyle, :framestyle,
:tick_direction,
]) ])
const _plotly_seriestype = [ const _plotly_seriestype = [
@ -235,7 +236,7 @@ function plotly_axis(axis::Axis, sp::Subplot)
:zerolinecolor => rgba_string(axis[:foreground_color_axis]), :zerolinecolor => rgba_string(axis[:foreground_color_axis]),
:showline => framestyle in (:box, :axes), :showline => framestyle in (:box, :axes),
:linecolor => rgba_string(plot_color(axis[:foreground_color_axis])), :linecolor => rgba_string(plot_color(axis[:foreground_color_axis])),
:ticks => "inside", :ticks => axis[:tick_direction] == :out ? "outside" : "inside",
:mirror => framestyle == :box, :mirror => framestyle == :box,
) )

View File

@ -34,6 +34,7 @@ const _pyplot_attr = merge_with_base_supported([
:colorbar_title, :colorbar_title,
:stride, :stride,
:framestyle, :framestyle,
:tick_direction,
]) ])
const _pyplot_seriestype = [ const _pyplot_seriestype = [
:path, :steppre, :steppost, :shape, :path, :steppre, :steppost, :shape,
@ -1052,6 +1053,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
ticks[2][ticks[1] .== 0] = "" ticks[2][ticks[1] .== 0] = ""
end end
py_set_ticks(ax, ticks, letter) py_set_ticks(ax, ticks, letter)
pyaxis[:set_tick_params](direction = axis[:tick_direction] == :out ? "out" : "in")
ax[Symbol("set_", letter, "label")](axis[:guide]) ax[Symbol("set_", letter, "label")](axis[:guide])
if get(axis.d, :flip, false) if get(axis.d, :flip, false)
ax[Symbol("invert_", letter, "axis")]() ax[Symbol("invert_", letter, "axis")]()