In nested SVG, inner icon is getting truncated












0















My challenge is to take two random svg icons and splice them together such that the inner one is located on the lower left quadrant of the overall image. Thanks to a previous answer I have a framework for doing this but the inner icon is getting truncated unless I make manual changes. I need to do this programmatically, so the question becomes, how do I know how large to make my B viewport, algorithmically speaking?



If this is Icon A:



<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 100 100">
<rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)"
</svg>


This is a minimal but fairly accurate example of an Icon B:



<svg height="512pt" viewBox="-51 0 512 512.00253" width="512pt" xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
</svg>


This is the framework for putting them together:



<svg viewBox="0 0 100 100">

<defs>
<symbol id="A" viewBox="0 0 100 100"> <!-- making viewbox of symbol A
match viewbox on contained
svg element, which works -->

%ENTIRE CONTENTS OF SVG A%

</symbol>

<symbol id="B" viewBox="51 0 512 512"> <!-- making viewbox of symbol B
match viewbox on contained
svg element, which truncates -->

%ENTIRE CONTENTS OF SVG B%

</symbol>
</defs>

<use xlink:href="#A" x="0" y="0" width="100" height="100" />
<use xlink:href="#B" x="0" y="50" width="50%" height="50%" />

</svg>


This is the current svg:



<svg viewBox="0 0 100 100">

<defs>
<symbol id="A" viewBox="0 0 100 100">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 100 100">
<rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)"
</svg>

</symbol>

<symbol id="B" viewBox="51 0 512 512">
<svg height="512pt" viewBox="-51 0 512 512.00253" width="512pt" xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
</svg>

</symbol>
</defs>

<use xlink:href="#A" x="0" y="0" width="100" height="100" />
<use xlink:href="#B" x="0" y="50" width="50%" height="50%" />

</svg>


Here's what that looks like. Note the truncation; that inner icon is getting chomped on the right and bottom.



Outer icon is fine, inner is truncated



I can manually tweak it like this, with the results below. But I can't do manual tweaking on these.



<svg viewBox="0 0 100 100">

<defs>
<symbol id="A" viewBox="0 0 100 100">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 100 100">
<rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)"
</svg>

</symbol>

<!-- Note this pair of 680 values, and the 0 x-pos on the line below -->
<symbol id="B" viewBox="0 0 680 680">
<svg height="512pt" viewBox="0 0 512 512.00253" width="512pt" xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
</svg>

</symbol>
</defs>

<use xlink:href="#A" x="0" y="0" width="100" height="100" />
<use xlink:href="#B" x="0" y="50" width="50%" height="50%" />

</svg>


What I want, but too manual for my needs



