Which events are raised by LinkShifting Tool?

Hi, I am experimenting a little with the Link Shifting Tools. It work fine but I am don’t understand for which events I can listen to. If the user shift a link through the little handle, Id like to regenerate the diagram json and save it, exactly as I do with LinkReshaped and SelectionMoved Diagram’s events.
I have listener also for Diagram Modified and none of these are raised when I shift a link.
Any suggestion?

Just add TwoWay Bindings to Link.fromSpot and Link.toSpot.

Thanks a lot! It works!


Hi Walter, it works but… only for the first time :-( I mean that after shifting a link, the Diagram modified listener is called, but it is never called again on the subsequent shifts. At the end of my listener I have

saveButton.attr({'disabled' : !myDiagram.isModified});

to reset the modified status but I doesn’t seems to work… what else I need to reset the diagram internal state?

Enabling an HTML button makes sense in a “Modified” DiagramEvent listener.

But it does not make sense to modify the Diagram in that listener. Doing so is forbidden in the documentation for that listener: DiagramEvent | GoJS API

The TwoWay Binding will automatically save the state in the model. If you really want to get an event after that tool runs, you can modify the code in doMouseUp if isActive.

Hi Walter, you’re right. To be honest that was my ‘last try’, before in my listener I was setting only html button’s property but the modified event got triggered only the first once… I don’t understand why.
I am very interested in your suggestion, could you give me more details about it? In particular, how can I fire an event from the doMouseUp method?

Many thanks,

The “Modified” DiagramEvent only happens when the value of Diagram.isModified changes, outside of a transaction. So if the value of that property is false initially, after the first changes the “Modified” DiagramEvent is raised. It isn’t raised again until after you set Diagram.isModified to false again.

You can raise your own event in that doMouseUp method.

Hi, following your suggestion I have been able to modify the source code for doMouseUp as the following:

` if (this.isActive) {
this.transactionResult = this.name;

////// trying to raise a Modified event each time user moves the handle
var diagram=this.diagram;
var h=this._handle;

if (h!=null) {
	var ad = h.part;
	var link = ad.adornedObject.part;
	if (!(link instanceof go.Link)) return;    
} else {
	console.info('h is null');

When I move the handle, the event is raised but in my listener

myDiagram.addDiagramListener("Modified", function(e) { console.info('e='+e.toString()+' - e.source='+e.Subject);

I can’t get the event’s source/subject, it always prints out this:

e=*Modified:Link#1216([object Object])(ShiftingHandle) - e.source=undefined

Can you give me an hint?

You must not try to subvert the meaning of the “Modified” DiagramEvent.

Instead raise your own event using your own mechanism.

Or you can implement your own Diagram.addChangedListener listener that looks for a ChangedEvent.propertyName === “toSpot” (or === “fromSpot”) with the ChangedEvent.object being a Link.

Yes, you are right and that has been my first attempt, I had in place a ChangedListener but propertyName and the object was always undefined.
Now, I put the the listener back, as you suggested:

myDiagram.addChangedListener(function(e){ if (e.PropertyName==="toSpot" || e.PropertyName==="fromSpot") { console.info('object: '+e.Object+' - oldValue:'+e.oldValue+' newValue:'+e.newValue); } else { console.info('Property:'+e.PropertyName+' newValue:'+e.newValue); } });

and when I move the handle, the property name is undefined :-(

JavaScript is case-sensitive, so you have to be careful how you spell each property name.

Oh no… I am sorry for this. :-(