Merge pull request #3390 from daschw/gr-guides

fix guide positions in GR
This commit is contained in:
Daniel Schwabeneder 2021-03-28 23:50:40 +02:00 committed by GitHub
commit bf23b8f7a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 14 deletions

View File

@ -1504,39 +1504,35 @@ end
function gr_label_axis(sp, letter, viewport_plotarea) function gr_label_axis(sp, letter, viewport_plotarea)
axis = sp[Symbol(letter, :axis)] axis = sp[Symbol(letter, :axis)]
mirror = axis[:mirror]
# guide # guide
if axis[:guide] != "" if axis[:guide] != ""
GR.savestate() GR.savestate()
gr_set_font(guidefont(axis), sp) gr_set_font(guidefont(axis), sp)
guide_position = axis[:guide_position] guide_position = axis[:guide_position]
if letter === :y if letter === :y
w = 0.03 + gr_axis_width(sp, axis)
GR.setcharup(-1, 0) GR.setcharup(-1, 0)
# ypos = gr_view_yposition(viewport_plotarea, position(axis[:guidefontvalign]))
yposition = gr_view_yposition(viewport_plotarea, position(axis[:guidefontvalign]))
yalign = alignment(axis[:guidefontvalign]) yalign = alignment(axis[:guidefontvalign])
# if guide_position === :right || (guide_position == :auto && mirror)
if guide_position == :right || (guide_position == :auto && axis[:mirror])
GR.settextalign(yalign, GR.TEXT_VALIGN_BOTTOM) 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 else
GR.settextalign(yalign, GR.TEXT_VALIGN_TOP) 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 end
else else
h = 0.015 + gr_axis_height(sp, axis) xpos = gr_view_xposition(viewport_plotarea, position(axis[:guidefonthalign]))
#
xposition = gr_view_xposition(viewport_plotarea, position(axis[:guidefonthalign]))
xalign = alignment(axis[:guidefonthalign]) xalign = alignment(axis[:guidefonthalign])
# if guide_position === :top || (guide_position == :auto && mirror)
if guide_position == :top || (guide_position == :auto && axis[:mirror])
GR.settextalign(xalign, GR.TEXT_VALIGN_TOP) 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 else
GR.settextalign(xalign, GR.TEXT_VALIGN_BOTTOM) 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
end end
gr_text(xpos, ypos, axis[:guide])
GR.restorestate() GR.restorestate()
end end
end end

View File

@ -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 # Some constants for PlotDocs and PlotReferenceImages