//####Arg-Graph####
// a simple JQuery library to generate directional graphs.
// version 1.1, 2 Apr 2018
// by Naser Yousefi
// Website: https://github.com/n-yousefi/Arg-Graph
//################
; (function ($) {
$.fn.ArgGraph = function (options) {
var element = $(this);
var defaults = {
dragObject: new Object(),
mouseObject: new Object(),
groupingAttr: "data-group-id",
onChange: function () { },
onGraphChange: function () { }
};
var settings = {};
var getCenter = function (div) {
return {
x: div.offsetLeft + div.offsetWidth / 2,
y: div.offsetTop + div.offsetHeight / 2
};
};
var getRectangleLines = function (div) {
var result = new Object();
result.L1 = {
x1: div.offsetLeft,
y1: div.offsetTop,
x2: div.offsetLeft,
y2: div.offsetTop + div.offsetHeight
};
result.L2 = {
x1: div.offsetLeft,
y1: div.offsetTop,
x2: div.offsetLeft + div.offsetWidth,
y2: div.offsetTop
};
result.L3 = {
x1: div.offsetLeft,
y1: div.offsetTop + div.offsetHeight,
x2: div.offsetLeft + div.offsetWidth,
y2: div.offsetTop + div.offsetHeight,
};
result.L4 = {
x1: div.offsetLeft + div.offsetWidth,
y1: div.offsetTop,
x2: div.offsetLeft + div.offsetWidth,
y2: div.offsetTop + div.offsetHeight,
};
return result;
};
var checkLineCollision = function (line1, line2) {
var uA = ((line2.x2 - line2.x1) * (line1.y1 - line2.y1) - (line2.y2 - line2.y1) * (line1.x1 - line2.x1)) / ((line2.y2 - line2.y1) * (line1.x2 - line1.x1) - (line2.x2 - line2.x1) * (line1.y2 - line1.y1));
var uB = ((line1.x2 - line1.x1) * (line1.y1 - line2.y1) - (line1.y2 - line1.y1) * (line1.x1 - line2.x1)) / ((line2.y2 - line2.y1) * (line1.x2 - line1.x1) - (line2.x2 - line2.x1) * (line1.y2 - line1.y1));
if (uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1) {
var intersection =
{
x: line1.x1 + (uA * (line1.x2 - line1.x1)),
y: line1.y1 + (uA * (line1.y2 - line1.y1)),
};
return intersection;
}
return null;
};
var getDestinationPosition = function (orginPoint, destinationDiv) {
var destinationPoint = getCenter(destinationDiv);
var connectorLine = {
x1: orginPoint.x,
y1: orginPoint.y,
x2: destinationPoint.x,
y2: destinationPoint.y
};
var destinationLines = getRectangleLines(destinationDiv);
var result;
$.each(destinationLines,
function (index, line) {
if (!result) {
var collisionPoint = checkLineCollision(connectorLine, line);
if (collisionPoint) {
result = collisionPoint;
}
}
});
return result;
};
var getdStr = function (fropPos, toPos) {
return "M" +
(fropPos.x) + "," + (fropPos.y) + " " +
"L" +
(toPos.x) + "," + (toPos.y) + " ";
};
var refreshConnectors = function () {
var arrows = element.find("svg > g")[0];
if (arrows) {
arrows.innerHTML = "";
$.each(items,
function (index, orginDiv) {
var orginPoint = getCenter(orginDiv);
var $orginDiv = $(orginDiv);
if (settings.dragObject.dragging
&& settings.dragObject.type == 'C'
&& $orginDiv.attr("Id") == settings.dragObject.itemId
&& settings.mouseObject) {
var path = '