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

Old axis labels showing up in new Figure with SVG in CairoMakie #952

Closed
palday opened this issue May 17, 2021 · 11 comments
Closed

Old axis labels showing up in new Figure with SVG in CairoMakie #952

palday opened this issue May 17, 2021 · 11 comments

Comments

@palday
Copy link
Contributor

palday commented May 17, 2021

When plotting successive figures to SVG with CairoMakie, the previous figures linger and contaminate the new figure. This is visible in a recent docs preview in MixedModelsMakie. The first plot renders correctly, but the second and third plots have clear problems with overprinting in the y-axis labels. Likewise, the final plot, which is completely distinct clearly has some overplotted axis labels from the first three plots.

This problem does not occur with PNG output.

cc @dmbates

@SimonDanisch
Copy link
Member

We switched the default to PNG because of this:
https://discourse.julialang.org/t/cairomakie-and-fontconfig/55931/4
JuliaPlots/CairoMakie.jl#147

As far I can tell, there isn't much we can do on the Makie side of things...

@jkrumbiegel
Copy link
Member

The problem is that Documenter's tagged version puts svgs directly into the page. This causes them to interact which each other because glyph ids are shared among them. The fix is to use svgs in <img> tags, as they don't interact anymore this way. (or to salt the ids of the svg to be unique, I think matplotlib does that to avoid the same issue). You can look at your "messed up" documentation examples in a new tab and they will be fine.

I fixed this issue on Documenter#master, which is what our docs currently build with until a new version is tagged.

@palday
Copy link
Contributor Author

palday commented May 17, 2021

Is there a way to get different glyph ids? Pass a UUID or the like when constructing the SVG object?

@jkrumbiegel
Copy link
Member

grafik

here you can see it, these generic glyph ids repeat

@jkrumbiegel
Copy link
Member

Is there a way to get different glyph ids? Pass a UUID or the like when constructing the SVG object?

I guess we could look for id="glyph and add a uuid there, yes

@jkrumbiegel
Copy link
Member

the other issue with directly embedded svgs is that they don't resize, so I find the img way in Documenter#master preferable, even without the glyphs

@palday
Copy link
Contributor Author

palday commented May 17, 2021

I'm thinking more as a stop-gap until Documenter has a new release (besides just using PNG)

@jkrumbiegel
Copy link
Member

maybe we should do this anyway if it messes up other tools as well, like jupyter notebooks

@knuesel
Copy link

knuesel commented May 17, 2021

Oh it does mess Jupyter notebooks :) I was going to file an issue about this after doing some research. I'll write my results here:

For Jupyter the isolated metadata fixes this by wrapping the SVG in an iframe. It can be implemented by specializing the IJulia.metadata method but apparently that must be made for every type that can go through display or related methods (e.g. IJulia.display_dict):

# For plots shown as return value
IJulia.metadata(::AbstractPlotting.Figure) = Dict("isolated" => true)

# For plots shown by calling `display` explicitely
IJulia.metadata(::AbstractPlotting.Scene) = Dict("isolated" => true)

# For AlgebraOfGraphics plots shown by return value
IJulia.metadata(::AlgebraOfGraphics.FigureGrid) = Dict("isolated" => true)

So there are at least the following options:

  • Use Jupyter isolated metadata: this only fixes it for Jupyter, and it requires a dependence on IJulia and must(?) be done for each figure type.
  • Provide an API to optionally wrap the SVG in an HTML iframe.
  • Make the IDs unique. There was a patch submitted to Cairo for this but the developers think it's best done downstream when several SVGs are put together: https://gitlab.freedesktop.org/cairo/cairo/-/issues/304

@jkrumbiegel
Copy link
Member

I think I'll follow the matplotlib approach and replace the ids with salted versions, created with the shortened hash of the full svg. This means that the same file will have the same salt when reproducing figures.

@jkrumbiegel
Copy link
Member

jkrumbiegel commented May 20, 2021

fixed by JuliaPlots/CairoMakie.jl#163

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