SVG is rendering with white space

Hi,

We’re using GoJS to render the SVG, but we’re getting white space during the rendering. Please see the screenshot below.

image

Please check the node template code

 $(go.Node, 'Spot', { rotatable: true, selectionObjectName: "PIC"},
        {
          contextMenu:
            $('ContextMenu',
              $('ContextMenuButton',
                $(go.TextBlock, 'Group'),
                { click: function(e, obj) { e.diagram.commandHandler.groupSelection(); } },
                new go.Binding('visible', '', function(o) {
                  return o.diagram.selection.count > 1;
                }).ofObject()),
              $('ContextMenuButton',
                $(go.TextBlock, 'SubSheet'),
                {
                  click: function (e, obj)
                  {
                    console.log(this.showDialog);
                    console.log(e);
                    console.log(obj);
                  }

                },
                new go.Binding('visible', '', function (o) {
                  return o.diagram.selection.count == 1;
                }).ofObject())
            )
        },
        new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify),
        $(go.Panel, 'Auto',
          {
            doubleClick: function (e, obj)
            {
            }
          },
          $(go.Shape, 'RoundedRectangle', {
            width: 40,
            height: 40, stroke: null,
            fromLinkable: true, fromLinkableSelfNode: false, fromLinkableDuplicates: false,
            toLinkable: true, toLinkableSelfNode: false, toLinkableDuplicates: false
          },

            new go.Binding('fill', 'color', (c, panel) => {
             
              return c;
            })
          ),

          $(go.TextBlock, {
            margin: 0, editable: true },
            new go.Binding('text').makeTwoWay()),
          $(go.Picture,
            {
              //desiredSize: new go.Size(50, 50),
              alignment: go.Spot.Center,
              width: 75,
              height: 75,
            //},
            },
            new go.Binding("source"),
            {
              click: function (e, obj)
              {
               
              }
          })
        ),
        // Ports
        makePort('t', go.Spot.TopCenter,false,true),
        makePort('l', go.Spot.Left, true, true),
        makePort('r', go.Spot.Right, true, true),
        makePort('b', go.Spot.BottomCenter, true, false),
        { // handle mouse enter/leave events to show/hide the ports
          mouseEnter: (e, node) => showSmallPorts(node, true),
          mouseLeave: (e, node) => showSmallPorts(node, false)
        }
      );

Please check the SVG image template

If that screenshot shows what you are getting, what are you expecting?
What is the SVG file being shown?

I am not able to add the SVG file…

Please check the expected look and feel

image

Thanks. Just post the contents of the SVG file. It’s just text.

It is not allowing me to add the svg file or text

Please check this SVG content

An image of text won’t help me try to reproduce the problem.

Please post the text surrounded by lines consisting of only triple backquotes.

<svg width="150" height="123" viewBox="0 0 150 123" width="75" height="75" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M59.5 0H58.6716L58.0858 0.585786L35.5858 23.0858L35 23.6716V24.5V56.5V57.3471L35.6084 57.9365L57.8019 79.4365L58 79.6284V102.872H43.5H27H25V104.872V121V123H27H123H125V121V104.872V102.872H123H107H93V79.8192L93.3979 79.4304L115.398 57.9304L116 57.3419V56.5V24.5V23.6716L115.414 23.0858L92.9142 0.585786L92.3284 0H91.5H59.5ZM89 80H62V104.872V106.872H60H43.5H29V119H121V106.872H107H91H89V104.872V80ZM39 25.3284L60.3284 4H90.6716L112 25.3284V55.6581L91.185 76H60.0034L39 55.6529V25.3284Z" fill="#0066D0"/>
<path d="M76.6814 44.19V39.0844L95 39.0548V55.2025C92.1878 57.4584 89.2871 59.1603 86.2979 60.308C83.3088 61.436 80.2409 62 77.0944 62C72.8466 62 68.9823 61.0897 65.5015 59.2691C62.0403 57.4288 59.4248 54.777 57.6549 51.314C55.885 47.8509 55 43.9822 55 39.7078C55 35.473 55.8751 31.5251 57.6254 27.8641C59.3953 24.1834 61.9322 21.4525 65.236 19.6715C68.5398 17.8905 72.3451 17 76.6519 17C79.7788 17 82.6008 17.5145 85.118 18.5435C87.6549 19.5528 89.6411 20.9677 91.0767 22.7883C92.5123 24.6088 93.6037 26.9835 94.351 29.9123L89.1888 31.3371C88.5398 29.1207 87.7335 27.3793 86.7699 26.1128C85.8063 24.8463 84.4297 23.8371 82.6401 23.0851C80.8505 22.3133 78.8643 21.9274 76.6814 21.9274C74.0659 21.9274 71.8043 22.3331 69.8968 23.1445C67.9892 23.936 66.4454 24.9848 65.2655 26.2909C64.1052 27.597 63.2006 29.0317 62.5516 30.595C61.4503 33.2863 60.8997 36.2051 60.8997 39.3516C60.8997 43.2302 61.5585 46.4756 62.8761 49.0877C64.2134 51.6999 66.1504 53.6392 68.6873 54.9057C71.2242 56.1722 73.9184 56.8054 76.7699 56.8054C79.2478 56.8054 81.6667 56.3305 84.0266 55.3806C86.3864 54.4109 88.176 53.3819 89.3953 52.2935V44.19H76.6814Z" fill="#0066D0"/>
<path d="M42.1716 39.5001L22.5 59.1716L2.82843 39.5001L22.5 19.8285L42.1716 39.5001Z" fill="#008000" stroke="#8B0000" stroke-width="4"/>
<path d="M42.1716 39.5001L22.5 59.1716L2.82843 39.5001L22.5 19.8285L42.1716 39.5001Z" fill="#008000" stroke="#8B0000" stroke-width="4"/>
<path d="M127.5 59.5001L107.5 39.5001L127.5 19.5001L147.5 39.5001L127.5 59.5001Z" fill="#008000" stroke="#8B0000" stroke-width="3.53553"/>
<path d="M106 99.7541L80 115V97.5721L80 85L106 99.7541Z" fill="#231F20"/>
<path d="M44 99.2623H81" stroke="#231F20" stroke-width="4" stroke-miterlimit="10"/>
</svg>

