[Feature] Expand current selection to include neighbors by pressing CTRL+SHIFT+UP (#1090)
* Expand current selection to include neighbors by pressing CTRL+SHIFT+UP * minor fixes as requested
This commit is contained in:
parent
1124d76475
commit
33276444c7
3 changed files with 43 additions and 23 deletions
|
@ -20,6 +20,21 @@ const Control = {
|
||||||
node.setData('dim', 30, 'current')
|
node.setData('dim', 30, 'current')
|
||||||
Selected.Nodes.push(node)
|
Selected.Nodes.push(node)
|
||||||
},
|
},
|
||||||
|
selectNeighbors: function() {
|
||||||
|
if (Selected.Nodes.length > 0) {
|
||||||
|
//For each selected node, select all connected node and the synapses too
|
||||||
|
Selected.Nodes.forEach((item) => {
|
||||||
|
if (Visualize.mGraph.graph.getNode(item.id).adjacencies) {
|
||||||
|
for (const adjID in Visualize.mGraph.graph.getNode(item.id).adjacencies) {
|
||||||
|
Control.selectNode(Visualize.mGraph.graph.getNode(adjID))
|
||||||
|
Control.selectEdge(Visualize.mGraph.graph.getNode(item.id).adjacencies[adjID])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
Visualize.mGraph.plot()
|
||||||
|
}
|
||||||
|
},
|
||||||
deselectAllNodes: function() {
|
deselectAllNodes: function() {
|
||||||
var l = Selected.Nodes.length
|
var l = Selected.Nodes.length
|
||||||
for (var i = l - 1; i >= 0; i -= 1) {
|
for (var i = l - 1; i >= 0; i -= 1) {
|
||||||
|
|
|
@ -31,8 +31,13 @@ const Listeners = {
|
||||||
case 27: // if esc key is pressed
|
case 27: // if esc key is pressed
|
||||||
JIT.escKeyHandler()
|
JIT.escKeyHandler()
|
||||||
break
|
break
|
||||||
|
case 38: // if UP key is pressed
|
||||||
|
if ((e.ctrlKey || e.metaKey) && e.shiftKey){
|
||||||
|
Control.selectNeighbors()
|
||||||
|
}
|
||||||
|
break
|
||||||
case 46: // if DEL is pressed
|
case 46: // if DEL is pressed
|
||||||
if(e.target.tagName !== "INPUT" && e.target.tagName !== "TEXTAREA" && (Selected.Nodes.length + Selected.Edges.length) > 0){
|
if (e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA' && (Selected.Nodes.length + Selected.Edges.length) > 0) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
Control.removeSelectedNodes()
|
Control.removeSelectedNodes()
|
||||||
Control.removeSelectedEdges()
|
Control.removeSelectedEdges()
|
||||||
|
|
|
@ -208,27 +208,27 @@ const Util = {
|
||||||
ox = graph.canvas.translateOffsetX,
|
ox = graph.canvas.translateOffsetX,
|
||||||
oy = graph.canvas.translateOffsetY,
|
oy = graph.canvas.translateOffsetY,
|
||||||
sx = graph.canvas.scaleOffsetX,
|
sx = graph.canvas.scaleOffsetX,
|
||||||
sy = graph.canvas.scaleOffsetY;
|
sy = graph.canvas.scaleOffsetY
|
||||||
|
|
||||||
var pointerCoordX = (zoomPoint.x - p.x - s.width / 2 - ox) * (1 / sx),
|
var pointerCoordX = (zoomPoint.x - p.x - s.width / 2 - ox) * (1 / sx),
|
||||||
pointerCoordY = (zoomPoint.y - p.y - s.height / 2 - oy) * (1 / sy);
|
pointerCoordY = (zoomPoint.y - p.y - s.height / 2 - oy) * (1 / sy)
|
||||||
|
|
||||||
//This translates the canvas to be centred over the zoomPoint, then the canvas is zoomed as intended.
|
// This translates the canvas to be centred over the zoomPoint, then the canvas is zoomed as intended.
|
||||||
graph.canvas.translate(-pointerCoordX,-pointerCoordY);
|
graph.canvas.translate(-pointerCoordX, -pointerCoordY)
|
||||||
graph.canvas.scale(ans, ans);
|
graph.canvas.scale(ans, ans)
|
||||||
|
|
||||||
//Get the canvas attributes again now that is has changed
|
// Get the canvas attributes again now that is has changed
|
||||||
s = graph.canvas.getSize(),
|
s = graph.canvas.getSize(),
|
||||||
p = graph.canvas.getPos(),
|
p = graph.canvas.getPos(),
|
||||||
ox = graph.canvas.translateOffsetX,
|
ox = graph.canvas.translateOffsetX,
|
||||||
oy = graph.canvas.translateOffsetY,
|
oy = graph.canvas.translateOffsetY,
|
||||||
sx = graph.canvas.scaleOffsetX,
|
sx = graph.canvas.scaleOffsetX,
|
||||||
sy = graph.canvas.scaleOffsetY;
|
sy = graph.canvas.scaleOffsetY
|
||||||
var newX = (zoomPoint.x - p.x - s.width / 2 - ox) * (1 / sx),
|
var newX = (zoomPoint.x - p.x - s.width / 2 - ox) * (1 / sx),
|
||||||
newY = (zoomPoint.y - p.y - s.height / 2 - oy) * (1 / sy);
|
newY = (zoomPoint.y - p.y - s.height / 2 - oy) * (1 / sy)
|
||||||
|
|
||||||
//Translate the canvas to put the pointer back over top the same coordinate it was over before
|
// Translate the canvas to put the pointer back over top the same coordinate it was over before
|
||||||
graph.canvas.translate(newX-pointerCoordX,newY-pointerCoordY);
|
graph.canvas.translate(newX - pointerCoordX, newY - pointerCoordY)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue