LinkShiftingTool's Handle Distance - Issue

Hey there, People. → LinkShiftingTool

I’ve added the “LinkShifting” Extension that allows users to shift the link to anywhere on the shape using a handle. It’s working as expected but I’m having a slight issue with the position/distance of the handles (on both ends of the link)

Here’s an example image of the problem,
image

As you can see, the (LinkShiftingTool) handles on both ends are overlapping the re-linking tool’s handles, and I want to avoid that.

Apparently, the position of both the handles of the LinkShiftingTool is somehow linked the the link’s toEndSegmentLength & fromEndSegmentLength properties. But, I don’t want to change them (set to 0).

Look,

Is there any way I can change the position of both the handles of the LinkShiftingTool a bit inwards?

I just want the 2nd image’s behaviour to be played in the 1st image (problem) without the need of changing the toEndSegmentLength & fromEndSegmentLength properties of the Link.

Just for the reference, this is a code snippet from the extension file (LinkShiftingTool.ts),

  constructor(init?: Partial<LinkShiftingTool>) {
    super();
    this.name = "LinkShifting";
    const h: go.Shape = new go.Shape();
    h.geometryString = "F1 M0 0 L8 0 M8 4 L0 4";
    h.fill = null;
    h.stroke = "dodgerblue";
    h.background = "lightblue";
    h.cursor = "pointer";
    h.segmentIndex = 0;
    h.segmentFraction = 1;
    h.segmentOrientation = go.Orientation.Along;
    const g: go.Shape = new go.Shape();
    g.geometryString = "F1 M0 0 L8 0 M8 4 L0 4";
    g.fill = null;
    g.stroke = "dodgerblue";
    g.background = "lightblue";
    g.cursor = "pointer";
    g.segmentIndex = -1;
    g.segmentFraction = 1;
    g.segmentOrientation = go.Orientation.Along;
    this._fromHandleArchetype = h;
    this._toHandleArchetype = g;
    this._originalPoints = null;
    this._handle = null;
    this._originalPoints = null;
    if (init) Object.assign(this, init);
  }

Thank you for reading.

What if you try to set a segmentOffset on each of them?

h.segmentOffset = new go.Point(10, 0);
// ...
g.segmentOffset = new go.Point(-10, 0);

(edited: the “to” handle you probably want a negative offset, not positive)

It does help with the problem, but only if you have links that are only routed go.Routing.Normal. I’ve 2 different types of links, therefore setting the offset does this,

Example Picture,

I’m okay with this as it does the job, but is there a way to apply the offset values so that the handle follows the link’s path and not go off of it?

Try something like

    h.segmentIndex = 1;
    h.segmentFraction = 0.05;
    // ...
    g.segmentIndex = -2;
    g.segmentFraction = 0.05;

(with no offset)

1 Like

It worked flawlessly! Exactly what I needed.
Appreciated!