improve tick_padding and fix rotation for plotly/gr
This commit is contained in:
parent
5ed913ba5e
commit
4416fc919e
@ -473,11 +473,11 @@ function axis_drawing_info(sp::Subplot)
|
|||||||
t2 = invf(f(ymax) - 0.015*(f(ymax)-f(ymin)))
|
t2 = invf(f(ymax) - 0.015*(f(ymax)-f(ymin)))
|
||||||
|
|
||||||
push!(spine_segs, (xmin,ymin), (xmax,ymin)) # bottom spine
|
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]
|
for xtick in xticks[1]
|
||||||
push!(spine_segs, (xtick, ymin), (xtick, t1)) # bottom tick
|
push!(spine_segs, (xtick, ymin), (xtick, t1)) # bottom tick
|
||||||
push!(grid_segs, (xtick, t1), (xtick, t2)) # vertical grid
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -488,11 +488,11 @@ function axis_drawing_info(sp::Subplot)
|
|||||||
t2 = invf(f(xmax) - 0.015*(f(xmax)-f(xmin)))
|
t2 = invf(f(xmax) - 0.015*(f(xmax)-f(xmin)))
|
||||||
|
|
||||||
push!(spine_segs, (xmin,ymin), (xmin,ymax)) # left spine
|
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]
|
for ytick in yticks[1]
|
||||||
push!(spine_segs, (xmin, ytick), (t1, ytick)) # left tick
|
push!(spine_segs, (xmin, ytick), (t1, ytick)) # left tick
|
||||||
push!(grid_segs, (t1, ytick), (t2, ytick)) # horizontal grid
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -51,15 +51,24 @@ _before_layout_calcs(plt::Plot) = nothing
|
|||||||
title_padding(sp::Subplot) = sp[:title] == "" ? 0mm : sp[:titlefont].pointsize * pt
|
title_padding(sp::Subplot) = sp[:title] == "" ? 0mm : sp[:titlefont].pointsize * pt
|
||||||
guide_padding(axis::Axis) = axis[:guide] == "" ? 0mm : axis[:guidefont].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)
|
function tick_padding(axis::Axis)
|
||||||
|
vals, labs = get_ticks(axis)
|
||||||
ptsz = axis[:tickfont].pointsize * pt
|
ptsz = axis[:tickfont].pointsize * pt
|
||||||
if axis[:ticks] in (nothing,false)
|
if axis[:ticks] in (nothing,false)
|
||||||
0mm
|
0mm
|
||||||
elseif axis[:letter] == :x
|
|
||||||
2mm + ptsz
|
|
||||||
else
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -337,10 +337,11 @@ end
|
|||||||
const _gr_point_mult = zeros(1)
|
const _gr_point_mult = zeros(1)
|
||||||
|
|
||||||
# set the font attributes... assumes _gr_point_mult has been populated already
|
# 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)
|
family = lowercase(f.family)
|
||||||
GR.setcharheight(_gr_point_mult[1] * f.pointsize)
|
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)
|
if haskey(gr_font_family, family)
|
||||||
GR.settextfontprec(100 + gr_font_family[family], GR.TEXT_PRECISION_STRING)
|
GR.settextfontprec(100 + gr_font_family[family], GR.TEXT_PRECISION_STRING)
|
||||||
end
|
end
|
||||||
@ -622,7 +623,10 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
# x labels
|
# x labels
|
||||||
flip = sp[:yaxis][:flip]
|
flip = sp[:yaxis][:flip]
|
||||||
mirror = sp[:xaxis][:mirror]
|
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...)
|
for (cv, dv) in zip(xticks...)
|
||||||
# use xor ($) to get the right y coords
|
# use xor ($) to get the right y coords
|
||||||
xi, yi = GR.wctondc(cv, (flip $ mirror) ? ymax : ymin)
|
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
|
# y labels
|
||||||
flip = sp[:xaxis][:flip]
|
flip = sp[:xaxis][:flip]
|
||||||
mirror = sp[:yaxis][:mirror]
|
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...)
|
for (cv, dv) in zip(yticks...)
|
||||||
# use xor ($) to get the right y coords
|
# use xor ($) to get the right y coords
|
||||||
xi, yi = GR.wctondc((flip $ mirror) ? xmax : xmin, cv)
|
xi, yi = GR.wctondc((flip $ mirror) ? xmax : xmin, cv)
|
||||||
|
|||||||
@ -115,7 +115,7 @@ function plotly_annotation_dict(x, y, ptxt::PlotText; xref="paper", yref="paper"
|
|||||||
:font => plotly_font(ptxt.font),
|
:font => plotly_font(ptxt.font),
|
||||||
:xanchor => ptxt.font.halign == :hcenter ? :center : ptxt.font.halign,
|
:xanchor => ptxt.font.halign == :hcenter ? :center : ptxt.font.halign,
|
||||||
:yanchor => ptxt.font.valign == :vcenter ? :middle : ptxt.font.valign,
|
:yanchor => ptxt.font.valign == :vcenter ? :middle : ptxt.font.valign,
|
||||||
:rotation => ptxt.font.rotation,
|
:rotation => -ptxt.font.rotation,
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -166,6 +166,7 @@ function plotly_axis(axis::Axis, sp::Subplot)
|
|||||||
:title => axis[:guide],
|
:title => axis[:guide],
|
||||||
:showgrid => sp[:grid],
|
:showgrid => sp[:grid],
|
||||||
:zeroline => false,
|
:zeroline => false,
|
||||||
|
:ticks => "inside",
|
||||||
)
|
)
|
||||||
|
|
||||||
if letter in (:x,:y)
|
if letter in (:x,:y)
|
||||||
@ -175,7 +176,7 @@ function plotly_axis(axis::Axis, sp::Subplot)
|
|||||||
|
|
||||||
rot = axis[:rotation]
|
rot = axis[:rotation]
|
||||||
if rot != 0
|
if rot != 0
|
||||||
ax[:tickangle] = rot
|
ax[:tickangle] = -rot
|
||||||
end
|
end
|
||||||
|
|
||||||
if !(axis[:ticks] in (nothing, :none))
|
if !(axis[:ticks] in (nothing, :none))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user