MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.38k stars 302 forks source link

wglmakie saved html file is too large when color is an image #2180

Open lazarusA opened 2 years ago

lazarusA commented 2 years ago

The following is just 419 KB, however if the color is changed by earth_img then the final size is 57 MB 😱.

I remember seeing something similar some months ago and at some point @SimonDanisch did some magic, probably there is a regression now 🤷🏼‍♂️

using WGLMakie, JSServe
using Downloads, FileIO
WGLMakie.activate!()

earth_img = load(Downloads.download("https://upload.wikimedia.org/wikipedia/commons/5/56/Blue_Marble_Next_Generation_%2B_topography_%2B_bathymetry.jpg"))

page = Page(offline=true, exportable=true)
app = JSServe.App() do session::Session
    fig = mesh(Sphere(Point3f(0),1), color = earth_img, #:dodgerblue, 
        figure = (; resolution = (1600,800),
        backgroundcolor = :black), shading=true, 
        lightposition = Vec3f(2, 0, 0), ambient = Vec3f(0.1, 0.3, 0.2),
        #backlight = 1.0f0
        )
return JSServe.record_states(session, DOM.div(fig))
end

open("MWE.html", "w") do io
    println(io, """
    <head>
  </head>
  <body>
    """)
    show(io, MIME"text/html"(), page)
    show(io, MIME"text/html"(), app)
    println(io, """
        </body>
    </html>
    """)
end
pkg> st WGLMakie JSServe Downloads FileIO
      Status `~/Documents/Project.toml`
  [5789e2e9] FileIO v1.14.0
  [824d6782] JSServe v1.2.7
  [276b4fcb] WGLMakie v0.6.12
  [f43a241f] Downloads

EDIT: It looks like this is the way it is because the image is too large. But still, I wonder if is possible to have a smaller file.

SimonDanisch commented 2 years ago

What do you mean by if the color is changed by earth_img? I don't see something like that in the code? Or do you just mean, to actually pass earth_img as color?

lazarusA commented 2 years ago

yes, pass earth_img as color. Just as it is.

ffreyer commented 3 weeks ago

@SimonDanisch What's the state of this? Is this a bug, expected, ...?

SimonDanisch commented 3 weeks ago

This is somewhat expected... Although I can see this being worse than before, one Bonito (formerly JSServe) release made record_state record many more redundant states than before, and there may also be something related to the recently fixed triple updates of updating a heatmap with a new color.

ffreyer commented 3 weeks ago

Hmm, sounds like there is work to be done then. Maybe this should be moved to Bonito though?