Vertical panel seems to ignore lower margin on resize

I have a simple “entity” node created using an Auto panel and a couple of Vertical panels as shown:
image

The surrounding rectangle has a thick border or width 5 and the
the light blue area is a vertical panel with a margin of 10 (revealing the light background of the surrounding rectangle).

I have two problems:

  1. the margin of 10, appears inconsistent . I have 5 at the top, 7.5 on the sides (I think) and 10 on the bottom.
  2. when a resize the node to make it smaller ( I may wish to to this if a have a long attribute list and dont want the node to be draw really long) the bottom margin and border disappear as follows which looks ugly as follows.

image

The behavior seems to be related to the Vertical Panel because I note the sample ER daigram that uses a table panel doesnt do this.

How can I preserve the border and margin when I resize the node?

Code here:

<!DOCTYPE html>
<html lang="en">

<head>

  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover" />


  <script src="https://unpkg.com/gojs/release/go-debug.js"></script>
  <script lang="javascript" src="https://unpkg.com/xlsx/dist/xlsx.full.min.js"></script>


  <script>

    // Global variables
    var myDiagram;



    function init() {

      var $$ = go.GraphObject.make;  // for conciseness in defining templates

      var myDiagram = $$(go.Diagram, "myDiagramDiv"
        , {
          allowDrop: true
          , allowDelete: true
          , allowCopy: true
          , "grid.visible": true
        }
      );


      var attributeTemplate =

        $$(go.Panel, "Vertical",
          {
            name: "Inside Vertical Panel"
            , background: "transparent"
            , stretch: go.GraphObject.Horizontal
            , alignment: go.Spot.TopLeft
            , defaultAlignment: go.Spot.Left
          },


          $$(go.Panel, // This is meant to be "Horizontal" , however if you make it horizontal it seems to stuff up the margin to the right when you minimize
            {
              name: "Horizontal Panel"
              , stretch: go.GraphObject.Horizontal
              , background: "white"

            },

            $$(go.Shape,
              {
                desiredSize: new go.Size(15, 15)
                , strokeJoin: "round", strokeWidth: 2
                , margin: go.Margin.parse("2 4 2 2") // t,r,b,l
                , stroke: null, cursor: "default"
              },
            ),

            $$(go.TextBlock,
              {
                stroke: "#333333"
                , font: "bold 14px sans-serif"
                , editable: true
                , cursor: "default"
                , margin: new go.Margin(2, 2, 2, 23)  // t,r,b,l
                , height: 18
                , verticalAlignment: go.Spot.Center
                , alignment: go.Spot.TopLeft
              },
              new go.Binding("text", "attributeName").makeTwoWay()
            )
          ) // end of Horizontal Panel 
          //  , attributeSeparator 
        ); // end of vertical  Panel 




      var entityTemplate =
        $$(go.Node, "Auto"
          , {
            resizable: true
            , height: 150
          }

          , $$(go.Shape
            , {
              name: "PORTSHAPE"
              , figure: "Rectangle"
              , strokeWidth: 5
              , stretch: go.GraphObject.Fill
              , fill: "lightgray"
            }

          )

          , $$(go.Panel, "Vertical",
            {
              margin: 10
              , background: "lightblue"
              , stretch: go.GraphObject.Fill
              , alignment: go.Spot.TopCenter
            }

            , $$(go.TextBlock,
              {
                name: "textBlockTitle"
                , cursor: "default"
                , alignment: go.Spot.Center
                , textAlign: "center"
                , margin: new go.Margin(5, 13, 5, 5)  // t,r,b,l
                , stretch: go.GraphObject.Horizontal
                , font: "18px sans-serif"
                , editable: true
                , text: "Node Title"
                , background: "transparent"
              }

            )
            //, attributeSeparator 
            , $$(go.Shape, "LineH",
              {
                height: 1
                , stretch: go.GraphObject.Horizontal
                , cursor: "crosshair"
                , margin: new go.Margin(0, 5, 0, 5)  // t,r,b,l
                , stroke: "transparent"
                , strokeWidth: 1
                , strokeCap: "square"
                , name: "SEPARATOR"
              }
            )


            , $$(go.Panel, "Vertical"
              , {
                name: "ATTRIBUTEPANEL"
                , cursor: "default"
                , alignment: go.Spot.TopCenter
                , margin: new go.Margin(0, 5, 5, 5) // t,r,b,l
                , stretch: go.GraphObject.Fill
                , background: "transparent"
                , itemTemplate: attributeTemplate
              }
              , new go.Binding("itemArray", "attributes")

            )
          ) // end Vertical panel

        );


      var nodeDataArray = [
        { key: "Node 1", nodeTitle: "short title", loc: new go.Point(0, 200), attributes: [{attributeName: "One"},{attributeName: "Two"}, {attributeName: "Three"} ] },

      ];

      myDiagram.nodeTemplate = entityTemplate;
      myDiagram.model = new go.GraphLinksModel(nodeDataArray);

    }  // end init()

    window.addEventListener('DOMContentLoaded', init);

  </script>

</head>

<body>

  <div id="myDiagramDiv" style="border: solid 1px blue; width:1000px; height:1000px"></div>

</body>

</html>

while you set the Panel alignment TopCenter,set it to Center,the margin can be look the same

