|
| 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 | +}); |
0 commit comments