Skip to content

Instantly share code, notes, and snippets.

@littledian
Last active July 6, 2018 08:40
Show Gist options
  • Save littledian/a350b19070777333e561bdaa946178d4 to your computer and use it in GitHub Desktop.
Save littledian/a350b19070777333e561bdaa946178d4 to your computer and use it in GitHub Desktop.
createForeignObjectSVG = (
width: number,
height: number,
x: number,
y: number,
node: Node
) => {
const xmlns = 'http://www.w3.org/2000/svg';
const svg = document.createElementNS(xmlns, 'svg');
const foreignObject = document.createElementNS(xmlns, 'foreignObject');
svg.setAttributeNS(null, 'width', width);
svg.setAttributeNS(null, 'height', height);
foreignObject.setAttributeNS(null, 'width', '100%');
foreignObject.setAttributeNS(null, 'height', '100%');
foreignObject.setAttributeNS(null, 'x', x);
foreignObject.setAttributeNS(null, 'y', y);
foreignObject.setAttributeNS(null, 'externalResourcesRequired', 'true');
svg.appendChild(foreignObject);
foreignObject.appendChild(node);
return svg;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment