Constraints in EJ 1 ASP.NET Core Diagram
23 Sep 2020 / 5 minutes to read
Constraints are used to enable/disable certain behaviors of the diagram, node and connector. Constraints are provided as flagged enumerations, so that multiple behaviors can be enabled/disabled with bitwise operators (
To know more about bitwise operators, refer to Bitwise Operations
Diagram constraints allow to enable or disable the following behaviors.
- Page Editing
- Line Bridging
- Zoom and Pan
- Undo Redo
For more information about Diagram constraints, refer to Diagram Constraints.
The following example illustrates how to disable page editing.
//Set Diagram in read-only mode <ej-diagram id="diagram" width="100%" height="700px" enable-context-menu="false" constraints="Default &~ DiagramConstraints.PageEditable">
NodeConstraints allows to enable or disable the following behaviors of node.
- Drop shadow
- Drag label
- Define tooltip
For more information about node constraints, refer to Node Constraints
The following code illustrates how to disable rotation.
//Disables rotation <e-node name="node1" width="90" height="40" offset-X="80" offset-Y="90" constraints ="Default &~ NodeConstraints.Rotate"></e-node>
ConnectorConstraints allow to enable or disable certain behaviors of Connectors. They are as follows.
- Segment editing
- Define tooltip
- Label dragging
For more information about connector constraints, refer to Connector Constraints
The following code illustrates how to disable selection.
//Disables Selection <e-connector name="connector1" source-node="node1" target-node="node2" constraints="Default &~ ConnectorConstraints.Select">
You can enable or disable certain behaviors of Port. They are as follows.
For more information about port constraints, refer to Port Constraints
The following code illustrates how to disable creating connections with a port.
<e-ports> <e-port name="in" shape="Circle" constraints="None"> <e-offset x="0.4f" y="0.01f"></e-offset> </e-ports>
Selector visually represents the selected elements with certain editable thumbs. The visibility of the thumbs can be controlled with selector constraints. The part of selector is categorized as follows.
- User handles
For more information about Selector constraints, refer to Selector Constraints
The following code illustrates how to hide rotator.
//Hides rotator <e-selected-items constraints="All &~ SelectorConstraints.Rotator"></e-selected-items>
Snap Constraints control the visibility of gridlines and enable/disable snapping. Snap constraints allow to set the following behaviors.
- Show only horizontal or vertical gridlines
- Show both horizontal and vertical gridlines
- Snap to either horizontal or vertical gridlines
- Snap to both horizontal and vertical gridlines
For more information about snap constraints, refer to Snap Constraints
The following code illustrates how to show only horizontal gridlines.
<e-snap-settings snap-constraints="ShowHorizontalLines"> </e-snap-settings>
Some of the behaviors can be defined through both the specific object(node/connector) and Diagram. When the behaviors are contradictorily defined through both, the actual behavior is set through inherit options.
The following code example illustrates how to inherit the line bridging behavior from the Diagram model.
//Sets to inherit bridging from model <e-connector constraints="Default &~ ConnectorConstraints. InheritBridging" line-width="1" line-color="black"> //Enables line bridging for all connectors model.Constraints = .Default | DiagramConstraints.Bridging;
Bitwise Operations are used to manipulate the flagged enumerations [enum]. In this section, Bitwise Operations are illustrated by using node Constraints. The same is applicable while working with Node Constraints, Connector Constraints, or Port Constraints.
You can add or enable multiple values at a time by using Bitwise ‘|’ (OR) operator.
<e-node name="node1" width="90" height="40" offset-X="80" offset-Y="90" constraints ="Default | NodeConstraints.Rotate"> </e-node>
In the above example, you can do both the selection and rotation.
You can remove or disable values by using Bitwise ‘&~’ (XOR) operator.
<e-node name="node1" width="90" height="40" offset-X="80" offset-Y="90" constraints ="Default &~ NodeConstraints.Rotate"> </e-node>
In the above example, Rotation is disabled but other constraints are enabled.
You can check any value by using Bitwise ‘&’ (AND) operator.
if ((node.Constraints & (NodeConstraints.Rotate)) == (NodeConstraints.Rotate))
In the above example, you can check whether the rotate constraints are enabled in a Node. When Node constraints have rotate constraints, the expression returns a rotate constraint.