I don’t know is this bug but I want to check with you. If you look at next code you will see my workaround to get what I need.
BPMN.diagram.addDiagramListener("LinkDrawn", function (e) { if (e.subject.fromNode.category === "annotation") { e.subject.category = "annotation"; // annotation association } else if (e.subject.fromNode.category === "dataobject" || e.subject.toNode.category === "dataobject") { e.subject.category = "data"; // data association } else if (e.subject.fromNode.category === "datastore" || e.subject.toNode.category === "datastore") { e.subject.category = "data"; // data association } e.subject.data.points = e.subject.points; BPMN.modelUpdater.createObject(e.subject.data); });
Because in this moment link.points has initialized but those values are not reflected in data.points property yet (two way binding occurs later) I must manually store this value to link.data instead of two way binding do that. Two way binding does it but obviously later because when I check clicking on link after it is created I see that in console.
BPMN.diagram.addDiagramListener("ObjectSingleClicked", function (e) { console.log(e.subject.part.data); //console.log(e.subject.part.actualBounds.toString()); document.getElementById("infoDraggable").style.visibility = "hidden"; if (e.subject.part instanceof go.Link) { let link = e.subject.part; console.log(link.data); //console.log(link.findObject('label').segmentOffset.toString(), link.findObject('label').segmentIndex); //console.log(e.diagram.model.toJson()); } });
Well solution you gave me does not work. I tried several things and in every case e.object is null. I could not find any situation when it reference to finished transaction!
// only when have added a new link if (!evt.object.changes.any( function(c) { return (c.change === go.ChangedEvent.Insert && c.propertyName === "linkDataArray"); }) ) return; // log link's new route evt.object.each(function(c) { if (c.change === go.ChangedEvent.Property && c.propertyName === "points") console.log(c.object.points);});
myDiagram.addModelChangedListener(function (e) {
// only at end of transaction or undo or redo
if (!e.isTransactionFinished) return;
// only when have added a new link
if (!e.object.changes.any(function(c) { return (c.change === go.ChangedEvent.Insert && c.propertyName === "linkDataArray")); } return;
// log link's new route
e.object.changes.each(function(c) {
if (c.change === go.ChangedEvent.Property && c.propertyName === "points") console.log(c.object.points);
});
Yes I did but just not copy / paste that line. Sorry for confusion about that.
if (!evt.isTransactionFinished) return; // only when have added a new link if (!evt.object.changes.any( function (c) { return (c.change === go.ChangedEvent.Insert && c.propertyName === "linkDataArray"); }) ) return; // log link's new route evt.object.each(function (c) { if (c.change === go.ChangedEvent.Property && c.propertyName === "points") console.log(c.object.points); });
But I got error
[Log] CommittingTransaction – “ChangedEvent.Transaction-ChangedEvent.Insert” (BPMN.js, line 272)
[Log] CommittedTransaction – “ChangedEvent.Transaction-ChangedEvent.Insert” (BPMN.js, line 272)
[Log] CommittedTransaction-ChangedEvent.Transaction (BPMN.js, line 276)
[Error] TypeError: null is not an object (evaluating ‘evt.object.changes’)
(anonymous function) (BPMN.js:277)
Gw (GoJS-1-7-0-beta1-73fe42e4bb1c28964a9d5a61156033b916f1236f.js:314:356)
ed (GoJS-1-7-0-beta1-73fe42e4bb1c28964a9d5a61156033b916f1236f.js:422:162)
eh (GoJS-1-7-0-beta1-73fe42e4bb1c28964a9d5a61156033b916f1236f.js:419:137)
Ed (GoJS-1-7-0-beta1-73fe42e4bb1c28964a9d5a61156033b916f1236f.js:417:89)
Ed (GoJS-1-7-0-beta1-73fe42e4bb1c28964a9d5a61156033b916f1236f.js:808:154)
yk (GoJS-1-7-0-beta1-73fe42e4bb1c28964a9d5a61156033b916f1236f.js:477:116)
doSimulatedDrop (GoJS-1-7-0-beta1-73fe42e4bb1c28964a9d5a61156033b916f1236f.js:524:382)
JF (GoJS-1-7-0-beta1-73fe42e4bb1c28964a9d5a61156033b916f1236f.js:916:462)
Sp (GoJS-1-7-0-beta1-73fe42e4bb1c28964a9d5a61156033b916f1236f.js:941:94)
Sorry, I forgot to type “.changes” when referring to the Transaction that is the value of e.object for such Model ChangedEvents that are of type “Transaction”.
Here’s the code again:
myDiagram.addModelChangedListener(function (e) {
// only at end of transaction or undo or redo
if (!e.isTransactionFinished) return;
// only when have added a new link
if (!e.object.changes.any(function(c) {
return (c.change === go.ChangedEvent.Insert && c.propertyName === "linkDataArray");
})) return;
// log link's new route
e.object.changes.each(function(c) {
if (c.model !== null && c.change === go.ChangedEvent.Property && c.propertyName === "points") {
console.log(c.object.points);
}
});
});