I am trying to test linking between 2 nodes,
using the robot class I try to link between two ports.
Instead of creating the link gojs just move the start node to the position of the other node.
what am I doing wrong?
let robot = new GoJsRobot(diagram);
let startNode = diagram.findNodeForKey(SUB_PROCESS_NODE_KEY);
let otherNode = diagram.findNodeForKey(SERVICE_TASK_NODE_KEY);
let startPort = startNode.ports.first();
let otherPort = otherNode.ports.first();
let fromPoint = {
x: startPort.getDocumentPoint(Spot.Center).x,
y: startPort.getDocumentPoint(Spot.Center).y
};
let toPoint = {
x: otherPort.getDocumentPoint(Spot.Center).x,
y: otherPort.getDocumentPoint(Spot.Center).y
};
robot.mouseDown(fromPoint.x, fromPoint.y, 0, {});
robot.mouseMove(toPoint.x, toPoint.y, 200, {});
robot.mouseUp(toPoint.x, toPoint.y, 250, {});
so that the center of each node’s port will be linkable. Note how in the original sample, the center of the port would pick the TextBlock, not the Shape, so the robot would not be doing a mouse-down on a port but on the text.
Remove the initial link between Lambda and Mu, and then this code works:
function linkNodes() {
var from = myDiagram.findNodeForKey("Lambda");
var to = myDiagram.findNodeForKey("Mu");
if (!from || !to) return;
var frompt = from.port.getDocumentPoint(go.Spot.Center);
var topt = to.port.getDocumentPoint(go.Spot.Center);
robot.mouseDown(frompt.x, frompt.y, 0);
robot.mouseMove((frompt.x+topt.x)/2, (frompt.y+topt.y)/2, 200);
robot.mouseUp(topt.x, topt.y, 400);
}
I think it would be better to call robot.mouseMove before the robot.mouseDown call. That would be more general than assuming the Node had a GraphObject.mouseEnter event handler. Same goes for the mouseLeave event handler.
The problem is that a lot of the behavior is asynchronous. In this case, you need to give the system a chance to update its Adornments.
function resizeNode() {
var node = myDiagram.findNodeForKey("Lambda");
if (!node) return;
// select the node and make sure the handles appear
myDiagram.commit(function(d) { d.select(node); });
// find the bottom-left corner handle of the Resizing Adornment
var adornment = node.findAdornment("Resizing");
if (!adornment) return;
var handle = null;
adornment.elements.each(function(h) {
if (h.alignment.equals(go.Spot.BottomLeft)) handle = h;
});
if (!handle) return;
// now drag that handle leftwards and downwards
var frompt = handle.getDocumentPoint(go.Spot.Center);
var topt = frompt.copy().offset(-30, 40);
robot.mouseDown(frompt.x, frompt.y, 100);
robot.mouseMove((frompt.x+topt.x)/2, (frompt.y+topt.y)/2, 200);
robot.mouseUp(topt.x, topt.y, 400);
}