问题
I have multiple vertex cells in the graph. I am using JavaScript library mxGraph. When i drag the cell from the boundary of canvas, the canvas extends. I want to disallow the cell drag. Is there some function available to limit the drag within the canvas boundaries?
There is function called: graph.setCellsMovable(false);
but this one lock overall, i need to set cell movement false only if user drag it outside the boundary.
回答1:
You should give a try to the mxgraph.autoExtend
property which seems to configure exactly what you are looking for
https://jgraph.github.io/mxgraph/docs/js-api/files/view/mxGraph-js.html#mxGraph.autoExtend
Specifies if the size of the graph should be automatically extended if the mouse goes near the container edge while dragging. This is only taken into account if the container has scrollbars. Default is true.
There are also other configuration properties about auto extend, like https://jgraph.github.io/mxgraph/docs/js-api/files/view/mxGraph-js.html#mxGraph.extendParentsOnAdd
来源:https://stackoverflow.com/questions/64805220/set-mxgraph-cell-only-draggable-within-the-canvas-width