abeyang
February 13, 2019, 11:37pm
1
Hi, is there a way to embed an external svg into the current svg?
The closest thing I could find is this notebook:
However, in Martien’s case, he’s placing the svg directly as an Observable cell… for my use case, I’d like to host/pull it elsewhere (like from Gist or Github, etc).
Surely there’s a way! (I just have no idea how to do it…)
1 Like
bgchen
February 13, 2019, 11:44pm
2
You should be able to use the <image>
tag and its xlink:href
attribute.
abeyang
February 14, 2019, 12:14am
3
Hm, that’s not working for me. So this is what I’m trying to pull:
Assets.svg
<?xml version="1.0" encoding="UTF-8"?>
<svg width="749px" height="574px" viewBox="0 0 749 574" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 52.6 (67491) - http://www.bohemiancoding.com/sketch -->
<title>Island - Original</title>
<desc>Created with Sketch.</desc>
<g id="Island---Original" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="DDG_island" transform="translate(-690.000000, -109.000000)">
<g id="Layer_1">
<rect id="Rectangle" fill="#678FFF" x="0" y="0" width="1600" height="740"></rect>
<g id="Group" transform="translate(1003.000000, 157.000000)">
This file has been truncated. show original
And here’s my code:
svg.append("image").attr("xlink:href", "https://gist.githubusercontent.com/abeyang/7f382e53d6ae92fb64e7fad4ebdfda06/raw/62ca0d16dae9c500afb45397f882b92044b0a8ea/Assets.svg")
Looking at my dev console, this is what I see (I think this is related?):
abeyang
February 14, 2019, 12:20am
4
However , when I hosted it elsewhere (like cloudapp), it seems to work.
But would be nice to host from github / gist… or am I asking too much?
bgchen
February 14, 2019, 12:36am
5
Not sure… this SO answer says that adding ?sanitize=true
to the end of the URL might help, and doing this seems to work for my test notebook in Chrome, but not Firefox. Maybe that’s good enough?
abeyang
February 14, 2019, 12:40am
6
Wow, thanks so much! Yeah think that’s good enough!
1 Like
abeyang
February 14, 2019, 12:56am
7
Ack, sorry! I need this to be downloadable (rasterized or serialized), and this method seems to not work?
Is it because of the image tag? Or am I doing something wrong?
bgchen
February 14, 2019, 1:24am
8
2 Likes