Hi,
I have a diagram that, when a user does not connect a connector to another node, it has to delete itself. It worked fine in the beginning, but now the diagrams gets more complicated(more nodes and connectors) it shows a weird bug sometimes.
When the diagram is filled with 10+ connectors(&diagrams) and the code tries to delete the selected unconnected connector with no targetID, it sometimes returns an error.
But it doesnt make any sense, why? It works fine sometimes and sometimes it doesn't. The diagram can't seem to find the connector it's trying to delete??
I have added a zip with a GIF for a visual example. In the example it works and then the second time it freezes with an error.
Tried:
- I have "loaded" a diagram into the diagram directly, with 25+ connectors and 25+ nodes and it random happens when the user does not "finish" a connection.
- I have started from scratch connecting different nodes and suddenly it just happens when a user doesnt "finish" a connection.
Info:
The connector cannot be manually adjusted when a connection is created between nodes(Readonly).
The connector needs to be automatically deleted if there is no target when the user does not finish the connection after dragging.
////////////////////////////////////////////////////////////////////////////////////////////////////////////
THE CODE:
//set the properties of the connector
getConnectorDefaults(args: ConnectorModel, diagram: Diagram): ConnectorModel {
args.targetDecorator.height = 5;
args.targetDecorator.width = 5;
args.style.strokeColor = "#797979";
args.targetDecorator.style = { fill: "#797979", strokeColor: "#797979" };
args.constraints = ConnectorConstraints.Default | ConnectorConstraints.ReadOnly; // User cannot adjust connector afterwards, only delete
return args;
};
//prevent userhandles from showing on connector
selectionChange(args: ISelectionChangeEventArgs) {
if (args.state === "Changed" && args.newValue[0] instanceof Connector) {
if ((args.newValue[0] as any).targetID === "") {
console.log(args) //<--the connector still exists
this.diagram.remove(args.newValue[0]); ERROR -> this is row 413, see below)
}
} else {
if (args.state === "Changing" && args.type === "Addition" && args.newValue[0]) {
if (args.newValue[0] instanceof Connector) { //Block handles form view on connector
this.diagram.selectedItems.userHandles[0].visible = false; // is copy handle
this.diagram.selectedItems.userHandles[1].visible = false; // is drawing handle
} else {
this.diagram.selectedItems.userHandles[0].visible = true;
this.diagram.selectedItems.userHandles[1].visible = true;
}
}
}
}
//Defines the link tool used to link Connector
class MyLinkTool extends ConnectorDrawingTool {
diagram: DiagramComponent = null;
mouseDown(args: MouseEventArgs): void {
var connector: ConnectorModel = {
type: "Straight", // initialize the straight line connector
sourceID: this.diagram.selectedItems.nodes[0].id // Source node id have been set
};
// sets the straight line connector as the drawing object.
this.diagram.drawingObject = connector;
super.mouseDown(args);
this.inAction = true;
}
}
//prevent user from dragging connector
connectionChange(args: IConnectionChangeEventArgs) {
console.log(args);
if (args["state"] === "Changing" && args.connector) {
args.cancel = true;
}
}
THE ERROR:
ERROR TypeError: Cannot read property 'length' of undefined
at DiagramComponent.push../node_modules/@syncfusion/ej2-diagrams/src/diagram/diagram.js.Diagram.spliceConnectorEdges (diagram.js:1355)
at DiagramComponent.push../node_modules/@syncfusion/ej2-diagrams/src/diagram/diagram.js.Diagram.remove (diagram.js:1496)
at FlowComponent.push../src/app/flow/flow.component.ts.FlowComponent.selectionChange (flow.component.ts:413)
at Object.eval [as handleEvent] (FlowComponent.html:58)
at handleEvent (core.js:19628)
at callWithDebugContext (core.js:20722)
at Object.debugHandleEvent [as handleEvent] (core.js:20425)
at dispatchEvent (core.js:17077)
at core.js:18567
at SafeSubscriber.schedulerFn [as _next] (core.js:10250)
package.json:
"@syncfusion/ej2-angular-base": "^16.3.32",
"@syncfusion/ej2-angular-buttons": "^16.3.30",
"@syncfusion/ej2-angular-diagrams": "^16.3.30",
"@syncfusion/ej2-angular-grids": "^16.3.30",
"@syncfusion/ej2-angular-inputs": "^16.3.30",
"@syncfusion/ej2-angular-lists": "^16.3.30",
"@syncfusion/ej2-angular-navigations": "^16.3.30",
"@syncfusion/ej2-angular-splitbuttons": "^16.3.30",
Attachment:
error_c7c248d6.zip