Quantcast
Channel: GoJS - Northwoods Software
Viewing all articles
Browse latest Browse all 7069

diagram.model.removeLinkData not working

$
0
0

@tommybernaciak wrote:

Hi,
I have finally an issue I can’t overcome even with docs so I need to ask here. In my application, I have functionality that allows the user to drop the diagram node on another node to create a connection. I have two types of nodes - conditions and rules - so to make a valid and correct diagram, when a condition is dropped on a rule it is not added after it, but between a direct parent to rule and rule itself. I have a function which handles it:

const addNodeBetweenDestinationAndParent = (
	draggedNode: Node,
	destinationNode: Node,
	diagram: any
) => {
	const parentLink: Link | null = destinationNode.findTreeParentLink();
	const parentNode: Node | null = destinationNode.findTreeParentNode();
	if (parentLink && parentNode) {
		if (parentNode.data.key === draggedNode.data.key) return;
		diagram.model.addLinkData({ from: parentNode.data.key, to: draggedNode.data.key });
		diagram.model.addLinkData({ from: draggedNode.data.key, to: destinationNode.data.key });
		diagram.model.removeLinkData(parentLink.data);
	} else {
		diagram.model.addLinkData({ from: draggedNode.data.key, to: destinationNode.data.key });
	}
};

I have a functionality that allows editing a diagram already saved to the database. When the diagram is created it works fine, but when a diagram is edited - taken from API and converted from JSON to gojs format - there is one issue. There is a problem with removeLinkData function. It seems like it does nothing, the link is not removed. I put console.log(diagram.model.containsLinkData(parentLink.data)); before and after and I received true and false respectively like it was removed, but it is still there. I tried to find a solution and I checked this issue here: Sometimes diagram.model.removeLinkData(linkdata) not working and I tried to change my code to:

const addNodeBetweenDestinationAndParent = (
	draggedNode: Node,
	destinationNode: Node,
	diagram: any
) => {
	const parentLink: Link | null = destinationNode.findTreeParentLink();
	const parentNode: Node | null = destinationNode.findTreeParentNode();
	if (parentLink && parentNode) {
		if (parentNode.data.key === draggedNode.data.key) return;
		console.log(diagram.model.containsLinkData(parentLink.data));

		diagram.startTransaction('removing links');
		diagram.model.addLinkData({ from: parentNode.data.key, to: draggedNode.data.key });
		diagram.model.addLinkData({ from: draggedNode.data.key, to: destinationNode.data.key });
		diagram.removeParts(new Set<ObjectData>().add(parentLink));
		diagram.commitTransaction('removing links');

		console.log(diagram.model.containsLinkData(parentLink.data));
		console.log('data', diagram.model.linkDataArray);
	} else {
		diagram.model.addLinkData({ from: draggedNode.data.key, to: destinationNode.data.key });
	}
};

But it didnt help, it still does not work as expected

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 7069

Trending Articles