Node Template Structure

Hi team,
I need to create a node template to look like this.
also want to implement the expand & collapse functionality with lazy data loading on the expansion of node

image

Not able to implement as shown in the image.

myDiagram.nodeTemplate =
                $(go.Node, "Auto",
                    {
                        locationSpot: go.Spot.Top,
                        isShadowed: true, shadowBlur: 1,
                        shadowOffset: new go.Point(0, 1),
                        shadowColor: "rgba(0, 0, 0, .14)",
                        locationObjectName: "BODY",
                        click: showNodeDetailView,
                        selectionAdornmentTemplate:  // selection adornment to match shape of nodes
                            $(go.Adornment, "Auto",
                                $(go.Shape, "RoundedRectangle", roundedRectangleParams,
                                    { fill: null, stroke: "#7986cb", strokeWidth: 3 }
                                ),
                                $(go.Placeholder)
                            )  // end Adornment
                    },
                    new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify),
                    $(go.Shape, "RoundedRectangle", roundedRectangleParams,
                        { name: "SHAPE", fill: "#ffffff", strokeWidth: 2.5 },
                        // gold if highlighted, white otherwise
                        //new go.Binding("fill", "isHighlighted", function (h) { return h ? "gold" : "#ffffff"; }).ofObject()
                        new go.Binding("stroke", "highlight", function (h) {
                            return h ? "red" : "lightblue";
                        }),
                        new go.Binding("opacity").makeTwoWay(),
                        new go.Binding("stroke", "actionType", function (key) { return key === "Activity" || key === "RecordCreation" ? "lightblue" : "orange" }),
                    ),
                    $(go.Panel, "Vertical",
                        $(go.Panel, "Horizontal",
                            { margin: 8 },
                            $(go.Picture,  // flag image, only visible if a nation is specified
                                { margin: mr8, visible: false, desiredSize: new go.Size(50, 50) },
                                new go.Binding("source", "text", theNationFlagConverter),
                                new go.Binding("visible", "text", function (nat) { return nat !== undefined; })
                            ),
                            $(go.Panel, "Table",
                                $(go.TextBlock,
                                    {
                                        row: 0, alignment: go.Spot.Left,
                                        font: "bold small-caps 11pt helvetica, bold arial, sans-serif",
                                        stroke: "rgba(0, 0, 0, .87)",
                                        maxSize: new go.Size(300, NaN)
                                    },
                                    new go.Binding("opacity").makeTwoWay(),
                                    new go.Binding("text", "text")
                                ),
                                $(go.TextBlock, textStyle("title"),
                                    {
                                        row: 1, alignment: go.Spot.Left,
                                        maxSize: new go.Size(300, NaN)
                                    },
                                    new go.Binding("text", "text")
                                ),
                                $("PanelExpanderButton", "INFO",
                                    { row: 0, column: 2, rowSpan: 2, margin: ml8 }
                                )
                            )
                        ),
                        $(go.Shape, "LineH",
                            {
                                stroke: "rgba(0, 0, 0, .60)", strokeWidth: 1,
                                height: 1, stretch: go.GraphObject.Horizontal
                            },
                            new go.Binding("visible").ofObject("INFO")  // only visible when info is expanded
                        ),
                        $(go.Panel, "Vertical",
                            {
                                name: "INFO",  // identify to the PanelExpanderButton
                                // visible: false, //to set collapse as default 
                                stretch: go.GraphObject.Horizontal,  // take up whole available width
                                margin: 8,
                                defaultAlignment: go.Spot.Left,  // thus no need to specify alignment on each element
                            },
                            $(go.TextBlock, textStyle("headOf"),
                                new go.Binding("text", "headOf", function (head) { return "Head of: " + head; })
                            ),
                            $(go.TextBlock, textStyle("text"),
                                {
                                    font: "12pt helvetica, arial, sans-serif",
                                    stroke: "rgba(0, 1, 0, .87)",
                                },
                                new go.Binding("margin", "headOf", function (head) { return mt8; }), // some space above if there is also a headOf value
                                //new go.Binding("text", "text", function (boss) {
                                //    var boss = myDiagram.model.findNodeDataForKey(boss);
                                //    if (boss !== null) {
                                //        return "Reporting to: " + boss.text;
                                //    }
                                //    return "";
                                //})
                                new go.Binding("text", "nodeWeight", function (nodeWeight, curre) {
                                    debugger
                                    let panelData = `${dataFactory.currentVariantType} Count :  ${nFormatter(parseInt(nodeWeight), nodeWeight.toString().length)}\n
                                                       Frequency                Rework
                                                        Total Count:   12          Self Loop Count: 10 
                                                        Case count:      2        Loop Count: 20 
                                                        Case count (%) : 50
                                                    `;
                                    return panelData;
                                }).makeTwoWay()
                            )
                        )
                    )
                );

