we would like to have the link labels be on the first segment that can actually fit them… is that possible?
for some reason they appear to actually be perpendicular to links in some cases… my guess is that they are actually linked to a 0px segment there… :-S
this is the relevant part of the link template: map.add('', $GO(go.Link, <go.Link>{ selectionAdorned: true, routing: go.Link.AvoidsNodes, curve: go.Link.JumpOver, corner: 20, toEndSegmentLength: 25, fromEndSegmentLength: 25, toShortLength: 10 }, $GO(go.Shape, // the link path shape { isPanelMain: true, stroke: '#858585', strokeWidth: 2 }), $GO(go.Shape, // the arrowhead { toArrow: 'standard', stroke: null, fill: '#858585', scale: 1.5 }), $GO(go.TextBlock, 'outcome', // the label { textAlign: 'center', alignment: go.Spot.Center, alignmentFocus: go.Spot.BottomCenter, font: 'bold 13px sans-serif', stroke: '#242424', segmentFraction: 0.5, segmentOrientation: go.Link.OrientUpright }, new go.Binding('text', 'label'), new go.Binding('visible', 'showLabel') ) ));
what I ended up doing is binding segmentIndex to waypoints and using a converter function to compute the segment closest to the middle of the link that can fit the label…
this seems to work fine for both orthogonal and non-orthogonal links…
now… the remaining problem, and I believe this to be a bug in goJS, is that links that appear to be straight from one node to another have a 0px segment in the middle… :(… I will check this again to be sure it’s not my code causing it and I’ll try to provide you with more info…
In version 1.6.11 we made an improvement to the orientation of labels along segments where both end points are approximately at the same point. That’s why with this template:
Well, the upside down labels are due to Link.segmentOrientation being go.Link.OrientAlong instead of go.Link.OrientUpright. In my example that was intentional so that you could see the effective angle.
Yes, the link routing happens first, and then any link labels are positioned and “angled” accordingly. Forcing a re-route based on the size of a label might cause infinite routings or conflicts between multiple labels.
true… that’s why I said that computing links based on label widths is too much to ask for…
my problem with labels being perpendicular, even when using OrientAlong… seems to be related to links coming from top of the node and linking to top of node… if it’s a straight line between them (ie. from right side of the left node to left side of the right node) then it works fine.