How to Find a Graph Object in a Specific Point

Hi, IN GOXAM we have used this following code is used to Find Specific graph object in a Point, Similarly can u provide a GoJS equalent code(for the code which i mentioned) to Find the Graph Object in Specific Point

myDiagram.Panel.FindElementsAt(portPt,
x =>
{ // some GraphObject at portPt
var o = x as FrameworkElement;
// walk up the chain of panels
while (o != null && Node.GetPortId(o) == null)
{
o = VisualTreeHelper.GetParent(o) as FrameworkElement;
}
return o;
},
p =>
{
var pnode = Part.FindAncestor§;
if (coll.Contains(pnode)) return false;
var ppt = pnode.GetElementPoint(p, Spot.Center);
if (ProcessDraggingTool.DistanceSquared(ppt, portPt) >= 7) return false;
return ProcessDraggingTool.CompatiblePorts(p, port);
},
SearchLayers.Nodes);

Thanks & Regards
Amit Kumar Jha

Normally we expect programmers to be able to do this translation. Furthermore if you searched the samples, you would find that we have already done this: http://gojs.net/latest/samples/pipes.html. But since you’re probably new to JavaScript, I’ll explain the translation.

There’s no separate DiagramPanel class, since that is basically the Canvas HTML element. (The Div HTML element corresponds to the Diagram object, but obviously Diagram does not inherit from Div.) I suppose we could have had a separate DiagramPanel class in GoJS, but instead we merged it into the Diagram class, since it couldn’t be inherited from Div anyway. Furthermore, where WPF and Silverlight have FrameworkElements, GoJS has GraphObjects. Often the term “Element” can be replaced with “Object”. Hence myDiagram.Panel.FindElementsAt –> myDiagram.findObjectsAt.

JavaScript doesn’t have lambda expressions (yet), so x => { … } –> function(x) { … }.

JavaScript doesn’t have type declarations either, so there’s no equivalent for x as FrameworkElement. You can assume x is a GraphObject.

There are no attached properties in JavaScript, so a number of attached properties in GoXam are just plain properties on GraphObject. That does make GraphObject more messy than it ought to be, but it’s worth it. So Node.GetPortId(o) –> o.portId.

I don’t know why VisualTreeHelper wasn’t built into the Visual class. VisualTreeHelper.GetParent(o) –> o.panel.

Part.FindAncestor doesn’t have a general translation in GoJS, but in the case of looking up the tree for a Part/Node/Group/Link, Part.FindAncestor§ –> p.part.

Part.GetElementPoint has been moved into GraphObject: pnode.GetElementPoint(p, Spot.Center) --> p.getDocumentPoint(go.Spot.Center).

DistanceSquared has been moved into the Point class, where it is more useful to everyone (one of the advantages of having to define basic classes such as Point). So DistanceSquared(ppt, portPt) --> portPt.distanceSquaredPoint(ppt).

Altogether:

myDiagram.findObjectsAt(portPt, function(x) { // some GraphObject at portPt var o = x; // walk up the chain of panels while (o !== null && o.portId === null) o = o.panel; return o; }, function(p) { // a "port" Panel // the parent Node must not be in the dragged collection, and // this port P must be compatible with the NODE's PORT if (coll.contains(p.part)) return false; var ppt = p.getDocumentPoint(go.Spot.Center); if (portPt.distanceSquaredPoint(ppt) >= 7) return false; return ProcessDraggingTool.compatiblePorts(port, p); });