This SVG is actually invalid (Attribute width and height are redefined, and I’m surprised it would display anything at all:

<svg width=“150” height=“123” viewBox=“0 0 150 123” width=“75” height=“75” fill=“none”

If I remove one of those, I get something like this with your template:

image

Which is very different from your original image.

I think the problem, in your original post, is that you have a rounded rectangle that is larger than your SVG icon. It only appears to be white space, but it’s the real size of the Shape that is in your template.

I have made below changes and it looks like this

Code: -
$(go.Shape, ‘RoundedRectangle’, {
width: 45,
height: 45, stroke: null,
fromLinkable: true, fromLinkableSelfNode: false, fromLinkableDuplicates: false,
toLinkable: true, toLinkableSelfNode: false, toLinkableDuplicates: false
},

$(go.Picture,
{
//desiredSize: new go.Size(50, 50),
alignment: go.Spot.Center,
width: 50,
height: 50,
//},
},

Snippet

<svg width="160" height="160" viewBox="0 0 150 123" fill="none" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" clip-rule="evenodd" d="M59.5 0H58.6716L58.0858 0.585786L35.5858 23.0858L35 23.6716V24.5V56.5V57.3471L35.6084 57.9365L57.8019 79.4365L58 79.6284V102.872H43.5H27H25V104.872V121V123H27H123H125V121V104.872V102.872H123H107H93V79.8192L93.3979 79.4304L115.398 57.9304L116 57.3419V56.5V24.5V23.6716L115.414 23.0858L92.9142 0.585786L92.3284 0H91.5H59.5ZM89 80H62V104.872V106.872H60H43.5H29V119H121V106.872H107H91H89V104.872V80ZM39 25.3284L60.3284 4H90.6716L112 25.3284V55.6581L91.185 76H60.0034L39 55.6529V25.3284Z" fill="#0066D0"/> <path d="M76.6814 44.19V39.0844L95 39.0548V55.2025C92.1878 57.4584 89.2871 59.1603 86.2979 60.308C83.3088 61.436 80.2409 62 77.0944 62C72.8466 62 68.9823 61.0897 65.5015 59.2691C62.0403 57.4288 59.4248 54.777 57.6549 51.314C55.885 47.8509 55 43.9822 55 39.7078C55 35.473 55.8751 31.5251 57.6254 27.8641C59.3953 24.1834 61.9322 21.4525 65.236 19.6715C68.5398 17.8905 72.3451 17 76.6519 17C79.7788 17 82.6008 17.5145 85.118 18.5435C87.6549 19.5528 89.6411 20.9677 91.0767 22.7883C92.5123 24.6088 93.6037 26.9835 94.351 29.9123L89.1888 31.3371C88.5398 29.1207 87.7335 27.3793 86.7699 26.1128C85.8063 24.8463 84.4297 23.8371 82.6401 23.0851C80.8505 22.3133 78.8643 21.9274 76.6814 21.9274C74.0659 21.9274 71.8043 22.3331 69.8968 23.1445C67.9892 23.936 66.4454 24.9848 65.2655 26.2909C64.1052 27.597 63.2006 29.0317 62.5516 30.595C61.4503 33.2863 60.8997 36.2051 60.8997 39.3516C60.8997 43.2302 61.5585 46.4756 62.8761 49.0877C64.2134 51.6999 66.1504 53.6392 68.6873 54.9057C71.2242 56.1722 73.9184 56.8054 76.7699 56.8054C79.2478 56.8054 81.6667 56.3305 84.0266 55.3806C86.3864 54.4109 88.176 53.3819 89.3953 52.2935V44.19H76.6814Z" fill="#0066D0"/> <path d="M42.1716 39.5001L22.5 59.1716L2.82843 39.5001L22.5 19.8285L42.1716 39.5001Z" fill="#008000" stroke="#8B0000" stroke-width="4"/> <path d="M42.1716 39.5001L22.5 59.1716L2.82843 39.5001L22.5 19.8285L42.1716 39.5001Z" fill="#008000" stroke="#8B0000" stroke-width="4"/> <path d="M127.5 59.5001L107.5 39.5001L127.5 19.5001L147.5 39.5001L127.5 59.5001Z" fill="#008000" stroke="#8B0000" stroke-width="3.53553"/> <path d="M106 99.7541L80 115V97.5721L80 85L106 99.7541Z" fill="#231F20"/> <path d="M44 99.2623H81" stroke="#231F20" stroke-width="4" stroke-miterlimit="10"/> </svg>

image

I made some changes in SVG but a small gap is present
Snippet

<svg width="140" height="190" viewBox="0 0 160 90" fill="none" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" clip-rule="evenodd" d="M59.5 0H58.6716L58.0858 0.585786L35.5858 23.0858L35 23.6716V24.5V56.5V57.3471L35.6084 57.9365L57.8019 79.4365L58 79.6284V102.872H43.5H27H25V104.872V121V123H27H123H125V121V104.872V102.872H123H107H93V79.8192L93.3979 79.4304L115.398 57.9304L116 57.3419V56.5V24.5V23.6716L115.414 23.0858L92.9142 0.585786L92.3284 0H91.5H59.5ZM89 80H62V104.872V106.872H60H43.5H29V119H121V106.872H107H91H89V104.872V80ZM39 25.3284L60.3284 4H90.6716L112 25.3284V55.6581L91.185 76H60.0034L39 55.6529V25.3284Z" fill="#0066D0"/> <path d="M76.6814 44.19V39.0844L95 39.0548V55.2025C92.1878 57.4584 89.2871 59.1603 86.2979 60.308C83.3088 61.436 80.2409 62 77.0944 62C72.8466 62 68.9823 61.0897 65.5015 59.2691C62.0403 57.4288 59.4248 54.777 57.6549 51.314C55.885 47.8509 55 43.9822 55 39.7078C55 35.473 55.8751 31.5251 57.6254 27.8641C59.3953 24.1834 61.9322 21.4525 65.236 19.6715C68.5398 17.8905 72.3451 17 76.6519 17C79.7788 17 82.6008 17.5145 85.118 18.5435C87.6549 19.5528 89.6411 20.9677 91.0767 22.7883C92.5123 24.6088 93.6037 26.9835 94.351 29.9123L89.1888 31.3371C88.5398 29.1207 87.7335 27.3793 86.7699 26.1128C85.8063 24.8463 84.4297 23.8371 82.6401 23.0851C80.8505 22.3133 78.8643 21.9274 76.6814 21.9274C74.0659 21.9274 71.8043 22.3331 69.8968 23.1445C67.9892 23.936 66.4454 24.9848 65.2655 26.2909C64.1052 27.597 63.2006 29.0317 62.5516 30.595C61.4503 33.2863 60.8997 36.2051 60.8997 39.3516C60.8997 43.2302 61.5585 46.4756 62.8761 49.0877C64.2134 51.6999 66.1504 53.6392 68.6873 54.9057C71.2242 56.1722 73.9184 56.8054 76.7699 56.8054C79.2478 56.8054 81.6667 56.3305 84.0266 55.3806C86.3864 54.4109 88.176 53.3819 89.3953 52.2935V44.19H76.6814Z" fill="#0066D0"/> <path d="M42.1716 39.5001L22.5 59.1716L2.82843 39.5001L22.5 19.8285L42.1716 39.5001Z" fill="#008000" stroke="#8B0000" stroke-width="4"/> <path d="M42.1716 39.5001L22.5 59.1716L2.82843 39.5001L22.5 19.8285L42.1716 39.5001Z" fill="#008000" stroke="#8B0000" stroke-width="4"/> <path d="M127.5 59.5001L107.5 39.5001L127.5 19.5001L147.5 39.5001L127.5 59.5001Z" fill="#008000" stroke="#8B0000" stroke-width="3.53553"/> <path d="M106 99.7541L80 115V97.5721L80 85L106 99.7541Z" fill="#231F20"/> <path d="M44 99.2623H81" stroke="#231F20" stroke-width="4" stroke-miterlimit="10"/> </svg>

image

Is there a reason to have a different width and height from the viewbox width and height?

Are those green diamonds with red border supposed to act as ports?
Because I noticed that you seem to have automatically appearing gray circles – are those not ports?