I think you want something like:

Node, "Spot"
  Panel, "Auto"
    Shape, "RoundedRectangle"
    Panel, "Table"
      Panel, "Table"
        . . . first three rows in four columns,
        . . . each cell a "Horizontal" Panel with a Picture and a TextBlock
      Panel, "Table"
        . . . two rows
      Panel, "Auto"
        Shape, "RoundedRectangle"  // filled blue
        TextBlock
        TextBlock
        "PanelExpanderButton"?
  Panel, "Auto"  // the expand/collapse button
    Shape, "Circle"
    Shape

Hi Walter,
Can you please help me in adding this to my above code?

myDiagram.nodeTemplate =
                $(go.Node, "Auto",
                    {
                        locationSpot: go.Spot.Top,
                        isShadowed: true, shadowBlur: 1,
                        shadowOffset: new go.Point(0, 1),
                        shadowColor: "rgba(0, 0, 0, .14)",
                        locationObjectName: "BODY",
                        click: showNodeDetailView,
                        selectionAdornmentTemplate:  // selection adornment to match shape of nodes
                            $(go.Adornment, "Auto",
                                $(go.Shape, "RoundedRectangle", roundedRectangleParams,
                                    { fill: null, stroke: "#7986cb", strokeWidth: 3 }
                                ),
                                $(go.Placeholder)
                            )  // end Adornment
                    },
                    new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify),
                    $(go.Shape, "RoundedRectangle", roundedRectangleParams,
                        { name: "SHAPE", fill: "#ffffff", strokeWidth: 2.5 },
                        // gold if highlighted, white otherwise
                        //new go.Binding("fill", "isHighlighted", function (h) { return h ? "gold" : "#ffffff"; }).ofObject()
                        new go.Binding("stroke", "highlight", function (h) {
                            return h ? "red" : "lightblue";
                        }),
                        new go.Binding("opacity").makeTwoWay(),
                        new go.Binding("stroke", "actionType", function (key) { return key === "Activity" || key === "RecordCreation" ? "lightblue" : "orange" }),
                    ),
                    $(go.Panel, "Vertical",
                        $(go.Panel, "Horizontal",
                            { margin: 8 },
                            $(go.Picture,  // flag image, only visible if a nation is specified
                                { margin: mr8, visible: false, desiredSize: new go.Size(50, 50) },
                                new go.Binding("source", "text", theNationFlagConverter),
                                new go.Binding("visible", "text", function (nat) { return nat !== undefined; })
                            ),
                            $(go.Panel, "Table",
                                $(go.TextBlock,
                                    {
                                        row: 0, alignment: go.Spot.Left,
                                        font: "bold small-caps 11pt helvetica, bold arial, sans-serif",
                                        stroke: "rgba(0, 0, 0, .87)",
                                        maxSize: new go.Size(300, NaN)
                                    },
                                    new go.Binding("opacity").makeTwoWay(),
                                    new go.Binding("text", "text")
                                ),
                                $(go.TextBlock, textStyle("title"),
                                    {
                                        row: 1, alignment: go.Spot.Left,
                                        maxSize: new go.Size(300, NaN)
                                    },
                                    new go.Binding("text", "text")
                                ),
                                $("PanelExpanderButton", "INFO",
                                    { row: 0, column: 2, rowSpan: 2, margin: ml8 }
                                )
                            )
                        ),
                        $(go.Shape, "LineH",
                            {
                                stroke: "rgba(0, 0, 0, .60)", strokeWidth: 1,
                                height: 1, stretch: go.GraphObject.Horizontal
                            },
                            new go.Binding("visible").ofObject("INFO")  // only visible when info is expanded
                        ),
                        $(go.Panel, "Vertical",
                            {
                                name: "INFO",  // identify to the PanelExpanderButton
                                // visible: false, //to set collapse as default 
                                stretch: go.GraphObject.Horizontal,  // take up whole available width
                                margin: 8,
                                defaultAlignment: go.Spot.Left,  // thus no need to specify alignment on each element
                            },
                            $(go.TextBlock, textStyle("headOf"),
                                new go.Binding("text", "headOf", function (head) { return "Head of: " + head; })
                            ),
                            $(go.TextBlock, textStyle("text"),
                                {
                                    font: "12pt helvetica, arial, sans-serif",
                                    stroke: "rgba(0, 1, 0, .87)",
                                },
                                new go.Binding("margin", "headOf", function (head) { return mt8; }), // some space above if there is also a headOf value
                                //new go.Binding("text", "text", function (boss) {
                                //    var boss = myDiagram.model.findNodeDataForKey(boss);
                                //    if (boss !== null) {
                                //        return "Reporting to: " + boss.text;
                                //    }
                                //    return "";
                                //})
                                new go.Binding("text", "nodeWeight", function (nodeWeight, curre) {
                                    debugger
                                    let panelData = `${dataFactory.currentVariantType} Count :  ${nFormatter(parseInt(nodeWeight), nodeWeight.toString().length)}\n
                                                       Frequency                Rework
                                                        Total Count:   12          Self Loop Count: 10 
                                                        Case count:      2        Loop Count: 20 
                                                        Case count (%) : 50
                                                    `;
                                    return panelData;
                                }).makeTwoWay()
                            )
                        )
                    )
                );

