mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Handle many-to-one slicing of wires
This commit is contained in:
		| @@ -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,20 +1907,38 @@ RED.view = (function() { | ||||
|  | ||||
|                 RED.nodes.addJunction(junction) | ||||
|                 addedJunctions.push(junction) | ||||
|                 var newLink = { | ||||
|                     source: links[0].source, | ||||
|                     sourcePort: links[0].sourcePort, | ||||
|                     target: junction | ||||
|                 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 = { | ||||
|                         source: junction, | ||||
|                         sourcePort: 0, | ||||
|                         target: l.target | ||||
|                     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) | ||||
| @@ -1937,7 +1960,7 @@ RED.view = (function() { | ||||
|                     t: 'add', | ||||
|                     links: addedLinks, | ||||
|                     junctions: addedJunctions, | ||||
|                     removedLinks: removedLinks | ||||
|                     removedLinks: Array.from(removedLinks) | ||||
|                 }) | ||||
|                 RED.nodes.dirty(true) | ||||
|             } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user