Implement colorbar_title for GR

This commit is contained in:
Takafumi Arakaki 2018-08-14 20:26:49 -07:00
parent 2d217edc15
commit 2acd088226

View File

@ -27,7 +27,7 @@ const _gr_attr = merge_with_base_supported([
:guidefontfamily, :guidefontsize, :guidefonthalign, :guidefontvalign, :guidefontfamily, :guidefontsize, :guidefonthalign, :guidefontvalign,
:guidefontrotation, :guidefontcolor, :guidefontrotation, :guidefontcolor,
:grid, :gridalpha, :gridstyle, :gridlinewidth, :grid, :gridalpha, :gridstyle, :gridlinewidth,
:legend, :legendtitle, :colorbar, :legend, :legendtitle, :colorbar, :colorbar_title,
:fill_z, :line_z, :marker_z, :levels, :fill_z, :line_z, :marker_z, :levels,
:ribbon, :quiver, :ribbon, :quiver,
:orientation, :orientation,
@ -421,6 +421,8 @@ const viewport_plotarea = zeros(4)
# the size of the current plot in pixels # the size of the current plot in pixels
const gr_plot_size = [600.0, 400.0] const gr_plot_size = [600.0, 400.0]
const gr_colorbar_ratio = 0.1
function gr_viewport_from_bbox(sp::Subplot{GRBackend}, bb::BoundingBox, w, h, viewport_canvas) function gr_viewport_from_bbox(sp::Subplot{GRBackend}, bb::BoundingBox, w, h, viewport_canvas)
viewport = zeros(4) viewport = zeros(4)
viewport[1] = viewport_canvas[2] * (left(bb) / w) viewport[1] = viewport_canvas[2] * (left(bb) / w)
@ -436,7 +438,7 @@ function gr_viewport_from_bbox(sp::Subplot{GRBackend}, bb::BoundingBox, w, h, vi
viewport[4] = 0.5 * (vp[3] + vp[4] + extent) viewport[4] = 0.5 * (vp[3] + vp[4] + extent)
end end
if hascolorbar(sp) if hascolorbar(sp)
viewport[2] -= 0.1 viewport[2] -= gr_colorbar_ratio
end end
viewport viewport
end end
@ -483,6 +485,13 @@ function gr_colorbar(sp::Subplot, clims)
GR.cellarray(xmin, xmax, clims[2], clims[1], 1, length(l), l) GR.cellarray(xmin, xmax, clims[2], clims[1], 1, length(l), l)
ztick = 0.5 * GR.tick(clims[1], clims[2]) ztick = 0.5 * GR.tick(clims[1], clims[2])
GR.axes(0, ztick, xmax, clims[1], 0, 1, 0.005) GR.axes(0, ztick, xmax, clims[1], 0, 1, 0.005)
gr_set_font(guidefont(sp[:yaxis]))
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_BOTTOM)
GR.setcharup(-1, 0)
gr_text(viewport_plotarea[2] + gr_colorbar_ratio,
gr_view_ycenter(), sp[:colorbar_title])
gr_set_viewport_plotarea() gr_set_viewport_plotarea()
end end
@ -657,6 +666,9 @@ function _update_min_padding!(sp::Subplot{GRBackend})
if sp[:yaxis][:guide] != "" if sp[:yaxis][:guide] != ""
leftpad += 4mm leftpad += 4mm
end end
if sp[:colorbar_title] != ""
rightpad += 4mm
end
sp.minpad = Tuple(dpi * [leftpad, toppad, rightpad, bottompad]) sp.minpad = Tuple(dpi * [leftpad, toppad, rightpad, bottompad])
end end