Skip to content

Commit 8a4fc2e

Browse files
committed
build elkjs 0.10.0
1 parent 2d656db commit 8a4fc2e

File tree

10 files changed

+116803
-1
lines changed

10 files changed

+116803
-1
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ ext.versions = [
4343
emfGwt: '2.12.4',
4444
gwt: '2.11.0',
4545
guava: '31.1-jre',
46-
melk: '0.10.0-SNAPSHOT',
46+
melk: '0.10.0',
4747
xtext: '2.28.0',
4848

4949
// From 2.26 on Xtext supports Java 17, however,

lib/elk-api.d.ts

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2019 TypeFox and others.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*******************************************************************************/
10+
11+
export interface LayoutOptions {
12+
[key: string]: string
13+
}
14+
15+
export interface ElkPoint {
16+
x: number
17+
y: number
18+
}
19+
20+
export interface ElkGraphElement {
21+
id?: string
22+
labels?: ElkLabel[]
23+
layoutOptions?: LayoutOptions
24+
}
25+
26+
export interface ElkShape extends ElkGraphElement {
27+
x?: number
28+
y?: number
29+
width?: number
30+
height?: number
31+
}
32+
33+
export interface ElkNode extends ElkShape {
34+
id: string
35+
children?: ElkNode[]
36+
ports?: ElkPort[]
37+
edges?: ElkExtendedEdge[]
38+
}
39+
40+
export interface ElkPort extends ElkShape {
41+
id: string
42+
}
43+
44+
export interface ElkLabel extends ElkShape {
45+
text?: string
46+
}
47+
48+
/**
49+
* @deprecated use ElkExtendedEdge directly
50+
*/
51+
export interface ElkEdge extends ElkGraphElement {
52+
id: string
53+
container?: string
54+
junctionPoints?: ElkPoint[]
55+
}
56+
57+
/**
58+
* @deprecated use ElkExtendedEdge instead
59+
*/
60+
export interface ElkPrimitiveEdge extends ElkEdge {
61+
source: string
62+
sourcePort?: string
63+
target: string
64+
targetPort?: string
65+
sourcePoint?: ElkPoint
66+
targetPoint?: ElkPoint
67+
bendPoints?: ElkPoint[]
68+
}
69+
70+
export interface ElkExtendedEdge extends ElkEdge {
71+
sources: string[]
72+
targets: string[]
73+
sections?: ElkEdgeSection[]
74+
}
75+
76+
export interface ElkEdgeSection extends ElkGraphElement {
77+
id: string
78+
startPoint: ElkPoint
79+
endPoint: ElkPoint
80+
bendPoints?: ElkPoint[]
81+
incomingShape?: string
82+
outgoingShape?: string
83+
incomingSections?: string[]
84+
outgoingSections?: string[]
85+
}
86+
87+
export interface ElkLayoutArguments {
88+
layoutOptions?: LayoutOptions
89+
logging?: boolean
90+
measureExecutionTime?: boolean
91+
}
92+
93+
export interface ElkCommonDescription {
94+
id?: string
95+
name?: string
96+
description?: string
97+
}
98+
99+
export interface ElkLayoutAlgorithmDescription extends ElkCommonDescription {
100+
category?: string
101+
knownOptions?: string[]
102+
supportedFeatures?: string[]
103+
}
104+
105+
export interface ElkLayoutOptionDescription extends ElkCommonDescription {
106+
group?: string
107+
type?: string
108+
targets?: string[]
109+
}
110+
111+
export interface ElkLayoutCategoryDescription extends ElkCommonDescription {
112+
knownLayouters?: string[]
113+
}
114+
115+
export interface ELK {
116+
layout<T extends ElkNode>(
117+
graph: T,
118+
args?: ElkLayoutArguments
119+
): Promise<Omit<T, 'children'> & { children?: (T['children'][number] & ElkNode)[] }>;
120+
knownLayoutAlgorithms(): Promise<ElkLayoutAlgorithmDescription[]>
121+
knownLayoutOptions(): Promise<ElkLayoutOptionDescription[]>
122+
knownLayoutCategories(): Promise<ElkLayoutCategoryDescription[]>
123+
terminateWorker(): void;
124+
}
125+
126+
export interface ELKConstructorArguments {
127+
defaultLayoutOptions?: LayoutOptions
128+
algorithms?: string[]
129+
workerUrl?: string
130+
workerFactory?: (url?: string) => Worker
131+
}
132+
133+
declare const ElkConstructor: {
134+
new(args?: ELKConstructorArguments): ELK;
135+
};
136+
export default ElkConstructor;

lib/elk-api.js

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ELK = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2+
"use strict";
3+
4+
Object.defineProperty(exports, "__esModule", {
5+
value: true
6+
});
7+
exports["default"] = void 0;
8+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
9+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
10+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
11+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
12+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
13+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
14+
/*******************************************************************************
15+
* Copyright (c) 2017 Kiel University and others.
16+
*
17+
* This program and the accompanying materials are made
18+
* available under the terms of the Eclipse Public License 2.0
19+
* which is available at https://www.eclipse.org/legal/epl-2.0/
20+
*
21+
* SPDX-License-Identifier: EPL-2.0
22+
*******************************************************************************/
23+
var ELK = exports["default"] = /*#__PURE__*/function () {
24+
function ELK() {
25+
var _this = this;
26+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
27+
_ref$defaultLayoutOpt = _ref.defaultLayoutOptions,
28+
defaultLayoutOptions = _ref$defaultLayoutOpt === void 0 ? {} : _ref$defaultLayoutOpt,
29+
_ref$algorithms = _ref.algorithms,
30+
algorithms = _ref$algorithms === void 0 ? ['layered', 'stress', 'mrtree', 'radial', 'force', 'disco', 'sporeOverlap', 'sporeCompaction', 'rectpacking'] : _ref$algorithms,
31+
workerFactory = _ref.workerFactory,
32+
workerUrl = _ref.workerUrl;
33+
_classCallCheck(this, ELK);
34+
this.defaultLayoutOptions = defaultLayoutOptions;
35+
this.initialized = false;
36+
37+
// check valid worker construction possible
38+
if (typeof workerUrl === 'undefined' && typeof workerFactory === 'undefined') {
39+
throw new Error("Cannot construct an ELK without both 'workerUrl' and 'workerFactory'.");
40+
}
41+
var factory = workerFactory;
42+
if (typeof workerUrl !== 'undefined' && typeof workerFactory === 'undefined') {
43+
// use default Web Worker
44+
factory = function factory(url) {
45+
return new Worker(url);
46+
};
47+
}
48+
49+
// create the worker
50+
var worker = factory(workerUrl);
51+
if (typeof worker.postMessage !== 'function') {
52+
throw new TypeError("Created worker does not provide" + " the required 'postMessage' function.");
53+
}
54+
55+
// wrap the worker to return promises
56+
this.worker = new PromisedWorker(worker);
57+
58+
// initially register algorithms
59+
this.worker.postMessage({
60+
cmd: 'register',
61+
algorithms: algorithms
62+
}).then(function (r) {
63+
return _this.initialized = true;
64+
})["catch"](console.err);
65+
}
66+
return _createClass(ELK, [{
67+
key: "layout",
68+
value: function layout(graph) {
69+
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
70+
_ref2$layoutOptions = _ref2.layoutOptions,
71+
layoutOptions = _ref2$layoutOptions === void 0 ? this.defaultLayoutOptions : _ref2$layoutOptions,
72+
_ref2$logging = _ref2.logging,
73+
logging = _ref2$logging === void 0 ? false : _ref2$logging,
74+
_ref2$measureExecutio = _ref2.measureExecutionTime,
75+
measureExecutionTime = _ref2$measureExecutio === void 0 ? false : _ref2$measureExecutio;
76+
if (!graph) {
77+
return Promise.reject(new Error("Missing mandatory parameter 'graph'."));
78+
}
79+
return this.worker.postMessage({
80+
cmd: 'layout',
81+
graph: graph,
82+
layoutOptions: layoutOptions,
83+
options: {
84+
logging: logging,
85+
measureExecutionTime: measureExecutionTime
86+
}
87+
});
88+
}
89+
}, {
90+
key: "knownLayoutAlgorithms",
91+
value: function knownLayoutAlgorithms() {
92+
return this.worker.postMessage({
93+
cmd: 'algorithms'
94+
});
95+
}
96+
}, {
97+
key: "knownLayoutOptions",
98+
value: function knownLayoutOptions() {
99+
return this.worker.postMessage({
100+
cmd: 'options'
101+
});
102+
}
103+
}, {
104+
key: "knownLayoutCategories",
105+
value: function knownLayoutCategories() {
106+
return this.worker.postMessage({
107+
cmd: 'categories'
108+
});
109+
}
110+
}, {
111+
key: "terminateWorker",
112+
value: function terminateWorker() {
113+
if (this.worker) this.worker.terminate();
114+
}
115+
}]);
116+
}();
117+
var PromisedWorker = /*#__PURE__*/function () {
118+
function PromisedWorker(worker) {
119+
var _this2 = this;
120+
_classCallCheck(this, PromisedWorker);
121+
if (worker === undefined) {
122+
throw new Error("Missing mandatory parameter 'worker'.");
123+
}
124+
this.resolvers = {};
125+
this.worker = worker;
126+
this.worker.onmessage = function (answer) {
127+
// why is this necessary?
128+
setTimeout(function () {
129+
_this2.receive(_this2, answer);
130+
}, 0);
131+
};
132+
}
133+
return _createClass(PromisedWorker, [{
134+
key: "postMessage",
135+
value: function postMessage(msg) {
136+
var id = this.id || 0;
137+
this.id = id + 1;
138+
msg.id = id;
139+
var self = this;
140+
return new Promise(function (resolve, reject) {
141+
// prepare the resolver
142+
self.resolvers[id] = function (err, res) {
143+
if (err) {
144+
self.convertGwtStyleError(err);
145+
reject(err);
146+
} else {
147+
resolve(res);
148+
}
149+
};
150+
// post the message
151+
self.worker.postMessage(msg);
152+
});
153+
}
154+
}, {
155+
key: "receive",
156+
value: function receive(self, answer) {
157+
var json = answer.data;
158+
var resolver = self.resolvers[json.id];
159+
if (resolver) {
160+
delete self.resolvers[json.id];
161+
if (json.error) {
162+
resolver(json.error);
163+
} else {
164+
resolver(null, json.data);
165+
}
166+
}
167+
}
168+
}, {
169+
key: "terminate",
170+
value: function terminate() {
171+
if (this.worker) {
172+
this.worker.terminate();
173+
}
174+
}
175+
}, {
176+
key: "convertGwtStyleError",
177+
value: function convertGwtStyleError(err) {
178+
if (!err) {
179+
return;
180+
}
181+
// Somewhat flatten the way GWT stores nested exception(s)
182+
var javaException = err['__java$exception'];
183+
if (javaException) {
184+
// Note that the property name of the nested exception is different
185+
// in the non-minified ('cause') and the minified (not deterministic) version.
186+
// Hence, the version below only works for the non-minified version.
187+
// However, as the minified stack trace is not of much use anyway, one
188+
// should switch the used version for debugging in such a case.
189+
if (javaException.cause && javaException.cause.backingJsObject) {
190+
err.cause = javaException.cause.backingJsObject;
191+
this.convertGwtStyleError(err.cause);
192+
}
193+
delete err['__java$exception'];
194+
}
195+
}
196+
}]);
197+
}();
198+
},{}],2:[function(require,module,exports){
199+
"use strict";
200+
201+
/*******************************************************************************
202+
* Copyright (c) 2021 Kiel University and others.
203+
* This program and the accompanying materials are made available under the
204+
* terms of the Eclipse Public License 2.0 which is available at
205+
* http://www.eclipse.org/legal/epl-2.0.
206+
*
207+
* SPDX-License-Identifier: EPL-2.0
208+
*******************************************************************************/
209+
var ELK = require('./elk-api.js')["default"];
210+
Object.defineProperty(module.exports, "__esModule", {
211+
value: true
212+
});
213+
module.exports = ELK;
214+
ELK["default"] = ELK;
215+
},{"./elk-api.js":1}]},{},[2])(2)
216+
});

lib/elk-worker.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type Worker = Worker

0 commit comments

Comments
 (0)