Auto scrolling implementation

Hi all!

I am trying to enable scrolling effect when an item that is not part of the diagram is dragged over the canvas edge. I have an onDrag handler that translates dragging object’s position to diagram position and detects whether it is hovered over the edge.

I am trying to have diagram behave as if an actual diagram part is dragged over the edge and have it scroll. Wondering if this is at all possible? How exactly is autoScrollInterval property used in the diagram code?

You can invoke the built-in autoscrolling behavior by calling Diagram.doAutoScroll, or stop it by calling Diagram.stopAutoScroll. These are undocumented but declared in the go.d.ts file: https://github.com/NorthwoodsSoftware/GoJS/blob/master/release/go.d.ts

Note that the argument to doAutoScroll is a Point in viewport coordinates, not in document coordinates.

Thank you! Does this method set any attribute in the diagram to indicate it is scrolling at the moment?

No, I don’t think it does.

Is there some other method that handles growth of the diagram if scroll goes out of bounds of the document? The solution I have right now if setting fixedBounds during drag and then unsetting fixedBounds on drop, but wondering if this logic is already handled by any method?

Scrolling and zooming has no effect on the Diagram.documentBounds. (But they always affect Diagram.viewportBounds.)

What are you trying to do? Why do you believe you need to set Diagram.fixedBounds? What is wrong with what you have implemented so far?

What I am trying to accomplish is the same effect as when an item that is a part of the diagram is dragged over the top edge (or any other) and after it reaches all the way at the top, it increases document bounds and continues scrolling upwards. However, when I called doAutoScroll method, it does not handle diagram growth, only scrolling. To achieve the same effect, I added a handler which will set fixedBounds and increase them while diagram is scrolling. So I am wondering if there is a built-in behavior that will handle growth of the diagram?

Ah, yes, that makes sense. Well, when dragging a Node within the Diagram the bounds of the document will automatically increase as the Node is moved outside of the original Diagram.documentBounds. But in your case where the user is not actually dragging any Node within the Diagram, the automatic recomputation of the document bounds does not happen. So temporarily setting Diagram.fixedBounds sounds quite reasonable, if it’s working for you.

Thanks!
I also have another question: which handler calls doAutoScroll function? Is it called in doDragOver?

DraggingTool, DragSelectingTool, LinkingTool, and RelinkingTool all call Diagram.doAutoScroll. They all call it in an override of Tool.doMouseMove. DraggingTool also calls it from doMouseUp.