|
The first one "START" is shown always by default (can i make it non editable?) |
Yes, by using the NodeConstraints we can able to make the node as non-Editable. Remove the Delete, Drag, Rotate, Resize constraints from the node constraints. To make the annotation as non-editable. Set the annotation constraints as ReadOnly. Please refer to the below code snippet
| ||
|
I can have up to 2 rectangles under START or can have 1 or none - I want to open a modal when a rectangle is dropped on the screen to fill some info.
then connector is added ,
which event can i use to show modal?
|
When we drag and drop the node from palette to diagram, drop event gets triggered. In that event you can add some info for rectangle. We have prepared a KB for Add annotation to the diagram objects while dragging it from palette onto the diagram. Please find the KB in below link
| ||
|
which event will i know when the START and Level 1 are connected ? |
When we change the connection for the connector, connectionChange event gets triggered. | ||
|
Please provide an example with as many events are for shapes drag and drop
and for connector events
|
We have prepared a sample in our live demos for events. Please find the sample in below link
| ||
|
I will be creating a JSON from this diagram
And when i get a JSON, i should be able to render the same
|
By using the diagram SaveDiagram and LoadDiagram method we can able to save and load the diagram from JSON. The saveDiagram method is used to serialize the diagram as string. This string can be converted to JSON data and stored in the database for future purpose. Please refer below code snippet
Diagram is loaded from this serialized string data by using the loadDiagram public method.
We have already prepared a sample for how to save and load the diagram in our live demos. Please find the sample in below link
For more information about save and load, please refer to below UG documentation link
|
|
public getSymbolDefaults(symbol: NodeModel): void {
symbol.constraints = NodeConstraints.Default | NodeConstraints.AllowDrop;
} |
|
public drop(args: IDropEventArgs) {
if (args.element instanceof Node && this.diagram.nodes.length > 0) {
if (args.element.id !== (args.target as NodeModel).id) {
args.cancel = true;
//Argument element is used to get the dropped node.
let node: NodeModel = args.element;
let newNode: NodeModel = {
id: "node" + randomId(),
offsetX: args.element.offsetX,
offsetY: args.element.offsetY + 100,
shape: args.element.shape,
height: 75,
width: 75
};
this.diagram.add(newNode);
let connector: ConnectorModel = {
id: "connector" + randomId(),
sourceID: (args.target as NodeModel).id,
targetID: newNode.id,
};
this.diagram.add(connector);
} else {
alert("Node does not dropped on other node!!!!");
}
}
} |
|
//TS
public created(): void {
let node: NodeModel =
{
// Position of the node
offsetX: 100,
offsetY: 100,
// Size of the node
width: 100,
height: 100,
style: {
fill: '#6BA5D7',
strokeColor: 'white'
},
annotations: [
{
content: 'Project Name'
}
]
};
this.diagram.add(node);
}
//HTML
<ejs-diagram #diagram id="diagram" width="100%" height="700px" [snapSettings]='snapSettings' (created)="created($event)" (drop)="drop($event)">
</ejs-diagram> |
|
public drop(args: IDropEventArgs) {
if (args.element instanceof Node && this.diagram.nodes.length > 0) {
if (args.element.id !== (args.target as NodeModel).id) {
args.cancel = true;
//Argument element is used to get the dropped node.
let node: NodeModel = args.element;
let newNode: NodeModel = {
id: "node" + randomId(),
offsetX: args.element.offsetX,
offsetY: args.element.offsetY + 100,
shape: args.element.shape,
height: 75,
width: 75,
constraints: NodeConstraints.Default | NodeConstraints.AllowDrop,
annotations: [{}]
};
this.diagram.add(newNode);
let connector: ConnectorModel = {
id: "connector" + randomId(),
sourceID: (args.target as NodeModel).id,
targetID: newNode.id
};
this.diagram.add(connector);
this.objectFromPalette = newNode.id;
this.promptDialog.show();
//open a dialog box
this.dialogOpen();
} else {
alert("Node does not dropped on other node!!!!");
}
}
} |
|
s there a way to Auto arrange the node with proper spacing when i drop/add node? |
We have already prepared a KB for How to automatically arrange nodes without overlapping in Angular Diagram. So you can refer this KB and arrange the nodes automatically in diagram.
|
|
when i click a node, i want to show context menu with Add/Delete node. Will i know which node i clicked/selected? |
When you click on the node, click event gets triggered. In that event by using the args.element you can find in which node you have clicked.
By using the diagram context menu you can able to include context menu for the diagram.
For more information about how to use context menu in the diagram, please refer to the below UG documentation link
We have prepared a sample for the context menu. Please find the sample in below link
|
|
public contextMenuOpen(args: DiagramBeforeMenuOpenEventArgs) {
for (let item of args.items) {
if (item.text === "Activity") {
if (this.diagram.selectedItems.nodes.length > 0) {
args.hiddenItems.push(item.id);
}
}
}
} |
|
When there are no menu items in contextmenu, still seeing menu |
We are unable to reproduce the reported issue at our end. Could you please confirm us whether you use Syncfusion context menu component or Diagram context menu in your sample. If you use diagram context menu means then as we said earlier, When we try to open the context menu means , the contextMenuOpen event gets triggered. In that event push the context menu items that you does not want to show in the args hidden items.
| ||
|
How do i delete current node and children under it.
What is the event i can use for delete
|
By using the diagram remove method we can able to remove the selected node and its connection.
When we add or delete any node in the diagram, collectionChange event gets triggered. In that event check if the args.state is Removal or not. If we delete the node means then args.state is returned as Removal
For more information about collectionChange event args, please refer to below UG documentation link
|
|
let connectors: string[] = (this.diagram.selectedItems.nodes[0] as Node) .outEdges; |
|
let connector: ConnectorModel = this.diagram.getObject(
connectorList[i]
);
let node: NodeModel = this.diagram.getObject(connector.targetID);
this.diagram.remove(node); |
|
this.diagram.clear(); |
Hi Arvindi was using layout save ans LOAD diagram to build my layout earlierthis.diagram.loadDiagram(save);I want to build my own JSON and bind data = > update with my own JSONhow do i build the JSON, need a samplei created the JSON object and binding, but the diagram is not updating!!public diagDataObj: object[] = [];public data: Object = {id: "id",parentId: "parentId",dataSource: new DataManager((this.diagDataObj)),doBinding: (nodeModel: NodeModel, data: object, diagram: Diagram) => {nodeModel.shape = {type: "Text",content: (data as TypeInfo).name,margin: { left: 10, right: 10, top: 10, bottom: 10 }};}};export interface TypeInfo {name: string;color: string;}<ejs-diagram #diagram id="diagram" width="100%" height="700px" (collectionChange) = "collectionChange($event)"[selectedItems]="selectedItems" [getCustomTool]="getCustomTool"[snapSettings]='snapSettings' [layout]="layout" (click)="nodeClick($event)"[layout]="layout"[dataSourceSettings]="data"(created)="created($event)" [tool]="tool">ejs-diagram>
- 0:
- color: "Yellow"
- id: "Root-10027-11"
- name: "Test Project for WBS"
- __proto__: Object
- 1:
- color: "white"
- id: "Epic-10027-12-5"
- name: "Epic1"
- parentId: "Root-10027-11"
- __proto__: Object
- 2:
- color: "white"
- id: "Feature-10027-14-7"
- name: "Feature1 of Epic1"
- parentId: "Epic-10027-12-5"
- __proto__: Object
- 3:
- color: "white"
- id: "Task-10027-19-12"
- name: "Task1 of Feature1 Epic 1"
- parentId: "Feature-10027-14-7"
- __proto__: Object
- 4:
- color: "white"
- id: "Task-10027-20-13"
- name: "Task2 of Feature1 Epic 1"
- parentId: "Feature-10027-14-7"
- __proto__: Object
- 5:
- color: "white"
- id: "Feature-10027-15-8"
- name: "Feature2 of Epic1"
- parentId: "Epic-10027-12-5"
- __proto__: Object
- 6:
- color: "white"
- id: "Feature-10027-16-9"
- name: "Feature3 of Epic1"
- parentId: "Epic-10027-12-5"
- __proto__: Object
- 7:
- color: "white"
- id: "Task-10027-21-14"
- name: "Task1 of Feature3 Epic 1"
- parentId: "Feature-10027-16-9"
- __proto__: Object
- 8:
- color: "white"
- id: "Epic-10027-13-6"
- name: "Epic2"
- parentId: "Root-10027-11"
- __proto__: Object
- 9:
- color: "white"
- id: "Feature-10027-17-10"
- name: "Feature1 of Epic2"
- parentId: "Epic-10027-13-6"
- __proto__: Object
- 10:
- color: "white"
- id: "Task-10027-22-15"
- name: "Task1 of Feature1 Epic 2"
- parentId: "Feature-10027-17-10"
- __proto__: Object
- 11:
- color: "white"
- id: "Epic-10027-59-52"
- name: "Epic3"
- parentId: "Root-10027-11"
- __proto__: Object
- 12:
- color: "white"
- id: "Feature-10027-67-60"
- name: "Feature1 for Epic3"
- parentId: "Epic-10027-59-52"
- __proto__: Object
- 13:
- color: "white"
- id: "Epic-10027-60-53"
- name: "Epic3"
- parentId: "Root-10027-11"
|
public Save() {
let save: string = this.diagram.saveDiagram();
let data = JSON.parse(save);
let nodes = data["nodes"];
let json = [];
let data1;
for (let i = 0; i < nodes.length; i++) {
if (nodes[i].inEdges.length > 0) {
let parentId: string = nodes[i].inEdges;
let connector: ConnectorModel = this.diagram.getObject(parentId);
data1 = {
id: nodes[i].id,
name: nodes[i].annotations[0].content,
color: nodes[i].style.fill,
parentId: connector.sourceID
};
} else {
data1 = {
id: nodes[i].id,
name: nodes[i].annotations[0].content,
color: nodes[i].style.fill
};
}
// Push the data to the JSON
json.push(data1);
}
console.log(json);
} |
|
public Data = [{ id: "FOUgT", name: "Board", color: "#71AF17" },
{
id: "iH41u",
name: "General Manager",
color: "#71AF17",
parentId: "FOUgT"
},
{
id: "FqoSg",
name: "Assistant General Manager",
color: "#71AF17",
parentId: "iH41u"
},
];
public data: Object = {
id: "id",
parentId: "parentId",
dataSource: new DataManager(this.Data),
doBinding: (nodeModel: NodeModel, data: object, diagram: Diagram) => {
nodeModel.annotations = [
{
content: (data as EmployeeInfo).name
}
];
}
}; |