diff --git a/src/components/EditorCanvas/Relationship.jsx b/src/components/EditorCanvas/Relationship.jsx
index 2793f68..cffb67a 100644
--- a/src/components/EditorCanvas/Relationship.jsx
+++ b/src/components/EditorCanvas/Relationship.jsx
@@ -1,10 +1,5 @@
-import { useMemo, useRef } from "react";
-import {
- Cardinality,
- darkBgTheme,
- ObjectType,
- Tab,
-} from "../../data/constants";
+import { useMemo, useRef, useState, useEffect } from "react";
+import { Cardinality, ObjectType, Tab } from "../../data/constants";
import { calcPath } from "../../utils/calcPath";
import { useDiagram, useSettings, useLayout, useSelect } from "../../hooks";
import { useTranslation } from "react-i18next";
@@ -46,13 +41,13 @@ export default function Relationship({ data }) {
// the translated values are to ensure backwards compatibility
case t(Cardinality.MANY_TO_ONE):
case Cardinality.MANY_TO_ONE:
- cardinalityStart = "n";
+ cardinalityStart = data.manyLabel || "n";
cardinalityEnd = "1";
break;
case t(Cardinality.ONE_TO_MANY):
case Cardinality.ONE_TO_MANY:
cardinalityStart = "1";
- cardinalityEnd = "n";
+ cardinalityEnd = data.manyLabel || "n";
break;
case t(Cardinality.ONE_TO_ONE):
case Cardinality.ONE_TO_ONE:
@@ -128,63 +123,30 @@ export default function Relationship({ data }) {
cursor="pointer"
/>
{settings.showRelationshipLabels && (
- <>
-
-
- {data.name}
-
- >
+
+ {data.name}
+
)}
{pathRef.current && settings.showCardinality && (
<>
-
-
- {cardinalityStart}
-
-
-
- {cardinalityEnd}
-
+ text={cardinalityEnd}
+ />
>
)}
@@ -212,3 +174,41 @@ export default function Relationship({ data }) {
>
);
}
+
+function CardinalityLabel({ x, y, text, r = 12, padding = 14 }) {
+ const [textWidth, setTextWidth] = useState(0);
+ const textRef = useRef(null);
+
+ useEffect(() => {
+ if (textRef.current) {
+ const bbox = textRef.current.getBBox();
+ setTextWidth(bbox.width);
+ }
+ }, [text]);
+
+ return (
+
+
+
+ {text}
+
+
+ );
+}
diff --git a/src/components/EditorSidePanel/RelationshipsTab/RelationshipInfo.jsx b/src/components/EditorSidePanel/RelationshipsTab/RelationshipInfo.jsx
index be15be1..2d7f74d 100644
--- a/src/components/EditorSidePanel/RelationshipsTab/RelationshipInfo.jsx
+++ b/src/components/EditorSidePanel/RelationshipsTab/RelationshipInfo.jsx
@@ -223,6 +223,41 @@ export default function RelationshipInfo({ data }) {
className="w-full"
onChange={changeCardinality}
/>
+
+ {data.cardinality !== Cardinality.ONE_TO_ONE && (
+ <>
+
+ {t("many_side_label")}:
+
+ updateRelationship(data.id, { manyLabel: value })}
+ onFocus={(e) => setEditField({ manyLabel: e.target.value })}
+ defaultValue="n"
+ onBlur={(e) => {
+ if (e.target.value === editField.manyLabel) return;
+ setUndoStack((prev) => [
+ ...prev,
+ {
+ action: Action.EDIT,
+ element: ObjectType.RELATIONSHIP,
+ component: "self",
+ rid: data.id,
+ undo: editField,
+ redo: { manyLabel: e.target.value },
+ message: t("edit_relationship", {
+ refName: e.target.value,
+ extra: "[manyLabel]",
+ }),
+ },
+ ]);
+ setRedoStack([]);
+ }}
+ />
+ >
+ )}
+
{t("on_update")}:
diff --git a/src/i18n/locales/en.js b/src/i18n/locales/en.js
index 9d401a3..f280f4d 100644
--- a/src/i18n/locales/en.js
+++ b/src/i18n/locales/en.js
@@ -256,6 +256,8 @@ const en = {
export_saved_data: "Export saved data",
dbml_view: "DBML view",
tab_view: "Tab view",
+ label: "Label",
+ many_side_label: "Many(n) side label",
},
};