Binding function to recognise if a from or to link exists

Question: Is there a way to bind a property to a function that identifies if a node has inbound or outbound links?

My use-case is that I wish to vary the margin on a part depending on whether there is a link coming in to the node. In other scenarios, I could want to change a fill color if links are present, etc.

I understand that the .ofObject() parameter can be added to binding functions but what would I test inside the binding function in order to recognise links were present ? I looked for hasToLinks, and toLinkCount but neither was available in the docs.

Keep looking – read the documentation for Nodes: http://gojs.net/latest/api/symbols/Node.html

Also, there are examples at:
http://gojs.net/latest/intro/collections.html
http://gojs.net/latest/intro/highlighting.html
http://gojs.net/latest/samples/distances.html
http://gojs.net/latest/samples/flowgrammer.html
http://gojs.net/latest/samples/friendWheel.html
http://gojs.net/latest/samples/genogram.html
http://gojs.net/latest/samples/logicCircuit.html
http://gojs.net/latest/samples/navigation.html
http://gojs.net/latest/samples/pipes.html
http://gojs.net/latest/samples/sankey.html

Thanks - I have spent some time looking at the examples and reading the recommended page. In summary I can see clearly how I can use a settable parameter such is isHighlighted to drive a binding. However, my question relates to binding to knowledge of a link count in and out which I do not see explained in the links you have provided, though there is a lot of other good techniques there.

An Explanation: Let us take the case of changing fill of some part of a node based on whether or not that node has an inbound link. For the sake of argument say also that there is a node property named ‘isLinkedTo’ which is a boolean with value True when there are one or more inbound links to any port on the node, and False otherwise.

I could then bind the fill colour as:

new go.Binding("fill", "isLinkedTo", function(val) { return val ? "red" : "green"}).ofObject()

Are there any properties that I could use in this way for this purpose ?

You cannot add properties to the Node class. (Well, this is JavaScript, so you can, but you are not permitted to do so.) So it doesn’t make sense to try to use Node.isLinkedTo as a binding source, nor as a binding target.

But you could achieve the desired effect by:

    function updateShapeConnectivity(node, link, port) {
        node.findObject("SHAPE").fill = (node.findLinksInto().count > 0) ? "red" : "green";
    }
    $(go.Node, . . .,
        {
          linkConnected: updateShapeConnectivity,
          linkDisconnected: updateShapeConnectivity
        },
        . . .

Thanks for that insight. If I am correct then linkConnected & linkDisconnected are event-based. This is feasible for my current use-case so I will give it a try.

Just for the record though, will those events fire for the initial layout of the diagram?

Also, is findShape documented only I could not find reference to it in the Node docs.

Sorry, that was a typo. I have corrected it.

Yes the events are raised when loading a model.

Thanks - it works well.