diff --git a/src/axes.jl b/src/axes.jl index 142ccedb..0cd8ac4c 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -473,11 +473,11 @@ function axis_drawing_info(sp::Subplot) t2 = invf(f(ymax) - 0.015*(f(ymax)-f(ymin))) push!(spine_segs, (xmin,ymin), (xmax,ymin)) # bottom spine - push!(spine_segs, (xmin,ymax), (xmax,ymax)) # top spine + # push!(spine_segs, (xmin,ymax), (xmax,ymax)) # top spine for xtick in xticks[1] push!(spine_segs, (xtick, ymin), (xtick, t1)) # bottom tick push!(grid_segs, (xtick, t1), (xtick, t2)) # vertical grid - push!(spine_segs, (xtick, ymax), (xtick, t2)) # top tick + # push!(spine_segs, (xtick, ymax), (xtick, t2)) # top tick end end @@ -488,11 +488,11 @@ function axis_drawing_info(sp::Subplot) t2 = invf(f(xmax) - 0.015*(f(xmax)-f(xmin))) push!(spine_segs, (xmin,ymin), (xmin,ymax)) # left spine - push!(spine_segs, (xmax,ymin), (xmax,ymax)) # right spine + # push!(spine_segs, (xmax,ymin), (xmax,ymax)) # right spine for ytick in yticks[1] push!(spine_segs, (xmin, ytick), (t1, ytick)) # left tick push!(grid_segs, (t1, ytick), (t2, ytick)) # horizontal grid - push!(spine_segs, (xmax, ytick), (t2, ytick)) # right tick + # push!(spine_segs, (xmax, ytick), (t2, ytick)) # right tick end end diff --git a/src/backends.jl b/src/backends.jl index 699f1cc1..c2376a80 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -51,15 +51,24 @@ _before_layout_calcs(plt::Plot) = nothing title_padding(sp::Subplot) = sp[:title] == "" ? 0mm : sp[:titlefont].pointsize * pt guide_padding(axis::Axis) = axis[:guide] == "" ? 0mm : axis[:guidefont].pointsize * pt -# TODO: this should account for both tick font and the size/length/rotation of tick labels +# account for the size/length/rotation of tick labels function tick_padding(axis::Axis) + vals, labs = get_ticks(axis) ptsz = axis[:tickfont].pointsize * pt if axis[:ticks] in (nothing,false) 0mm - elseif axis[:letter] == :x - 2mm + ptsz else - 8mm + # we need to compute the size of the ticks generically + # this means computing the bounding box and then getting the width/height + longest_label = maximum(length(lab) for lab in labs) + labelwidth = 0.8longest_label * ptsz + + # generalize by "rotating" y labels + rot = axis[:rotation] + (axis[:letter] == :y ? 90 : 0) + + # now compute the generalized "height" after rotation as the "opposite+adjacent" of 2 triangles + hgt = abs(sind(rot)) * labelwidth + abs(cosd(rot)) * ptsz + 1mm + hgt end end diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 9a4b3c7a..090aa499 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -337,10 +337,11 @@ end const _gr_point_mult = zeros(1) # set the font attributes... assumes _gr_point_mult has been populated already -function gr_set_font(f::Font; halign = f.halign, valign = f.valign, color = f.color) +function gr_set_font(f::Font; halign = f.halign, valign = f.valign, + color = f.color, rotation = f.rotation) family = lowercase(f.family) GR.setcharheight(_gr_point_mult[1] * f.pointsize) - GR.setcharup(sin(f.rotation), cos(f.rotation)) + GR.setcharup(sind(-rotation), cosd(-rotation)) if haskey(gr_font_family, family) GR.settextfontprec(100 + gr_font_family[family], GR.TEXT_PRECISION_STRING) end @@ -622,7 +623,10 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # x labels flip = sp[:yaxis][:flip] mirror = sp[:xaxis][:mirror] - gr_set_font(sp[:xaxis][:tickfont], valign = (mirror ? :bottom : :top), color = sp[:xaxis][:foreground_color_axis]) + gr_set_font(sp[:xaxis][:tickfont], + valign = (mirror ? :bottom : :top), + color = sp[:xaxis][:foreground_color_axis], + rotation = sp[:xaxis][:rotation]) for (cv, dv) in zip(xticks...) # use xor ($) to get the right y coords xi, yi = GR.wctondc(cv, (flip $ mirror) ? ymax : ymin) @@ -635,7 +639,10 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # y labels flip = sp[:xaxis][:flip] mirror = sp[:yaxis][:mirror] - gr_set_font(sp[:yaxis][:tickfont], halign = (mirror ? :left : :right), color = sp[:yaxis][:foreground_color_axis]) + gr_set_font(sp[:yaxis][:tickfont], + halign = (mirror ? :left : :right), + color = sp[:yaxis][:foreground_color_axis], + rotation = sp[:yaxis][:rotation]) for (cv, dv) in zip(yticks...) # use xor ($) to get the right y coords xi, yi = GR.wctondc((flip $ mirror) ? xmax : xmin, cv) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index de30acd3..dca86b14 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -115,7 +115,7 @@ function plotly_annotation_dict(x, y, ptxt::PlotText; xref="paper", yref="paper" :font => plotly_font(ptxt.font), :xanchor => ptxt.font.halign == :hcenter ? :center : ptxt.font.halign, :yanchor => ptxt.font.valign == :vcenter ? :middle : ptxt.font.valign, - :rotation => ptxt.font.rotation, + :rotation => -ptxt.font.rotation, )) end @@ -166,6 +166,7 @@ function plotly_axis(axis::Axis, sp::Subplot) :title => axis[:guide], :showgrid => sp[:grid], :zeroline => false, + :ticks => "inside", ) if letter in (:x,:y) @@ -175,7 +176,7 @@ function plotly_axis(axis::Axis, sp::Subplot) rot = axis[:rotation] if rot != 0 - ax[:tickangle] = rot + ax[:tickangle] = -rot end if !(axis[:ticks] in (nothing, :none))