complexplot; Arrow side; gr arrows
This commit is contained in:
parent
bf0f44773f
commit
75f1cf8cbb
@ -132,7 +132,7 @@ gr_set_textcolor(c) = GR.settextcolorind(gr_getcolorind(cycle(c,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; arrow=false)
|
||||
function gr_polyline(x, y, func = GR.polyline; arrowside=:none)
|
||||
iend = 0
|
||||
n = length(x)
|
||||
while iend < n-1
|
||||
@ -160,9 +160,12 @@ function gr_polyline(x, y, func = GR.polyline; arrow=false)
|
||||
# if we found a start and end, draw the line segment, otherwise we're done
|
||||
if istart > 0 && iend > 0
|
||||
func(x[istart:iend], y[istart:iend])
|
||||
if arrow
|
||||
if arrowside in (:head,:both)
|
||||
GR.drawarrow(x[iend-1], y[iend-1], x[iend], y[iend])
|
||||
end
|
||||
if arrowside in (:tail,:both)
|
||||
GR.drawarrow(x[2], y[2], x[1], y[1])
|
||||
end
|
||||
else
|
||||
break
|
||||
end
|
||||
@ -768,7 +771,8 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
||||
# draw the line(s)
|
||||
if st == :path
|
||||
gr_set_line(series[:linewidth], series[:linestyle], series[:linecolor]) #, series[:linealpha])
|
||||
gr_polyline(x, y; arrow = isa(series[:arrow], Arrow))
|
||||
arrowside = isa(series[:arrow], Arrow) ? series[:arrow].side : :none
|
||||
gr_polyline(x, y; arrowside = arrowside)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -463,19 +463,25 @@ Base.eltype{T}(vol::Volume{T}) = T
|
||||
# style is :open or :closed (for now)
|
||||
immutable Arrow
|
||||
style::Symbol
|
||||
side::Symbol # :head (default), :tail, or :both
|
||||
headlength::Float64
|
||||
headwidth::Float64
|
||||
end
|
||||
|
||||
function arrow(args...)
|
||||
style = :simple
|
||||
side = :head
|
||||
headlength = 0.3
|
||||
headwidth = 0.3
|
||||
setlength = false
|
||||
for arg in args
|
||||
T = typeof(arg)
|
||||
if T == Symbol
|
||||
style = arg
|
||||
if arg in (:head, :tail, :both)
|
||||
side = arg
|
||||
else
|
||||
style = arg
|
||||
end
|
||||
elseif T <: Number
|
||||
# first we apply to both, but if there's more, then only change width after the first number
|
||||
headwidth = Float64(arg)
|
||||
@ -489,7 +495,7 @@ function arrow(args...)
|
||||
warn("Skipped arrow arg $arg")
|
||||
end
|
||||
end
|
||||
Arrow(style, headlength, headwidth)
|
||||
Arrow(style, side, headlength, headwidth)
|
||||
end
|
||||
|
||||
|
||||
|
||||
@ -792,3 +792,14 @@ abline!(args...; kw...) = abline!(current(), args...; kw...)
|
||||
|
||||
@recipe f(::Type{Date}, dt::Date) = (dt -> convert(Int,dt), dt -> string(convert(Date,dt)))
|
||||
@recipe f(::Type{DateTime}, dt::DateTime) = (dt -> convert(Int,dt), dt -> string(convert(DateTime,dt)))
|
||||
|
||||
# -------------------------------------------------
|
||||
# Complex Numbers
|
||||
|
||||
@userplot ComplexPlot
|
||||
@recipe function f(cp::ComplexPlot)
|
||||
xguide --> "Real Part"
|
||||
yguide --> "Imaginary Part"
|
||||
linetype --> :scatter
|
||||
real(cp.args[1]), imag(cp.args[1])
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user