diff --git a/amd/src/simpleline.js b/amd/src/simpleline.js index a7bb4c9..0c43552 100644 --- a/amd/src/simpleline.js +++ b/amd/src/simpleline.js @@ -197,10 +197,10 @@ export class SimpleLine { } if(this.specs.anchors[anchor].includes("top")){ y = 0; - dirY = 1; + dirY = -1; } else if (this.specs.anchors[anchor].includes("bottom")) { y = el.offsetHeight -1; - dirY = -1; + dirY = 1; } else { // middle y = el.offsetHeight / 2; dirY = 0; @@ -264,22 +264,22 @@ export class SimpleLine { // Determine basic h/w between start and end anchor to help determine desired control point length const w = Math.max(elStartPos.x + startAnchor.x,elEndPos.x + endAnchor.x) - Math.min(elStartPos.x + startAnchor.x,elEndPos.x + endAnchor.x); - const h = Math.max(elStartPos.y + startAnchor.y,elEndPos.x + endAnchor.y) - - Math.min(elStartPos.y + startAnchor.y,elEndPos.x + endAnchor.y); - + const h = Math.max(elStartPos.y + startAnchor.y,elEndPos.y + endAnchor.y) + - Math.min(elStartPos.y + startAnchor.y,elEndPos.y + endAnchor.y); + const weight = Math.sqrt(h*h+w*w)/2; // Determine start positions and end positions relative to container const cStartPos = { x: elStartPos.x + startAnchor.x, y: elStartPos.y + startAnchor.y, - dirx: elStartPos.x + startAnchor.x + startAnchor.dir.x * this.specs.gravity.start * (w/2), - diry: elStartPos.y + startAnchor.y + startAnchor.dir.y * this.specs.gravity.start * (h/2), + dirx: elStartPos.x + startAnchor.x + startAnchor.dir.x * this.specs.gravity.start * weight, + diry: elStartPos.y + startAnchor.y + startAnchor.dir.y * this.specs.gravity.start * weight, }; const cEndPos = { x: elEndPos.x + endAnchor.x, y: elEndPos.y + endAnchor.y, - dirx: elEndPos.x + endAnchor.x + endAnchor.dir.x * this.specs.gravity.end * (w/2), - diry: elEndPos.y + endAnchor.y + endAnchor.dir.y * this.specs.gravity.end * (h/2), + dirx: elEndPos.x + endAnchor.x + endAnchor.dir.x * this.specs.gravity.end * weight, + diry: elEndPos.y + endAnchor.y + endAnchor.dir.y * this.specs.gravity.end * weight, }; // determine the bounding rectangle of the diff --git a/test/simpleline-test.html b/test/simpleline-test.html index bade200..d0efcac 100644 --- a/test/simpleline-test.html +++ b/test/simpleline-test.html @@ -37,7 +37,7 @@ import { SimpleLine } from "../amd/src/simpleline.js"; let line = new SimpleLine("#start","#end", {autorefresh: 10}); - let line2 = new SimpleLine("#start2","#end2",{autorefresh: 10}); + let line2 = new SimpleLine("#start2","#end2",{autorefresh: 10, anchors: {start: ["bottom","right"], end: ["top","left"]}});