# Straighten Links between nodes

**URL:** <https://discourse.nodered.org/t/straighten-links-between-nodes/102237>\
**Category:** General\
**Created:** [25 November 2026 10:43 UTC](https://discourse.nodered.org/t/straighten-links-between-nodes/102237 "2026-11-25T10:43:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [25 November 2026 10:43 UTC](https://discourse.nodered.org/t/straighten-links-between-nodes/102237/1 "2026-11-25T10:43:40Z")

</div>

Hi There,

aligning links to be straight has been a bugbear for a while, so finally inspiration has hit:

![align-link-to-source-or-target](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/6/8619ca262f9b8920bae60b18b06b9a070a6e44ea.gif)

I created some JS code to straighten links. This works by computing the differ between the start of a link and the end of a link. Then that differ is either added or subtract from the target/source node location. Since I don't use grids, this a bugbear with me hence this functionality.

This works with multi-output nodes as will as single output nodes. Hence this extra functionality: align middle/top/bottom does not work with multi-output nodes and single links.

I added shortcuts for this:

 ![shortcut-align-link](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/5/d52f1e39882d0e924277d44418b02f675b1fa3e1.png)

And I will add it to the [presenter-mode](https://flows.nodered.org/node/@gregoriusrippenstein/node-red-presenter-mode) node where I collect together various extra functionality.

Functionality:

```auto
(function(){
    RED.actions.remove("presenter-mode:align-link-to-destination")
    RED.actions.add("presenter-mode:align-link-to-destination", () => {
        if (RED.view.selection().links?.length > 0) {
            RED.view.selection().links.forEach( lnk => {
                let diff = Math.abs(lnk.y1 - lnk.y2)
                let hst = {
                    dirty: false,
                    t: "move",
                    nodes: [{
                        n: lnk.source,
                        ox: lnk.source.x,
                        oy: lnk.source.y,
                        moved: false
                    }]
                }

                // here we move the source to match the target, which means
                // adding the diff or subtracting the diff from the source 
                // y value
                if ( lnk.y1 > lnk.y2) { // source is higher than target
                    lnk.source.y -= diff
                } else {
                    lnk.source.y += diff
                }
                lnk.source.dirty = true
                RED.history.push(hst)
            })
        }
        RED.nodes.dirty(true);
        RED.view.redraw();
    })

    RED.actions.remove("presenter-mode:align-link-to-source")
    RED.actions.add("presenter-mode:align-link-to-source", () => {
        if (RED.view.selection().links?.length > 0) {
            RED.view.selection().links.forEach(lnk => {
                let diff = Math.abs(lnk.y1 - lnk.y2)
                let hst = {
                    dirty: false,
                    t: "move",
                    nodes: [{
                        n: lnk.target,
                        ox: lnk.target.x,
                        oy: lnk.target.y,
                        moved: false
                    }]
                }

                if (lnk.y1 > lnk.y2) { // source is higher than target
                    lnk.target.y += diff
                } else {
                    lnk.target.y -= diff
                }

                lnk.target.dirty = true
                RED.history.push(hst)
            })
        }
        RED.nodes.dirty(true);
        RED.view.redraw();
    })

})();

```

Related:

- [Align Horizontally, align vertically feature request](https://discourse.nodered.org/t/align-horizontally-align-vertically-feature-request/37725)
- [Align to make wires straight](https://discourse.nodered.org/t/align-to-make-wires-straight/99223)
- ...
