@@ -187,155 +194,3 @@ export default function Templates() {
);
}
-
-function Thumbnail({ diagram, i }) {
- const zoom = 0.3;
- return (
-
-
-
- );
-}
diff --git a/src/templates/template1.js b/src/templates/template1.js
index 6069546..fd4948d 100644
--- a/src/templates/template1.js
+++ b/src/templates/template1.js
@@ -288,15 +288,10 @@ export const template1 = {
startFieldId: 1,
endTableId: 0,
endFieldId: 0,
- startX: 292.57925,
- startY: 124.20675000000011,
- endX: 129.92525,
- endY: 350.2977500000002,
name: "blog_posts_user_id_fk",
cardinality: "Many to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 0,
},
{
@@ -304,15 +299,10 @@ export const template1 = {
startFieldId: 1,
endTableId: 1,
endFieldId: 0,
- startX: 520.6211250000003,
- startY: 446.6078750000002,
- endX: 292.57925,
- endY: 88.20675000000011,
name: "comments_blog_id_fk",
cardinality: "Many to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 1,
},
{
@@ -320,15 +310,10 @@ export const template1 = {
startFieldId: 2,
endTableId: 0,
endFieldId: 0,
- startX: 520.6211250000003,
- startY: 482.6078750000002,
- endX: 129.92525,
- endY: 350.2977500000002,
name: "comments_user_id_fk",
cardinality: "Many to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 2,
},
{
@@ -336,15 +321,10 @@ export const template1 = {
startFieldId: 1,
endTableId: 3,
endFieldId: 0,
- startX: 827.1175000000004,
- startY: 236.55062500000008,
- endX: 758.2832500000009,
- endY: 387.1841250000001,
name: "blog_tag_tag_id_fk",
cardinality: "Many to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 3,
},
{
@@ -352,15 +332,10 @@ export const template1 = {
startFieldId: 0,
endTableId: 1,
endFieldId: 0,
- startX: 827.1175000000004,
- startY: 200.55062500000008,
- endX: 292.57925,
- endY: 88.20675000000011,
name: "blog_tag_blog_id_fk",
cardinality: "Many to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 4,
},
],
diff --git a/src/templates/template2.js b/src/templates/template2.js
index 91a040e..89014bc 100644
--- a/src/templates/template2.js
+++ b/src/templates/template2.js
@@ -303,15 +303,10 @@ export const template2 = {
startFieldId: 4,
endTableId: 1,
endFieldId: 0,
- startX: 380,
- startY: 233,
- endX: 56,
- endY: 128,
name: "employees_dep_id_fk",
cardinality: "Many to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 0,
},
{
@@ -319,15 +314,10 @@ export const template2 = {
startFieldId: 5,
endTableId: 2,
endFieldId: 0,
- startX: 380,
- startY: 269,
- endX: 52,
- endY: 353,
name: "employees_pos_id_fk",
cardinality: "One to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 1,
},
{
@@ -335,15 +325,10 @@ export const template2 = {
startFieldId: 1,
endTableId: 3,
endFieldId: 0,
- startX: 699,
- startY: 400,
- endX: 683,
- endY: 97,
name: "project_assignment_project_id_fk",
cardinality: "One to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 2,
},
{
@@ -351,15 +336,10 @@ export const template2 = {
startFieldId: 2,
endTableId: 0,
endFieldId: 0,
- startX: 699,
- startY: 436,
- endX: 380,
- endY: 89,
name: "project_assignment_employee_id_fk",
cardinality: "Many to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 3,
},
],
diff --git a/src/templates/template3.js b/src/templates/template3.js
index 9734c22..a3d30f4 100644
--- a/src/templates/template3.js
+++ b/src/templates/template3.js
@@ -364,15 +364,10 @@ export const template3 = {
startFieldId: 5,
endTableId: 0,
endFieldId: 0,
- startX: 771,
- startY: 296,
- endX: 346,
- endY: 369,
name: "order_product_id_fk",
cardinality: "One to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 0,
},
{
@@ -380,15 +375,10 @@ export const template3 = {
startFieldId: 4,
endTableId: 1,
endFieldId: 0,
- startX: 346,
- startY: 513,
- endX: 664,
- endY: 460,
name: "products_category_id_fk",
cardinality: "Many to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 1,
},
{
@@ -396,15 +386,10 @@ export const template3 = {
startFieldId: 1,
endTableId: 4,
endFieldId: 0,
- startX: 48,
- startY: 198,
- endX: 417,
- endY: 85,
name: "reviews_customer_id_fk",
cardinality: "Many to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 2,
},
{
@@ -412,15 +397,10 @@ export const template3 = {
startFieldId: 2,
endTableId: 0,
endFieldId: 0,
- startX: 48,
- startY: 234,
- endX: 346,
- endY: 369,
name: "reviews_product_id_fk",
cardinality: "One to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 3,
},
{
@@ -428,15 +408,10 @@ export const template3 = {
startFieldId: 2,
endTableId: 4,
endFieldId: 0,
- startX: 771,
- startY: 188,
- endX: 417,
- endY: 85,
name: "orders_customer_id_fk",
cardinality: "Many to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 4,
},
],
diff --git a/src/templates/template4.js b/src/templates/template4.js
index 7290859..997c277 100644
--- a/src/templates/template4.js
+++ b/src/templates/template4.js
@@ -315,15 +315,10 @@ export const template4 = {
startFieldId: 3,
endTableId: 2,
endFieldId: 0,
- startX: 182,
- startY: 265,
- endX: 490,
- endY: 411,
name: "books_author_id_fk",
cardinality: "Many to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 0,
},
{
@@ -331,15 +326,10 @@ export const template4 = {
startFieldId: 1,
endTableId: 0,
endFieldId: 0,
- startX: 516,
- startY: 119,
- endX: 182,
- endY: 157,
name: "reservations_book_id_fk",
cardinality: "One to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 1,
},
{
@@ -347,15 +337,10 @@ export const template4 = {
startFieldId: 2,
endTableId: 4,
endFieldId: 0,
- startX: 516,
- startY: 155,
- endX: 795,
- endY: 289,
name: "reservations_patron_id_fk",
cardinality: "One to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 2,
},
{
@@ -363,15 +348,10 @@ export const template4 = {
startFieldId: 4,
endTableId: 1,
endFieldId: 0,
- startX: 182,
- startY: 301,
- endX: 93,
- endY: 448,
name: "books_genre_id_fk",
cardinality: "Many to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 3,
},
],
diff --git a/src/templates/template5.js b/src/templates/template5.js
index d0b7c5d..2dbe15d 100644
--- a/src/templates/template5.js
+++ b/src/templates/template5.js
@@ -553,15 +553,10 @@ export const template5 = {
startFieldId: 1,
endTableId: 1,
endFieldId: 0,
- startX: 144,
- startY: 197,
- endX: 399,
- endY: 384,
name: "accounts_customer_id_fk",
cardinality: "Many to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 0,
},
{
@@ -569,15 +564,10 @@ export const template5 = {
startFieldId: 2,
endTableId: 1,
endFieldId: 0,
- startX: 787,
- startY: 170,
- endX: 399,
- endY: 384,
name: "cards_customer_id_fk",
cardinality: "Many to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 1,
},
{
@@ -585,15 +575,10 @@ export const template5 = {
startFieldId: 1,
endTableId: 1,
endFieldId: 0,
- startX: 934,
- startY: 386,
- endX: 399,
- endY: 384,
name: "loans_customer_id_fk",
cardinality: "Many to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 2,
},
{
@@ -601,15 +586,10 @@ export const template5 = {
startFieldId: 1,
endTableId: 1,
endFieldId: 0,
- startX: 679,
- startY: 500,
- endX: 399,
- endY: 384,
name: "investments_customer_id_fk",
cardinality: "Many to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 3,
},
{
@@ -617,15 +597,10 @@ export const template5 = {
startFieldId: 1,
endTableId: 0,
endFieldId: 0,
- startX: 446,
- startY: 109,
- endX: 144,
- endY: 161,
name: "transactions_account_id_fk",
cardinality: "Many to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 4,
},
{
@@ -633,15 +608,10 @@ export const template5 = {
startFieldId: 2,
endTableId: 0,
endFieldId: 0,
- startX: 127,
- startY: 499,
- endX: 144,
- endY: 161,
name: "transfers_to_fk",
cardinality: "Many to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 5,
},
{
@@ -649,15 +619,10 @@ export const template5 = {
startFieldId: 1,
endTableId: 0,
endFieldId: 0,
- startX: 127,
- startY: 463,
- endX: 144,
- endY: 161,
name: "transfers_from_fk",
cardinality: "Many to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 6,
},
],
diff --git a/src/templates/template6.js b/src/templates/template6.js
index 046cd6b..251fd47 100644
--- a/src/templates/template6.js
+++ b/src/templates/template6.js
@@ -399,15 +399,10 @@ export const template6 = {
startFieldId: 2,
endTableId: 0,
endFieldId: 0,
- startX: 96,
- startY: 518,
- endX: 215,
- endY: 79,
name: "enrollment_student_id_fk",
cardinality: "Many to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 0,
},
{
@@ -415,15 +410,10 @@ export const template6 = {
startFieldId: 1,
endTableId: 1,
endFieldId: 0,
- startX: 96,
- startY: 482,
- endX: 492,
- endY: 423,
name: "enrollment_course_id_fk",
cardinality: "Many to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 1,
},
{
@@ -431,15 +421,10 @@ export const template6 = {
startFieldId: 4,
endTableId: 4,
endFieldId: 0,
- startX: 786,
- startY: 263,
- endX: 800,
- endY: 407,
name: "instructors_dep_id_fk",
cardinality: "One to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 2,
},
{
@@ -447,15 +432,10 @@ export const template6 = {
startFieldId: 2,
endTableId: 4,
endFieldId: 0,
- startX: 492,
- startY: 495,
- endX: 800,
- endY: 407,
name: "courses_dep_id_fk",
cardinality: "One to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 3,
},
{
@@ -463,15 +443,10 @@ export const template6 = {
startFieldId: 7,
endTableId: 5,
endFieldId: 0,
- startX: 215,
- startY: 331,
- endX: 510,
- endY: 147,
name: "students_major_id_fk",
cardinality: "Many to one",
updateConstraint: "No action",
deleteConstraint: "No action",
- mandatory: false,
id: 4,
},
],
diff --git a/src/utils/calcPath.js b/src/utils/calcPath.js
index 88f5481..50616d3 100644
--- a/src/utils/calcPath.js
+++ b/src/utils/calcPath.js
@@ -1,110 +1,100 @@
-export function calcPath(x1, x2, y1, y2, zoom = 1) {
- const tableWidth = 200 * zoom;
- if (y1 <= y2) {
- if (x1 + tableWidth <= x2) {
- x2 -= 14;
- } else if (x2 <= x1 + tableWidth && x1 <= x2) {
- // x2-=14;
- // x1-=14;
- } else if (x2 + tableWidth >= x1 && x2 + tableWidth <= x1 + tableWidth) {
- x1 -= 14;
- x2 -= 14;
- } else {
- x2 -= 14;
- x1 -= 14;
- }
- } else {
- if (x1 + tableWidth <= x2) {
- x2 -= 14;
- } else if (x1 + tableWidth >= x2 && x1 + tableWidth <= x2 + tableWidth) {
- //
- x1 -= 14;
- x2 -= 14;
- } else if (x1 >= x2 && x1 <= x2 + tableWidth) {
- // x1-=19;
- // x2-=14;
- } else {
- x1 -= 14;
- x2 -= 14;
- }
- }
- x1 *= zoom;
- x2 *= zoom;
- y1 *= zoom;
- y2 *= zoom;
+import {
+ tableFieldHeight,
+ tableHeaderHeight,
+ tableWidth,
+} from "../data/constants";
- let r = 10 * zoom;
- const offsetX = 8 * zoom;
- const midX = (x2 + x1 + tableWidth) / 2;
- const endX = x2 + tableWidth < x1 ? x2 + tableWidth : x2;
+export function calcPath(r, zoom = 1) {
+ const width = tableWidth * zoom;
+ let x1 = r.startTable.x;
+ let y1 =
+ r.startTable.y +
+ r.startFieldId * tableFieldHeight +
+ tableHeaderHeight +
+ tableFieldHeight / 2;
+ let x2 = r.endTable.x;
+ let y2 =
+ r.endTable.y +
+ r.endFieldId * tableFieldHeight +
+ tableHeaderHeight +
+ tableFieldHeight / 2;
+
+ let radius = 10 * zoom;
+ const midX = (x2 + x1 + width) / 2;
+ const endX = x2 + width < x1 ? x2 + width : x2;
if (Math.abs(y1 - y2) <= 36 * zoom) {
- r = Math.abs(y2 - y1) / 3;
- if (r <= 2) {
- if (x1 + tableWidth <= x2)
- return `M ${x1 + tableWidth - 2 * offsetX} ${y1} L ${x2} ${y2 + 0.1}`;
- else if (x2 + tableWidth < x1)
- return `M ${x1} ${y1} L ${x2 + tableWidth} ${y2 + 0.1}`;
+ radius = Math.abs(y2 - y1) / 3;
+ if (radius <= 2) {
+ if (x1 + width <= x2) return `M ${x1 + width} ${y1} L ${x2} ${y2 + 0.1}`;
+ else if (x2 + width < x1)
+ return `M ${x1} ${y1} L ${x2 + width} ${y2 + 0.1}`;
}
}
if (y1 <= y2) {
- if (x1 + tableWidth <= x2) {
- return `M ${x1 + tableWidth - offsetX * 2} ${y1} L ${
- midX - r
- } ${y1} A ${r} ${r} 0 0 1 ${midX} ${y1 + r} L ${midX} ${
- y2 - r
- } A ${r} ${r} 0 0 0 ${midX + r} ${y2} L ${endX} ${y2}`;
- } else if (x2 <= x1 + tableWidth && x1 <= x2) {
- return `M ${x1 + tableWidth - 2 * offsetX} ${y1} L ${
- x2 + tableWidth
- } ${y1} A ${r} ${r} 0 0 1 ${x2 + tableWidth + r} ${y1 + r} L ${
- x2 + tableWidth + r
- } ${y2 - r} A ${r} ${r} 0 0 1 ${x2 + tableWidth} ${y2} L ${
- x2 + tableWidth - 2 * offsetX
- } ${y2}`;
- } else if (x2 + tableWidth >= x1 && x2 + tableWidth <= x1 + tableWidth) {
- return `M ${x1} ${y1} L ${x2 - r} ${y1} A ${r} ${r} 0 0 0 ${x2 - r - r} ${
- y1 + r
- } L ${x2 - r - r} ${y2 - r} A ${r} ${r} 0 0 0 ${
- x2 - r
+ if (x1 + width <= x2) {
+ return `M ${x1 + width} ${y1} L ${
+ midX - radius
+ } ${y1} A ${radius} ${radius} 0 0 1 ${midX} ${y1 + radius} L ${midX} ${
+ y2 - radius
+ } A ${radius} ${radius} 0 0 0 ${midX + radius} ${y2} L ${endX} ${y2}`;
+ } else if (x2 <= x1 + width && x1 <= x2) {
+ return `M ${x1 + width} ${y1} L ${
+ x2 + width
+ } ${y1} A ${radius} ${radius} 0 0 1 ${x2 + width + radius} ${
+ y1 + radius
+ } L ${x2 + width + radius} ${y2 - radius} A ${radius} ${radius} 0 0 1 ${
+ x2 + width
+ } ${y2} L ${x2 + width} ${y2}`;
+ } else if (x2 + width >= x1 && x2 + width <= x1 + width) {
+ return `M ${x1} ${y1} L ${
+ x2 - radius
+ } ${y1} A ${radius} ${radius} 0 0 0 ${x2 - radius - radius} ${
+ y1 + radius
+ } L ${x2 - radius - radius} ${y2 - radius} A ${radius} ${radius} 0 0 0 ${
+ x2 - radius
} ${y2} L ${x2} ${y2}`;
} else {
- return `M ${x1} ${y1} L ${midX + r} ${y1} A ${r} ${r} 0 0 0 ${midX} ${
- y1 + r
- } L ${midX} ${y2 - r} A ${r} ${r} 0 0 1 ${
- midX - r
- } ${y2} L ${endX} ${y2}`;
+ return `M ${x1} ${y1} L ${
+ midX + radius
+ } ${y1} A ${radius} ${radius} 0 0 0 ${midX} ${y1 + radius} L ${midX} ${
+ y2 - radius
+ } A ${radius} ${radius} 0 0 1 ${midX - radius} ${y2} L ${endX} ${y2}`;
}
} else {
- if (x1 + tableWidth <= x2) {
- return `M ${x1 + tableWidth - offsetX * 2} ${y1} L ${
- midX - r
- } ${y1} A ${r} ${r} 0 0 0 ${midX} ${y1 - r} L ${midX} ${
- y2 + r
- } A ${r} ${r} 0 0 1 ${midX + r} ${y2} L ${endX} ${y2}`;
- } else if (x1 + tableWidth >= x2 && x1 + tableWidth <= x2 + tableWidth) {
- return `M ${x1} ${y1} L ${x1 - r - r} ${y1} A ${r} ${r} 0 0 1 ${
- x1 - r - r - r
- } ${y1 - r} L ${x1 - r - r - r} ${y2 + r} A ${r} ${r} 0 0 1 ${
- x1 - r - r
+ if (x1 + width <= x2) {
+ return `M ${x1 + width} ${y1} L ${
+ midX - radius
+ } ${y1} A ${radius} ${radius} 0 0 0 ${midX} ${y1 - radius} L ${midX} ${
+ y2 + radius
+ } A ${radius} ${radius} 0 0 1 ${midX + radius} ${y2} L ${endX} ${y2}`;
+ } else if (x1 + width >= x2 && x1 + width <= x2 + width) {
+ return `M ${x1} ${y1} L ${
+ x1 - radius - radius
+ } ${y1} A ${radius} ${radius} 0 0 1 ${x1 - radius - radius - radius} ${
+ y1 - radius
+ } L ${x1 - radius - radius - radius} ${
+ y2 + radius
+ } A ${radius} ${radius} 0 0 1 ${
+ x1 - radius - radius
} ${y2} L ${endX} ${y2}`;
- } else if (x1 >= x2 && x1 <= x2 + tableWidth) {
- return `M ${x1 + tableWidth - 2 * offsetX} ${y1} L ${
- x1 + tableWidth - 2 * offsetX + r
- } ${y1} A ${r} ${r} 0 0 0 ${x1 + tableWidth - 2 * offsetX + r + r} ${
- y1 - r
- } L ${x1 + tableWidth - 2 * offsetX + r + r} ${
- y2 + r
- } A ${r} ${r} 0 0 0 ${x1 + tableWidth - 2 * offsetX + r} ${y2} L ${
- x2 + tableWidth - 2 * offsetX
+ } else if (x1 >= x2 && x1 <= x2 + width) {
+ return `M ${x1 + width} ${y1} L ${
+ x1 + width + radius
+ } ${y1} A ${radius} ${radius} 0 0 0 ${x1 + width + radius + radius} ${
+ y1 - radius
+ } L ${x1 + width + radius + radius} ${
+ y2 + radius
+ } A ${radius} ${radius} 0 0 0 ${x1 + width + radius} ${y2} L ${
+ x2 + width
} ${y2}`;
} else {
- return `M ${x1} ${y1} L ${midX + r} ${y1} A ${r} ${r} 0 0 1 ${midX} ${
- y1 - r
- } L ${midX} ${y2 + r} A ${r} ${r} 0 0 0 ${
- midX - r
- } ${y2} L ${endX} ${y2}`;
+ return `M ${x1} ${y1} L ${
+ midX + radius
+ } ${y1} A ${radius} ${radius} 0 0 1 ${midX} ${y1 - radius} L ${midX} ${
+ y2 + radius
+ } A ${radius} ${radius} 0 0 0 ${midX - radius} ${y2} L ${endX} ${y2}`;
}
}
}