How to get names/labels of connected edges

Hi, like to better understand the right way to get the names of the label text from all the connected edges to a single node. What is the best way?

I am trying to get children and grandchildren but it seems to only work for the nodes and not the edge/link text.

Are you trying to get the text strings of the labels on the links that are coming into a node?

First, aNode.findLinksInto() returns the collection of links whose Link.toNode is that node.

If the text of the label is coming from the link data in the model, then I would get the string from there. Something like:

aNode.findLinksInto().each(function(link) {
    console.log(link.data.somePropertyThatIsTheSourceOfADataBinding);
})

Otherwise you can grab the text from the TextBlock that is (or is within) the label on the link. You could do that by giving that TextBlock a name in your link template. Let’s say that name is “LABEL”, for example in:

myDiagram.linkTemplate =
  $(go.Link,
    . . .
    $(go.TextBlock, . . .,
        { name: "LABEL" },
        new go.Binding("text", ...))
  );

Then you could do something like:

aNode.findLinksInto().each(function(link) {
  var lab = link.findObject("LABEL");
  if (lab) console.log(lab.text);
})

@walter Thanks so much. This worked great. Now I am understanding iterators with this solution. Now I just need to learn how to add an adornment with a count value. Any pointers there would be great. FYI, we are in evaluation mode with GoJS and will be getting a seat shortly. Very impressed with this framework - and this is after evaluating many. Great job.

Thank you for your kind words. I guess having experience produces better results.

When do you want that count to be showing? If it is all the time for all nodes (or if you are asking about links – same answer), then just add it to the template.

If it is whenever the node or link is selected, then specify a custom selection Adornment that includes the count. GoJS Selection -- Northwoods Software

If it is some other circumstance, please elaborate when and how.

When I successfully bring back all the incoming link labels using the above method, how do I push them into a single array? I have this:

        linksInto.each(function(link) {
          var lab = link.findObject("linkName");
          console.log("in--"+lab.text);
            //topicIns.push = lab.text;
            var arr = [];
            arr.push(lab.text);
            console.log(arr);
            self.topicIns = arr;
          })

This is pushing 3 separate arrays VS a single array:

image

Is there a way to make the results from the .each to be a single array? is there a GoJS way or how would I do this in regular JS if that is recommended?

Alas, there’s no Iterator.toArray() method. You could try this instead:

new go.List().addAll(someCollection.map(link => link.findObject("linkName").text)).toArray()

I took a break, went to see my family, thought about it a bit more and was like: ‘what if I remove the array assignment out of the function’ …hmm…tried it when I got back home. Worked:

        var arr = [];
        var linksInto = node.findLinksInto();
        var linksOutof = node.findLinksOutOf();

        linksInto.each(function(link) {
          var lab = link.findObject("linkName");
          console.log("in--"+lab.text);
            //topicIns.push = lab.text;
            var ins = lab.text;
            arr.push(lab.text);
          })
        self.topicIns = arr

As you can probably tell, I am new to programming (actually went to school for painting). Thanks again!