From 530ad1e701e7e371e964f919c42a2c64edb5f830 Mon Sep 17 00:00:00 2001 From: Pearl Li Date: Mon, 23 Oct 2017 17:03:45 -0400 Subject: [PATCH 1/2] Implement title_location for GR --- src/backends/gr.jl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index facfeb7f..fd3d5da4 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -20,7 +20,7 @@ const _gr_attr = merge_with_base_supported([ :fillrange, :fillcolor, :fillalpha, :bins, :layout, - :title, :window_title, + :title, :title_location, :window_title, :guide, :lims, :ticks, :scale, :flip, :tickfont, :guidefont, :legendfont, :grid, :gridalpha, :gridstyle, :gridlinewidth, @@ -865,7 +865,14 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) gr_set_font(sp[:titlefont]) GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_TOP) gr_set_textcolor(sp[:foreground_color_title]) - gr_text(gr_view_xcenter(), viewport_subplot[4], sp[:title]) + tpos = if sp[:title_location] == :left + viewport_plotarea[1] + elseif sp[:title_location] == :right + viewport_plotarea[2] + else + gr_view_xcenter() + end + gr_text(tpos, viewport_subplot[4], sp[:title]) end if xaxis[:guide] != "" From 9ea78af4a288962bcb14d36981d1bee9836b90ef Mon Sep 17 00:00:00 2001 From: Pearl Li Date: Mon, 23 Oct 2017 17:19:16 -0400 Subject: [PATCH 2/2] Right-align title text if title_location = :right --- src/backends/gr.jl | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index fd3d5da4..c9d9fd46 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -863,16 +863,17 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) GR.savestate() if sp[:title] != "" gr_set_font(sp[:titlefont]) - GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_TOP) gr_set_textcolor(sp[:foreground_color_title]) - tpos = if sp[:title_location] == :left - viewport_plotarea[1] + if sp[:title_location] == :left + GR.settextalign(GR.TEXT_HALIGN_LEFT, GR.TEXT_VALIGN_TOP) + gr_text(viewport_plotarea[1], viewport_subplot[4], sp[:title]) elseif sp[:title_location] == :right - viewport_plotarea[2] + GR.settextalign(GR.TEXT_HALIGN_RIGHT, GR.TEXT_VALIGN_TOP) + gr_text(viewport_plotarea[2], viewport_subplot[4], sp[:title]) else - gr_view_xcenter() + GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_TOP) + gr_text(gr_view_xcenter(), viewport_subplot[4], sp[:title]) end - gr_text(tpos, viewport_subplot[4], sp[:title]) end if xaxis[:guide] != ""