aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinkView.tsx
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2020-09-09 17:34:35 -0400
committerbobzel <zzzman@gmail.com>2020-09-09 17:34:35 -0400
commite650f4dddb6a5f30b8eac0c6097cead28e04cd48 (patch)
treef015b71920a0ff6a0d5a7124b00acb4f8dc1001b /src/client/views/collections/collectionFreeForm/CollectionFreeFormLinkView.tsx
parent54c02b71da4e7a698e0d5d7ecf66ab3fd082edf6 (diff)
parent19751f41b642ad68e8029e6ea618232543a02ad8 (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web
Diffstat (limited to 'src/client/views/collections/collectionFreeForm/CollectionFreeFormLinkView.tsx')
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormLinkView.tsx30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinkView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinkView.tsx
index 3a2979696..417b4c1ff 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinkView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinkView.tsx
@@ -103,8 +103,24 @@ export class CollectionFreeFormLinkView extends React.Component<CollectionFreeFo
// showLinks={action(() => { })}
// />, { x: 300, y: 300 });
});
+
+
}
+ visibleY = (el: any) => {
+ var rect = el.getBoundingClientRect(), top = rect.top, height = rect.height,
+ el = el.parentNode;
+ do {
+ rect = el.getBoundingClientRect();
+ if (top <= rect.bottom === false && getComputedStyle(el).overflow === "hidden") return rect.bottom;
+ // Check if the element is out of view due to a container scrolling
+ if ((top + height) <= rect.top && getComputedStyle(el).overflow === "hidden") return rect.top;
+ el = el.parentNode;
+ } while (el != document.body);
+ // Check its within the document viewport
+ return top;//top <= document.documentElement.clientHeight && getComputedStyle(document.documentElement).overflow === "hidden";
+ };
+
@computed get renderData() {
this._start;
if (SnappingManager.GetIsDragging() || !this.props.A.ContentDiv || !this.props.B.ContentDiv || !this.props.LinkDocs.length) {
@@ -115,16 +131,18 @@ export class CollectionFreeFormLinkView extends React.Component<CollectionFreeFo
const bcont = this.props.B.ContentDiv.getElementsByClassName("linkAnchorBox-cont");
const a = (acont.length ? acont[0] : this.props.A.ContentDiv).getBoundingClientRect();
const b = (bcont.length ? bcont[0] : this.props.B.ContentDiv).getBoundingClientRect();
- const apt = Utils.closestPtBetweenRectangles(a.left, a.top, a.width, a.height,
- b.left, b.top, b.width, b.height,
+ const atop = this.visibleY(this.props.A.ContentDiv);
+ const btop = this.visibleY(this.props.B.ContentDiv);
+ const apt = Utils.closestPtBetweenRectangles(a.left, atop, a.width, a.height,
+ b.left, btop, b.width, b.height,
a.left + a.width / 2, a.top + a.height / 2);
- const bpt = Utils.closestPtBetweenRectangles(b.left, b.top, b.width, b.height,
- a.left, a.top, a.width, a.height,
+ const bpt = Utils.closestPtBetweenRectangles(b.left, btop, b.width, b.height,
+ a.left, atop, a.width, a.height,
apt.point.x, apt.point.y);
const pt1 = [apt.point.x, apt.point.y];
const pt2 = [bpt.point.x, bpt.point.y];
- const pt1vec = [pt1[0] - (a.left + a.width / 2), pt1[1] - (a.top + a.height / 2)];
- const pt2vec = [pt2[0] - (b.left + b.width / 2), pt2[1] - (b.top + b.height / 2)];
+ const pt1vec = [pt1[0] - (a.left + a.width / 2), pt1[1] - (atop + a.height / 2)];
+ const pt2vec = [pt2[0] - (b.left + b.width / 2), pt2[1] - (btop + b.height / 2)];
const pt1len = Math.sqrt((pt1vec[0] * pt1vec[0]) + (pt1vec[1] * pt1vec[1]));
const pt2len = Math.sqrt((pt2vec[0] * pt2vec[0]) + (pt2vec[1] * pt2vec[1]));
const ptlen = Math.sqrt((pt1[0] - pt2[0]) * (pt1[0] - pt2[0]) + (pt1[1] - pt2[1]) * (pt1[1] - pt2[1])) / 2;