paper.fitToContent([opt])
Expand or shrink the paper to fit the content inside it. The method returns the area (g.Rect
) of the paper after fitting in local coordinates.
The function accepts an object with additional settings (all optional):
opt.gridWidth
and opt.gridHeight
– snap the resulting width and height of the paper to a grid defined by these dimensions.opt.padding
– additional padding around the resulting paper. It may be specified as a number, in which case it represents the padding width on all sides of the paper. It may be an object of the form { top?: [number], right?: [number], bottom?: [number], left?: [number], vertical?: [number], horizontal?: [number] }
.opt.allowNewOrigin
– should the origin of the resulting paper be adjusted to match the origin of the paper content? In addition to no value being set, three values are recognized by this option: 'positive'
, 'negative'
, 'any'
.
'positive'
– the method only recognizes the content at positive coordinates and puts the origin of resulting paper at the origin of the content. (Still, if the content starts at negative coordinates in an axis, the resulting paper's origin will be assigned 0
in that axis.)'negative'
– the method only recognizes the content at negative coordinates and puts the origin of resulting paper at the origin of the content. (However, if the content starts at positive coordinates in an axis, the resulting paper's origin will be assigned 0
in that axis.)'any'
– the method recognizes all of paper content. The origin of the resulting paper will be at the origin of the content.opt.minWidth
and opt.minHeight
– define the minimum width and height of the resulting paper after fitting it to content.opt.maxWidth
and opt.maxHeight
– define the maximum width and height of the resulting paper.
after fitting it to content.opt.useModelGeometry
– should paper content area be calculated from cell models instead of views? Default is false
. See the documentation of the paper.getContentArea
function for more details.opt.contentArea
– an object of the form { x: [number], y: [number], width: [number], height: [number] }
is the area representing the content bounding box in the local coordinate system that paper should be fitted to. By default opt.contentArea
is paper.getContentArea(opt)
.You can try many of these options interactively in the paper demo.
This method might internally trigger the "resize"
and "translate"
events. These can be handled by listening on the paper object (paper.on('resize', myHandler)
).
paper.fitToContent([gridWidth, gridHeight, padding, opt])
Depracated usage. All parameters are expected to be passed inside the opt
object.