1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #3604 from node-red/fix-many-to-one-junction-slice

Handle many-to-one slicing of wires
This commit is contained in:
Stephen McLaughlin 2022-05-10 08:09:00 +01:00 committed by GitHub
commit 2ef50ab71f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -205,11 +205,6 @@ RED.view = (function() {
function init() {
// setTimeout(function() {
// function snap(p) { return RED.view.gridSize() * Math.round(p/RED.view.gridSize())}; for (var i = 0;i<10;i++) {
// RED.nodes.addJunction({_def:{defaults:{}}, type:'junction', z:"0ccdc1d81f2729cc",id:RED.nodes.id(),x:snap(Math.floor(Math.random()*600)),y:snap(Math.floor(Math.random()*600)), w:0,h:0})
// } ; RED.view.redraw(true)
// },2000)
chart = $("#red-ui-workspace-chart");
outer = d3.select("#red-ui-workspace-chart")
@ -1862,7 +1857,7 @@ RED.view = (function() {
slicePath = null;
RED.view.redraw(true);
} else if (mouse_mode == RED.state.SLICING_JUNCTION) {
var removedLinks = []
var removedLinks = new Set()
var addedLinks = []
var addedJunctions = []
@ -1871,8 +1866,14 @@ RED.view = (function() {
var sourceId = l.source.id+":"+l.sourcePort
groupedLinks[sourceId] = groupedLinks[sourceId] || []
groupedLinks[sourceId].push(l)
groupedLinks[l.target.id] = groupedLinks[l.target.id] || []
groupedLinks[l.target.id].push(l)
});
var linkGroups = Object.keys(groupedLinks)
linkGroups.sort(function(A,B) {
return groupedLinks[B].length - groupedLinks[A].length
})
linkGroups.forEach(function(gid) {
var links = groupedLinks[gid]
var junction = {
@ -1887,6 +1888,10 @@ RED.view = (function() {
inputs: 1,
dirty: true
}
links = links.filter(function(l) { return !removedLinks.has(l) })
if (links.length === 0) {
return
}
links.forEach(function(l) {
junction.x += l._sliceLocation.x
junction.y += l._sliceLocation.y
@ -1902,21 +1907,39 @@ RED.view = (function() {
RED.nodes.addJunction(junction)
addedJunctions.push(junction)
var newLink = {
let newLink
if (gid === links[0].source.id+":"+links[0].sourcePort) {
newLink = {
source: links[0].source,
sourcePort: links[0].sourcePort,
target: junction
}
} else {
newLink = {
source: junction,
sourcePort: 0,
target: links[0].target
}
}
addedLinks.push(newLink)
RED.nodes.addLink(newLink)
links.forEach(function(l) {
removedLinks.push(l)
removedLinks.add(l)
RED.nodes.removeLink(l)
var newLink = {
let newLink
if (gid === l.target.id) {
newLink = {
source: l.source,
sourcePort: l.sourcePort,
target: junction
}
} else {
newLink = {
source: junction,
sourcePort: 0,
target: l.target
}
}
addedLinks.push(newLink)
RED.nodes.addLink(newLink)
nodeGroups.add(l.source.g || "__NONE__")
@ -1937,7 +1960,7 @@ RED.view = (function() {
t: 'add',
links: addedLinks,
junctions: addedJunctions,
removedLinks: removedLinks
removedLinks: Array.from(removedLinks)
})
RED.nodes.dirty(true)
}