Spinanimation on Images

Hello

Since I am hitting a wall in this matter, I need your help for solving the following problem:

I got a node which contains a panel which contains an Image. The goal is to create a spinanimation on the image without changing the size of the panel. Refer to the image for better understanding:

bug

The Object in the middle has the following structure:

  var pumpTemplate =
                            $(go.Node, "Table",
                                {
                                    locationObjectName: "BODY",
                                    locationSpot: go.Spot.TopLeft,
                                    layoutConditions: go.Part.LayoutStandard & ~go.Part.LayoutNodeSized,
                                    selectionObjectName: "BODY",
                                    contextMenu: nodeMenuPorts,
                                    resizable: true,
                                    selectable: _.editMode,
                                    resizeObjectName: "image",
                                },
                                $(go.Panel, "Auto",
                                    {
                                        row: 1, column: 1, name: "BODY",
                                    },
                                    $(go.Picture, {
                                        source: "off.svg",
                                        name: "image",
                                        width: 100,
                                        height: 100,
                                    },
                                        new go.Binding("angle", "", (data) => { 
                                            return data.controlSettings.rotation;
                                        }),
										new go.Binding("desiredSize", "size").makeTwoWay())
                                ),
								//Stuff below are the ports
                                $(go.Panel, "Vertical",
                                    new go.Binding("itemArray", "leftArray"),
                                    {
                                        row: 1, column: 0,
                                        itemTemplate:
                                            $(go.Panel,
                                                {
                                                    _side: "left",  // internal property to make it easier to tell which side it's on
                                                    fromSpot: go.Spot.Left, toSpot: go.Spot.Left,
                                                    fromLinkable: true, toLinkable: true, cursor: "pointer",
                                                    contextMenu: portMenu
                                                },
                                                new go.Binding("portId", "portId"),
                                                $(go.Shape, "Rectangle",
                                                    {
                                                        stroke: null, strokeWidth: 0,
                                                        desiredSize: portSize,
                                                        margin: new go.Margin(1, 0)

                                                    },
                                                    new go.Binding("desiredSize", "", (data) => {
                                                        return _.portsVisible ? portSize : new go.Size(0, 0);
                                                    }),
                                                    new go.Binding("fill", "", (data) => { return _.portsVisible ? data.portColor : "transparent"; }))
                                            )  // end itemTemplate
                                    }
                                ),
                                $(go.Panel, "Horizontal",
                                    new go.Binding("itemArray", "topArray"),
                                    {
                                        row: 0, column: 1,
                                        itemTemplate:
                                            $(go.Panel,
                                                {
                                                    _side: "top",
                                                    fromSpot: go.Spot.Top, toSpot: go.Spot.Top,
                                                    fromLinkable: true, toLinkable: true, cursor: "pointer",
                                                    contextMenu: portMenu
                                                },
                                                new go.Binding("portId", "portId"),
                                                $(go.Shape, "Rectangle",
                                                    {
                                                        stroke: null, strokeWidth: 0,
                                                        desiredSize: portSize,
                                                        margin: new go.Margin(0, 1)
                                                    },
                                                    new go.Binding("desiredSize", "", (data) => {
                                                        return _.portsVisible ? portSize : new go.Size(0, 0);
                                                    }),
                                                    new go.Binding("fill", "", (data) => { return _.portsVisible ? data.portColor : "transparent"; }))
                                            )
                                    }
                                ),
                                $(go.Panel, "Vertical",
                                    new go.Binding("itemArray", "rightArray"),
                                    {
                                        row: 1, column: 2,
                                        itemTemplate:
                                            $(go.Panel,
                                                {
                                                    _side: "right",
                                                    fromSpot: go.Spot.Right, toSpot: go.Spot.Right,
                                                    fromLinkable: true, toLinkable: true, cursor: "pointer",
                                                    contextMenu: portMenu
                                                },
                                                new go.Binding("portId", "portId"),
                                                $(go.Shape, "Rectangle",
                                                    {
                                                        stroke: null, strokeWidth: 0,
                                                        desiredSize: portSize,
                                                        margin: new go.Margin(1, 0)
                                                    },
                                                    new go.Binding("desiredSize", "", (data) => {
                                                        return _.portsVisible ? portSize : new go.Size(0, 0);
                                                    }),
                                                    new go.Binding("fill", "", (data) => { return _.portsVisible ? data.portColor : "transparent"; }))
                                            )
                                    }
                                ),
                                $(go.Panel, "Horizontal",
                                    new go.Binding("itemArray", "bottomArray"),
                                    {
                                        row: 2, column: 1,
                                        itemTemplate:
                                            $(go.Panel,
                                                {
                                                    _side: "bottom",
                                                    fromSpot: go.Spot.Bottom, toSpot: go.Spot.Bottom,
                                                    fromLinkable: true, toLinkable: true, cursor: "pointer",
                                                    contextMenu: portMenu
                                                },
                                                new go.Binding("portId", "portId"),
                                                $(go.Shape, "Rectangle",
                                                    {
                                                        stroke: null, strokeWidth: 0,
                                                        desiredSize: portSize,
                                                        margin: new go.Margin(0, 1)
                                                    },
                                                    new go.Binding("desiredSize", "", (data) => {
                                                        return _.portsVisible ? portSize : new go.Size(0, 0);
                                                    }),
                                                    new go.Binding("fill", "", (data) => { return _.portsVisible ? data.portColor : "transparent"; }))
                                            )
                                    }
                                )
                            );

As you can see the structure has a table, containing multiple ports(red dots in top and bottom) and an auto panel(marked with number 5) in the middle. This auto panel then contains an image(marked with number 3) which has to rotate. Even though the image is round, it actually is a square (number 4) obviously.

My question now is: how can i configure the autopanel so that it does not change its size (the extra width and height indicated by 1 and 2) when its content is rotating? It is also important that the ports do not change position when rotating the image.

In case you need more information(video of the actual rotation) feel free to ask!

Edit: The location.spot.TopLeft is important for snapping to grid

I haven’t had the chance to try this, but what happens if you set width: 100, height: 100 on the “BODY” Auto Panel that holds your rotating Picture?

Thanks for the fast reply

I tried it right now, it constrains the width and height of the panel, but the image still bounces to the bottom right corner, getting cut off at the edge of the panel:
image

The problem is that the Auto Panel should have a fixed desiredSize and at least two elements. The main object is sized to fit around the other object. Try adding a transparent Shape as the first element of the Auto Panel.

Thank you so much, that did the trick! Working fine now

If you were using go-debug.js you probably could have seen a warning message about “Auto” Panels expecting at least two elements.

It actually is there but I did not see, as my console was getting flooded by messages about skipping undomanger (rotation) :D

That’s odd – you should not be getting any such messages while an Animation is running, i.e. while AnimationManager.isTicking is true.