davibarreira / Vizagrams.jl

Integrating diagramming and data visualization
https://davibarreira.github.io/Vizagrams.jl/
MIT License
39 stars 1 forks source link

Example from "First Data Vizualization" in docs throws an error #20

Closed non-Jedi closed 1 month ago

non-Jedi commented 1 month ago

Copy-pasting the first example shown in "First Data Vizualization" in the "Data Vizualizations Basics" tutorial throws an error.

Code pasted:

Random.seed!(4)
plt = plot(x=rand(10),y=rand(10))
# plt = S(:vectorEffect=>"none")plt
draw(plt,height=300)

Stack trace:

ERROR: AssertionError: Size must be a positive real number
Stacktrace:
  [1] TextGeom(text::String, pos::Vector{Float64}, fontsize::Float64, θ::Float64, fontfamily::String)
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/primitives/text.jl:8
  [2] ψ(s::Vizagrams.CovText)
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/primitives/text.jl:32
  [3] act(gs::Tuple{G, S}, x::Prim{TextGeom})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/primitives/graphical_primitives.jl:64
  [4] (::Vizagrams.var"#110#111"{Act{Vector{Prim}}})(y::Prim{TextGeom})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/diagram_tree.jl:10
  [5] iterate
    @ ./generator.jl:47 [inlined]
  [6] _collect(c::Vector{…}, itr::Base.Generator{…}, ::Base.EltypeUnknown, isz::Base.HasShape{…})
    @ Base ./array.jl:854
  [7] collect_similar
    @ ./array.jl:763 [inlined]
  [8] map
    @ ./abstractarray.jl:3285 [inlined]
  [9] alg(x::Act{Vector{Prim}})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/diagram_tree.jl:10
 [10] cata(alg::typeof(Vizagrams.alg), x::Vizagrams.FreeAct{Vector{Prim}})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/freemonad.jl:60
 [11] (::Vizagrams.var"#108#109"{typeof(Vizagrams.alg)})(y::Vizagrams.FreeAct{Vector{Prim}})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/freemonad.jl:60
 [12] fmap(f::Vizagrams.var"#108#109"{typeof(Vizagrams.alg)}, x::Comp{Vizagrams.FreeF})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/freemonad.jl:8
 [13] cata(alg::typeof(Vizagrams.alg), x::Vizagrams.FreeComp{Vector{Prim}})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/freemonad.jl:60
 [14] flatten(m::Tick)
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/mark_tree.jl:30
 [15] fmap(f::typeof(Vizagrams.flatten), x::Vizagrams.Pure{Mark})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/freemonad.jl:48
 [16] (::Vizagrams.var"#104#105"{typeof(Vizagrams.flatten)})(y::Vizagrams.Pure{Mark})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/freemonad.jl:49
 [17] fmap(f::Vizagrams.var"#104#105"{typeof(Vizagrams.flatten)}, x::Comp{Vizagrams.FreeF})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/freemonad.jl:8
 [18] fmap(f::Function, x::Vizagrams.FreeComp{Mark})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/freemonad.jl:49
--- the last 3 lines are repeated 1 more time ---
 [22] flatten(dm::Vizagrams.FreeComp{Mark})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/mark_tree.jl:35
 [23] envelope
    @ ~/.julia/packages/Vizagrams/gWrWE/src/trees/envelopes.jl:1 [inlined]
 [24] beside(d1::Vizagrams.FreeComp{Mark}, d2::Vizagrams.Pure{Mark}, v::Vector{Int64}; g::G, h::G)
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/operations.jl:46
 [25] ↓(d1::Vizagrams.FreeComp{Mark}, d2::Tuple{G, TextMark})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/operations.jl:86
 [26] ζ(axis::Axis)
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/marks/axes.jl:125
 [27] ζ(xaxis::XAxis)
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/marks/axes.jl:149
 [28] getmark(M::Type{Tick}, d::XAxis)
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/auxiliar/treemanipulation.jl:86
 [29] _broadcast_getindex_evalf
    @ ./broadcast.jl:709 [inlined]
 [30] _broadcast_getindex
    @ ./broadcast.jl:692 [inlined]
 [31] getindex
    @ ./broadcast.jl:636 [inlined]
 [32] copy
    @ ./broadcast.jl:942 [inlined]
 [33] materialize
    @ ./broadcast.jl:903 [inlined]
 [34] getmark(M::Type{Tick}, d::Vector{XAxis})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/auxiliar/treemanipulation.jl:87
 [35] (::Vizagrams.var"#376#377")(acc::Vector{XAxis}, s::Type)
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/auxiliar/treemanipulation.jl:95
 [36] BottomRF
    @ ./reduce.jl:86 [inlined]
 [37] _foldl_impl(op::Base.BottomRF{Vizagrams.var"#376#377"}, init::Vizagrams.FreeAct{Mark}, itr::Vector{DataType})
    @ Base ./reduce.jl:62
 [38] foldl_impl
    @ ./reduce.jl:48 [inlined]
 [39] mapfoldl_impl
    @ ./reduce.jl:44 [inlined]
 [40] mapfoldl
    @ ./reduce.jl:175 [inlined]
 [41] foldl
    @ ./reduce.jl:198 [inlined]
 [42] getmark(M::Vector{DataType}, d::Vizagrams.FreeAct{Mark})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/auxiliar/treemanipulation.jl:94
 [43] ζ(spec::PlotSpec)
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/marks/plotspec.jl:45
 [44] θ(m::PlotSpec)
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/mark_tree.jl:84
 [45] fmap(f::typeof(θ), x::Vizagrams.Pure{Mark})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/freemonad.jl:48
 [46] (::Vizagrams.var"#104#105"{typeof(θ)})(y::Vizagrams.Pure{Mark})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/freemonad.jl:49
 [47] fmap(f::Vizagrams.var"#104#105"{typeof(θ)}, x::Comp{Vizagrams.FreeF})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/freemonad.jl:8
 [48] fmap(f::Function, x::Vizagrams.FreeComp{Mark})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/freemonad.jl:49
 [49] θ(dm::Vizagrams.FreeComp{Mark})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/mark_tree.jl:81
 [50] θ(m::Plot)
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/mark_tree.jl:84
 [51] fmap(f::typeof(θ), x::Vizagrams.Pure{Mark})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/freemonad.jl:48
 [52] flatten(m::Plot)
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/mark_tree.jl:30
 [53] fmap(f::typeof(Vizagrams.flatten), x::Vizagrams.Pure{Mark})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/trees/freemonad.jl:48
 [54] flatten
    @ ~/.julia/packages/Vizagrams/gWrWE/src/trees/mark_tree.jl:35 [inlined]
 [55] boundingbox
    @ ~/.julia/packages/Vizagrams/gWrWE/src/trees/envelopes.jl:7 [inlined]
 [56] drawsvg(d::Vizagrams.Pure{Mark}; height::Int64, pad::Int64, width::Nothing, kwargs::@Kwargs{})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/backends/svgbackend.jl:372
 [57] drawsvg(p::Plot; height::Int64, pad::Int64, kwargs::@Kwargs{})
    @ Vizagrams ~/.julia/packages/Vizagrams/gWrWE/src/backends/svgbackend.jl:405
 [58] #draw#371
    @ ~/.julia/packages/Vizagrams/gWrWE/src/backends/draw.jl:17 [inlined]
Some type information was truncated. Use `show(err)` to see complete types.

Execution environment:

julia> versioninfo()
Julia Version 1.10.4
Commit 48d4fd48430 (2024-06-04 10:41 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 12 × Intel(R) Core(TM) i7-10810U CPU @ 1.10GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, skylake)
Threads: 1 default, 0 interactive, 1 GC (on 12 virtual cores)
Environment:
  JULIA_PKG_USE_CLI_GIT = true
  JULIA_PKG_SERVER =

(jl_dvWYce) pkg> st
Status `/tmp/jl_dvWYce/Project.toml`
  [a93c6f00] DataFrames v1.6.1
  [8c229dad] Vizagrams v0.1.1
  [9a3f8284] Random
  [10745b16] Statistics v1.10.0
davibarreira commented 1 month ago

Thanks for trying the package.

I'm having trouble replicating the error. I've done a clean install and ran the code, and it seems to be working. Also, the CI seems to be passing the tests.

Can you try doing other simpler operations, such as

d = Circle() + T(2,0)Circle()
draw(d)
davibarreira commented 1 month ago

The issue might be related to fonts, as the error seems to be that the TextGeom is returning a fontsize either negative or zero, which is not allowed.

non-Jedi commented 1 month ago

Hi Davi. Thanks for taking a look. I can confirm that the code you posted works just fine. I'll try working my way through the "Diagramming Basics" tutorial to see if I get any errors. I can also send you an --bug-report=rr recording if that would help?

davibarreira commented 1 month ago

Thanks, I think that might help. BTW, if you run:

plt = plot(x=rand(10),y=rand(10))
draw(plt)

using different random values. Does it always returns the same error?

Also, if you may. Try running the following:

plt = plot(
    config=(
        xaxis=(title="",),
        yaxis=(title="",),),
    x=rand(10),y=rand(10)
)
draw(plt)
davibarreira commented 1 month ago

I'm modifying the code in order to accept negative fontsize. This does not address your issue directly, but it is possible that after this your code will run without errors, but the final drawing might come out strange. Yet, this will help in the debugging.

non-Jedi commented 1 month ago

I'm modifying the code in order to accept negative fontsize. This does not address your issue directly, but it is possible that after this your code will run without errors, but the final drawing might come out strange. Yet, this will help in the debugging.

I've ]deved "Vizagrams", and the change just seems to give me a new error. Maybe it's progress? See below stacktrace:

