So for these red spots how can i find out whether a spot is on left,right,top or bottom side of the node because i make them on wherever mouse click is performed on the node.
If i can find that then i think i can set fromSpot and toSpot properties for each spot like this…
This is the template for spots :
{ // each spot is represented by a Panel holding a circular Shape
// at a particular alignment relative to the "BODY"
itemTemplate:
GO(go.Panel,
{toLinkable: true,fromLinkable:true},
new go.Binding("portId", "portId"),
GO(go.Shape, "Circle",
{
fill: "red",
strokeWidth: 0, width: 8, height: 8
}
),
new go.Binding("fromSpot","fromSpot"),
new go.Binding("toSpot","toSpot"),
new go.Binding("alignment", "spot", go.Spot.parse).makeTwoWay(go.Spot.stringify)
),
// when the user clicks on the node, add a "spot"
click: function(e, obj) {
if($('#StopSign').data('clicked')){
e.diagram.startTransaction();
debugger;
// convert click point into Spot in node's bounds
var pt = e.documentPoint; // in document coordinates
var node = obj.part;
var b = node.actualBounds; // will be in document coordinates
var L=Math.max(0, Math.min((pt.x - b.x) / b.width, 1))
var R=Math.max(0, Math.min((pt.y - b.y) / b.height, 1))
var spot = new go.Spot(L,R);
setSpot(position of spots); //position will tell whether the spot is on left/right/top/bottom
var spotsArray = node.data.spots;
if (!Array.isArray(spotsArray)) spotsArray = node.data.spots = [];
var name ="spot_"+random_string();
e.diagram.model.addArrayItem(spotsArray, { spot: go.Spot.stringify(spot),portId:name,fromSpot:setSpot(position of spots),toSpot:setSpot(position of spots) });
e.diagram.commitTransaction("added spot");
}
}
And here is the function i suppose i can use to set fromSpot and toSpot according to the spots positions
var setSpot = function(position of spot){
var spot;
if(spot is on left side of node ){
spot = go.Spot.Bottom;
return spot;
}
else if(spot is on right side of node ){
spot = go.Spot.Right;
return spot;
}
else if(spot is on top side of node ){
spot = go.Spot.Top;
return spot;
}
else if(spot is on bottom side of node ){
spot = go.Spot.Bottom;
return spot;
}
}