Skip to content

Commit cd0dc6b

Browse files
committed
Added lib for 0.8.2
1 parent 99d76b5 commit cd0dc6b

9 files changed

+113685
-0
lines changed

lib/elk-api.d.ts

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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+
junctionPoints?: ElkPoint[]
54+
}
55+
56+
/**
57+
* @deprecated use ElkExtendedEdge instead
58+
*/
59+
export interface ElkPrimitiveEdge extends ElkEdge {
60+
source: string
61+
sourcePort?: string
62+
target: string
63+
targetPort?: string
64+
sourcePoint?: ElkPoint
65+
targetPoint?: ElkPoint
66+
bendPoints?: ElkPoint[]
67+
}
68+
69+
export interface ElkExtendedEdge extends ElkEdge {
70+
sources: string[]
71+
targets: string[]
72+
sections?: ElkEdgeSection[]
73+
}
74+
75+
export interface ElkEdgeSection extends ElkGraphElement {
76+
id: string
77+
startPoint: ElkPoint
78+
endPoint: ElkPoint
79+
bendPoints?: ElkPoint[]
80+
incomingShape?: string
81+
outgoingShape?: string
82+
incomingSections?: string[]
83+
outgoingSections?: string[]
84+
}
85+
86+
export interface ElkLayoutArguments {
87+
layoutOptions?: LayoutOptions
88+
logging?: boolean
89+
measureExecutionTime?: boolean
90+
}
91+
92+
export interface ElkCommonDescription {
93+
id?: string
94+
name?: string
95+
description?: string
96+
}
97+
98+
export interface ElkLayoutAlgorithmDescription extends ElkCommonDescription {
99+
category?: string
100+
knownOptions?: string[]
101+
supportedFeatures?: string[]
102+
}
103+
104+
export interface ElkLayoutOptionDescription extends ElkCommonDescription {
105+
group?: string
106+
type?: string
107+
targets?: string[]
108+
}
109+
110+
export interface ElkLayoutCategoryDescription extends ElkCommonDescription {
111+
knownLayouters?: string[]
112+
}
113+
114+
export interface ELK {
115+
layout(graph: ElkNode, args?: ElkLayoutArguments): Promise<ElkNode>;
116+
knownLayoutAlgorithms(): Promise<ElkLayoutAlgorithmDescription[]>
117+
knownLayoutOptions(): Promise<ElkLayoutOptionDescription[]>
118+
knownLayoutCategories(): Promise<ElkLayoutCategoryDescription[]>
119+
}
120+
121+
export interface ELKConstructorArguments {
122+
defaultLayoutOptions?: LayoutOptions
123+
algorithms?: string[]
124+
workerUrl?: string
125+
workerFactory?: (url?: string) => Worker
126+
}
127+
128+
declare const ElkConstructor: {
129+
new(args?: ELKConstructorArguments): ELK;
130+
};
131+
export default ElkConstructor;

lib/elk-api.js

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

lib/elk-worker.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type Worker = Worker

0 commit comments

Comments
 (0)