Browse Source

feat: vertical align for labelled arrows

Aakansha Doshi 2 years ago
parent
commit
66ccc254f0
2 changed files with 20 additions and 2 deletions
  1. 15 1
      src/element/linearElementEditor.ts
  2. 5 1
      src/element/textElement.ts

+ 15 - 1
src/element/linearElementEditor.ts

@@ -40,7 +40,11 @@ import { isBindingElement } from "./typeChecks";
 import { shouldRotateWithDiscreteAngle } from "../keys";
 import { getBoundTextElement, handleBindTextResize } from "./textElement";
 import { getShapeForElement } from "../renderer/renderElement";
-import { DRAGGING_THRESHOLD } from "../constants";
+import {
+  BOUND_TEXT_PADDING,
+  DRAGGING_THRESHOLD,
+  VERTICAL_ALIGN,
+} from "../constants";
 import { Mutable } from "../utility-types";
 
 const editorMidPointsCache: {
@@ -1304,6 +1308,16 @@ export class LinearElementEditor {
       }
       x = midSegmentMidpoint[0] - boundTextElement.width / 2;
       y = midSegmentMidpoint[1] - boundTextElement.height / 2;
+      if (element.points.length === 2) {
+        if (boundTextElement.verticalAlign === VERTICAL_ALIGN.TOP) {
+          y =
+            midSegmentMidpoint[1] -
+            boundTextElement.height -
+            BOUND_TEXT_PADDING * 2;
+        } else if (boundTextElement.verticalAlign === VERTICAL_ALIGN.BOTTOM) {
+          y = midSegmentMidpoint[1] + BOUND_TEXT_PADDING * 2;
+        }
+      }
     }
     return { x, y };
   };

+ 5 - 1
src/element/textElement.ts

@@ -793,7 +793,11 @@ export const shouldAllowVerticalAlign = (
     const hasBoundContainer = isBoundToContainer(element);
     if (hasBoundContainer) {
       const container = getContainerElement(element);
-      if (isTextElement(element) && isArrowElement(container)) {
+      if (
+        isTextElement(element) &&
+        isArrowElement(container) &&
+        container.points.length > 2
+      ) {
         return false;
       }
       return true;