Diagrams can display geometric shapes by setting the shape property of ShapeNode instances.
JavaScript Copy Code |
---|
shapeNode.shape = MindFusion.Diagramming.Shapes.Actor(); |
You can define your own shapes by using the static createShape method of the Diagramming.Controls.ShapeBuilder class. The shape geometry is specified as an array of ShapeElements. The ShapeElement class constructor expects a command and an array of command parameters, and optionally styling. The list of supported commands matches the HTML Canvas drawing API (e.g moveTo, lineTo, bezierCurveTo, arc, roundRect). Coordinates are defined as percentage of a node's bounding rectangle.
JavaScript Copy Code |
---|
var outline = []; |
The Shape definition can also contain decorations and shape decorations. A decoration is a geometry that consists of one or more lines or curves. A shape decoration is a closed path of lines and/or curves, that can also have a fill. A shape can have one decoration and a number of shape decorations, that are specified through the decorationElements and shapeDecorationElements parameters as follows:
JavaScript Copy Code |
---|
var decoration = []; |
If you don't need the per-element styling options, another way to create a shape is by creating an instance of the Shape class providing the outline definition using SVG Path syntax.
JavaScript Copy Code |
---|
var shape = new Shape({ |
A string identifier must be specified for every shape so they will be accessible via the Shape.fromId method.
You can use a Shape Library xml file to store your collection of custom shapes. Set the shapeLibraryLocation property to specify the path to the file.
JavaScript Copy Code |
---|
diagram.shapeLibraryLocation = "MyShapes.sl"; |
The shapes in the Shape Library file will be automatically added to the shared list of shapes kept in the Shape class, which lets you access them by calling the fromId method.
The ShapeDesigner tool that comes with JsDiagram lets you create and edit custom shapes interactively and save them to Shape Library files. When the tool starts, a new shape library is created by default with a single basic rectangular shape in it. To modify the shape, drag and drop shape elements from the palette to the right onto the shape canvas. The following drop operations are supported:
Elements/decorations can be further customized by dragging their control points.
You can delete, copy and paste dropped elements/decorations, as well as undo and redo drop actions via the options in the Edit menu.
Styling can be specified to elements/decorations by using the controls in the property panel, that is shown when an element/decoration is selected.
The Preview panel lets you see how your shape will look and behave in a real DiagramView control.
New shapes can be added from the Shape/New menu option.
The finished library can be exported to an .sl file from the File/Save Library menu option.