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

Undefined xlink namespace is generated by the svgstring function #168

Closed
arendsee opened this issue Apr 20, 2023 · 1 comment
Closed

Undefined xlink namespace is generated by the svgstring function #168

arendsee opened this issue Apr 20, 2023 · 1 comment

Comments

@arendsee
Copy link

arendsee commented Apr 20, 2023

Using svglite v2.1.1, given the following code:

require(ggplot2)
require(svglite)

p <- ggplot(mtcars) +
    geom_point(aes(x = disp, y = mpg, color = gear))

svg <- svgstring(fix_text_size = FALSE, standalone = FALSE)
plot(p)
invisible(dev.off())
s <- svg()
write(s, file="foo.svg")

When I open the SVG file "foo.svg" in the chrome browser, I get the error message:

error on line 108 at column 401: Namespace prefix xlink for href on image is not defined

Line 108 of the SVG contains:

<image width='17.28' height='86.40' x='672.30' y='239.58' preserveAspectRatio='none' xlink:href='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAEsCAYAAAAC    UNnVAAAAmElEQVQ4ja2UQRLDMAgDd3hk/tnX5agcknFaCoa0vnkMCEnGsL12GQhDYDpPwoDrpBFlRDWi/9Wu6AHC9FkLYLrzlhD3oJ3mDvRHRYy7IC8A7bCK8gpWKYDzeQVArDcDyD2YAnSofZvzaOA6Q7Oahp/    dmRuVTQ0xU5TGP2o8Waool1obVuv1q8qP9xPvg633XlGLDtfIhNUBcBeA5ss0BXMAAAAASUVORK5CYII='/>

The SVG renders correctly if we define xlink in the first line of the SVG file. That is, if we replace the current first line:

<svg class='svglite' width='720.00pt' height='576.00pt' viewBox='0 0 720.00 576.00'>

with

<svg class='svglite' width='720.00pt' height='576.00pt' viewBox='0 0 720.00 576.00' xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
@thomasp85
Copy link
Member

This is because you specifically sets standalone = FALSE which, as the documentation says, removes the namespaces from the file

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

2 participants