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

using Gadfly causes Method error in AlgebraOfGraphics.draw() #215

Closed
jonasjonker opened this issue Jun 21, 2021 · 2 comments
Closed

using Gadfly causes Method error in AlgebraOfGraphics.draw() #215

jonasjonker opened this issue Jun 21, 2021 · 2 comments

Comments

@jonasjonker
Copy link

jonasjonker commented Jun 21, 2021

I'm not really sure if this is a Gadfly.jl/Compose.jl or a AlgebraOfGraphics.jl issue so I thought I make an issue at both repos. here

I was making a notebook with plots from multiple packages (to compare them) when I found that using Gadfly introduces an error when calling AlgebraOfGraphics.draw(). The error message mentions some Compose.jl object, but the draw method I call and the AlgebraOfGraphics.Layer I call it on don't seem to be directly affected.

this works fine

julia> using AlgebraOfGraphics, RDatasets, CairoMakie

julia> const AoG = AlgebraOfGraphics

julia> iris = dataset("datasets", "iris")

julia> iris_frequency = AoG.data(iris) *
           AoG.mapping(:PetalLength, :PetalWidth) *
           AoG.mapping(color = :Species)

julia> fg1 = AoG.draw(iris_frequency)

julia> save("figure.png", fg1, px_per_unit = 3)

but using Gadfly introduces an error

julia> using Gadfly

# now throws an error
julia> fg2 = AoG.draw(iris_frequency)
ERROR: MethodError: no method matching size(::Compose.Property{Compose.FillPrimitive})
Closest candidates are:
  size(::Union{LinearAlgebra.QR, LinearAlgebra.QRCompactWY, LinearAlgebra.QRPivoted}) at /opt/julia/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/qr.jl:524
  size(::Union{LinearAlgebra.QR, LinearAlgebra.QRCompactWY, LinearAlgebra.QRPivoted}, ::Integer) at /opt/julia/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/qr.jl:523
  size(::Union{LinearAlgebra.Cholesky, LinearAlgebra.CholeskyPivoted}) at /opt/julia/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/cholesky.jl:442
  ...
Stacktrace:
  [1] axes
    @ ./abstractarray.jl:89 [inlined]
  [2] combine_axes(::Compose.Property{Compose.FillPrimitive}, ::Compose.Property{Compose.FillPrimitive}, ::Compose.Property{Compose.FillPrimitive})
    @ Base.Broadcast ./broadcast.jl:483
  [3] shape(x::AlgebraOfGraphics.Layer)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/4qspg/src/algebra/processing.jl:17
  [4] getlabeledarray(layer::AlgebraOfGraphics.Layer, s::Symbol)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/4qspg/src/algebra/processing.jl:72
  [5] (::AlgebraOfGraphics.var"#119#121"{Tuple{Symbol, Symbol}, AlgebraOfGraphics.Layer, Dict{Union{Int64, Symbol}, Any}})(key::Int64)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/4qspg/src/algebra/processing.jl:100
  [6] ntuple
    @ ./ntuple.jl:19 [inlined]
  [7] mapkeys
    @ ~/.julia/packages/AlgebraOfGraphics/4qspg/src/entries.jl:75 [inlined]
  [8] (::AlgebraOfGraphics.var"#118#120"{AlgebraOfGraphics.Layer, Dict{Union{Int64, Symbol}, Any}})(tup::Tuple{Symbol, Symbol})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/4qspg/src/algebra/processing.jl:99
  [9] map
    @ ./tuple.jl:214 [inlined]
 [10] process_mappings(layer::AlgebraOfGraphics.Layer)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/4qspg/src/algebra/processing.jl:98
 [11] to_entry(layer::AlgebraOfGraphics.Layer)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/4qspg/src/algebra/processing.jl:115
 [12] process(layer::AlgebraOfGraphics.Layer)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/4qspg/src/algebra/processing.jl:122
 [13] iterate
    @ ./generator.jl:47 [inlined]
 [14] collect(itr::Base.Generator{AlgebraOfGraphics.Layers, typeof(AlgebraOfGraphics.process)})
    @ Base ./array.jl:678
 [15] map
    @ ./abstractarray.jl:2323 [inlined]
 [16] compute_axes_grid(fig::Figure, s::AlgebraOfGraphics.Layer; axis::NamedTuple{(), Tuple{}}, palettes::NamedTuple{(), Tuple{}})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/4qspg/src/algebra/layers.jl:70
 [17] plot!(fig::Figure, s::AlgebraOfGraphics.Layer; axis::NamedTuple{(), Tuple{}}, palettes::NamedTuple{(), Tuple{}})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/4qspg/src/algebra/layers.jl:135
 [18] #plot#91
    @ ~/.julia/packages/AlgebraOfGraphics/4qspg/src/algebra/layers.jl:143 [inlined]
 [19] draw(s::AlgebraOfGraphics.Layer; axis::NamedTuple{(), Tuple{}}, figure::NamedTuple{(), Tuple{}}, palettes::NamedTuple{(), Tuple{}})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/4qspg/src/algebra/layers.jl:150
 [20] draw(s::AlgebraOfGraphics.Layer)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/4qspg/src/algebra/layers.jl:150
 [21] top-level scope
    @ REPL[14]:1

I checked that the following returns the same before and after using Gadfly:

julia> typeof(iris_frequency)
AlgebraOfGraphics.Layer

help?> AoG.draw
  No documentation found.

  AlgebraOfGraphics.draw is a Function.

  # 1 method for generic function "draw":
  [1] draw(s::Union{AlgebraOfGraphics.Layer, AlgebraOfGraphics.Layers}; axis, figure, palettes) in AlgebraOfGraphics at /home/me/.julia/packages/AlgebraOfGraphics/4qspg/src/algebra/layers.jl:148
(juliaplotting) pkg> status
      Status `~/Repos/juliaplotting/Project.toml`
  [cbdf2221] AlgebraOfGraphics v0.4.5
  [13f3f980] CairoMakie v0.5.10
  ...
  [c91e804a] Gadfly v1.3.3
  ...
  [ce6b1742] RDatasets v0.7.5
@knuesel
Copy link
Contributor

knuesel commented Jun 22, 2021

A fine example of type piracy :)

It happens here: https://github.com/JuliaPlots/AlgebraOfGraphics.jl/blob/a07775fbc970555addae664cf983e0c14951ff20/src/algebra/processing.jl#L16

Afer loading Gadfly we get the following:

julia> arrays = map(var -> var isa AoG.ArrayLike ? var : fill(nothing), (:PetalLength, :PetalWidth))
(Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]))

because

julia> fill(nothing)
Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))])

because

julia> @less fill(nothing)
# Shows the following in Compose/5GmGj/src/property.jl:
fill(c::Nothing) = Fill([FillPrimitive(RGBA{Float64}(0.0, 0.0, 0.0, 0.0))])

So it's a bug in Compose.jl.

@piever
Copy link
Collaborator

piever commented Jun 22, 2021

Thanks for investigating! Closing here because this needs to be fixed on the Compose side.

@piever piever closed this as completed Jun 22, 2021
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

No branches or pull requests

3 participants