$$(go.Panel, "Vertical",
            {
              margin: 10
              , background: "lightblue"
              , stretch: go.GraphObject.Fill
              , alignment: go.Spot.Center
            }

the second problem, you can set a minSize to the Node to fixed it such as

$$(go.Node, "Auto"
			  , {
				minSize:new go.Size(130,150),
				resizable: true
				, height: 150
			  }

Thanks Gunmo. Tried that. Its actually not great.
I made those two changes and added a couple more attributes:
Heres what you get:
image

Now its obscuring both the top and bottom borders: which is why I used TopCenter. I want the NodeTitle to always be displayed in its correct position.
I can’t use minSize. The whole point is the user should be able to size the Node however they like.

Here’s one way you could accomplish what I think you want:

      var attributeTemplate =
        $$(go.Panel, "Horizontal",
          {
            name: "Horizontal Panel",
            background: "white",
            height: 18,
            stretch: go.GraphObject.Fill
          },
          $$(go.Shape,
            {
              desiredSize: new go.Size(15, 15),
              strokeJoin: "round", strokeWidth: 0,
              margin: new go.Margin(2, 4, 2, 2),
              cursor: "default"
            },
          ),
          $$(go.TextBlock,
            {
              stroke: "#333333",
              font: "bold 14px sans-serif",
              editable: true,
              margin: 2,
              verticalAlignment: go.Spot.Center,
              textAlign: "left"
            },
            new go.Binding("text", "attributeName").makeTwoWay()
          )
        ); // end of Horizontal Panel

      var marg = 10;

      // a resize adornment for the "VERT" panel, with handles near the edge of the whole node
      var resizeAdorn = 
        $$(go.Adornment, "Spot",
          { locationSpot: go.Spot.Center },
          $$(go.Placeholder, { margin: 10 }),
          $$(go.Shape, { alignment: new go.Spot(0, 0, -marg, -marg), cursor: "nw-resize", desiredSize: new go.Size(6, 6), fill: "lightblue", stroke: "dodgerblue" }),
          $$(go.Shape, { alignment: new go.Spot(.5, 0, 0, -marg), cursor: "n-resize", desiredSize: new go.Size(6, 6), fill: "lightblue", stroke: "dodgerblue" }),
          $$(go.Shape, { alignment: new go.Spot(1, 0, marg, -marg), cursor: "ne-resize", desiredSize: new go.Size(6, 6), fill: "lightblue", stroke: "dodgerblue" }),

          $$(go.Shape, { alignment: new go.Spot(0, .5, -marg, 0), cursor: "w-resize", desiredSize: new go.Size(6, 6), fill: "lightblue", stroke: "dodgerblue" }),
          $$(go.Shape, { alignment: new go.Spot(1, .5, marg, 0), cursor: "e-resize", desiredSize: new go.Size(6, 6), fill: "lightblue", stroke: "dodgerblue" }),

          $$(go.Shape, { alignment: new go.Spot(0, 1, -marg, marg), cursor: "se-resize", desiredSize: new go.Size(6, 6), fill: "lightblue", stroke: "dodgerblue" }),
          $$(go.Shape, { alignment: new go.Spot(.5, 1, 0, marg), cursor: "s-resize", desiredSize: new go.Size(6, 6), fill: "lightblue", stroke: "dodgerblue" }),
          $$(go.Shape, { alignment: new go.Spot(1, 1, marg, marg), cursor: "sw-resize", desiredSize: new go.Size(6, 6), fill: "lightblue", stroke: "dodgerblue" })
        );

      var entityTemplate =
        $$(go.Node, "Auto",
          {
            resizable: true, resizeObjectName: "VERT",
            resizeAdornmentTemplate: resizeAdorn
          },
          $$(go.Shape, "Rectangle",
            {
              name: "PORTSHAPE",
              strokeWidth: 5,
              fill: "lightgray"
            }
          ),
          $$(go.Panel, "Vertical",
            {
              name: "VERT",
              margin: marg,
              background: "lightblue",
              minSize: new go.Size(100, 150)
            },
            $$(go.TextBlock,
              {
                name: "textBlockTitle",
                cursor: "default",
                alignment: go.Spot.Center,
                textAlign: "center",
                margin: new go.Margin(5, 13, 5, 5),  // t,r,b,l
                font: "18px sans-serif",
                editable: true,
                text: "Node Title",
              }
            ),
            //attributeSeparator,
            $$(go.Shape, "LineH",
              {
                height: 1,
                stretch: go.GraphObject.Horizontal,
                cursor: "crosshair",
                margin: new go.Margin(0, 5, 0, 5),  // t,r,b,l
                stroke: "black",
                strokeWidth: 1,
                strokeCap: "square",
                name: "SEPARATOR",
              }
            ),
            $$(go.Panel, "Vertical",
              {
                name: "ATTRIBUTEPANEL",
                stretch: go.GraphObject.Fill,
                itemTemplate: attributeTemplate
              },
              new go.Binding("itemArray", "attributes")
            )
          ) // end Vertical panel
        );

The minSize is set on the Vertical Panel (“VERT”), and “VERT” also acts as the resizing object. There’s a custom resize adornment, to keep the resize handles near the node edges instead of the edges of “VERT”.

Hi JHardy. Thanks for the suggestion.
I’ve solved it slightly differently by simply by adding a height binding onto the light blue vertical panel as follows:

new go.Binding("height", "height", (h)=>h-20).ofObject()

This simply forces the Panel height to be 20 less than the whole Node (allow for margin of 10 on top and bottom).

I still dont now why the top/bottom margins are ignored for Vertical panels. Doesnt seem right to me, but at least this solution works.