julia> show(err)
1-element ExceptionStack:
NaN values are not allowed for HTML or SVG nodes: <text> x=NaN >
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] validateattr(ctx::Hyperscript.HTMLSVG, tag::SubString{String}, attr::Pair{String, Float64})
    @ Hyperscript ~/.julia/packages/Hyperscript/l66rR/src/Hyperscript.jl:296
  [3] (::Hyperscript.var"#2#5"{Pair{Symbol, Any}, Hyperscript.HTMLSVG, SubString{String}})(attr′::Pair{String, Float64})
    @ Hyperscript ./none:0
  [4] iterate
    @ ./generator.jl:47 [inlined]
  [5] iterate
    @ ./iterators.jl:1202 [inlined]
  [6] iterate
    @ ./iterators.jl:1196 [inlined]
  [7] Dict{String, Any}(kv::Base.Iterators.Flatten{Base.Generator{@Kwargs{x::Float64, y::Float64, transform::String, style::String}, Hyperscript.var"#3#4"{Hyperscript.HTMLSVG, SubString{String}}}})
    @ Base ./dict.jl:83
  [8] processattrs
    @ ~/.julia/packages/Hyperscript/l66rR/src/Hyperscript.jl:126 [inlined]
  [9] Hyperscript.Node(ctx::Hyperscript.HTMLSVG, tag::String, children::Tuple{String}, attrs::@Kwargs{x::Float64, y::Float64, transform::String, style::String})
    @ Hyperscript ~/.julia/packages/Hyperscript/l66rR/src/Hyperscript.jl:88
 [10] #m#18
    @ ~/.julia/packages/Hyperscript/l66rR/src/Hyperscript.jl:335 [inlined]
 [11] primtosvg(geom::TextGeom, s::S)
    @ Vizagrams ~/.julia/dev/Vizagrams/src/backends/svgbackend.jl:265
 [12] primtosvg
    @ ~/.julia/dev/Vizagrams/src/backends/svgbackend.jl:69 [inlined]
 [13] (::Vizagrams.var"#375#376")(p::Prim{TextGeom})
    @ Vizagrams ~/.julia/dev/Vizagrams/src/backends/svgbackend.jl:357
 [14] iterate
    @ ./generator.jl:47 [inlined]
 [15] collect_to!(dest::Vector{Hyperscript.Node{Hyperscript.HTMLSVG}}, itr::Base.Generator{Vector{Prim}, Vizagrams.var"#375#376"}, offs::Int64, st::Int64)
    @ Base ./array.jl:892
 [16] collect_to_with_first!(dest::Vector{Hyperscript.Node{Hyperscript.HTMLSVG}}, v1::Hyperscript.Node{Hyperscript.HTMLSVG}, itr::Base.Generator{Vector{Prim}, Vizagrams.var"#375#376"}, st::Int64)
    @ Base ./array.jl:870
 [17] _collect(c::Vector{Prim}, itr::Base.Generator{Vector{Prim}, Vizagrams.var"#375#376"}, ::Base.EltypeUnknown, isz::Base.HasShape{1})
    @ Base ./array.jl:864
 [18] collect_similar
    @ ./array.jl:763 [inlined]
 [19] map
    @ ./abstractarray.jl:3285 [inlined]
 [20] tosvg(dmark::Vizagrams.Pure{Mark}; height::Int64, width::Float64, kwargs::@Kwargs{viewBox::String, preserveAspectRatio::String})
    @ Vizagrams ~/.julia/dev/Vizagrams/src/backends/svgbackend.jl:356
 [21] drawsvg(d::Vizagrams.Pure{Mark}; height::Int64, pad::Int64, width::Nothing, kwargs::@Kwargs{})
    @ Vizagrams ~/.julia/dev/Vizagrams/src/backends/svgbackend.jl:393
 [22] drawsvg(p::Plot; height::Int64, pad::Int64, kwargs::@Kwargs{})
    @ Vizagrams ~/.julia/dev/Vizagrams/src/backends/svgbackend.jl:405
 [23] #draw#390
    @ ~/.julia/dev/Vizagrams/src/backends/draw.jl:17 [inlined]
 [24] top-level scope
    @ REPL[13]:1

using different random values. Does it always returns the same error?

I seem to get this new error no matter what I seed with or how I define x and y.

Also, if you may. Try running the following:

plt = plot(
    config=(
        xaxis=(title="",),
        yaxis=(title="",),),
    x=rand(10),y=rand(10)
)
draw(plt)

This gives the same error as the above.

non-Jedi commented 1 month ago

I'm working on getting you an rr trace, but I'm currently getting a (probably unrelated) strange error when attempting to save the trace.

I can also confirm that the package works as expected on these commands if I ssh into my server and execute them, so it's something funky about my local install. I would recommend not spending any more of your time investigating this until I've spent some more time confirming it's not some sort of strange user error on my part.

davibarreira commented 1 month ago

Ah, ok! Thanks for letting me know.

davibarreira commented 1 month ago

I'll close the issue for now. But if you think the problem is on the package, feel free to open it again.