@eclipse-glsp/layout-elk 0.9.0-next.397cddd.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +642 -0
- package/README.md +9 -0
- package/lib/basic-type-mapper.d.ts +26 -0
- package/lib/basic-type-mapper.d.ts.map +1 -0
- package/lib/basic-type-mapper.js +97 -0
- package/lib/basic-type-mapper.js.map +1 -0
- package/lib/di.config.d.ts +53 -0
- package/lib/di.config.d.ts.map +1 -0
- package/lib/di.config.js +90 -0
- package/lib/di.config.js.map +1 -0
- package/lib/di.config.spec.d.ts +2 -0
- package/lib/di.config.spec.d.ts.map +1 -0
- package/lib/di.config.spec.js +100 -0
- package/lib/di.config.spec.js.map +1 -0
- package/lib/glsp-element-filter.d.ts +17 -0
- package/lib/glsp-element-filter.d.ts.map +1 -0
- package/lib/glsp-element-filter.js +53 -0
- package/lib/glsp-element-filter.js.map +1 -0
- package/lib/glsp-elk-layout-engine.d.ts +39 -0
- package/lib/glsp-elk-layout-engine.d.ts.map +1 -0
- package/lib/glsp-elk-layout-engine.js +80 -0
- package/lib/glsp-elk-layout-engine.js.map +1 -0
- package/lib/glsp-layout-configurator.d.ts +43 -0
- package/lib/glsp-layout-configurator.d.ts.map +1 -0
- package/lib/glsp-layout-configurator.js +57 -0
- package/lib/glsp-layout-configurator.js.map +1 -0
- package/lib/index.d.ts +23 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +36 -0
- package/lib/index.js.map +1 -0
- package/package.json +61 -0
- package/src/basic-type-mapper.ts +73 -0
- package/src/di.config.spec.ts +92 -0
- package/src/di.config.ts +117 -0
- package/src/glsp-element-filter.ts +38 -0
- package/src/glsp-elk-layout-engine.ts +57 -0
- package/src/glsp-layout-configurator.ts +59 -0
- package/src/index.ts +22 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2022 STMicroelectronics and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
import { LayoutOptions } from 'elkjs';
|
|
17
|
+
import { DefaultLayoutConfigurator } from 'sprotty-elk';
|
|
18
|
+
import { SGraph, SModelElement, SModelIndex } from 'sprotty-protocol';
|
|
19
|
+
import { BasicTypeMapper } from './basic-type-mapper';
|
|
20
|
+
/**
|
|
21
|
+
* Configurator for ELK layout algorithms; provides mappings of layout options for each model element.
|
|
22
|
+
* For a list of all available layout options checkout the official ELK documentation.
|
|
23
|
+
* A minimal configuration should at least specify the `elk.algorithm` option as
|
|
24
|
+
* return value of {@link GlspLayoutConfigurator.graphOptions}.
|
|
25
|
+
* {@link https://www.eclipse.org/elk/reference/options.html}
|
|
26
|
+
*/
|
|
27
|
+
export declare class GlspLayoutConfigurator extends DefaultLayoutConfigurator {
|
|
28
|
+
protected typeMapper: BasicTypeMapper;
|
|
29
|
+
protected getBasicType(smodel: SModelElement): string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A fallback configurator that is used in the `configureELKLayoutModule` utility method.
|
|
33
|
+
* If no explicit layout configurator binding is provided a new instance of the fallback configurator is
|
|
34
|
+
* bound as replacement. Basic layout options for the root graph element are derived from the
|
|
35
|
+
* configuration parameters that haven been passed to the `configureELKLayoutModule` function.
|
|
36
|
+
*/
|
|
37
|
+
export declare class FallbackGlspLayoutConfigurator extends GlspLayoutConfigurator {
|
|
38
|
+
protected typeMapper: BasicTypeMapper;
|
|
39
|
+
protected fallbackGraphOptions: LayoutOptions;
|
|
40
|
+
constructor(typeMapper: BasicTypeMapper, algorithms: string[], defaultLayoutOptions?: LayoutOptions);
|
|
41
|
+
protected graphOptions(sgraph: SGraph, index: SModelIndex): LayoutOptions | undefined;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=glsp-layout-configurator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glsp-layout-configurator.d.ts","sourceRoot":"","sources":["../src/glsp-layout-configurator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAClF,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD;;;;;;GAMG;AACH,qBACa,sBAAuB,SAAQ,yBAAyB;IAEjE,SAAS,CAAC,UAAU,EAAE,eAAe,CAAC;IAEtC,SAAS,CAAC,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM;CAGxD;AAED;;;;;GAKG;AACH,qBACa,8BAA+B,SAAQ,sBAAsB;IAE1D,SAAS,CAAC,UAAU,EAAE,eAAe;IADjD,SAAS,CAAC,oBAAoB,EAAE,aAAa,CAAC;gBACxB,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,oBAAoB,GAAE,aAAkB;IAQjH,SAAS,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,aAAa,GAAG,SAAS;CAGxF"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.FallbackGlspLayoutConfigurator = exports.GlspLayoutConfigurator = void 0;
|
|
13
|
+
const inversify_1 = require("inversify");
|
|
14
|
+
const sprotty_elk_1 = require("sprotty-elk");
|
|
15
|
+
const basic_type_mapper_1 = require("./basic-type-mapper");
|
|
16
|
+
/**
|
|
17
|
+
* Configurator for ELK layout algorithms; provides mappings of layout options for each model element.
|
|
18
|
+
* For a list of all available layout options checkout the official ELK documentation.
|
|
19
|
+
* A minimal configuration should at least specify the `elk.algorithm` option as
|
|
20
|
+
* return value of {@link GlspLayoutConfigurator.graphOptions}.
|
|
21
|
+
* {@link https://www.eclipse.org/elk/reference/options.html}
|
|
22
|
+
*/
|
|
23
|
+
let GlspLayoutConfigurator = class GlspLayoutConfigurator extends sprotty_elk_1.DefaultLayoutConfigurator {
|
|
24
|
+
getBasicType(smodel) {
|
|
25
|
+
return this.typeMapper.getBasicType(smodel);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
__decorate([
|
|
29
|
+
inversify_1.inject(basic_type_mapper_1.BasicTypeMapper),
|
|
30
|
+
__metadata("design:type", basic_type_mapper_1.BasicTypeMapper)
|
|
31
|
+
], GlspLayoutConfigurator.prototype, "typeMapper", void 0);
|
|
32
|
+
GlspLayoutConfigurator = __decorate([
|
|
33
|
+
inversify_1.injectable()
|
|
34
|
+
], GlspLayoutConfigurator);
|
|
35
|
+
exports.GlspLayoutConfigurator = GlspLayoutConfigurator;
|
|
36
|
+
/**
|
|
37
|
+
* A fallback configurator that is used in the `configureELKLayoutModule` utility method.
|
|
38
|
+
* If no explicit layout configurator binding is provided a new instance of the fallback configurator is
|
|
39
|
+
* bound as replacement. Basic layout options for the root graph element are derived from the
|
|
40
|
+
* configuration parameters that haven been passed to the `configureELKLayoutModule` function.
|
|
41
|
+
*/
|
|
42
|
+
let FallbackGlspLayoutConfigurator = class FallbackGlspLayoutConfigurator extends GlspLayoutConfigurator {
|
|
43
|
+
constructor(typeMapper, algorithms, defaultLayoutOptions = {}) {
|
|
44
|
+
super();
|
|
45
|
+
this.typeMapper = typeMapper;
|
|
46
|
+
this.fallbackGraphOptions = Object.assign({ 'elk.algorithm': algorithms[0] }, defaultLayoutOptions);
|
|
47
|
+
}
|
|
48
|
+
graphOptions(sgraph, index) {
|
|
49
|
+
return this.fallbackGraphOptions;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
FallbackGlspLayoutConfigurator = __decorate([
|
|
53
|
+
inversify_1.injectable(),
|
|
54
|
+
__metadata("design:paramtypes", [basic_type_mapper_1.BasicTypeMapper, Array, Object])
|
|
55
|
+
], FallbackGlspLayoutConfigurator);
|
|
56
|
+
exports.FallbackGlspLayoutConfigurator = FallbackGlspLayoutConfigurator;
|
|
57
|
+
//# sourceMappingURL=glsp-layout-configurator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glsp-layout-configurator.js","sourceRoot":"","sources":["../src/glsp-layout-configurator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAgBA,yCAA+C;AAC/C,6CAAwD;AAExD,2DAAsD;AAEtD;;;;;;GAMG;AAEH,IAAa,sBAAsB,GAAnC,MAAa,sBAAuB,SAAQ,uCAAyB;IAIvD,YAAY,CAAC,MAAqB;QACxC,OAAO,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;CACJ,CAAA;AALG;IADC,kBAAM,CAAC,mCAAe,CAAC;8BACF,mCAAe;0DAAC;AAF7B,sBAAsB;IADlC,sBAAU,EAAE;GACA,sBAAsB,CAOlC;AAPY,wDAAsB;AASnC;;;;;GAKG;AAEH,IAAa,8BAA8B,GAA3C,MAAa,8BAA+B,SAAQ,sBAAsB;IAEtE,YAAsB,UAA2B,EAAE,UAAoB,EAAE,uBAAsC,EAAE;QAC7G,KAAK,EAAE,CAAC;QADU,eAAU,GAAV,UAAU,CAAiB;QAE7C,IAAI,CAAC,oBAAoB,mBACrB,eAAe,EAAE,UAAU,CAAC,CAAC,CAAC,IAC3B,oBAAoB,CAC1B,CAAC;IACN,CAAC;IAES,YAAY,CAAC,MAAc,EAAE,KAAkB;QACrD,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACrC,CAAC;CACJ,CAAA;AAbY,8BAA8B;IAD1C,sBAAU,EAAE;qCAGyB,mCAAe;GAFxC,8BAA8B,CAa1C;AAbY,wEAA8B"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2022 EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
export * from 'sprotty-elk';
|
|
17
|
+
export { SModelIndex } from 'sprotty-protocol/lib/utils/model-utils';
|
|
18
|
+
export * from './basic-type-mapper';
|
|
19
|
+
export * from './di.config';
|
|
20
|
+
export * from './glsp-element-filter';
|
|
21
|
+
export * from './glsp-elk-layout-engine';
|
|
22
|
+
export * from './glsp-layout-configurator';
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAClF,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AACrE,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
/********************************************************************************
|
|
14
|
+
* Copyright (c) 2022 EclipseSource and others.
|
|
15
|
+
*
|
|
16
|
+
* This program and the accompanying materials are made available under the
|
|
17
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
18
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
19
|
+
*
|
|
20
|
+
* This Source Code may also be made available under the following Secondary
|
|
21
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
22
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
23
|
+
* with the GNU Classpath Exception which is available at
|
|
24
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
25
|
+
*
|
|
26
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
27
|
+
********************************************************************************/
|
|
28
|
+
__exportStar(require("sprotty-elk"), exports);
|
|
29
|
+
var model_utils_1 = require("sprotty-protocol/lib/utils/model-utils");
|
|
30
|
+
Object.defineProperty(exports, "SModelIndex", { enumerable: true, get: function () { return model_utils_1.SModelIndex; } });
|
|
31
|
+
__exportStar(require("./basic-type-mapper"), exports);
|
|
32
|
+
__exportStar(require("./di.config"), exports);
|
|
33
|
+
__exportStar(require("./glsp-element-filter"), exports);
|
|
34
|
+
__exportStar(require("./glsp-elk-layout-engine"), exports);
|
|
35
|
+
__exportStar(require("./glsp-layout-configurator"), exports);
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;;;;;kFAckF;AAClF,8CAA4B;AAC5B,sEAAqE;AAA5D,0GAAA,WAAW,OAAA;AACpB,sDAAoC;AACpC,8CAA4B;AAC5B,wDAAsC;AACtC,2DAAyC;AACzC,6DAA2C"}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@eclipse-glsp/layout-elk",
|
|
3
|
+
"version": "0.9.0-next.397cddd.4+397cddd",
|
|
4
|
+
"description": "Integration of ELK graph layout algorithms in GLSP Node Server",
|
|
5
|
+
"license": "(EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0)",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"eclipse",
|
|
8
|
+
"graphics",
|
|
9
|
+
"diagram",
|
|
10
|
+
"modeling",
|
|
11
|
+
"visualization",
|
|
12
|
+
"glsp",
|
|
13
|
+
"diagram editor"
|
|
14
|
+
],
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "Eclipse GLSP"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://www.eclipse.org/glsp/",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/eclipse-glsp/glsp-server-node.git"
|
|
22
|
+
},
|
|
23
|
+
"bugs": "https://github.com/eclipse-glsp/glsp/issues",
|
|
24
|
+
"contributors": [
|
|
25
|
+
{
|
|
26
|
+
"name": "STMicroelectronics",
|
|
27
|
+
"url": "https://www.st.com/"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"name": "Eclipse GLSP Project",
|
|
31
|
+
"email": "glsp-dev@eclipse.org",
|
|
32
|
+
"url": "https://projects.eclipse.org/projects/ecd.glsp"
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
"files": [
|
|
36
|
+
"lib",
|
|
37
|
+
"src",
|
|
38
|
+
"css"
|
|
39
|
+
],
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@eclipse-glsp/server-node": "0.9.0-next.397cddd.4+397cddd",
|
|
42
|
+
"elkjs": "^0.7.1",
|
|
43
|
+
"inversify": "^5.0.1",
|
|
44
|
+
"sprotty-elk": "next"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"clean": "rimraf lib",
|
|
48
|
+
"build": "yarn run clean && tsc",
|
|
49
|
+
"test": "mocha --config ../../.mocharc.json \"./src/**/*.spec.?(ts|tsx)\"",
|
|
50
|
+
"test:ci": "export JUNIT_REPORT_PATH=./report.xml && yarn test --reporter mocha-jenkins-reporter",
|
|
51
|
+
"lint": "eslint -c ../../.eslintrc.js --ext .ts,.tsx ./src",
|
|
52
|
+
"lint:fix": "eslint --fix -c ../../.eslintrc.js --ext .ts,.tsx ./src",
|
|
53
|
+
"watch": "tsc -w"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
57
|
+
},
|
|
58
|
+
"main": "lib/index",
|
|
59
|
+
"types": "lib/index",
|
|
60
|
+
"gitHead": "397cddd532e9596bbe3717d931ae5ca826d949dd"
|
|
61
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2022 STMicroelectronics and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
import { DiagramConfiguration, GEdge, GGraph, GLabel, GModelElementConstructor, GNode, GPort } from '@eclipse-glsp/server-node';
|
|
17
|
+
import { inject, injectable, postConstruct } from 'inversify';
|
|
18
|
+
import { SModelElement } from 'sprotty-protocol';
|
|
19
|
+
|
|
20
|
+
export type BasicGModelType = 'graph' | 'node' | 'edge' | 'label' | 'port' | 'unknown';
|
|
21
|
+
|
|
22
|
+
@injectable()
|
|
23
|
+
/**
|
|
24
|
+
* The `BasicTypeMapper` provides the means to derive the basic type from a given graph model element.
|
|
25
|
+
* The basic type information is used by the `ElkLayoutEngine` to transform graphic model elements into their corresponding ELK object
|
|
26
|
+
* representation.
|
|
27
|
+
*/
|
|
28
|
+
export class BasicTypeMapper {
|
|
29
|
+
@inject(DiagramConfiguration)
|
|
30
|
+
protected diagramConfiguration: DiagramConfiguration;
|
|
31
|
+
|
|
32
|
+
protected basicTypeMap: Map<string, BasicGModelType>;
|
|
33
|
+
|
|
34
|
+
@postConstruct()
|
|
35
|
+
protected postConstruct(): void {
|
|
36
|
+
this.basicTypeMap = new Map();
|
|
37
|
+
this.diagramConfiguration.typeMapping.forEach((constructor, type) => {
|
|
38
|
+
const basicType = this.toBasicType(constructor);
|
|
39
|
+
if (basicType) {
|
|
40
|
+
this.basicTypeMap.set(type, basicType);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
protected toBasicType(constructor: GModelElementConstructor): BasicGModelType {
|
|
46
|
+
const element = new constructor();
|
|
47
|
+
if (element instanceof GNode) {
|
|
48
|
+
return 'node';
|
|
49
|
+
} else if (element instanceof GEdge) {
|
|
50
|
+
return 'edge';
|
|
51
|
+
} else if (element instanceof GGraph) {
|
|
52
|
+
return 'graph';
|
|
53
|
+
} else if (element instanceof GLabel) {
|
|
54
|
+
return 'label';
|
|
55
|
+
} else if (element instanceof GPort) {
|
|
56
|
+
return 'port';
|
|
57
|
+
}
|
|
58
|
+
return 'unknown';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
getBasicType(input: SModelElement | string): BasicGModelType {
|
|
62
|
+
const type = typeof input === 'string' ? input : input.type;
|
|
63
|
+
const basicType = this.basicTypeMap.get(type);
|
|
64
|
+
if (basicType) {
|
|
65
|
+
return basicType;
|
|
66
|
+
}
|
|
67
|
+
const subtypeSeparator = type.lastIndexOf(':');
|
|
68
|
+
if (subtypeSeparator > 0) {
|
|
69
|
+
return this.getBasicType(type.substring(0, subtypeSeparator));
|
|
70
|
+
}
|
|
71
|
+
return 'unknown';
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2022 STMicroelectronics and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
import { DefaultModelState, DiagramConfiguration, GGraph, GModelElementConstructor, ModelState } from '@eclipse-glsp/server-node';
|
|
17
|
+
import { StubDiagramConfiguration } from '@eclipse-glsp/server-node/lib/test/mock-util';
|
|
18
|
+
import { expect } from 'chai';
|
|
19
|
+
import { Container, ContainerModule, injectable } from 'inversify';
|
|
20
|
+
import * as sinon from 'sinon';
|
|
21
|
+
import { IElementFilter, ILayoutConfigurator } from 'sprotty-elk';
|
|
22
|
+
import { SModelIndex } from 'sprotty-protocol';
|
|
23
|
+
import { GlspLayoutConfigurator } from '.';
|
|
24
|
+
import { configureELKLayoutModule } from './di.config';
|
|
25
|
+
import { GlspElementFilter } from './glsp-element-filter';
|
|
26
|
+
import { FallbackGlspLayoutConfigurator } from './glsp-layout-configurator';
|
|
27
|
+
|
|
28
|
+
@injectable()
|
|
29
|
+
class CustomLayoutConfigurator extends GlspLayoutConfigurator {}
|
|
30
|
+
|
|
31
|
+
@injectable()
|
|
32
|
+
class CustomElementFilter extends GlspElementFilter {}
|
|
33
|
+
|
|
34
|
+
describe('test configureELKLayoutModule', () => {
|
|
35
|
+
const sandbox = sinon.createSandbox();
|
|
36
|
+
const mockDiagramConfiguration = new StubDiagramConfiguration();
|
|
37
|
+
const typeMappings = new Map<string, GModelElementConstructor>();
|
|
38
|
+
|
|
39
|
+
typeMappings.set('graph', GGraph);
|
|
40
|
+
sandbox.stub(mockDiagramConfiguration, 'typeMapping').value(typeMappings);
|
|
41
|
+
const modelState = new DefaultModelState();
|
|
42
|
+
const baseModule = new ContainerModule(bind => {
|
|
43
|
+
bind(DiagramConfiguration).toConstantValue(mockDiagramConfiguration);
|
|
44
|
+
bind(ModelState).toConstantValue(modelState);
|
|
45
|
+
});
|
|
46
|
+
it('configure with minimal options', () => {
|
|
47
|
+
const algorithm = 'layered';
|
|
48
|
+
const elkModule = configureELKLayoutModule({ algorithms: [algorithm] });
|
|
49
|
+
const container = new Container();
|
|
50
|
+
container.load(baseModule, elkModule);
|
|
51
|
+
const filter = container.get<IElementFilter>(IElementFilter);
|
|
52
|
+
expect(filter).to.be.instanceOf(GlspElementFilter);
|
|
53
|
+
const configurator = container.get<ILayoutConfigurator>(ILayoutConfigurator);
|
|
54
|
+
expect(configurator).to.be.instanceOf(FallbackGlspLayoutConfigurator);
|
|
55
|
+
const graphOptions = configurator.apply(new GGraph(), new SModelIndex());
|
|
56
|
+
expect(graphOptions).not.to.be.undefined;
|
|
57
|
+
expect(graphOptions!['elk.algorithm']).to.equal(algorithm);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('configure with additional default layout options', () => {
|
|
61
|
+
const algorithm = 'layered';
|
|
62
|
+
const defaultLayoutOptions = {
|
|
63
|
+
'elk.direction': 'LEFT',
|
|
64
|
+
'elk.edgeRouting': 'POLYLINE'
|
|
65
|
+
};
|
|
66
|
+
const elkModule = configureELKLayoutModule({ algorithms: [algorithm], defaultLayoutOptions });
|
|
67
|
+
const container = new Container();
|
|
68
|
+
container.load(baseModule, elkModule);
|
|
69
|
+
const configurator = container.get<ILayoutConfigurator>(ILayoutConfigurator);
|
|
70
|
+
const graphOptions = configurator.apply(new GGraph(), new SModelIndex());
|
|
71
|
+
expect(graphOptions).not.to.be.undefined;
|
|
72
|
+
expect(graphOptions).to.include(defaultLayoutOptions);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('configure with custom layout configurator', () => {
|
|
76
|
+
const algorithm = 'layered';
|
|
77
|
+
const elkModule = configureELKLayoutModule({ algorithms: [algorithm], layoutConfigurator: CustomLayoutConfigurator });
|
|
78
|
+
const container = new Container();
|
|
79
|
+
container.load(baseModule, elkModule);
|
|
80
|
+
const configurator = container.get<ILayoutConfigurator>(ILayoutConfigurator);
|
|
81
|
+
expect(configurator).to.be.instanceOf(CustomLayoutConfigurator);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('configure with custom element filter', () => {
|
|
85
|
+
const algorithm = 'layered';
|
|
86
|
+
const elkModule = configureELKLayoutModule({ algorithms: [algorithm], elementFilter: CustomElementFilter });
|
|
87
|
+
const container = new Container();
|
|
88
|
+
container.load(baseModule, elkModule);
|
|
89
|
+
const filter = container.get<IElementFilter>(IElementFilter);
|
|
90
|
+
expect(filter).to.be.instanceOf(CustomElementFilter);
|
|
91
|
+
});
|
|
92
|
+
});
|
package/src/di.config.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2022 STMicroelectronics and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
import { LayoutEngine } from '@eclipse-glsp/server-node/';
|
|
17
|
+
import ElkConstructor, { LayoutOptions } from 'elkjs/lib/elk.bundled';
|
|
18
|
+
import { ContainerModule } from 'inversify';
|
|
19
|
+
import { ElkFactory, ElkLayoutEngine, IElementFilter, ILayoutConfigurator } from 'sprotty-elk';
|
|
20
|
+
import { GlspElkLayoutEngine } from '.';
|
|
21
|
+
import { BasicTypeMapper } from './basic-type-mapper';
|
|
22
|
+
import { GlspElementFilter } from './glsp-element-filter';
|
|
23
|
+
import { BaseElkLayoutEngine } from './glsp-elk-layout-engine';
|
|
24
|
+
import { FallbackGlspLayoutConfigurator, GlspLayoutConfigurator } from './glsp-layout-configurator';
|
|
25
|
+
|
|
26
|
+
type Constructor<T> = new (...args: any[]) => T;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Configuration options for the {@link configureELKLayoutModule} function.
|
|
30
|
+
*/
|
|
31
|
+
export interface ElkModuleOptions {
|
|
32
|
+
/**
|
|
33
|
+
* The set of elk algorithms that is used by the {@link GlspElkLayoutEngine}.
|
|
34
|
+
*/
|
|
35
|
+
algorithms: string[];
|
|
36
|
+
/**
|
|
37
|
+
* Additional default layout options. This options are passed to the underlying {@link ElkFactory}.
|
|
38
|
+
* In addition, they are used to configure the {@link FallbackGlspLayoutConfigurator}.
|
|
39
|
+
*/
|
|
40
|
+
defaultLayoutOptions?: LayoutOptions;
|
|
41
|
+
/**
|
|
42
|
+
* The custom {@link GlspLayoutConfigurator} class that should be bound. If this option is not set
|
|
43
|
+
* the {@link FallbackGlspLayoutConfigurator} is bound instead.
|
|
44
|
+
*/
|
|
45
|
+
layoutConfigurator?: Constructor<GlspLayoutConfigurator>;
|
|
46
|
+
/**
|
|
47
|
+
* The custom {@link GlspElementFilter} class that should be bound. If this option is not set, the default implementation
|
|
48
|
+
* is bound.
|
|
49
|
+
*/
|
|
50
|
+
elementFilter?: Constructor<GlspElementFilter>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Utility method to create a DI module that provides all necessary bindings to use the {@link GlspElkLayoutEngine} in a node GLSP server
|
|
55
|
+
* implementation. A set of configuration options is provided to enable easy customization. In most cases at least
|
|
56
|
+
* the custom {@link layoutConfigurator} binding should be provided (in addition to the required `algorithms' property) via these options.
|
|
57
|
+
*
|
|
58
|
+
* The constructed module is not intended for standalone use cases and only works in combination with a GLSPDiagramModule.
|
|
59
|
+
*
|
|
60
|
+
* * The following bindings are provided:
|
|
61
|
+
* - {@link BasicTypeMapper}
|
|
62
|
+
* - {@link BaseElkLayoutEngine}
|
|
63
|
+
* - {@link ElkLayoutEngine}
|
|
64
|
+
* - {@link GlspElementFilter}
|
|
65
|
+
* - {@link IElementFilter}
|
|
66
|
+
* - {@link GlspLayoutConfigurator}
|
|
67
|
+
* - {@link ILayoutConfigurator}
|
|
68
|
+
* - {@link LayoutEngine}
|
|
69
|
+
* - {@link ElkFactory}
|
|
70
|
+
*
|
|
71
|
+
* @param options The configuration options
|
|
72
|
+
* @returns A DI module that can be loaded as additional module when configuring a diagram module for a GLSP server.
|
|
73
|
+
*/
|
|
74
|
+
export function configureELKLayoutModule(options: ElkModuleOptions): ContainerModule {
|
|
75
|
+
return new ContainerModule(bind => {
|
|
76
|
+
bind(BasicTypeMapper).toSelf().inSingletonScope();
|
|
77
|
+
bind(BaseElkLayoutEngine)
|
|
78
|
+
.toDynamicValue(context => {
|
|
79
|
+
const elkFactory = context.container.get<ElkFactory>(ElkFactory);
|
|
80
|
+
const elementFilter = context.container.get<IElementFilter>(IElementFilter);
|
|
81
|
+
const layoutConfigurator = context.container.get<ILayoutConfigurator>(ILayoutConfigurator);
|
|
82
|
+
const typeMapper = context.container.get<BasicTypeMapper>(BasicTypeMapper);
|
|
83
|
+
return new BaseElkLayoutEngine(elkFactory, elementFilter, layoutConfigurator, typeMapper);
|
|
84
|
+
})
|
|
85
|
+
.inSingletonScope();
|
|
86
|
+
|
|
87
|
+
bind(ElkLayoutEngine).to(BaseElkLayoutEngine);
|
|
88
|
+
|
|
89
|
+
if (options.elementFilter) {
|
|
90
|
+
bind(GlspElementFilter).to(options.elementFilter).inSingletonScope();
|
|
91
|
+
} else {
|
|
92
|
+
bind(GlspElementFilter).toSelf().inSingletonScope();
|
|
93
|
+
}
|
|
94
|
+
bind(IElementFilter).toService(GlspElementFilter);
|
|
95
|
+
|
|
96
|
+
if (options.layoutConfigurator) {
|
|
97
|
+
bind(GlspLayoutConfigurator).to(options.layoutConfigurator);
|
|
98
|
+
} else {
|
|
99
|
+
bind(GlspLayoutConfigurator)
|
|
100
|
+
.toDynamicValue(context => {
|
|
101
|
+
const typeMapper = context.container.get<BasicTypeMapper>(BasicTypeMapper);
|
|
102
|
+
return new FallbackGlspLayoutConfigurator(typeMapper, options.algorithms, options.defaultLayoutOptions);
|
|
103
|
+
})
|
|
104
|
+
.inSingletonScope();
|
|
105
|
+
}
|
|
106
|
+
bind(ILayoutConfigurator).toService(GlspLayoutConfigurator);
|
|
107
|
+
bind(LayoutEngine).to(GlspElkLayoutEngine).inSingletonScope();
|
|
108
|
+
|
|
109
|
+
const elkFactory: ElkFactory = () =>
|
|
110
|
+
new ElkConstructor({
|
|
111
|
+
algorithms: options.algorithms,
|
|
112
|
+
defaultLayoutOptions: options.defaultLayoutOptions
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
bind(ElkFactory).toConstantValue(elkFactory);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2022 STMicroelectronics and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
import { inject, injectable } from 'inversify';
|
|
17
|
+
import { DefaultElementFilter } from 'sprotty-elk';
|
|
18
|
+
import { SModelElement } from 'sprotty-protocol';
|
|
19
|
+
import { BasicTypeMapper } from './basic-type-mapper';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The default `IElementFilter` used to determine which model elements should be included in the automatic layout.
|
|
23
|
+
* Without further configuration this filter includes all basic model elements (nodes,edges,labels,ports) that are
|
|
24
|
+
* part of the graphical model. For each a custom filter behavior is in place. Edges that have no source or target are filtered out.
|
|
25
|
+
* In addition, edges that are connected to a filtered element are filtered out as well.
|
|
26
|
+
* The filter behavior for each of the basic types can be customized by overriding the corresponding `filter` method.
|
|
27
|
+
* (e.g. {@link GlspElementFilter.filterNode})
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
@injectable()
|
|
31
|
+
export class GlspElementFilter extends DefaultElementFilter {
|
|
32
|
+
@inject(BasicTypeMapper)
|
|
33
|
+
protected typeMapper: BasicTypeMapper;
|
|
34
|
+
|
|
35
|
+
protected getBasicType(smodel: SModelElement): string {
|
|
36
|
+
return this.typeMapper.getBasicType(smodel);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2022 STMicroelectronics and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
import { LayoutEngine, ModelState } from '@eclipse-glsp/server-node';
|
|
17
|
+
import { inject, injectable } from 'inversify';
|
|
18
|
+
import { ElkFactory, ElkLayoutEngine, IElementFilter, ILayoutConfigurator } from 'sprotty-elk/lib/inversify';
|
|
19
|
+
import { SModelElement } from 'sprotty-protocol/lib/model';
|
|
20
|
+
import { BasicTypeMapper } from './basic-type-mapper';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Layout engine that delegates to ELK by transforming the graphical model into an ELK graph.
|
|
24
|
+
*/
|
|
25
|
+
@injectable()
|
|
26
|
+
export class BaseElkLayoutEngine extends ElkLayoutEngine {
|
|
27
|
+
constructor(
|
|
28
|
+
@inject(ElkFactory) elkFactory: ElkFactory,
|
|
29
|
+
@inject(IElementFilter) protected readonly filter: IElementFilter,
|
|
30
|
+
@inject(ILayoutConfigurator) protected readonly configurator: ILayoutConfigurator,
|
|
31
|
+
@inject(BasicTypeMapper) protected typeMapper: BasicTypeMapper
|
|
32
|
+
) {
|
|
33
|
+
super(elkFactory, filter, configurator);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
protected getBasicType(smodel: SModelElement): string {
|
|
37
|
+
return this.typeMapper.getBasicType(smodel);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A implement of GLSP's {@link LayoutEngine} interface that retrieves the graphical model from the {@link ModelState}
|
|
43
|
+
* and delegates the to an underlying {@link BaseElkLayoutEngine} instance for computing the layout.
|
|
44
|
+
*/
|
|
45
|
+
@injectable()
|
|
46
|
+
export class GlspElkLayoutEngine implements LayoutEngine {
|
|
47
|
+
@inject(ModelState)
|
|
48
|
+
protected modelState: ModelState;
|
|
49
|
+
|
|
50
|
+
@inject(BaseElkLayoutEngine)
|
|
51
|
+
protected elkLayoutEngine: BaseElkLayoutEngine;
|
|
52
|
+
|
|
53
|
+
async layout(): Promise<void> {
|
|
54
|
+
const graph = this.modelState.root;
|
|
55
|
+
await this.elkLayoutEngine.layout(graph);
|
|
56
|
+
}
|
|
57
|
+
}
|