You could also use s.th. like this:
/**
* Convert svg node to data url
* @param {HTMLElement} node
target node
* @returns {string}
*
@private
*/
getSvgDataUrl:
function
getSvgDataUrl(node):string
{
if
(!node || node.nodeName
!==
'svg')
return
'';
const serializer:XMLSerializer =
new
XMLSerializer()
,
clone = node.cloneNode(!0)
,
xmlns =
http://www.w3.org/2000/xmlns/
,
xlinkns =
http://www.w3.org/1999/xlink
,
svgns =
http://www.w3.org/2000/svg;
clone.setAttributeNS(xmlns,
"xmlns",
svgns);
clone.setAttributeNS(xmlns,
"xmlns:xlink",
xlinkns);
return 'data:image/svg+xml;base64,'
+
b64EncodeUnicode(serializer.serializeToString(clone));
}
To produce an SVG image and then simply save this data as a file.
Hope that helps
Von: d3...@googlegroups.com <d3...@googlegroups.com>
Im Auftrag von Jim McGlaughlin
Gesendet: Donnerstag, 26. Mai 2022 17:19
An: d3-js <d3...@googlegroups.com>
Betreff: How to create SVG file without using html
Sie erhalten nicht oft eine E-Mail von jim.mcgla...@gmail.com. Erfahren Sie, warum dies wichtig ist |
--
You received this message because you are subscribed to the Google Groups "d3-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
d3-js+un...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/d3-js/f1fd9201-4ae5-4d8d-9be6-f0d5a5e71438n%40googlegroups.com.