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

[solved] error on draw: NaN values are not allowed for HTML or SVG nodes: ... #66

Closed
exaexa opened this issue Jan 13, 2025 · 29 comments · May be fixed by #68
Closed

[solved] error on draw: NaN values are not allowed for HTML or SVG nodes: ... #66

exaexa opened this issue Jan 13, 2025 · 29 comments · May be fixed by #68

Comments

@exaexa
Copy link
Contributor

exaexa commented Jan 13, 2025

Hi,

on one setup I got Vizagrams reporting the following error when trying to draw or savesvg:

ERROR: 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/packages/Vizagrams/mVsVF/src/backends/svgbackend.jl:267
 [12] primtosvg
    @ ~/.julia/packages/Vizagrams/mVsVF/src/backends/svgbackend.jl:71 [inlined]
 [13] (::Vizagrams.var"#369#370")(p::Prim{TextGeom})
    @ Vizagrams ~/.julia/packages/Vizagrams/mVsVF/src/backends/svgbackend.jl:419
 [14] iterate
    @ ./generator.jl:47 [inlined]
 [15] collect_to!(dest::Vector{Hyperscript.Node{Hyperscript.HTMLSVG}}, itr::Base.Generator{Vector{Prim}, Vizagrams.var"#369#370"}, 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"#369#370"}, st::Int64)
    @ Base ./array.jl:870
 [17] _collect(c::Vector{Prim}, itr::Base.Generator{Vector{Prim}, Vizagrams.var"#369#370"}, ::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/packages/Vizagrams/mVsVF/src/backends/svgbackend.jl:418
 [21] drawsvg(d::Vizagrams.Pure{Mark}; height::Int64, pad::Int64, width::Nothing, kwargs::@Kwargs{})
    @ Vizagrams ~/.julia/packages/Vizagrams/mVsVF/src/backends/svgbackend.jl:455
 [22] drawsvg(p::Plot; height::Int64, pad::Int64, kwargs::@Kwargs{})
    @ Vizagrams ~/.julia/packages/Vizagrams/mVsVF/src/backends/svgbackend.jl:467
 [23] drawsvg
    @ ~/.julia/packages/Vizagrams/mVsVF/src/backends/svgbackend.jl:464 [inlined]
 [24] #draw#384
    @ ~/.julia/packages/Vizagrams/mVsVF/src/backends/draw.jl:17 [inlined]
 [25] draw(d::Plot)
    @ Vizagrams ~/.julia/packages/Vizagrams/mVsVF/src/backends/draw.jl:11
 [26] top-level scope
    @ REPL[28]:1

The reproducer is literally the first (or any other) plotting example from here: https://davibarreira.github.io/Vizagrams.jl/dev/#Quickstart

My version info and packages are below:

julia> versioninfo()
Julia Version 1.10.2
Commit bd47eca2c8a (2024-03-01 10:14 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 16 × Intel(R) Core(TM) i7-10875H CPU @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, skylake)
Threads: 1 default, 0 interactive, 1 GC (on 16 virtual cores)
Environment:
  LD_LIBRARY_PATH = /opt/gurobi1103/linux64/lib

(@v1.10) pkg> st -m
Status `~/.julia/environments/v1.10/Manifest.toml`
  [a4c015fc] ANSIColoredPrinters v0.0.1
  [1520ce14] AbstractTrees v0.4.5
  [7d9f7c33] Accessors v0.1.41
  [66dad0bd] AliasTables v1.1.3
  [dce04be8] ArgCheck v2.4.0
  [c7e460c6] ArgParse v1.2.0
  [bf4720bc] AssetRegistry v0.1.0
⌅ [15f4f7f2] AutoHashEquals v0.2.0
  [67c07d97] Automa v1.1.0
  [198e06fe] BangBang v0.4.3
  [9718e550] Baselet v0.1.1
⌃ [6e4b80f9] BenchmarkTools v1.5.0
⌃ [12aac903] BinaryBuilder v0.5.8
⌃ [7f725544] BinaryBuilderBase v1.32.0
  [d1d4a3ce] BitFlags v0.1.9
  [e1450e63] BufferedStreams v1.2.2
  [fa961155] CEnum v0.5.0
⌃ [babc4406] COBREXA v1.5.1
  [00ebfdb7] CSTParser v3.4.3
⌃ [336ed68f] CSV v0.10.14
⌃ [523fee87] CodecBzip2 v0.8.4
  [944b1d66] CodecZlib v0.7.6
  [35d6a980] ColorSchemes v3.27.1
⌅ [3da002f7] ColorTypes v0.11.5
⌃ [c3611d14] ColorVectorSpace v0.10.0
⌅ [5ae59095] Colors v0.12.11
  [a80b9123] CommonMark v0.8.15
  [bbf7d656] CommonSubexpressions v0.3.1
  [34da2185] Compat v4.16.0
  [a33af91c] CompositionsBase v0.1.2
⌃ [f0e56b4a] ConcurrentUtilities v2.4.2
  [187b0558] ConstructionBase v1.5.8
  [150eb455] CoordinateTransformations v0.6.3
⌃ [a2441757] Coverage v1.6.0
  [c36e975a] CoverageTools v1.3.2
  [a8cc5b0e] Crayons v4.1.1
  [9a962f9c] DataAPI v1.16.0
  [a93c6f00] DataFrames v1.7.0
  [864edb3b] DataStructures v0.18.20
  [e2d170a0] DataValueInterfaces v1.0.0
  [e7dc6d0d] DataValues v0.4.13
  [244e2a9f] DefineSingletons v0.1.2
  [163ba53b] DiffResults v1.1.0
  [b552c78f] DiffRules v1.15.1
  [f6a0035f] DistributedData v0.2.0
  [ffbed154] DocStringExtensions v0.9.3
⌃ [e30172f5] Documenter v1.7.0
  [35a29f4d] DocumenterTools v0.1.20
  [497a8b3b] DoubleFloats v1.4.2
⌃ [460bff9d] ExceptionUnwrapping v0.1.10
  [e2ba6199] ExprTools v0.1.10
  [411431e0] Extents v0.1.5
⌃ [5789e2e9] FileIO v1.16.3
  [8fc22ac5] FilePaths v0.8.3
  [48062228] FilePathsBase v0.9.22
  [53c48c17] FixedPointNumbers v0.8.5
  [59287772] Formatting v0.4.3
⌃ [f6369f11] ForwardDiff v0.10.36
  [b38be410] FreeType v4.1.1
  [663a7486] FreeTypeAbstraction v0.10.6
⌃ [60bf3e95] GLPK v1.2.0
  [14197337] GenericLinearAlgebra v0.3.14
  [68eda718] GeoFormatTypes v0.4.3
  [cf35fbd7] GeoInterface v1.4.0
  [5c1252a2] GeometryBasics v0.5.1
  [d7ba0133] Git v1.3.1
  [8f6bce27] GitForge v0.4.2
  [bc5e4493] GitHub v5.9.0
  [c27321d9] Glob v1.3.1
  [42e2da0e] Grisu v1.0.2
⌃ [708ec375] Gumbo v0.8.2
⌅ [f67ccb44] HDF5 v0.16.16
⌃ [cd3eb016] HTTP v1.10.8
  [9fb69e20] Hiccup v0.2.2
  [6df8b67a] HistoricalStdlibVersions v2.0.0
  [47d2ed2b] Hyperscript v0.0.5
  [b5f81e59] IOCapture v0.2.5
  [615f187c] IfElse v0.1.1
  [22cec73e] InitialValues v0.3.1
  [842dd82b] InlineStrings v1.4.2
  [3587e190] InverseFunctions v0.1.17
  [41ab1584] InvertedIndices v1.3.1
  [92d709cd] IrrationalConstants v0.2.2
  [c8e1da08] IterTools v1.10.0
  [1c8ee90f] IterableTables v1.0.0
  [82899510] IteratorInterfaceExtensions v1.0.0
⌅ [033835bb] JLD2 v0.4.53
⌃ [692b3bcd] JLLWrappers v1.6.0
  [682c06a0] JSON v0.21.4
⌃ [0f8b85d8] JSON3 v1.14.0
⌃ [4076af6c] JuMP v1.23.2
⌃ [98e50ef6] JuliaFormatter v1.0.52
  [b964fa9f] LaTeXStrings v1.4.0
⌃ [0e77f7df] LazilyInitializedFields v1.2.2
⌃ [2ab3a3ac] LogExpFunctions v0.3.28
⌃ [e6f89c97] LoggingExtras v1.0.3
  [23992714] MAT v0.10.7
  [d8e11817] MLStyle v0.4.17
  [3da0fdf6] MPIPreferences v0.1.11
⌃ [1914dd2f] MacroTools v0.5.13
  [d0879d2d] MarkdownAST v0.1.2
⌃ [b8f27783] MathOptInterface v1.31.2
  [0a4f8689] MathTeXEngine v0.6.2
  [739be429] MbedTLS v1.1.9
  [c03570c3] Memoize v0.4.4
  [128add7d] MicroCollections v0.2.0
  [e1d29d7a] Missings v1.2.0
⌅ [78c3b35d] Mocking v0.7.9
  [ffc61752] Mustache v1.0.20
⌃ [d8a4904e] MutableArithmetics v1.5.0
  [a975b10e] Mux v1.0.2
⌃ [77ba4419] NaNMath v1.0.2
  [d9ec5142] NamedTupleTools v0.14.3
  [4d1e1d77] Nullables v1.0.0
⌃ [d8793406] ObjectFile v0.4.2
  [4d8831e6] OpenSSL v1.4.3
⌃ [bac558e1] OrderedCollections v1.6.3
  [6c11c7d4] OutputCollectors v0.1.1
  [69de0a69] Parsers v2.8.1
  [fa939f87] Pidfile v1.3.0
⌅ [3bbf5609] PikaParser v0.5.2
  [fc669557] PkgLicenses v0.2.0
  [f27b6e38] Polynomials v4.0.12
  [2dfb63ee] PooledArrays v1.4.3
  [aea7be01] PrecompileTools v1.2.1
  [21216c6a] Preferences v1.4.3
  [08abe8d2] PrettyTables v2.4.0
  [92933f4c] ProgressMeter v1.10.2
  [43287f4e] PtrArrays v1.2.1
  [be4d8f0f] Quadmath v0.5.10
  [94ee1d12] Quaternions v0.7.6
  [1a8c2f83] Query v1.0.0
  [2aef5ad7] QueryOperators v0.9.3
  [c1ae055f] RealDot v0.1.0
  [3cdcf5f2] RecipesBase v1.3.4
  [189a3867] Reexport v1.2.2
  [4418983a] Registrator v1.9.3
  [2792f1a3] RegistryInstances v0.1.0
  [d1eb7eb1] RegistryTools v2.3.0
  [05181044] RelocatableFolders v1.0.1
  [ae029012] Requires v1.3.0
  [6038ab10] Rotations v1.7.1
⌅ [e5567a89] SBML v1.4.4
  [fdea26ae] SIMD v3.7.1
  [322a6be2] Sass v0.2.0
  [6c6a2e73] Scratch v1.2.1
⌃ [91c51154] SentinelArrays v1.4.5
  [efcf1570] Setfield v1.1.1
  [992d4aef] Showoff v1.0.3
  [777ac1f9] SimpleBufferStream v1.2.0
  [2133526b] SodiumSeal v0.1.1
  [a2af1166] SortingAlgorithms v1.2.1
⌃ [276daf66] SpecialFunctions v2.4.0
  [171d559e] SplittablesBase v0.1.15
⌃ [860ef19b] StableRNGs v1.0.1
  [90137ffa] StaticArrays v1.9.10
  [1e83bf80] StaticArraysCore v1.4.3
  [82ae8749] StatsAPI v1.7.0
  [2913bbd2] StatsBase v0.34.4
  [892a3eda] StringManipulation v0.4.0
⌅ [09ab397b] StructArrays v0.6.18
  [53d494c1] StructIO v0.3.1
  [856f2bd8] StructTypes v1.11.0
⌃ [dc5dba14] TZJData v1.3.0+2024b
  [ab02a1b2] TableOperations v1.2.0
  [5e66a065] TableShowUtils v0.2.6
  [3783bdb8] TableTraits v1.0.1
  [382cd787] TableTraitsUtils v1.0.2
⌃ [bd369af6] Tables v1.11.1
  [62fd8b95] TensorCore v0.1.1
  [e0df1984] TextParse v1.0.2
  [b718987f] TextWrap v1.0.2
  [37f0c46e] TimeToLive v0.3.0
⌃ [f269a46b] TimeZones v1.18.1
  [0796e94c] Tokenize v0.5.29
  [3bb67fe8] TranscodingStreams v0.11.3
  [28d57a85] Transducers v0.4.84
  [5c2747f8] URIs v1.5.1
  [1cfade01] UnicodeFun v0.4.1
⌃ [1986cc42] Unitful v1.21.0
  [0ae4a718] VegaDatasets v2.1.1
  [8c229dad] Vizagrams v0.2.10
  [ea10d353] WeakRefStrings v1.4.2
  [76eceee3] WorkerUtilities v1.6.1
⌃ [c2297ded] ZMQ v1.3.0
  [1fd713ca] Attr_jll v2.5.2+0
⌃ [6e34b625] Bzip2_jll v1.0.8+1
  [83423d85] Cairo_jll v1.18.2+1
  [5ae413db] EarCut_jll v2.2.4+0
⌃ [2e619515] Expat_jll v2.6.2+0
⌃ [a3f928ae] Fontconfig_jll v2.13.96+0
  [d7e528f0] FreeType2_jll v2.13.3+1
  [559328eb] FriBidi_jll v1.0.16+0
⌃ [e8aa6df9] GLPK_jll v5.0.1+0
  [78b55507] Gettext_jll v0.21.0+0
⌃ [f8c6e375] Git_jll v2.46.2+0
  [7746bdde] Glib_jll v2.82.4+0
  [3b182d85] Graphite2_jll v1.3.14+1
  [528830af] Gumbo_jll v0.10.2+0
  [be1be57a] Gzip_jll v1.13.0+0
  [0234f1f7] HDF5_jll v1.14.3+3
  [2e76f6c2] HarfBuzz_jll v8.5.0+0
⌃ [e33a78d0] Hwloc_jll v2.11.2+0
⌃ [aacddb02] JpegTurbo_jll v3.1.0+2
⌃ [88015f11] LERC_jll v4.0.0+3
  [1d63c593] LLVMOpenMP_jll v18.1.7+0
⌃ [dd4b983a] LZO_jll v2.10.2+3
⌅ [e9f186c6] Libffi_jll v3.2.2+2
  [d4300ac3] Libgcrypt_jll v1.11.0+0
⌃ [7add5ba3] Libgpg_error_jll v1.51.0+2
⌃ [94ce4f54] Libiconv_jll v1.17.0+0
⌃ [4b2f31a3] Libmount_jll v2.40.2+2
  [925c91fb] Librsvg_jll v2.54.5+0
⌃ [89763e89] Libtiff_jll v4.7.0+0
⌃ [38a345b3] Libuuid_jll v2.40.2+2
  [7cb0a576] MPICH_jll v4.2.3+0
⌃ [f1f71cc9] MPItrampoline_jll v5.5.1+0
⌃ [9237b28f] MicrosoftMPI_jll v10.1.4+2
⌅ [fe0851c0] OpenMPI_jll v4.1.6+0
  [9bd350c2] OpenSSH_jll v9.9.1+1
⌃ [458c3c95] OpenSSL_jll v3.0.15+1
⌃ [efe28fd5] OpenSpecFun_jll v0.5.5+0
⌃ [36c8627f] Pango_jll v1.54.1+0
⌅ [30392449] Pixman_jll v0.43.4+0
  [bb12108a] SBML_jll v5.20.1+0
  [9b64493d] Tar_jll v1.35.0+0
⌃ [02c8fc9c] XML2_jll v2.13.3+0
  [aed1982a] XSLT_jll v1.1.42+0
⌃ [ffd25f8a] XZ_jll v5.4.6+0
  [4f6342f7] Xorg_libX11_jll v1.8.6+3
⌃ [0c0b7dd1] Xorg_libXau_jll v1.0.11+3
⌃ [a3789734] Xorg_libXdmcp_jll v1.1.4+3
  [1082639a] Xorg_libXext_jll v1.3.6+3
  [ea2f1a96] Xorg_libXrender_jll v0.9.11+1
⌃ [14d82f49] Xorg_libpthread_stubs_jll v0.1.1+3
  [c7cfdc94] Xorg_libxcb_jll v1.17.0+3
⌃ [c5fb5394] Xorg_xtrans_jll v1.5.0+3
⌃ [8f1865be] ZeroMQ_jll v4.3.5+0
⌃ [3161d3a3] Zstd_jll v1.5.6+1
  [da03df04] gdk_pixbuf_jll v2.42.12+0
⌅ [07c12ed4] ghr_jll v0.14.0+0
⌃ [477f73a3] libaec_jll v1.1.2+0
⌃ [b53b4c65] libpng_jll v1.6.44+2
  [47bcb7c8] libsass_jll v3.6.6+0
⌃ [a9144af2] libsodium_jll v1.0.20+1
  [1bc43ea1] pigz_jll v2.8.0+0
  [88f77b66] unzip_jll v6.0.2+0
  [0dad84c5] ArgTools v1.1.1
  [56f22d72] Artifacts
  [2a0f44e3] Base64
  [ade2ca70] Dates
  [8ba89e20] Distributed
  [f43a241f] Downloads v1.6.0
  [7b1f6079] FileWatching
  [9fa8497b] Future
  [b77e0a4c] InteractiveUtils
  [4af54fe1] LazyArtifacts
  [b27032c2] LibCURL v0.6.4
  [76f85450] LibGit2
  [8f399da3] Libdl
  [37e2e46d] LinearAlgebra
  [56ddb016] Logging
  [d6f4376e] Markdown
  [a63ad114] Mmap
  [ca575930] NetworkOptions v1.2.0
  [44cfe95a] Pkg v1.10.0
  [de0858da] Printf
  [9abbd945] Profile
  [3fa0cd96] REPL
  [9a3f8284] Random
  [ea8e919c] SHA v0.7.0
  [9e88b42a] Serialization
  [6462fe0b] Sockets
  [2f01184e] SparseArrays v1.10.0
  [10745b16] Statistics v1.10.0
  [fa267f1f] TOML v1.0.3
  [a4e569a6] Tar v1.10.0
  [8dfed614] Test
  [cf7118a7] UUIDs
  [4ec0a83e] Unicode
  [e66e0078] CompilerSupportLibraries_jll v1.1.0+0
  [781609d7] GMP_jll v6.2.1+6
  [deac9b47] LibCURL_jll v8.4.0+0
  [e37daf67] LibGit2_jll v1.6.4+0
  [29816b5a] LibSSH2_jll v1.11.0+1
  [c8ffd9c3] MbedTLS_jll v2.28.2+1
  [14a3606d] MozillaCACerts_jll v2023.1.10
  [4536629a] OpenBLAS_jll v0.3.23+4
  [05823500] OpenLibm_jll v0.8.1+2
  [efcefdf7] PCRE2_jll v10.42.0+1
  [bea87d4a] SuiteSparse_jll v7.2.1+1
  [83775a58] Zlib_jll v1.2.13+1
  [8e850b90] libblastrampoline_jll v5.8.0+1
  [8e850ede] nghttp2_jll v1.52.0+1
  [3f19e933] p7zip_jll v17.4.0+2

I was unfortunately unable to find anything usable to see where the issue comes from. If there is any debugging I can do please send commands to run/try.

Thank you!
-mk

@davibarreira
Copy link
Owner

davibarreira commented Jan 13, 2025

In this setup with Vizagrams, are other packages working? Your issues seems system related. Someone had a similar issue a while ago, but then the user said that the error was actually in his setup (which should be the case, since the package has CI/CD testing which is passing).

There is something you might try, which has been afflicting some users (me included). Which is updating the JLLWrappers package to version 1.7.0.
I don't think it is actually the error you are reporting, but it might be worth trying it out. Just update the JLLWrappers (or install the newest version if you don't already have it). Then, remove Vizagrams, update your environment, and reinstall Vizagrams.

