Skip to content

Commit 67255ec

Browse files
committed
todo: fix when changing original x,y from object
1 parent 6cb7a15 commit 67255ec

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

js/views/association-view.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ import { canvas } from "../main.js";
22

33
// List 1:1 association in a vertical list
44
export function buildAssociationView(viewObjects, associationName) {
5-
const association = viewObjects.associations[associationName];
5+
const associations = viewObjects.associations[associationName];
6+
const length = associations.length;
67

7-
const fromCollection = association.map((association) => association.from);
8-
const toCollection = association.map((association) => association.to);
9-
10-
if (fromCollection.length === 0 || toCollection.length === 0) {
8+
if (length === 0) {
119
alert("No association found!");
1210
return;
1311
}
1412

15-
const fromWidth = fromCollection[0].width;
16-
const toWidth = toCollection[0].width;
13+
const fromWidth = associations[0].from.width;
14+
const toWidth = associations[0].to.width;
1715
const fromHorizontalGap = 0.3 * fromWidth;
1816
const toHorizontalGap = 0.3 * toWidth;
1917
const gap = 2 * (fromWidth + toWidth);
@@ -22,14 +20,13 @@ export function buildAssociationView(viewObjects, associationName) {
2220
const width = totalWidth > window.innerWidth ? totalWidth : window.innerWidth;
2321
canvas.width = width;
2422

25-
const fromHeight = fromCollection[0].height;
26-
const toHeight = toCollection[0].height;
23+
const fromHeight = associations[0].from.height;
24+
const toHeight = associations[0].to.height;
2725

2826
const height = Math.max(fromHeight, toHeight);
2927
const verticalGap = 0.3 * height;
3028

31-
const totalHeight =
32-
fromCollection.length * (height + verticalGap) + verticalGap;
29+
const totalHeight = length * (height + verticalGap) + verticalGap;
3330

3431
canvas.height = totalHeight;
3532

@@ -39,13 +36,15 @@ export function buildAssociationView(viewObjects, associationName) {
3936

4037
const toX = width / 2 + toHorizontalGap;
4138

42-
for (let i = 0; i < fromCollection.length; i++) {
43-
fromCollection[i].x = fromX;
44-
toCollection[i].x = toX;
39+
associations.forEach((association) => {
40+
association.from.x = fromX;
41+
association.to.x = toX;
4542

4643
const space = height + verticalGap;
47-
fromCollection[i].y = accHeight + space / 2 - fromHeight / 2;
48-
toCollection[i].y = accHeight + space / 2 - toHeight / 2;
44+
const fromY = accHeight + space / 2 - fromHeight / 2;
45+
const toY = accHeight + space / 2 - toHeight / 2;
46+
association.from.y = fromY;
47+
association.to.y = toY;
4948
accHeight += height + verticalGap;
50-
}
49+
});
5150
}

0 commit comments

Comments
 (0)