From 6a90d878f9fe4caa96a9ce51d5dd0f3b76c299fb Mon Sep 17 00:00:00 2001 From: Neonit Date: Mon, 22 Oct 2018 07:58:17 +0200 Subject: [PATCH] add example code for multiple svg.js instances --- readme.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/readme.md b/readme.md index c10f51b..1ea0454 100644 --- a/readme.md +++ b/readme.md @@ -31,6 +31,23 @@ console.log(draw.svg()) console.log(draw.node.outerHTML) ``` +If you need more than one instance for independent SVG objects, you can also use newly created `` elements. + +```js +// returns a window with a document and an svg root node +const window = require('svgdom') +const SVG = require('svg.js')(window) +const document = window.document + +// create svg.js instances +const drawA = SVG(document.createElement('svg')) +const drawB = SVG(document.createElement('svg')) +const drawC = SVG(document.createElement('svg')) + +// drawA, drawB and drawC are independent svg.js instances you can use as normal +// ... +``` + ## Fonts In order to calculate bounding boxes for text the font needs to be loaded first. `svgdom` loads `OpenSans-Regular` by default when no font file for the specified font was found.