how can we restrict a link from lower group to higher group node. exactly we want to link from top to bottom. i mean top lane to bottom lane only no need to allow from bottom to top.
You will need to define a linkValidation predicate.
https://gojs.net/latest/intro/validation.html#GeneralLinkingValidation
sorry, your right. but i’m asking want to restrict LANE II to LANE I, that’s one mention from and to is true or false. why mean it going LANE III, LANE IV etc… wont to allow LANE II to LANE I, and like LANE III to LANE II allow only TOP LANE to DOWN LANE.
Here is a possible link validation predicate:
function isLinkValid(fromnode, fromport, tonode, toport) {
var fromgrp = fromnode.containingGroup;
var togrp = tonode.containingGroup;
// both nodes must be in groups
if (!fromgrp || !togrp) return false;
// if the groups are the same, it's OK to draw a link upwards
if (fromgrp === togrp) return true;
// OK if link goes from an upper group (lower Y) to a lower group (higher Y)
return (fromgrp.location.y <= togrp.location.y);
}
You may need to modify the function in case you have nodes outside of groups, or if you don’t want to allow drawing links upwards even within a single group.
Use this predicate for the LinkingTool.linkValidation property. If your app allows reconnecting existing links, you probably also want to set RelinkingTool.linkValidation. For example when initializing your Diagram:
$(go.Diagram, ...,
{
. . .,
"linkingTool.linkValidation": isLinkValid,
"relinkingTool.linkValidation": isLinkValid
})
its not working walter. can you give me a correct place with valid one
function isLinkValid(fromnode, fromport, tonode, toport) {
debugger
var fromgrp = fromnode.containingGroup;
var togrp = tonode.containingGroup;
// both nodes must be in groups
if (!fromgrp || !togrp) return false;
// if the groups are the same, it’s OK to draw a link upwards
if (fromgrp === togrp) return true;
// OK if link goes from an upper group (lower Y) to a lower group (higher Y)
return (fromgrp.location.y <= togrp.location.y);
}
this is Pallete code, here i mention from and to link
var shape = “roundedRectangle”;
myDiagram.nodeTemplate =
(go.Node, "Auto",
//{ contextMenu: myContextMenu },
//{ selectionAdornmentTemplate: defaultAdornment },
new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify),
(go.Shape, shape,
{
stroke: null, portId: “”, cursor: “pointer”, fromLinkable: true, toLinkable: true, width: 200, height: 30,
fromSpot: go.Spot.Bottom, toSpot: go.Spot.Top, fromLinkableDuplicates: false, toLinkableDuplicates: true
},
new go.Binding(“fromLinkable”, “from”),
new go.Binding(“toLinkable”, “to”),
new go.Binding(“fill”, “color”)),
$(go.TextBlock, { editable: true, margin: 7, stroke: “white”, font: “bold 10pt time new roman”, isMultiline: false },//, editable: true
new go.Binding(“text”, “key”).makeTwoWay()),
How is it not working? When you step through the code, when does the isValidLink
function return false when you mean for it to return true, or vice-versa?
Also, why are you mentioning “Palette code”? Your screenshot appears to have correctly installed the link validation predicates on the Diagram where the user can draw a new link, on that diagram’s tools.
cannot understand what you said. in my code im mention the IsLinkvalid that function i mention and the data of the argument is undefined
Which data? Which argument?
So when you set a breakpoint in that function, and the debugger stops there, you are finding that the value of fromnode
is undefined?
OK, I have just made a copy of the Swim Lanes sample, Swim Lanes
I added this function definition:
function isLinkValid(fromnode, fromport, tonode, toport) {
var fromgrp = fromnode.containingGroup;
var togrp = tonode.containingGroup;
// both nodes must be in groups
if (!fromgrp || !togrp) return false;
// if the groups are the same, it's OK to draw a link upwards
if (fromgrp === togrp) return true;
// OK if link goes from an upper group (lower Y) to a lower group (higher Y)
return (fromgrp.location.y <= togrp.location.y);
}
and I added these initializations for the Diagram, as you did:
$(go.Diagram, "myDiagramDiv",
{
"linkingTool.linkValidation": isLinkValid,
"relinkingTool.linkValidation": isLinkValid,
// ...
Everything worked exactly as I expected and as I believe you are asking for. The user could draw new links between groups/lanes downward but not upward.
sorry for me not woking this bottom to top link? any clue?
No, I have no clue of what you are doing.
I have explained the rationale for why link validation exists, and I have given a sample definition that I believe does what you are asking for, and I have demonstrated that it works in the Swim Lanes sample.
rest of the thing any alternate properties may be enable or disable?
If you modify the Swim Lanes sample as I did, is the user restricted from drawing new links in the manner that you wanted?
yes, that one is enough
any chance to highlighting which one node is not link [to link only]while save
I’m sorry but I do not understand what you want.
Maybe you want to set LinkingBaseTool | GoJS API
just i want to throw an error with out any link from CPT100 to Trainee on that time want to highlight which node is not link i mean Trainee border is highlighted
It would be best to customize the link validation so that such a link could not be drawn.