Skip to content

Commit

Permalink
Merge pull request #1331 from laborg/scalefix_1330
Browse files Browse the repository at this point in the history
Fix #1330 handle closures with special scaling
  • Loading branch information
bjarthur authored Oct 20, 2019
2 parents 0f9e999 + 51da94c commit dd9c49d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/scale.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ const slope_continuous = continuous_scale_partial([:slope], identity_transform)
alpha_continuous[(; minvalue=0.0, maxvalue=1.0, labels=nothing,
format=nothing, minticks=2, maxticks=10, scalable=true)]
Rescale the data values between `minvalue` and `maxvalue` to opacity (alpha) values between 0 and 1.
Rescale the data values between `minvalue` and `maxvalue` to opacity (alpha) values between 0 and 1.
"""
alpha_continuous(; minvalue=0.0, maxvalue=1.0, labels=nothing, format=nothing, minticks=2, maxticks=10, scalable=true) =
ContinuousScale([:alpha], identity_transform, minvalue=minvalue, maxvalue=maxvalue,
Expand All @@ -192,7 +192,7 @@ function apply_scale(scale::ContinuousScale,
# special case for function arrays bound to :y
# pass the function values through and wait for the scale to
# be reapplied by Stat.func
if var == :y && eltype(vals) == Function
if var == :y && eltype(vals) <: Function
aes.y = vals
continue
end
Expand Down Expand Up @@ -325,7 +325,7 @@ anything in the data that's not respresented in `levels` will be set to
`missing`. `order` is a vector of integers giving a permutation of the levels
default order.
See also [`group_discrete`](@ref), [`shape_discrete`](@ref),
See also [`group_discrete`](@ref), [`shape_discrete`](@ref),
[`size_discrete`](@ref), [`linestyle_discrete`](@ref), and [`alpha_discrete`](@ref).
"""

Expand Down Expand Up @@ -479,13 +479,13 @@ Gadfly.Scale.DiscreteColorScale(Gadfly.Scale.default_discrete_colors, nothing, n
julia> x.f(3)
3-element Array{ColorTypes.Color,1}:
LCHab{Float32}(70.0,60.0,240.0)
LCHab{Float32}(80.0,70.0,100.435)
LCHab{Float32}(70.0,60.0,240.0)
LCHab{Float32}(80.0,70.0,100.435)
LCHab{Float32}(65.8994,62.2146,353.998)
```
"""
color_discrete_hue(f=default_discrete_colors;
levels=nothing, order=nothing, preserve_order=true) =
levels=nothing, order=nothing, preserve_order=true) =
DiscreteColorScale(f, levels=levels, order=order, preserve_order=preserve_order)

@deprecate discrete_color_hue(; levels=nothing, order=nothing, preserve_order=true) color_discrete_hue(; levels=levels, order=order, preserve_order=preserve_order)
Expand Down Expand Up @@ -712,7 +712,7 @@ const label = LabelScale
xgroup[(; labels=nothing, levels=nothing, order=nothing)]
A discrete scale for use with [`Geom.subplot_grid`](@ref Gadfly.Geom.subplot_grid).
"""
"""
xgroup(; labels=nothing, levels=nothing, order=nothing) =
DiscreteScale([:xgroup], labels=labels, levels=levels, order=order)

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

set_default_plot_size(6inch, 3inch)

closure(a) = [x -> a[i]*x for i in 1:length(a)]
plot(closure(1:2), 0, 2π, Scale.y_log10())

0 comments on commit dd9c49d

Please sign in to comment.