@finos/legend-extension-dsl-diagram 1.0.28 → 1.0.29

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. package/lib/DiagramRenderer.d.ts +1 -1
  2. package/lib/DiagramRenderer.d.ts.map +1 -1
  3. package/lib/DiagramRenderer.js +52 -51
  4. package/lib/DiagramRenderer.js.map +1 -1
  5. package/lib/components/studio/DiagramEditor.d.ts.map +1 -1
  6. package/lib/components/studio/DiagramEditor.js +4 -3
  7. package/lib/components/studio/DiagramEditor.js.map +1 -1
  8. package/lib/helpers/DiagramHelper.d.ts.map +1 -1
  9. package/lib/helpers/DiagramHelper.js +4 -3
  10. package/lib/helpers/DiagramHelper.js.map +1 -1
  11. package/lib/index.css +1 -1
  12. package/lib/index.d.ts +2 -1
  13. package/lib/index.d.ts.map +1 -1
  14. package/lib/index.js +2 -1
  15. package/lib/index.js.map +1 -1
  16. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassView.d.ts +0 -3
  17. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassView.d.ts.map +1 -1
  18. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassView.js +1 -13
  19. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassView.js.map +1 -1
  20. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassViewReference.d.ts +0 -1
  21. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassViewReference.d.ts.map +1 -1
  22. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassViewReference.js +1 -6
  23. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassViewReference.js.map +1 -1
  24. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_Diagram.d.ts +0 -11
  25. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_Diagram.d.ts.map +1 -1
  26. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_Diagram.js +2 -46
  27. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_Diagram.js.map +1 -1
  28. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_GraphModifierHelper.d.ts +35 -0
  29. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_GraphModifierHelper.d.ts.map +1 -0
  30. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_GraphModifierHelper.js +118 -0
  31. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_GraphModifierHelper.js.map +1 -0
  32. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipEdgeView.d.ts +0 -2
  33. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipEdgeView.d.ts.map +1 -1
  34. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipEdgeView.js +1 -9
  35. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipEdgeView.js.map +1 -1
  36. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipView.d.ts +0 -17
  37. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipView.d.ts.map +1 -1
  38. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipView.js +6 -109
  39. package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipView.js.map +1 -1
  40. package/lib/models/metamodels/pure/packageableElements/diagram/geometry/DSLDiagram_PositionedRectangle.d.ts +0 -8
  41. package/lib/models/metamodels/pure/packageableElements/diagram/geometry/DSLDiagram_PositionedRectangle.d.ts.map +1 -1
  42. package/lib/models/metamodels/pure/packageableElements/diagram/geometry/DSLDiagram_PositionedRectangle.js +1 -16
  43. package/lib/models/metamodels/pure/packageableElements/diagram/geometry/DSLDiagram_PositionedRectangle.js.map +1 -1
  44. package/lib/models/protocols/pure/v1/transformation/pureGraph/V1_DSLDiagram_GraphBuilderHelper.d.ts.map +1 -1
  45. package/lib/models/protocols/pure/v1/transformation/pureGraph/V1_DSLDiagram_GraphBuilderHelper.js +3 -2
  46. package/lib/models/protocols/pure/v1/transformation/pureGraph/V1_DSLDiagram_GraphBuilderHelper.js.map +1 -1
  47. package/lib/package.json +4 -4
  48. package/lib/stores/studio/DSLDiagram_ModifierHelper.d.ts +54 -0
  49. package/lib/stores/studio/DSLDiagram_ModifierHelper.d.ts.map +1 -0
  50. package/lib/stores/studio/DSLDiagram_ModifierHelper.js +87 -0
  51. package/lib/stores/studio/DSLDiagram_ModifierHelper.js.map +1 -0
  52. package/package.json +10 -10
  53. package/src/DiagramRenderer.ts +122 -54
  54. package/src/components/studio/DiagramEditor.tsx +8 -3
  55. package/src/helpers/DiagramHelper.ts +4 -3
  56. package/src/index.ts +2 -4
  57. package/src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassView.ts +1 -14
  58. package/src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassViewReference.ts +1 -7
  59. package/src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_Diagram.ts +2 -52
  60. package/src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_GraphModifierHelper.ts +165 -0
  61. package/src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipEdgeView.ts +1 -10
  62. package/src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipView.ts +6 -147
  63. package/src/models/metamodels/pure/packageableElements/diagram/geometry/DSLDiagram_PositionedRectangle.ts +1 -17
  64. package/src/models/protocols/pure/v1/transformation/pureGraph/V1_DSLDiagram_GraphBuilderHelper.ts +3 -2
  65. package/src/stores/studio/DSLDiagram_ModifierHelper.ts +148 -0
  66. package/tsconfig.json +2 -0
@@ -14,13 +14,8 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import { observable, action, makeObservable, override } from 'mobx';
18
- import {
19
- hashArray,
20
- addUniqueEntry,
21
- deleteEntry,
22
- type Hashable,
23
- } from '@finos/legend-shared';
17
+ import { observable, makeObservable, override } from 'mobx';
18
+ import { hashArray, type Hashable } from '@finos/legend-shared';
24
19
  import type { ClassView } from './DSLDiagram_ClassView';
25
20
  import type { PropertyView } from './DSLDiagram_PropertyView';
26
21
  import type { GeneralizationView } from './DSLDiagram_GeneralizationView';
@@ -45,55 +40,10 @@ export class Diagram extends PackageableElement implements Hashable {
45
40
  associationViews: observable,
46
41
  generalizationViews: observable,
47
42
  propertyViews: observable,
48
- setClassViews: action,
49
- addClassView: action,
50
- deleteClassView: action,
51
- setAssociationViews: action,
52
- deleteAssociationView: action,
53
- setGeneralizationViews: action,
54
- addGeneralizationView: action,
55
- deleteGeneralizationView: action,
56
- setPropertyViews: action,
57
- addPropertyView: action,
58
- deletePropertyView: action,
59
43
  _elementHashCode: override,
60
44
  });
61
45
  }
62
46
 
