My file can be opened in browser, but when I try to open it with Illustrator, I’ve got this error: The operation cannot be complete because of an unknown error. [STEX].
It’s everything Ok with svg file from tutorial though.
Built-in option doesn’t offer to me to save in svg (
How to fix it? Or if there is another way to export chart to svg?
The cell you are trying to download as SVG is not SVG but HTML. The built in tool for downloading properly recognize this and doesn’t offer you the option. The code referenced by the button doesn’t have this check, attempts to convert the HTML, and returns gibberish. In short, there’s no reason to expect those tools to work.
Here’s a work around that might be sufficient for your needs:
{
const {elementToSVG, inlineResources} = await import('https://esm.sh/dom-to-svg');
// Capture specific element
const {documentElement: svg} = elementToSVG(graph);
// Seems to ignore xlink:href. Replace with href.
for(const n of svg.querySelectorAll('[xlink\\:href]')) {
n.setAttribute('href', n.getAttribute('xlink:href'));
n.removeAttribute('xlink:href');
}
// Inline external resources (fonts, images, etc) as data: URIs
await inlineResources(svg);
// Detach from its parent, so that Observable's Inspector will display it.
svg.remove();
return svg;
}
One way would be to just rasterize them, i.e., render them to a canvas and inline that as data URL. Frankly I’m surprised that dom-to-svg can’t handle that already – might wanna take a look at the issues and docs.