diff --git a/src/backends/gr.jl b/src/backends/gr.jl index c4618b43..87165997 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -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 diff --git a/src/components.jl b/src/components.jl index 952a13dc..49dbf949 100644 --- a/src/components.jl +++ b/src/components.jl @@ -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 diff --git a/src/recipes.jl b/src/recipes.jl index 6a5cc4c7..8ba9389f 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -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