Created
September 4, 2013 15:53
-
-
Save oxtoacart/6439042 to your computer and use it in GitHub Desktop.
Snippet for generating self-loops on Lantern map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use this in place of the existing pathConnection defined in vis.js | |
$scope.pathConnection = function (peer) { | |
var pSelf = projection([model.location.lon, model.location.lat]), | |
pPeer = projection([peer.lon, peer.lat]), | |
xS = pSelf[0], yS = pSelf[1], xP = pPeer[0], yP = pPeer[1]; | |
var distanceBetweenPeers = Math.sqrt(Math.pow(xS - xP, 2) + Math.pow(yS - yP, 2)); | |
if (distanceBetweenPeers < 30) { | |
// Peer and self are very close, draw a loopy arc | |
var xC1 = Math.min(xS, xP) - 20; | |
var xC2 = Math.max(xS, xP) + 20; | |
var yC = Math.max(yS, yP) + 30; | |
return 'M'+xS+','+yS+' C '+xC1+','+yC+' '+xC2+','+yC+' '+xP+','+yP; | |
} else { | |
// Peer and self are at different positions, draw arc between them | |
var controlPoint = [abs(xS+xP)/2, min(yS, yP) - abs(xP-xS)*0.3], | |
xC = controlPoint[0], yC = controlPoint[1]; | |
return $scope.inGiveMode ? | |
'M'+xP+','+yP+' Q '+xC+','+yC+' '+xS+','+yS : | |
'M'+xS+','+yS+' Q '+xC+','+yC+' '+xP+','+yP; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment