Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I keep jointjs cells from overflowing the paper?

I'm using jointjs to make diagrams which will be user-editable. The user may drag them around and relocate each cell. However, when a cell is dragged to the edge, it overflows and becomes cut off. I want to prevent this from happening, instead the cell to stop before it gets to the edge of the paper and not be allowed to cross the edge, thus always staying completely within the paper. The behavior can be seen in jointjs' very own demos here:

http://www.jointjs.com/tutorial/ports

Try dragging the cell to the edge and you'll see that it eventually becomes hidden as it crosses the edge of the paper element.

Secondly, I'm using the plugin for directed graph layout, found here:

http://jointjs.com/rappid/docs/layout/directedGraph

As you can see, the tree position automatically moves to the upper left of the paper element whenever your click layout. How can I modify these default positions? The only options I see for the provided function are space between ranks and space between nodes, no initial position. Say I wanted the tree to appear in the middle of the paper upon clicking 'layout', where would I have to make changes? Thanks in advance for any help.

like image 953
dalvacoder Avatar asked May 05 '15 20:05

dalvacoder


1 Answers

As an addition to Roman's answer, restrictTranslate can also be configured as true to restrict movement of elements to the boundary of the paper area.

Example:

var paper = new joint.dia.Paper({
    el: $('#paper'),
    width: 600,
    height: 400,
    model: graph,
    restrictTranslate: true
})
like image 119
Robert Klein Kromhof Avatar answered Sep 21 '22 18:09

Robert Klein Kromhof