There is a limitation in that one cannot modify the class of an object. We decided that that was a reasonable limitation because allowing a Node to turn into a Group (or vice versa) or allowing a Node to turn into a CustomNode (or vice versa) causes too many problems. And most language systems don’t allow it anyway. We didn’t want to remove the old Part and allocate and add a new Part because then references to the old object would be invalid. Those references could be anywhere in your code.
Which version of GoJS are you using? Evaluate go.version or look at the first few lines of the go.js file.
My guess is that you have loaded the definition of SemiCricleLink twice, once before defining the link templates and once after. So the two classes are technically different from each other, even though (presumably) they have the same definition.
Hi Walter, i got about the limitation, but then what would be the right way to change the template of the link?
In some cases i need dotted link, for some case line link. Code reference is in my above comment.
Thanks.
Most such cases of wanting to show a solid line or a dotted line or a dashed line can be achieved within the same template via a data Binding on the Shape.strokeDashArray property. Have the conversion function return
null for a solid line
[2, 2], or something like that, for a dotted line
[8, 3], or something like that, for a dashed line
So you would not be changing the category property of the link data object, nor the Part.category of the Link, but just some other property on the link data object and letting the binding update the link’s path’s strokeDashArray property. Remember to call Model.set to change any data properties.
Thus you might be able to use a single link template for all of your links, and you would not need to use the Diagram.linkTemplateMap at all.
But if you really need to sometimes have a semi-circular link path and sometimes a straight one, you should modify the SemicircleLink class so that the override of Link.makeGeometry, depending on some data property, either returns the custom Geometry or returns the “normal” result by calling the super method.
Hmmm, looking at the code, it seems that is already does that – just set or bind the Link.curviness property to zero if you want the normal rendering behavior.
Yes changing the strokeDashArray is easy, but in my case
sometimes dashed without arrow head and sometimes
normal with arrow head…
Basically im just setting the template for link on callback event
but if i dont use linkTemplate then it would become hard for me change the template, but also because of the class changing limitation category set is getting stuck.
I hope you got my point.