How to embed nodes SVG pictures in the SVG exported diagram

Hi, when exporting the diagram as SVG (makeSVG), is it possible to embed nodes images (SVG Picture) instead of using xmlns:xlink?
Right now I’m retrieving those SVG images from a server, and when opening a saved SVG file and the server if offline, the nodes are showing empty. Also in the case of distributing the diagrams to people without access to the server they won’t be able to see it correctly.

Thanks for your help in advance.

Yes, in your call to Diagram.makeSvg you can specify the elementFinished option. If supplied it must be a function taking the GraphObject being rendered and the SVGElement that has been produced so far.

What you can do in that function is modify the SVG element so that it embeds the image instead of referring to a URI.

I’ll try that. Thanks a lot for your quick reply!

Did you manage to achieve this? I’d like to do the same thing myself and haven’t the foggiest how to do it

I got this working for bitmap images and SVGs by embedding as bitmaps, but I’d like to get it working by embedding the SVG vector image. I could try and grab the source file from the image’s src, but since that would be by an async request, the image generation would be long gone by the time it returns. Is the source SVG available somewhere in the go.Picture instance?, I couldn’t find anything in the API reference

the Picture.element is a reference to the <img> that gets created, after setting a source, if that’s what you’re looking for.

That gives me the source URL but not much else. I’m after the XML of the actual SVG, but I guess GoJS may have no need to have access to that so probably won’t expose it

Yes, we don’t do any parsing of the source or anything, just attempt to paint it with an HTML Canvas context call to drawImage.