Tweaks in diagonal lines
This commit is contained in:
parent
5ab38bb1c6
commit
57d02448c8
|
@ -197,10 +197,10 @@ export class SimpleLine {
|
||||||
}
|
}
|
||||||
if(this.specs.anchors[anchor].includes("top")){
|
if(this.specs.anchors[anchor].includes("top")){
|
||||||
y = 0;
|
y = 0;
|
||||||
dirY = 1;
|
dirY = -1;
|
||||||
} else if (this.specs.anchors[anchor].includes("bottom")) {
|
} else if (this.specs.anchors[anchor].includes("bottom")) {
|
||||||
y = el.offsetHeight -1;
|
y = el.offsetHeight -1;
|
||||||
dirY = -1;
|
dirY = 1;
|
||||||
} else { // middle
|
} else { // middle
|
||||||
y = el.offsetHeight / 2;
|
y = el.offsetHeight / 2;
|
||||||
dirY = 0;
|
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
|
// 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)
|
const w = Math.max(elStartPos.x + startAnchor.x,elEndPos.x + endAnchor.x)
|
||||||
- Math.min(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)
|
const h = Math.max(elStartPos.y + startAnchor.y,elEndPos.y + endAnchor.y)
|
||||||
- Math.min(elStartPos.y + startAnchor.y,elEndPos.x + 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
|
// Determine start positions and end positions relative to container
|
||||||
const cStartPos = {
|
const cStartPos = {
|
||||||
x: elStartPos.x + startAnchor.x,
|
x: elStartPos.x + startAnchor.x,
|
||||||
y: elStartPos.y + startAnchor.y,
|
y: elStartPos.y + startAnchor.y,
|
||||||
dirx: elStartPos.x + startAnchor.x + startAnchor.dir.x * this.specs.gravity.start * (w/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 * (h/2),
|
diry: elStartPos.y + startAnchor.y + startAnchor.dir.y * this.specs.gravity.start * weight,
|
||||||
};
|
};
|
||||||
|
|
||||||
const cEndPos = {
|
const cEndPos = {
|
||||||
x: elEndPos.x + endAnchor.x,
|
x: elEndPos.x + endAnchor.x,
|
||||||
y: elEndPos.y + endAnchor.y,
|
y: elEndPos.y + endAnchor.y,
|
||||||
dirx: elEndPos.x + endAnchor.x + endAnchor.dir.x * this.specs.gravity.end * (w/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 * (h/2),
|
diry: elEndPos.y + endAnchor.y + endAnchor.dir.y * this.specs.gravity.end * weight,
|
||||||
};
|
};
|
||||||
|
|
||||||
// determine the bounding rectangle of the
|
// determine the bounding rectangle of the
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
import { SimpleLine } from "../amd/src/simpleline.js";
|
import { SimpleLine } from "../amd/src/simpleline.js";
|
||||||
|
|
||||||
let line = new SimpleLine("#start","#end", {autorefresh: 10});
|
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"]}});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user