0

This is all using SVG.js

I have instantiated an svg, and am trying to append a child svg that I am loading from a file. Here is the pseudo-code:

let myDoc = ...my root svg element;
let myChildSVG = ...require('UIElement.svg');
let child = myDoc.nested().svg(myChildSVG);

This accomplishes what I want, but ends up with 3 svg tags: the original, the middle (from nested) and the bottom (from the final svg call).

Am I missing a better way of adding the child to myDoc that will avoid that middle svg? Can I create the nested svg with the child itself somehow? Such as: myDoc.nested(myChildSVG) (which doesn't seem to work).

Thanks.

  • Why not just `myDoc.svg(myChildSVG)`? Import does not overwrite content – Fuzzyma May 31 '17 at 08:56
  • The difference is that `svg()` returns the parent whereas `nested()` returns the child svg and so when using `nested().svg()` I have reference to the child svg. I am now using `parent.svg().select('svg').last()`. Thanks for your help. – Ariel Jakobovits Jun 02 '17 at 19:18
  • Well you can search for the imported svg with select("svg").first() – Fuzzyma Jun 02 '17 at 19:19

0 Answers0