JavaScript/jQuery Diagram - Custom Shapes
The Diagram UI component provides a collection of built-in shapes. Use the customShapes property to extend this collection with custom shapes.
The toolbox property allows you to add the custom shapes to the toolbox.
A custom shape can be created based on a default shape type or with a custom background image. The type property identifies custom shapes and should be unique.
Shapes with Base Type
Shapes with Base Type
Use the baseType property to specify a base type for a shape. The built-in shape types are shown in the Shape Types section.
- <dx-diagram #diagram id="diagram">
- <dxi-custom-shape *ngFor="let emp of employees"
- category="employees"
- [type]='"employee" + emp.ID'
- baseType="rectangle"
- [defaultText]="emp.Full_Name"
- [allowEditText]="false">
- </dxi-custom-shape>
- <dxo-toolbox>
- <dxi-group category="employees" title="Employees" displayMode="texts"></dxi-group>
- </dxo-toolbox>
- </dx-diagram>
You can use the style and textStyle properties to specify the default style settings for a shape and a shape’s text.
- <dx-diagram #diagram id="diagram">
- <dxo-default-item-properties
- style="fill: yellow;"
- textStyle="font-size: 14pt;">
- </dxo-default-item-properties>
- <!-- ... -->
- </dx-diagram>
Shapes with Custom Background Images
Use the backgroundImageUrl property to specify the custom shape's background image in SVG format.
- <svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 48 26">
- <g><rect rx="5" ry="5" x="0.5" y="0.5" width="47" height="25"
- style="fill:#FFFFFF;stroke:#000000;stroke-width:1px;"/></g>
- </svg>
- <dx-diagram #diagram id="diagram">
- <dxi-custom-shape
- type="Rounded Rectangle"
- backgroundImageUrl="images/shapes/roundedRectangle.svg"
- </dxi-custom-shape>
- </dx-diagram>
The image below shows the result:
The following properties allow you to customize the image size and position:
Shape Size
Use the following properties to specify the shape size settings:
- <dx-diagram #diagram id="diagram">
- <dxi-custom-shape
- <!-- ... -->
- [defaultWidth]="2"
- [defaultHeight]="1"
- </dxi-custom-shape>
- </dx-diagram>
The image below shows the result:
Shape Inner Image
A custom shape can display an inner image. Use the defaultImageUrl property to specify the image URL.
The following properties allow you to specify the image size and position:
- <dx-diagram #diagram id="diagram">
- <dxi-custom-shape
- <!-- ... -->
- defaultImageUrl="images/photo.png"
- [imageHeight]="0.8"
- [imageWidth]="0.3"
- [imageTop]="0.1"
- [imageLeft]="0.1"
- </dxi-custom-shape>
- </dx-diagram>
The image below shows the result:
If the allowEditImage property is set to true
, the Diagram context menu displays commands that allow users to change the image.
Shape Text
The defaultText property specifies the shape text. Users can change the text if the allowEditText property is set to true
.
Use the following properties to specify the size and position of the text container:
- <dx-diagram #diagram id="diagram">
- <dxi-custom-shape
- <!-- ... -->
- defaultText="Employee"
- [textLeft]="0.4"
- [textWidth]="0.6">
- </dxi-custom-shape>
- </dx-diagram>
The image below shows the result:
You can use the textStyle property to specify the default style settings for a shape's text.
- <dx-diagram #diagram id="diagram">
- <dxo-default-item-properties
- textStyle="font-size: 14pt;">
- </dxo-default-item-properties>
- <!-- ... -->
- </dx-diagram>
The image below shows the result:
Connection Points
Use the connectionPoints property to specify a collection of custom connection points for a shape. If the property is not specified, the shape displays the default connection points.
- <dx-diagram #diagram id="diagram">
- <dxi-custom-shape
- <!-- ... -->
- <dxi-connection-point [x]="0.5" [y]="0"></dxi-connection-point>
- <dxi-connection-point [x]="0.5" [y]="1"></dxi-connection-point>
- </dxi-custom-shape>
- </dx-diagram>
The image below shows the result:
If you have technical questions, please create a support ticket in the DevExpress Support Center.