Merge pull request #2060 from daschw/gr_arrow

Implement arrowstyle for GR (fix #2059)
This commit is contained in:
Daniel Schwabeneder 2019-06-12 23:02:12 +02:00 committed by GitHub
commit 94841669bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View File

@ -1030,7 +1030,7 @@ function preprocessArgs!(plotattributes::KW)
arrow()
elseif a in (false, nothing, :none)
nothing
elseif !(typeof(a) <: Arrow)
elseif !(typeof(a) <: Arrow || typeof(a) <: AbstractArray{Arrow})
arrow(wraptuple(a)...)
else
a

View File

@ -84,12 +84,23 @@ gr_set_transparency(c, α) = gr_set_transparency(α)
gr_set_transparency(c::Colorant, ::Nothing) = gr_set_transparency(c)
gr_set_transparency(c::Colorant) = GR.settransparency(alpha(c))
const _gr_arrow_map = Dict(
:simple => 1,
:hollow => 3,
:filled => 4,
:triangle => 5,
:filledtriangle => 6,
:closed => 6,
:open => 5,
)
gr_set_arrowstyle(s::Symbol) = GR.setarrowstyle(get(_gr_arrow_map, s, 1))
# --------------------------------------------------------------------------------------
# draw line segments, splitting x/y into contiguous/finite segments
# note: this can be used for shapes by passing func `GR.fillarea`
function gr_polyline(x, y, func = GR.polyline; arrowside=:none)
function gr_polyline(x, y, func = GR.polyline; arrowside = :none, arrowstyle = :simple)
iend = 0
n = length(x)
while iend < n-1
@ -118,9 +129,11 @@ function gr_polyline(x, y, func = GR.polyline; arrowside=:none)
if istart > 0 && iend > 0
func(x[istart:iend], y[istart:iend])
if arrowside in (:head,:both)
gr_set_arrowstyle(arrowstyle)
GR.drawarrow(x[iend-1], y[iend-1], x[iend], y[iend])
end
if arrowside in (:tail,:both)
gr_set_arrowstyle(arrowstyle)
GR.drawarrow(x[istart+1], y[istart+1], x[istart], y[istart])
end
else
@ -1269,7 +1282,9 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
gr_set_line(get_linewidth(series, i), get_linestyle(series, i), lc) #, series[:linealpha])
gr_set_transparency(lc, get_linealpha(series, i))
arrowside = isa(series[:arrow], Arrow) ? series[:arrow].side : :none
gr_polyline(x[rng], y[rng]; arrowside = arrowside)
arrowstyle = isa(series[:arrow], Arrow) ? series[:arrow].style : :simple
gr_set_fillcolor(lc)
gr_polyline(x[rng], y[rng]; arrowside = arrowside, arrowstyle = arrowstyle)
end
end
end