I've just tested the package in a brand new LTS (1.10.7) Julia setup, and it worked once I've updated the JLLWrappers. BTW, my system is a Mac. Are you on Windows? Sometimes Windows is a bit clunky.

@exaexa
Copy link
Contributor Author

exaexa commented Jan 13, 2025

Hi, thanks for the response!

are other packages working?

As far as I can tell other packages are OK. Didn't try much other plotting packages (well, except for UnicodePlots which work, and Makie which has been failing here for some different reason (X11-related) since forever).

Which is updating the JLLWrappers package to version 1.7.0.

Ah ok, will try that (tomorrow). In case there's reports that this helps, could it be useful to have it bounded in actual package dependencies?

Are you on Windows?

haha nooo no no nope noooope I wouldn't touch that thing with a thirty-foot insulated pole

@davibarreira
Copy link
Owner

I've now tested the package using JuliaHub, and everything worked fine. My guess is something with your setup... Perhaps something related with packages versions. Did you try a clean setup to see if everything works? I mean, create a new folder, a new environment with Pkg.activate() and just install Vizagrams to see if it works.

@exaexa
Copy link
Contributor Author

exaexa commented Jan 13, 2025

OK I'm on another machine now, but the same error is happening in a clean environment, julia 1.11.1 and JLLWrappers 1.7.0. If it helps, the arch is: Linux (hostname) 6.12.6-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.6-1 (2024-12-21) x86_64 GNU/Linux.

@davibarreira
Copy link
Owner

davibarreira commented Jan 13, 2025

Are you running in a jupyter notebook or Pluto notebook? Or just VSCode? Could you check if other plotting packages work?

I'm not able to reproduce this error you are getting :/

Also, if you could perhaps share a screenshot with the code and the error.

@exaexa
Copy link
Contributor Author

exaexa commented Jan 14, 2025

Hi,
ok I managed to debug a bit, the issue seems to happen with text geoms. Weh I insert a bit of @info into primtosvg(::TextGeom) as follows

...
    posx = geom.pos[1]
    # posy = h - geom.pos[2]
    posy = geom.pos[2]

    @info "style" s
    sty, attr = split_style_attributes(s)
    @info "primtosvg(::TextGeom)" geom geom.text posx posy sty attr
    return m(
        "text",
        geom.text;
        x=posx,
...

I get:

┌ Info: style
└   s = S(Dict{Any, Any}(:fontFamily => "Helvetica", :textAnchor => :middle, :vectorEffect => "non-scaling-stroke", :fontSize => "NaNpt"))
┌ Info: primtosvg(::TextGeom)
│   geom = TextGeom("50", [NaN, NaN], NaN, NaN, "Helvetica")
│   geom.text = "50"
│   posx = NaN
│   posy = NaN
│   sty =
│    Dict{Any, Any} with 4 entries:
│      :fontFamily   => "Helvetica"
│      :textAnchor   => :middle
│      ⋮             => ⋮
└   attr = Dict{Any, Any}()

I somehow guess the NaNpt is the problem. I wasn't able to find where the NaN gets in actually (adding explicit fontsize all around the plot didn't help).

Any ideas on where to try next? :)

@exaexa
Copy link
Contributor Author

exaexa commented Jan 14, 2025

ah btw

Are you running in a jupyter notebook or Pluto notebook? Or just VSCode? Could you check if other plotting packages work?

no, bare terminal + julia repl. I suffered through Makie installation and it seems to be able to save a picture.

@davibarreira
Copy link
Owner

So is Makie working in your system? Using Vizagrams inside the terminal is probably not very useful, as it does not show the images...

I truly have no idea what is going on here. This "NaN" issue is very odd, and since I can't reproduce it, it is quite hard to investigate. I've tried installing a different Julia version on my machine, and I also ran a brand new server using JuliaHub. Both worked without issues.

If you had trouble installing Makie, this suggests to me that there is something going on with your machine and Julia in general, in other words, I don't think the issue is Vizagrams. In fact, the error message you posted suggested an error in the Hyperscript.jl package... but again, I don't think the issue is that package, but something in your setup.

My suggestion would be to investigate if Julia installation is properly done in your computer. Did you use JuliaUp or something else?

I'm sorry I can't be of much help.

@exaexa
Copy link
Contributor Author

exaexa commented Jan 14, 2025

Julia is straight from Julia downloads, it's a clean install and works basically with everything. Makie fails for me because of Cairo dependency that is borked.

About the NaNs in the Text geom:

  • are they supposed to be there?
  • if not, can you please point me to the part of the code which is supposed to fill these values properly?
  • I assume these thing might come from measuring the text sizes, which needs a system font library, which might be the borked one, does that sound plausible?

Thanks!

@exaexa
Copy link
Contributor Author

exaexa commented Jan 14, 2025

btw

Using Vizagrams inside the terminal is probably not very useful

I want this to generate pictures for Literate documents via CI, so it's always going to be drawsvg() and saving to a file. I guess the bare terminal is closest to that.

@davibarreira
Copy link
Owner

Julia is straight from Julia downloads, it's a clean install and works basically with everything. Makie fails for me because of Cairo dependency that is borked.

About the NaNs in the Text geom:

  • are they supposed to be there?
  • if not, can you please point me to the part of the code which is supposed to fill these values properly?
  • I assume these thing might come from measuring the text sizes, which needs a system font library, which might be the borked one, does that sound plausible?

Thanks!

I see. Indeed, this is a possibility. But does simple diagrams without text work? I mean

d = Circle()
draw(d)

If this works, and only the TextGeom is failing, then yes, there is a high chance that the issue is with fonts, which is a pain to deal with. But if that is the case, I can try to figure out what might be going on in your case. It would be nice to see if other packages that deal with fonts are working, perhaps try Plots.jl.

