Skip to content

Commit

Permalink
Merge pull request #883 from tlnagy/pull-request/24f5d936
Browse files Browse the repository at this point in the history
add stronger typing to poetic plotting, fixes #882
  • Loading branch information
shashi committed Aug 25, 2016
2 parents 07e0c9f + 8804dde commit f3f9bda
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
21 changes: 6 additions & 15 deletions src/poetry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,7 @@
# Returns:
# A plot objects.
#
function plot{T <: Base.Callable}(fs::Vector{T}, a, b, elements::ElementOrFunction...; mapping...)
# Catch a common misuse of this function
if isa(b, ElementOrFunction)
error(
"""
Invalid plot usage:
plot(xs, ys, ...) should be plot(x=xs, y=ys, ...)
""")
end

function plot{T <: Base.Callable}(fs::Vector{T}, a::Number, b::Number, elements::ElementOrFunction...; mapping...)
if isempty(elements)
elements = ElementOrFunction[]
elseif isa(elements, Tuple)
Expand Down Expand Up @@ -55,13 +46,13 @@ end


# Plot a single function.
function plot(f::Function, a, b, elements::ElementOrFunction...; mapping...)
function plot(f::Function, a::Number, b::Number, elements::ElementOrFunction...; mapping...)
plot(Function[f], a, b, elements...; mapping...)
end


# Plot a single function using a contour plot
function plot(f::Function, xmin, xmax, ymin, ymax,
function plot(f::Function, xmin::Number, xmax::Number, ymin::Number, ymax::Number,
elements::ElementOrFunction...; mapping...)
default_elements = ElementOrFunction[]
element_types = Set(map(typeof, elements))
Expand All @@ -85,7 +76,7 @@ function plot(f::Function, xmin, xmax, ymin, ymax,
end


function layer(f::Function, xmin, xmax, ymin, ymax,
function layer(f::Function, xmin::Number, xmax::Number, ymin::Number, ymax::Number,
elements::ElementOrFunction...; mapping...)
if isempty(elements)
elements = ElementOrFunction[]
Expand All @@ -106,13 +97,13 @@ end


# Create a layer from a list of functions or expressions.
function layer(fs::Array, a, b, elements::ElementOrFunction...)
function layer(fs::Array, a::Number, b::Number, elements::ElementOrFunction...)
layer(y=fs, xmin=[a], xmax=[b], Stat.func, Geom.line, elements...)
end


# Create a layer from a single function.
function layer(f::Function, a, b, elements::ElementOrFunction...)
function layer(f::Function, a::Number, b::Number, elements::ElementOrFunction...)
layer([f], a, b, elements...)
end

Expand Down
8 changes: 8 additions & 0 deletions test/issue882.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Gadfly

# check that calling `plot` in the following format
# (::Array{Any,1}, ::Gadfly.#plot, ::Gadfly.Geom.#density,
# ::Gadfly.Guide.XLabel, ::Gadfly.Guide.YLabel)
# does not raise an ambiguity MethodError on Julia v0.5+
plot(x=1:10, y=1:10, color=1:10, Geom.density,
Guide.xlabel("foo"), Guide.ylabel("bar"))
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ tests = [
("coord_limits", 6inch, 6inch),
("rug", 6inch, 3inch),
("beeswarm", 6inch, 3inch),
("issue871", 6inch, 3inch)
("issue871", 6inch, 3inch),
("issue882", 6inch, 3inch)
]


Expand Down

0 comments on commit f3f9bda

Please sign in to comment.