Skip to content

Commit 15c7180

Browse files
Merge branch 'develop' into feature/box-selection
2 parents 6d8ff72 + dcd4878 commit 15c7180

File tree

8 files changed

+13
-69
lines changed

8 files changed

+13
-69
lines changed

src/main/components/store/model-state.ts

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export interface ModelState {
5454
// the boundary of the diagram is determined by some relationship.
5555

5656
export class ModelState {
57-
static fromModel(compatModel: UMLModelCompat, repositionRoots = true): PartialModelState {
57+
static fromModel(compatModel: UMLModelCompat): PartialModelState {
5858
const model = backwardsCompatibleModel(compatModel);
5959

6060
const apollonElements = model.elements;
@@ -89,17 +89,6 @@ export class ModelState {
8989
return relationship;
9090
});
9191

92-
if (repositionRoots) {
93-
const roots = [...elements.filter((element) => !element.owner), ...relationships];
94-
const bounds = computeBoundingBoxForElements(roots);
95-
bounds.width = Math.ceil(bounds.width / 20) * 20;
96-
bounds.height = Math.ceil(bounds.height / 20) * 20;
97-
for (const element of roots) {
98-
element.bounds.x -= bounds.x + bounds.width / 2;
99-
element.bounds.y -= bounds.y + bounds.height / 2;
100-
}
101-
}
102-
10392
// set diagram to keep diagram type
10493
const diagram: UMLDiagram = new UMLDiagram();
10594
diagram.type = model.type as UMLDiagramType;
@@ -131,7 +120,7 @@ export class ModelState {
131120
};
132121
}
133122

134-
static toModel(state: ModelState, repositionRoots = true): Apollon.UMLModel {
123+
static toModel(state: ModelState): Apollon.UMLModel {
135124
const elements = Object.values(state.elements)
136125
.map<UMLElement | null>((element) => UMLElementRepository.get(element))
137126
.reduce<{ [id: string]: UMLElement }>((acc, val) => ({ ...acc, ...(val && { [val.id]: val }) }), {});
@@ -172,21 +161,6 @@ export class ModelState {
172161
relationship.serialize(),
173162
);
174163

175-
if (repositionRoots) {
176-
const roots = [...apollonElementsArray, ...apollonRelationships].filter((element) => !element.owner);
177-
const bounds = computeBoundingBoxForElements(roots);
178-
bounds.width = Math.ceil(bounds.width / 20) * 20;
179-
bounds.height = Math.ceil(bounds.height / 20) * 20;
180-
for (const element of apollonElementsArray) {
181-
element.bounds.x -= bounds.x;
182-
element.bounds.y -= bounds.y;
183-
}
184-
for (const element of apollonRelationships) {
185-
element.bounds.x -= bounds.x;
186-
element.bounds.y -= bounds.y;
187-
}
188-
}
189-
190164
const interactive: Apollon.Selection = {
191165
elements: arrayToInclusionMap(state.interactive.filter((id) => UMLElement.isUMLElement(state.elements[id]))),
192166
relationships: arrayToInclusionMap(

src/main/components/store/model-store.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const createReduxStore = (
4949
const patchReducer =
5050
patcher &&
5151
createPatcherReducer<UMLModel, ModelState>(patcher, {
52-
transform: (model) => ModelState.fromModel(model, false) as ModelState,
52+
transform: (model) => ModelState.fromModel(model) as ModelState,
5353
merge,
5454
});
5555

@@ -73,7 +73,7 @@ export const createReduxStore = (
7373
createPatcherMiddleware<UMLModel, Actions, ModelState>(patcher, {
7474
selectDiscrete: (action) => isDiscreteAction(action) || isSelectionAction(action),
7575
selectContinuous: (action) => isContinuousAction(action),
76-
transform: (state) => ModelState.toModel(state, false),
76+
transform: (state) => ModelState.toModel(state),
7777
}),
7878
]
7979
: []),

src/tests/unit/apollon-editor-test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ afterEach(() => {
2626
});
2727
});
2828

29+
// eslint-disable-next-line @typescript-eslint/no-var-requires
2930
const testClassDiagramAsSVG = require('./test-resources/class-diagram-as-svg.json') as string;
3031

3132
const ignoreSVGClassNames = (svgString: string): string => {

src/tests/unit/components/store/model-state-test.ts

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,14 @@ import { computeBoundingBoxForElements } from '../../../../main/utils/geometry/b
44
import diagram from '../../test-resources/class-diagram.json';
55

66
describe('model state.', () => {
7-
it('centers a model when imported.', () => {
7+
it('does not center the model when imported.', () => {
88
const state = ModelState.fromModel(diagram as any);
99
const bounds = computeBoundingBoxForElements(Object.values(state.elements as any));
1010

11-
expect(Math.abs(bounds.x + bounds.width / 2)).toBeLessThan(40);
12-
expect(Math.abs(bounds.y + bounds.height / 2)).toBeLessThan(40);
13-
});
14-
15-
it('does not center the model when imported, given the option.', () => {
16-
const state = ModelState.fromModel(diagram as any, false);
17-
const bounds = computeBoundingBoxForElements(Object.values(state.elements as any));
18-
1911
expect(bounds.x).toBe(0);
2012
});
2113

22-
it('puts model on 0,0 when exporting.', () => {
14+
it('deos not put model on 0,0 when exporting.', () => {
2315
const state = ModelState.fromModel(diagram as any);
2416
expect(state.elements).toBeDefined();
2517
state.elements &&
@@ -38,29 +30,6 @@ describe('model state.', () => {
3830
const exp = ModelState.toModel(state as any);
3931
const bounds = computeBoundingBoxForElements([...Object.values(exp.elements), ...Object.values(exp.relationships)]);
4032

41-
expect(bounds.x).toBe(0);
42-
expect(bounds.y).toBe(0);
43-
});
44-
45-
it('deos not put model on 0,0 when exporting, given the option.', () => {
46-
const state = ModelState.fromModel(diagram as any);
47-
expect(state.elements).toBeDefined();
48-
state.elements &&
49-
Object.values(state.elements).forEach((element) => {
50-
if (UMLRelationship.isUMLRelationship(element)) {
51-
element.path.forEach((point) => {
52-
point.x += 100;
53-
point.y += 100;
54-
});
55-
}
56-
57-
element.bounds.x += 100;
58-
element.bounds.y += 100;
59-
});
60-
61-
const exp = ModelState.toModel(state as any, false);
62-
const bounds = computeBoundingBoxForElements([...Object.values(exp.elements), ...Object.values(exp.relationships)]);
63-
6433
expect(bounds.x).not.toBe(0);
6534
expect(bounds.y).not.toBe(0);
6635
});

src/tests/unit/test-resources/class-diagram-v2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"version": "2.0.0",
33
"type": "ClassDiagram",
4-
"size": { "width": 860, "height": 260 },
4+
"size": { "width": 1680, "height": 480 },
55
"interactive": { "elements": [], "relationships": [] },
66
"elements": [
77
{

src/tests/unit/test-resources/class-diagram.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"version": "3.0.0",
33
"type": "ClassDiagram",
4-
"size": { "width": 860, "height": 260 },
4+
"size": { "width": 1680, "height": 480 },
55
"interactive": { "elements": {}, "relationships": {} },
66
"elements": {
77
"c10b995a-036c-4e9e-aa67-0570ada5cb6a": {

src/tests/unit/test-resources/communication-diagram-v2.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"version": "2.0.0",
33
"type": "CommunicationDiagram",
44
"size": {
5-
"width": 380,
6-
"height": 240
5+
"width": 700,
6+
"height": 405
77
},
88
"interactive": {
99
"elements": [],

src/tests/unit/test-resources/communication-diagram.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"version": "3.0.0",
33
"type": "CommunicationDiagram",
44
"size": {
5-
"width": 380,
6-
"height": 240
5+
"width": 700,
6+
"height": 405
77
},
88
"interactive": {
99
"elements": {},

0 commit comments

Comments
 (0)