@@ -2,18 +2,16 @@ import { canvas } from "../main.js";
2
2
3
3
// List 1:1 association in a vertical list
4
4
export function buildAssociationView ( viewObjects , associationName ) {
5
- const association = viewObjects . associations [ associationName ] ;
5
+ const associations = viewObjects . associations [ associationName ] ;
6
+ const length = associations . length ;
6
7
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 ) {
11
9
alert ( "No association found!" ) ;
12
10
return ;
13
11
}
14
12
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 ;
17
15
const fromHorizontalGap = 0.3 * fromWidth ;
18
16
const toHorizontalGap = 0.3 * toWidth ;
19
17
const gap = 2 * ( fromWidth + toWidth ) ;
@@ -22,14 +20,13 @@ export function buildAssociationView(viewObjects, associationName) {
22
20
const width = totalWidth > window . innerWidth ? totalWidth : window . innerWidth ;
23
21
canvas . width = width ;
24
22
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 ;
27
25
28
26
const height = Math . max ( fromHeight , toHeight ) ;
29
27
const verticalGap = 0.3 * height ;
30
28
31
- const totalHeight =
32
- fromCollection . length * ( height + verticalGap ) + verticalGap ;
29
+ const totalHeight = length * ( height + verticalGap ) + verticalGap ;
33
30
34
31
canvas . height = totalHeight ;
35
32
@@ -39,13 +36,15 @@ export function buildAssociationView(viewObjects, associationName) {
39
36
40
37
const toX = width / 2 + toHorizontalGap ;
41
38
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 ;
45
42
46
43
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 ;
49
48
accHeight += height + verticalGap ;
50
- }
49
+ } ) ;
51
50
}
0 commit comments