63
- setClassViews(val: ClassView[]): void {
64
- this.classViews = val;
65
- }
66
- addClassView(val: ClassView): void {
67
- addUniqueEntry(this.classViews, val);
68
- }
69
- deleteClassView(val: ClassView): void {
70
- deleteEntry(this.classViews, val);
71
- }
72
- setAssociationViews(val: AssociationView[]): void {
73
- this.associationViews = val;
74
- }
75
- deleteAssociationView(val: AssociationView): void {
76
- deleteEntry(this.associationViews, val);
77
- }
78
- setGeneralizationViews(val: GeneralizationView[]): void {
79
- this.generalizationViews = val;
80
- }
81
- addGeneralizationView(val: GeneralizationView): void {
82
- addUniqueEntry(this.generalizationViews, val);
83
- }
84
- deleteGeneralizationView(val: GeneralizationView): void {
85
- deleteEntry(this.generalizationViews, val);
86
- }
87
- setPropertyViews(val: PropertyView[]): void {
88
- this.propertyViews = val;
89
- }
90
- addPropertyView(val: PropertyView): void {
91
- addUniqueEntry(this.propertyViews, val);
92
- }
93
- deletePropertyView(val: PropertyView): void {
94
- deleteEntry(this.propertyViews, val);
95
- }
96
-
97
47
  protected override get _elementHashCode(): string {
98
48
  return hashArray([
99
49
  DIAGRAM_HASH_STRUCTURE.DIAGRAM,
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Copyright (c) 2020-present, Goldman Sachs
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import type { ClassView } from './DSLDiagram_ClassView';
18
+ import type { RelationshipView } from './DSLDiagram_RelationshipView';
19
+ import { Point } from './geometry/DSLDiagram_Point';
20
+ import { Vector } from './geometry/DSLDiagram_Vector';
21
+
22
+ export const _relationView_setPath = (
23
+ relationView: RelationshipView,
24
+ val: Point[],
25
+ ): void => {
26
+ relationView.path = val;
27
+ };
28
+
29
+ /**
30
+ * For a path, only counts the points which lie outside of the 2 class views
31
+ */
32
+ export const _relationView_manageInsidePointsDynamically = (
33
+ path: Point[],
34
+ from: ClassView,
35
+ to: ClassView,
36
+ ): Point[] => {
37
+ if (!path.length) {
38
+ return [];
39
+ }
40
+
41
+ let start = 0;
42
+ let startPoint = path[start] as Point;
43
+
44
+ while (start < path.length - 1 && from.contains(startPoint.x, startPoint.y)) {
45
+ start++;
46
+ startPoint = path[start] as Point;
47
+ }
48
+
49
+ let end = path.length - 1;
50
+ let endPoint = path[end] as Point;
51
+
52
+ while (end > 0 && to.contains(endPoint.x, endPoint.y)) {
53
+ end--;
54
+ endPoint = path[end] as Point;
55
+ }
56
+
57
+ return path.slice(start - 1, end + 2);
58
+ };
59
+
60
+ /**
61
+ * Flatten the path if the angle is wide enough
62
+ * Also `swallow` points in path which lie inside of the rectangle of a view
63
+ */
64
+ export const _relationView_possiblyFlattenPath = (
65
+ relationView: RelationshipView,
66
+ ): void => {
67
+ const fullPath = relationView.buildFullPath();
68
+ // NOTE: this method here will `swallow` up points inside of the boxes
69
+ const newPath = _relationView_manageInsidePointsDynamically(
70
+ fullPath,
71
+ relationView.from.classView.value,
72
+ relationView.to.classView.value,
73
+ );
74
+
75
+ // recompute the offset point from center inside of `from` and `to` classviews.
76
+ // for each, we first check if `manageInsidePointsDynamically` removes any points from the full path
77
+ // if it does we will update the offset
78
+ if (newPath[0] !== fullPath[0]) {
79
+ const center = relationView.from.classView.value.center();
80
+
81
+ relationView.from.offsetX = (newPath[0] as Point).x - center.x;
82
+ relationView.from.offsetY = (newPath[0] as Point).y - center.y;
83
+ }
84
+
85
+ if (newPath[newPath.length - 1] !== fullPath[fullPath.length - 1]) {
86
+ const center = relationView.to.classView.value.center();
87
+ relationView.to.offsetX =
88
+ (newPath[newPath.length - 1] as Point).x - center.x;
89
+ relationView.to.offsetY =
90
+ (newPath[newPath.length - 1] as Point).y - center.y;
91
+ }
92
+
93
+ // find the point which can be flattened due to its wide angle
94
+ const result = [];
95
+ for (let i = 0; i < newPath.length - 2; i++) {
96
+ const v1 = Vector.fromPoints(
97
+ newPath[i + 1] as Point,
98
+ newPath[i] as Point,
99
+ ).norm();
100
+ const v2 = Vector.fromPoints(
101
+ newPath[i + 1] as Point,
102
+ newPath[i + 2] as Point,
103
+ ).norm();
104
+ const dot = v1.dotProduct(v2);
105
+ const angle = (Math.acos(dot) * 180) / Math.PI;
106
+ if (Math.abs(angle - 180) > 5) {
107
+ result.push(newPath[i + 1] as Point);
108
+ }
109
+ }
110
+ // here's where we will modify the path, i.e. swallow inside points if we have to
111
+ _relationView_setPath(relationView, result);
112
+ };
113
+
114
+ /**
115
+ * Based on the location, find the point on the path that matches or create new point
116
+ * (within a threshold of proximity) from the coordinate and put this in the path array
117
+ * so it doesn't look too weird
118
+ */
119
+ export const _findOrBuildPoint = (
120
+ relationView: RelationshipView,
121
+ x: number,
122
+ y: number,
123
+ zoom: number,
124
+ allowChange = true,
125
+ ): Point | undefined => {
126
+ for (const pt of relationView.path) {
127
+ if (
128
+ Math.sqrt((x - pt.x) * (x - pt.x) + (y - pt.y) * (y - pt.y)) <
129
+ 10 / zoom
130
+ ) {
131
+ return pt;
132
+ }
133
+ }
134
+
135
+ const fullPath = relationView.buildFullPath(allowChange);
136
+ const newPath = [];
137
+ let point;
138
+
139
+ for (let i = 0; i < fullPath.length - 1; i++) {
140
+ const a = fullPath[i] as Point;
141
+ const b = fullPath[i + 1] as Point;
142
+ const n = new Vector(a.x, a.y).normal(new Vector(b.x, b.y)).norm();
143
+ const v = Vector.fromPoints(a, new Point(x, y));
144
+
145
+ if (Math.abs(n.dotProduct(v)) < 5 / zoom) {
146
+ const lx = (a.x < b.x ? a.x : b.x) - 5 / zoom;
147
+ const hx = (a.x < b.x ? b.x : a.x) + 5 / zoom;
148
+ const ly = (a.y < b.y ? a.y : b.y) - 5 / zoom;
149
+ const hy = (a.y < b.y ? b.y : a.y) + 5 / zoom;
150
+
151
+ if (lx <= x && x <= hx && ly <= y && y <= hy) {
152
+ point = new Point(x, y);
153
+ newPath.push(point);
154
+ }
155
+ }
156
+
157
+ if (i < fullPath.length - 2) {
158
+ newPath.push(fullPath[i + 1] as Point);
159
+ }
160
+ }
161
+ if (point && allowChange) {
162
+ _relationView_setPath(relationView, newPath);
163
+ }
164
+ return point;
165
+ };
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import { observable, action, makeObservable } from 'mobx';
17
+ import { observable, makeObservable } from 'mobx';
18
18
  import type { ClassViewReference } from './DSLDiagram_ClassViewReference';
19
19
 
20
20
  export class RelationShipEdgeView {
@@ -26,17 +26,8 @@ export class RelationShipEdgeView {
26
26
  makeObservable(this, {
27
27
  offsetX: observable,
28
28
  offsetY: observable,
29
- setOffsetX: action,
30
- setOffsetY: action,
31
29
  });
32
30
 
33
31
  this.classView = classView;
34
32
  }
35
-
36
- setOffsetX(val: number): void {
37
- this.offsetX = val;
38
- }
39
- setOffsetY(val: number): void {
40
- this.offsetY = val;
41
- }
42
33
  }
@@ -14,46 +14,15 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import { observable, action, computed, makeObservable } from 'mobx';
18
- import { hashArray, changeEntry, type Hashable } from '@finos/legend-shared';
17
+ import { observable, computed, makeObservable } from 'mobx';
18
+ import { hashArray, type Hashable } from '@finos/legend-shared';
19
19
  import { RelationShipEdgeView as RelationshipEdgeView } from './DSLDiagram_RelationshipEdgeView';
20
20
  import { Point } from './geometry/DSLDiagram_Point';
21
21
  import type { ClassView } from './DSLDiagram_ClassView';
22
- import { Vector } from './geometry/DSLDiagram_Vector';
23
22
  import type { Diagram } from './DSLDiagram_Diagram';
24
23
  import { ClassViewExplicitReference } from './DSLDiagram_ClassViewReference';
25
24
  import { DIAGRAM_HASH_STRUCTURE } from '../../../../DSLDiagram_ModelUtils';
26
-
27
- /**
28
- * For a path, only counts the points which lie outside of the 2 class views
29
- */
30
- export const manageInsidePointsDynamically = (
31
- path: Point[],
32
- from: ClassView,
33
- to: ClassView,
34
- ): Point[] => {
35
- if (!path.length) {
36
- return [];
37
- }
38
-
39
- let start = 0;
40
- let startPoint = path[start] as Point;
41
-
42
- while (start < path.length - 1 && from.contains(startPoint.x, startPoint.y)) {
43
- start++;
44
- startPoint = path[start] as Point;
45
- }
46
-
47
- let end = path.length - 1;
48
- let endPoint = path[end] as Point;
49
-
50
- while (end > 0 && to.contains(endPoint.x, endPoint.y)) {
51
- end--;
52
- endPoint = path[end] as Point;
53
- }
54
-
55
- return path.slice(start - 1, end + 2);
56
- };
25
+ import { _relationView_manageInsidePointsDynamically } from './DSLDiagram_GraphModifierHelper';
57
26
 
58
27
  export class RelationshipView implements Hashable {
59
28
  owner: Diagram;
@@ -66,8 +35,6 @@ export class RelationshipView implements Hashable {
66
35
  constructor(owner: Diagram, from: ClassView, to: ClassView) {
67
36
  makeObservable(this, {
68
37
  path: observable,
69
- setPath: action,
70
- changePoint: action,
71
38
  fullPath: computed,
72
39
  });
73
40
 
@@ -78,13 +45,6 @@ export class RelationshipView implements Hashable {
78
45
  this.to = new RelationshipEdgeView(ClassViewExplicitReference.create(to));
79
46
  }
80
47
 
81
- setPath(val: Point[]): void {
82
- this.path = val;
83
- }
84
- changePoint(val: Point, newVal: Point): void {
85
- changeEntry(this.path, val, newVal);
86
- }
87
-
88
48
  /**
89
49
  * Compute the full path for an edge, but notice here that the end points are recomputed every time, as such
90
50
  * `path` only stores point that matters to the edge but are not end points
@@ -101,114 +61,13 @@ export class RelationshipView implements Hashable {
101
61
  * This method will compute the full path from the offset within class view for persistence purpose
102
62
  */
103
63
  get fullPath(): Point[] {
104
- return manageInsidePointsDynamically(
64
+ return _relationView_manageInsidePointsDynamically(
105
65
  this.buildFullPath(),
106
66
  this.from.classView.value,
107
67
  this.to.classView.value,
108
68
  );
109
69
  }
110
70
 
111
- /**
112
- * Flatten the path if the angle is wide enough
113
- * Also `swallow` points in path which lie inside of the rectangle of a view
114
- */
115
- possiblyFlattenPath(): void {
116
- const fullPath = this.buildFullPath();
117
- // NOTE: this method here will `swallow` up points inside of the boxes
118
- const newPath = manageInsidePointsDynamically(
119
- fullPath,
120
- this.from.classView.value,
121
- this.to.classView.value,
122
- );
123
-
124
- // recompute the offset point from center inside of `from` and `to` classviews.
125
- // for each, we first check if `manageInsidePointsDynamically` removes any points from the full path
126
- // if it does we will update the offset
127
- if (newPath[0] !== fullPath[0]) {
128
- const center = this.from.classView.value.center();
129
- this.from.setOffsetX((newPath[0] as Point).x - center.x);
130
- this.from.setOffsetY((newPath[0] as Point).y - center.y);
131
- }
132
-
133
- if (newPath[newPath.length - 1] !== fullPath[fullPath.length - 1]) {
134
- const center = this.to.classView.value.center();
135
- this.to.setOffsetX((newPath[newPath.length - 1] as Point).x - center.x);
136
- this.to.setOffsetY((newPath[newPath.length - 1] as Point).y - center.y);
137
- }
138
-
139
- // find the point which can be flattened due to its wide angle
140
- const result = [];
141
- for (let i = 0; i < newPath.length - 2; i++) {
142
- const v1 = Vector.fromPoints(
143
- newPath[i + 1] as Point,
144
- newPath[i] as Point,
145
- ).norm();
146
- const v2 = Vector.fromPoints(
147
- newPath[i + 1] as Point,
148
- newPath[i + 2] as Point,
149
- ).norm();
150
- const dot = v1.dotProduct(v2);
151
- const angle = (Math.acos(dot) * 180) / Math.PI;
152
- if (Math.abs(angle - 180) > 5) {
153
- result.push(newPath[i + 1] as Point);
154
- }
155
- }
156
- // here's where we will modify the path, i.e. swallow inside points if we have to
157
- this.setPath(result);
158
- }
159
-
160
- /**
161
- * Based on the location, find the point on the path that matches or create new point
162
- * (within a threshold of proximity) from the coordinate and put this in the path array
163
- * so it doesn't look too weird
164
- */
165
- findOrBuildPoint(
166
- x: number,
167
- y: number,
168
- zoom: number,
169
- allowChange = true,
170
- ): Point | undefined {
171
- for (const pt of this.path) {
172
- if (
173
- Math.sqrt((x - pt.x) * (x - pt.x) + (y - pt.y) * (y - pt.y)) <
174
- 10 / zoom
175
- ) {
176
- return pt;
177
- }
178
- }
179
-
180
- const fullPath = this.buildFullPath(allowChange);
181
- const newPath = [];
182
- let point;
183
-
184
- for (let i = 0; i < fullPath.length - 1; i++) {
185
- const a = fullPath[i] as Point;
186
- const b = fullPath[i + 1] as Point;
187
- const n = new Vector(a.x, a.y).normal(new Vector(b.x, b.y)).norm();
188
- const v = Vector.fromPoints(a, new Point(x, y));
189
-
190
- if (Math.abs(n.dotProduct(v)) < 5 / zoom) {
191
- const lx = (a.x < b.x ? a.x : b.x) - 5 / zoom;
192
- const hx = (a.x < b.x ? b.x : a.x) + 5 / zoom;
193
- const ly = (a.y < b.y ? a.y : b.y) - 5 / zoom;
194
- const hy = (a.y < b.y ? b.y : a.y) + 5 / zoom;
195
-
196
- if (lx <= x && x <= hx && ly <= y && y <= hy) {
197
- point = new Point(x, y);
198
- newPath.push(point);
199
- }
200
- }
201
-
202
- if (i < fullPath.length - 2) {
203
- newPath.push(fullPath[i + 1] as Point);
204
- }
205
- }
206
- if (point && allowChange) {
207
- this.setPath(newPath);
208
- }
209
- return point;
210
- }
211
-
212
71
  /**
213
72
  * Calculate the end points of the edge using offset, otherwise, use the center
214
73
  */
@@ -224,8 +83,8 @@ export class RelationshipView implements Hashable {
224
83
  return new Point(newX, newY);
225
84
  }
226
85
  if (allowChange) {
227
- edgeView.setOffsetX(0);
228
- edgeView.setOffsetY(0);
86
+ edgeView.offsetX = 0;
87
+ edgeView.offsetY = 0;
229
88
  }
230
89
  return new Point(center.x, center.y);
231
90
  }
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import { observable, action, makeObservable } from 'mobx';
17
+ import { observable, makeObservable } from 'mobx';
18
18
  import { hashArray, type Hashable } from '@finos/legend-shared';
19
19
  import { Point } from './DSLDiagram_Point';
20
20
  import { Rectangle } from './DSLDiagram_Rectangle';
@@ -28,28 +28,12 @@ export class PositionedRectangle implements Hashable {
28
28
  constructor(position: Point, rectangle: Rectangle) {
29
29
  makeObservable(this, {
30
30
  dummyObservable: observable,
31
- forceRefreshHash: action,
32
31
  });
33
32
 
34
33
  this.position = position;
35
34
  this.rectangle = rectangle;
36
35
  }
37
36
 
38
- setRectangle(value: Rectangle): void {
39
- this.rectangle = value;
40
- }
41
- setPosition(value: Point): void {
42
- this.position = value;
43
- }
44
- /**
45
- * NOTE: Having `position` and `rectangle` as observables compromises the performance of diagram
46
- * so we want to have a way to refresh the hash for change detection to pick up new hash when we resize
47
- * the class view box or move it.
48
- */
49
- forceRefreshHash(): void {
50
- this.dummyObservable = {};
51
- }
52
-
53
37
  edgePoint = (): Point =>
54
38
  new Point(
55
39
  this.position.x + this.rectangle.width,
@@ -36,6 +36,7 @@ import type { V1_Rectangle } from '../../model/packageableElements/diagram/geome
36
36
  import type { V1_PropertyView } from '../../model/packageableElements/diagram/V1_DSLDiagram_PropertyView';
37
37
  import type { V1_GeneralizationView } from '../../model/packageableElements/diagram/V1_DSLDiagram_GeneralizationView';
38
38
  import { getClassView } from '../../../../../../helpers/DiagramHelper';
39
+ import { _relationView_possiblyFlattenPath } from '../../../../../metamodels/pure/packageableElements/diagram/DSLDiagram_GraphModifierHelper';
39
40
 
40
41
  const buildPoint = (point: V1_Point): Point => {
41
42
  const x = guaranteeNonNullable(point.x, `Point 'x' coordinate is missing`);
@@ -115,7 +116,7 @@ export const V1_buildPropertyView = (
115
116
  targetClassView,
116
117
  );
117
118
  view.path = propertyView.line.points.map((point) => buildPoint(point));
118
- view.possiblyFlattenPath(); // transform the line because we store only 2 end points that are inside points and we will calculate the offset
119
+ _relationView_possiblyFlattenPath(view); // transform the line because we store only 2 end points that are inside points and we will calculate the offset
119
120
  return view;
120
121
  };
121
122
 
@@ -141,7 +142,7 @@ export const V1_buildGeneralizationView = (
141
142
  targetClassView,
142
143
  );
143
144
  view.path = generalizationView.line.points.map((point) => buildPoint(point));
144
- view.possiblyFlattenPath(); // transform the line because we store only 2 end points that are inside points and we will calculate the offset
145
+ _relationView_possiblyFlattenPath(view); // transform the line because we store only 2 end points that are inside points and we will calculate the offset
145
146
  return view;
146
147
  };
147
148
 
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Copyright (c) 2020-present, Goldman Sachs
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { addUniqueEntry, changeEntry, deleteEntry } from '@finos/legend-shared';
18
+ import { action } from 'mobx';
19
+ import type { AssociationView } from '../../models/metamodels/pure/packageableElements/diagram/DSLDiagram_AssociationView';
20
+ import type { ClassView } from '../../models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassView';
21
+ import type { Diagram } from '../../models/metamodels/pure/packageableElements/diagram/DSLDiagram_Diagram';
22
+ import type { GeneralizationView } from '../../models/metamodels/pure/packageableElements/diagram/DSLDiagram_GeneralizationView';
23
+ import {
24
+ _findOrBuildPoint,
25
+ _relationView_possiblyFlattenPath,
26
+ _relationView_setPath,
27
+ } from '../../models/metamodels/pure/packageableElements/diagram/DSLDiagram_GraphModifierHelper';
28
+ import type { PropertyView } from '../../models/metamodels/pure/packageableElements/diagram/DSLDiagram_PropertyView';
29
+ import type { RelationShipEdgeView } from '../../models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipEdgeView';
30
+ import type { RelationshipView } from '../../models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipView';
31
+ import type { Point } from '../../models/metamodels/pure/packageableElements/diagram/geometry/DSLDiagram_Point';
32
+ import type { PositionedRectangle } from '../../models/metamodels/pure/packageableElements/diagram/geometry/DSLDiagram_PositionedRectangle';
33
+ import type { Rectangle } from '../../models/metamodels/pure/packageableElements/diagram/geometry/DSLDiagram_Rectangle';
34
+
35
+ export const diagram_setClassViews = action(
36
+ (diagram: Diagram, val: ClassView[]): void => {
37
+ diagram.classViews = val;
38
+ },
39
+ );
40
+ export const diagram_addClassView = action(
41
+ (diagram: Diagram, val: ClassView): void => {
42
+ addUniqueEntry(diagram.classViews, val);
43
+ },
44
+ );
45
+ export const diagram_deleteClassView = action(
46
+ (diagram: Diagram, val: ClassView): void => {
47
+ deleteEntry(diagram.classViews, val);
48
+ },
49
+ );
50
+ export const diagram_setAssociationViews = action(
51
+ (diagram: Diagram, val: AssociationView[]): void => {
52
+ diagram.associationViews = val;
53
+ },
54
+ );
55
+ export const diagram_deleteAssociationView = action(
56
+ (diagram: Diagram, val: AssociationView): void => {
57
+ deleteEntry(diagram.associationViews, val);
58
+ },
59
+ );
60
+ export const diagram_setGeneralizationViews = action(
61
+ (diagram: Diagram, val: GeneralizationView[]): void => {
62
+ diagram.generalizationViews = val;
63
+ },
64
+ );
65
+ export const diagram_addGeneralizationView = action(
66
+ (diagram: Diagram, val: GeneralizationView): void => {
67
+ addUniqueEntry(diagram.generalizationViews, val);
68
+ },
69
+ );
70
+ export const diagram_deleteGeneralizationView = action(
71
+ (diagram: Diagram, val: GeneralizationView): void => {
72
+ deleteEntry(diagram.generalizationViews, val);
73
+ },
74
+ );
75
+ export const diagram_setPropertyViews = action(
76
+ (diagram: Diagram, val: PropertyView[]): void => {
77
+ diagram.propertyViews = val;
78
+ },
79
+ );
80
+ export const diagram_addPropertyView = action(
81
+ (diagram: Diagram, val: PropertyView): void => {
82
+ addUniqueEntry(diagram.propertyViews, val);
83
+ },
84
+ );
85
+ export const diagram_deletePropertyView = action(
86
+ (diagram: Diagram, val: PropertyView): void => {
87
+ deleteEntry(diagram.propertyViews, val);
88
+ },
89
+ );
90
+
91
+ export const classView_setHideProperties = action(
92
+ (cv: ClassView, val: boolean): void => {
93
+ cv.hideProperties = val;
94
+ },
95
+ );
96
+ export const classView_setHideStereotypes = action(
97
+ (cv: ClassView, val: boolean): void => {
98
+ cv.hideStereotypes = val;
99
+ },
100
+ );
101
+ export const classView_setHideTaggedValues = action(
102
+ (cv: ClassView, val: boolean): void => {
103
+ cv.hideTaggedValues = val;
104
+ },
105
+ );
106
+ export const relationShipEdgeView_setOffsetX = action(
107
+ (r: RelationShipEdgeView, val: number): void => {
108
+ r.offsetX = val;
109
+ },
110
+ );
111
+ export const relationShipEdgeView_setOffsetY = action(
112
+ (r: RelationShipEdgeView, val: number): void => {
113
+ r.offsetY = val;
114
+ },
115
+ );
116
+
117
+ export const relationshipView_changePoint = action(
118
+ (v: RelationshipView, val: Point, newVal: Point): void => {
119
+ changeEntry(v.path, val, newVal);
120
+ },
121
+ );
122
+ export const relationView_possiblyFlattenPath = action(
123
+ _relationView_possiblyFlattenPath,
124
+ );
125
+
126
+ export const findOrBuildPoint = action(_findOrBuildPoint);
127
+ export const relationView_setPath = action(_relationView_setPath);
128
+
129
+ export const positionedRectangle_setRectangle = action(
130
+ (pR: PositionedRectangle, value: Rectangle): void => {
131
+ pR.rectangle = value;
132
+ },
133
+ );
134
+ export const positionedRectangle_setPosition = action(
135
+ (pR: PositionedRectangle, value: Point): void => {
136
+ pR.position = value;
137
+ },
138
+ );
139
+ /**
140
+ * NOTE: Having `position` and `rectangle` as observables compromises the performance of diagram
141
+ * so we want to have a way to refresh the hash for change detection to pick up new hash when we resize
142
+ * the class view box or move it.
143
+ */
144
+ export const positionedRectangle_forceRefreshHash = action(
145
+ (pR: PositionedRectangle): void => {
146
+ pR.dummyObservable = {};
147
+ },
148
+ );
package/tsconfig.json CHANGED
@@ -51,6 +51,7 @@
51
51
  "./src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassViewReference.ts",
52
52
  "./src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_Diagram.ts",
53
53
  "./src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_GeneralizationView.ts",
54
+ "./src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_GraphModifierHelper.ts",
54
55
  "./src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_PropertyHolderView.ts",
55
56
  "./src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_PropertyView.ts",
56
57
  "./src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipEdgeView.ts",
@@ -73,6 +74,7 @@
73
74
  "./src/models/protocols/pure/v1/transformation/pureGraph/V1_DSLDiagram_GraphBuilderHelper.ts",
74
75
  "./src/models/protocols/pure/v1/transformation/pureGraph/V1_DSLDiagram_TransformerHelper.ts",
75
76
  "./src/models/protocols/pure/v1/transformation/pureProtocol/V1_DSLDiagram_ProtocolHelper.ts",
77
+ "./src/stores/studio/DSLDiagram_ModifierHelper.ts",
76
78
  "./src/stores/studio/DiagramEditorState.ts",
77
79
  "./src/components/studio/ClassDiagramPreview.tsx",
78
80
  "./src/components/studio/DSLDiagram_LegendStudioPlugin.tsx",