Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The function apply_statistic_typed doesn't handle type Measure #1357

Closed
CiaranOMara opened this issue Nov 28, 2019 · 3 comments · Fixed by #1358
Closed

The function apply_statistic_typed doesn't handle type Measure #1357

CiaranOMara opened this issue Nov 28, 2019 · 3 comments · Fixed by #1358

Comments

@CiaranOMara
Copy link
Contributor

I've been using the new {h,v}band geometry at the head of the master branch for a day or so and have found that it errors in the presence of other geometries that use either xmin, xmax or ymin, ymax.

Below is an MWE and the error produced.

(v1.2) pkg> st Gadfly
    Status `~/.julia/environments/v1.2/Project.toml`
  [5ae59095] Colors v0.9.6
  [a81c6b42] Compose v0.7.4 #master (https://github.com/GiovineItalia/Compose.jl.git)
  [c91e804a] Gadfly v1.1.0 #master (https://github.com/GiovineItalia/Gadfly.jl)
  [c8e1da08] IterTools v1.3.0
  [e5e0dc1b] Juno v0.7.2

julia> using Gadfly
[ Info: Recompiling stale cache file /Users/username/.julia/compiled/v1.2/Gadfly/DvECm.ji for Gadfly [c91e804a-d5a3-530f-b6f0-dfbca275c004]

julia> plot(
           layer(Geom.band, xmin=[.25], xmax=[.75], Theme(default_color="red")),
           layer(Geom.rect, xmin=[0], xmax=[1], ymin=[0], ymax=[1], Theme(default_color="blue"))
       )
Error showing value of type Plot:
ERROR: MethodError: no method matching isfinite(::Measures.Length{:h,Float64})
Closest candidates are:
  isfinite(::BigFloat) at mpfr.jl:889
  isfinite(::Missing) at missing.jl:79
  isfinite(::Float16) at float.jl:548
  ...
Stacktrace:
 [1] apply_statistic_typed(::Measures.Length{:h,Float64}, ::Measures.Length{:h,Float64}, ::Array{Any,1}, ::Array{Nothing,1}, ::Array{Nothing,1}) at /Users/username/.julia/packages/Gadfly/VCJo4/src/statistics.jl:984
 [2] apply_statistic(::Gadfly.Stat.TickStatistic, ::Dict{Symbol,Gadfly.ScaleElement}, ::Gadfly.Coord.Cartesian, ::Gadfly.Aesthetics) at /Users/username/.julia/packages/Gadfly/VCJo4/src/statistics.jl:847
 [3] apply_statistics(::Array{Gadfly.StatisticElement,1}, ::Dict{Symbol,Gadfly.ScaleElement}, ::Gadfly.Coord.Cartesian, ::Gadfly.Aesthetics) at /Users/username/.julia/packages/Gadfly/VCJo4/src/statistics.jl:32
 [4] render_prepare(::Plot) at /Users/username/.julia/packages/Gadfly/VCJo4/src/Gadfly.jl:702
 [5] render(::Plot) at /Users/username/.julia/packages/Gadfly/VCJo4/src/Gadfly.jl:753
 [6] draw at /Users/username/.julia/packages/Gadfly/VCJo4/src/Gadfly.jl:862 [inlined]
 [7] display(::Gadfly.GadflyDisplay, ::MIME{Symbol("text/html")}, ::Plot) at /Users/username/.julia/packages/Gadfly/VCJo4/src/Gadfly.jl:1067
 [8] display(::Gadfly.GadflyDisplay, ::String, ::Any) at ./multimedia.jl:214
 [9] display(::Gadfly.GadflyDisplay, ::Plot) at /Users/username/.julia/packages/Gadfly/VCJo4/src/Gadfly.jl:1024
 [10] display(::Any) at ./multimedia.jl:323
 [11] #invokelatest#1 at ./essentials.jl:790 [inlined]
 [12] invokelatest at ./essentials.jl:789 [inlined]
 [13] print_response(::IO, ::Any, ::Bool, ::Bool, ::Any) at /Users/sabae/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.2/REPL/src/REPL.jl:156
 [14] print_response(::REPL.AbstractREPL, ::Any, ::Bool, ::Bool) at /Users/sabae/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.2/REPL/src/REPL.jl:141
 [15] (::getfield(REPL, Symbol("#do_respond#38")){Bool,getfield(REPL, Symbol("##48#57")){REPL.LineEditREPL,REPL.REPLHistoryProvider},REPL.LineEditREPL,REPL.LineEdit.Prompt})(::Any, ::Any, ::Any) at /Users/sabae/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.2/REPL/src/REPL.jl:718
 [16] #invokelatest#1 at ./essentials.jl:790 [inlined]
 [17] invokelatest at ./essentials.jl:789 [inlined]
 [18] run_interface(::REPL.Terminals.TextTerminal, ::REPL.LineEdit.ModalInterface, ::REPL.LineEdit.MIState) at /Users/sabae/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.2/REPL/src/LineEdit.jl:2306
 [19] run_frontend(::REPL.LineEditREPL, ::REPL.REPLBackendRef) at /Users/sabae/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.2/REPL/src/REPL.jl:1038
 [20] run_repl(::REPL.AbstractREPL, ::Any) at /Users/sabae/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.2/REPL/src/REPL.jl:201
 [21] (::getfield(Base, Symbol("##737#739")){Bool,Bool,Bool,Bool})(::Module) at ./client.jl:390
 [22] #invokelatest#1 at ./essentials.jl:790 [inlined]
 [23] invokelatest at ./essentials.jl:789 [inlined]
 [24] run_main_repl(::Bool, ::Bool, ::Bool, ::Bool, ::Bool) at ./client.jl:374
 [25] exec_options(::Base.JLOptions) at ./client.jl:312
 [26] _start() at ./client.jl:464

julia> 

I had opened a PR with a hotfix (#1356).

@Mattriks
Copy link
Member

See my #1356 (comment). I'd like to first see a design outline that answers the q "what should happen to an aesthetic with type Measure in Stat.TickStatistic?"

@Mattriks
Copy link
Member

Here's my (part) solution for this issue:

using Compose
using Compose.Measures

# extends an existing function in Measures.jl
isabsolute(::Type{Length{U, T}}) where {U,T} = !in([:w,:h]).(U)

# In Gadfly, another function is also needed here for swapped a, b
function cat_aes_var!(a::AbstractVector{T}, b::AbstractVector{U}) where {T<:Measure, U}
    isabsolute(T) ? [a..., b...] : b
end

This says that relative Measure types are not useful for determining the aesthetic ranges (and tickmarks), and hence are not passed to the plot_aes. This won't affect the layer_aess.

Examples:

# Relative Measure type
julia> cat_aes_var!([0.2,0.7].*w, rand(2))   
2-element Array{Float64,1}:
 0.2125510201773233
 0.6520227057327439   

But absolute Measure types can be passed to the plot_aes for further processing:

julia> cat_aes_var!([1:2;].*mm, rand(2))  
4-element Array{Any,1}:
  1.0mm            
  2.0mm            
 0.6705462198009864
 0.815355870966787 

This will require PRs to both Measures.jl and Gadfly. I'll probably need to make some changes in apply_statistic(TickStatistic) too. I'll submit the PRs sometime soon.

@Mattriks Mattriks mentioned this issue Nov 29, 2019
4 tasks
@Mattriks
Copy link
Member

Mattriks commented Dec 1, 2019

Another apply_statistic_typed error example:

julia> plot(x=[2,4], y=[2,4], size=[1.4142], color=[colorant"gold"])

TypeError: in typeassert, expected Int64, got Float64

Stacktrace:
 [1] minvalmaxval(::Int64, ::Int64, ::Int64, ::Float64, ::Nothing) at C:\Users\mjf\.julia\dev\Gadfly\src\statistics.jl:1004
 [2] apply_statistic_typed(::Int64, ::Int64, ::Array{Int64,1}, ::Array{Float64,1}, ::Array{Nothing,1}) at C:\Users\mjf\.julia\dev\Gadfly\src\statistics.jl:989

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants