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

Error: CanvasRenderer is missing a valid canvas or context #383

Closed
John-Boik opened this issue Apr 12, 2021 · 7 comments
Closed

Error: CanvasRenderer is missing a valid canvas or context #383

John-Boik opened this issue Apr 12, 2021 · 7 comments

Comments

@John-Boik
Copy link

I'm new to VegaLite and trying to use it to plot a histogram of datetimes. I have a dataframe, df2, that has a column "time" containing datetimes. I want to save the figure as a png. I'm using REPL in a command window on linux, and calling my Julia script using include(scriptname.jl). In the script, a module, I import VegaLite. When I try to save as a png file I get the error: CanvasRenderer is missing a valid canvas or context.
I have installed Canvas.jl, and am using Julia Version 1.5.3 with a new install of VegaLite.
Any ideas why I get this error, and how I can produce a png file?
I call:
df2 |> VegaLite.@vlplot(:bar, x="yearmonthdate(time):o", y="count()") |> VegaLite.save("hist_start_day.png")
Then I receive the error:

Error: CanvasRenderer is missing a valid canvas or context
    at Object.error (/home/jboik/.julia/artifacts/ead9a31a77872dcae4f9a0e110ddb2281812b6b0/node_modules/vega-scenegraph/node_modules/vega-util/build/vega-util.js:39:11)
    at CanvasRenderer.resize (/home/jboik/.julia/artifacts/ead9a31a77872dcae4f9a0e110ddb2281812b6b0/node_modules/vega-scenegraph/build/vega-scenegraph.js:3633:28)
    at CanvasRenderer.initialize (/home/jboik/.julia/artifacts/ead9a31a77872dcae4f9a0e110ddb2281812b6b0/node_modules/vega-scenegraph/build/vega-scenegraph.js:3190:19)
    at CanvasRenderer.initialize (/home/jboik/.julia/artifacts/ead9a31a77872dcae4f9a0e110ddb2281812b6b0/node_modules/vega-scenegraph/build/vega-scenegraph.js:3621:30)
    at initializeRenderer (/home/jboik/.julia/artifacts/ead9a31a77872dcae4f9a0e110ddb2281812b6b0/node_modules/vega-view/build/vega-view.js:639:14)
    at renderHeadless (/home/jboik/.julia/artifacts/ead9a31a77872dcae4f9a0e110ddb2281812b6b0/node_modules/vega-view/build/vega-view.js:758:12)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async View.renderToCanvas [as toCanvas] (/home/jboik/.julia/artifacts/ead9a31a77872dcae4f9a0e110ddb2281812b6b0/node_modules/vega-view/build/vega-view.js:794:15)

If I instead try to save as an html file, then it works properly. Also, if I have "using VegaLite" in my script, it does not correct the error. I tried to install vega-cli, but there does not seem to be any julia package similar to that name.

@jeremiahpslewis
Copy link
Contributor

Hey! Nice to have new users to VegaLite, sorry about the frustration with canvas (quite likely a javascript dependency issue).

Before someone is able to look into this in more detail, there are three things you can do to help the community give feedback on your problem:

  1. Can you try using the latest stable Julia release, 1.6.0? https://julialang.org

  2. Can you post a minimal working example, e.g. enough code so that someone else could run your snippet completely? (In this case, you would need to include a 'mock' df2 data frame which reproduces the problem as well as the necessary import statements, something like using DataFrames, VegaLite).

  3. Can you use the following command using Pkg; Pkg.status() and paste the output into a code block in this issue?

@John-Boik
Copy link
Author

OK, I have now updated to Julia 1.6.0, and rebuilt my package from scratch.
Here is a code snipit that causes saving with png to fail. The line that saves as html works just fine.

module test_vega

import DataFrames
import Dates
import VegaLite
using Infiltrator
using Revise

some_dates = []
for ii in -3:3
    push!(some_dates, Dates.now() + Dates.Day(ii))
end
df = DataFrames.DataFrame(time=some_dates)

df |> VegaLite.@vlplot(:bar, x={"timeUnit" = "yearmonthdate", "field" = "time","type" = "ordinal", 
    "axis"={"labelAngle"=-45}}, y="count()", title="End day") |> VegaLite.save("test_vegalite.html")

df |> VegaLite.@vlplot(:bar, x={"timeUnit" = "yearmonthdate", "field" = "time","type" = "ordinal", 
    "axis"={"labelAngle"=-45}}, y="count()", title="End day") |> VegaLite.save("test_vegalite.png")

#@infiltrate; @assert false

end # ---------------------- module --------------------------------

Here is the pkg status:

(Ideai) pkg> status
     Project Ideai v0.1.0
      Status `~/Devel/Ideai_Ju/Ideai/Project.toml`
  [fbb218c0] BSON v0.3.3
  [336ed68f] CSV v0.8.4
  [a93c6f00] DataFrames v0.22.7
  [aae7a2af] DiffEqFlux v1.36.1
  [0c46a032] DifferentialEquations v6.16.0
  [31c24e10] Distributions v0.24.15
  [587475ba] Flux v0.12.1
  [59287772] Formatting v0.4.2
  [c27321d9] Glob v1.3.0
  [5903a43b] Infiltrator v0.3.0
  [194296ae] LibPQ v1.6.2
  [429524aa] Optim v1.3.0
  [1dea7af3] OrdinaryDiffEq v5.52.3
  [91a5bcdd] Plots v1.11.2
  [438e738f] PyCall v1.92.3
  [d330b81b] PyPlot v2.9.0
  [295af30f] Revise v3.1.14
  [2913bbd2] StatsBase v0.33.5
  [112f6efa] VegaLite v2.4.0
  [fdbf4ff8] XLSX v0.7.6
  [e88e6eb3] Zygote v0.6.9
  [10745b16] Statistics

Here is the error:

julia> include("./test_vegalite.jl")
WARNING: replacing module test_vega.
Error: CanvasRenderer is missing a valid canvas or context
    at Object.error (/home/jboik/.julia/artifacts/ead9a31a77872dcae4f9a0e110ddb2281812b6b0/node_modules/vega-scenegraph/node_modules/vega-util/build/vega-util.js:39:11)
    at CanvasRenderer.resize (/home/jboik/.julia/artifacts/ead9a31a77872dcae4f9a0e110ddb2281812b6b0/node_modules/vega-scenegraph/build/vega-scenegraph.js:3633:28)
    at CanvasRenderer.initialize (/home/jboik/.julia/artifacts/ead9a31a77872dcae4f9a0e110ddb2281812b6b0/node_modules/vega-scenegraph/build/vega-scenegraph.js:3190:19)
    at CanvasRenderer.initialize (/home/jboik/.julia/artifacts/ead9a31a77872dcae4f9a0e110ddb2281812b6b0/node_modules/vega-scenegraph/build/vega-scenegraph.js:3621:30)
    at initializeRenderer (/home/jboik/.julia/artifacts/ead9a31a77872dcae4f9a0e110ddb2281812b6b0/node_modules/vega-view/build/vega-view.js:639:14)
    at renderHeadless (/home/jboik/.julia/artifacts/ead9a31a77872dcae4f9a0e110ddb2281812b6b0/node_modules/vega-view/build/vega-view.js:758:12)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async View.renderToCanvas [as toCanvas] (/home/jboik/.julia/artifacts/ead9a31a77872dcae4f9a0e110ddb2281812b6b0/node_modules/vega-view/build/vega-view.js:794:15)

@jeremiahpslewis
Copy link
Contributor

Sorry, it should have occurred to me way sooner. This is a known issue which will be resolved in a future version; at the moment, there is a test which captures the fact that this behavior is broken...

#361

@test_broken p |> save("testfile.png")

@jeremiahpslewis
Copy link
Contributor

There are dependencies which need to be updated / deconflicted before this will work. In the meantime, you might be able to use VegaLite to generate a Vega spec and then pipe it to vg2png in the Vega-cli package. Admittedly, a poor solution, but one of few available until this is resolved.

@davidanthoff
Copy link
Member

This should now be fixed on master.

@xeruf
Copy link

xeruf commented Mar 16, 2022

Is the fix released yet? I still get this error and had to resort to the workaround with vega (vl2vg and then vg2png).

@xeruf
Copy link

xeruf commented Jan 20, 2023

Now I even encounter this issue in vg2png...

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

4 participants