Skip to content

Commit

Permalink
separate out the parallel edge check and always apply it
Browse files Browse the repository at this point in the history
  • Loading branch information
gordonwoodhull committed Oct 23, 2017
1 parent 82c8cbb commit 9d8dd8d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/match_ports.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ dc_graph.match_ports = function(diagram, symbolPorts) {
nids.push(diagram.portNodeKey.eval(source.port));
symbolPorts.animateNodes(nids);
}
function is_valid(sourcePort, targetPort) {
return (_behavior.allowParallel() || !_wedges.some(function(e) {
return sourcePort.edges.indexOf(e) >= 0 && targetPort.edges.indexOf(e) >= 0;
})) && _behavior.isValid()(sourcePort, targetPort);
}
var _behavior = {
isValid: property(function(sourcePort, targetPort) {
if(!_behavior.allowParallel() && _wedges.some(function(e) {
return sourcePort.edges.indexOf(e) >= 0 && targetPort.edges.indexOf(e) >= 0;
})) return false;
return targetPort !== sourcePort && targetPort.name === sourcePort.name;
}),
allowParallel: property(false).react(function(v) {
Expand All @@ -30,15 +32,15 @@ dc_graph.match_ports = function(diagram, symbolPorts) {
}),
hoverPort: function(port) {
if(port) {
_validTargets = _wports.filter(_behavior.isValid().bind(null, port));
_validTargets = _wports.filter(is_valid.bind(null, port));
if(_validTargets.length)
return change_state(_validTargets, 'shimmer-medium');
} else if(_validTargets)
return change_state(_validTargets, 'small');
return null;
},
startDragEdge: function(source) {
_validTargets = _wports.filter(_behavior.isValid().bind(null, source.port));
_validTargets = _wports.filter(is_valid.bind(null, source.port));
var nids = change_state(_validTargets, 'shimmer');
if(_validTargets.length) {
symbolPorts.enableHover(false);
Expand All @@ -50,7 +52,7 @@ dc_graph.match_ports = function(diagram, symbolPorts) {
return _validTargets.length !== 0;
},
changeDragTarget: function(source, target) {
var nids, valid = target && _behavior.isValid()(source.port, target.port), before;
var nids, valid = target && is_valid(source.port, target.port), before;
if(valid) {
nids = change_state(_validTargets, 'small');
target.port.state = 'large'; // it's one of the valid
Expand All @@ -66,7 +68,7 @@ dc_graph.match_ports = function(diagram, symbolPorts) {
finishDragEdge: function(source, target) {
symbolPorts.enableHover(true);
reset_ports(source);
return _behavior.isValid()(source.port, target.port);
return is_valid(source.port, target.port);
},
cancelDragEdge: function(source) {
symbolPorts.enableHover(true);
Expand Down

0 comments on commit 9d8dd8d

Please sign in to comment.