Angular Diagram - Restrict Edit Operations

The Diagram UI component allows you to restrict edit operations in the following ways.

Prohibit All Operations of a Specific Type

To prohibit an operation, set the corresponding allow{Operation} editing property to false.

Code
  • <dx-diagram #diagram id="diagram" >
  • <dxo-diagram-editing
  • [allowAddShape]="false"
  • [allowChangeConnection]="false"
  • [allowChangeConnectorPoints]="false"
  • [allowChangeConnectorText]="false"
  • [allowChangeShapeText]="false"
  • [allowDeleteConnector]="false"
  • [allowDeleteShape]="false"
  • [allowMoveShape]="false"
  • [allowResizeShape]="false">
  • </dxo-diagram-editing>
  • </dx-diagram>

Prohibit Individual Operations

View Demo

Every time a user attempts an edit operation, the UI component raises the requestEditOperation event. Use the allowed parameter to either permit or cancel the user action. To identify the operation type and target element, use the event parameters listed below.

  • The operation parameter identifies the edit operation. Note that if an Allow{Operation} property is set to false, the event does not fire for this operation. The table below lists all available operations.
OperationUser action / IU update operation causes the event to be raisedAllow{Operation} property
addShapeA user is about to add a shape / The UI component determines the **Paste** command's visibility.allowAddShape
addShapeFromToolboxThe UI component determines the visibility of a shape in the toolbox or context toolbox.allowAddShape
beforeChangeConnectorTextA user is about to edit a connector's text.allowChangeConnectorText
beforeChangeShapeTextA user is about to edit a shape's text.allowChangeShapeText
changeConnectionA user is about to link or delink a connector from a shape / The UI component determines a connection point's visibility.allowChangeConnection
changeConnectorPointsA user changed a connector's points.allowChangeConnectorPoints
changeConnectorTextA user changed a connector's text.allowChangeConnectorText
changeShapeTextA user changed a shape's text.allowChangeShapeText
deleteConnectorA user is about to delete a connector / The UI component determines the **Cut** and **Delete** commands' visibility.allowDeleteConnector
deleteShapeA user is about to delete a shape / The UI component determines the visibility of the **Cut** and **Delete** commands.allowDeleteShape
moveShapeA user moved a shape.allowMoveShape
resizeShapeA user resized a shape.allowResizeShape
  • The args parameter contains information about the shape or connector that takes part in the edit operation. The parameter's value type depends on the operation type.
Edit OperationReturn Value's Type
addShapeDiagramAddShapeArgs
addShapeFromToolboxDiagramAddShapeFromToolboxArgs
beforeChangeConnectorTextDiagramBeforeChangeConnectorTextArgs
beforeChangeShapeTextDiagramBeforeChangeShapeTextArgs
changeConnectionDiagramChangeConnectionArgs
changeConnectorPointsDiagramChangeConnectorPointsArgs
changeConnectorTextDiagramChangeConnectorTextArgs
changeShapeTextDiagramChangeShapeTextArgs
deleteConnectorDiagramDeleteConnectorArgs
deleteShapeDiagramDeleteShapeArgs
moveShapeDiagramMoveShapeArgs
resizeShapeDiagramResizeShapeArgs
  • The reason parameter specifies whether the event responds to a user action or requests instruction on related UI command availability.

    • The true value indicates that the Diagram is updating the UI. Set the allowed option to false to hide the UI element associated with the specified operation.

    • The modelModification value indicates that a user attempts an edit operation. You can specify whether the operation is allowed and display an error message if necessary.

app.component.html
app.component.ts
  • <dx-diagram #diagram id="diagram" (onRequestEditOperation)="requestEditOperationHandler($event)">
  • requestEditOperationHandler(e) {
  • if(e.operation === "addShape") {
  • if(e.args.shape.type !== "employee" && e.args.shape.type !== "team") {
  • if(e.reason !== "checkUIElementAvailability")
  • this.showToast("You can add only a 'Team' or 'Employee' shape.");
  • e.allowed = false;
  • }
  • }
  • else if(e.operation === "changeShapeText") {
  • if(e.args.text === "") {
  • if(e.reason !== "checkUIElementAvailability")
  • this.showToast("A shape text cannot be empty.");
  • e.allowed = false;
  • }
  • }
  • else if(e.operation === "beforeChangeConnectorText") {
  • e.allowed = false;
  • }
  • ...

Read Only Mode

Set the readOnly property to true to protect the Diagram UI component from edit operations. In this mode, the UI component hides its UI elements: the toolbox, history toolbar, and properties panel.

View Demo