Note the tweaked "680" h/w on the symbol B viewbox. (And also tweaking the viewbox on the inner svg to shift the X position to 0, which I'm really unhappy doing). That "680" number was determined experimentally, which would be fine only if this was a one-time deal and not something I need to make systematic. How do I know how big to make that viewbox programmatically?










share|improve this question





























    0















    My challenge is to take two random svg icons and splice them together such that the inner one is located on the lower left quadrant of the overall image. Thanks to a previous answer I have a framework for doing this but the inner icon is getting truncated unless I make manual changes. I need to do this programmatically, so the question becomes, how do I know how large to make my B viewport, algorithmically speaking?



    If this is Icon A:



    <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 100 100">
    <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)"
    </svg>


    This is a minimal but fairly accurate example of an Icon B:



    <svg height="512pt" viewBox="-51 0 512 512.00253" width="512pt" xmlns="http://www.w3.org/2000/svg">
    <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
    </svg>


    This is the framework for putting them together:



    <svg viewBox="0 0 100 100">

    <defs>
    <symbol id="A" viewBox="0 0 100 100"> <!-- making viewbox of symbol A
    match viewbox on contained
    svg element, which works -->

    %ENTIRE CONTENTS OF SVG A%

    </symbol>

    <symbol id="B" viewBox="51 0 512 512"> <!-- making viewbox of symbol B
    match viewbox on contained
    svg element, which truncates -->

    %ENTIRE CONTENTS OF SVG B%

    </symbol>
    </defs>

    <use xlink:href="#A" x="0" y="0" width="100" height="100" />
    <use xlink:href="#B" x="0" y="50" width="50%" height="50%" />

    </svg>


    This is the current svg:



    <svg viewBox="0 0 100 100">

    <defs>
    <symbol id="A" viewBox="0 0 100 100">
    <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 100 100">
    <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)"
    </svg>

    </symbol>

    <symbol id="B" viewBox="51 0 512 512">
    <svg height="512pt" viewBox="-51 0 512 512.00253" width="512pt" xmlns="http://www.w3.org/2000/svg">
    <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
    </svg>

    </symbol>
    </defs>

    <use xlink:href="#A" x="0" y="0" width="100" height="100" />
    <use xlink:href="#B" x="0" y="50" width="50%" height="50%" />

    </svg>


    Here's what that looks like. Note the truncation; that inner icon is getting chomped on the right and bottom.



    Outer icon is fine, inner is truncated



    I can manually tweak it like this, with the results below. But I can't do manual tweaking on these.



    <svg viewBox="0 0 100 100">

    <defs>
    <symbol id="A" viewBox="0 0 100 100">
    <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 100 100">
    <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)"
    </svg>

    </symbol>

    <!-- Note this pair of 680 values, and the 0 x-pos on the line below -->
    <symbol id="B" viewBox="0 0 680 680">
    <svg height="512pt" viewBox="0 0 512 512.00253" width="512pt" xmlns="http://www.w3.org/2000/svg">
    <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
    </svg>

    </symbol>
    </defs>

    <use xlink:href="#A" x="0" y="0" width="100" height="100" />
    <use xlink:href="#B" x="0" y="50" width="50%" height="50%" />

    </svg>


    What I want, but too manual for my needs



    Note the tweaked "680" h/w on the symbol B viewbox. (And also tweaking the viewbox on the inner svg to shift the X position to 0, which I'm really unhappy doing). That "680" number was determined experimentally, which would be fine only if this was a one-time deal and not something I need to make systematic. How do I know how big to make that viewbox programmatically?










    share|improve this question



























      0












      0








      0








      My challenge is to take two random svg icons and splice them together such that the inner one is located on the lower left quadrant of the overall image. Thanks to a previous answer I have a framework for doing this but the inner icon is getting truncated unless I make manual changes. I need to do this programmatically, so the question becomes, how do I know how large to make my B viewport, algorithmically speaking?



      If this is Icon A:



      <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 100 100">
      <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)"
      </svg>


      This is a minimal but fairly accurate example of an Icon B:



      <svg height="512pt" viewBox="-51 0 512 512.00253" width="512pt" xmlns="http://www.w3.org/2000/svg">
      <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
      </svg>


      This is the framework for putting them together:



      <svg viewBox="0 0 100 100">

      <defs>
      <symbol id="A" viewBox="0 0 100 100"> <!-- making viewbox of symbol A
      match viewbox on contained
      svg element, which works -->

      %ENTIRE CONTENTS OF SVG A%

      </symbol>

      <symbol id="B" viewBox="51 0 512 512"> <!-- making viewbox of symbol B
      match viewbox on contained
      svg element, which truncates -->

      %ENTIRE CONTENTS OF SVG B%

      </symbol>
      </defs>

      <use xlink:href="#A" x="0" y="0" width="100" height="100" />
      <use xlink:href="#B" x="0" y="50" width="50%" height="50%" />

      </svg>


      This is the current svg:



      <svg viewBox="0 0 100 100">

      <defs>
      <symbol id="A" viewBox="0 0 100 100">
      <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 100 100">
      <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)"
      </svg>

      </symbol>

      <symbol id="B" viewBox="51 0 512 512">
      <svg height="512pt" viewBox="-51 0 512 512.00253" width="512pt" xmlns="http://www.w3.org/2000/svg">
      <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
      </svg>

      </symbol>
      </defs>

      <use xlink:href="#A" x="0" y="0" width="100" height="100" />
      <use xlink:href="#B" x="0" y="50" width="50%" height="50%" />

      </svg>


      Here's what that looks like. Note the truncation; that inner icon is getting chomped on the right and bottom.



      Outer icon is fine, inner is truncated



      I can manually tweak it like this, with the results below. But I can't do manual tweaking on these.



      <svg viewBox="0 0 100 100">

      <defs>
      <symbol id="A" viewBox="0 0 100 100">
      <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 100 100">
      <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)"
      </svg>

      </symbol>

      <!-- Note this pair of 680 values, and the 0 x-pos on the line below -->
      <symbol id="B" viewBox="0 0 680 680">
      <svg height="512pt" viewBox="0 0 512 512.00253" width="512pt" xmlns="http://www.w3.org/2000/svg">
      <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
      </svg>

      </symbol>
      </defs>

      <use xlink:href="#A" x="0" y="0" width="100" height="100" />
      <use xlink:href="#B" x="0" y="50" width="50%" height="50%" />

      </svg>


      What I want, but too manual for my needs



      Note the tweaked "680" h/w on the symbol B viewbox. (And also tweaking the viewbox on the inner svg to shift the X position to 0, which I'm really unhappy doing). That "680" number was determined experimentally, which would be fine only if this was a one-time deal and not something I need to make systematic. How do I know how big to make that viewbox programmatically?










      share|improve this question
















      My challenge is to take two random svg icons and splice them together such that the inner one is located on the lower left quadrant of the overall image. Thanks to a previous answer I have a framework for doing this but the inner icon is getting truncated unless I make manual changes. I need to do this programmatically, so the question becomes, how do I know how large to make my B viewport, algorithmically speaking?



      If this is Icon A:



      <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 100 100">
      <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)"
      </svg>


      This is a minimal but fairly accurate example of an Icon B:



      <svg height="512pt" viewBox="-51 0 512 512.00253" width="512pt" xmlns="http://www.w3.org/2000/svg">
      <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
      </svg>


      This is the framework for putting them together:



      <svg viewBox="0 0 100 100">

      <defs>
      <symbol id="A" viewBox="0 0 100 100"> <!-- making viewbox of symbol A
      match viewbox on contained
      svg element, which works -->

      %ENTIRE CONTENTS OF SVG A%

      </symbol>

      <symbol id="B" viewBox="51 0 512 512"> <!-- making viewbox of symbol B
      match viewbox on contained
      svg element, which truncates -->

      %ENTIRE CONTENTS OF SVG B%

      </symbol>
      </defs>

      <use xlink:href="#A" x="0" y="0" width="100" height="100" />
      <use xlink:href="#B" x="0" y="50" width="50%" height="50%" />

      </svg>


      This is the current svg:



      <svg viewBox="0 0 100 100">

      <defs>
      <symbol id="A" viewBox="0 0 100 100">
      <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 100 100">
      <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)"
      </svg>

      </symbol>

      <symbol id="B" viewBox="51 0 512 512">
      <svg height="512pt" viewBox="-51 0 512 512.00253" width="512pt" xmlns="http://www.w3.org/2000/svg">
      <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
      </svg>

      </symbol>
      </defs>

      <use xlink:href="#A" x="0" y="0" width="100" height="100" />
      <use xlink:href="#B" x="0" y="50" width="50%" height="50%" />

      </svg>


      Here's what that looks like. Note the truncation; that inner icon is getting chomped on the right and bottom.



      Outer icon is fine, inner is truncated



      I can manually tweak it like this, with the results below. But I can't do manual tweaking on these.



      <svg viewBox="0 0 100 100">

      <defs>
      <symbol id="A" viewBox="0 0 100 100">
      <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 100 100">
      <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)"
      </svg>

      </symbol>

      <!-- Note this pair of 680 values, and the 0 x-pos on the line below -->
      <symbol id="B" viewBox="0 0 680 680">
      <svg height="512pt" viewBox="0 0 512 512.00253" width="512pt" xmlns="http://www.w3.org/2000/svg">
      <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
      </svg>

      </symbol>
      </defs>

      <use xlink:href="#A" x="0" y="0" width="100" height="100" />
      <use xlink:href="#B" x="0" y="50" width="50%" height="50%" />

      </svg>


      What I want, but too manual for my needs



      Note the tweaked "680" h/w on the symbol B viewbox. (And also tweaking the viewbox on the inner svg to shift the X position to 0, which I'm really unhappy doing). That "680" number was determined experimentally, which would be fine only if this was a one-time deal and not something I need to make systematic. How do I know how big to make that viewbox programmatically?







      svg






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 25 '18 at 20:02







      billmill

















      asked Nov 25 '18 at 19:52









      billmillbillmill

      94110




      94110
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Remove the width and the height attributes from the inner SVG






          svg{width:90vh}

          <svg viewBox="0 0 100 100">

          <defs>
          <symbol id="A" viewBox="0 0 100 100">
          <svg viewBox="0 0 100 100">
          <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>

          <symbol id="B" viewBox="0 0 512 512">
          <svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
          <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>
          </defs>

          <use xlink:href="#A" x="0" y="0" width="100" height="100" />
          <use xlink:href="#B" x="0" y="50" width="50" height="50" />

          </svg>





          UPDATE



          The OP comments that they can't remove the width and the height attributes from the inner SVG. In this case I need to add a few lines of JavaScript. First I need to get the size of the second SVG canvas in px.



          const pt = 96/72;
          let size = 512 * pt;


          Also I need to know the stroke width



          let strokeWidth = 30 * pt; 


          Next I need to reset the value for the viewBox attribute for the `#B``






          const pt = 96/72;
          let size = 512 * pt;
          let strokeWidth = 30 * pt;
          B.setAttributeNS(null,"viewBox", `-${strokeWidth/2} -${strokeWidth/2} ${size+strokeWidth} ${size+strokeWidth}`)

          <svg viewBox="0 0 100 100">

          <defs>
          <symbol id="A" viewBox="0 0 100 100">
          <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 100 100">
          <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>

          <symbol id="B" viewBox="0 0 512 512">
          <svg height="512pt" viewBox="0 0 512 512" width="512pt" xmlns="http://www.w3.org/2000/svg">
          <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>
          </defs>

          <use xlink:href="#A" x="0" y="0" width="100" height="100" />
          <use xlink:href="#B" x="0" y="50" width="50%" height="50%" />

          </svg>








          share|improve this answer


























          • Thank you. I'm trying to avoid doing exactly that however ... adds manual overhead and/or programming complexity to the process any time I make any changes at all to the inner svg. Is there no way to figure out how big the symbol viewbox needs to be to avoid truncation?

            – billmill
            Nov 26 '18 at 13:56











          • I think this is what I need -- that 96/72 ratio. The stroke width won't exist at all in the final analysis; I just put it there to make the boundaries of the space obvious. And I can't use javascript for reasons that are too complex to go into but since I am able to use groovy I should be set.

            – billmill
            Nov 26 '18 at 15:00











          • If you don't mind me asking, where does that 96/72 ratio come from?

            – billmill
            Nov 26 '18 at 15:00











          • 72pt = 1 inch. Also 96px = 1 inch. So 1pt = 96/72 px. And in SVG 1 user unit is 1px

            – enxaneta
            Nov 26 '18 at 15:08











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53471283%2fin-nested-svg-inner-icon-is-getting-truncated%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Remove the width and the height attributes from the inner SVG






          svg{width:90vh}

          <svg viewBox="0 0 100 100">

          <defs>
          <symbol id="A" viewBox="0 0 100 100">
          <svg viewBox="0 0 100 100">
          <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>

          <symbol id="B" viewBox="0 0 512 512">
          <svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
          <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>
          </defs>

          <use xlink:href="#A" x="0" y="0" width="100" height="100" />
          <use xlink:href="#B" x="0" y="50" width="50" height="50" />

          </svg>





          UPDATE



          The OP comments that they can't remove the width and the height attributes from the inner SVG. In this case I need to add a few lines of JavaScript. First I need to get the size of the second SVG canvas in px.



          const pt = 96/72;
          let size = 512 * pt;


          Also I need to know the stroke width



          let strokeWidth = 30 * pt; 


          Next I need to reset the value for the viewBox attribute for the `#B``






          const pt = 96/72;
          let size = 512 * pt;
          let strokeWidth = 30 * pt;
          B.setAttributeNS(null,"viewBox", `-${strokeWidth/2} -${strokeWidth/2} ${size+strokeWidth} ${size+strokeWidth}`)

          <svg viewBox="0 0 100 100">

          <defs>
          <symbol id="A" viewBox="0 0 100 100">
          <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 100 100">
          <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>

          <symbol id="B" viewBox="0 0 512 512">
          <svg height="512pt" viewBox="0 0 512 512" width="512pt" xmlns="http://www.w3.org/2000/svg">
          <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>
          </defs>

          <use xlink:href="#A" x="0" y="0" width="100" height="100" />
          <use xlink:href="#B" x="0" y="50" width="50%" height="50%" />

          </svg>








          share|improve this answer


























          • Thank you. I'm trying to avoid doing exactly that however ... adds manual overhead and/or programming complexity to the process any time I make any changes at all to the inner svg. Is there no way to figure out how big the symbol viewbox needs to be to avoid truncation?

            – billmill
            Nov 26 '18 at 13:56











          • I think this is what I need -- that 96/72 ratio. The stroke width won't exist at all in the final analysis; I just put it there to make the boundaries of the space obvious. And I can't use javascript for reasons that are too complex to go into but since I am able to use groovy I should be set.

            – billmill
            Nov 26 '18 at 15:00











          • If you don't mind me asking, where does that 96/72 ratio come from?

            – billmill
            Nov 26 '18 at 15:00











          • 72pt = 1 inch. Also 96px = 1 inch. So 1pt = 96/72 px. And in SVG 1 user unit is 1px

            – enxaneta
            Nov 26 '18 at 15:08
















          1














          Remove the width and the height attributes from the inner SVG






          svg{width:90vh}

          <svg viewBox="0 0 100 100">

          <defs>
          <symbol id="A" viewBox="0 0 100 100">
          <svg viewBox="0 0 100 100">
          <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>

          <symbol id="B" viewBox="0 0 512 512">
          <svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
          <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>
          </defs>

          <use xlink:href="#A" x="0" y="0" width="100" height="100" />
          <use xlink:href="#B" x="0" y="50" width="50" height="50" />

          </svg>





          UPDATE



          The OP comments that they can't remove the width and the height attributes from the inner SVG. In this case I need to add a few lines of JavaScript. First I need to get the size of the second SVG canvas in px.



          const pt = 96/72;
          let size = 512 * pt;


          Also I need to know the stroke width



          let strokeWidth = 30 * pt; 


          Next I need to reset the value for the viewBox attribute for the `#B``






          const pt = 96/72;
          let size = 512 * pt;
          let strokeWidth = 30 * pt;
          B.setAttributeNS(null,"viewBox", `-${strokeWidth/2} -${strokeWidth/2} ${size+strokeWidth} ${size+strokeWidth}`)

          <svg viewBox="0 0 100 100">

          <defs>
          <symbol id="A" viewBox="0 0 100 100">
          <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 100 100">
          <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>

          <symbol id="B" viewBox="0 0 512 512">
          <svg height="512pt" viewBox="0 0 512 512" width="512pt" xmlns="http://www.w3.org/2000/svg">
          <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>
          </defs>

          <use xlink:href="#A" x="0" y="0" width="100" height="100" />
          <use xlink:href="#B" x="0" y="50" width="50%" height="50%" />

          </svg>








          share|improve this answer


























          • Thank you. I'm trying to avoid doing exactly that however ... adds manual overhead and/or programming complexity to the process any time I make any changes at all to the inner svg. Is there no way to figure out how big the symbol viewbox needs to be to avoid truncation?

            – billmill
            Nov 26 '18 at 13:56











          • I think this is what I need -- that 96/72 ratio. The stroke width won't exist at all in the final analysis; I just put it there to make the boundaries of the space obvious. And I can't use javascript for reasons that are too complex to go into but since I am able to use groovy I should be set.

            – billmill
            Nov 26 '18 at 15:00











          • If you don't mind me asking, where does that 96/72 ratio come from?

            – billmill
            Nov 26 '18 at 15:00











          • 72pt = 1 inch. Also 96px = 1 inch. So 1pt = 96/72 px. And in SVG 1 user unit is 1px

            – enxaneta
            Nov 26 '18 at 15:08














          1












          1








          1







          Remove the width and the height attributes from the inner SVG






          svg{width:90vh}

          <svg viewBox="0 0 100 100">

          <defs>
          <symbol id="A" viewBox="0 0 100 100">
          <svg viewBox="0 0 100 100">
          <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>

          <symbol id="B" viewBox="0 0 512 512">
          <svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
          <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>
          </defs>

          <use xlink:href="#A" x="0" y="0" width="100" height="100" />
          <use xlink:href="#B" x="0" y="50" width="50" height="50" />

          </svg>





          UPDATE



          The OP comments that they can't remove the width and the height attributes from the inner SVG. In this case I need to add a few lines of JavaScript. First I need to get the size of the second SVG canvas in px.



          const pt = 96/72;
          let size = 512 * pt;


          Also I need to know the stroke width



          let strokeWidth = 30 * pt; 


          Next I need to reset the value for the viewBox attribute for the `#B``






          const pt = 96/72;
          let size = 512 * pt;
          let strokeWidth = 30 * pt;
          B.setAttributeNS(null,"viewBox", `-${strokeWidth/2} -${strokeWidth/2} ${size+strokeWidth} ${size+strokeWidth}`)

          <svg viewBox="0 0 100 100">

          <defs>
          <symbol id="A" viewBox="0 0 100 100">
          <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 100 100">
          <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>

          <symbol id="B" viewBox="0 0 512 512">
          <svg height="512pt" viewBox="0 0 512 512" width="512pt" xmlns="http://www.w3.org/2000/svg">
          <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>
          </defs>

          <use xlink:href="#A" x="0" y="0" width="100" height="100" />
          <use xlink:href="#B" x="0" y="50" width="50%" height="50%" />

          </svg>








          share|improve this answer















          Remove the width and the height attributes from the inner SVG






          svg{width:90vh}

          <svg viewBox="0 0 100 100">

          <defs>
          <symbol id="A" viewBox="0 0 100 100">
          <svg viewBox="0 0 100 100">
          <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>

          <symbol id="B" viewBox="0 0 512 512">
          <svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
          <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>
          </defs>

          <use xlink:href="#A" x="0" y="0" width="100" height="100" />
          <use xlink:href="#B" x="0" y="50" width="50" height="50" />

          </svg>





          UPDATE



          The OP comments that they can't remove the width and the height attributes from the inner SVG. In this case I need to add a few lines of JavaScript. First I need to get the size of the second SVG canvas in px.



          const pt = 96/72;
          let size = 512 * pt;


          Also I need to know the stroke width



          let strokeWidth = 30 * pt; 


          Next I need to reset the value for the viewBox attribute for the `#B``






          const pt = 96/72;
          let size = 512 * pt;
          let strokeWidth = 30 * pt;
          B.setAttributeNS(null,"viewBox", `-${strokeWidth/2} -${strokeWidth/2} ${size+strokeWidth} ${size+strokeWidth}`)

          <svg viewBox="0 0 100 100">

          <defs>
          <symbol id="A" viewBox="0 0 100 100">
          <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 100 100">
          <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>

          <symbol id="B" viewBox="0 0 512 512">
          <svg height="512pt" viewBox="0 0 512 512" width="512pt" xmlns="http://www.w3.org/2000/svg">
          <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>
          </defs>

          <use xlink:href="#A" x="0" y="0" width="100" height="100" />
          <use xlink:href="#B" x="0" y="50" width="50%" height="50%" />

          </svg>








          svg{width:90vh}

          <svg viewBox="0 0 100 100">

          <defs>
          <symbol id="A" viewBox="0 0 100 100">
          <svg viewBox="0 0 100 100">
          <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>

          <symbol id="B" viewBox="0 0 512 512">
          <svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
          <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>
          </defs>

          <use xlink:href="#A" x="0" y="0" width="100" height="100" />
          <use xlink:href="#B" x="0" y="50" width="50" height="50" />

          </svg>





          svg{width:90vh}

          <svg viewBox="0 0 100 100">

          <defs>
          <symbol id="A" viewBox="0 0 100 100">
          <svg viewBox="0 0 100 100">
          <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>

          <symbol id="B" viewBox="0 0 512 512">
          <svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
          <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>
          </defs>

          <use xlink:href="#A" x="0" y="0" width="100" height="100" />
          <use xlink:href="#B" x="0" y="50" width="50" height="50" />

          </svg>





          const pt = 96/72;
          let size = 512 * pt;
          let strokeWidth = 30 * pt;
          B.setAttributeNS(null,"viewBox", `-${strokeWidth/2} -${strokeWidth/2} ${size+strokeWidth} ${size+strokeWidth}`)

          <svg viewBox="0 0 100 100">

          <defs>
          <symbol id="A" viewBox="0 0 100 100">
          <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 100 100">
          <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>

          <symbol id="B" viewBox="0 0 512 512">
          <svg height="512pt" viewBox="0 0 512 512" width="512pt" xmlns="http://www.w3.org/2000/svg">
          <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>
          </defs>

          <use xlink:href="#A" x="0" y="0" width="100" height="100" />
          <use xlink:href="#B" x="0" y="50" width="50%" height="50%" />

          </svg>





          const pt = 96/72;
          let size = 512 * pt;
          let strokeWidth = 30 * pt;
          B.setAttributeNS(null,"viewBox", `-${strokeWidth/2} -${strokeWidth/2} ${size+strokeWidth} ${size+strokeWidth}`)

          <svg viewBox="0 0 100 100">

          <defs>
          <symbol id="A" viewBox="0 0 100 100">
          <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 100 100">
          <rect width="100%" height="100%" style="fill:rgb(255,0,0);stroke-width:3; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>

          <symbol id="B" viewBox="0 0 512 512">
          <svg height="512pt" viewBox="0 0 512 512" width="512pt" xmlns="http://www.w3.org/2000/svg">
          <rect width="100%" height="100%" style="fill:rgb(0,0,255);stroke-width:30; stroke:rgb(0,0,0)" />
          </svg>

          </symbol>
          </defs>

          <use xlink:href="#A" x="0" y="0" width="100" height="100" />
          <use xlink:href="#B" x="0" y="50" width="50%" height="50%" />

          </svg>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 26 '18 at 14:48

























          answered Nov 26 '18 at 12:45









          enxanetaenxaneta

          7,4342517




          7,4342517













          • Thank you. I'm trying to avoid doing exactly that however ... adds manual overhead and/or programming complexity to the process any time I make any changes at all to the inner svg. Is there no way to figure out how big the symbol viewbox needs to be to avoid truncation?

            – billmill
            Nov 26 '18 at 13:56











          • I think this is what I need -- that 96/72 ratio. The stroke width won't exist at all in the final analysis; I just put it there to make the boundaries of the space obvious. And I can't use javascript for reasons that are too complex to go into but since I am able to use groovy I should be set.

            – billmill
            Nov 26 '18 at 15:00











          • If you don't mind me asking, where does that 96/72 ratio come from?

            – billmill
            Nov 26 '18 at 15:00











          • 72pt = 1 inch. Also 96px = 1 inch. So 1pt = 96/72 px. And in SVG 1 user unit is 1px

            – enxaneta
            Nov 26 '18 at 15:08



















          • Thank you. I'm trying to avoid doing exactly that however ... adds manual overhead and/or programming complexity to the process any time I make any changes at all to the inner svg. Is there no way to figure out how big the symbol viewbox needs to be to avoid truncation?

            – billmill
            Nov 26 '18 at 13:56











          • I think this is what I need -- that 96/72 ratio. The stroke width won't exist at all in the final analysis; I just put it there to make the boundaries of the space obvious. And I can't use javascript for reasons that are too complex to go into but since I am able to use groovy I should be set.

            – billmill
            Nov 26 '18 at 15:00











          • If you don't mind me asking, where does that 96/72 ratio come from?

            – billmill
            Nov 26 '18 at 15:00











          • 72pt = 1 inch. Also 96px = 1 inch. So 1pt = 96/72 px. And in SVG 1 user unit is 1px

            – enxaneta
            Nov 26 '18 at 15:08

















          Thank you. I'm trying to avoid doing exactly that however ... adds manual overhead and/or programming complexity to the process any time I make any changes at all to the inner svg. Is there no way to figure out how big the symbol viewbox needs to be to avoid truncation?

          – billmill
          Nov 26 '18 at 13:56





          Thank you. I'm trying to avoid doing exactly that however ... adds manual overhead and/or programming complexity to the process any time I make any changes at all to the inner svg. Is there no way to figure out how big the symbol viewbox needs to be to avoid truncation?

          – billmill
          Nov 26 '18 at 13:56













          I think this is what I need -- that 96/72 ratio. The stroke width won't exist at all in the final analysis; I just put it there to make the boundaries of the space obvious. And I can't use javascript for reasons that are too complex to go into but since I am able to use groovy I should be set.

          – billmill
          Nov 26 '18 at 15:00





          I think this is what I need -- that 96/72 ratio. The stroke width won't exist at all in the final analysis; I just put it there to make the boundaries of the space obvious. And I can't use javascript for reasons that are too complex to go into but since I am able to use groovy I should be set.

          – billmill
          Nov 26 '18 at 15:00













          If you don't mind me asking, where does that 96/72 ratio come from?

          – billmill
          Nov 26 '18 at 15:00





          If you don't mind me asking, where does that 96/72 ratio come from?

          – billmill
          Nov 26 '18 at 15:00













          72pt = 1 inch. Also 96px = 1 inch. So 1pt = 96/72 px. And in SVG 1 user unit is 1px

          – enxaneta
          Nov 26 '18 at 15:08





          72pt = 1 inch. Also 96px = 1 inch. So 1pt = 96/72 px. And in SVG 1 user unit is 1px

          – enxaneta
          Nov 26 '18 at 15:08


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53471283%2fin-nested-svg-inner-icon-is-getting-truncated%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Contact image not getting when fetch all contact list from iPhone by CNContact

          count number of partitions of a set with n elements into k subsets

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks