layout-base.js 115 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else if(typeof exports === 'object')
  7. exports["layoutBase"] = factory();
  8. else
  9. root["layoutBase"] = factory();
  10. })(this, function() {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // identity function for calling harmony imports with the correct context
  47. /******/ __webpack_require__.i = function(value) { return value; };
  48. /******/
  49. /******/ // define getter function for harmony exports
  50. /******/ __webpack_require__.d = function(exports, name, getter) {
  51. /******/ if(!__webpack_require__.o(exports, name)) {
  52. /******/ Object.defineProperty(exports, name, {
  53. /******/ configurable: false,
  54. /******/ enumerable: true,
  55. /******/ get: getter
  56. /******/ });
  57. /******/ }
  58. /******/ };
  59. /******/
  60. /******/ // getDefaultExport function for compatibility with non-harmony modules
  61. /******/ __webpack_require__.n = function(module) {
  62. /******/ var getter = module && module.__esModule ?
  63. /******/ function getDefault() { return module['default']; } :
  64. /******/ function getModuleExports() { return module; };
  65. /******/ __webpack_require__.d(getter, 'a', getter);
  66. /******/ return getter;
  67. /******/ };
  68. /******/
  69. /******/ // Object.prototype.hasOwnProperty.call
  70. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  71. /******/
  72. /******/ // __webpack_public_path__
  73. /******/ __webpack_require__.p = "";
  74. /******/
  75. /******/ // Load entry module and return exports
  76. /******/ return __webpack_require__(__webpack_require__.s = 26);
  77. /******/ })
  78. /************************************************************************/
  79. /******/ ([
  80. /* 0 */
  81. /***/ (function(module, exports, __webpack_require__) {
  82. "use strict";
  83. function LayoutConstants() {}
  84. /**
  85. * Layout Quality: 0:draft, 1:default, 2:proof
  86. */
  87. LayoutConstants.QUALITY = 1;
  88. /**
  89. * Default parameters
  90. */
  91. LayoutConstants.DEFAULT_CREATE_BENDS_AS_NEEDED = false;
  92. LayoutConstants.DEFAULT_INCREMENTAL = false;
  93. LayoutConstants.DEFAULT_ANIMATION_ON_LAYOUT = true;
  94. LayoutConstants.DEFAULT_ANIMATION_DURING_LAYOUT = false;
  95. LayoutConstants.DEFAULT_ANIMATION_PERIOD = 50;
  96. LayoutConstants.DEFAULT_UNIFORM_LEAF_NODE_SIZES = false;
  97. // -----------------------------------------------------------------------------
  98. // Section: General other constants
  99. // -----------------------------------------------------------------------------
  100. /*
  101. * Margins of a graph to be applied on bouding rectangle of its contents. We
  102. * assume margins on all four sides to be uniform.
  103. */
  104. LayoutConstants.DEFAULT_GRAPH_MARGIN = 15;
  105. /*
  106. * Whether to consider labels in node dimensions or not
  107. */
  108. LayoutConstants.NODE_DIMENSIONS_INCLUDE_LABELS = false;
  109. /*
  110. * Default dimension of a non-compound node.
  111. */
  112. LayoutConstants.SIMPLE_NODE_SIZE = 40;
  113. /*
  114. * Default dimension of a non-compound node.
  115. */
  116. LayoutConstants.SIMPLE_NODE_HALF_SIZE = LayoutConstants.SIMPLE_NODE_SIZE / 2;
  117. /*
  118. * Empty compound node size. When a compound node is empty, its both
  119. * dimensions should be of this value.
  120. */
  121. LayoutConstants.EMPTY_COMPOUND_NODE_SIZE = 40;
  122. /*
  123. * Minimum length that an edge should take during layout
  124. */
  125. LayoutConstants.MIN_EDGE_LENGTH = 1;
  126. /*
  127. * World boundaries that layout operates on
  128. */
  129. LayoutConstants.WORLD_BOUNDARY = 1000000;
  130. /*
  131. * World boundaries that random positioning can be performed with
  132. */
  133. LayoutConstants.INITIAL_WORLD_BOUNDARY = LayoutConstants.WORLD_BOUNDARY / 1000;
  134. /*
  135. * Coordinates of the world center
  136. */
  137. LayoutConstants.WORLD_CENTER_X = 1200;
  138. LayoutConstants.WORLD_CENTER_Y = 900;
  139. module.exports = LayoutConstants;
  140. /***/ }),
  141. /* 1 */
  142. /***/ (function(module, exports, __webpack_require__) {
  143. "use strict";
  144. var LGraphObject = __webpack_require__(2);
  145. var IGeometry = __webpack_require__(8);
  146. var IMath = __webpack_require__(9);
  147. function LEdge(source, target, vEdge) {
  148. LGraphObject.call(this, vEdge);
  149. this.isOverlapingSourceAndTarget = false;
  150. this.vGraphObject = vEdge;
  151. this.bendpoints = [];
  152. this.source = source;
  153. this.target = target;
  154. }
  155. LEdge.prototype = Object.create(LGraphObject.prototype);
  156. for (var prop in LGraphObject) {
  157. LEdge[prop] = LGraphObject[prop];
  158. }
  159. LEdge.prototype.getSource = function () {
  160. return this.source;
  161. };
  162. LEdge.prototype.getTarget = function () {
  163. return this.target;
  164. };
  165. LEdge.prototype.isInterGraph = function () {
  166. return this.isInterGraph;
  167. };
  168. LEdge.prototype.getLength = function () {
  169. return this.length;
  170. };
  171. LEdge.prototype.isOverlapingSourceAndTarget = function () {
  172. return this.isOverlapingSourceAndTarget;
  173. };
  174. LEdge.prototype.getBendpoints = function () {
  175. return this.bendpoints;
  176. };
  177. LEdge.prototype.getLca = function () {
  178. return this.lca;
  179. };
  180. LEdge.prototype.getSourceInLca = function () {
  181. return this.sourceInLca;
  182. };
  183. LEdge.prototype.getTargetInLca = function () {
  184. return this.targetInLca;
  185. };
  186. LEdge.prototype.getOtherEnd = function (node) {
  187. if (this.source === node) {
  188. return this.target;
  189. } else if (this.target === node) {
  190. return this.source;
  191. } else {
  192. throw "Node is not incident with this edge";
  193. }
  194. };
  195. LEdge.prototype.getOtherEndInGraph = function (node, graph) {
  196. var otherEnd = this.getOtherEnd(node);
  197. var root = graph.getGraphManager().getRoot();
  198. while (true) {
  199. if (otherEnd.getOwner() == graph) {
  200. return otherEnd;
  201. }
  202. if (otherEnd.getOwner() == root) {
  203. break;
  204. }
  205. otherEnd = otherEnd.getOwner().getParent();
  206. }
  207. return null;
  208. };
  209. LEdge.prototype.updateLength = function () {
  210. var clipPointCoordinates = new Array(4);
  211. this.isOverlapingSourceAndTarget = IGeometry.getIntersection(this.target.getRect(), this.source.getRect(), clipPointCoordinates);
  212. if (!this.isOverlapingSourceAndTarget) {
  213. this.lengthX = clipPointCoordinates[0] - clipPointCoordinates[2];
  214. this.lengthY = clipPointCoordinates[1] - clipPointCoordinates[3];
  215. if (Math.abs(this.lengthX) < 1.0) {
  216. this.lengthX = IMath.sign(this.lengthX);
  217. }
  218. if (Math.abs(this.lengthY) < 1.0) {
  219. this.lengthY = IMath.sign(this.lengthY);
  220. }
  221. this.length = Math.sqrt(this.lengthX * this.lengthX + this.lengthY * this.lengthY);
  222. }
  223. };
  224. LEdge.prototype.updateLengthSimple = function () {
  225. this.lengthX = this.target.getCenterX() - this.source.getCenterX();
  226. this.lengthY = this.target.getCenterY() - this.source.getCenterY();
  227. if (Math.abs(this.lengthX) < 1.0) {
  228. this.lengthX = IMath.sign(this.lengthX);
  229. }
  230. if (Math.abs(this.lengthY) < 1.0) {
  231. this.lengthY = IMath.sign(this.lengthY);
  232. }
  233. this.length = Math.sqrt(this.lengthX * this.lengthX + this.lengthY * this.lengthY);
  234. };
  235. module.exports = LEdge;
  236. /***/ }),
  237. /* 2 */
  238. /***/ (function(module, exports, __webpack_require__) {
  239. "use strict";
  240. function LGraphObject(vGraphObject) {
  241. this.vGraphObject = vGraphObject;
  242. }
  243. module.exports = LGraphObject;
  244. /***/ }),
  245. /* 3 */
  246. /***/ (function(module, exports, __webpack_require__) {
  247. "use strict";
  248. var LGraphObject = __webpack_require__(2);
  249. var Integer = __webpack_require__(10);
  250. var RectangleD = __webpack_require__(13);
  251. var LayoutConstants = __webpack_require__(0);
  252. var RandomSeed = __webpack_require__(16);
  253. var PointD = __webpack_require__(4);
  254. function LNode(gm, loc, size, vNode) {
  255. //Alternative constructor 1 : LNode(LGraphManager gm, Point loc, Dimension size, Object vNode)
  256. if (size == null && vNode == null) {
  257. vNode = loc;
  258. }
  259. LGraphObject.call(this, vNode);
  260. //Alternative constructor 2 : LNode(Layout layout, Object vNode)
  261. if (gm.graphManager != null) gm = gm.graphManager;
  262. this.estimatedSize = Integer.MIN_VALUE;
  263. this.inclusionTreeDepth = Integer.MAX_VALUE;
  264. this.vGraphObject = vNode;
  265. this.edges = [];
  266. this.graphManager = gm;
  267. if (size != null && loc != null) this.rect = new RectangleD(loc.x, loc.y, size.width, size.height);else this.rect = new RectangleD();
  268. }
  269. LNode.prototype = Object.create(LGraphObject.prototype);
  270. for (var prop in LGraphObject) {
  271. LNode[prop] = LGraphObject[prop];
  272. }
  273. LNode.prototype.getEdges = function () {
  274. return this.edges;
  275. };
  276. LNode.prototype.getChild = function () {
  277. return this.child;
  278. };
  279. LNode.prototype.getOwner = function () {
  280. // if (this.owner != null) {
  281. // if (!(this.owner == null || this.owner.getNodes().indexOf(this) > -1)) {
  282. // throw "assert failed";
  283. // }
  284. // }
  285. return this.owner;
  286. };
  287. LNode.prototype.getWidth = function () {
  288. return this.rect.width;
  289. };
  290. LNode.prototype.setWidth = function (width) {
  291. this.rect.width = width;
  292. };
  293. LNode.prototype.getHeight = function () {
  294. return this.rect.height;
  295. };
  296. LNode.prototype.setHeight = function (height) {
  297. this.rect.height = height;
  298. };
  299. LNode.prototype.getCenterX = function () {
  300. return this.rect.x + this.rect.width / 2;
  301. };
  302. LNode.prototype.getCenterY = function () {
  303. return this.rect.y + this.rect.height / 2;
  304. };
  305. LNode.prototype.getCenter = function () {
  306. return new PointD(this.rect.x + this.rect.width / 2, this.rect.y + this.rect.height / 2);
  307. };
  308. LNode.prototype.getLocation = function () {
  309. return new PointD(this.rect.x, this.rect.y);
  310. };
  311. LNode.prototype.getRect = function () {
  312. return this.rect;
  313. };
  314. LNode.prototype.getDiagonal = function () {
  315. return Math.sqrt(this.rect.width * this.rect.width + this.rect.height * this.rect.height);
  316. };
  317. /**
  318. * This method returns half the diagonal length of this node.
  319. */
  320. LNode.prototype.getHalfTheDiagonal = function () {
  321. return Math.sqrt(this.rect.height * this.rect.height + this.rect.width * this.rect.width) / 2;
  322. };
  323. LNode.prototype.setRect = function (upperLeft, dimension) {
  324. this.rect.x = upperLeft.x;
  325. this.rect.y = upperLeft.y;
  326. this.rect.width = dimension.width;
  327. this.rect.height = dimension.height;
  328. };
  329. LNode.prototype.setCenter = function (cx, cy) {
  330. this.rect.x = cx - this.rect.width / 2;
  331. this.rect.y = cy - this.rect.height / 2;
  332. };
  333. LNode.prototype.setLocation = function (x, y) {
  334. this.rect.x = x;
  335. this.rect.y = y;
  336. };
  337. LNode.prototype.moveBy = function (dx, dy) {
  338. this.rect.x += dx;
  339. this.rect.y += dy;
  340. };
  341. LNode.prototype.getEdgeListToNode = function (to) {
  342. var edgeList = [];
  343. var edge;
  344. var self = this;
  345. self.edges.forEach(function (edge) {
  346. if (edge.target == to) {
  347. if (edge.source != self) throw "Incorrect edge source!";
  348. edgeList.push(edge);
  349. }
  350. });
  351. return edgeList;
  352. };
  353. LNode.prototype.getEdgesBetween = function (other) {
  354. var edgeList = [];
  355. var edge;
  356. var self = this;
  357. self.edges.forEach(function (edge) {
  358. if (!(edge.source == self || edge.target == self)) throw "Incorrect edge source and/or target";
  359. if (edge.target == other || edge.source == other) {
  360. edgeList.push(edge);
  361. }
  362. });
  363. return edgeList;
  364. };
  365. LNode.prototype.getNeighborsList = function () {
  366. var neighbors = new Set();
  367. var self = this;
  368. self.edges.forEach(function (edge) {
  369. if (edge.source == self) {
  370. neighbors.add(edge.target);
  371. } else {
  372. if (edge.target != self) {
  373. throw "Incorrect incidency!";
  374. }
  375. neighbors.add(edge.source);
  376. }
  377. });
  378. return neighbors;
  379. };
  380. LNode.prototype.withChildren = function () {
  381. var withNeighborsList = new Set();
  382. var childNode;
  383. var children;
  384. withNeighborsList.add(this);
  385. if (this.child != null) {
  386. var nodes = this.child.getNodes();
  387. for (var i = 0; i < nodes.length; i++) {
  388. childNode = nodes[i];
  389. children = childNode.withChildren();
  390. children.forEach(function (node) {
  391. withNeighborsList.add(node);
  392. });
  393. }
  394. }
  395. return withNeighborsList;
  396. };
  397. LNode.prototype.getNoOfChildren = function () {
  398. var noOfChildren = 0;
  399. var childNode;
  400. if (this.child == null) {
  401. noOfChildren = 1;
  402. } else {
  403. var nodes = this.child.getNodes();
  404. for (var i = 0; i < nodes.length; i++) {
  405. childNode = nodes[i];
  406. noOfChildren += childNode.getNoOfChildren();
  407. }
  408. }
  409. if (noOfChildren == 0) {
  410. noOfChildren = 1;
  411. }
  412. return noOfChildren;
  413. };
  414. LNode.prototype.getEstimatedSize = function () {
  415. if (this.estimatedSize == Integer.MIN_VALUE) {
  416. throw "assert failed";
  417. }
  418. return this.estimatedSize;
  419. };
  420. LNode.prototype.calcEstimatedSize = function () {
  421. if (this.child == null) {
  422. return this.estimatedSize = (this.rect.width + this.rect.height) / 2;
  423. } else {
  424. this.estimatedSize = this.child.calcEstimatedSize();
  425. this.rect.width = this.estimatedSize;
  426. this.rect.height = this.estimatedSize;
  427. return this.estimatedSize;
  428. }
  429. };
  430. LNode.prototype.scatter = function () {
  431. var randomCenterX;
  432. var randomCenterY;
  433. var minX = -LayoutConstants.INITIAL_WORLD_BOUNDARY;
  434. var maxX = LayoutConstants.INITIAL_WORLD_BOUNDARY;
  435. randomCenterX = LayoutConstants.WORLD_CENTER_X + RandomSeed.nextDouble() * (maxX - minX) + minX;
  436. var minY = -LayoutConstants.INITIAL_WORLD_BOUNDARY;
  437. var maxY = LayoutConstants.INITIAL_WORLD_BOUNDARY;
  438. randomCenterY = LayoutConstants.WORLD_CENTER_Y + RandomSeed.nextDouble() * (maxY - minY) + minY;
  439. this.rect.x = randomCenterX;
  440. this.rect.y = randomCenterY;
  441. };
  442. LNode.prototype.updateBounds = function () {
  443. if (this.getChild() == null) {
  444. throw "assert failed";
  445. }
  446. if (this.getChild().getNodes().length != 0) {
  447. // wrap the children nodes by re-arranging the boundaries
  448. var childGraph = this.getChild();
  449. childGraph.updateBounds(true);
  450. this.rect.x = childGraph.getLeft();
  451. this.rect.y = childGraph.getTop();
  452. this.setWidth(childGraph.getRight() - childGraph.getLeft());
  453. this.setHeight(childGraph.getBottom() - childGraph.getTop());
  454. // Update compound bounds considering its label properties
  455. if (LayoutConstants.NODE_DIMENSIONS_INCLUDE_LABELS) {
  456. var width = childGraph.getRight() - childGraph.getLeft();
  457. var height = childGraph.getBottom() - childGraph.getTop();
  458. if (this.labelWidth > width) {
  459. this.rect.x -= (this.labelWidth - width) / 2;
  460. this.setWidth(this.labelWidth);
  461. }
  462. if (this.labelHeight > height) {
  463. if (this.labelPos == "center") {
  464. this.rect.y -= (this.labelHeight - height) / 2;
  465. } else if (this.labelPos == "top") {
  466. this.rect.y -= this.labelHeight - height;
  467. }
  468. this.setHeight(this.labelHeight);
  469. }
  470. }
  471. }
  472. };
  473. LNode.prototype.getInclusionTreeDepth = function () {
  474. if (this.inclusionTreeDepth == Integer.MAX_VALUE) {
  475. throw "assert failed";
  476. }
  477. return this.inclusionTreeDepth;
  478. };
  479. LNode.prototype.transform = function (trans) {
  480. var left = this.rect.x;
  481. if (left > LayoutConstants.WORLD_BOUNDARY) {
  482. left = LayoutConstants.WORLD_BOUNDARY;
  483. } else if (left < -LayoutConstants.WORLD_BOUNDARY) {
  484. left = -LayoutConstants.WORLD_BOUNDARY;
  485. }
  486. var top = this.rect.y;
  487. if (top > LayoutConstants.WORLD_BOUNDARY) {
  488. top = LayoutConstants.WORLD_BOUNDARY;
  489. } else if (top < -LayoutConstants.WORLD_BOUNDARY) {
  490. top = -LayoutConstants.WORLD_BOUNDARY;
  491. }
  492. var leftTop = new PointD(left, top);
  493. var vLeftTop = trans.inverseTransformPoint(leftTop);
  494. this.setLocation(vLeftTop.x, vLeftTop.y);
  495. };
  496. LNode.prototype.getLeft = function () {
  497. return this.rect.x;
  498. };
  499. LNode.prototype.getRight = function () {
  500. return this.rect.x + this.rect.width;
  501. };
  502. LNode.prototype.getTop = function () {
  503. return this.rect.y;
  504. };
  505. LNode.prototype.getBottom = function () {
  506. return this.rect.y + this.rect.height;
  507. };
  508. LNode.prototype.getParent = function () {
  509. if (this.owner == null) {
  510. return null;
  511. }
  512. return this.owner.getParent();
  513. };
  514. module.exports = LNode;
  515. /***/ }),
  516. /* 4 */
  517. /***/ (function(module, exports, __webpack_require__) {
  518. "use strict";
  519. function PointD(x, y) {
  520. if (x == null && y == null) {
  521. this.x = 0;
  522. this.y = 0;
  523. } else {
  524. this.x = x;
  525. this.y = y;
  526. }
  527. }
  528. PointD.prototype.getX = function () {
  529. return this.x;
  530. };
  531. PointD.prototype.getY = function () {
  532. return this.y;
  533. };
  534. PointD.prototype.setX = function (x) {
  535. this.x = x;
  536. };
  537. PointD.prototype.setY = function (y) {
  538. this.y = y;
  539. };
  540. PointD.prototype.getDifference = function (pt) {
  541. return new DimensionD(this.x - pt.x, this.y - pt.y);
  542. };
  543. PointD.prototype.getCopy = function () {
  544. return new PointD(this.x, this.y);
  545. };
  546. PointD.prototype.translate = function (dim) {
  547. this.x += dim.width;
  548. this.y += dim.height;
  549. return this;
  550. };
  551. module.exports = PointD;
  552. /***/ }),
  553. /* 5 */
  554. /***/ (function(module, exports, __webpack_require__) {
  555. "use strict";
  556. var LGraphObject = __webpack_require__(2);
  557. var Integer = __webpack_require__(10);
  558. var LayoutConstants = __webpack_require__(0);
  559. var LGraphManager = __webpack_require__(6);
  560. var LNode = __webpack_require__(3);
  561. var LEdge = __webpack_require__(1);
  562. var RectangleD = __webpack_require__(13);
  563. var Point = __webpack_require__(12);
  564. var LinkedList = __webpack_require__(11);
  565. function LGraph(parent, obj2, vGraph) {
  566. LGraphObject.call(this, vGraph);
  567. this.estimatedSize = Integer.MIN_VALUE;
  568. this.margin = LayoutConstants.DEFAULT_GRAPH_MARGIN;
  569. this.edges = [];
  570. this.nodes = [];
  571. this.isConnected = false;
  572. this.parent = parent;
  573. if (obj2 != null && obj2 instanceof LGraphManager) {
  574. this.graphManager = obj2;
  575. } else if (obj2 != null && obj2 instanceof Layout) {
  576. this.graphManager = obj2.graphManager;
  577. }
  578. }
  579. LGraph.prototype = Object.create(LGraphObject.prototype);
  580. for (var prop in LGraphObject) {
  581. LGraph[prop] = LGraphObject[prop];
  582. }
  583. LGraph.prototype.getNodes = function () {
  584. return this.nodes;
  585. };
  586. LGraph.prototype.getEdges = function () {
  587. return this.edges;
  588. };
  589. LGraph.prototype.getGraphManager = function () {
  590. return this.graphManager;
  591. };
  592. LGraph.prototype.getParent = function () {
  593. return this.parent;
  594. };
  595. LGraph.prototype.getLeft = function () {
  596. return this.left;
  597. };
  598. LGraph.prototype.getRight = function () {
  599. return this.right;
  600. };
  601. LGraph.prototype.getTop = function () {
  602. return this.top;
  603. };
  604. LGraph.prototype.getBottom = function () {
  605. return this.bottom;
  606. };
  607. LGraph.prototype.isConnected = function () {
  608. return this.isConnected;
  609. };
  610. LGraph.prototype.add = function (obj1, sourceNode, targetNode) {
  611. if (sourceNode == null && targetNode == null) {
  612. var newNode = obj1;
  613. if (this.graphManager == null) {
  614. throw "Graph has no graph mgr!";
  615. }
  616. if (this.getNodes().indexOf(newNode) > -1) {
  617. throw "Node already in graph!";
  618. }
  619. newNode.owner = this;
  620. this.getNodes().push(newNode);
  621. return newNode;
  622. } else {
  623. var newEdge = obj1;
  624. if (!(this.getNodes().indexOf(sourceNode) > -1 && this.getNodes().indexOf(targetNode) > -1)) {
  625. throw "Source or target not in graph!";
  626. }
  627. if (!(sourceNode.owner == targetNode.owner && sourceNode.owner == this)) {
  628. throw "Both owners must be this graph!";
  629. }
  630. if (sourceNode.owner != targetNode.owner) {
  631. return null;
  632. }
  633. // set source and target
  634. newEdge.source = sourceNode;
  635. newEdge.target = targetNode;
  636. // set as intra-graph edge
  637. newEdge.isInterGraph = false;
  638. // add to graph edge list
  639. this.getEdges().push(newEdge);
  640. // add to incidency lists
  641. sourceNode.edges.push(newEdge);
  642. if (targetNode != sourceNode) {
  643. targetNode.edges.push(newEdge);
  644. }
  645. return newEdge;
  646. }
  647. };
  648. LGraph.prototype.remove = function (obj) {
  649. var node = obj;
  650. if (obj instanceof LNode) {
  651. if (node == null) {
  652. throw "Node is null!";
  653. }
  654. if (!(node.owner != null && node.owner == this)) {
  655. throw "Owner graph is invalid!";
  656. }
  657. if (this.graphManager == null) {
  658. throw "Owner graph manager is invalid!";
  659. }
  660. // remove incident edges first (make a copy to do it safely)
  661. var edgesToBeRemoved = node.edges.slice();
  662. var edge;
  663. var s = edgesToBeRemoved.length;
  664. for (var i = 0; i < s; i++) {
  665. edge = edgesToBeRemoved[i];
  666. if (edge.isInterGraph) {
  667. this.graphManager.remove(edge);
  668. } else {
  669. edge.source.owner.remove(edge);
  670. }
  671. }
  672. // now the node itself
  673. var index = this.nodes.indexOf(node);
  674. if (index == -1) {
  675. throw "Node not in owner node list!";
  676. }
  677. this.nodes.splice(index, 1);
  678. } else if (obj instanceof LEdge) {
  679. var edge = obj;
  680. if (edge == null) {
  681. throw "Edge is null!";
  682. }
  683. if (!(edge.source != null && edge.target != null)) {
  684. throw "Source and/or target is null!";
  685. }
  686. if (!(edge.source.owner != null && edge.target.owner != null && edge.source.owner == this && edge.target.owner == this)) {
  687. throw "Source and/or target owner is invalid!";
  688. }
  689. var sourceIndex = edge.source.edges.indexOf(edge);
  690. var targetIndex = edge.target.edges.indexOf(edge);
  691. if (!(sourceIndex > -1 && targetIndex > -1)) {
  692. throw "Source and/or target doesn't know this edge!";
  693. }
  694. edge.source.edges.splice(sourceIndex, 1);
  695. if (edge.target != edge.source) {
  696. edge.target.edges.splice(targetIndex, 1);
  697. }
  698. var index = edge.source.owner.getEdges().indexOf(edge);
  699. if (index == -1) {
  700. throw "Not in owner's edge list!";
  701. }
  702. edge.source.owner.getEdges().splice(index, 1);
  703. }
  704. };
  705. LGraph.prototype.updateLeftTop = function () {
  706. var top = Integer.MAX_VALUE;
  707. var left = Integer.MAX_VALUE;
  708. var nodeTop;
  709. var nodeLeft;
  710. var margin;
  711. var nodes = this.getNodes();
  712. var s = nodes.length;
  713. for (var i = 0; i < s; i++) {
  714. var lNode = nodes[i];
  715. nodeTop = lNode.getTop();
  716. nodeLeft = lNode.getLeft();
  717. if (top > nodeTop) {
  718. top = nodeTop;
  719. }
  720. if (left > nodeLeft) {
  721. left = nodeLeft;
  722. }
  723. }
  724. // Do we have any nodes in this graph?
  725. if (top == Integer.MAX_VALUE) {
  726. return null;
  727. }
  728. if (nodes[0].getParent().paddingLeft != undefined) {
  729. margin = nodes[0].getParent().paddingLeft;
  730. } else {
  731. margin = this.margin;
  732. }
  733. this.left = left - margin;
  734. this.top = top - margin;
  735. // Apply the margins and return the result
  736. return new Point(this.left, this.top);
  737. };
  738. LGraph.prototype.updateBounds = function (recursive) {
  739. // calculate bounds
  740. var left = Integer.MAX_VALUE;
  741. var right = -Integer.MAX_VALUE;
  742. var top = Integer.MAX_VALUE;
  743. var bottom = -Integer.MAX_VALUE;
  744. var nodeLeft;
  745. var nodeRight;
  746. var nodeTop;
  747. var nodeBottom;
  748. var margin;
  749. var nodes = this.nodes;
  750. var s = nodes.length;
  751. for (var i = 0; i < s; i++) {
  752. var lNode = nodes[i];
  753. if (recursive && lNode.child != null) {
  754. lNode.updateBounds();
  755. }
  756. nodeLeft = lNode.getLeft();
  757. nodeRight = lNode.getRight();
  758. nodeTop = lNode.getTop();
  759. nodeBottom = lNode.getBottom();
  760. if (left > nodeLeft) {
  761. left = nodeLeft;
  762. }
  763. if (right < nodeRight) {
  764. right = nodeRight;
  765. }
  766. if (top > nodeTop) {
  767. top = nodeTop;
  768. }
  769. if (bottom < nodeBottom) {
  770. bottom = nodeBottom;
  771. }
  772. }
  773. var boundingRect = new RectangleD(left, top, right - left, bottom - top);
  774. if (left == Integer.MAX_VALUE) {
  775. this.left = this.parent.getLeft();
  776. this.right = this.parent.getRight();
  777. this.top = this.parent.getTop();
  778. this.bottom = this.parent.getBottom();
  779. }
  780. if (nodes[0].getParent().paddingLeft != undefined) {
  781. margin = nodes[0].getParent().paddingLeft;
  782. } else {
  783. margin = this.margin;
  784. }
  785. this.left = boundingRect.x - margin;
  786. this.right = boundingRect.x + boundingRect.width + margin;
  787. this.top = boundingRect.y - margin;
  788. this.bottom = boundingRect.y + boundingRect.height + margin;
  789. };
  790. LGraph.calculateBounds = function (nodes) {
  791. var left = Integer.MAX_VALUE;
  792. var right = -Integer.MAX_VALUE;
  793. var top = Integer.MAX_VALUE;
  794. var bottom = -Integer.MAX_VALUE;
  795. var nodeLeft;
  796. var nodeRight;
  797. var nodeTop;
  798. var nodeBottom;
  799. var s = nodes.length;
  800. for (var i = 0; i < s; i++) {
  801. var lNode = nodes[i];
  802. nodeLeft = lNode.getLeft();
  803. nodeRight = lNode.getRight();
  804. nodeTop = lNode.getTop();
  805. nodeBottom = lNode.getBottom();
  806. if (left > nodeLeft) {
  807. left = nodeLeft;
  808. }
  809. if (right < nodeRight) {
  810. right = nodeRight;
  811. }
  812. if (top > nodeTop) {
  813. top = nodeTop;
  814. }
  815. if (bottom < nodeBottom) {
  816. bottom = nodeBottom;
  817. }
  818. }
  819. var boundingRect = new RectangleD(left, top, right - left, bottom - top);
  820. return boundingRect;
  821. };
  822. LGraph.prototype.getInclusionTreeDepth = function () {
  823. if (this == this.graphManager.getRoot()) {
  824. return 1;
  825. } else {
  826. return this.parent.getInclusionTreeDepth();
  827. }
  828. };
  829. LGraph.prototype.getEstimatedSize = function () {
  830. if (this.estimatedSize == Integer.MIN_VALUE) {
  831. throw "assert failed";
  832. }
  833. return this.estimatedSize;
  834. };
  835. LGraph.prototype.calcEstimatedSize = function () {
  836. var size = 0;
  837. var nodes = this.nodes;
  838. var s = nodes.length;
  839. for (var i = 0; i < s; i++) {
  840. var lNode = nodes[i];
  841. size += lNode.calcEstimatedSize();
  842. }
  843. if (size == 0) {
  844. this.estimatedSize = LayoutConstants.EMPTY_COMPOUND_NODE_SIZE;
  845. } else {
  846. this.estimatedSize = size / Math.sqrt(this.nodes.length);
  847. }
  848. return this.estimatedSize;
  849. };
  850. LGraph.prototype.updateConnected = function () {
  851. var self = this;
  852. if (this.nodes.length == 0) {
  853. this.isConnected = true;
  854. return;
  855. }
  856. var queue = new LinkedList();
  857. var visited = new Set();
  858. var currentNode = this.nodes[0];
  859. var neighborEdges;
  860. var currentNeighbor;
  861. var childrenOfNode = currentNode.withChildren();
  862. childrenOfNode.forEach(function (node) {
  863. queue.push(node);
  864. visited.add(node);
  865. });
  866. while (queue.length !== 0) {
  867. currentNode = queue.shift();
  868. // Traverse all neighbors of this node
  869. neighborEdges = currentNode.getEdges();
  870. var size = neighborEdges.length;
  871. for (var i = 0; i < size; i++) {
  872. var neighborEdge = neighborEdges[i];
  873. currentNeighbor = neighborEdge.getOtherEndInGraph(currentNode, this);
  874. // Add unvisited neighbors to the list to visit
  875. if (currentNeighbor != null && !visited.has(currentNeighbor)) {
  876. var childrenOfNeighbor = currentNeighbor.withChildren();
  877. childrenOfNeighbor.forEach(function (node) {
  878. queue.push(node);
  879. visited.add(node);
  880. });
  881. }
  882. }
  883. }
  884. this.isConnected = false;
  885. if (visited.size >= this.nodes.length) {
  886. var noOfVisitedInThisGraph = 0;
  887. visited.forEach(function (visitedNode) {
  888. if (visitedNode.owner == self) {
  889. noOfVisitedInThisGraph++;
  890. }
  891. });
  892. if (noOfVisitedInThisGraph == this.nodes.length) {
  893. this.isConnected = true;
  894. }
  895. }
  896. };
  897. module.exports = LGraph;
  898. /***/ }),
  899. /* 6 */
  900. /***/ (function(module, exports, __webpack_require__) {
  901. "use strict";
  902. var LGraph;
  903. var LEdge = __webpack_require__(1);
  904. function LGraphManager(layout) {
  905. LGraph = __webpack_require__(5); // It may be better to initilize this out of this function but it gives an error (Right-hand side of 'instanceof' is not callable) now.
  906. this.layout = layout;
  907. this.graphs = [];
  908. this.edges = [];
  909. }
  910. LGraphManager.prototype.addRoot = function () {
  911. var ngraph = this.layout.newGraph();
  912. var nnode = this.layout.newNode(null);
  913. var root = this.add(ngraph, nnode);
  914. this.setRootGraph(root);
  915. return this.rootGraph;
  916. };
  917. LGraphManager.prototype.add = function (newGraph, parentNode, newEdge, sourceNode, targetNode) {
  918. //there are just 2 parameters are passed then it adds an LGraph else it adds an LEdge
  919. if (newEdge == null && sourceNode == null && targetNode == null) {
  920. if (newGraph == null) {
  921. throw "Graph is null!";
  922. }
  923. if (parentNode == null) {
  924. throw "Parent node is null!";
  925. }
  926. if (this.graphs.indexOf(newGraph) > -1) {
  927. throw "Graph already in this graph mgr!";
  928. }
  929. this.graphs.push(newGraph);
  930. if (newGraph.parent != null) {
  931. throw "Already has a parent!";
  932. }
  933. if (parentNode.child != null) {
  934. throw "Already has a child!";
  935. }
  936. newGraph.parent = parentNode;
  937. parentNode.child = newGraph;
  938. return newGraph;
  939. } else {
  940. //change the order of the parameters
  941. targetNode = newEdge;
  942. sourceNode = parentNode;
  943. newEdge = newGraph;
  944. var sourceGraph = sourceNode.getOwner();
  945. var targetGraph = targetNode.getOwner();
  946. if (!(sourceGraph != null && sourceGraph.getGraphManager() == this)) {
  947. throw "Source not in this graph mgr!";
  948. }
  949. if (!(targetGraph != null && targetGraph.getGraphManager() == this)) {
  950. throw "Target not in this graph mgr!";
  951. }
  952. if (sourceGraph == targetGraph) {
  953. newEdge.isInterGraph = false;
  954. return sourceGraph.add(newEdge, sourceNode, targetNode);
  955. } else {
  956. newEdge.isInterGraph = true;
  957. // set source and target
  958. newEdge.source = sourceNode;
  959. newEdge.target = targetNode;
  960. // add edge to inter-graph edge list
  961. if (this.edges.indexOf(newEdge) > -1) {
  962. throw "Edge already in inter-graph edge list!";
  963. }
  964. this.edges.push(newEdge);
  965. // add edge to source and target incidency lists
  966. if (!(newEdge.source != null && newEdge.target != null)) {
  967. throw "Edge source and/or target is null!";
  968. }
  969. if (!(newEdge.source.edges.indexOf(newEdge) == -1 && newEdge.target.edges.indexOf(newEdge) == -1)) {
  970. throw "Edge already in source and/or target incidency list!";
  971. }
  972. newEdge.source.edges.push(newEdge);
  973. newEdge.target.edges.push(newEdge);
  974. return newEdge;
  975. }
  976. }
  977. };
  978. LGraphManager.prototype.remove = function (lObj) {
  979. if (lObj instanceof LGraph) {
  980. var graph = lObj;
  981. if (graph.getGraphManager() != this) {
  982. throw "Graph not in this graph mgr";
  983. }
  984. if (!(graph == this.rootGraph || graph.parent != null && graph.parent.graphManager == this)) {
  985. throw "Invalid parent node!";
  986. }
  987. // first the edges (make a copy to do it safely)
  988. var edgesToBeRemoved = [];
  989. edgesToBeRemoved = edgesToBeRemoved.concat(graph.getEdges());
  990. var edge;
  991. var s = edgesToBeRemoved.length;
  992. for (var i = 0; i < s; i++) {
  993. edge = edgesToBeRemoved[i];
  994. graph.remove(edge);
  995. }
  996. // then the nodes (make a copy to do it safely)
  997. var nodesToBeRemoved = [];
  998. nodesToBeRemoved = nodesToBeRemoved.concat(graph.getNodes());
  999. var node;
  1000. s = nodesToBeRemoved.length;
  1001. for (var i = 0; i < s; i++) {
  1002. node = nodesToBeRemoved[i];
  1003. graph.remove(node);
  1004. }
  1005. // check if graph is the root
  1006. if (graph == this.rootGraph) {
  1007. this.setRootGraph(null);
  1008. }
  1009. // now remove the graph itself
  1010. var index = this.graphs.indexOf(graph);
  1011. this.graphs.splice(index, 1);
  1012. // also reset the parent of the graph
  1013. graph.parent = null;
  1014. } else if (lObj instanceof LEdge) {
  1015. edge = lObj;
  1016. if (edge == null) {
  1017. throw "Edge is null!";
  1018. }
  1019. if (!edge.isInterGraph) {
  1020. throw "Not an inter-graph edge!";
  1021. }
  1022. if (!(edge.source != null && edge.target != null)) {
  1023. throw "Source and/or target is null!";
  1024. }
  1025. // remove edge from source and target nodes' incidency lists
  1026. if (!(edge.source.edges.indexOf(edge) != -1 && edge.target.edges.indexOf(edge) != -1)) {
  1027. throw "Source and/or target doesn't know this edge!";
  1028. }
  1029. var index = edge.source.edges.indexOf(edge);
  1030. edge.source.edges.splice(index, 1);
  1031. index = edge.target.edges.indexOf(edge);
  1032. edge.target.edges.splice(index, 1);
  1033. // remove edge from owner graph manager's inter-graph edge list
  1034. if (!(edge.source.owner != null && edge.source.owner.getGraphManager() != null)) {
  1035. throw "Edge owner graph or owner graph manager is null!";
  1036. }
  1037. if (edge.source.owner.getGraphManager().edges.indexOf(edge) == -1) {
  1038. throw "Not in owner graph manager's edge list!";
  1039. }
  1040. var index = edge.source.owner.getGraphManager().edges.indexOf(edge);
  1041. edge.source.owner.getGraphManager().edges.splice(index, 1);
  1042. }
  1043. };
  1044. LGraphManager.prototype.updateBounds = function () {
  1045. this.rootGraph.updateBounds(true);
  1046. };
  1047. LGraphManager.prototype.getGraphs = function () {
  1048. return this.graphs;
  1049. };
  1050. LGraphManager.prototype.getAllNodes = function () {
  1051. if (this.allNodes == null) {
  1052. var nodeList = [];
  1053. var graphs = this.getGraphs();
  1054. var s = graphs.length;
  1055. for (var i = 0; i < s; i++) {
  1056. nodeList = nodeList.concat(graphs[i].getNodes());
  1057. }
  1058. this.allNodes = nodeList;
  1059. }
  1060. return this.allNodes;
  1061. };
  1062. LGraphManager.prototype.resetAllNodes = function () {
  1063. this.allNodes = null;
  1064. };
  1065. LGraphManager.prototype.resetAllEdges = function () {
  1066. this.allEdges = null;
  1067. };
  1068. LGraphManager.prototype.resetAllNodesToApplyGravitation = function () {
  1069. this.allNodesToApplyGravitation = null;
  1070. };
  1071. LGraphManager.prototype.getAllEdges = function () {
  1072. if (this.allEdges == null) {
  1073. var edgeList = [];
  1074. var graphs = this.getGraphs();
  1075. var s = graphs.length;
  1076. for (var i = 0; i < graphs.length; i++) {
  1077. edgeList = edgeList.concat(graphs[i].getEdges());
  1078. }
  1079. edgeList = edgeList.concat(this.edges);
  1080. this.allEdges = edgeList;
  1081. }
  1082. return this.allEdges;
  1083. };
  1084. LGraphManager.prototype.getAllNodesToApplyGravitation = function () {
  1085. return this.allNodesToApplyGravitation;
  1086. };
  1087. LGraphManager.prototype.setAllNodesToApplyGravitation = function (nodeList) {
  1088. if (this.allNodesToApplyGravitation != null) {
  1089. throw "assert failed";
  1090. }
  1091. this.allNodesToApplyGravitation = nodeList;
  1092. };
  1093. LGraphManager.prototype.getRoot = function () {
  1094. return this.rootGraph;
  1095. };
  1096. LGraphManager.prototype.setRootGraph = function (graph) {
  1097. if (graph.getGraphManager() != this) {
  1098. throw "Root not in this graph mgr!";
  1099. }
  1100. this.rootGraph = graph;
  1101. // root graph must have a root node associated with it for convenience
  1102. if (graph.parent == null) {
  1103. graph.parent = this.layout.newNode("Root node");
  1104. }
  1105. };
  1106. LGraphManager.prototype.getLayout = function () {
  1107. return this.layout;
  1108. };
  1109. LGraphManager.prototype.isOneAncestorOfOther = function (firstNode, secondNode) {
  1110. if (!(firstNode != null && secondNode != null)) {
  1111. throw "assert failed";
  1112. }
  1113. if (firstNode == secondNode) {
  1114. return true;
  1115. }
  1116. // Is second node an ancestor of the first one?
  1117. var ownerGraph = firstNode.getOwner();
  1118. var parentNode;
  1119. do {
  1120. parentNode = ownerGraph.getParent();
  1121. if (parentNode == null) {
  1122. break;
  1123. }
  1124. if (parentNode == secondNode) {
  1125. return true;
  1126. }
  1127. ownerGraph = parentNode.getOwner();
  1128. if (ownerGraph == null) {
  1129. break;
  1130. }
  1131. } while (true);
  1132. // Is first node an ancestor of the second one?
  1133. ownerGraph = secondNode.getOwner();
  1134. do {
  1135. parentNode = ownerGraph.getParent();
  1136. if (parentNode == null) {
  1137. break;
  1138. }
  1139. if (parentNode == firstNode) {
  1140. return true;
  1141. }
  1142. ownerGraph = parentNode.getOwner();
  1143. if (ownerGraph == null) {
  1144. break;
  1145. }
  1146. } while (true);
  1147. return false;
  1148. };
  1149. LGraphManager.prototype.calcLowestCommonAncestors = function () {
  1150. var edge;
  1151. var sourceNode;
  1152. var targetNode;
  1153. var sourceAncestorGraph;
  1154. var targetAncestorGraph;
  1155. var edges = this.getAllEdges();
  1156. var s = edges.length;
  1157. for (var i = 0; i < s; i++) {
  1158. edge = edges[i];
  1159. sourceNode = edge.source;
  1160. targetNode = edge.target;
  1161. edge.lca = null;
  1162. edge.sourceInLca = sourceNode;
  1163. edge.targetInLca = targetNode;
  1164. if (sourceNode == targetNode) {
  1165. edge.lca = sourceNode.getOwner();
  1166. continue;
  1167. }
  1168. sourceAncestorGraph = sourceNode.getOwner();
  1169. while (edge.lca == null) {
  1170. edge.targetInLca = targetNode;
  1171. targetAncestorGraph = targetNode.getOwner();
  1172. while (edge.lca == null) {
  1173. if (targetAncestorGraph == sourceAncestorGraph) {
  1174. edge.lca = targetAncestorGraph;
  1175. break;
  1176. }
  1177. if (targetAncestorGraph == this.rootGraph) {
  1178. break;
  1179. }
  1180. if (edge.lca != null) {
  1181. throw "assert failed";
  1182. }
  1183. edge.targetInLca = targetAncestorGraph.getParent();
  1184. targetAncestorGraph = edge.targetInLca.getOwner();
  1185. }
  1186. if (sourceAncestorGraph == this.rootGraph) {
  1187. break;
  1188. }
  1189. if (edge.lca == null) {
  1190. edge.sourceInLca = sourceAncestorGraph.getParent();
  1191. sourceAncestorGraph = edge.sourceInLca.getOwner();
  1192. }
  1193. }
  1194. if (edge.lca == null) {
  1195. throw "assert failed";
  1196. }
  1197. }
  1198. };
  1199. LGraphManager.prototype.calcLowestCommonAncestor = function (firstNode, secondNode) {
  1200. if (firstNode == secondNode) {
  1201. return firstNode.getOwner();
  1202. }
  1203. var firstOwnerGraph = firstNode.getOwner();
  1204. do {
  1205. if (firstOwnerGraph == null) {
  1206. break;
  1207. }
  1208. var secondOwnerGraph = secondNode.getOwner();
  1209. do {
  1210. if (secondOwnerGraph == null) {
  1211. break;
  1212. }
  1213. if (secondOwnerGraph == firstOwnerGraph) {
  1214. return secondOwnerGraph;
  1215. }
  1216. secondOwnerGraph = secondOwnerGraph.getParent().getOwner();
  1217. } while (true);
  1218. firstOwnerGraph = firstOwnerGraph.getParent().getOwner();
  1219. } while (true);
  1220. return firstOwnerGraph;
  1221. };
  1222. LGraphManager.prototype.calcInclusionTreeDepths = function (graph, depth) {
  1223. if (graph == null && depth == null) {
  1224. graph = this.rootGraph;
  1225. depth = 1;
  1226. }
  1227. var node;
  1228. var nodes = graph.getNodes();
  1229. var s = nodes.length;
  1230. for (var i = 0; i < s; i++) {
  1231. node = nodes[i];
  1232. node.inclusionTreeDepth = depth;
  1233. if (node.child != null) {
  1234. this.calcInclusionTreeDepths(node.child, depth + 1);
  1235. }
  1236. }
  1237. };
  1238. LGraphManager.prototype.includesInvalidEdge = function () {
  1239. var edge;
  1240. var s = this.edges.length;
  1241. for (var i = 0; i < s; i++) {
  1242. edge = this.edges[i];
  1243. if (this.isOneAncestorOfOther(edge.source, edge.target)) {
  1244. return true;
  1245. }
  1246. }
  1247. return false;
  1248. };
  1249. module.exports = LGraphManager;
  1250. /***/ }),
  1251. /* 7 */
  1252. /***/ (function(module, exports, __webpack_require__) {
  1253. "use strict";
  1254. var LayoutConstants = __webpack_require__(0);
  1255. function FDLayoutConstants() {}
  1256. //FDLayoutConstants inherits static props in LayoutConstants
  1257. for (var prop in LayoutConstants) {
  1258. FDLayoutConstants[prop] = LayoutConstants[prop];
  1259. }
  1260. FDLayoutConstants.MAX_ITERATIONS = 2500;
  1261. FDLayoutConstants.DEFAULT_EDGE_LENGTH = 50;
  1262. FDLayoutConstants.DEFAULT_SPRING_STRENGTH = 0.45;
  1263. FDLayoutConstants.DEFAULT_REPULSION_STRENGTH = 4500.0;
  1264. FDLayoutConstants.DEFAULT_GRAVITY_STRENGTH = 0.4;
  1265. FDLayoutConstants.DEFAULT_COMPOUND_GRAVITY_STRENGTH = 1.0;
  1266. FDLayoutConstants.DEFAULT_GRAVITY_RANGE_FACTOR = 3.8;
  1267. FDLayoutConstants.DEFAULT_COMPOUND_GRAVITY_RANGE_FACTOR = 1.5;
  1268. FDLayoutConstants.DEFAULT_USE_SMART_IDEAL_EDGE_LENGTH_CALCULATION = true;
  1269. FDLayoutConstants.DEFAULT_USE_SMART_REPULSION_RANGE_CALCULATION = true;
  1270. FDLayoutConstants.DEFAULT_COOLING_FACTOR_INCREMENTAL = 0.3;
  1271. FDLayoutConstants.COOLING_ADAPTATION_FACTOR = 0.33;
  1272. FDLayoutConstants.ADAPTATION_LOWER_NODE_LIMIT = 1000;
  1273. FDLayoutConstants.ADAPTATION_UPPER_NODE_LIMIT = 5000;
  1274. FDLayoutConstants.MAX_NODE_DISPLACEMENT_INCREMENTAL = 100.0;
  1275. FDLayoutConstants.MAX_NODE_DISPLACEMENT = FDLayoutConstants.MAX_NODE_DISPLACEMENT_INCREMENTAL * 3;
  1276. FDLayoutConstants.MIN_REPULSION_DIST = FDLayoutConstants.DEFAULT_EDGE_LENGTH / 10.0;
  1277. FDLayoutConstants.CONVERGENCE_CHECK_PERIOD = 100;
  1278. FDLayoutConstants.PER_LEVEL_IDEAL_EDGE_LENGTH_FACTOR = 0.1;
  1279. FDLayoutConstants.MIN_EDGE_LENGTH = 1;
  1280. FDLayoutConstants.GRID_CALCULATION_CHECK_PERIOD = 10;
  1281. module.exports = FDLayoutConstants;
  1282. /***/ }),
  1283. /* 8 */
  1284. /***/ (function(module, exports, __webpack_require__) {
  1285. "use strict";
  1286. /**
  1287. * This class maintains a list of static geometry related utility methods.
  1288. *
  1289. *
  1290. * Copyright: i-Vis Research Group, Bilkent University, 2007 - present
  1291. */
  1292. var Point = __webpack_require__(12);
  1293. function IGeometry() {}
  1294. /**
  1295. * This method calculates *half* the amount in x and y directions of the two
  1296. * input rectangles needed to separate them keeping their respective
  1297. * positioning, and returns the result in the input array. An input
  1298. * separation buffer added to the amount in both directions. We assume that
  1299. * the two rectangles do intersect.
  1300. */
  1301. IGeometry.calcSeparationAmount = function (rectA, rectB, overlapAmount, separationBuffer) {
  1302. if (!rectA.intersects(rectB)) {
  1303. throw "assert failed";
  1304. }
  1305. var directions = new Array(2);
  1306. this.decideDirectionsForOverlappingNodes(rectA, rectB, directions);
  1307. overlapAmount[0] = Math.min(rectA.getRight(), rectB.getRight()) - Math.max(rectA.x, rectB.x);
  1308. overlapAmount[1] = Math.min(rectA.getBottom(), rectB.getBottom()) - Math.max(rectA.y, rectB.y);
  1309. // update the overlapping amounts for the following cases:
  1310. if (rectA.getX() <= rectB.getX() && rectA.getRight() >= rectB.getRight()) {
  1311. /* Case x.1:
  1312. *
  1313. * rectA
  1314. * | |
  1315. * | _________ |
  1316. * | | | |
  1317. * |________|_______|______|
  1318. * | |
  1319. * | |
  1320. * rectB
  1321. */
  1322. overlapAmount[0] += Math.min(rectB.getX() - rectA.getX(), rectA.getRight() - rectB.getRight());
  1323. } else if (rectB.getX() <= rectA.getX() && rectB.getRight() >= rectA.getRight()) {
  1324. /* Case x.2:
  1325. *
  1326. * rectB
  1327. * | |
  1328. * | _________ |
  1329. * | | | |
  1330. * |________|_______|______|
  1331. * | |
  1332. * | |
  1333. * rectA
  1334. */
  1335. overlapAmount[0] += Math.min(rectA.getX() - rectB.getX(), rectB.getRight() - rectA.getRight());
  1336. }
  1337. if (rectA.getY() <= rectB.getY() && rectA.getBottom() >= rectB.getBottom()) {
  1338. /* Case y.1:
  1339. * ________ rectA
  1340. * |
  1341. * |
  1342. * ______|____ rectB
  1343. * | |
  1344. * | |
  1345. * ______|____|
  1346. * |
  1347. * |
  1348. * |________
  1349. *
  1350. */
  1351. overlapAmount[1] += Math.min(rectB.getY() - rectA.getY(), rectA.getBottom() - rectB.getBottom());
  1352. } else if (rectB.getY() <= rectA.getY() && rectB.getBottom() >= rectA.getBottom()) {
  1353. /* Case y.2:
  1354. * ________ rectB
  1355. * |
  1356. * |
  1357. * ______|____ rectA
  1358. * | |
  1359. * | |
  1360. * ______|____|
  1361. * |
  1362. * |
  1363. * |________
  1364. *
  1365. */
  1366. overlapAmount[1] += Math.min(rectA.getY() - rectB.getY(), rectB.getBottom() - rectA.getBottom());
  1367. }
  1368. // find slope of the line passes two centers
  1369. var slope = Math.abs((rectB.getCenterY() - rectA.getCenterY()) / (rectB.getCenterX() - rectA.getCenterX()));
  1370. // if centers are overlapped
  1371. if (rectB.getCenterY() === rectA.getCenterY() && rectB.getCenterX() === rectA.getCenterX()) {
  1372. // assume the slope is 1 (45 degree)
  1373. slope = 1.0;
  1374. }
  1375. var moveByY = slope * overlapAmount[0];
  1376. var moveByX = overlapAmount[1] / slope;
  1377. if (overlapAmount[0] < moveByX) {
  1378. moveByX = overlapAmount[0];
  1379. } else {
  1380. moveByY = overlapAmount[1];
  1381. }
  1382. // return half the amount so that if each rectangle is moved by these
  1383. // amounts in opposite directions, overlap will be resolved
  1384. overlapAmount[0] = -1 * directions[0] * (moveByX / 2 + separationBuffer);
  1385. overlapAmount[1] = -1 * directions[1] * (moveByY / 2 + separationBuffer);
  1386. };
  1387. /**
  1388. * This method decides the separation direction of overlapping nodes
  1389. *
  1390. * if directions[0] = -1, then rectA goes left
  1391. * if directions[0] = 1, then rectA goes right
  1392. * if directions[1] = -1, then rectA goes up
  1393. * if directions[1] = 1, then rectA goes down
  1394. */
  1395. IGeometry.decideDirectionsForOverlappingNodes = function (rectA, rectB, directions) {
  1396. if (rectA.getCenterX() < rectB.getCenterX()) {
  1397. directions[0] = -1;
  1398. } else {
  1399. directions[0] = 1;
  1400. }
  1401. if (rectA.getCenterY() < rectB.getCenterY()) {
  1402. directions[1] = -1;
  1403. } else {
  1404. directions[1] = 1;
  1405. }
  1406. };
  1407. /**
  1408. * This method calculates the intersection (clipping) points of the two
  1409. * input rectangles with line segment defined by the centers of these two
  1410. * rectangles. The clipping points are saved in the input double array and
  1411. * whether or not the two rectangles overlap is returned.
  1412. */
  1413. IGeometry.getIntersection2 = function (rectA, rectB, result) {
  1414. //result[0-1] will contain clipPoint of rectA, result[2-3] will contain clipPoint of rectB
  1415. var p1x = rectA.getCenterX();
  1416. var p1y = rectA.getCenterY();
  1417. var p2x = rectB.getCenterX();
  1418. var p2y = rectB.getCenterY();
  1419. //if two rectangles intersect, then clipping points are centers
  1420. if (rectA.intersects(rectB)) {
  1421. result[0] = p1x;
  1422. result[1] = p1y;
  1423. result[2] = p2x;
  1424. result[3] = p2y;
  1425. return true;
  1426. }
  1427. //variables for rectA
  1428. var topLeftAx = rectA.getX();
  1429. var topLeftAy = rectA.getY();
  1430. var topRightAx = rectA.getRight();
  1431. var bottomLeftAx = rectA.getX();
  1432. var bottomLeftAy = rectA.getBottom();
  1433. var bottomRightAx = rectA.getRight();
  1434. var halfWidthA = rectA.getWidthHalf();
  1435. var halfHeightA = rectA.getHeightHalf();
  1436. //variables for rectB
  1437. var topLeftBx = rectB.getX();
  1438. var topLeftBy = rectB.getY();
  1439. var topRightBx = rectB.getRight();
  1440. var bottomLeftBx = rectB.getX();
  1441. var bottomLeftBy = rectB.getBottom();
  1442. var bottomRightBx = rectB.getRight();
  1443. var halfWidthB = rectB.getWidthHalf();
  1444. var halfHeightB = rectB.getHeightHalf();
  1445. //flag whether clipping points are found
  1446. var clipPointAFound = false;
  1447. var clipPointBFound = false;
  1448. // line is vertical
  1449. if (p1x === p2x) {
  1450. if (p1y > p2y) {
  1451. result[0] = p1x;
  1452. result[1] = topLeftAy;
  1453. result[2] = p2x;
  1454. result[3] = bottomLeftBy;
  1455. return false;
  1456. } else if (p1y < p2y) {
  1457. result[0] = p1x;
  1458. result[1] = bottomLeftAy;
  1459. result[2] = p2x;
  1460. result[3] = topLeftBy;
  1461. return false;
  1462. } else {
  1463. //not line, return null;
  1464. }
  1465. }
  1466. // line is horizontal
  1467. else if (p1y === p2y) {
  1468. if (p1x > p2x) {
  1469. result[0] = topLeftAx;
  1470. result[1] = p1y;
  1471. result[2] = topRightBx;
  1472. result[3] = p2y;
  1473. return false;
  1474. } else if (p1x < p2x) {
  1475. result[0] = topRightAx;
  1476. result[1] = p1y;
  1477. result[2] = topLeftBx;
  1478. result[3] = p2y;
  1479. return false;
  1480. } else {
  1481. //not valid line, return null;
  1482. }
  1483. } else {
  1484. //slopes of rectA's and rectB's diagonals
  1485. var slopeA = rectA.height / rectA.width;
  1486. var slopeB = rectB.height / rectB.width;
  1487. //slope of line between center of rectA and center of rectB
  1488. var slopePrime = (p2y - p1y) / (p2x - p1x);
  1489. var cardinalDirectionA = void 0;
  1490. var cardinalDirectionB = void 0;
  1491. var tempPointAx = void 0;
  1492. var tempPointAy = void 0;
  1493. var tempPointBx = void 0;
  1494. var tempPointBy = void 0;
  1495. //determine whether clipping point is the corner of nodeA
  1496. if (-slopeA === slopePrime) {
  1497. if (p1x > p2x) {
  1498. result[0] = bottomLeftAx;
  1499. result[1] = bottomLeftAy;
  1500. clipPointAFound = true;
  1501. } else {
  1502. result[0] = topRightAx;
  1503. result[1] = topLeftAy;
  1504. clipPointAFound = true;
  1505. }
  1506. } else if (slopeA === slopePrime) {
  1507. if (p1x > p2x) {
  1508. result[0] = topLeftAx;
  1509. result[1] = topLeftAy;
  1510. clipPointAFound = true;
  1511. } else {
  1512. result[0] = bottomRightAx;
  1513. result[1] = bottomLeftAy;
  1514. clipPointAFound = true;
  1515. }
  1516. }
  1517. //determine whether clipping point is the corner of nodeB
  1518. if (-slopeB === slopePrime) {
  1519. if (p2x > p1x) {
  1520. result[2] = bottomLeftBx;
  1521. result[3] = bottomLeftBy;
  1522. clipPointBFound = true;
  1523. } else {
  1524. result[2] = topRightBx;
  1525. result[3] = topLeftBy;
  1526. clipPointBFound = true;
  1527. }
  1528. } else if (slopeB === slopePrime) {
  1529. if (p2x > p1x) {
  1530. result[2] = topLeftBx;
  1531. result[3] = topLeftBy;
  1532. clipPointBFound = true;
  1533. } else {
  1534. result[2] = bottomRightBx;
  1535. result[3] = bottomLeftBy;
  1536. clipPointBFound = true;
  1537. }
  1538. }
  1539. //if both clipping points are corners
  1540. if (clipPointAFound && clipPointBFound) {
  1541. return false;
  1542. }
  1543. //determine Cardinal Direction of rectangles
  1544. if (p1x > p2x) {
  1545. if (p1y > p2y) {
  1546. cardinalDirectionA = this.getCardinalDirection(slopeA, slopePrime, 4);
  1547. cardinalDirectionB = this.getCardinalDirection(slopeB, slopePrime, 2);
  1548. } else {
  1549. cardinalDirectionA = this.getCardinalDirection(-slopeA, slopePrime, 3);
  1550. cardinalDirectionB = this.getCardinalDirection(-slopeB, slopePrime, 1);
  1551. }
  1552. } else {
  1553. if (p1y > p2y) {
  1554. cardinalDirectionA = this.getCardinalDirection(-slopeA, slopePrime, 1);
  1555. cardinalDirectionB = this.getCardinalDirection(-slopeB, slopePrime, 3);
  1556. } else {
  1557. cardinalDirectionA = this.getCardinalDirection(slopeA, slopePrime, 2);
  1558. cardinalDirectionB = this.getCardinalDirection(slopeB, slopePrime, 4);
  1559. }
  1560. }
  1561. //calculate clipping Point if it is not found before
  1562. if (!clipPointAFound) {
  1563. switch (cardinalDirectionA) {
  1564. case 1:
  1565. tempPointAy = topLeftAy;
  1566. tempPointAx = p1x + -halfHeightA / slopePrime;
  1567. result[0] = tempPointAx;
  1568. result[1] = tempPointAy;
  1569. break;
  1570. case 2:
  1571. tempPointAx = bottomRightAx;
  1572. tempPointAy = p1y + halfWidthA * slopePrime;
  1573. result[0] = tempPointAx;
  1574. result[1] = tempPointAy;
  1575. break;
  1576. case 3:
  1577. tempPointAy = bottomLeftAy;
  1578. tempPointAx = p1x + halfHeightA / slopePrime;
  1579. result[0] = tempPointAx;
  1580. result[1] = tempPointAy;
  1581. break;
  1582. case 4:
  1583. tempPointAx = bottomLeftAx;
  1584. tempPointAy = p1y + -halfWidthA * slopePrime;
  1585. result[0] = tempPointAx;
  1586. result[1] = tempPointAy;
  1587. break;
  1588. }
  1589. }
  1590. if (!clipPointBFound) {
  1591. switch (cardinalDirectionB) {
  1592. case 1:
  1593. tempPointBy = topLeftBy;
  1594. tempPointBx = p2x + -halfHeightB / slopePrime;
  1595. result[2] = tempPointBx;
  1596. result[3] = tempPointBy;
  1597. break;
  1598. case 2:
  1599. tempPointBx = bottomRightBx;
  1600. tempPointBy = p2y + halfWidthB * slopePrime;
  1601. result[2] = tempPointBx;
  1602. result[3] = tempPointBy;
  1603. break;
  1604. case 3:
  1605. tempPointBy = bottomLeftBy;
  1606. tempPointBx = p2x + halfHeightB / slopePrime;
  1607. result[2] = tempPointBx;
  1608. result[3] = tempPointBy;
  1609. break;
  1610. case 4:
  1611. tempPointBx = bottomLeftBx;
  1612. tempPointBy = p2y + -halfWidthB * slopePrime;
  1613. result[2] = tempPointBx;
  1614. result[3] = tempPointBy;
  1615. break;
  1616. }
  1617. }
  1618. }
  1619. return false;
  1620. };
  1621. /**
  1622. * This method returns in which cardinal direction does input point stays
  1623. * 1: North
  1624. * 2: East
  1625. * 3: South
  1626. * 4: West
  1627. */
  1628. IGeometry.getCardinalDirection = function (slope, slopePrime, line) {
  1629. if (slope > slopePrime) {
  1630. return line;
  1631. } else {
  1632. return 1 + line % 4;
  1633. }
  1634. };
  1635. /**
  1636. * This method calculates the intersection of the two lines defined by
  1637. * point pairs (s1,s2) and (f1,f2).
  1638. */
  1639. IGeometry.getIntersection = function (s1, s2, f1, f2) {
  1640. if (f2 == null) {
  1641. return this.getIntersection2(s1, s2, f1);
  1642. }
  1643. var x1 = s1.x;
  1644. var y1 = s1.y;
  1645. var x2 = s2.x;
  1646. var y2 = s2.y;
  1647. var x3 = f1.x;
  1648. var y3 = f1.y;
  1649. var x4 = f2.x;
  1650. var y4 = f2.y;
  1651. var x = void 0,
  1652. y = void 0; // intersection point
  1653. var a1 = void 0,
  1654. a2 = void 0,
  1655. b1 = void 0,
  1656. b2 = void 0,
  1657. c1 = void 0,
  1658. c2 = void 0; // coefficients of line eqns.
  1659. var denom = void 0;
  1660. a1 = y2 - y1;
  1661. b1 = x1 - x2;
  1662. c1 = x2 * y1 - x1 * y2; // { a1*x + b1*y + c1 = 0 is line 1 }
  1663. a2 = y4 - y3;
  1664. b2 = x3 - x4;
  1665. c2 = x4 * y3 - x3 * y4; // { a2*x + b2*y + c2 = 0 is line 2 }
  1666. denom = a1 * b2 - a2 * b1;
  1667. if (denom === 0) {
  1668. return null;
  1669. }
  1670. x = (b1 * c2 - b2 * c1) / denom;
  1671. y = (a2 * c1 - a1 * c2) / denom;
  1672. return new Point(x, y);
  1673. };
  1674. /**
  1675. * This method finds and returns the angle of the vector from the + x-axis
  1676. * in clockwise direction (compatible w/ Java coordinate system!).
  1677. */
  1678. IGeometry.angleOfVector = function (Cx, Cy, Nx, Ny) {
  1679. var C_angle = void 0;
  1680. if (Cx !== Nx) {
  1681. C_angle = Math.atan((Ny - Cy) / (Nx - Cx));
  1682. if (Nx < Cx) {
  1683. C_angle += Math.PI;
  1684. } else if (Ny < Cy) {
  1685. C_angle += this.TWO_PI;
  1686. }
  1687. } else if (Ny < Cy) {
  1688. C_angle = this.ONE_AND_HALF_PI; // 270 degrees
  1689. } else {
  1690. C_angle = this.HALF_PI; // 90 degrees
  1691. }
  1692. return C_angle;
  1693. };
  1694. /**
  1695. * This method checks whether the given two line segments (one with point
  1696. * p1 and p2, the other with point p3 and p4) intersect at a point other
  1697. * than these points.
  1698. */
  1699. IGeometry.doIntersect = function (p1, p2, p3, p4) {
  1700. var a = p1.x;
  1701. var b = p1.y;
  1702. var c = p2.x;
  1703. var d = p2.y;
  1704. var p = p3.x;
  1705. var q = p3.y;
  1706. var r = p4.x;
  1707. var s = p4.y;
  1708. var det = (c - a) * (s - q) - (r - p) * (d - b);
  1709. if (det === 0) {
  1710. return false;
  1711. } else {
  1712. var lambda = ((s - q) * (r - a) + (p - r) * (s - b)) / det;
  1713. var gamma = ((b - d) * (r - a) + (c - a) * (s - b)) / det;
  1714. return 0 < lambda && lambda < 1 && 0 < gamma && gamma < 1;
  1715. }
  1716. };
  1717. // -----------------------------------------------------------------------------
  1718. // Section: Class Constants
  1719. // -----------------------------------------------------------------------------
  1720. /**
  1721. * Some useful pre-calculated constants
  1722. */
  1723. IGeometry.HALF_PI = 0.5 * Math.PI;
  1724. IGeometry.ONE_AND_HALF_PI = 1.5 * Math.PI;
  1725. IGeometry.TWO_PI = 2.0 * Math.PI;
  1726. IGeometry.THREE_PI = 3.0 * Math.PI;
  1727. module.exports = IGeometry;
  1728. /***/ }),
  1729. /* 9 */
  1730. /***/ (function(module, exports, __webpack_require__) {
  1731. "use strict";
  1732. function IMath() {}
  1733. /**
  1734. * This method returns the sign of the input value.
  1735. */
  1736. IMath.sign = function (value) {
  1737. if (value > 0) {
  1738. return 1;
  1739. } else if (value < 0) {
  1740. return -1;
  1741. } else {
  1742. return 0;
  1743. }
  1744. };
  1745. IMath.floor = function (value) {
  1746. return value < 0 ? Math.ceil(value) : Math.floor(value);
  1747. };
  1748. IMath.ceil = function (value) {
  1749. return value < 0 ? Math.floor(value) : Math.ceil(value);
  1750. };
  1751. module.exports = IMath;
  1752. /***/ }),
  1753. /* 10 */
  1754. /***/ (function(module, exports, __webpack_require__) {
  1755. "use strict";
  1756. function Integer() {}
  1757. Integer.MAX_VALUE = 2147483647;
  1758. Integer.MIN_VALUE = -2147483648;
  1759. module.exports = Integer;
  1760. /***/ }),
  1761. /* 11 */
  1762. /***/ (function(module, exports, __webpack_require__) {
  1763. "use strict";
  1764. 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; }; }();
  1765. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1766. var nodeFrom = function nodeFrom(value) {
  1767. return { value: value, next: null, prev: null };
  1768. };
  1769. var add = function add(prev, node, next, list) {
  1770. if (prev !== null) {
  1771. prev.next = node;
  1772. } else {
  1773. list.head = node;
  1774. }
  1775. if (next !== null) {
  1776. next.prev = node;
  1777. } else {
  1778. list.tail = node;
  1779. }
  1780. node.prev = prev;
  1781. node.next = next;
  1782. list.length++;
  1783. return node;
  1784. };
  1785. var _remove = function _remove(node, list) {
  1786. var prev = node.prev,
  1787. next = node.next;
  1788. if (prev !== null) {
  1789. prev.next = next;
  1790. } else {
  1791. list.head = next;
  1792. }
  1793. if (next !== null) {
  1794. next.prev = prev;
  1795. } else {
  1796. list.tail = prev;
  1797. }
  1798. node.prev = node.next = null;
  1799. list.length--;
  1800. return node;
  1801. };
  1802. var LinkedList = function () {
  1803. function LinkedList(vals) {
  1804. var _this = this;
  1805. _classCallCheck(this, LinkedList);
  1806. this.length = 0;
  1807. this.head = null;
  1808. this.tail = null;
  1809. if (vals != null) {
  1810. vals.forEach(function (v) {
  1811. return _this.push(v);
  1812. });
  1813. }
  1814. }
  1815. _createClass(LinkedList, [{
  1816. key: "size",
  1817. value: function size() {
  1818. return this.length;
  1819. }
  1820. }, {
  1821. key: "insertBefore",
  1822. value: function insertBefore(val, otherNode) {
  1823. return add(otherNode.prev, nodeFrom(val), otherNode, this);
  1824. }
  1825. }, {
  1826. key: "insertAfter",
  1827. value: function insertAfter(val, otherNode) {
  1828. return add(otherNode, nodeFrom(val), otherNode.next, this);
  1829. }
  1830. }, {
  1831. key: "insertNodeBefore",
  1832. value: function insertNodeBefore(newNode, otherNode) {
  1833. return add(otherNode.prev, newNode, otherNode, this);
  1834. }
  1835. }, {
  1836. key: "insertNodeAfter",
  1837. value: function insertNodeAfter(newNode, otherNode) {
  1838. return add(otherNode, newNode, otherNode.next, this);
  1839. }
  1840. }, {
  1841. key: "push",
  1842. value: function push(val) {
  1843. return add(this.tail, nodeFrom(val), null, this);
  1844. }
  1845. }, {
  1846. key: "unshift",
  1847. value: function unshift(val) {
  1848. return add(null, nodeFrom(val), this.head, this);
  1849. }
  1850. }, {
  1851. key: "remove",
  1852. value: function remove(node) {
  1853. return _remove(node, this);
  1854. }
  1855. }, {
  1856. key: "pop",
  1857. value: function pop() {
  1858. return _remove(this.tail, this).value;
  1859. }
  1860. }, {
  1861. key: "popNode",
  1862. value: function popNode() {
  1863. return _remove(this.tail, this);
  1864. }
  1865. }, {
  1866. key: "shift",
  1867. value: function shift() {
  1868. return _remove(this.head, this).value;
  1869. }
  1870. }, {
  1871. key: "shiftNode",
  1872. value: function shiftNode() {
  1873. return _remove(this.head, this);
  1874. }
  1875. }, {
  1876. key: "get_object_at",
  1877. value: function get_object_at(index) {
  1878. if (index <= this.length()) {
  1879. var i = 1;
  1880. var current = this.head;
  1881. while (i < index) {
  1882. current = current.next;
  1883. i++;
  1884. }
  1885. return current.value;
  1886. }
  1887. }
  1888. }, {
  1889. key: "set_object_at",
  1890. value: function set_object_at(index, value) {
  1891. if (index <= this.length()) {
  1892. var i = 1;
  1893. var current = this.head;
  1894. while (i < index) {
  1895. current = current.next;
  1896. i++;
  1897. }
  1898. current.value = value;
  1899. }
  1900. }
  1901. }]);
  1902. return LinkedList;
  1903. }();
  1904. module.exports = LinkedList;
  1905. /***/ }),
  1906. /* 12 */
  1907. /***/ (function(module, exports, __webpack_require__) {
  1908. "use strict";
  1909. /*
  1910. *This class is the javascript implementation of the Point.java class in jdk
  1911. */
  1912. function Point(x, y, p) {
  1913. this.x = null;
  1914. this.y = null;
  1915. if (x == null && y == null && p == null) {
  1916. this.x = 0;
  1917. this.y = 0;
  1918. } else if (typeof x == 'number' && typeof y == 'number' && p == null) {
  1919. this.x = x;
  1920. this.y = y;
  1921. } else if (x.constructor.name == 'Point' && y == null && p == null) {
  1922. p = x;
  1923. this.x = p.x;
  1924. this.y = p.y;
  1925. }
  1926. }
  1927. Point.prototype.getX = function () {
  1928. return this.x;
  1929. };
  1930. Point.prototype.getY = function () {
  1931. return this.y;
  1932. };
  1933. Point.prototype.getLocation = function () {
  1934. return new Point(this.x, this.y);
  1935. };
  1936. Point.prototype.setLocation = function (x, y, p) {
  1937. if (x.constructor.name == 'Point' && y == null && p == null) {
  1938. p = x;
  1939. this.setLocation(p.x, p.y);
  1940. } else if (typeof x == 'number' && typeof y == 'number' && p == null) {
  1941. //if both parameters are integer just move (x,y) location
  1942. if (parseInt(x) == x && parseInt(y) == y) {
  1943. this.move(x, y);
  1944. } else {
  1945. this.x = Math.floor(x + 0.5);
  1946. this.y = Math.floor(y + 0.5);
  1947. }
  1948. }
  1949. };
  1950. Point.prototype.move = function (x, y) {
  1951. this.x = x;
  1952. this.y = y;
  1953. };
  1954. Point.prototype.translate = function (dx, dy) {
  1955. this.x += dx;
  1956. this.y += dy;
  1957. };
  1958. Point.prototype.equals = function (obj) {
  1959. if (obj.constructor.name == "Point") {
  1960. var pt = obj;
  1961. return this.x == pt.x && this.y == pt.y;
  1962. }
  1963. return this == obj;
  1964. };
  1965. Point.prototype.toString = function () {
  1966. return new Point().constructor.name + "[x=" + this.x + ",y=" + this.y + "]";
  1967. };
  1968. module.exports = Point;
  1969. /***/ }),
  1970. /* 13 */
  1971. /***/ (function(module, exports, __webpack_require__) {
  1972. "use strict";
  1973. function RectangleD(x, y, width, height) {
  1974. this.x = 0;
  1975. this.y = 0;
  1976. this.width = 0;
  1977. this.height = 0;
  1978. if (x != null && y != null && width != null && height != null) {
  1979. this.x = x;
  1980. this.y = y;
  1981. this.width = width;
  1982. this.height = height;
  1983. }
  1984. }
  1985. RectangleD.prototype.getX = function () {
  1986. return this.x;
  1987. };
  1988. RectangleD.prototype.setX = function (x) {
  1989. this.x = x;
  1990. };
  1991. RectangleD.prototype.getY = function () {
  1992. return this.y;
  1993. };
  1994. RectangleD.prototype.setY = function (y) {
  1995. this.y = y;
  1996. };
  1997. RectangleD.prototype.getWidth = function () {
  1998. return this.width;
  1999. };
  2000. RectangleD.prototype.setWidth = function (width) {
  2001. this.width = width;
  2002. };
  2003. RectangleD.prototype.getHeight = function () {
  2004. return this.height;
  2005. };
  2006. RectangleD.prototype.setHeight = function (height) {
  2007. this.height = height;
  2008. };
  2009. RectangleD.prototype.getRight = function () {
  2010. return this.x + this.width;
  2011. };
  2012. RectangleD.prototype.getBottom = function () {
  2013. return this.y + this.height;
  2014. };
  2015. RectangleD.prototype.intersects = function (a) {
  2016. if (this.getRight() < a.x) {
  2017. return false;
  2018. }
  2019. if (this.getBottom() < a.y) {
  2020. return false;
  2021. }
  2022. if (a.getRight() < this.x) {
  2023. return false;
  2024. }
  2025. if (a.getBottom() < this.y) {
  2026. return false;
  2027. }
  2028. return true;
  2029. };
  2030. RectangleD.prototype.getCenterX = function () {
  2031. return this.x + this.width / 2;
  2032. };
  2033. RectangleD.prototype.getMinX = function () {
  2034. return this.getX();
  2035. };
  2036. RectangleD.prototype.getMaxX = function () {
  2037. return this.getX() + this.width;
  2038. };
  2039. RectangleD.prototype.getCenterY = function () {
  2040. return this.y + this.height / 2;
  2041. };
  2042. RectangleD.prototype.getMinY = function () {
  2043. return this.getY();
  2044. };
  2045. RectangleD.prototype.getMaxY = function () {
  2046. return this.getY() + this.height;
  2047. };
  2048. RectangleD.prototype.getWidthHalf = function () {
  2049. return this.width / 2;
  2050. };
  2051. RectangleD.prototype.getHeightHalf = function () {
  2052. return this.height / 2;
  2053. };
  2054. module.exports = RectangleD;
  2055. /***/ }),
  2056. /* 14 */
  2057. /***/ (function(module, exports, __webpack_require__) {
  2058. "use strict";
  2059. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  2060. function UniqueIDGeneretor() {}
  2061. UniqueIDGeneretor.lastID = 0;
  2062. UniqueIDGeneretor.createID = function (obj) {
  2063. if (UniqueIDGeneretor.isPrimitive(obj)) {
  2064. return obj;
  2065. }
  2066. if (obj.uniqueID != null) {
  2067. return obj.uniqueID;
  2068. }
  2069. obj.uniqueID = UniqueIDGeneretor.getString();
  2070. UniqueIDGeneretor.lastID++;
  2071. return obj.uniqueID;
  2072. };
  2073. UniqueIDGeneretor.getString = function (id) {
  2074. if (id == null) id = UniqueIDGeneretor.lastID;
  2075. return "Object#" + id + "";
  2076. };
  2077. UniqueIDGeneretor.isPrimitive = function (arg) {
  2078. var type = typeof arg === "undefined" ? "undefined" : _typeof(arg);
  2079. return arg == null || type != "object" && type != "function";
  2080. };
  2081. module.exports = UniqueIDGeneretor;
  2082. /***/ }),
  2083. /* 15 */
  2084. /***/ (function(module, exports, __webpack_require__) {
  2085. "use strict";
  2086. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  2087. var LayoutConstants = __webpack_require__(0);
  2088. var LGraphManager = __webpack_require__(6);
  2089. var LNode = __webpack_require__(3);
  2090. var LEdge = __webpack_require__(1);
  2091. var LGraph = __webpack_require__(5);
  2092. var PointD = __webpack_require__(4);
  2093. var Transform = __webpack_require__(17);
  2094. var Emitter = __webpack_require__(27);
  2095. function Layout(isRemoteUse) {
  2096. Emitter.call(this);
  2097. //Layout Quality: 0:draft, 1:default, 2:proof
  2098. this.layoutQuality = LayoutConstants.QUALITY;
  2099. //Whether layout should create bendpoints as needed or not
  2100. this.createBendsAsNeeded = LayoutConstants.DEFAULT_CREATE_BENDS_AS_NEEDED;
  2101. //Whether layout should be incremental or not
  2102. this.incremental = LayoutConstants.DEFAULT_INCREMENTAL;
  2103. //Whether we animate from before to after layout node positions
  2104. this.animationOnLayout = LayoutConstants.DEFAULT_ANIMATION_ON_LAYOUT;
  2105. //Whether we animate the layout process or not
  2106. this.animationDuringLayout = LayoutConstants.DEFAULT_ANIMATION_DURING_LAYOUT;
  2107. //Number iterations that should be done between two successive animations
  2108. this.animationPeriod = LayoutConstants.DEFAULT_ANIMATION_PERIOD;
  2109. /**
  2110. * Whether or not leaf nodes (non-compound nodes) are of uniform sizes. When
  2111. * they are, both spring and repulsion forces between two leaf nodes can be
  2112. * calculated without the expensive clipping point calculations, resulting
  2113. * in major speed-up.
  2114. */
  2115. this.uniformLeafNodeSizes = LayoutConstants.DEFAULT_UNIFORM_LEAF_NODE_SIZES;
  2116. /**
  2117. * This is used for creation of bendpoints by using dummy nodes and edges.
  2118. * Maps an LEdge to its dummy bendpoint path.
  2119. */
  2120. this.edgeToDummyNodes = new Map();
  2121. this.graphManager = new LGraphManager(this);
  2122. this.isLayoutFinished = false;
  2123. this.isSubLayout = false;
  2124. this.isRemoteUse = false;
  2125. if (isRemoteUse != null) {
  2126. this.isRemoteUse = isRemoteUse;
  2127. }
  2128. }
  2129. Layout.RANDOM_SEED = 1;
  2130. Layout.prototype = Object.create(Emitter.prototype);
  2131. Layout.prototype.getGraphManager = function () {
  2132. return this.graphManager;
  2133. };
  2134. Layout.prototype.getAllNodes = function () {
  2135. return this.graphManager.getAllNodes();
  2136. };
  2137. Layout.prototype.getAllEdges = function () {
  2138. return this.graphManager.getAllEdges();
  2139. };
  2140. Layout.prototype.getAllNodesToApplyGravitation = function () {
  2141. return this.graphManager.getAllNodesToApplyGravitation();
  2142. };
  2143. Layout.prototype.newGraphManager = function () {
  2144. var gm = new LGraphManager(this);
  2145. this.graphManager = gm;
  2146. return gm;
  2147. };
  2148. Layout.prototype.newGraph = function (vGraph) {
  2149. return new LGraph(null, this.graphManager, vGraph);
  2150. };
  2151. Layout.prototype.newNode = function (vNode) {
  2152. return new LNode(this.graphManager, vNode);
  2153. };
  2154. Layout.prototype.newEdge = function (vEdge) {
  2155. return new LEdge(null, null, vEdge);
  2156. };
  2157. Layout.prototype.checkLayoutSuccess = function () {
  2158. return this.graphManager.getRoot() == null || this.graphManager.getRoot().getNodes().length == 0 || this.graphManager.includesInvalidEdge();
  2159. };
  2160. Layout.prototype.runLayout = function () {
  2161. this.isLayoutFinished = false;
  2162. if (this.tilingPreLayout) {
  2163. this.tilingPreLayout();
  2164. }
  2165. this.initParameters();
  2166. var isLayoutSuccessfull;
  2167. if (this.checkLayoutSuccess()) {
  2168. isLayoutSuccessfull = false;
  2169. } else {
  2170. isLayoutSuccessfull = this.layout();
  2171. }
  2172. if (LayoutConstants.ANIMATE === 'during') {
  2173. // If this is a 'during' layout animation. Layout is not finished yet.
  2174. // We need to perform these in index.js when layout is really finished.
  2175. return false;
  2176. }
  2177. if (isLayoutSuccessfull) {
  2178. if (!this.isSubLayout) {
  2179. this.doPostLayout();
  2180. }
  2181. }
  2182. if (this.tilingPostLayout) {
  2183. this.tilingPostLayout();
  2184. }
  2185. this.isLayoutFinished = true;
  2186. return isLayoutSuccessfull;
  2187. };
  2188. /**
  2189. * This method performs the operations required after layout.
  2190. */
  2191. Layout.prototype.doPostLayout = function () {
  2192. //assert !isSubLayout : "Should not be called on sub-layout!";
  2193. // Propagate geometric changes to v-level objects
  2194. if (!this.incremental) {
  2195. this.transform();
  2196. }
  2197. this.update();
  2198. };
  2199. /**
  2200. * This method updates the geometry of the target graph according to
  2201. * calculated layout.
  2202. */
  2203. Layout.prototype.update2 = function () {
  2204. // update bend points
  2205. if (this.createBendsAsNeeded) {
  2206. this.createBendpointsFromDummyNodes();
  2207. // reset all edges, since the topology has changed
  2208. this.graphManager.resetAllEdges();
  2209. }
  2210. // perform edge, node and root updates if layout is not called
  2211. // remotely
  2212. if (!this.isRemoteUse) {
  2213. // update all edges
  2214. var edge;
  2215. var allEdges = this.graphManager.getAllEdges();
  2216. for (var i = 0; i < allEdges.length; i++) {
  2217. edge = allEdges[i];
  2218. // this.update(edge);
  2219. }
  2220. // recursively update nodes
  2221. var node;
  2222. var nodes = this.graphManager.getRoot().getNodes();
  2223. for (var i = 0; i < nodes.length; i++) {
  2224. node = nodes[i];
  2225. // this.update(node);
  2226. }
  2227. // update root graph
  2228. this.update(this.graphManager.getRoot());
  2229. }
  2230. };
  2231. Layout.prototype.update = function (obj) {
  2232. if (obj == null) {
  2233. this.update2();
  2234. } else if (obj instanceof LNode) {
  2235. var node = obj;
  2236. if (node.getChild() != null) {
  2237. // since node is compound, recursively update child nodes
  2238. var nodes = node.getChild().getNodes();
  2239. for (var i = 0; i < nodes.length; i++) {
  2240. update(nodes[i]);
  2241. }
  2242. }
  2243. // if the l-level node is associated with a v-level graph object,
  2244. // then it is assumed that the v-level node implements the
  2245. // interface Updatable.
  2246. if (node.vGraphObject != null) {
  2247. // cast to Updatable without any type check
  2248. var vNode = node.vGraphObject;
  2249. // call the update method of the interface
  2250. vNode.update(node);
  2251. }
  2252. } else if (obj instanceof LEdge) {
  2253. var edge = obj;
  2254. // if the l-level edge is associated with a v-level graph object,
  2255. // then it is assumed that the v-level edge implements the
  2256. // interface Updatable.
  2257. if (edge.vGraphObject != null) {
  2258. // cast to Updatable without any type check
  2259. var vEdge = edge.vGraphObject;
  2260. // call the update method of the interface
  2261. vEdge.update(edge);
  2262. }
  2263. } else if (obj instanceof LGraph) {
  2264. var graph = obj;
  2265. // if the l-level graph is associated with a v-level graph object,
  2266. // then it is assumed that the v-level object implements the
  2267. // interface Updatable.
  2268. if (graph.vGraphObject != null) {
  2269. // cast to Updatable without any type check
  2270. var vGraph = graph.vGraphObject;
  2271. // call the update method of the interface
  2272. vGraph.update(graph);
  2273. }
  2274. }
  2275. };
  2276. /**
  2277. * This method is used to set all layout parameters to default values
  2278. * determined at compile time.
  2279. */
  2280. Layout.prototype.initParameters = function () {
  2281. if (!this.isSubLayout) {
  2282. this.layoutQuality = LayoutConstants.QUALITY;
  2283. this.animationDuringLayout = LayoutConstants.DEFAULT_ANIMATION_DURING_LAYOUT;
  2284. this.animationPeriod = LayoutConstants.DEFAULT_ANIMATION_PERIOD;
  2285. this.animationOnLayout = LayoutConstants.DEFAULT_ANIMATION_ON_LAYOUT;
  2286. this.incremental = LayoutConstants.DEFAULT_INCREMENTAL;
  2287. this.createBendsAsNeeded = LayoutConstants.DEFAULT_CREATE_BENDS_AS_NEEDED;
  2288. this.uniformLeafNodeSizes = LayoutConstants.DEFAULT_UNIFORM_LEAF_NODE_SIZES;
  2289. }
  2290. if (this.animationDuringLayout) {
  2291. this.animationOnLayout = false;
  2292. }
  2293. };
  2294. Layout.prototype.transform = function (newLeftTop) {
  2295. if (newLeftTop == undefined) {
  2296. this.transform(new PointD(0, 0));
  2297. } else {
  2298. // create a transformation object (from Eclipse to layout). When an
  2299. // inverse transform is applied, we get upper-left coordinate of the
  2300. // drawing or the root graph at given input coordinate (some margins
  2301. // already included in calculation of left-top).
  2302. var trans = new Transform();
  2303. var leftTop = this.graphManager.getRoot().updateLeftTop();
  2304. if (leftTop != null) {
  2305. trans.setWorldOrgX(newLeftTop.x);
  2306. trans.setWorldOrgY(newLeftTop.y);
  2307. trans.setDeviceOrgX(leftTop.x);
  2308. trans.setDeviceOrgY(leftTop.y);
  2309. var nodes = this.getAllNodes();
  2310. var node;
  2311. for (var i = 0; i < nodes.length; i++) {
  2312. node = nodes[i];
  2313. node.transform(trans);
  2314. }
  2315. }
  2316. }
  2317. };
  2318. Layout.prototype.positionNodesRandomly = function (graph) {
  2319. if (graph == undefined) {
  2320. //assert !this.incremental;
  2321. this.positionNodesRandomly(this.getGraphManager().getRoot());
  2322. this.getGraphManager().getRoot().updateBounds(true);
  2323. } else {
  2324. var lNode;
  2325. var childGraph;
  2326. var nodes = graph.getNodes();
  2327. for (var i = 0; i < nodes.length; i++) {
  2328. lNode = nodes[i];
  2329. childGraph = lNode.getChild();
  2330. if (childGraph == null) {
  2331. lNode.scatter();
  2332. } else if (childGraph.getNodes().length == 0) {
  2333. lNode.scatter();
  2334. } else {
  2335. this.positionNodesRandomly(childGraph);
  2336. lNode.updateBounds();
  2337. }
  2338. }
  2339. }
  2340. };
  2341. /**
  2342. * This method returns a list of trees where each tree is represented as a
  2343. * list of l-nodes. The method returns a list of size 0 when:
  2344. * - The graph is not flat or
  2345. * - One of the component(s) of the graph is not a tree.
  2346. */
  2347. Layout.prototype.getFlatForest = function () {
  2348. var flatForest = [];
  2349. var isForest = true;
  2350. // Quick reference for all nodes in the graph manager associated with
  2351. // this layout. The list should not be changed.
  2352. var allNodes = this.graphManager.getRoot().getNodes();
  2353. // First be sure that the graph is flat
  2354. var isFlat = true;
  2355. for (var i = 0; i < allNodes.length; i++) {
  2356. if (allNodes[i].getChild() != null) {
  2357. isFlat = false;
  2358. }
  2359. }
  2360. // Return empty forest if the graph is not flat.
  2361. if (!isFlat) {
  2362. return flatForest;
  2363. }
  2364. // Run BFS for each component of the graph.
  2365. var visited = new Set();
  2366. var toBeVisited = [];
  2367. var parents = new Map();
  2368. var unProcessedNodes = [];
  2369. unProcessedNodes = unProcessedNodes.concat(allNodes);
  2370. // Each iteration of this loop finds a component of the graph and
  2371. // decides whether it is a tree or not. If it is a tree, adds it to the
  2372. // forest and continued with the next component.
  2373. while (unProcessedNodes.length > 0 && isForest) {
  2374. toBeVisited.push(unProcessedNodes[0]);
  2375. // Start the BFS. Each iteration of this loop visits a node in a
  2376. // BFS manner.
  2377. while (toBeVisited.length > 0 && isForest) {
  2378. //pool operation
  2379. var currentNode = toBeVisited[0];
  2380. toBeVisited.splice(0, 1);
  2381. visited.add(currentNode);
  2382. // Traverse all neighbors of this node
  2383. var neighborEdges = currentNode.getEdges();
  2384. for (var i = 0; i < neighborEdges.length; i++) {
  2385. var currentNeighbor = neighborEdges[i].getOtherEnd(currentNode);
  2386. // If BFS is not growing from this neighbor.
  2387. if (parents.get(currentNode) != currentNeighbor) {
  2388. // We haven't previously visited this neighbor.
  2389. if (!visited.has(currentNeighbor)) {
  2390. toBeVisited.push(currentNeighbor);
  2391. parents.set(currentNeighbor, currentNode);
  2392. }
  2393. // Since we have previously visited this neighbor and
  2394. // this neighbor is not parent of currentNode, given
  2395. // graph contains a component that is not tree, hence
  2396. // it is not a forest.
  2397. else {
  2398. isForest = false;
  2399. break;
  2400. }
  2401. }
  2402. }
  2403. }
  2404. // The graph contains a component that is not a tree. Empty
  2405. // previously found trees. The method will end.
  2406. if (!isForest) {
  2407. flatForest = [];
  2408. }
  2409. // Save currently visited nodes as a tree in our forest. Reset
  2410. // visited and parents lists. Continue with the next component of
  2411. // the graph, if any.
  2412. else {
  2413. var temp = [].concat(_toConsumableArray(visited));
  2414. flatForest.push(temp);
  2415. //flatForest = flatForest.concat(temp);
  2416. //unProcessedNodes.removeAll(visited);
  2417. for (var i = 0; i < temp.length; i++) {
  2418. var value = temp[i];
  2419. var index = unProcessedNodes.indexOf(value);
  2420. if (index > -1) {
  2421. unProcessedNodes.splice(index, 1);
  2422. }
  2423. }
  2424. visited = new Set();
  2425. parents = new Map();
  2426. }
  2427. }
  2428. return flatForest;
  2429. };
  2430. /**
  2431. * This method creates dummy nodes (an l-level node with minimal dimensions)
  2432. * for the given edge (one per bendpoint). The existing l-level structure
  2433. * is updated accordingly.
  2434. */
  2435. Layout.prototype.createDummyNodesForBendpoints = function (edge) {
  2436. var dummyNodes = [];
  2437. var prev = edge.source;
  2438. var graph = this.graphManager.calcLowestCommonAncestor(edge.source, edge.target);
  2439. for (var i = 0; i < edge.bendpoints.length; i++) {
  2440. // create new dummy node
  2441. var dummyNode = this.newNode(null);
  2442. dummyNode.setRect(new Point(0, 0), new Dimension(1, 1));
  2443. graph.add(dummyNode);
  2444. // create new dummy edge between prev and dummy node
  2445. var dummyEdge = this.newEdge(null);
  2446. this.graphManager.add(dummyEdge, prev, dummyNode);
  2447. dummyNodes.add(dummyNode);
  2448. prev = dummyNode;
  2449. }
  2450. var dummyEdge = this.newEdge(null);
  2451. this.graphManager.add(dummyEdge, prev, edge.target);
  2452. this.edgeToDummyNodes.set(edge, dummyNodes);
  2453. // remove real edge from graph manager if it is inter-graph
  2454. if (edge.isInterGraph()) {
  2455. this.graphManager.remove(edge);
  2456. }
  2457. // else, remove the edge from the current graph
  2458. else {
  2459. graph.remove(edge);
  2460. }
  2461. return dummyNodes;
  2462. };
  2463. /**
  2464. * This method creates bendpoints for edges from the dummy nodes
  2465. * at l-level.
  2466. */
  2467. Layout.prototype.createBendpointsFromDummyNodes = function () {
  2468. var edges = [];
  2469. edges = edges.concat(this.graphManager.getAllEdges());
  2470. edges = [].concat(_toConsumableArray(this.edgeToDummyNodes.keys())).concat(edges);
  2471. for (var k = 0; k < edges.length; k++) {
  2472. var lEdge = edges[k];
  2473. if (lEdge.bendpoints.length > 0) {
  2474. var path = this.edgeToDummyNodes.get(lEdge);
  2475. for (var i = 0; i < path.length; i++) {
  2476. var dummyNode = path[i];
  2477. var p = new PointD(dummyNode.getCenterX(), dummyNode.getCenterY());
  2478. // update bendpoint's location according to dummy node
  2479. var ebp = lEdge.bendpoints.get(i);
  2480. ebp.x = p.x;
  2481. ebp.y = p.y;
  2482. // remove the dummy node, dummy edges incident with this
  2483. // dummy node is also removed (within the remove method)
  2484. dummyNode.getOwner().remove(dummyNode);
  2485. }
  2486. // add the real edge to graph
  2487. this.graphManager.add(lEdge, lEdge.source, lEdge.target);
  2488. }
  2489. }
  2490. };
  2491. Layout.transform = function (sliderValue, defaultValue, minDiv, maxMul) {
  2492. if (minDiv != undefined && maxMul != undefined) {
  2493. var value = defaultValue;
  2494. if (sliderValue <= 50) {
  2495. var minValue = defaultValue / minDiv;
  2496. value -= (defaultValue - minValue) / 50 * (50 - sliderValue);
  2497. } else {
  2498. var maxValue = defaultValue * maxMul;
  2499. value += (maxValue - defaultValue) / 50 * (sliderValue - 50);
  2500. }
  2501. return value;
  2502. } else {
  2503. var a, b;
  2504. if (sliderValue <= 50) {
  2505. a = 9.0 * defaultValue / 500.0;
  2506. b = defaultValue / 10.0;
  2507. } else {
  2508. a = 9.0 * defaultValue / 50.0;
  2509. b = -8 * defaultValue;
  2510. }
  2511. return a * sliderValue + b;
  2512. }
  2513. };
  2514. /**
  2515. * This method finds and returns the center of the given nodes, assuming
  2516. * that the given nodes form a tree in themselves.
  2517. */
  2518. Layout.findCenterOfTree = function (nodes) {
  2519. var list = [];
  2520. list = list.concat(nodes);
  2521. var removedNodes = [];
  2522. var remainingDegrees = new Map();
  2523. var foundCenter = false;
  2524. var centerNode = null;
  2525. if (list.length == 1 || list.length == 2) {
  2526. foundCenter = true;
  2527. centerNode = list[0];
  2528. }
  2529. for (var i = 0; i < list.length; i++) {
  2530. var node = list[i];
  2531. var degree = node.getNeighborsList().size;
  2532. remainingDegrees.set(node, node.getNeighborsList().size);
  2533. if (degree == 1) {
  2534. removedNodes.push(node);
  2535. }
  2536. }
  2537. var tempList = [];
  2538. tempList = tempList.concat(removedNodes);
  2539. while (!foundCenter) {
  2540. var tempList2 = [];
  2541. tempList2 = tempList2.concat(tempList);
  2542. tempList = [];
  2543. for (var i = 0; i < list.length; i++) {
  2544. var node = list[i];
  2545. var index = list.indexOf(node);
  2546. if (index >= 0) {
  2547. list.splice(index, 1);
  2548. }
  2549. var neighbours = node.getNeighborsList();
  2550. neighbours.forEach(function (neighbour) {
  2551. if (removedNodes.indexOf(neighbour) < 0) {
  2552. var otherDegree = remainingDegrees.get(neighbour);
  2553. var newDegree = otherDegree - 1;
  2554. if (newDegree == 1) {
  2555. tempList.push(neighbour);
  2556. }
  2557. remainingDegrees.set(neighbour, newDegree);
  2558. }
  2559. });
  2560. }
  2561. removedNodes = removedNodes.concat(tempList);
  2562. if (list.length == 1 || list.length == 2) {
  2563. foundCenter = true;
  2564. centerNode = list[0];
  2565. }
  2566. }
  2567. return centerNode;
  2568. };
  2569. /**
  2570. * During the coarsening process, this layout may be referenced by two graph managers
  2571. * this setter function grants access to change the currently being used graph manager
  2572. */
  2573. Layout.prototype.setGraphManager = function (gm) {
  2574. this.graphManager = gm;
  2575. };
  2576. module.exports = Layout;
  2577. /***/ }),
  2578. /* 16 */
  2579. /***/ (function(module, exports, __webpack_require__) {
  2580. "use strict";
  2581. function RandomSeed() {}
  2582. // adapted from: https://stackoverflow.com/a/19303725
  2583. RandomSeed.seed = 1;
  2584. RandomSeed.x = 0;
  2585. RandomSeed.nextDouble = function () {
  2586. RandomSeed.x = Math.sin(RandomSeed.seed++) * 10000;
  2587. return RandomSeed.x - Math.floor(RandomSeed.x);
  2588. };
  2589. module.exports = RandomSeed;
  2590. /***/ }),
  2591. /* 17 */
  2592. /***/ (function(module, exports, __webpack_require__) {
  2593. "use strict";
  2594. var PointD = __webpack_require__(4);
  2595. function Transform(x, y) {
  2596. this.lworldOrgX = 0.0;
  2597. this.lworldOrgY = 0.0;
  2598. this.ldeviceOrgX = 0.0;
  2599. this.ldeviceOrgY = 0.0;
  2600. this.lworldExtX = 1.0;
  2601. this.lworldExtY = 1.0;
  2602. this.ldeviceExtX = 1.0;
  2603. this.ldeviceExtY = 1.0;
  2604. }
  2605. Transform.prototype.getWorldOrgX = function () {
  2606. return this.lworldOrgX;
  2607. };
  2608. Transform.prototype.setWorldOrgX = function (wox) {
  2609. this.lworldOrgX = wox;
  2610. };
  2611. Transform.prototype.getWorldOrgY = function () {
  2612. return this.lworldOrgY;
  2613. };
  2614. Transform.prototype.setWorldOrgY = function (woy) {
  2615. this.lworldOrgY = woy;
  2616. };
  2617. Transform.prototype.getWorldExtX = function () {
  2618. return this.lworldExtX;
  2619. };
  2620. Transform.prototype.setWorldExtX = function (wex) {
  2621. this.lworldExtX = wex;
  2622. };
  2623. Transform.prototype.getWorldExtY = function () {
  2624. return this.lworldExtY;
  2625. };
  2626. Transform.prototype.setWorldExtY = function (wey) {
  2627. this.lworldExtY = wey;
  2628. };
  2629. /* Device related */
  2630. Transform.prototype.getDeviceOrgX = function () {
  2631. return this.ldeviceOrgX;
  2632. };
  2633. Transform.prototype.setDeviceOrgX = function (dox) {
  2634. this.ldeviceOrgX = dox;
  2635. };
  2636. Transform.prototype.getDeviceOrgY = function () {
  2637. return this.ldeviceOrgY;
  2638. };
  2639. Transform.prototype.setDeviceOrgY = function (doy) {
  2640. this.ldeviceOrgY = doy;
  2641. };
  2642. Transform.prototype.getDeviceExtX = function () {
  2643. return this.ldeviceExtX;
  2644. };
  2645. Transform.prototype.setDeviceExtX = function (dex) {
  2646. this.ldeviceExtX = dex;
  2647. };
  2648. Transform.prototype.getDeviceExtY = function () {
  2649. return this.ldeviceExtY;
  2650. };
  2651. Transform.prototype.setDeviceExtY = function (dey) {
  2652. this.ldeviceExtY = dey;
  2653. };
  2654. Transform.prototype.transformX = function (x) {
  2655. var xDevice = 0.0;
  2656. var worldExtX = this.lworldExtX;
  2657. if (worldExtX != 0.0) {
  2658. xDevice = this.ldeviceOrgX + (x - this.lworldOrgX) * this.ldeviceExtX / worldExtX;
  2659. }
  2660. return xDevice;
  2661. };
  2662. Transform.prototype.transformY = function (y) {
  2663. var yDevice = 0.0;
  2664. var worldExtY = this.lworldExtY;
  2665. if (worldExtY != 0.0) {
  2666. yDevice = this.ldeviceOrgY + (y - this.lworldOrgY) * this.ldeviceExtY / worldExtY;
  2667. }
  2668. return yDevice;
  2669. };
  2670. Transform.prototype.inverseTransformX = function (x) {
  2671. var xWorld = 0.0;
  2672. var deviceExtX = this.ldeviceExtX;
  2673. if (deviceExtX != 0.0) {
  2674. xWorld = this.lworldOrgX + (x - this.ldeviceOrgX) * this.lworldExtX / deviceExtX;
  2675. }
  2676. return xWorld;
  2677. };
  2678. Transform.prototype.inverseTransformY = function (y) {
  2679. var yWorld = 0.0;
  2680. var deviceExtY = this.ldeviceExtY;
  2681. if (deviceExtY != 0.0) {
  2682. yWorld = this.lworldOrgY + (y - this.ldeviceOrgY) * this.lworldExtY / deviceExtY;
  2683. }
  2684. return yWorld;
  2685. };
  2686. Transform.prototype.inverseTransformPoint = function (inPoint) {
  2687. var outPoint = new PointD(this.inverseTransformX(inPoint.x), this.inverseTransformY(inPoint.y));
  2688. return outPoint;
  2689. };
  2690. module.exports = Transform;
  2691. /***/ }),
  2692. /* 18 */
  2693. /***/ (function(module, exports, __webpack_require__) {
  2694. "use strict";
  2695. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  2696. var Layout = __webpack_require__(15);
  2697. var FDLayoutConstants = __webpack_require__(7);
  2698. var LayoutConstants = __webpack_require__(0);
  2699. var IGeometry = __webpack_require__(8);
  2700. var IMath = __webpack_require__(9);
  2701. function FDLayout() {
  2702. Layout.call(this);
  2703. this.useSmartIdealEdgeLengthCalculation = FDLayoutConstants.DEFAULT_USE_SMART_IDEAL_EDGE_LENGTH_CALCULATION;
  2704. this.idealEdgeLength = FDLayoutConstants.DEFAULT_EDGE_LENGTH;
  2705. this.springConstant = FDLayoutConstants.DEFAULT_SPRING_STRENGTH;
  2706. this.repulsionConstant = FDLayoutConstants.DEFAULT_REPULSION_STRENGTH;
  2707. this.gravityConstant = FDLayoutConstants.DEFAULT_GRAVITY_STRENGTH;
  2708. this.compoundGravityConstant = FDLayoutConstants.DEFAULT_COMPOUND_GRAVITY_STRENGTH;
  2709. this.gravityRangeFactor = FDLayoutConstants.DEFAULT_GRAVITY_RANGE_FACTOR;
  2710. this.compoundGravityRangeFactor = FDLayoutConstants.DEFAULT_COMPOUND_GRAVITY_RANGE_FACTOR;
  2711. this.displacementThresholdPerNode = 3.0 * FDLayoutConstants.DEFAULT_EDGE_LENGTH / 100;
  2712. this.coolingFactor = FDLayoutConstants.DEFAULT_COOLING_FACTOR_INCREMENTAL;
  2713. this.initialCoolingFactor = FDLayoutConstants.DEFAULT_COOLING_FACTOR_INCREMENTAL;
  2714. this.totalDisplacement = 0.0;
  2715. this.oldTotalDisplacement = 0.0;
  2716. this.maxIterations = FDLayoutConstants.MAX_ITERATIONS;
  2717. }
  2718. FDLayout.prototype = Object.create(Layout.prototype);
  2719. for (var prop in Layout) {
  2720. FDLayout[prop] = Layout[prop];
  2721. }
  2722. FDLayout.prototype.initParameters = function () {
  2723. Layout.prototype.initParameters.call(this, arguments);
  2724. this.totalIterations = 0;
  2725. this.notAnimatedIterations = 0;
  2726. this.useFRGridVariant = FDLayoutConstants.DEFAULT_USE_SMART_REPULSION_RANGE_CALCULATION;
  2727. this.grid = [];
  2728. };
  2729. FDLayout.prototype.calcIdealEdgeLengths = function () {
  2730. var edge;
  2731. var lcaDepth;
  2732. var source;
  2733. var target;
  2734. var sizeOfSourceInLca;
  2735. var sizeOfTargetInLca;
  2736. var allEdges = this.getGraphManager().getAllEdges();
  2737. for (var i = 0; i < allEdges.length; i++) {
  2738. edge = allEdges[i];
  2739. edge.idealLength = this.idealEdgeLength;
  2740. if (edge.isInterGraph) {
  2741. source = edge.getSource();
  2742. target = edge.getTarget();
  2743. sizeOfSourceInLca = edge.getSourceInLca().getEstimatedSize();
  2744. sizeOfTargetInLca = edge.getTargetInLca().getEstimatedSize();
  2745. if (this.useSmartIdealEdgeLengthCalculation) {
  2746. edge.idealLength += sizeOfSourceInLca + sizeOfTargetInLca - 2 * LayoutConstants.SIMPLE_NODE_SIZE;
  2747. }
  2748. lcaDepth = edge.getLca().getInclusionTreeDepth();
  2749. edge.idealLength += FDLayoutConstants.DEFAULT_EDGE_LENGTH * FDLayoutConstants.PER_LEVEL_IDEAL_EDGE_LENGTH_FACTOR * (source.getInclusionTreeDepth() + target.getInclusionTreeDepth() - 2 * lcaDepth);
  2750. }
  2751. }
  2752. };
  2753. FDLayout.prototype.initSpringEmbedder = function () {
  2754. var s = this.getAllNodes().length;
  2755. if (this.incremental) {
  2756. if (s > FDLayoutConstants.ADAPTATION_LOWER_NODE_LIMIT) {
  2757. this.coolingFactor = Math.max(this.coolingFactor * FDLayoutConstants.COOLING_ADAPTATION_FACTOR, this.coolingFactor - (s - FDLayoutConstants.ADAPTATION_LOWER_NODE_LIMIT) / (FDLayoutConstants.ADAPTATION_UPPER_NODE_LIMIT - FDLayoutConstants.ADAPTATION_LOWER_NODE_LIMIT) * this.coolingFactor * (1 - FDLayoutConstants.COOLING_ADAPTATION_FACTOR));
  2758. }
  2759. this.maxNodeDisplacement = FDLayoutConstants.MAX_NODE_DISPLACEMENT_INCREMENTAL;
  2760. } else {
  2761. if (s > FDLayoutConstants.ADAPTATION_LOWER_NODE_LIMIT) {
  2762. this.coolingFactor = Math.max(FDLayoutConstants.COOLING_ADAPTATION_FACTOR, 1.0 - (s - FDLayoutConstants.ADAPTATION_LOWER_NODE_LIMIT) / (FDLayoutConstants.ADAPTATION_UPPER_NODE_LIMIT - FDLayoutConstants.ADAPTATION_LOWER_NODE_LIMIT) * (1 - FDLayoutConstants.COOLING_ADAPTATION_FACTOR));
  2763. } else {
  2764. this.coolingFactor = 1.0;
  2765. }
  2766. this.initialCoolingFactor = this.coolingFactor;
  2767. this.maxNodeDisplacement = FDLayoutConstants.MAX_NODE_DISPLACEMENT;
  2768. }
  2769. this.maxIterations = Math.max(this.getAllNodes().length * 5, this.maxIterations);
  2770. this.totalDisplacementThreshold = this.displacementThresholdPerNode * this.getAllNodes().length;
  2771. this.repulsionRange = this.calcRepulsionRange();
  2772. };
  2773. FDLayout.prototype.calcSpringForces = function () {
  2774. var lEdges = this.getAllEdges();
  2775. var edge;
  2776. for (var i = 0; i < lEdges.length; i++) {
  2777. edge = lEdges[i];
  2778. this.calcSpringForce(edge, edge.idealLength);
  2779. }
  2780. };
  2781. FDLayout.prototype.calcRepulsionForces = function () {
  2782. var gridUpdateAllowed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  2783. var forceToNodeSurroundingUpdate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  2784. var i, j;
  2785. var nodeA, nodeB;
  2786. var lNodes = this.getAllNodes();
  2787. var processedNodeSet;
  2788. if (this.useFRGridVariant) {
  2789. if (this.totalIterations % FDLayoutConstants.GRID_CALCULATION_CHECK_PERIOD == 1 && gridUpdateAllowed) {
  2790. this.updateGrid();
  2791. }
  2792. processedNodeSet = new Set();
  2793. // calculate repulsion forces between each nodes and its surrounding
  2794. for (i = 0; i < lNodes.length; i++) {
  2795. nodeA = lNodes[i];
  2796. this.calculateRepulsionForceOfANode(nodeA, processedNodeSet, gridUpdateAllowed, forceToNodeSurroundingUpdate);
  2797. processedNodeSet.add(nodeA);
  2798. }
  2799. } else {
  2800. for (i = 0; i < lNodes.length; i++) {
  2801. nodeA = lNodes[i];
  2802. for (j = i + 1; j < lNodes.length; j++) {
  2803. nodeB = lNodes[j];
  2804. // If both nodes are not members of the same graph, skip.
  2805. if (nodeA.getOwner() != nodeB.getOwner()) {
  2806. continue;
  2807. }
  2808. this.calcRepulsionForce(nodeA, nodeB);
  2809. }
  2810. }
  2811. }
  2812. };
  2813. FDLayout.prototype.calcGravitationalForces = function () {
  2814. var node;
  2815. var lNodes = this.getAllNodesToApplyGravitation();
  2816. for (var i = 0; i < lNodes.length; i++) {
  2817. node = lNodes[i];
  2818. this.calcGravitationalForce(node);
  2819. }
  2820. };
  2821. FDLayout.prototype.moveNodes = function () {
  2822. var lNodes = this.getAllNodes();
  2823. var node;
  2824. for (var i = 0; i < lNodes.length; i++) {
  2825. node = lNodes[i];
  2826. node.move();
  2827. }
  2828. };
  2829. FDLayout.prototype.calcSpringForce = function (edge, idealLength) {
  2830. var sourceNode = edge.getSource();
  2831. var targetNode = edge.getTarget();
  2832. var length;
  2833. var springForce;
  2834. var springForceX;
  2835. var springForceY;
  2836. // Update edge length
  2837. if (this.uniformLeafNodeSizes && sourceNode.getChild() == null && targetNode.getChild() == null) {
  2838. edge.updateLengthSimple();
  2839. } else {
  2840. edge.updateLength();
  2841. if (edge.isOverlapingSourceAndTarget) {
  2842. return;
  2843. }
  2844. }
  2845. length = edge.getLength();
  2846. if (length == 0) return;
  2847. // Calculate spring forces
  2848. springForce = this.springConstant * (length - idealLength);
  2849. // Project force onto x and y axes
  2850. springForceX = springForce * (edge.lengthX / length);
  2851. springForceY = springForce * (edge.lengthY / length);
  2852. // Apply forces on the end nodes
  2853. sourceNode.springForceX += springForceX;
  2854. sourceNode.springForceY += springForceY;
  2855. targetNode.springForceX -= springForceX;
  2856. targetNode.springForceY -= springForceY;
  2857. };
  2858. FDLayout.prototype.calcRepulsionForce = function (nodeA, nodeB) {
  2859. var rectA = nodeA.getRect();
  2860. var rectB = nodeB.getRect();
  2861. var overlapAmount = new Array(2);
  2862. var clipPoints = new Array(4);
  2863. var distanceX;
  2864. var distanceY;
  2865. var distanceSquared;
  2866. var distance;
  2867. var repulsionForce;
  2868. var repulsionForceX;
  2869. var repulsionForceY;
  2870. if (rectA.intersects(rectB)) // two nodes overlap
  2871. {
  2872. // calculate separation amount in x and y directions
  2873. IGeometry.calcSeparationAmount(rectA, rectB, overlapAmount, FDLayoutConstants.DEFAULT_EDGE_LENGTH / 2.0);
  2874. repulsionForceX = 2 * overlapAmount[0];
  2875. repulsionForceY = 2 * overlapAmount[1];
  2876. var childrenConstant = nodeA.noOfChildren * nodeB.noOfChildren / (nodeA.noOfChildren + nodeB.noOfChildren);
  2877. // Apply forces on the two nodes
  2878. nodeA.repulsionForceX -= childrenConstant * repulsionForceX;
  2879. nodeA.repulsionForceY -= childrenConstant * repulsionForceY;
  2880. nodeB.repulsionForceX += childrenConstant * repulsionForceX;
  2881. nodeB.repulsionForceY += childrenConstant * repulsionForceY;
  2882. } else // no overlap
  2883. {
  2884. // calculate distance
  2885. if (this.uniformLeafNodeSizes && nodeA.getChild() == null && nodeB.getChild() == null) // simply base repulsion on distance of node centers
  2886. {
  2887. distanceX = rectB.getCenterX() - rectA.getCenterX();
  2888. distanceY = rectB.getCenterY() - rectA.getCenterY();
  2889. } else // use clipping points
  2890. {
  2891. IGeometry.getIntersection(rectA, rectB, clipPoints);
  2892. distanceX = clipPoints[2] - clipPoints[0];
  2893. distanceY = clipPoints[3] - clipPoints[1];
  2894. }
  2895. // No repulsion range. FR grid variant should take care of this.
  2896. if (Math.abs(distanceX) < FDLayoutConstants.MIN_REPULSION_DIST) {
  2897. distanceX = IMath.sign(distanceX) * FDLayoutConstants.MIN_REPULSION_DIST;
  2898. }
  2899. if (Math.abs(distanceY) < FDLayoutConstants.MIN_REPULSION_DIST) {
  2900. distanceY = IMath.sign(distanceY) * FDLayoutConstants.MIN_REPULSION_DIST;
  2901. }
  2902. distanceSquared = distanceX * distanceX + distanceY * distanceY;
  2903. distance = Math.sqrt(distanceSquared);
  2904. repulsionForce = this.repulsionConstant * nodeA.noOfChildren * nodeB.noOfChildren / distanceSquared;
  2905. // Project force onto x and y axes
  2906. repulsionForceX = repulsionForce * distanceX / distance;
  2907. repulsionForceY = repulsionForce * distanceY / distance;
  2908. // Apply forces on the two nodes
  2909. nodeA.repulsionForceX -= repulsionForceX;
  2910. nodeA.repulsionForceY -= repulsionForceY;
  2911. nodeB.repulsionForceX += repulsionForceX;
  2912. nodeB.repulsionForceY += repulsionForceY;
  2913. }
  2914. };
  2915. FDLayout.prototype.calcGravitationalForce = function (node) {
  2916. var ownerGraph;
  2917. var ownerCenterX;
  2918. var ownerCenterY;
  2919. var distanceX;
  2920. var distanceY;
  2921. var absDistanceX;
  2922. var absDistanceY;
  2923. var estimatedSize;
  2924. ownerGraph = node.getOwner();
  2925. ownerCenterX = (ownerGraph.getRight() + ownerGraph.getLeft()) / 2;
  2926. ownerCenterY = (ownerGraph.getTop() + ownerGraph.getBottom()) / 2;
  2927. distanceX = node.getCenterX() - ownerCenterX;
  2928. distanceY = node.getCenterY() - ownerCenterY;
  2929. absDistanceX = Math.abs(distanceX) + node.getWidth() / 2;
  2930. absDistanceY = Math.abs(distanceY) + node.getHeight() / 2;
  2931. if (node.getOwner() == this.graphManager.getRoot()) // in the root graph
  2932. {
  2933. estimatedSize = ownerGraph.getEstimatedSize() * this.gravityRangeFactor;
  2934. if (absDistanceX > estimatedSize || absDistanceY > estimatedSize) {
  2935. node.gravitationForceX = -this.gravityConstant * distanceX;
  2936. node.gravitationForceY = -this.gravityConstant * distanceY;
  2937. }
  2938. } else // inside a compound
  2939. {
  2940. estimatedSize = ownerGraph.getEstimatedSize() * this.compoundGravityRangeFactor;
  2941. if (absDistanceX > estimatedSize || absDistanceY > estimatedSize) {
  2942. node.gravitationForceX = -this.gravityConstant * distanceX * this.compoundGravityConstant;
  2943. node.gravitationForceY = -this.gravityConstant * distanceY * this.compoundGravityConstant;
  2944. }
  2945. }
  2946. };
  2947. FDLayout.prototype.isConverged = function () {
  2948. var converged;
  2949. var oscilating = false;
  2950. if (this.totalIterations > this.maxIterations / 3) {
  2951. oscilating = Math.abs(this.totalDisplacement - this.oldTotalDisplacement) < 2;
  2952. }
  2953. converged = this.totalDisplacement < this.totalDisplacementThreshold;
  2954. this.oldTotalDisplacement = this.totalDisplacement;
  2955. return converged || oscilating;
  2956. };
  2957. FDLayout.prototype.animate = function () {
  2958. if (this.animationDuringLayout && !this.isSubLayout) {
  2959. if (this.notAnimatedIterations == this.animationPeriod) {
  2960. this.update();
  2961. this.notAnimatedIterations = 0;
  2962. } else {
  2963. this.notAnimatedIterations++;
  2964. }
  2965. }
  2966. };
  2967. //This method calculates the number of children (weight) for all nodes
  2968. FDLayout.prototype.calcNoOfChildrenForAllNodes = function () {
  2969. var node;
  2970. var allNodes = this.graphManager.getAllNodes();
  2971. for (var i = 0; i < allNodes.length; i++) {
  2972. node = allNodes[i];
  2973. node.noOfChildren = node.getNoOfChildren();
  2974. }
  2975. };
  2976. // -----------------------------------------------------------------------------
  2977. // Section: FR-Grid Variant Repulsion Force Calculation
  2978. // -----------------------------------------------------------------------------
  2979. FDLayout.prototype.calcGrid = function (graph) {
  2980. var sizeX = 0;
  2981. var sizeY = 0;
  2982. sizeX = parseInt(Math.ceil((graph.getRight() - graph.getLeft()) / this.repulsionRange));
  2983. sizeY = parseInt(Math.ceil((graph.getBottom() - graph.getTop()) / this.repulsionRange));
  2984. var grid = new Array(sizeX);
  2985. for (var i = 0; i < sizeX; i++) {
  2986. grid[i] = new Array(sizeY);
  2987. }
  2988. for (var i = 0; i < sizeX; i++) {
  2989. for (var j = 0; j < sizeY; j++) {
  2990. grid[i][j] = new Array();
  2991. }
  2992. }
  2993. return grid;
  2994. };
  2995. FDLayout.prototype.addNodeToGrid = function (v, left, top) {
  2996. var startX = 0;
  2997. var finishX = 0;
  2998. var startY = 0;
  2999. var finishY = 0;
  3000. startX = parseInt(Math.floor((v.getRect().x - left) / this.repulsionRange));
  3001. finishX = parseInt(Math.floor((v.getRect().width + v.getRect().x - left) / this.repulsionRange));
  3002. startY = parseInt(Math.floor((v.getRect().y - top) / this.repulsionRange));
  3003. finishY = parseInt(Math.floor((v.getRect().height + v.getRect().y - top) / this.repulsionRange));
  3004. for (var i = startX; i <= finishX; i++) {
  3005. for (var j = startY; j <= finishY; j++) {
  3006. this.grid[i][j].push(v);
  3007. v.setGridCoordinates(startX, finishX, startY, finishY);
  3008. }
  3009. }
  3010. };
  3011. FDLayout.prototype.updateGrid = function () {
  3012. var i;
  3013. var nodeA;
  3014. var lNodes = this.getAllNodes();
  3015. this.grid = this.calcGrid(this.graphManager.getRoot());
  3016. // put all nodes to proper grid cells
  3017. for (i = 0; i < lNodes.length; i++) {
  3018. nodeA = lNodes[i];
  3019. this.addNodeToGrid(nodeA, this.graphManager.getRoot().getLeft(), this.graphManager.getRoot().getTop());
  3020. }
  3021. };
  3022. FDLayout.prototype.calculateRepulsionForceOfANode = function (nodeA, processedNodeSet, gridUpdateAllowed, forceToNodeSurroundingUpdate) {
  3023. if (this.totalIterations % FDLayoutConstants.GRID_CALCULATION_CHECK_PERIOD == 1 && gridUpdateAllowed || forceToNodeSurroundingUpdate) {
  3024. var surrounding = new Set();
  3025. nodeA.surrounding = new Array();
  3026. var nodeB;
  3027. var grid = this.grid;
  3028. for (var i = nodeA.startX - 1; i < nodeA.finishX + 2; i++) {
  3029. for (var j = nodeA.startY - 1; j < nodeA.finishY + 2; j++) {
  3030. if (!(i < 0 || j < 0 || i >= grid.length || j >= grid[0].length)) {
  3031. for (var k = 0; k < grid[i][j].length; k++) {
  3032. nodeB = grid[i][j][k];
  3033. // If both nodes are not members of the same graph,
  3034. // or both nodes are the same, skip.
  3035. if (nodeA.getOwner() != nodeB.getOwner() || nodeA == nodeB) {
  3036. continue;
  3037. }
  3038. // check if the repulsion force between
  3039. // nodeA and nodeB has already been calculated
  3040. if (!processedNodeSet.has(nodeB) && !surrounding.has(nodeB)) {
  3041. var distanceX = Math.abs(nodeA.getCenterX() - nodeB.getCenterX()) - (nodeA.getWidth() / 2 + nodeB.getWidth() / 2);
  3042. var distanceY = Math.abs(nodeA.getCenterY() - nodeB.getCenterY()) - (nodeA.getHeight() / 2 + nodeB.getHeight() / 2);
  3043. // if the distance between nodeA and nodeB
  3044. // is less then calculation range
  3045. if (distanceX <= this.repulsionRange && distanceY <= this.repulsionRange) {
  3046. //then add nodeB to surrounding of nodeA
  3047. surrounding.add(nodeB);
  3048. }
  3049. }
  3050. }
  3051. }
  3052. }
  3053. }
  3054. nodeA.surrounding = [].concat(_toConsumableArray(surrounding));
  3055. }
  3056. for (i = 0; i < nodeA.surrounding.length; i++) {
  3057. this.calcRepulsionForce(nodeA, nodeA.surrounding[i]);
  3058. }
  3059. };
  3060. FDLayout.prototype.calcRepulsionRange = function () {
  3061. return 0.0;
  3062. };
  3063. module.exports = FDLayout;
  3064. /***/ }),
  3065. /* 19 */
  3066. /***/ (function(module, exports, __webpack_require__) {
  3067. "use strict";
  3068. var LEdge = __webpack_require__(1);
  3069. var FDLayoutConstants = __webpack_require__(7);
  3070. function FDLayoutEdge(source, target, vEdge) {
  3071. LEdge.call(this, source, target, vEdge);
  3072. this.idealLength = FDLayoutConstants.DEFAULT_EDGE_LENGTH;
  3073. }
  3074. FDLayoutEdge.prototype = Object.create(LEdge.prototype);
  3075. for (var prop in LEdge) {
  3076. FDLayoutEdge[prop] = LEdge[prop];
  3077. }
  3078. module.exports = FDLayoutEdge;
  3079. /***/ }),
  3080. /* 20 */
  3081. /***/ (function(module, exports, __webpack_require__) {
  3082. "use strict";
  3083. var LNode = __webpack_require__(3);
  3084. function FDLayoutNode(gm, loc, size, vNode) {
  3085. // alternative constructor is handled inside LNode
  3086. LNode.call(this, gm, loc, size, vNode);
  3087. //Spring, repulsion and gravitational forces acting on this node
  3088. this.springForceX = 0;
  3089. this.springForceY = 0;
  3090. this.repulsionForceX = 0;
  3091. this.repulsionForceY = 0;
  3092. this.gravitationForceX = 0;
  3093. this.gravitationForceY = 0;
  3094. //Amount by which this node is to be moved in this iteration
  3095. this.displacementX = 0;
  3096. this.displacementY = 0;
  3097. //Start and finish grid coordinates that this node is fallen into
  3098. this.startX = 0;
  3099. this.finishX = 0;
  3100. this.startY = 0;
  3101. this.finishY = 0;
  3102. //Geometric neighbors of this node
  3103. this.surrounding = [];
  3104. }
  3105. FDLayoutNode.prototype = Object.create(LNode.prototype);
  3106. for (var prop in LNode) {
  3107. FDLayoutNode[prop] = LNode[prop];
  3108. }
  3109. FDLayoutNode.prototype.setGridCoordinates = function (_startX, _finishX, _startY, _finishY) {
  3110. this.startX = _startX;
  3111. this.finishX = _finishX;
  3112. this.startY = _startY;
  3113. this.finishY = _finishY;
  3114. };
  3115. module.exports = FDLayoutNode;
  3116. /***/ }),
  3117. /* 21 */
  3118. /***/ (function(module, exports, __webpack_require__) {
  3119. "use strict";
  3120. function DimensionD(width, height) {
  3121. this.width = 0;
  3122. this.height = 0;
  3123. if (width !== null && height !== null) {
  3124. this.height = height;
  3125. this.width = width;
  3126. }
  3127. }
  3128. DimensionD.prototype.getWidth = function () {
  3129. return this.width;
  3130. };
  3131. DimensionD.prototype.setWidth = function (width) {
  3132. this.width = width;
  3133. };
  3134. DimensionD.prototype.getHeight = function () {
  3135. return this.height;
  3136. };
  3137. DimensionD.prototype.setHeight = function (height) {
  3138. this.height = height;
  3139. };
  3140. module.exports = DimensionD;
  3141. /***/ }),
  3142. /* 22 */
  3143. /***/ (function(module, exports, __webpack_require__) {
  3144. "use strict";
  3145. var UniqueIDGeneretor = __webpack_require__(14);
  3146. function HashMap() {
  3147. this.map = {};
  3148. this.keys = [];
  3149. }
  3150. HashMap.prototype.put = function (key, value) {
  3151. var theId = UniqueIDGeneretor.createID(key);
  3152. if (!this.contains(theId)) {
  3153. this.map[theId] = value;
  3154. this.keys.push(key);
  3155. }
  3156. };
  3157. HashMap.prototype.contains = function (key) {
  3158. var theId = UniqueIDGeneretor.createID(key);
  3159. return this.map[key] != null;
  3160. };
  3161. HashMap.prototype.get = function (key) {
  3162. var theId = UniqueIDGeneretor.createID(key);
  3163. return this.map[theId];
  3164. };
  3165. HashMap.prototype.keySet = function () {
  3166. return this.keys;
  3167. };
  3168. module.exports = HashMap;
  3169. /***/ }),
  3170. /* 23 */
  3171. /***/ (function(module, exports, __webpack_require__) {
  3172. "use strict";
  3173. var UniqueIDGeneretor = __webpack_require__(14);
  3174. function HashSet() {
  3175. this.set = {};
  3176. }
  3177. ;
  3178. HashSet.prototype.add = function (obj) {
  3179. var theId = UniqueIDGeneretor.createID(obj);
  3180. if (!this.contains(theId)) this.set[theId] = obj;
  3181. };
  3182. HashSet.prototype.remove = function (obj) {
  3183. delete this.set[UniqueIDGeneretor.createID(obj)];
  3184. };
  3185. HashSet.prototype.clear = function () {
  3186. this.set = {};
  3187. };
  3188. HashSet.prototype.contains = function (obj) {
  3189. return this.set[UniqueIDGeneretor.createID(obj)] == obj;
  3190. };
  3191. HashSet.prototype.isEmpty = function () {
  3192. return this.size() === 0;
  3193. };
  3194. HashSet.prototype.size = function () {
  3195. return Object.keys(this.set).length;
  3196. };
  3197. //concats this.set to the given list
  3198. HashSet.prototype.addAllTo = function (list) {
  3199. var keys = Object.keys(this.set);
  3200. var length = keys.length;
  3201. for (var i = 0; i < length; i++) {
  3202. list.push(this.set[keys[i]]);
  3203. }
  3204. };
  3205. HashSet.prototype.size = function () {
  3206. return Object.keys(this.set).length;
  3207. };
  3208. HashSet.prototype.addAll = function (list) {
  3209. var s = list.length;
  3210. for (var i = 0; i < s; i++) {
  3211. var v = list[i];
  3212. this.add(v);
  3213. }
  3214. };
  3215. module.exports = HashSet;
  3216. /***/ }),
  3217. /* 24 */
  3218. /***/ (function(module, exports, __webpack_require__) {
  3219. "use strict";
  3220. 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; }; }();
  3221. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3222. /**
  3223. * A classic Quicksort algorithm with Hoare's partition
  3224. * - Works also on LinkedList objects
  3225. *
  3226. * Copyright: i-Vis Research Group, Bilkent University, 2007 - present
  3227. */
  3228. var LinkedList = __webpack_require__(11);
  3229. var Quicksort = function () {
  3230. function Quicksort(A, compareFunction) {
  3231. _classCallCheck(this, Quicksort);
  3232. if (compareFunction !== null || compareFunction !== undefined) this.compareFunction = this._defaultCompareFunction;
  3233. var length = void 0;
  3234. if (A instanceof LinkedList) length = A.size();else length = A.length;
  3235. this._quicksort(A, 0, length - 1);
  3236. }
  3237. _createClass(Quicksort, [{
  3238. key: '_quicksort',
  3239. value: function _quicksort(A, p, r) {
  3240. if (p < r) {
  3241. var q = this._partition(A, p, r);
  3242. this._quicksort(A, p, q);
  3243. this._quicksort(A, q + 1, r);
  3244. }
  3245. }
  3246. }, {
  3247. key: '_partition',
  3248. value: function _partition(A, p, r) {
  3249. var x = this._get(A, p);
  3250. var i = p;
  3251. var j = r;
  3252. while (true) {
  3253. while (this.compareFunction(x, this._get(A, j))) {
  3254. j--;
  3255. }while (this.compareFunction(this._get(A, i), x)) {
  3256. i++;
  3257. }if (i < j) {
  3258. this._swap(A, i, j);
  3259. i++;
  3260. j--;
  3261. } else return j;
  3262. }
  3263. }
  3264. }, {
  3265. key: '_get',
  3266. value: function _get(object, index) {
  3267. if (object instanceof LinkedList) return object.get_object_at(index);else return object[index];
  3268. }
  3269. }, {
  3270. key: '_set',
  3271. value: function _set(object, index, value) {
  3272. if (object instanceof LinkedList) object.set_object_at(index, value);else object[index] = value;
  3273. }
  3274. }, {
  3275. key: '_swap',
  3276. value: function _swap(A, i, j) {
  3277. var temp = this._get(A, i);
  3278. this._set(A, i, this._get(A, j));
  3279. this._set(A, j, temp);
  3280. }
  3281. }, {
  3282. key: '_defaultCompareFunction',
  3283. value: function _defaultCompareFunction(a, b) {
  3284. return b > a;
  3285. }
  3286. }]);
  3287. return Quicksort;
  3288. }();
  3289. module.exports = Quicksort;
  3290. /***/ }),
  3291. /* 25 */
  3292. /***/ (function(module, exports, __webpack_require__) {
  3293. "use strict";
  3294. 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; }; }();
  3295. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3296. /**
  3297. * Needleman-Wunsch algorithm is an procedure to compute the optimal global alignment of two string
  3298. * sequences by S.B.Needleman and C.D.Wunsch (1970).
  3299. *
  3300. * Aside from the inputs, you can assign the scores for,
  3301. * - Match: The two characters at the current index are same.
  3302. * - Mismatch: The two characters at the current index are different.
  3303. * - Insertion/Deletion(gaps): The best alignment involves one letter aligning to a gap in the other string.
  3304. */
  3305. var NeedlemanWunsch = function () {
  3306. function NeedlemanWunsch(sequence1, sequence2) {
  3307. var match_score = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
  3308. var mismatch_penalty = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : -1;
  3309. var gap_penalty = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : -1;
  3310. _classCallCheck(this, NeedlemanWunsch);
  3311. this.sequence1 = sequence1;
  3312. this.sequence2 = sequence2;
  3313. this.match_score = match_score;
  3314. this.mismatch_penalty = mismatch_penalty;
  3315. this.gap_penalty = gap_penalty;
  3316. // Just the remove redundancy
  3317. this.iMax = sequence1.length + 1;
  3318. this.jMax = sequence2.length + 1;
  3319. // Grid matrix of scores
  3320. this.grid = new Array(this.iMax);
  3321. for (var i = 0; i < this.iMax; i++) {
  3322. this.grid[i] = new Array(this.jMax);
  3323. for (var j = 0; j < this.jMax; j++) {
  3324. this.grid[i][j] = 0;
  3325. }
  3326. }
  3327. // Traceback matrix (2D array, each cell is an array of boolean values for [`Diag`, `Up`, `Left`] positions)
  3328. this.tracebackGrid = new Array(this.iMax);
  3329. for (var _i = 0; _i < this.iMax; _i++) {
  3330. this.tracebackGrid[_i] = new Array(this.jMax);
  3331. for (var _j = 0; _j < this.jMax; _j++) {
  3332. this.tracebackGrid[_i][_j] = [null, null, null];
  3333. }
  3334. }
  3335. // The aligned sequences (return multiple possibilities)
  3336. this.alignments = [];
  3337. // Final alignment score
  3338. this.score = -1;
  3339. // Calculate scores and tracebacks
  3340. this.computeGrids();
  3341. }
  3342. _createClass(NeedlemanWunsch, [{
  3343. key: "getScore",
  3344. value: function getScore() {
  3345. return this.score;
  3346. }
  3347. }, {
  3348. key: "getAlignments",
  3349. value: function getAlignments() {
  3350. return this.alignments;
  3351. }
  3352. // Main dynamic programming procedure
  3353. }, {
  3354. key: "computeGrids",
  3355. value: function computeGrids() {
  3356. // Fill in the first row
  3357. for (var j = 1; j < this.jMax; j++) {
  3358. this.grid[0][j] = this.grid[0][j - 1] + this.gap_penalty;
  3359. this.tracebackGrid[0][j] = [false, false, true];
  3360. }
  3361. // Fill in the first column
  3362. for (var i = 1; i < this.iMax; i++) {
  3363. this.grid[i][0] = this.grid[i - 1][0] + this.gap_penalty;
  3364. this.tracebackGrid[i][0] = [false, true, false];
  3365. }
  3366. // Fill the rest of the grid
  3367. for (var _i2 = 1; _i2 < this.iMax; _i2++) {
  3368. for (var _j2 = 1; _j2 < this.jMax; _j2++) {
  3369. // Find the max score(s) among [`Diag`, `Up`, `Left`]
  3370. var diag = void 0;
  3371. if (this.sequence1[_i2 - 1] === this.sequence2[_j2 - 1]) diag = this.grid[_i2 - 1][_j2 - 1] + this.match_score;else diag = this.grid[_i2 - 1][_j2 - 1] + this.mismatch_penalty;
  3372. var up = this.grid[_i2 - 1][_j2] + this.gap_penalty;
  3373. var left = this.grid[_i2][_j2 - 1] + this.gap_penalty;
  3374. // If there exists multiple max values, capture them for multiple paths
  3375. var maxOf = [diag, up, left];
  3376. var indices = this.arrayAllMaxIndexes(maxOf);
  3377. // Update Grids
  3378. this.grid[_i2][_j2] = maxOf[indices[0]];
  3379. this.tracebackGrid[_i2][_j2] = [indices.includes(0), indices.includes(1), indices.includes(2)];
  3380. }
  3381. }
  3382. // Update alignment score
  3383. this.score = this.grid[this.iMax - 1][this.jMax - 1];
  3384. }
  3385. // Gets all possible valid sequence combinations
  3386. }, {
  3387. key: "alignmentTraceback",
  3388. value: function alignmentTraceback() {
  3389. var inProcessAlignments = [];
  3390. inProcessAlignments.push({ pos: [this.sequence1.length, this.sequence2.length],
  3391. seq1: "",
  3392. seq2: ""
  3393. });
  3394. while (inProcessAlignments[0]) {
  3395. var current = inProcessAlignments[0];
  3396. var directions = this.tracebackGrid[current.pos[0]][current.pos[1]];
  3397. if (directions[0]) {
  3398. inProcessAlignments.push({ pos: [current.pos[0] - 1, current.pos[1] - 1],
  3399. seq1: this.sequence1[current.pos[0] - 1] + current.seq1,
  3400. seq2: this.sequence2[current.pos[1] - 1] + current.seq2
  3401. });
  3402. }
  3403. if (directions[1]) {
  3404. inProcessAlignments.push({ pos: [current.pos[0] - 1, current.pos[1]],
  3405. seq1: this.sequence1[current.pos[0] - 1] + current.seq1,
  3406. seq2: '-' + current.seq2
  3407. });
  3408. }
  3409. if (directions[2]) {
  3410. inProcessAlignments.push({ pos: [current.pos[0], current.pos[1] - 1],
  3411. seq1: '-' + current.seq1,
  3412. seq2: this.sequence2[current.pos[1] - 1] + current.seq2
  3413. });
  3414. }
  3415. if (current.pos[0] === 0 && current.pos[1] === 0) this.alignments.push({ sequence1: current.seq1,
  3416. sequence2: current.seq2
  3417. });
  3418. inProcessAlignments.shift();
  3419. }
  3420. return this.alignments;
  3421. }
  3422. // Helper Functions
  3423. }, {
  3424. key: "getAllIndexes",
  3425. value: function getAllIndexes(arr, val) {
  3426. var indexes = [],
  3427. i = -1;
  3428. while ((i = arr.indexOf(val, i + 1)) !== -1) {
  3429. indexes.push(i);
  3430. }
  3431. return indexes;
  3432. }
  3433. }, {
  3434. key: "arrayAllMaxIndexes",
  3435. value: function arrayAllMaxIndexes(array) {
  3436. return this.getAllIndexes(array, Math.max.apply(null, array));
  3437. }
  3438. }]);
  3439. return NeedlemanWunsch;
  3440. }();
  3441. module.exports = NeedlemanWunsch;
  3442. /***/ }),
  3443. /* 26 */
  3444. /***/ (function(module, exports, __webpack_require__) {
  3445. "use strict";
  3446. var layoutBase = function layoutBase() {
  3447. return;
  3448. };
  3449. layoutBase.FDLayout = __webpack_require__(18);
  3450. layoutBase.FDLayoutConstants = __webpack_require__(7);
  3451. layoutBase.FDLayoutEdge = __webpack_require__(19);
  3452. layoutBase.FDLayoutNode = __webpack_require__(20);
  3453. layoutBase.DimensionD = __webpack_require__(21);
  3454. layoutBase.HashMap = __webpack_require__(22);
  3455. layoutBase.HashSet = __webpack_require__(23);
  3456. layoutBase.IGeometry = __webpack_require__(8);
  3457. layoutBase.IMath = __webpack_require__(9);
  3458. layoutBase.Integer = __webpack_require__(10);
  3459. layoutBase.Point = __webpack_require__(12);
  3460. layoutBase.PointD = __webpack_require__(4);
  3461. layoutBase.RandomSeed = __webpack_require__(16);
  3462. layoutBase.RectangleD = __webpack_require__(13);
  3463. layoutBase.Transform = __webpack_require__(17);
  3464. layoutBase.UniqueIDGeneretor = __webpack_require__(14);
  3465. layoutBase.Quicksort = __webpack_require__(24);
  3466. layoutBase.LinkedList = __webpack_require__(11);
  3467. layoutBase.LGraphObject = __webpack_require__(2);
  3468. layoutBase.LGraph = __webpack_require__(5);
  3469. layoutBase.LEdge = __webpack_require__(1);
  3470. layoutBase.LGraphManager = __webpack_require__(6);
  3471. layoutBase.LNode = __webpack_require__(3);
  3472. layoutBase.Layout = __webpack_require__(15);
  3473. layoutBase.LayoutConstants = __webpack_require__(0);
  3474. layoutBase.NeedlemanWunsch = __webpack_require__(25);
  3475. module.exports = layoutBase;
  3476. /***/ }),
  3477. /* 27 */
  3478. /***/ (function(module, exports, __webpack_require__) {
  3479. "use strict";
  3480. function Emitter() {
  3481. this.listeners = [];
  3482. }
  3483. var p = Emitter.prototype;
  3484. p.addListener = function (event, callback) {
  3485. this.listeners.push({
  3486. event: event,
  3487. callback: callback
  3488. });
  3489. };
  3490. p.removeListener = function (event, callback) {
  3491. for (var i = this.listeners.length; i >= 0; i--) {
  3492. var l = this.listeners[i];
  3493. if (l.event === event && l.callback === callback) {
  3494. this.listeners.splice(i, 1);
  3495. }
  3496. }
  3497. };
  3498. p.emit = function (event, data) {
  3499. for (var i = 0; i < this.listeners.length; i++) {
  3500. var l = this.listeners[i];
  3501. if (event === l.event) {
  3502. l.callback(data);
  3503. }
  3504. }
  3505. };
  3506. module.exports = Emitter;
  3507. /***/ })
  3508. /******/ ]);
  3509. });