Merge pull request #1038 from piever/grmargin
Adjust margin (ticks + margin given by user) with GR ( fix #1028 )
This commit is contained in:
commit
31f080e4f4
@ -326,7 +326,7 @@ function gr_draw_markers(series::Series, x, y, msize, mz)
|
|||||||
cfuncind(ci)
|
cfuncind(ci)
|
||||||
GR.settransparency(_gr_gradient_alpha[ci-999])
|
GR.settransparency(_gr_gradient_alpha[ci-999])
|
||||||
end
|
end
|
||||||
# don't draw filled area if marker shape is 1D
|
# don't draw filled area if marker shape is 1D
|
||||||
if !(shape in (:hline, :vline, :+, :x, :cross, :xcross))
|
if !(shape in (:hline, :vline, :+, :x, :cross, :xcross))
|
||||||
gr_draw_marker(x[i], y[i], msi, shape)
|
gr_draw_marker(x[i], y[i], msi, shape)
|
||||||
end
|
end
|
||||||
@ -542,32 +542,74 @@ function gr_display(plt::Plot)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function gr_set_xticks_font(sp)
|
||||||
|
flip = sp[:yaxis][:flip]
|
||||||
|
mirror = sp[:xaxis][:mirror]
|
||||||
|
gr_set_font(sp[:xaxis][:tickfont],
|
||||||
|
halign = (:left, :hcenter, :right)[sign(sp[:xaxis][:rotation]) + 2],
|
||||||
|
valign = (mirror ? :bottom : :top),
|
||||||
|
color = sp[:xaxis][:foreground_color_axis],
|
||||||
|
rotation = sp[:xaxis][:rotation])
|
||||||
|
return flip, mirror
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function gr_set_yticks_font(sp)
|
||||||
|
flip = sp[:xaxis][:flip]
|
||||||
|
mirror = sp[:yaxis][:mirror]
|
||||||
|
gr_set_font(sp[:yaxis][:tickfont],
|
||||||
|
halign = (mirror ? :left : :right),
|
||||||
|
valign = (:top, :vcenter, :bottom)[sign(sp[:yaxis][:rotation]) + 2],
|
||||||
|
color = sp[:yaxis][:foreground_color_axis],
|
||||||
|
rotation = sp[:yaxis][:rotation])
|
||||||
|
return flip, mirror
|
||||||
|
end
|
||||||
|
|
||||||
|
function gr_get_ticks_size(ticks, i)
|
||||||
|
l = 0.0
|
||||||
|
for (cv, dv) in zip(ticks...)
|
||||||
|
tb = gr_inqtext(0, 0, string(dv))[i]
|
||||||
|
tb_min, tb_max = extrema(tb)
|
||||||
|
l = max(l, tb_max - tb_min)
|
||||||
|
end
|
||||||
|
return l
|
||||||
|
end
|
||||||
|
|
||||||
function _update_min_padding!(sp::Subplot{GRBackend})
|
function _update_min_padding!(sp::Subplot{GRBackend})
|
||||||
leftpad = 10mm
|
# Add margin given by the user
|
||||||
toppad = 2mm
|
leftpad = 2mm + sp[:left_margin]
|
||||||
rightpad = 2mm
|
toppad = 2mm + sp[:top_margin]
|
||||||
bottompad = 6mm
|
rightpad = 4mm + sp[:right_margin]
|
||||||
|
bottompad = 2mm + sp[:bottom_margin]
|
||||||
|
# Add margin for title
|
||||||
if sp[:title] != ""
|
if sp[:title] != ""
|
||||||
toppad += 5mm
|
toppad += 5mm
|
||||||
end
|
end
|
||||||
if sp[:xaxis][:guide] != ""
|
# Add margin for x and y ticks
|
||||||
xticks = axis_drawing_info(sp)[1]
|
xticks, yticks = axis_drawing_info(sp)[1:2]
|
||||||
if !(xticks in (nothing, false))
|
if !(xticks in (nothing, false))
|
||||||
gr_set_font(sp[:xaxis][:tickfont],
|
flip, mirror = gr_set_xticks_font(sp)
|
||||||
halign = (:left, :hcenter, :right)[sign(sp[:xaxis][:rotation]) + 2],
|
l = gr_get_ticks_size(xticks, 2)
|
||||||
valign = :top,
|
if mirror
|
||||||
color = sp[:xaxis][:foreground_color_axis],
|
toppad += 1mm + gr_plot_size[2] * l * px
|
||||||
rotation = sp[:xaxis][:rotation])
|
|
||||||
h = 0
|
|
||||||
for (cv, dv) in zip(xticks...)
|
|
||||||
tbx, tby = gr_inqtext(0, 0, string(dv))
|
|
||||||
h = max(h, tby[2] - tby[1])
|
|
||||||
end
|
|
||||||
bottompad += 1mm + gr_plot_size[2] * h * px
|
|
||||||
else
|
else
|
||||||
bottompad += 4mm
|
bottompad += 1mm + gr_plot_size[2] * l * px
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if !(yticks in (nothing, false))
|
||||||
|
flip, mirror = gr_set_yticks_font(sp)
|
||||||
|
l = gr_get_ticks_size(yticks, 1)
|
||||||
|
if mirror
|
||||||
|
rightpad += 1mm + gr_plot_size[1] * l * px
|
||||||
|
else
|
||||||
|
leftpad += 1mm + gr_plot_size[1] * l * px
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# Add margin for x label
|
||||||
|
if sp[:xaxis][:guide] != ""
|
||||||
|
bottompad += 4mm
|
||||||
|
end
|
||||||
|
# Add margin for y label
|
||||||
if sp[:yaxis][:guide] != ""
|
if sp[:yaxis][:guide] != ""
|
||||||
leftpad += 4mm
|
leftpad += 4mm
|
||||||
end
|
end
|
||||||
@ -742,13 +784,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
|
|
||||||
if !(xticks in (nothing, false))
|
if !(xticks in (nothing, false))
|
||||||
# x labels
|
# x labels
|
||||||
flip = sp[:yaxis][:flip]
|
flip, mirror = gr_set_xticks_font(sp)
|
||||||
mirror = sp[:xaxis][:mirror]
|
|
||||||
gr_set_font(sp[:xaxis][:tickfont],
|
|
||||||
halign = (:left, :hcenter, :right)[sign(sp[:xaxis][:rotation]) + 2],
|
|
||||||
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, xor(flip, mirror) ? ymax : ymin)
|
xi, yi = GR.wctondc(cv, xor(flip, mirror) ? ymax : ymin)
|
||||||
@ -759,13 +795,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
|
|
||||||
if !(yticks in (nothing, false))
|
if !(yticks in (nothing, false))
|
||||||
# y labels
|
# y labels
|
||||||
flip = sp[:xaxis][:flip]
|
flip, mirror = gr_set_yticks_font(sp)
|
||||||
mirror = sp[:yaxis][:mirror]
|
|
||||||
gr_set_font(sp[:yaxis][:tickfont],
|
|
||||||
halign = (mirror ? :left : :right),
|
|
||||||
valign = (:top, :vcenter, :bottom)[sign(sp[:yaxis][:rotation]) + 2],
|
|
||||||
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(xor(flip, mirror) ? xmax : xmin, cv)
|
xi, yi = GR.wctondc(xor(flip, mirror) ? xmax : xmin, cv)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user