I haven’t added much in the way of data binding or styling:

  function makeInfo(name, icon, row, col) {
    return [
      $(go.Picture, icon,
        { row: row, column: 2*col, width: 14, height: 14, margin: 4, background: "lightgray" }),
      $(go.TextBlock, textStyle(),
        { row: row, column: 2*col+1, margin: 4 },
        new go.Binding("text", name))
    ]
  }

  function textStyle() { return { stroke: "gray" }; }

  myDiagram.nodeTemplate =
    $(go.Node, "Spot",
      $(go.Panel, "Auto",
        { width: 300 },
        $(go.Shape, "RoundedRectangle",
          { fill: "transparent", stroke: "gray",
            spot1: go.Spot.TopLeft, spot2: go.Spot.BottomRight }),
        $(go.Panel, "Table",
          { stretch: go.GraphObject.Fill,
            defaultStretch: go.GraphObject.Fill,
            defaultRowSeparatorStroke: "lightgray" },
          $(go.Panel, "Table", { row: 0 },
            { margin: 4, defaultAlignment: go.Spot.Left },
            $(go.RowColumnDefinition, { column: 0, sizing: go.RowColumnDefinition.None }),
            $(go.RowColumnDefinition, { column: 2, sizing: go.RowColumnDefinition.None }),
            makeInfo("prop1", "icon1.jpg", 0, 0),
            makeInfo("prop2", "icon2.jpg", 1, 0),
            makeInfo("prop3", "icon3.jpg", 1, 1),
            makeInfo("prop4", "icon4.jpg", 2, 0),
            makeInfo("prop5", "icon5.jpg", 2, 1),
          ),
          $(go.Panel, "Table", { row: 1 },
            { margin: 4 },
            $(go.TextBlock, "Next split by", textStyle(),
              { row: 0, alignment: go.Spot.Left, font: "bold 10pt sans-serif", margin: 4 }),
            $(go.Panel, "Table",
              { row: 1, stretch: go.GraphObject.Fill },
              $(go.TextBlock, "Best choice", { column: 0 }, textStyle()),
              $(go.TextBlock, "SupplierName", { column: 1 }, textStyle()),
              $(go.TextBlock, "123.456", { column: 2 }, textStyle()),
              $(go.TextBlock, "100.00%", { column: 3 }, textStyle()),
              $(go.Shape, "TriangleDown",
                { column: 4, width: 6, height: 5,
                  click: (e, shp) => {
                    const pan = shp.part.findObject("DETAILS");
                    e.diagram.commit(diag => {
                      pan.visible = !pan.visible;
                      shp.figure = pan.visible ? "TriangleUp" : "TriangleDown";
                    });
                  }
                })
            )
          ),
          $(go.Panel, "Auto",
            { row: 2 },
            $(go.Shape, "RoundedRectangle", { fill: "dodgerblue", strokeWidth: 0 }),
            $(go.TextBlock, "some time", { alignment: go.Spot.Left, stroke: "white", margin: 4 }),
            $(go.TextBlock, "id", { alignment: go.Spot.Right, stroke: "white", margin: 4 })
          )
        )
      ),
      $("TreeExpanderButton", { alignment: go.Spot.Bottom })
    );

  myDiagram.model = new go.GraphLinksModel(
  [
    { key: 1, prop0: 1234, prop1: 3, prop2: 123123123, prop3: 234234234, prop4: 345345345 },
    { key: 2, prop0: 1234, prop1: 3, prop2: 123123123, prop3: 234234234, prop4: 345345345 }
  ],
  [
    { from: 1, to: 2 }
  ]);