paper.fitToContent([opt])
Expand/shrink the paper to fit the content inside it. Snap the resulting width/height to the grid defined by opt.gridWidth
/ opt.gridHeight
.
opt.padding
adds to the resulting width/height of the paper. The opt.padding
can eithr be a number in which case it represents the padding
on all the sides or it can be an object of the form { top: Number, right: Number, bottom: Number, left: Number }
. By default the method fits the paper to a content with positive coordinates only and sets the origin to (0,0) for the resulting paper.
To change this behaviour use the allowNewOrigin: ['negative'|'positive'|'any']
option.
Set allowNewOrigin
to 'negative'
to account for content with negative coordinates.
Set allowNewOrigin
to 'positive'
to allow origin to be set to the top-left coordinate of the content.
Set allowNewOrigin
to 'any'
to apply both. This method might internally trigger the "resize"
and "translate"
events that can be handled by listening on the paper object (paper.on('resize', myHandler)
).
opt.minWidth
and opt.minHeight
define the minium width and height of the paper
and opt.maxWidth
and opt.maxHeight
define the maximum width and height of the paper
after fitting it to the content.
You can try many of these options interactively in the paper demo.
Depracated usage: paper.fitToContent(gridWidth, gridHeight, padding, opt)