Stencil
The plugin implements a palette of JointJS Elements and allows you to drag them to a Paper.
To learn more about the plugin, check out the Element palette section.
constructor​
constructor(opt?: Stencil.Options);
The Stencil constructor accepts several parameters:
canDrag()​
(cellView: dia.CellView, evt: dia.Event, groupName: string | null) => boolean;
[optional] A function to determine whether an Element from the Stencil can be dragged by the user or not. All Elements can be dragged by default.
container​
[optional] A CSS selector or a DOM element of the container element, which the element being dragged is appended to.
contentOptions​
[optional] When the Stencil Papers are resized to fit their content, the dia.Paper.fitToContent() function is used internally. Use this option to modify the behavior.
dragEndClone()​
(cell: dia.Cell) => dia.Cell;
[optional] A function that produces an Element clone when the user places the dragged Element into the Paper. It defaults to dia.Cell.clone().
dragStartClone()​
(cell: dia.Cell) => dia.Cell;
[optional] A function that produces an Element clone when the user starts dragging. It defaults to dia.Cell.clone().
dropAnimation​
[optional] An object defining an animation that will be performed on an Element that is dropped outside the target Paper area. It defaults to undefined meaning that there will be no animation.
The dropAnimation object can have duration and easing properties:
- [optional]
durationis the duration of the animation in milliseconds (defaults to150), - [optional]
easingis the timing function set to'ease-in-out'by default (all CSS transition timing functions are supported).
Example:
dropAnimation: {
duration: 300,
easing: 'linear'
}
groups​
[optional] An object that defines the groups in the Stencil (if any).
The keys of this object are strings that uniquely identify the groups and values are objects that contain properties for a given group:
- [required]
labelproperty specifies the name of the group that will be displayed in the UI, - [required]
indexis a number specifying the position of the group among other groups within the Stencil, - [optional]
closedproperty tells Stencil whether this group should initially be closed or opened (falseby default), - [optional]
heightproperty specifying the height of the Paper containing the shapes of the group. If not defined, then the height of the Stencil will be used. If none of these heights are defined, the Paper will automatically resize to fit the content (recommended). While doing so, it uses thedia.Paper.fitToContent()method withui.Stencil.options.contentOptionsinternally. The groupheightproperty allows you to override the global setting for a particular group, - [optional]
layoutproperty which acts in the same way asui.Stencil.options.layout. The grouplayoutproperty allows you to override the global setting for a particular group, - [optional]
paperOptionsproperty which acts in the same way asui.Stencil.options.paperOptions. The grouppaperOptionsproperty allows you to override the global setting for a particular group.
An example of what this object can look like:
groups: {
basic: { label: 'Basic Elements', index: 1 },
text: { label: 'Text', index: 2, closed: true },
advanced: { label: 'Advanced Elements', index: 3, closed: true }
}
groupsToggleButtons​
[optional] If set to true, buttons for expanding/collapsing groups (expand all/collapse all) are rendered into the Stencil. It defaults to false.
height​
[optional] The height of the Stencil. If no height property is explicitly stated, the default height of the Stencil will be 800px. If height: null is used, the Stencil height will be calculated automatically to fit its content. The dia.Paper.fitToContent() method with ui.Stencil.options.contentOptions is used internally for resizing.