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:
commit
2ef50ab71f
@ -205,11 +205,6 @@ RED.view = (function() {
|
|||||||
|
|
||||||
function init() {
|
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");
|
chart = $("#red-ui-workspace-chart");
|
||||||
|
|
||||||
outer = d3.select("#red-ui-workspace-chart")
|
outer = d3.select("#red-ui-workspace-chart")
|
||||||
@ -1862,7 +1857,7 @@ RED.view = (function() {
|
|||||||
slicePath = null;
|
slicePath = null;
|
||||||
RED.view.redraw(true);
|
RED.view.redraw(true);
|
||||||
} else if (mouse_mode == RED.state.SLICING_JUNCTION) {
|
} else if (mouse_mode == RED.state.SLICING_JUNCTION) {
|
||||||
var removedLinks = []
|
var removedLinks = new Set()
|
||||||
var addedLinks = []
|
var addedLinks = []
|
||||||
var addedJunctions = []
|
var addedJunctions = []
|
||||||
|
|
||||||
@ -1871,8 +1866,14 @@ RED.view = (function() {
|
|||||||
var sourceId = l.source.id+":"+l.sourcePort
|
var sourceId = l.source.id+":"+l.sourcePort
|
||||||
groupedLinks[sourceId] = groupedLinks[sourceId] || []
|
groupedLinks[sourceId] = groupedLinks[sourceId] || []
|
||||||
groupedLinks[sourceId].push(l)
|
groupedLinks[sourceId].push(l)
|
||||||
|
|
||||||
|
groupedLinks[l.target.id] = groupedLinks[l.target.id] || []
|
||||||
|
groupedLinks[l.target.id].push(l)
|
||||||
});
|
});
|
||||||
var linkGroups = Object.keys(groupedLinks)
|
var linkGroups = Object.keys(groupedLinks)
|
||||||
|
linkGroups.sort(function(A,B) {
|
||||||
|
return groupedLinks[B].length - groupedLinks[A].length
|
||||||
|
})
|
||||||
linkGroups.forEach(function(gid) {
|
linkGroups.forEach(function(gid) {
|
||||||
var links = groupedLinks[gid]
|
var links = groupedLinks[gid]
|
||||||
var junction = {
|
var junction = {
|
||||||
@ -1887,6 +1888,10 @@ RED.view = (function() {
|
|||||||
inputs: 1,
|
inputs: 1,
|
||||||
dirty: true
|
dirty: true
|
||||||
}
|
}
|
||||||
|
links = links.filter(function(l) { return !removedLinks.has(l) })
|
||||||
|
if (links.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
links.forEach(function(l) {
|
links.forEach(function(l) {
|
||||||
junction.x += l._sliceLocation.x
|
junction.x += l._sliceLocation.x
|
||||||
junction.y += l._sliceLocation.y
|
junction.y += l._sliceLocation.y
|
||||||
@ -1902,20 +1907,38 @@ RED.view = (function() {
|
|||||||
|
|
||||||
RED.nodes.addJunction(junction)
|
RED.nodes.addJunction(junction)
|
||||||
addedJunctions.push(junction)
|
addedJunctions.push(junction)
|
||||||
var newLink = {
|
let newLink
|
||||||
source: links[0].source,
|
if (gid === links[0].source.id+":"+links[0].sourcePort) {
|
||||||
sourcePort: links[0].sourcePort,
|
newLink = {
|
||||||
target: junction
|
source: links[0].source,
|
||||||
|
sourcePort: links[0].sourcePort,
|
||||||
|
target: junction
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newLink = {
|
||||||
|
source: junction,
|
||||||
|
sourcePort: 0,
|
||||||
|
target: links[0].target
|
||||||
|
}
|
||||||
}
|
}
|
||||||
addedLinks.push(newLink)
|
addedLinks.push(newLink)
|
||||||
RED.nodes.addLink(newLink)
|
RED.nodes.addLink(newLink)
|
||||||
links.forEach(function(l) {
|
links.forEach(function(l) {
|
||||||
removedLinks.push(l)
|
removedLinks.add(l)
|
||||||
RED.nodes.removeLink(l)
|
RED.nodes.removeLink(l)
|
||||||
var newLink = {
|
let newLink
|
||||||
source: junction,
|
if (gid === l.target.id) {
|
||||||
sourcePort: 0,
|
newLink = {
|
||||||
target: l.target
|
source: l.source,
|
||||||
|
sourcePort: l.sourcePort,
|
||||||
|
target: junction
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newLink = {
|
||||||
|
source: junction,
|
||||||
|
sourcePort: 0,
|
||||||
|
target: l.target
|
||||||
|
}
|
||||||
}
|
}
|
||||||
addedLinks.push(newLink)
|
addedLinks.push(newLink)
|
||||||
RED.nodes.addLink(newLink)
|
RED.nodes.addLink(newLink)
|
||||||
@ -1937,7 +1960,7 @@ RED.view = (function() {
|
|||||||
t: 'add',
|
t: 'add',
|
||||||
links: addedLinks,
|
links: addedLinks,
|
||||||
junctions: addedJunctions,
|
junctions: addedJunctions,
|
||||||
removedLinks: removedLinks
|
removedLinks: Array.from(removedLinks)
|
||||||
})
|
})
|
||||||
RED.nodes.dirty(true)
|
RED.nodes.dirty(true)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user