MCPcopy Create free account
hub / github.com/SeaOfNodes/Simple / _moveEdge

Function _moveEdge

chapter24/docs/d3-graphviz.js:1491–1539  ·  view source on GitHub ↗
(edge, x1, y1, x2, y2, attributes, options)

Source from the content-addressed store, hash-verified

1489 _moveEdge(edge, x1, y1, x2, y2, attributes, options);
1490 }
1491 function _moveEdge(edge, x1, y1, x2, y2, attributes, options) {
1492 var shortening = options.shortening || 0;
1493 var arrowHeadLength = 10;
1494 var arrowHeadWidth = 7;
1495 var margin = 0.1;
1496 var arrowHeadPoints = [[0, -arrowHeadWidth / 2], [arrowHeadLength, 0], [0, arrowHeadWidth / 2], [0, -arrowHeadWidth / 2]];
1497 var dx = x2 - x1;
1498 var dy = y2 - y1;
1499 var length = Math.sqrt(dx * dx + dy * dy);
1500 if (length == 0) {
1501 var cosA = 1;
1502 var sinA = 0;
1503 } else {
1504 var cosA = dx / length;
1505 var sinA = dy / length;
1506 }
1507 x2 = x1 + (length - shortening - arrowHeadLength - margin) * cosA;
1508 y2 = y1 + (length - shortening - arrowHeadLength - margin) * sinA;
1509 if (attributes.URL || attributes.tooltip) {
1510 var a = edge.selectWithoutDataPropagation("g").selectWithoutDataPropagation("a");
1511 var line = a.selectWithoutDataPropagation("path");
1512 var arrowHead = a.selectWithoutDataPropagation("polygon");
1513 } else {
1514 var line = edge.selectWithoutDataPropagation("path");
1515 var arrowHead = edge.selectWithoutDataPropagation("polygon");
1516 }
1517 var path1 = d3Path.path();
1518 path1.moveTo(x1, y1);
1519 path1.lineTo(x2, y2);
1520 line.attr("d", path1);
1521 x2 = x1 + (length - shortening - arrowHeadLength) * cosA;
1522 y2 = y1 + (length - shortening - arrowHeadLength) * sinA;
1523 for (var i = 0; i < arrowHeadPoints.length; i++) {
1524 var point = arrowHeadPoints[i];
1525 arrowHeadPoints[i] = rotate(point[0], point[1], cosA, sinA);
1526 }
1527 for (var i = 0; i < arrowHeadPoints.length; i++) {
1528 var point = arrowHeadPoints[i];
1529 arrowHeadPoints[i] = [x2 + point[0], y2 + point[1]];
1530 }
1531 var allPoints = [];
1532 for (var i = 0; i < arrowHeadPoints.length; i++) {
1533 var point = arrowHeadPoints[i];
1534 allPoints.push(point.join(','));
1535 }
1536 var pointsAttr = allPoints.join(' ');
1537 arrowHead.attr("points", pointsAttr);
1538 return this;
1539 }
1540 function moveDrawnEdgeEndPoint(x2, y2) {
1541 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1542 if (!this._drawnEdge) {

Callers 2

_updateEdgeFunction · 0.70
moveDrawnEdgeEndPointFunction · 0.70

Calls 5

rotateFunction · 0.70
moveToMethod · 0.45
lineToMethod · 0.45
pushMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected