Set a variable after "ViewportBoundsChanged" function is called

Hi @walter,

In the following sample : Basic Day/Hour Infinite Timeline,

I am trying to set the value of a variable after “ViewportBoundsChanged” is called.

Following are the 2 instances where i have used a variable based on which function for “ViewportBoundsChanged” is executed:

I have introduced a variable “isGoToDate” as follows:

Instance 1:

"ViewportBoundsChanged": function(e) {

  if (isGoToDate == true) {

     myDiagram.scale = e.diagram.scale;
     myDiagram.position = new go.Point(myDiagram.viewportBounds.x, e.diagram.position.y);

  }
}

Instance 2:

function initRowHeaders() {
     myDiagram.addDiagramListener("ViewportBoundsChanged", function(e) {
              // Automatically synchronize this diagram's Y position with the Y position of the main diagram, and the scale too.

        if (isGoToDate == true) {

           myRowHeaders.scale = myDiagram.scale;
           myRowHeaders.position = new go.Point(myRowHeaders.position.x, myDiagram.position.y);

        }
});

Now, after the execution of ViewportBoundsChanged’s function, i want to set isGoToDate to false.

How can this be done?

Thanks.

It’s not clear to me why you can’t just set it to false at the end of the function after you’ve performed your operation.

I tried to do so, But, using this way, it is not working as expected.

I am trying to alter the position differently when “isGoToDate” is true.

In “myRowHeaders”:

"ViewportBoundsChanged": function(e) {
	 	myDiagram.scale = e.diagram.scale;
			              
		if (isGoToDate == true) {
		    e.diagram.position.y = myRowHeadersPosition.y;
		}
		myDiagram.position = new go.Point(myDiagram.viewportBounds.x, e.diagram.position.y);
		//isGoToDate = false;
 }

In “myDiagram”:

positionComputation: function(diag, pos) {  // but not too far vertically, or at all if fits in viewport
			            	
            if (isGoToDate == true) {
                pos.y = myDiagramPosition.y;
            }
			            	
            var y = pos.y;
            if (diag.documentBounds.height < diag.viewportBounds.height) {
                y = 0;
            } else {
                y = Math.min(y, diag.documentBounds.bottom - diag.viewportBounds.height);
            	    if (y < 0) y = 0;  // don't show negative Y coordinates
            }
            //isGoToDate = false;
            return new go.Point(pos.x, y);
 }

When, in either of the above 2 functions, i set “isGoToDate = false” at any line, it changes the diagrams’ position as in case of “isGoToDate = false”, overriding the behavior in case of “isGoToDate = true”.

As is documented in Diagram | GoJS API, that function must not have any side effects. At least none that affect the behavior of the diagram, which your global variable probably does.

After all, you do not know how many times that function might be called.

Yes, correct.

But, my requirement is to reset the “isGoToDate” to false, after functions of “positionComputation”/“ViewportBoundsChanged” completing all the callings.

In the nutshell, where do i need to put the line “isGoToDate = false”, once functions of “positionComputation”/“ViewportBoundsChanged” completed their work.

Maybe in a “LayoutCompleted” DiagramEvent listener? But I’m still unsure of what you need to do. It sounds as if you should reorganize how you are solving your problem.

Thanks @walter!

“LayoutCompleted” DiagramEvent listener did it for me.

I wanted to reset a flag after everything is done, i.e at the end.