Question about screen size changes

I’ve added a Part as legend to a specific spot, relative to the viewport right and bottom. This is on top of a Leaflet map. This works great when the page displays but when it is resized, the Part does not adjust to the new right and bottom. I calculate the doc height and width in the template creation process and use to make the initial positioning. How can I ensure that the Part floats and sticks close to the bottom right of the screen? (Perhaps there is a more “gojs-like” way to do it. Here’s my relevant code. I’ve tried calling Diagram.requestUpdate(…) but no luck. Even placing into a timed check loop doesn’t seem to work.


let docWidth = this.theDiagram.viewportBounds.width; let docHeight = this.theDiagram.viewportBounds.height;

$(go.Part, "Auto", { position: new go.Point(docWidth-180, docHeight-220), selectable: false , alignment: go.Spot.BottomRight, layerName: "Foreground" },

GraphObject.alignment has no meaning for Parts, except maybe by some custom layout.

The position (or location) of a Part is always in document coordinates. So using the width or height of anything is not going to help.


$(go.Part, "Auto",
  { locationSpot: go.Spot.BottomRight, layerName: "Tool" },
  . . .)

and then just set its Part.location to

new go.Point(theDiagram.viewportBounds.right, theDiagram.viewportBounds.bottom)

thank you Walter. I was able to peg the legend position with your suggestions by:


  $(go.Part, "Auto",
    { locationSpot: go.Spot.BottomRight,
      layerName: "Tool",
      selectable: false ,
      location: new go.Point(
        this.theDiagram.viewportBounds.right-15, this.theDiagram.viewportBounds.bottom-30

but the problem of resize does not correct. When I resize my screen, Leaflet resizes (I use theMap.invalidateSize() there) but the legend stays in the same absolute position (ie out of the viewport).

Trying this.diagramComponent.theDiagram.layoutDiagram(true); does not work, even in a loop.

Any ideas?

Thanks again!


When a window resize happens, do you set that legend’s Part.location again?