Link segment length

Hi,
I am having a bit of an issue with labels on orthogonal connectors, even if the segment where the label is located is very small the label will rotate. For very small segments, this has as a consequence that you’ll see a label perpendicular to the connecting line. How can I prevent the label from rotating if the segment where it is is smaller than 50px or so?

cheers

Have you set any segment… properties on the label?

There is an undocumented method that you could override on the Link class to return any angle that you like:

  /**
   * Dynamically compute the desired angle of a GraphObject along a segment of the route.
   * This method is only called when the GraphObject's {@link GraphObject#segmentOrientation} property value is
   * not {@link Link.None}.
   * @param {GraphObject} elt The {@link GraphObject} being rotated.
   * @param {EnumValue} orient A {@link Link} constant `Orient...` that indicates how the angle should be computed.
   * @param {number} angle The angle of the segment of the route where the GraphObject is attached.
   * @return {number} The intended angle for the GraphObject, in degrees.
   */
  public computeAngle(elt: GraphObject, orient: EnumValue, angle: number): number {
    return . ..;
  }

Of course if you override this method I suggest that you return the value of calling the super method for all labels except the one you care about. See https://gojs.net/latest/intro/extensions.html. You will need to define a subclass of Link and use it in your link template.

Hi Walter, thanks for answering so fast.
My label is actually a panel with some stuff in it. Its below. I think the computeAngle solves half my issue. I still need to know how long the segment is in order to decide whether to override the angle, right?

let nameBlock = go.GraphObject.make(
  go.Panel,
  'Horizontal',
  {
    name: 'nameBlock',
    segmentOffset: new go.Point(0, -15),
    segmentOrientation: go.Link.OrientUpright,
  },
  intrinsicnessBlock('sourceIntrinsicness'),
  arrowBlock('leftArrow'),
  relName,
  arrowBlock('rightArrow'),
  intrinsicnessBlock('targetIntrinsicness')
);

You can look at its measuredBounds.

but how do I get to the segment itself to calculate the measuredBounds?

That’s the measured bounds of the label that you care about, yes?
The Link.midAngle and midPoint might help.