BTW, you can just use draw instead of drawsvg.

@exaexa
Copy link
Contributor Author

exaexa commented Jan 14, 2025

But does simple diagrams without text work?

yes that works perfectly (I noted that above but not very strongly I see :) )

EDIT: I noted that super implicitly, sorry. 😁

@exaexa
Copy link
Contributor Author

exaexa commented Jan 14, 2025

OK I realized I could just run Vizagrams test suite and it looks to point at the precise issue. Looks like it's FreeType issue and it kills envelopes.

I think it fails loading or rendering the bundled helvetica. Will let you know asap.

(On a related note you might want to avoid bundling actual helvetica TTF. Neglecting the possible copyright issues (Julia General might not be happy here), there's TeXGyreHeros which is much better for almost all concievable purposes, and the license is much more friendly there.)

@davibarreira
Copy link
Owner

Oh, thanks for pointing it. I did not know. I'll make the switch.

@exaexa
Copy link
Contributor Author

exaexa commented Jan 14, 2025

Test log here:
test.log

@exaexa
Copy link
Contributor Author

exaexa commented Jan 14, 2025

Oh, thanks for pointing it. I did not know. I'll make the switch.

I think there's (or should be!) a julia package already which bundles the TexGyre fonts, possibly best to defer to that.

@exaexa
Copy link
Contributor Author

exaexa commented Jan 14, 2025

Just for the record, culprit is:

julia> TextGeom(fontsize=15, text="hello")
TextGeom("hello", [0, 0], 15, 0, "Helvetica")

julia> envelope(TextGeom(fontsize=15, text="hello"), S(), [1,0])
NaN

@davibarreira
Copy link
Owner

The envelope requires the font... Now the missing point is why FreeType is not working in your setup.

@exaexa
Copy link
Contributor Author

exaexa commented Jan 14, 2025

OK so in the end it's the fonts. For whatever reason this happens:

julia> face = FreeTypeAbstraction.findfont("helvetica")
FTFont (family = Helvetica, style = Regular)

julia> FreeTypeAbstraction.get_extent(face, 'a')
FreeTypeAbstraction.FontExtent{Float32}(Float32[-Inf, Inf], Float32[NaN, Inf], Float32[Inf, Inf], Float32[Inf, Inf])

julia> face = FreeTypeAbstraction.findfont("TeXGyreHeros")
FTFont (family = TeXGyreHeros, style = Regular)

julia> FreeTypeAbstraction.get_extent(face, 'a')
FreeTypeAbstraction.FontExtent{Float32}(Float32[0.0, 0.0], Float32[0.042, 0.539], Float32[0.556, 0.0], Float32[0.493, 0.554])

what's kinda weird is that I don't have any actual helvetica.ttf on my system so I have no clue where it takes the helvetica from.

Fixing the default name to TeXGyreHeros seems to solve the issue.

@exaexa
Copy link
Contributor Author

exaexa commented Jan 14, 2025

(the actual problem here is that the findfont doesn't fail although it gives an unusable font. It seems to fail on other nonsense font names, just not on helvetica, for whatever weird reason. I assume fontconfig problems.

Is there any way to extract some information on "where it actually found the font" from the font_face structure that comes from findfont?

@exaexa
Copy link
Contributor Author

exaexa commented Jan 14, 2025

ok the culprit is fontconfig, which aliases helvetica to something that FreeType seems to be able to load but never actually gets a working glyph from. I assume this will happen wildly on linux and BSD machines given the general practice with fontconfig nowadays. Mine is on debian testing but the same might get very easily also get inherited into Ubuntu and Mint.

If possible, can we:

  • change the default to the freeer, better and unicode-er TeXGyre fonts?
  • put some tiny runtime assert into the envelope implementation that fails with a comprehensible error message in case it looks like NaN is getting produced? This would IMO almost always be a missing glyph.

Thanks!

@davibarreira
Copy link
Owner

Sounds good. Glad you figured out the issue.

@davibarreira
Copy link
Owner

I see you started to work on some PRs. There are some things I must point though.
The NaN envelope is not incorrect, it is actually how envelopes are designed.

The issue is actually that for some reason findfont is not finding the correct font in your system, and is returning gibberish. When a font is not found, it should default to the one in assets.

I'm trying to figure out if your issue is actually related to FreeFontType.jl and not to Vizagrams. But anyways, I'll try to write a function to try to catch the error you are facing.

@exaexa
Copy link
Contributor Author

exaexa commented Jan 14, 2025

OK, re the PRs please feel free to close if the correct solution is different, these were just things that I applied to get it working here.

Regarding the fontage, I think it actually managed to open some fixed-size bitmap helvetica-like font which Xft by default uses as a replacement for helvetica (wonders of having to support legacy apps! :)). Metrics of these are wild. So maybe it might be sufficient to somehow tell the font finder that we only want actual vector ones that have sensible metrics.

OTOH I'd say that whenever there's a NaN coming from the metrics when we actually need the dimension, the plotting is basically doomed, no? (except if we have some super simple case where sizing of stuff does provably not depend on the font sizing)

@davibarreira
Copy link
Owner

davibarreira commented Jan 14, 2025

Thanks for the effort on the PRs! I think I do agree with changing Helvetica.
The fontfinder is totally handled by FreeTypeAbstraction.jl. I must admit I do not understand how fonts are handled.

I just checked, and envelope should return either a real value or Nothing, not NaN (I was thinking of NaN as Nothing, but they are distinct). So there is something funky going on with the function itself in the case of text, probably these crazy metric you mentioned are throwing off the calculations.

@exaexa
Copy link
Contributor Author

exaexa commented Jan 15, 2025

I must admit I do not understand how fonts are handled.

Ah well that makes you a much happier person tbh. 🤣

Re the actual origin of the NaN, it might be here:

https://github.com/JuliaGraphics/FreeTypeAbstraction.jl/blob/master/src/types.jl#L84

...as called from:

https://github.com/JuliaGraphics/FreeTypeAbstraction.jl/blob/master/src/types.jl#L233

Pixel/bitmap fonts are AFAIK not required to have these metrics at all, so we're likely ending up with 0/0 here.

I think this settles the issue but still I'd love to have some helpful fix in place; at least the comprehensible error message from #67 if possible. :)

@exaexa
Copy link
Contributor Author

exaexa commented Jan 15, 2025

Solved for me and hopefully for various others by #69 . The rest of ideas lives in the other 2 PRs

@exaexa exaexa closed this as completed Jan 15, 2025
@exaexa exaexa changed the title error on draw: NaN values are not allowed for HTML or SVG nodes: ... [solved] error on draw: NaN values are not allowed for HTML or SVG nodes: ... Jan 19, 2025
@exaexa
Copy link
Contributor Author

exaexa commented Jan 19, 2025

Just for completeness, adding a possible quick and reasonably-correct solution:

The offending fonts are bitmap fonts and bitmap Helvetica that sometimes (often) gets installed with Debian, Ubuntus and Mints. The packages are:

  • xfonts-100dpi
  • xfonts-75dpi

Removing them has no big effect in most systems (unless you use very legacy software) and works this issue around.

@davibarreira
Copy link
Owner

Thanks, @exaexa!

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