@finos/legend-extension-dsl-diagram 1.0.27 → 1.0.30
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/DiagramRenderer.d.ts +4 -1
- package/lib/DiagramRenderer.d.ts.map +1 -1
- package/lib/DiagramRenderer.js +63 -63
- package/lib/DiagramRenderer.js.map +1 -1
- package/lib/components/studio/ClassDiagramPreview.d.ts.map +1 -1
- package/lib/components/studio/ClassDiagramPreview.js +3 -1
- package/lib/components/studio/ClassDiagramPreview.js.map +1 -1
- package/lib/components/studio/DiagramEditor.d.ts.map +1 -1
- package/lib/components/studio/DiagramEditor.js +10 -9
- package/lib/components/studio/DiagramEditor.js.map +1 -1
- package/lib/graphManager/DSLDiagram_PureGraphManagerPlugin.d.ts +2 -1
- package/lib/graphManager/DSLDiagram_PureGraphManagerPlugin.d.ts.map +1 -1
- package/lib/graphManager/DSLDiagram_PureGraphManagerPlugin.js +11 -0
- package/lib/graphManager/DSLDiagram_PureGraphManagerPlugin.js.map +1 -1
- package/lib/graphManager/action/changeDetection/DSLDiagram_ObserverHelper.d.ts +34 -0
- package/lib/graphManager/action/changeDetection/DSLDiagram_ObserverHelper.d.ts.map +1 -0
- package/lib/graphManager/action/changeDetection/DSLDiagram_ObserverHelper.js +94 -0
- package/lib/graphManager/action/changeDetection/DSLDiagram_ObserverHelper.js.map +1 -0
- package/lib/helpers/DiagramHelper.d.ts +16 -1
- package/lib/helpers/DiagramHelper.d.ts.map +1 -1
- package/lib/helpers/DiagramHelper.js +90 -3
- package/lib/helpers/DiagramHelper.js.map +1 -1
- package/lib/index.css +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_AssociationView.d.ts.map +1 -1
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_AssociationView.js +0 -4
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_AssociationView.js.map +1 -1
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassView.d.ts +0 -3
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassView.d.ts.map +1 -1
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassView.js +0 -20
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassView.js.map +1 -1
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassViewReference.d.ts +0 -1
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassViewReference.d.ts.map +1 -1
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassViewReference.js +1 -10
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassViewReference.js.map +1 -1
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_Diagram.d.ts +0 -12
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_Diagram.d.ts.map +1 -1
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_Diagram.js +1 -56
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_Diagram.js.map +1 -1
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_GeneralizationView.d.ts +0 -3
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_GeneralizationView.d.ts.map +1 -1
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_GeneralizationView.js +0 -7
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_GeneralizationView.js.map +1 -1
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_PropertyView.d.ts +0 -4
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_PropertyView.d.ts.map +1 -1
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_PropertyView.js +0 -7
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_PropertyView.js.map +1 -1
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipEdgeView.d.ts +6 -3
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipEdgeView.d.ts.map +1 -1
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipEdgeView.js +6 -14
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipEdgeView.js.map +1 -1
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipView.d.ts +24 -23
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipView.d.ts.map +1 -1
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipView.js +57 -129
- package/lib/models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipView.js.map +1 -1
- package/lib/models/metamodels/pure/packageableElements/diagram/geometry/DSLDiagram_PositionedRectangle.d.ts +0 -8
- package/lib/models/metamodels/pure/packageableElements/diagram/geometry/DSLDiagram_PositionedRectangle.d.ts.map +1 -1
- package/lib/models/metamodels/pure/packageableElements/diagram/geometry/DSLDiagram_PositionedRectangle.js +0 -19
- package/lib/models/metamodels/pure/packageableElements/diagram/geometry/DSLDiagram_PositionedRectangle.js.map +1 -1
- package/lib/models/metamodels/pure/packageableElements/diagram/geometry/DSLDiagram_Vector.d.ts +3 -3
- package/lib/models/metamodels/pure/packageableElements/diagram/geometry/DSLDiagram_Vector.d.ts.map +1 -1
- package/lib/models/metamodels/pure/packageableElements/diagram/geometry/DSLDiagram_Vector.js +1 -1
- package/lib/models/metamodels/pure/packageableElements/diagram/geometry/DSLDiagram_Vector.js.map +1 -1
- package/lib/models/protocols/pure/v1/transformation/pureGraph/V1_DSLDiagram_GraphBuilderHelper.d.ts.map +1 -1
- package/lib/models/protocols/pure/v1/transformation/pureGraph/V1_DSLDiagram_GraphBuilderHelper.js +3 -3
- package/lib/models/protocols/pure/v1/transformation/pureGraph/V1_DSLDiagram_GraphBuilderHelper.js.map +1 -1
- package/lib/models/protocols/pure/v1/transformation/pureGraph/V1_DSLDiagram_TransformerHelper.js +2 -2
- package/lib/models/protocols/pure/v1/transformation/pureGraph/V1_DSLDiagram_TransformerHelper.js.map +1 -1
- package/lib/package.json +4 -4
- package/lib/stores/studio/DSLDiagram_GraphModifierHelper.d.ts +57 -0
- package/lib/stores/studio/DSLDiagram_GraphModifierHelper.d.ts.map +1 -0
- package/lib/stores/studio/DSLDiagram_GraphModifierHelper.js +94 -0
- package/lib/stores/studio/DSLDiagram_GraphModifierHelper.js.map +1 -0
- package/lib/stores/studio/DiagramEditorState.d.ts.map +1 -1
- package/lib/stores/studio/DiagramEditorState.js +13 -10
- package/lib/stores/studio/DiagramEditorState.js.map +1 -1
- package/package.json +11 -11
- package/src/DiagramRenderer.ts +136 -72
- package/src/components/studio/ClassDiagramPreview.tsx +3 -1
- package/src/components/studio/DiagramEditor.tsx +17 -11
- package/src/graphManager/DSLDiagram_PureGraphManagerPlugin.ts +17 -0
- package/src/graphManager/action/changeDetection/DSLDiagram_ObserverHelper.ts +153 -0
- package/src/helpers/DiagramHelper.ts +126 -4
- package/src/index.ts +1 -4
- package/src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_AssociationView.ts +0 -6
- package/src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassView.ts +0 -23
- package/src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassViewReference.ts +0 -13
- package/src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_Diagram.ts +1 -64
- package/src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_GeneralizationView.ts +0 -11
- package/src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_PropertyView.ts +0 -17
- package/src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipEdgeView.ts +6 -16
- package/src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipView.ts +71 -169
- package/src/models/metamodels/pure/packageableElements/diagram/geometry/DSLDiagram_PositionedRectangle.ts +0 -21
- package/src/models/metamodels/pure/packageableElements/diagram/geometry/DSLDiagram_Vector.ts +3 -3
- package/src/models/protocols/pure/v1/transformation/pureGraph/V1_DSLDiagram_GraphBuilderHelper.ts +6 -3
- package/src/models/protocols/pure/v1/transformation/pureGraph/V1_DSLDiagram_TransformerHelper.ts +4 -4
- package/src/stores/studio/DSLDiagram_GraphModifierHelper.ts +164 -0
- package/src/stores/studio/DiagramEditorState.ts +28 -9
- package/tsconfig.json +2 -0
@@ -0,0 +1,153 @@
|
|
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 {
|
18
|
+
observe_Abstract_PackageableElement,
|
19
|
+
observe_PackageableElementReference,
|
20
|
+
observe_PropertyReference,
|
21
|
+
skipObserved,
|
22
|
+
} from '@finos/legend-graph';
|
23
|
+
import { computed, makeObservable, observable, override } from 'mobx';
|
24
|
+
import type { AssociationView } from '../../../models/metamodels/pure/packageableElements/diagram/DSLDiagram_AssociationView';
|
25
|
+
import type { ClassView } from '../../../models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassView';
|
26
|
+
import type { ClassViewReference } from '../../../models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassViewReference';
|
27
|
+
import type { Diagram } from '../../../models/metamodels/pure/packageableElements/diagram/DSLDiagram_Diagram';
|
28
|
+
import type { GeneralizationView } from '../../../models/metamodels/pure/packageableElements/diagram/DSLDiagram_GeneralizationView';
|
29
|
+
import type { PropertyView } from '../../../models/metamodels/pure/packageableElements/diagram/DSLDiagram_PropertyView';
|
30
|
+
import type { RelationshipEdgeView } from '../../../models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipEdgeView';
|
31
|
+
import type { RelationshipView } from '../../../models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipView';
|
32
|
+
import type { PositionedRectangle } from '../../../models/metamodels/pure/packageableElements/diagram/geometry/DSLDiagram_PositionedRectangle';
|
33
|
+
|
34
|
+
export const observe_PositionedRectangle = skipObserved(
|
35
|
+
(metamodel: PositionedRectangle): PositionedRectangle =>
|
36
|
+
makeObservable(metamodel, {
|
37
|
+
dummyObservable: observable,
|
38
|
+
}),
|
39
|
+
);
|
40
|
+
|
41
|
+
export const observe_ClassViewReference = skipObserved(
|
42
|
+
(metamodel: ClassViewReference): ClassViewReference => {
|
43
|
+
makeObservable(metamodel, {
|
44
|
+
value: observable,
|
45
|
+
});
|
46
|
+
|
47
|
+
observe_PackageableElementReference(metamodel.ownerReference);
|
48
|
+
|
49
|
+
return metamodel;
|
50
|
+
},
|
51
|
+
);
|
52
|
+
|
53
|
+
export const observe_ClassView = skipObserved(
|
54
|
+
(metamodel: ClassView): ClassView => {
|
55
|
+
observe_PositionedRectangle(metamodel);
|
56
|
+
|
57
|
+
makeObservable(metamodel, {
|
58
|
+
id: observable,
|
59
|
+
hideProperties: observable,
|
60
|
+
hideTaggedValues: observable,
|
61
|
+
hideStereotypes: observable,
|
62
|
+
hashCode: computed,
|
63
|
+
});
|
64
|
+
|
65
|
+
observe_PackageableElementReference(metamodel.class);
|
66
|
+
|
67
|
+
return metamodel;
|
68
|
+
},
|
69
|
+
);
|
70
|
+
|
71
|
+
export const observe_RelationShipEdgeView = skipObserved(
|
72
|
+
(metamodel: RelationshipEdgeView): RelationshipEdgeView => {
|
73
|
+
observe_ClassViewReference(metamodel.classView);
|
74
|
+
|
75
|
+
return metamodel;
|
76
|
+
},
|
77
|
+
);
|
78
|
+
|
79
|
+
export const observe_RelationshipView = skipObserved(
|
80
|
+
(metamodel: RelationshipView): RelationshipView => {
|
81
|
+
makeObservable(metamodel, {
|
82
|
+
// NOTE: to optimize performance for diagram, we have made classview's position and rectangle non-observable
|
83
|
+
// if we want to further optimize, perhaps we can also remove observability from path
|
84
|
+
path: observable,
|
85
|
+
pathForSerialization: computed,
|
86
|
+
});
|
87
|
+
|
88
|
+
observe_RelationShipEdgeView(metamodel.from);
|
89
|
+
observe_RelationShipEdgeView(metamodel.to);
|
90
|
+
|
91
|
+
return metamodel;
|
92
|
+
},
|
93
|
+
);
|
94
|
+
|
95
|
+
export const observe_GeneralizationView = skipObserved(
|
96
|
+
(metamodel: GeneralizationView): GeneralizationView => {
|
97
|
+
observe_RelationshipView(metamodel);
|
98
|
+
|
99
|
+
makeObservable(metamodel, {
|
100
|
+
hashCode: computed,
|
101
|
+
});
|
102
|
+
|
103
|
+
return metamodel;
|
104
|
+
},
|
105
|
+
);
|
106
|
+
|
107
|
+
export const observe_AssociationView = skipObserved(
|
108
|
+
(metamodel: AssociationView): AssociationView => {
|
109
|
+
observe_RelationshipView(metamodel);
|
110
|
+
|
111
|
+
makeObservable(metamodel, {
|
112
|
+
hashCode: computed,
|
113
|
+
});
|
114
|
+
|
115
|
+
observe_PropertyReference(metamodel.property);
|
116
|
+
observe_PackageableElementReference(metamodel.association);
|
117
|
+
|
118
|
+
return metamodel;
|
119
|
+
},
|
120
|
+
);
|
121
|
+
|
122
|
+
export const observe_PropertyView = skipObserved(
|
123
|
+
(metamodel: PropertyView): PropertyView => {
|
124
|
+
observe_RelationshipView(metamodel);
|
125
|
+
|
126
|
+
makeObservable(metamodel, {
|
127
|
+
hashCode: computed,
|
128
|
+
});
|
129
|
+
|
130
|
+
observe_PropertyReference(metamodel.property);
|
131
|
+
|
132
|
+
return metamodel;
|
133
|
+
},
|
134
|
+
);
|
135
|
+
|
136
|
+
export const observe_Diagram = skipObserved((metamodel: Diagram): Diagram => {
|
137
|
+
observe_Abstract_PackageableElement(metamodel);
|
138
|
+
|
139
|
+
makeObservable<Diagram, '_elementHashCode'>(metamodel, {
|
140
|
+
classViews: observable,
|
141
|
+
associationViews: observable,
|
142
|
+
generalizationViews: observable,
|
143
|
+
propertyViews: observable,
|
144
|
+
_elementHashCode: override,
|
145
|
+
});
|
146
|
+
|
147
|
+
metamodel.classViews.forEach(observe_ClassView);
|
148
|
+
metamodel.associationViews.forEach(observe_AssociationView);
|
149
|
+
metamodel.generalizationViews.forEach(observe_GeneralizationView);
|
150
|
+
metamodel.propertyViews.forEach(observe_PropertyView);
|
151
|
+
|
152
|
+
return metamodel;
|
153
|
+
});
|
@@ -14,10 +14,13 @@
|
|
14
14
|
* limitations under the License.
|
15
15
|
*/
|
16
16
|
|
17
|
+
import { RelationshipView } from '../models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipView';
|
18
|
+
import { Point } from '../models/metamodels/pure/packageableElements/diagram/geometry/DSLDiagram_Point';
|
19
|
+
import { Vector } from '../models/metamodels/pure/packageableElements/diagram/geometry/DSLDiagram_Vector';
|
17
20
|
import type { PureModel } from '@finos/legend-graph';
|
21
|
+
import { deleteEntry } from '@finos/legend-shared';
|
18
22
|
import type { ClassView } from '../models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassView';
|
19
23
|
import type { Diagram } from '../models/metamodels/pure/packageableElements/diagram/DSLDiagram_Diagram';
|
20
|
-
import { Point } from '../models/metamodels/pure/packageableElements/diagram/geometry/DSLDiagram_Point';
|
21
24
|
|
22
25
|
/**
|
23
26
|
* Get absolute position of element on the screen by recursively walking up element tree
|
@@ -51,14 +54,14 @@ export const cleanUpDeadReferencesInDiagram = (
|
|
51
54
|
.includes(propertyView.property.value.name),
|
52
55
|
);
|
53
56
|
propertyViewsToRemove.forEach((propertyView) =>
|
54
|
-
diagram.
|
57
|
+
deleteEntry(diagram.propertyViews, propertyView),
|
55
58
|
);
|
56
59
|
|
57
60
|
// Fix orphan class views
|
58
61
|
const classViewsToRemove = diagram.classViews.filter(
|
59
62
|
(cv) => !graph.getNullableClass(cv.class.value.path),
|
60
63
|
);
|
61
|
-
classViewsToRemove.forEach((cw) => diagram.
|
64
|
+
classViewsToRemove.forEach((cw) => deleteEntry(diagram.classViews, cw));
|
62
65
|
|
63
66
|
// Fix orphan gneralization views
|
64
67
|
const generalizationViewsToRemove = diagram.generalizationViews.filter(
|
@@ -74,6 +77,125 @@ export const cleanUpDeadReferencesInDiagram = (
|
|
74
77
|
},
|
75
78
|
);
|
76
79
|
generalizationViewsToRemove.forEach((g) =>
|
77
|
-
diagram.
|
80
|
+
deleteEntry(diagram.generalizationViews, g),
|
81
|
+
);
|
82
|
+
};
|
83
|
+
|
84
|
+
export const _relationshipView_setPath = (
|
85
|
+
relationshipView: RelationshipView,
|
86
|
+
val: Point[],
|
87
|
+
): void => {
|
88
|
+
relationshipView.path = val;
|
89
|
+
};
|
90
|
+
|
91
|
+
/**
|
92
|
+
* Simplify the path.
|
93
|
+
*
|
94
|
+
* Flatten the path if the angle is wide enough between 3 consecutive points
|
95
|
+
* Also remove unnecessary inside points
|
96
|
+
*/
|
97
|
+
export const _relationshipView_simplifyPath = (
|
98
|
+
relationshipView: RelationshipView,
|
99
|
+
): void => {
|
100
|
+
const fullPath = relationshipView.buildFullPath();
|
101
|
+
// NOTE: this method here will `swallow` up points inside of the boxes
|
102
|
+
const newPath = RelationshipView.pruneUnnecessaryInsidePoints(
|
103
|
+
fullPath,
|
104
|
+
relationshipView.from.classView.value,
|
105
|
+
relationshipView.to.classView.value,
|
78
106
|
);
|
107
|
+
|
108
|
+
// recompute the offset point from center inside of `from` and `to` classviews.
|
109
|
+
// for each, we first check if `manageInsidePointsDynamically` removes any points from the full path
|
110
|
+
// if it does we will update the offset
|
111
|
+
if (newPath[0] !== fullPath[0]) {
|
112
|
+
const center = relationshipView.from.classView.value.center();
|
113
|
+
relationshipView.from.offsetX = (newPath[0] as Point).x - center.x;
|
114
|
+
relationshipView.from.offsetY = (newPath[0] as Point).y - center.y;
|
115
|
+
}
|
116
|
+
|
117
|
+
if (newPath[newPath.length - 1] !== fullPath[fullPath.length - 1]) {
|
118
|
+
const center = relationshipView.to.classView.value.center();
|
119
|
+
relationshipView.to.offsetX =
|
120
|
+
(newPath[newPath.length - 1] as Point).x - center.x;
|
121
|
+
relationshipView.to.offsetY =
|
122
|
+
(newPath[newPath.length - 1] as Point).y - center.y;
|
123
|
+
}
|
124
|
+
|
125
|
+
// find the point which can be flattened due to its wide angle
|
126
|
+
const result = [];
|
127
|
+
for (let i = 0; i < newPath.length - 2; i++) {
|
128
|
+
const v1 = Vector.fromPoints(
|
129
|
+
newPath[i + 1] as Point,
|
130
|
+
newPath[i] as Point,
|
131
|
+
).unit();
|
132
|
+
const v2 = Vector.fromPoints(
|
133
|
+
newPath[i + 1] as Point,
|
134
|
+
newPath[i + 2] as Point,
|
135
|
+
).unit();
|
136
|
+
const dot = v1.dotProduct(v2);
|
137
|
+
const angle = (Math.acos(dot) * 180) / Math.PI;
|
138
|
+
if (Math.abs(angle - 180) > 5) {
|
139
|
+
result.push(newPath[i + 1] as Point);
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
143
|
+
// NOTE: this new path does not contain the 2 end points
|
144
|
+
_relationshipView_setPath(relationshipView, result);
|
145
|
+
};
|
146
|
+
|
147
|
+
/**
|
148
|
+
* Based on the location, find the point on the path that matches or create new point
|
149
|
+
* (within a threshold of proximity) from the coordinate and put this in the path array
|
150
|
+
* so it doesn't look too weird
|
151
|
+
*/
|
152
|
+
export const _findOrBuildPoint = (
|
153
|
+
relationshipView: RelationshipView,
|
154
|
+
x: number,
|
155
|
+
y: number,
|
156
|
+
zoom: number,
|
157
|
+
allowChange: boolean,
|
158
|
+
): Point | undefined => {
|
159
|
+
for (const pt of relationshipView.path) {
|
160
|
+
if (
|
161
|
+
Math.sqrt((x - pt.x) * (x - pt.x) + (y - pt.y) * (y - pt.y)) <
|
162
|
+
10 / zoom
|
163
|
+
) {
|
164
|
+
return pt;
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
const fullPath = relationshipView.buildFullPath(allowChange);
|
169
|
+
const newPath = [];
|
170
|
+
let point;
|
171
|
+
|
172
|
+
for (let i = 0; i < fullPath.length - 1; i++) {
|
173
|
+
const a = fullPath[i] as Point;
|
174
|
+
const b = fullPath[i + 1] as Point;
|
175
|
+
const u = new Vector(a.x, a.y).normal(new Vector(b.x, b.y)).unit();
|
176
|
+
const v = Vector.fromPoints(a, new Point(x, y));
|
177
|
+
|
178
|
+
// if the selection point is not too far from the segment
|
179
|
+
// of the path, create a new point and make it part of the path
|
180
|
+
if (Math.abs(u.dotProduct(v)) < 5 / zoom) {
|
181
|
+
const lx = (a.x < b.x ? a.x : b.x) - 5 / zoom;
|
182
|
+
const hx = (a.x < b.x ? b.x : a.x) + 5 / zoom;
|
183
|
+
const ly = (a.y < b.y ? a.y : b.y) - 5 / zoom;
|
184
|
+
const hy = (a.y < b.y ? b.y : a.y) + 5 / zoom;
|
185
|
+
|
186
|
+
if (lx <= x && x <= hx && ly <= y && y <= hy) {
|
187
|
+
point = new Point(x, y);
|
188
|
+
newPath.push(point);
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
192
|
+
if (i < fullPath.length - 2) {
|
193
|
+
newPath.push(fullPath[i + 1] as Point);
|
194
|
+
}
|
195
|
+
}
|
196
|
+
if (point && allowChange) {
|
197
|
+
// NOTE: this new path does not contain the 2 end points
|
198
|
+
_relationshipView_setPath(relationshipView, newPath);
|
199
|
+
}
|
200
|
+
return point;
|
79
201
|
};
|
package/src/index.ts
CHANGED
@@ -24,10 +24,7 @@ export { DiagramRenderer, DIAGRAM_INTERACTION_MODE } from './DiagramRenderer';
|
|
24
24
|
|
25
25
|
export { Diagram } from './models/metamodels/pure/packageableElements/diagram/DSLDiagram_Diagram';
|
26
26
|
export { ClassView } from './models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassView';
|
27
|
-
export {
|
28
|
-
RelationshipView,
|
29
|
-
manageInsidePointsDynamically,
|
30
|
-
} from './models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipView';
|
27
|
+
export { RelationshipView } from './models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipView';
|
31
28
|
export { PropertyHolderView } from './models/metamodels/pure/packageableElements/diagram/DSLDiagram_PropertyHolderView';
|
32
29
|
export { PropertyView } from './models/metamodels/pure/packageableElements/diagram/DSLDiagram_PropertyView';
|
33
30
|
export { AssociationView } from './models/metamodels/pure/packageableElements/diagram/DSLDiagram_AssociationView';
|
package/src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_AssociationView.ts
CHANGED
@@ -14,7 +14,6 @@
|
|
14
14
|
* limitations under the License.
|
15
15
|
*/
|
16
16
|
|
17
|
-
import { computed, makeObservable } from 'mobx';
|
18
17
|
import { hashArray, type Hashable } from '@finos/legend-shared';
|
19
18
|
import { PropertyHolderView } from './DSLDiagram_PropertyHolderView';
|
20
19
|
import type { ClassView } from './DSLDiagram_ClassView';
|
@@ -37,11 +36,6 @@ export class AssociationView extends PropertyHolderView implements Hashable {
|
|
37
36
|
to: ClassView,
|
38
37
|
) {
|
39
38
|
super(owner, property, from, to);
|
40
|
-
|
41
|
-
makeObservable(this, {
|
42
|
-
hashCode: computed,
|
43
|
-
});
|
44
|
-
|
45
39
|
this.association = association;
|
46
40
|
}
|
47
41
|
|
@@ -14,7 +14,6 @@
|
|
14
14
|
* limitations under the License.
|
15
15
|
*/
|
16
16
|
|
17
|
-
import { computed, observable, action, makeObservable } from 'mobx';
|
18
17
|
import { hashArray, type Hashable } from '@finos/legend-shared';
|
19
18
|
import { PositionedRectangle } from './geometry/DSLDiagram_PositionedRectangle';
|
20
19
|
import { Rectangle } from './geometry/DSLDiagram_Rectangle';
|
@@ -37,33 +36,11 @@ export class ClassView extends PositionedRectangle implements Hashable {
|
|
37
36
|
_class: PackageableElementReference<Class>,
|
38
37
|
) {
|
39
38
|
super(new Point(0, 0), new Rectangle(0, 0));
|
40
|
-
|
41
|
-
makeObservable(this, {
|
42
|
-
id: observable,
|
43
|
-
hideProperties: observable,
|
44
|
-
hideTaggedValues: observable,
|
45
|
-
hideStereotypes: observable,
|
46
|
-
setHideProperties: action,
|
47
|
-
setHideStereotypes: action,
|
48
|
-
setHideTaggedValues: action,
|
49
|
-
hashCode: computed,
|
50
|
-
});
|
51
|
-
|
52
39
|
this.owner = owner;
|
53
40
|
this.id = id;
|
54
41
|
this.class = _class;
|
55
42
|
}
|
56
43
|
|
57
|
-
setHideProperties(val: boolean): void {
|
58
|
-
this.hideProperties = val;
|
59
|
-
}
|
60
|
-
setHideStereotypes(val: boolean): void {
|
61
|
-
this.hideStereotypes = val;
|
62
|
-
}
|
63
|
-
setHideTaggedValues(val: boolean): void {
|
64
|
-
this.hideTaggedValues = val;
|
65
|
-
}
|
66
|
-
|
67
44
|
override get hashCode(): string {
|
68
45
|
return hashArray([
|
69
46
|
DIAGRAM_HASH_STRUCTURE.CLASS_VIEW,
|
package/src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_ClassViewReference.ts
CHANGED
@@ -14,13 +14,11 @@
|
|
14
14
|
* limitations under the License.
|
15
15
|
*/
|
16
16
|
|
17
|
-
import { observable, action, makeObservable } from 'mobx';
|
18
17
|
import type { Diagram } from './DSLDiagram_Diagram';
|
19
18
|
import type { ClassView } from './DSLDiagram_ClassView';
|
20
19
|
import {
|
21
20
|
PackageableElementExplicitReference,
|
22
21
|
ReferenceWithOwner,
|
23
|
-
setPackageableElementReferenceValue,
|
24
22
|
type PackageableElementImplicitReference,
|
25
23
|
type PackageableElementReference,
|
26
24
|
} from '@finos/legend-graph';
|
@@ -34,20 +32,9 @@ export abstract class ClassViewReference extends ReferenceWithOwner {
|
|
34
32
|
value: ClassView,
|
35
33
|
) {
|
36
34
|
super(ownerReference);
|
37
|
-
|
38
|
-
makeObservable(this, {
|
39
|
-
value: observable,
|
40
|
-
setValue: action,
|
41
|
-
});
|
42
|
-
|
43
35
|
this.ownerReference = ownerReference;
|
44
36
|
this.value = value;
|
45
37
|
}
|
46
|
-
|
47
|
-
setValue(value: ClassView): void {
|
48
|
-
this.value = value;
|
49
|
-
setPackageableElementReferenceValue(this.ownerReference, value.owner);
|
50
|
-
}
|
51
38
|
}
|
52
39
|
|
53
40
|
export class ClassViewExplicitReference extends ClassViewReference {
|
@@ -14,13 +14,7 @@
|
|
14
14
|
* limitations under the License.
|
15
15
|
*/
|
16
16
|
|
17
|
-
import {
|
18
|
-
import {
|
19
|
-
hashArray,
|
20
|
-
addUniqueEntry,
|
21
|
-
deleteEntry,
|
22
|
-
type Hashable,
|
23
|
-
} from '@finos/legend-shared';
|
17
|
+
import { hashArray, type Hashable } from '@finos/legend-shared';
|
24
18
|
import type { ClassView } from './DSLDiagram_ClassView';
|
25
19
|
import type { PropertyView } from './DSLDiagram_PropertyView';
|
26
20
|
import type { GeneralizationView } from './DSLDiagram_GeneralizationView';
|
@@ -37,63 +31,6 @@ export class Diagram extends PackageableElement implements Hashable {
|
|
37
31
|
generalizationViews: GeneralizationView[] = [];
|
38
32
|
propertyViews: PropertyView[] = [];
|
39
33
|
|
40
|
-
constructor(name: string) {
|
41
|
-
super(name);
|
42
|
-
|
43
|
-
makeObservable<Diagram, '_elementHashCode'>(this, {
|
44
|
-
classViews: observable,
|
45
|
-
associationViews: observable,
|
46
|
-
generalizationViews: observable,
|
47
|
-
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
|
-
_elementHashCode: override,
|
60
|
-
});
|
61
|
-
}
|
62
|
-
|
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
34
|
protected override get _elementHashCode(): string {
|
98
35
|
return hashArray([
|
99
36
|
DIAGRAM_HASH_STRUCTURE.DIAGRAM,
|
package/src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_GeneralizationView.ts
CHANGED
@@ -14,22 +14,11 @@
|
|
14
14
|
* limitations under the License.
|
15
15
|
*/
|
16
16
|
|
17
|
-
import { computed, makeObservable } from 'mobx';
|
18
17
|
import { hashArray, type Hashable } from '@finos/legend-shared';
|
19
18
|
import { RelationshipView } from './DSLDiagram_RelationshipView';
|
20
|
-
import type { Diagram } from './DSLDiagram_Diagram';
|
21
|
-
import type { ClassView } from './DSLDiagram_ClassView';
|
22
19
|
import { DIAGRAM_HASH_STRUCTURE } from '../../../../DSLDiagram_ModelUtils';
|
23
20
|
|
24
21
|
export class GeneralizationView extends RelationshipView implements Hashable {
|
25
|
-
constructor(owner: Diagram, from: ClassView, to: ClassView) {
|
26
|
-
super(owner, from, to);
|
27
|
-
|
28
|
-
makeObservable(this, {
|
29
|
-
hashCode: computed,
|
30
|
-
});
|
31
|
-
}
|
32
|
-
|
33
22
|
override get hashCode(): string {
|
34
23
|
return hashArray([
|
35
24
|
DIAGRAM_HASH_STRUCTURE.GENERALIZATION_VIEW,
|
@@ -14,28 +14,11 @@
|
|
14
14
|
* limitations under the License.
|
15
15
|
*/
|
16
16
|
|
17
|
-
import { computed, makeObservable } from 'mobx';
|
18
17
|
import { hashArray, type Hashable } from '@finos/legend-shared';
|
19
18
|
import { PropertyHolderView } from './DSLDiagram_PropertyHolderView';
|
20
|
-
import type { Diagram } from './DSLDiagram_Diagram';
|
21
|
-
import type { ClassView } from './DSLDiagram_ClassView';
|
22
|
-
import type { PropertyReference } from '@finos/legend-graph';
|
23
19
|
import { DIAGRAM_HASH_STRUCTURE } from '../../../../DSLDiagram_ModelUtils';
|
24
20
|
|
25
21
|
export class PropertyView extends PropertyHolderView implements Hashable {
|
26
|
-
constructor(
|
27
|
-
owner: Diagram,
|
28
|
-
property: PropertyReference,
|
29
|
-
from: ClassView,
|
30
|
-
to: ClassView,
|
31
|
-
) {
|
32
|
-
super(owner, property, from, to);
|
33
|
-
|
34
|
-
makeObservable(this, {
|
35
|
-
hashCode: computed,
|
36
|
-
});
|
37
|
-
}
|
38
|
-
|
39
22
|
override get hashCode(): string {
|
40
23
|
return hashArray([DIAGRAM_HASH_STRUCTURE.PROPERTY_VIEW, super.hashCode]);
|
41
24
|
}
|
package/src/models/metamodels/pure/packageableElements/diagram/DSLDiagram_RelationshipEdgeView.ts
CHANGED
@@ -14,29 +14,19 @@
|
|
14
14
|
* limitations under the License.
|
15
15
|
*/
|
16
16
|
|
17
|
-
import { observable, action, makeObservable } from 'mobx';
|
18
17
|
import type { ClassViewReference } from './DSLDiagram_ClassViewReference';
|
19
18
|
|
20
|
-
export class
|
19
|
+
export class RelationshipEdgeView {
|
21
20
|
classView: ClassViewReference;
|
21
|
+
/**
|
22
|
+
* Offsets from the center of the class view.
|
23
|
+
*
|
24
|
+
* These offsets can be used to compute the end points of relationship views.
|
25
|
+
*/
|
22
26
|
offsetX?: number | undefined;
|
23
27
|
offsetY?: number | undefined;
|
24
28
|
|
25
29
|
constructor(classView: ClassViewReference) {
|
26
|
-
makeObservable(this, {
|
27
|
-
offsetX: observable,
|
28
|
-
offsetY: observable,
|
29
|
-
setOffsetX: action,
|
30
|
-
setOffsetY: action,
|
31
|
-
});
|
32
|
-
|
33
30
|
this.classView = classView;
|
34
31
|
}
|
35
|
-
|
36
|
-
setOffsetX(val: number): void {
|
37
|
-
this.offsetX = val;
|
38
|
-
}
|
39
|
-
setOffsetY(val: number): void {
|
40
|
-
this.offsetY = val;
|
41
|
-
}
|
42
32
|
}
|