From 711a8448dc8c152d9d62efecdc2a8f0d5dfc81a0 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 28 Mar 2021 23:09:52 +0200 Subject: [PATCH 1/2] fix guidepostitions in GR --- src/backends/gr.jl | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index c5dd04b3..161ac190 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -1504,39 +1504,35 @@ end function gr_label_axis(sp, letter, viewport_plotarea) axis = sp[Symbol(letter, :axis)] + mirror = axis[:mirror] # guide if axis[:guide] != "" GR.savestate() gr_set_font(guidefont(axis), sp) guide_position = axis[:guide_position] if letter === :y - w = 0.03 + gr_axis_width(sp, axis) GR.setcharup(-1, 0) - # - yposition = gr_view_yposition(viewport_plotarea, position(axis[:guidefontvalign])) + ypos = gr_view_yposition(viewport_plotarea, position(axis[:guidefontvalign])) yalign = alignment(axis[:guidefontvalign]) - # - if guide_position == :right || (guide_position == :auto && axis[:mirror]) + if guide_position === :right || (guide_position == :auto && mirror) GR.settextalign(yalign, GR.TEXT_VALIGN_BOTTOM) - gr_text(viewport_plotarea[2] + w, yposition, axis[:guide]) + xpos = viewport_plotarea[2] + 0.03 + mirror * gr_axis_width(sp, axis) else GR.settextalign(yalign, GR.TEXT_VALIGN_TOP) - gr_text(viewport_plotarea[1] - w, yposition, axis[:guide]) + xpos = viewport_plotarea[1] - 0.03 - !mirror * gr_axis_width(sp, axis) end else - h = 0.015 + gr_axis_height(sp, axis) - # - xposition = gr_view_xposition(viewport_plotarea, position(axis[:guidefonthalign])) + xpos = gr_view_xposition(viewport_plotarea, position(axis[:guidefonthalign])) xalign = alignment(axis[:guidefonthalign]) - # - if guide_position == :top || (guide_position == :auto && axis[:mirror]) + if guide_position === :top || (guide_position == :auto && mirror) GR.settextalign(xalign, GR.TEXT_VALIGN_TOP) - gr_text(xposition, viewport_plotarea[4] + h, axis[:guide]) + ypos = viewport_plotarea[4] + 0.015 + (mirror ? gr_axis_height(sp, axis) : 0.015) else GR.settextalign(xalign, GR.TEXT_VALIGN_BOTTOM) - gr_text(xposition, viewport_plotarea[3] - h, axis[:guide]) + ypos = viewport_plotarea[3] - 0.015 - (mirror ? 0.015 : gr_axis_height(sp, axis)) end end + gr_text(xpos, ypos, axis[:guide]) GR.restorestate() end end From ce778ff7be178b542d3604e58ee2aa26fc1738e8 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 28 Mar 2021 23:20:09 +0200 Subject: [PATCH 2/2] add test image --- src/examples.jl | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/examples.jl b/src/examples.jl index c834be44..cfc76074 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -1138,6 +1138,30 @@ const _examples = PlotExample[ ), ], ), + PlotExample( # 54 + "Guide positions and alignment", + "", + [ + :( + begin + plot( + rand(10, 4), + layout=4, + xguide="x guide", + yguide="y guide", + xguidefonthalign=[:left :right :right :left], + yguidefontvalign=[:top :bottom :bottom :top], + xguideposition=:top, + yguideposition=[:right :left :right :left], + ymirror=[false true true false], + xmirror=[false false true true], + legend=false, + seriestype=[:bar :scatter :path :stepmid] + ) + end + ), + ], + ), ] # Some constants for PlotDocs and PlotReferenceImages