Layout binding twoway with function

Hi.

I am looking for a working example of binding the location of a node with a function in the twoway clause. My case involves using positioning to mimic scaling meaning that every time the node is moved I have to calculate the ‘non-zoomed’ position of the node which I later serialise. Perhaps just go with the idea that I want to fire a function when location changes and modify my model within the function.

This is the way I am thinking.

model = { loc: ‘100 200’, myX: 100, myY: 200 }

… in node template defn…

        , new go.Binding("location", "loc", go.Point.parse).makeTwoWay(locChange)

function locChange(loc, data) {
<span =“Apple-tab-span” style=“white-space:pre”> data.myX = loc.x * some_factor

<span =“Apple-tab-span” style=“white-space: pre;”> data.myY = loc.y * some_factor
}



I suggest that you adapt the “fromLocation” and “toLocation” functions that are examples in the documentation for the Binding class. Binding | GoJS API.

Thanks Walter. I had based my code on that but went off track when I added my own code and thought the example had an error. I can confirm the fault was mine and the sample works when cut & pasted.

Thanks again.