mxGraphMlCodec.js 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135
  1. function mxGraphMlCodec()
  2. {
  3. this.cachedRefObj = {};
  4. };
  5. mxGraphMlCodec.prototype.refRegexp = /^\{y\:GraphMLReference\s+(\d+)\}$/;
  6. mxGraphMlCodec.prototype.staticRegexp = /^\{x\:Static\s+(.+)\.(.+)\}$/;
  7. mxGraphMlCodec.prototype.decode = function (xml, callback, onError)
  8. {
  9. try
  10. {
  11. var doc = mxUtils.parseXml(xml);
  12. var graphs = this.getDirectChildNamedElements(doc.documentElement, mxGraphMlConstants.GRAPH);
  13. this.initializeKeys(doc.documentElement);
  14. var mxFile = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><mxfile>";
  15. for (var i = 0; i < graphs.length; i++)
  16. {
  17. var pageElement = graphs[i];
  18. var graph = this.createMxGraph();
  19. var model = graph.getModel();
  20. model.beginUpdate();
  21. try
  22. {
  23. this.nodesMap = {};
  24. this.edges = [];
  25. this.importGraph(pageElement, graph, graph.getDefaultParent());
  26. for (var i = 0; i < this.edges.length; i++)
  27. {
  28. var edgesObj = this.edges[i];
  29. var edges = edgesObj.edges;
  30. var parent = edgesObj.parent;
  31. var dx = edgesObj.dx, dy = edgesObj.dy;
  32. for (var j = 0; j < edges.length; j++)
  33. {
  34. this.importEdge(edges[j], graph, parent, dx, dy);
  35. }
  36. }
  37. }
  38. catch(e)
  39. {
  40. console.log(e);
  41. throw e;
  42. }
  43. finally
  44. {
  45. model.endUpdate();
  46. }
  47. //update edges' labels to convert their labels relative coordinate to ours
  48. model.beginUpdate();
  49. try
  50. {
  51. var cells = graph.getModel().cells;
  52. var tr = graph.view.translate;
  53. for (var id in cells)
  54. {
  55. var edge = cells[id];
  56. if (edge.edge && edge.getChildCount() > 0)
  57. {
  58. for (var i = 0; i < edge.getChildCount(); i++)
  59. {
  60. var cell = edge.children[i];
  61. var geo = cell.geometry;
  62. if (!geo.adjustIt) continue;
  63. var state = graph.view.getState(edge);
  64. var abdPs = state.absolutePoints;
  65. var p0 = abdPs[0];
  66. var pe = abdPs[abdPs.length - 1];
  67. var ratio = geo.x;
  68. var dist = geo.y;
  69. var dx = pe.x - p0.x
  70. var dy = pe.y - p0.y
  71. var x = p0.x + ratio * dx;
  72. var y = p0.y + ratio * dy;
  73. var d = Math.sqrt(dx*dx + dy*dy);
  74. dx /= d;
  75. dy /= d;
  76. x -= dist * dy;
  77. y += dist * dx;
  78. var np = graph.view.getRelativePoint(state, x, y);
  79. geo.x = np.x;
  80. geo.y = np.y;
  81. }
  82. }
  83. }
  84. }
  85. catch(e)
  86. {
  87. console.log(e);
  88. throw e;
  89. }
  90. finally
  91. {
  92. model.endUpdate();
  93. }
  94. mxFile += this.processPage(graph, i+1);
  95. }
  96. mxFile += "</mxfile>";
  97. if (callback)
  98. {
  99. callback(mxFile);
  100. }
  101. }
  102. catch(e)
  103. {
  104. if (onError)
  105. {
  106. onError(e);
  107. }
  108. }
  109. };
  110. mxGraphMlCodec.prototype.initializeKeys = function (graphmlElement)
  111. {
  112. var keys = this.getDirectChildNamedElements(graphmlElement, mxGraphMlConstants.KEY);
  113. this.nodesKeys = {};
  114. this.edgesKeys = {};
  115. this.portsKeys = {};
  116. this.sharedData = {};
  117. this.nodesKeys[mxGraphMlConstants.NODE_GEOMETRY] = {};
  118. this.nodesKeys[mxGraphMlConstants.USER_TAGS] = {};
  119. this.nodesKeys[mxGraphMlConstants.NODE_STYLE] = {};
  120. this.nodesKeys[mxGraphMlConstants.NODE_LABELS] = {};
  121. this.nodesKeys[mxGraphMlConstants.NODE_GRAPHICS] = {};
  122. this.edgesKeys[mxGraphMlConstants.EDGE_GEOMETRY] = {};
  123. this.edgesKeys[mxGraphMlConstants.EDGE_STYLE] = {};
  124. this.edgesKeys[mxGraphMlConstants.EDGE_LABELS] = {};
  125. this.portsKeys[mxGraphMlConstants.PORT_LOCATION_PARAMETER] = {};
  126. this.portsKeys[mxGraphMlConstants.PORT_STYLE] = {};
  127. this.portsKeys[mxGraphMlConstants.PORT_VIEW_STATE] = {};
  128. var sharedDataId;
  129. for (var i = 0; i < keys.length; i++)
  130. {
  131. var keyObj = this.dataElem2Obj(keys[i]);
  132. var id = keyObj[mxGraphMlConstants.ID];
  133. var _for = keyObj[mxGraphMlConstants.KEY_FOR];
  134. var attName = keyObj[mxGraphMlConstants.KEY_NAME];
  135. var yType = keyObj[mxGraphMlConstants.KEY_YTYPE];
  136. if (attName == mxGraphMlConstants.SHARED_DATA) sharedDataId = id;
  137. attName = attName? attName : yType
  138. //TODO handle the defaults inside these keys
  139. switch (_for)
  140. {
  141. case mxGraphMlConstants.NODE:
  142. this.nodesKeys[attName] = {key: id, keyObj: keyObj};
  143. break;
  144. case mxGraphMlConstants.EDGE:
  145. this.edgesKeys[attName] = {key: id, keyObj: keyObj};
  146. break;
  147. case mxGraphMlConstants.PORT:
  148. this.portsKeys[attName] = {key: id, keyObj: keyObj};
  149. break;
  150. case mxGraphMlConstants.ALL:
  151. var obj = {key: id, keyObj: keyObj};
  152. this.nodesKeys[attName] = obj;
  153. this.edgesKeys[attName] = obj;
  154. this.portsKeys[attName] = obj;
  155. break;
  156. }
  157. }
  158. var data = this.getDirectChildNamedElements(graphmlElement, mxGraphMlConstants.DATA);
  159. for (var i = 0; i < data.length; i++)
  160. {
  161. var key = data[i].getAttribute(mxGraphMlConstants.KEY);
  162. if (key == sharedDataId)
  163. {
  164. var sharedData = this.getDirectChildNamedElements(data[i], mxGraphMlConstants.Y_SHARED_DATA);
  165. for (var j = 0; j < sharedData.length; j++)
  166. {
  167. var dataItems = this.getDirectChildElements(sharedData[j]);
  168. for (var k = 0; k < dataItems.length; k++)
  169. {
  170. var dkey = dataItems[k].getAttribute(mxGraphMlConstants.X_KEY);
  171. this.sharedData[dkey] = dataItems[k];
  172. }
  173. }
  174. }
  175. else
  176. {
  177. var resources = this.getDirectChildNamedElements(data[i], mxGraphMlConstants.Y_RESOURCES);
  178. for (var j = 0; j < resources.length; j++)
  179. {
  180. var dataItems = this.getDirectChildElements(resources[j]);
  181. for (var k = 0; k < dataItems.length; k++)
  182. {
  183. var dkey = dataItems[k].getAttribute(mxGraphMlConstants.ID);
  184. this.sharedData[dkey] = dataItems[k];
  185. }
  186. }
  187. }
  188. }
  189. };
  190. mxGraphMlCodec.prototype.parseAttributes = function (elem, obj)
  191. {
  192. var atts = elem.attributes;
  193. if (atts)
  194. {
  195. for (var i = 0; i < atts.length; i++)
  196. {
  197. var val = atts[i].nodeValue;
  198. var ref = this.refRegexp.exec(val);
  199. var staticMem = this.staticRegexp.exec(val);
  200. if (ref)
  201. {
  202. var key = ref[1];
  203. var subObj = this.cachedRefObj[key];
  204. //already cached
  205. if (!subObj)
  206. {
  207. subObj = {};
  208. subObj[this.sharedData[key].nodeName] = this.dataElem2Obj(this.sharedData[key]);
  209. this.cachedRefObj[key] = subObj;
  210. }
  211. obj[atts[i].nodeName] = subObj;
  212. }
  213. else if (staticMem)
  214. {
  215. obj[atts[i].nodeName] = {};
  216. obj[atts[i].nodeName][staticMem[1]] = staticMem[2];
  217. }
  218. else
  219. {
  220. obj[atts[i].nodeName] = val;
  221. }
  222. }
  223. }
  224. };
  225. mxGraphMlCodec.prototype.dataElem2Obj = function (elem)
  226. {
  227. var ref = this.getDirectFirstChildNamedElements(elem, mxGraphMlConstants.GRAPHML_REFERENCE)
  228. || elem.getAttribute(mxGraphMlConstants.REFID);
  229. var refKey = null;
  230. var origElem = elem;
  231. var obj = {};
  232. if (ref)
  233. {
  234. var key = (typeof ref === "string")? ref : ref.getAttribute(mxGraphMlConstants.RESOURCE_KEY);
  235. var cachedObj = this.cachedRefObj[key];
  236. //already cached
  237. if (cachedObj)
  238. {
  239. //parse all attributes to update the reference
  240. this.parseAttributes(elem, cachedObj);
  241. return cachedObj;
  242. }
  243. elem = this.sharedData[key];
  244. refKey = key;
  245. }
  246. //parse all attributes
  247. this.parseAttributes(elem, obj);
  248. for (var i = 0; i < elem.childNodes.length; i++)
  249. {
  250. var child = elem.childNodes[i];
  251. if (child.nodeType == 1)
  252. {
  253. var attName = child.nodeName;
  254. //Special types of node (x:List and x:Static)
  255. if (attName == mxGraphMlConstants.X_LIST)
  256. {
  257. var arr = [];
  258. var arrayElem = this.getDirectChildElements(child);
  259. for (var j = 0; j < arrayElem.length; j++)
  260. {
  261. attName = arrayElem[j].nodeName;
  262. arr.push(this.dataElem2Obj(arrayElem[j]));
  263. }
  264. obj[attName] = arr;
  265. }
  266. else if (attName == mxGraphMlConstants.X_STATIC)
  267. {
  268. var member = child.getAttribute(mxGraphMlConstants.MEMBER);
  269. var dotPos = member.lastIndexOf('.');
  270. obj[member.substr(0, dotPos)] = member.substr(dotPos + 1);
  271. }
  272. else
  273. {
  274. var dotPos = attName.lastIndexOf(".");
  275. if (dotPos > 0)
  276. {
  277. attName = attName.substr(dotPos + 1);
  278. }
  279. if (obj[attName] != null)
  280. {
  281. if (!(obj[attName] instanceof Array))
  282. {
  283. obj[attName] = [obj[attName]];
  284. }
  285. obj[attName].push(this.dataElem2Obj(child));
  286. }
  287. else
  288. {
  289. obj[attName] = this.dataElem2Obj(child);
  290. }
  291. }
  292. }
  293. else if ((child.nodeType == 3 || child.nodeType == 4) && child.textContent.trim())
  294. {
  295. obj["#text"] = child.textContent;
  296. }
  297. }
  298. //cache referenced objects
  299. if (refKey)
  300. {
  301. var tmpObj = {};
  302. //parse all attributes before following the reference
  303. this.parseAttributes(origElem, tmpObj);
  304. tmpObj[this.sharedData[refKey].nodeName] = obj;
  305. this.cachedRefObj[refKey] = tmpObj;
  306. return tmpObj;
  307. }
  308. return obj;
  309. };
  310. mxGraphMlCodec.prototype.mapArray = function(arr, mapping, map)
  311. {
  312. var obj = {};
  313. for (var k = 0; k < arr.length; k++)
  314. {
  315. if (arr[k].name)
  316. {
  317. obj[arr[k].name] = arr[k].value || arr[k];
  318. }
  319. }
  320. this.mapObject(obj, mapping, map);
  321. }
  322. //Use mapping information to fill the map based on obj content
  323. //TODO yjs looks like they need special handling
  324. mxGraphMlCodec.prototype.mapObject = function (obj, mapping, map)
  325. {
  326. //defaults can be overridden by actual values later
  327. if (mapping.defaults)
  328. {
  329. for (var key in mapping.defaults)
  330. {
  331. map[key] = mapping.defaults[key];
  332. }
  333. }
  334. for (var key in mapping)
  335. {
  336. var parts = key.split('.');
  337. var val = obj;
  338. for (var i = 0; i < parts.length; i++)
  339. {
  340. if (!val) break;
  341. val = val[parts[i]];
  342. }
  343. if (val == null && obj) //some vals doesn't need to be split
  344. {
  345. val = obj[key];
  346. }
  347. if (val != null)
  348. {
  349. var mappingObj = mapping[key];
  350. if (typeof val === "string")
  351. {
  352. if (typeof mappingObj === "string")
  353. {
  354. map[mappingObj] = val.toLowerCase();
  355. }
  356. else if (typeof mappingObj === "object")
  357. {
  358. var modVal = val.toLowerCase();
  359. switch(mappingObj.mod)
  360. {
  361. case "color": //mxGraph support alfa in colors in the standard format
  362. if (val.indexOf("#") == 0 && val.length == 9)
  363. {
  364. modVal = "#" + val.substr(3) + val.substr(1,2);
  365. }
  366. else if (val == "TRANSPARENT")
  367. {
  368. modVal = "none";
  369. }
  370. break;
  371. case "shape":
  372. // console.log(val.toLowerCase());
  373. modVal = mxGraphMlShapesMap[val.toLowerCase()];
  374. break;
  375. case "bpmnOutline":
  376. // console.log(val.toLowerCase());
  377. modVal = mxGraphMlShapesMap.bpmnOutline[val.toLowerCase()];
  378. break;
  379. case "bpmnSymbol":
  380. // console.log(val.toLowerCase());
  381. modVal = mxGraphMlShapesMap.bpmnSymbol[val.toLowerCase()];
  382. break;
  383. case "bool":
  384. modVal = val == "true"? "1" : "0";
  385. break;
  386. case "scale":
  387. try {
  388. modVal = parseFloat(val) * mappingObj.scale;
  389. } catch(e) {
  390. //nothing!
  391. }
  392. break;
  393. case "arrow":
  394. modVal = mxGraphMlArrowsMap[val];
  395. break;
  396. }
  397. if (modVal != null)
  398. map[mappingObj.key] = modVal;
  399. }
  400. else
  401. {
  402. mappingObj(val, map);
  403. }
  404. }
  405. else if (val instanceof Array)
  406. {
  407. this.mapArray(val, mappingObj, map);
  408. }
  409. else if (val.name != null && val.value != null) //this is the case when a single y:Property is used
  410. {
  411. this.mapArray([val], mappingObj, map);
  412. }
  413. else
  414. {
  415. this.mapObject(val, mappingObj, map);
  416. }
  417. }
  418. }
  419. };
  420. mxGraphMlCodec.prototype.createMxGraph = function ()
  421. {
  422. var graph = new mxGraph();
  423. // graph.setExtendParents(false);
  424. // graph.setExtendParentsOnAdd(false);
  425. // graph.setConstrainChildren(false);
  426. // graph.setHtmlLabels(true);
  427. // graph.getModel().maintainEdgeParent = false;
  428. return graph;
  429. }
  430. mxGraphMlCodec.prototype.importGraph = function (pageElement, graph, parent)
  431. {
  432. var nodes = this.getDirectChildNamedElements(pageElement, mxGraphMlConstants.NODE);
  433. var p = parent;
  434. var dx = 0, dy = 0;
  435. while (p && p.geometry)
  436. {
  437. dx += p.geometry.x;
  438. dy += p.geometry.y;
  439. p = p.parent;
  440. }
  441. for (var i = 0; i < nodes.length; i++)
  442. {
  443. this.importNode(nodes[i], graph, parent, dx, dy);
  444. }
  445. this.edges.push({
  446. edges: this.getDirectChildNamedElements(pageElement, mxGraphMlConstants.EDGE),
  447. parent: parent,
  448. dx: dx,
  449. dy: dy
  450. });
  451. };
  452. //FIXME port 0.5, 0.5 push the edge to the other side (bpmn example)
  453. mxGraphMlCodec.prototype.importPort = function (portElement, portsMap)
  454. {
  455. var name = portElement.getAttribute(mxGraphMlConstants.PORT_NAME);
  456. var portObj = {};
  457. var data = this.getDirectChildNamedElements(portElement, mxGraphMlConstants.DATA);
  458. for (var i = 0; i < data.length; i++)
  459. {
  460. var d = data[i];
  461. var key = d.getAttribute(mxGraphMlConstants.KEY);
  462. var dataObj = this.dataElem2Obj(d);
  463. // console.log(dataObj);
  464. if (dataObj.key == this.portsKeys[mxGraphMlConstants.PORT_LOCATION_PARAMETER].key)
  465. {
  466. this.mapObject(dataObj, {
  467. "y:FreeNodePortLocationModelParameter.Ratio": function(val, map)
  468. {
  469. var parts = val.split(',');
  470. map["pos"] = {x: parts[0], y: parts[1]};
  471. }
  472. }, portObj);
  473. }
  474. /*
  475. else if (dataObj.key == this.portsKeys[mxGraphMlConstants.PORT_STYLE].key)
  476. {
  477. }
  478. else if (dataObj.key == this.portsKeys[mxGraphMlConstants.PORT_VIEW_STATE].key)
  479. {
  480. }*/
  481. }
  482. portsMap[name] = portObj;
  483. };
  484. mxGraphMlCodec.prototype.styleMap2Str = function (styleMap)
  485. {
  486. var semi = "";
  487. var str = "";
  488. for (var key in styleMap)
  489. {
  490. str += semi + key + "=" + styleMap[key];
  491. semi = ";";
  492. }
  493. return str;
  494. };
  495. mxGraphMlCodec.prototype.importNode = function (nodeElement, graph, parent, dx, dy)
  496. {
  497. var data = this.getDirectChildNamedElements(nodeElement, mxGraphMlConstants.DATA);
  498. var v;
  499. var id = nodeElement.getAttribute(mxGraphMlConstants.ID);
  500. var node = new mxCell();
  501. node.vertex = true;
  502. node.geometry = new mxGeometry(0,0,30,30); //some node has no geometry, this is the default
  503. graph.addCell(node, parent);
  504. var style = {graphMlID: id};
  505. var mlStyleObj = null;
  506. var mlTemplate = null;
  507. var mlUserTags = null;
  508. var lblObj = null;
  509. var lbls = null;
  510. for (var i = 0; i < data.length; i++)
  511. {
  512. var d = data[i];
  513. var dataObj = this.dataElem2Obj(d);
  514. if (dataObj.key)
  515. {
  516. if (dataObj.key == this.nodesKeys[mxGraphMlConstants.NODE_GEOMETRY].key)
  517. {
  518. this.addNodeGeo(node, dataObj, dx, dy);
  519. }
  520. else if (dataObj.key == this.nodesKeys[mxGraphMlConstants.USER_TAGS].key)
  521. {
  522. mlUserTags = dataObj;
  523. }
  524. else if (dataObj.key == this.nodesKeys[mxGraphMlConstants.NODE_STYLE].key)
  525. {
  526. // console.log(JSON.stringify(dataObj));
  527. mlStyleObj = dataObj;
  528. if (dataObj["yjs:StringTemplateNodeStyle"])
  529. {
  530. mlTemplate = dataObj["yjs:StringTemplateNodeStyle"]["#text"];
  531. }
  532. else
  533. {
  534. this.addNodeStyle(node, dataObj, style);
  535. }
  536. }
  537. else if (dataObj.key == this.nodesKeys[mxGraphMlConstants.NODE_LABELS].key)
  538. {
  539. lblObj = dataObj;
  540. }
  541. else if (dataObj.key == this.nodesKeys[mxGraphMlConstants.NODE_GRAPHICS].key)
  542. {
  543. var shape = null, key = null;
  544. for (var key in dataObj)
  545. {
  546. if (key == "key" || key == "#text") continue;
  547. //Special case when a node has multiple graphics
  548. //TODO support the open/closed states
  549. if (key == "y:ProxyAutoBoundsNode")
  550. {
  551. var realizers = dataObj[key]["y:Realizers"];
  552. if (realizers)
  553. {
  554. for (var key2 in realizers)
  555. {
  556. if (key2 == "active" || key2 == "#text") continue;
  557. shape = realizers[key2][realizers["active"]];
  558. dataObj = {};
  559. dataObj[key2] = shape;
  560. break;
  561. }
  562. }
  563. }
  564. else
  565. {
  566. shape = dataObj[key];
  567. }
  568. break;
  569. }
  570. if (shape)
  571. {
  572. if (shape[mxGraphMlConstants.GEOMETRY])
  573. {
  574. this.addNodeGeo(node, shape[mxGraphMlConstants.GEOMETRY], dx, dy);
  575. }
  576. if (shape[mxGraphMlConstants.NODE_LABEL])
  577. {
  578. lblObj = shape[mxGraphMlConstants.NODE_LABEL];
  579. }
  580. }
  581. mlStyleObj = dataObj;
  582. this.addNodeStyle(node, dataObj, style);
  583. }
  584. }
  585. }
  586. var ports = this.getDirectChildNamedElements(nodeElement, mxGraphMlConstants.PORT);
  587. var portsMap = {};
  588. for (var i = 0; i < ports.length; i++)
  589. {
  590. this.importPort(ports[i], portsMap);
  591. }
  592. if (mlTemplate)
  593. {
  594. this.handleTemplates(mlTemplate, mlUserTags, node, style);
  595. }
  596. this.handleFixedRatio(node, style);
  597. //handle special compound shapes
  598. this.handleCompoundShape(node, style, mlStyleObj, lbls);
  599. //fix for stroke size of zero
  600. if (style["strokeWidth"] == 0)
  601. {
  602. style["strokeColor"] = "none";
  603. }
  604. node.style = this.styleMap2Str(style);
  605. var subGraphs = this.getDirectChildNamedElements(nodeElement, mxGraphMlConstants.GRAPH);
  606. for (var i = 0; i < subGraphs.length; i++)
  607. {
  608. this.importGraph(subGraphs[i], graph, node, portsMap);
  609. }
  610. //handle labels after node geometry is determined. It is also the last such that labels are on top
  611. if (lblObj)
  612. lbls = this.addLabels(node, lblObj, style, graph);
  613. this.nodesMap[id] = {node: node, ports: portsMap};
  614. };
  615. mxGraphMlCodec.prototype.addNodeStyle = function (node, dataObj, style)
  616. {
  617. //TODO move these static mapping objects outside such that they are defined once only
  618. var dashStyleFn = function(val, map)
  619. {
  620. if (val == "line") return;
  621. map["dashed"] = 1;
  622. //map["fixDash"] = 1;
  623. var pattern = null;
  624. switch(val)
  625. {
  626. case "DashDot":
  627. pattern = "3 1 1 1";
  628. break;
  629. case "Dot":
  630. pattern = "1 1";
  631. break;
  632. case "DashDotDot":
  633. pattern = "3 1 1 1 1 1";
  634. break;
  635. case "Dash":
  636. pattern = "3 1";
  637. break;
  638. case "dotted":
  639. pattern = "1 3";
  640. break;
  641. case "dashed":
  642. pattern = "5 2";
  643. break;
  644. default:
  645. pattern = val.replace(/0/g, '1');
  646. }
  647. if (pattern)
  648. {
  649. //Some patterns in graphML has only one number
  650. if (pattern.indexOf(" ") < 0)
  651. {
  652. pattern = pattern + " " + pattern;
  653. }
  654. map["dashPattern"] = pattern;
  655. }
  656. };
  657. var styleCommonMap =
  658. {
  659. "shape": {key: "shape", mod: "shape"},
  660. "y:Shape.type": {key: "shape", mod: "shape"},
  661. "configuration": {key: "shape", mod: "shape"},
  662. "type": {key: "shape", mod: "shape"},
  663. "assetName": {key: "shape", mod: "shape"},
  664. "activityType": {key: "shape", mod: "shape"},
  665. "fill": {key: "fillColor", mod: "color"},
  666. "fill.yjs:SolidColorFill.color": {key: "fillColor", mod: "color"},
  667. "fill.yjs:SolidColorFill.color.yjs:Color.value": {key: "fillColor", mod: "color"},
  668. "y:Fill": {
  669. "color": {key: "fillColor", mod: "color"},
  670. //"color2": {key: "gradientColor", mod: "color"}, //??
  671. "transparent": function(val, map)
  672. {
  673. if (val == "true")
  674. {
  675. map["fillColor"] = "none";
  676. }
  677. }
  678. },
  679. "y:BorderStyle": {
  680. "color": {key: "strokeColor", mod: "color"},
  681. "width": "strokeWidth",
  682. "hasColor": function(val, map)
  683. {
  684. if (val == "false")
  685. {
  686. map["strokeColor"] = "none";
  687. }
  688. },
  689. "type": dashStyleFn
  690. //"raised": ??
  691. },
  692. "stroke": {key: "strokeColor", mod: "color"},
  693. "stroke.yjs:Stroke":
  694. {
  695. "dashStyle": dashStyleFn,
  696. "dashStyle.yjs:DashStyle.dashes": dashStyleFn,
  697. "fill": {key: "strokeColor", mod: "color"},
  698. "fill.yjs:SolidColorFill.color": {key: "strokeColor", mod: "color"},
  699. //"lineCap": "", //??
  700. "thickness.sys:Double": "strokeWidth",
  701. "thickness": "strokeWidth"
  702. }
  703. };
  704. var assetNodesStyle = mxUtils.clone(styleCommonMap);
  705. assetNodesStyle["defaults"] = {
  706. "fillColor": "#CCCCCC",
  707. "strokeColor": "#6881B3"
  708. };
  709. var bpmnActivityStyle = mxUtils.clone(styleCommonMap);
  710. bpmnActivityStyle["defaults"] = {
  711. "shape": "ext;rounded=1",
  712. "fillColor": "#FFFFFF",
  713. "strokeColor": "#000090"
  714. };
  715. var bpmnGatewayStyle = mxUtils.clone(styleCommonMap);
  716. bpmnGatewayStyle["defaults"] = {
  717. "shape": "rhombus;fillColor=#FFFFFF;strokeColor=#FFCD28"
  718. };
  719. var bpmnConversationStyle = mxUtils.clone(styleCommonMap);
  720. bpmnConversationStyle["defaults"] = {
  721. "shape": "hexagon",
  722. "strokeColor": "#007000"
  723. };
  724. var bpmnEventStyle = mxUtils.clone(styleCommonMap);
  725. bpmnEventStyle["defaults"] = {
  726. "shape": "mxgraph.bpmn.shape;perimeter=ellipsePerimeter;symbol=general",
  727. "outline": "standard"
  728. };
  729. bpmnEventStyle["characteristic"] = {key: "outline", mod: "bpmnOutline"};
  730. var bpmnDataObjectStyle = mxUtils.clone(styleCommonMap);
  731. bpmnDataObjectStyle["defaults"] = {
  732. "shape": "js:bpmnDataObject"
  733. };
  734. var bpmnDataStoreStyle = mxUtils.clone(styleCommonMap);
  735. bpmnDataStoreStyle["defaults"] = {
  736. "shape": "datastore"
  737. };
  738. var bpmnGroupNodeStyle = mxUtils.clone(styleCommonMap);
  739. bpmnGroupNodeStyle["defaults"] = {
  740. "shape": "swimlane;swimlaneLine=0;startSize=20;dashed=1;dashPattern=3 1 1 1;collapsible=0;rounded=1"
  741. };
  742. var bpmnChoreographyNodeStyle = mxUtils.clone(styleCommonMap);
  743. bpmnChoreographyNodeStyle["defaults"] = {
  744. "shape": "js:BpmnChoreography"//"swimlane;childLayout=stackLayout;horizontal=1;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;startSize=20;rounded=1;collapsible=0"
  745. };
  746. //approximation to GraphML shapes TODO improve them
  747. var bevelNodeStyle = mxUtils.clone(styleCommonMap);
  748. bevelNodeStyle["defaults"] = {
  749. "rounded": "1",
  750. "glass": "1",
  751. "strokeColor": "#FFFFFF"
  752. };
  753. bevelNodeStyle["inset"] = "strokeWidth";
  754. bevelNodeStyle["radius"] = "arcSize";
  755. bevelNodeStyle["drawShadow"] = {key:"shadow", mod:"bool"};
  756. bevelNodeStyle["color"] = {key:"fillColor", mod:"color", addGradient: "north"};
  757. bevelNodeStyle["color.yjs:Color.value"] = bevelNodeStyle["color"];
  758. var shinyPlateNodeStyle = mxUtils.clone(styleCommonMap);
  759. shinyPlateNodeStyle["defaults"] = {
  760. "rounded": "1",
  761. "arcSize": 10,
  762. "glass": "1",
  763. "shadow": "1",
  764. "strokeColor": "none"
  765. //,"rotation": -90 //TODO requires rotation!
  766. };
  767. shinyPlateNodeStyle["drawShadow"] = {key:"shadow", mod:"bool"};
  768. var demoGroupStyle = mxUtils.clone(styleCommonMap);
  769. demoGroupStyle["defaults"] = {
  770. "shape": "swimlane",
  771. "startSize": 20,
  772. "strokeWidth": 4,
  773. "spacingLeft": 10 //TODO can we change collapse icon to be in right side?
  774. };
  775. demoGroupStyle["isCollapsible"] = {key:"collapsible", mod:"bool"};
  776. demoGroupStyle["borderColor"] = {key:"strokeColor", mod:"color"};
  777. demoGroupStyle["folderFrontColor"] = {key:"fillColor", mod:"color"}; //TODO fillColor always match strokeColor!
  778. // demoGroupStyle["folderBackColor"] = {key:"fillColor", mod:"color"}; //??
  779. var collapsibleNodeStyle = mxUtils.clone(styleCommonMap);
  780. collapsibleNodeStyle["defaults"] = {
  781. "shape": "swimlane",
  782. "startSize": 20,
  783. "spacingLeft": 10 //TODO can we change collapse icon to be in right side?
  784. };
  785. collapsibleNodeStyle["yjs:PanelNodeStyle"] = {
  786. "color": {key:"swimlaneFillColor", mod:"color"},
  787. "color.yjs:Color.value": {key:"swimlaneFillColor", mod:"color"},
  788. "labelInsetsColor": {key:"fillColor", mod:"color"},
  789. "labelInsetsColor.yjs:Color.value": {key:"fillColor", mod:"color"}
  790. };
  791. var tableStyle = mxUtils.clone(styleCommonMap);
  792. tableStyle["defaults"] = {
  793. "shape": "js:table"
  794. };
  795. var imageNodeStyle = mxUtils.clone(styleCommonMap);
  796. imageNodeStyle["defaults"] = {
  797. "shape": "image"
  798. };
  799. imageNodeStyle["image"] = function(val, map)
  800. {
  801. map["image"] = val;
  802. };
  803. var svgNodeStyle = mxUtils.clone(styleCommonMap);
  804. svgNodeStyle["defaults"] = {
  805. "shape": "image"
  806. };
  807. // svgNodeStyle["y:SVGNodeProperties"] = {
  808. // "usingVisualBounds": ""//??
  809. // };
  810. // y:SVGModel.svgBoundsPolicy ??
  811. svgNodeStyle["y:SVGModel.y:SVGContent.y:Resource.#text"] = function(val, map)
  812. {
  813. map["image"] = "data:image/svg+xml," + ((window.btoa) ? btoa(val) : Base64.encode(val));
  814. };
  815. var groupNodeStyle = mxUtils.clone(styleCommonMap);
  816. groupNodeStyle["defaults"] = {
  817. "shape": "swimlane",
  818. "startSize": 20
  819. };
  820. groupNodeStyle["y:Shape.type"] = function(val, map)
  821. {
  822. if (val == "roundrectangle")
  823. {
  824. map['rounded'] = 1;
  825. map['arcSize'] = 5;
  826. }
  827. };
  828. var tableNodeStyle = mxUtils.clone(styleCommonMap);
  829. tableNodeStyle["defaults"] = {
  830. "shape": "js:table2"
  831. };
  832. var genericNodeStyle = mxUtils.clone(styleCommonMap);
  833. genericNodeStyle["defaults"] = {
  834. "gradientDirection": "east"
  835. };
  836. genericNodeStyle["y:Fill"]["color2"] = {key: "gradientColor", mod: "color"};
  837. genericNodeStyle["y:StyleProperties.y:Property"] = {
  838. "com.yworks.bpmn.characteristic": {key: "outline", mod: "bpmnOutline"},
  839. //TODO support colors for the icon itself other than the remaining shape!
  840. // "com.yworks.bpmn.icon.line.color": "",
  841. "com.yworks.bpmn.icon.fill": {key:"gradientColor", mod:"color"},
  842. "com.yworks.bpmn.icon.fill2": {key:"fillColor", mod:"color"},
  843. "com.yworks.bpmn.type": {key: "symbol", mod: "bpmnSymbol"},
  844. "y.view.ShadowNodePainter.SHADOW_PAINTING": {key: "shadow", mod: "bool"},
  845. "doubleBorder": {key: "double", mod: "bool"},
  846. "com.yworks.sbgn.style.radius": {key: "arcSize", mod: "scale", scale: 2},
  847. "com.yworks.sbgn.style.inverse": {key: "flipV", mod: "bool"}
  848. };
  849. // console.log(dataObj);
  850. this.mapObject(dataObj, {
  851. "yjs:ShapeNodeStyle": styleCommonMap,
  852. "demostyle:FlowchartNodeStyle": styleCommonMap,
  853. "demostyle:AssetNodeStyle": assetNodesStyle,
  854. "bpmn:ActivityNodeStyle": bpmnActivityStyle,
  855. "bpmn:GatewayNodeStyle": bpmnGatewayStyle,
  856. "bpmn:ConversationNodeStyle": bpmnConversationStyle,
  857. "bpmn:EventNodeStyle": bpmnEventStyle,
  858. "bpmn:DataObjectNodeStyle": bpmnDataObjectStyle,
  859. "bpmn:DataStoreNodeStyle": bpmnDataStoreStyle,
  860. "bpmn:GroupNodeStyle": bpmnGroupNodeStyle,
  861. "bpmn:ChoreographyNodeStyle": bpmnChoreographyNodeStyle,
  862. "yjs:BevelNodeStyle": bevelNodeStyle,
  863. "yjs:ShinyPlateNodeStyle": shinyPlateNodeStyle,
  864. "demostyle:DemoGroupStyle": demoGroupStyle,
  865. "yjs:CollapsibleNodeStyleDecorator": collapsibleNodeStyle,
  866. "bpmn:PoolNodeStyle": tableStyle,
  867. "yjs:TableNodeStyle": tableStyle,
  868. "demotablestyle:DemoTableStyle": tableStyle,
  869. "yjs:ImageNodeStyle": imageNodeStyle,
  870. //desktop
  871. "y:ShapeNode": styleCommonMap,
  872. "y:GenericNode": genericNodeStyle,
  873. "y:GenericGroupNode": genericNodeStyle,
  874. "y:TableNode": tableNodeStyle,
  875. "y:SVGNode": svgNodeStyle,
  876. "y:GroupNode": groupNodeStyle
  877. }, style);
  878. };
  879. mxGraphMlCodec.prototype.handleTemplates = function (template, userTags, node, styleMap)
  880. {
  881. if (template)
  882. {
  883. var w = node.geometry.width;
  884. var h = node.geometry.height;
  885. var header = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 '+ w + ' ' + h +'"><g>';
  886. var footer = '</g></svg>';
  887. //TODO optimize this! probably only the text before defs has bindings
  888. var matches = null;
  889. var bindingPairs = [];
  890. //find template bindings
  891. var tempBindRegEx = /\{TemplateBinding\s+([^}]+)\}/g;
  892. while ((matches = tempBindRegEx.exec(template)) != null)
  893. {
  894. var replacement = "";
  895. switch (matches[1])
  896. {
  897. case "width":
  898. replacement = w;
  899. break;
  900. case "height":
  901. replacement = h;
  902. break;
  903. }
  904. bindingPairs.push({match: matches[0], repl: replacement});
  905. }
  906. if (userTags && userTags["y:Json"])
  907. {
  908. var json = JSON.parse(userTags["y:Json"]["#text"]);
  909. //find user tags bindings
  910. var userTagBindRegEx = /\{Binding\s+([^}]+)\}/g;
  911. while ((matches = userTagBindRegEx.exec(template)) != null)
  912. {
  913. var parts = matches[1].split(',');
  914. var val = json[parts[0]];
  915. if (val)
  916. {
  917. if (parts.length > 1)
  918. {
  919. if (parts[1].indexOf('Converter='))
  920. {
  921. var func = mxGraphMlConverters[parts[1].substr(11)]; //11 is the length of Converter=
  922. if (func)
  923. {
  924. var args = [val];
  925. if (parts[2])
  926. {
  927. args.push(parts[2].substr(11)); //11 is the length of Parameter=
  928. }
  929. val = func.apply(null, args)
  930. }
  931. }
  932. }
  933. bindingPairs.push({match: matches[0], repl: mxUtils.htmlEntities(val)});
  934. }
  935. }
  936. }
  937. for (var i = 0; i < bindingPairs.length; i++)
  938. {
  939. template = template.replace(bindingPairs[i].match, bindingPairs[i].repl);
  940. }
  941. bindingPairs = [];
  942. //Fix text elements (TODO can it be merged with the previous step?)
  943. var txtRegEx = /\<text.+data-content="([^"]+).+\<\/text\>/g;
  944. while ((matches = txtRegEx.exec(template)) != null)
  945. {
  946. var val = matches[0].substr(0, matches[0].length - 7) + matches[1] + "</text>"; //7 is the length of </text>
  947. bindingPairs.push({match: matches[0], repl: val});
  948. }
  949. for (var i = 0; i < bindingPairs.length; i++)
  950. {
  951. template = template.replace(bindingPairs[i].match, bindingPairs[i].repl);
  952. }
  953. var svg = header + template + footer;
  954. styleMap["shape"] = "image";
  955. styleMap["image"] = "data:image/svg+xml," + ((window.btoa) ? btoa(svg) : Base64.encode(svg));
  956. }
  957. };
  958. mxGraphMlCodec.prototype.handleCompoundShape = function (node, styleMap, mlStyleObj, lbls)
  959. {
  960. var shape = styleMap["shape"];
  961. if (shape && shape.indexOf("js:") == 0)
  962. {
  963. switch(shape)
  964. {
  965. case "js:bpmnArtifactShadow":
  966. styleMap["shadow"] = "1";
  967. case "js:bpmnArtifact":
  968. styleMap["shape"] = styleMap["symbol"];
  969. delete styleMap["fillColor"];
  970. delete styleMap["strokeColor"];
  971. delete styleMap["gradientColor"];
  972. this.handleCompoundShape(node, styleMap, mlStyleObj, lbls)
  973. break;
  974. case "js:bpmnDataObjectShadow":
  975. case "js:bpmnDataObject":
  976. styleMap["shape"] = "note;size=16";
  977. // console.log(mlStyleObj);
  978. mlStyleObj = mlStyleObj["bpmn:DataObjectNodeStyle"] || mlStyleObj["y:GenericNode"] || mlStyleObj["y:GenericGroupNode"];
  979. var tmpMap = {};
  980. this.mapObject(mlStyleObj, {
  981. "y:StyleProperties.y:Property": {
  982. "com.yworks.bpmn.dataObjectType": "dataObjectType",
  983. "com.yworks.bpmn.marker1": "marker1"
  984. }
  985. }, tmpMap);
  986. if (mlStyleObj["collection"] == "true" || tmpMap["marker1"] == "bpmn_marker_parallel")
  987. {
  988. var cell2 = new mxCell('', new mxGeometry(0.5, 1, 10, 10), 'html=1;whiteSpace=wrap;shape=parallelMarker;');
  989. cell2.vertex = true;
  990. cell2.geometry.relative = true;
  991. cell2.geometry.offset = new mxPoint(-5, -10);
  992. node.insert(cell2);
  993. }
  994. if (mlStyleObj["type"] == "INPUT" || tmpMap["dataObjectType"] == "data_object_type_input")
  995. {
  996. var cell1 = new mxCell('', new mxGeometry(0, 0, 10, 10), 'html=1;shape=singleArrow;arrowWidth=0.4;arrowSize=0.4;');
  997. cell1.vertex = true;
  998. cell1.geometry.relative = true;
  999. cell1.geometry.offset = new mxPoint(2, 2);
  1000. node.insert(cell1);
  1001. }
  1002. else if (mlStyleObj["type"] == "OUTPUT" || tmpMap["dataObjectType"] == "data_object_type_output")
  1003. {
  1004. var cell1 = new mxCell('', new mxGeometry(0, 0, 10, 10), 'html=1;shape=singleArrow;arrowWidth=0.4;arrowSize=0.4;fillColor=#000000;');
  1005. cell1.vertex = true;
  1006. cell1.geometry.relative = true;
  1007. cell1.geometry.offset = new mxPoint(2, 2);
  1008. node.insert(cell1);
  1009. }
  1010. break;
  1011. case "js:BpmnChoreography":
  1012. this.mapObject(mlStyleObj, {
  1013. "defaults": {
  1014. "shape": "swimlane;collapsible=0;rounded=1",
  1015. "startSize": "20",
  1016. "strokeColor": "#006000",
  1017. "fillColor": "#CCCCCC"
  1018. }
  1019. }, styleMap);
  1020. //TODO the shape should be clipped by parent borders. It should also be resized relative to its parent
  1021. var pGeo = node.geometry;
  1022. var cell1 = new mxCell('', new mxGeometry(0, pGeo.height - 20, pGeo.width, 20), 'strokeColor=#006000;fillColor=#777777;rounded=1');
  1023. cell1.vertex = true;
  1024. node.insert(cell1);
  1025. //TODO handle labels accurately
  1026. if (lbls && lbls.lblTxts)
  1027. {
  1028. // console.log(lbls);
  1029. node.value = lbls.lblTxts[0];
  1030. cell1.value = lbls.lblTxts[1];
  1031. }
  1032. break;
  1033. case "js:bpmnActivityShadow":
  1034. case "js:bpmnActivity":
  1035. styleMap["shape"] = "ext;rounded=1";
  1036. var tmpMap = {};
  1037. mlStyleObj = mlStyleObj["y:GenericNode"] || mlStyleObj["y:GenericGroupNode"];
  1038. this.mapObject(mlStyleObj, {
  1039. "y:StyleProperties.y:Property": {
  1040. "com.yworks.bpmn.taskType": "taskType",
  1041. "com.yworks.bpmn.activityType": "activityType",
  1042. "com.yworks.bpmn.marker1": "marker1",
  1043. "com.yworks.bpmn.marker2": "marker2",
  1044. "com.yworks.bpmn.marker3": "marker3",
  1045. "com.yworks.bpmn.marker4": "marker4"
  1046. }
  1047. }, tmpMap);
  1048. switch(tmpMap["activityType"])
  1049. {
  1050. case "activity_type_transaction":
  1051. styleMap["double"] = "1";
  1052. break;
  1053. }
  1054. switch(tmpMap["taskType"])
  1055. {
  1056. case "task_type_send":
  1057. var item1 = new mxCell('', new mxGeometry(0, 0, 19, 12), 'shape=message;fillColor=#000000;strokeColor=#FFFFFF;');
  1058. item1.geometry.offset = new mxPoint(4, 7);
  1059. break;
  1060. case "task_type_receive":
  1061. var item1 = new mxCell('', new mxGeometry(0, 0, 19, 12), 'shape=message;');
  1062. item1.geometry.offset = new mxPoint(4, 7);
  1063. break;
  1064. case "task_type_user":
  1065. var item1 = new mxCell('', new mxGeometry(0, 0, 15, 15), 'shape=mxgraph.bpmn.user_task;');
  1066. item1.geometry.offset = new mxPoint(4, 5);
  1067. break;
  1068. case "task_type_manual":
  1069. var item1 = new mxCell('', new mxGeometry(0, 0, 15, 10), 'shape=mxgraph.bpmn.manual_task;');
  1070. item1.geometry.offset = new mxPoint(4, 7);
  1071. break;
  1072. case "task_type_business_rule":
  1073. var item1 = new mxCell('', new mxGeometry(0, 0, 18, 13), 'shape=mxgraph.bpmn.business_rule_task;');
  1074. item1.geometry.offset = new mxPoint(4, 7);
  1075. break;
  1076. case "task_type_service":
  1077. var item1 = new mxCell('', new mxGeometry(0, 0, 15, 15), 'shape=mxgraph.bpmn.service_task;');
  1078. item1.geometry.offset = new mxPoint(4, 5);
  1079. break;
  1080. case "task_type_script":
  1081. var item1 = new mxCell('', new mxGeometry(0, 0, 15, 15), 'shape=mxgraph.bpmn.script_task;');
  1082. item1.geometry.offset = new mxPoint(4, 5);
  1083. break;
  1084. }
  1085. if (item1)
  1086. {
  1087. item1.vertex = true;
  1088. item1.geometry.relative = true;
  1089. node.insert(item1);
  1090. item1 = null;
  1091. }
  1092. var numIcons = 0;
  1093. for (var i = 1; i <= 4; i++)
  1094. {
  1095. if (tmpMap["marker" + i])
  1096. numIcons++;
  1097. }
  1098. var iconX = -7.5 * numIcons - 2 * (numIcons - 1);
  1099. for (var i = 1; i <= numIcons; i++)
  1100. {
  1101. switch(tmpMap["marker" + i])
  1102. {
  1103. case "bpmn_marker_closed":
  1104. var item1 = new mxCell('', new mxGeometry(0.5, 1, 15, 15), 'shape=plus;part=1;');
  1105. item1.geometry.offset = new mxPoint(iconX, -20);
  1106. break;
  1107. case "bpmn_marker_open":
  1108. var item1 = new mxCell('', new mxGeometry(0.5, 1, 15, 15), 'shape=rect;part=1;');
  1109. item1.geometry.offset = new mxPoint(iconX, -20);
  1110. var item2 = new mxCell('', new mxGeometry(0.5, 0.5, 8, 1), 'shape=rect;part=1;');
  1111. item2.geometry.offset = new mxPoint(-4, -1);
  1112. item2.geometry.relative = true;
  1113. item2.vertex = true;
  1114. item1.insert(item2);
  1115. break;
  1116. case "bpmn_marker_loop":
  1117. var item1 = new mxCell('', new mxGeometry(0.5, 1, 15, 15), 'shape=mxgraph.bpmn.loop;part=1;');
  1118. item1.geometry.offset = new mxPoint(iconX, -20);
  1119. break;
  1120. case "bpmn_marker_parallel":
  1121. var item1 = new mxCell('', new mxGeometry(0.5, 1, 15, 15), 'shape=parallelMarker;part=1;');
  1122. item1.geometry.offset = new mxPoint(iconX, -20);
  1123. break;
  1124. case "bpmn_marker_sequential":
  1125. var item1 = new mxCell('', new mxGeometry(0.5, 1, 15, 15), 'shape=parallelMarker;direction=south;part=1;');
  1126. item1.geometry.offset = new mxPoint(iconX, -20);
  1127. break;
  1128. case "bpmn_marker_ad_hoc":
  1129. var item1 = new mxCell('', new mxGeometry(0.5, 1, 15, 10), 'shape=mxgraph.bpmn.ad_hoc;strokeColor=none;flipH=1;part=1;fillColor=#000000');
  1130. item1.geometry.offset = new mxPoint(iconX, -17);
  1131. break;
  1132. case "bpmn_marker_compensation":
  1133. var item1 = new mxCell('', new mxGeometry(0.5, 1, 15, 11), 'shape=mxgraph.bpmn.compensation;part=1;');
  1134. item1.geometry.offset = new mxPoint(iconX, -18);
  1135. break;
  1136. }
  1137. item1.geometry.relative = true;
  1138. item1.vertex = true;
  1139. node.insert(item1);
  1140. iconX += 20;
  1141. }
  1142. break;
  1143. case "js:table":
  1144. //TODO we need 2 passes to find the exact shift of columns/rows especially when there is rows inside rows
  1145. //TODO Internal table strokes needs to match table strokeWidth and only be on one side
  1146. //TODO code optimization
  1147. styleMap["shape"] = "swimlane;collapsible=0;swimlaneLine=0";
  1148. var tableObj = mlStyleObj["yjs:TableNodeStyle"] || mlStyleObj["demotablestyle:DemoTableStyle"];
  1149. if (!tableObj && mlStyleObj["bpmn:PoolNodeStyle"])
  1150. {
  1151. tableObj = mlStyleObj["bpmn:PoolNodeStyle"]["yjs:TableNodeStyle"];
  1152. }
  1153. // console.log(tableObj);
  1154. this.mapObject(tableObj, {
  1155. "backgroundStyle.demotablestyle:TableBackgroundStyle": {
  1156. "insetFill.yjs:SolidColorFill.color.yjs:Color.value": {key: "fillColor", mod: "color"},
  1157. "tableBackgroundFill.yjs:SolidColorFill.color.yjs:Color.value": {key: "swimlaneFillColor", mod: "color"},
  1158. "tableBackgroundStroke.yjs:Stroke":{
  1159. "fill": {key: "strokeColor", mod: "color"},
  1160. "thickness": "strokeWidth"
  1161. }
  1162. },
  1163. "backgroundStyle.yjs:ShapeNodeStyle.fill": {key: "fillColor", mod: "color"},
  1164. "backgroundStyle.yjs:ShapeNodeStyle.fill.yjs:SolidColorFill.color": {key: "fillColor", mod: "color"}
  1165. }, styleMap);
  1166. //Lane fill color is the same as the fill color
  1167. styleMap["swimlaneFillColor"] = styleMap["fillColor"];
  1168. tableObj = tableObj["table"]["y:Table"];
  1169. var x = 0, y = 0, xShift = {x: 0}, yShift = 0;
  1170. var insets = tableObj["Insets"];
  1171. if (insets)
  1172. {
  1173. insets = insets.split(',');
  1174. if (insets[0] != "0")
  1175. {
  1176. styleMap["startSize"] = insets[0];
  1177. xShift.x = parseFloat(insets[0]);
  1178. //x += xShift.x;
  1179. styleMap["horizontal"] = "0";
  1180. }
  1181. else if (insets[1] != "0")
  1182. {
  1183. styleMap["startSize"] = insets[1];
  1184. yShift = parseFloat(insets[1]);
  1185. y += yShift;
  1186. }
  1187. }
  1188. else
  1189. {
  1190. styleMap["startSize"] = "0";
  1191. }
  1192. var defRowStyle = {};
  1193. var rowMapping = {
  1194. "Insets": function(val, map)
  1195. {
  1196. map["startSize"] = val.split(',')[0];
  1197. },
  1198. "Style.bpmn:AlternatingLeafStripeStyle": {
  1199. "evenLeafDescriptor.bpmn:StripeDescriptor": {
  1200. "insetFill": {key: "evenFill", mod: "color"},
  1201. "backgroundFill": {key: "evenLaneFill", mod: "color"}
  1202. },
  1203. "oddLeafDescriptor.bpmn:StripeDescriptor": {
  1204. "insetFill": {key: "oddFill", mod: "color"},
  1205. "backgroundFill": {key: "oddLaneFill", mod: "color"}
  1206. }
  1207. //parentDescriptor ??
  1208. //TODO collect common types in a special mapping hash
  1209. },
  1210. "Style.yjs:NodeStyleStripeStyleAdapter":{
  1211. "demotablestyle:DemoStripeStyle": {
  1212. "stripeInsetFill.yjs:SolidColorFill.color.yjs:Color.value": {key: "fillColor", mod: "color"},
  1213. "tableLineFill.yjs:SolidColorFill.color.yjs:Color.value": {key: "strokeColor", mod: "color"}
  1214. },
  1215. "yjs:ShapeNodeStyle": {
  1216. "fill": {key: "swimlaneFillColor", mod: "color"}
  1217. }
  1218. },
  1219. "Size": "height"
  1220. };
  1221. this.mapObject(tableObj["RowDefaults"], {
  1222. "defaults": {
  1223. "shape": "swimlane;collapsible=0;horizontal=0",
  1224. "startSize": "0"
  1225. },
  1226. "y:StripeDefaults": rowMapping
  1227. }, defRowStyle);
  1228. var defColStyle = {};
  1229. var colMapping = {
  1230. "Insets": function(val, map)
  1231. {
  1232. map["startSize"] = val.split(',')[1];
  1233. },
  1234. "Style.bpmn:AlternatingLeafStripeStyle": {
  1235. "evenLeafDescriptor.bpmn:StripeDescriptor": {
  1236. "insetFill": {key: "evenFill", mod: "color"},
  1237. "backgroundFill": {key: "evenLaneFill", mod: "color"}
  1238. },
  1239. "oddLeafDescriptor.bpmn:StripeDescriptor": {
  1240. "insetFill": {key: "oddFill", mod: "color"},
  1241. "backgroundFill": {key: "oddLaneFill", mod: "color"}
  1242. }
  1243. //parentDescriptor ??
  1244. //TODO collect common types in a special mapping hash
  1245. },
  1246. "Style.yjs:NodeStyleStripeStyleAdapter":{
  1247. "demotablestyle:DemoStripeStyle": {
  1248. "stripeInsetFill.yjs:SolidColorFill.color.yjs:Color.value": {key: "fillColor", mod: "color"},
  1249. "tableLineFill.yjs:SolidColorFill.color.yjs:Color.value": {key: "strokeColor", mod: "color"}
  1250. },
  1251. "yjs:ShapeNodeStyle": {
  1252. "fill": {key: "swimlaneFillColor", mod: "color"}
  1253. }
  1254. },
  1255. "Size": "width"
  1256. };
  1257. this.mapObject(tableObj["ColumnDefaults"], {
  1258. "defaults": {
  1259. "shape": "swimlane;collapsible=0",
  1260. "startSize": "0",
  1261. "fillColor": "none"
  1262. },
  1263. "y:StripeDefaults": colMapping
  1264. }, defColStyle);
  1265. var pGeo = node.geometry;
  1266. var rows = tableObj["Rows"]["y:Row"];
  1267. y += parseFloat(defColStyle["startSize"]);
  1268. var maxX = xShift.x;
  1269. var initX = xShift.x;
  1270. xShift.lx = xShift.x;
  1271. //TODO We need two passes to determine the header size!
  1272. if (rows)
  1273. {
  1274. if (!(rows instanceof Array))
  1275. rows = [rows];
  1276. for (var i = 0; i < rows.length; i++)
  1277. {
  1278. xShift.x = initX;
  1279. xShift.lx = initX;
  1280. y = this.addRow(rows[i], node, (i & 1), y, xShift, rowMapping, defRowStyle);
  1281. maxX = Math.max(xShift.x, maxX);
  1282. }
  1283. }
  1284. var columns = tableObj["Columns"]["y:Column"];
  1285. x = maxX;//parseFloat(defRowStyle["startSize"]);
  1286. if (columns)
  1287. {
  1288. if (!(columns instanceof Array))
  1289. columns = [columns];
  1290. for (var i = 0; i < columns.length; i++)
  1291. {
  1292. x = this.addColumn(columns[i], node, (i & 1), x, yShift, colMapping, defColStyle);
  1293. }
  1294. }
  1295. break;
  1296. case "js:table2":
  1297. styleMap["shape"] = "swimlane;collapsible=0;swimlaneLine=0";
  1298. // console.log(mlStyleObj);
  1299. var tmpMap = {};
  1300. this.mapObject(mlStyleObj, {
  1301. "y:TableNode": {
  1302. "y:StyleProperties.y:Property": {
  1303. "yed.table.section.color": {key: "secColor", mod: "color"},
  1304. "yed.table.header.height": "headerH",
  1305. "yed.table.header.color.main": {key: "headerColor", mod: "color"},
  1306. "yed.table.header.color.alternating": {key: "headerColorAlt", mod: "color"},
  1307. "yed.table.lane.color.main": {key: "laneColor", mod: "color"},
  1308. "yed.table.lane.color.alternating": {key: "laneColorAlt", mod: "color"},
  1309. "yed.table.lane.style": "laneStyle",
  1310. "com.yworks.bpmn.type": "isHorz",
  1311. "POOL_LANE_COLOR_ALTERNATING": {key: "laneColorAlt", mod: "color"},
  1312. "POOL_LANE_COLOR_MAIN": {key: "laneColor", mod: "color"},
  1313. "POOL_LANE_STYLE": "laneStyle",
  1314. "POOL_HEADER_COLOR_MAIN": {key: "headerColor", mod: "color"},
  1315. "POOL_HEADER_COLOR_ALTERNATING": {key: "headerColorAlt", mod: "color"},
  1316. "POOL_TABLE_SECTION_COLOR": {key: "secColor", mod: "color"}
  1317. // //Not Used!
  1318. // "y.view.tabular.TableNodePainter.ALTERNATE_ROW_STYLE": {
  1319. // "y:SimpleStyle": {
  1320. // "fillColor": {key: "rowAltFillColor", mod: "color"},
  1321. // "lineColor": {key: "rowAltLineColor", mod: "color"},
  1322. // "lineType": "rowAltlineType",
  1323. // "lineWidth": "rowAltlineWidth"
  1324. // }
  1325. // },
  1326. // "y.view.tabular.TableNodePainter.ALTERNATE_COLUMN_STYLE": {
  1327. // "y:SimpleStyle": {
  1328. // "fillColor": {key: "colAltFillColor", mod: "color"},
  1329. // "lineColor": {key: "colAltLineColor", mod: "color"},
  1330. // "lineType": "colAltlineType",
  1331. // "lineWidth": "colAltlineWidth"
  1332. // }
  1333. // }
  1334. },
  1335. "y:Table": {
  1336. "y:DefaultColumnInsets.top": "colHHeight",
  1337. "y:DefaultRowInsets.left": "rowHWidth",
  1338. "y:Insets": {
  1339. "top": "tblHHeight",
  1340. "left": "tblHWidth"
  1341. }
  1342. }
  1343. }
  1344. }, tmpMap);
  1345. styleMap["swimlaneFillColor"] = styleMap["fillColor"];
  1346. var isHor = tmpMap["isHorz"] == "pool_type_lane_and_column"
  1347. || tmpMap["isHorz"] == "pool_type_empty"
  1348. || tmpMap["isHorz"] == "pool_type_lane";
  1349. var th = 0, tw = 0;
  1350. if (isHor)
  1351. {
  1352. tw = parseFloat(tmpMap["tblHWidth"]);
  1353. }
  1354. else
  1355. {
  1356. th = parseFloat(tmpMap["tblHHeight"]);
  1357. }
  1358. styleMap["startSize"] = th? th : tw;
  1359. //Assumptions: There is always rows and cols in every table
  1360. //Also all tables seems to be not rotated
  1361. try
  1362. {
  1363. var rows = mlStyleObj["y:TableNode"]["y:Table"]["y:Rows"]["y:Row"];
  1364. var cols = mlStyleObj["y:TableNode"]["y:Table"]["y:Columns"]["y:Column"];
  1365. var atts4Rows = tmpMap["laneStyle"] == "lane.style.rows" || tmpMap["laneStyle"] == "lane_style_rows";
  1366. if (!(rows instanceof Array))
  1367. rows = [rows];
  1368. if (!(cols instanceof Array))
  1369. cols = [cols];
  1370. var rowStartSize = parseFloat(tmpMap["rowHWidth"]);
  1371. for (var i = 0; i < rows.length; i++)
  1372. {
  1373. if (rows[i]["y:Insets"])
  1374. rowStartSize = Math.max(rowStartSize,
  1375. parseFloat(rows[i]["y:Insets"]["left"]) + parseFloat(rows[i]["y:Insets"]["right"]));
  1376. }
  1377. var colStartSize = parseFloat(tmpMap["colHHeight"]);
  1378. for (var i = 0; i < cols.length; i++)
  1379. {
  1380. if (cols[i]["y:Insets"])
  1381. colStartSize = Math.max(colStartSize,
  1382. parseFloat(cols[i]["y:Insets"]["top"]) + parseFloat(cols[i]["y:Insets"]["bottom"]));
  1383. }
  1384. if (atts4Rows)
  1385. {
  1386. this.addTbl2Rows(node, rows, th, tw, rowStartSize, colStartSize, atts4Rows, tmpMap);
  1387. this.addTbl2Cols(node, cols, th, tw, rowStartSize, colStartSize, atts4Rows, tmpMap);
  1388. }
  1389. else
  1390. {
  1391. this.addTbl2Cols(node, cols, th, tw, rowStartSize, colStartSize, atts4Rows, tmpMap);
  1392. this.addTbl2Rows(node, rows, th, tw, rowStartSize, colStartSize, atts4Rows, tmpMap);
  1393. }
  1394. }
  1395. catch(e)
  1396. {
  1397. //nothing!
  1398. }
  1399. break;
  1400. case "js:relationship_big_entity":
  1401. styleMap['shape'] = "swimlane;startSize=30;rounded=1;arcSize=5;collapsible=0";
  1402. var fill = mlStyleObj["y:GenericNode"]["y:Fill"];
  1403. if (fill)
  1404. {
  1405. styleMap['fillColor'] = fill["color2"];
  1406. styleMap['swimlaneFillColor'] = fill["color"];
  1407. }
  1408. break;
  1409. case "js:relationship_attribute":
  1410. if (styleMap["double"] == "1")
  1411. {
  1412. styleMap['shape'] = "doubleEllipse";
  1413. }
  1414. else
  1415. {
  1416. styleMap['shape'] = "ellipse";
  1417. }
  1418. break;
  1419. }
  1420. if (shape.indexOf("Shadow") > 0)
  1421. {
  1422. styleMap["shadow"] = "1";
  1423. }
  1424. }
  1425. };
  1426. mxGraphMlCodec.prototype.addTbl2Rows = function(node, rows, th, tw, rowStartSize, colStartSize, atts4Rows, tmpMap)
  1427. {
  1428. var y = th + colStartSize;
  1429. var isBPMN = tmpMap["isHorz"] != null;
  1430. for (var i = 0; i < rows.length; i++)
  1431. {
  1432. var odd = i & 1;
  1433. var cell = new mxCell();
  1434. cell.vertex = true;
  1435. var rowStyle = {
  1436. "shape": "swimlane;collapsible=0;horizontal=0",
  1437. "startSize": rowStartSize,
  1438. "fillColor": tmpMap["secColor"] || "none",
  1439. "swimlaneLine": (isBPMN? "0" : "1")
  1440. };
  1441. if (parseFloat(rowStyle["startSize"]) == 0)
  1442. {
  1443. rowStyle["fillColor"] = "none";
  1444. rowStyle["swimlaneLine"] = "0";
  1445. }
  1446. if (atts4Rows)
  1447. {
  1448. var fillColor = odd? tmpMap["headerColorAlt"] : tmpMap["headerColor"];
  1449. rowStyle["swimlaneFillColor"] = odd? tmpMap["laneColorAlt"] : tmpMap["laneColor"];
  1450. rowStyle["fillColor"] = fillColor? fillColor : rowStyle["swimlaneFillColor"];
  1451. }
  1452. var height = parseFloat(rows[i]["height"]);
  1453. var dh = (isBPMN && i == 0)? colStartSize : 0 ;
  1454. cell.geometry = new mxGeometry(tw, y - dh, node.geometry.width - tw, height + dh);
  1455. y += height;
  1456. // if (lblObj)
  1457. // this.addLabels(cell, lblObj, rowStyle)
  1458. cell.style = this.styleMap2Str(rowStyle);
  1459. node.insert(cell);
  1460. }
  1461. };
  1462. mxGraphMlCodec.prototype.addTbl2Cols = function(node, cols, th, tw, rowStartSize, colStartSize, atts4Rows, tmpMap)
  1463. {
  1464. var x = rowStartSize + tw;
  1465. var isBPMN = tmpMap["isHorz"] != null;
  1466. for (var i = 0; i < cols.length; i++)
  1467. {
  1468. var odd = i & 1;
  1469. var cell = new mxCell();
  1470. cell.vertex = true;
  1471. var colStyle = {
  1472. "shape": "swimlane;collapsible=0",
  1473. "startSize": colStartSize,
  1474. "fillColor": tmpMap["secColor"] || "none",
  1475. "swimlaneLine": (isBPMN? "0" : "1")
  1476. };
  1477. if (parseFloat(colStyle["startSize"]) == 0)
  1478. {
  1479. colStyle["fillColor"] = "none";
  1480. }
  1481. if (!atts4Rows)
  1482. {
  1483. var fillColor = odd? tmpMap["headerColorAlt"] : tmpMap["headerColor"];
  1484. colStyle["swimlaneFillColor"] = odd? tmpMap["laneColorAlt"] : tmpMap["laneColor"];
  1485. colStyle["fillColor"] = fillColor? fillColor : colStyle["swimlaneFillColor"];
  1486. }
  1487. var width = parseFloat(cols[i]["width"]);
  1488. var dw = (isBPMN && i == 0)? rowStartSize : 0 ;
  1489. cell.geometry = new mxGeometry(x - dw, th, width + dw, node.geometry.height - th);
  1490. x += width;
  1491. // if (lblObj)
  1492. // this.addLabels(cell, lblObj, rowStyle)
  1493. cell.style = this.styleMap2Str(colStyle);
  1494. node.insert(cell);
  1495. }
  1496. };
  1497. mxGraphMlCodec.prototype.addRow = function(row, parent, odd, y, xShift, rowMapping, defRowStyle)
  1498. {
  1499. var cell = new mxCell();
  1500. cell.vertex = true;
  1501. var rowStyle = mxUtils.clone(defRowStyle);
  1502. this.mapObject(row, rowMapping, rowStyle);
  1503. if (odd)
  1504. {
  1505. if (rowStyle["oddFill"])
  1506. rowStyle["fillColor"] = rowStyle["oddFill"];
  1507. if (rowStyle["oddLaneFill"])
  1508. rowStyle["swimlaneFillColor"] = rowStyle["oddLaneFill"];
  1509. }
  1510. else
  1511. {
  1512. if (rowStyle["evenFill"])
  1513. rowStyle["fillColor"] = rowStyle["evenFill"];
  1514. if (rowStyle["evenLaneFill"])
  1515. rowStyle["swimlaneFillColor"] = rowStyle["evenLaneFill"];
  1516. }
  1517. var height = parseFloat(rowStyle["height"]);
  1518. cell.geometry = new mxGeometry(xShift.lx, y, parent.geometry.width - xShift.lx, height);
  1519. var lblObj = row["Labels"];
  1520. if (lblObj)
  1521. this.addLabels(cell, lblObj, rowStyle)
  1522. cell.style = this.styleMap2Str(rowStyle);
  1523. parent.insert(cell);
  1524. var subRow = row["y:Row"];
  1525. xShift.lx = 0;
  1526. if (rowStyle["startSize"])
  1527. {
  1528. xShift.lx = parseFloat(rowStyle["startSize"]);
  1529. xShift.x += xShift.lx;
  1530. }
  1531. var initX = xShift.x, maxX = xShift.x, initLx = xShift.lx;
  1532. var subY = 0;
  1533. if (subRow)
  1534. {
  1535. if (!(subRow instanceof Array))
  1536. subRow = [subRow];
  1537. for (var i = 0; i < subRow.length; i++)
  1538. {
  1539. xShift.x = initX;
  1540. xShift.lx = initLx;
  1541. subY = this.addRow(subRow[i], cell, (i & 1), subY, xShift, rowMapping, defRowStyle);
  1542. maxX = Math.max(xShift.x, maxX)
  1543. }
  1544. }
  1545. xShift.x = maxX;
  1546. height = Math.max(height, subY);
  1547. cell.geometry.height = height;
  1548. y += height;
  1549. return y;
  1550. }
  1551. mxGraphMlCodec.prototype.addColumn = function(column, parent, odd, x, yShift, colMapping, defColStyle)
  1552. {
  1553. var cell = new mxCell();
  1554. cell.vertex = true;
  1555. var colStyle = mxUtils.clone(defColStyle);
  1556. this.mapObject(column, colMapping, colStyle);
  1557. if (odd)
  1558. {
  1559. if (colStyle["oddFill"])
  1560. colStyle["fillColor"] = colStyle["oddFill"];
  1561. if (colStyle["oddLaneFill"])
  1562. colStyle["swimlaneFillColor"] = colStyle["oddLaneFill"];
  1563. }
  1564. else
  1565. {
  1566. if (colStyle["evenFill"])
  1567. colStyle["fillColor"] = colStyle["evenFill"];
  1568. if (colStyle["evenLaneFill"])
  1569. colStyle["swimlaneFillColor"] = colStyle["evenLaneFill"];
  1570. }
  1571. var width = parseFloat(colStyle["width"]);
  1572. cell.geometry = new mxGeometry(x, yShift, width, parent.geometry.height - yShift);
  1573. var lblObj = column["Labels"];
  1574. if (lblObj)
  1575. this.addLabels(cell, lblObj, colStyle)
  1576. cell.style = this.styleMap2Str(colStyle);
  1577. parent.insert(cell);
  1578. var subCol = column["y:Column"];
  1579. var subX = 0;
  1580. if (subCol)
  1581. {
  1582. if (!(subCol instanceof Array))
  1583. subCol = [subCol];
  1584. for (var i = 0; i < subCol.length; i++)
  1585. {
  1586. subX = this.addColumn(subCol[i], cell, (i & 1), subX, yShift, colMapping, defColStyle);
  1587. }
  1588. }
  1589. width = Math.max(width, subX);
  1590. cell.geometry.width = width;
  1591. x += width;
  1592. return x;
  1593. }
  1594. mxGraphMlCodec.prototype.handleFixedRatio = function (node, styleMap)
  1595. {
  1596. var shape = styleMap["shape"];
  1597. var geo = node.geometry;
  1598. if (shape && geo)
  1599. {
  1600. if (shape.indexOf(";aspect=fixed") > 0)
  1601. {
  1602. var min = Math.min(geo.height, geo.width);
  1603. if (min == geo.height) //fix coordinates
  1604. {
  1605. geo.x += (geo.width - min) / 2;
  1606. }
  1607. geo.height = min;
  1608. geo.width = min;
  1609. }
  1610. else if (shape.indexOf(";rotation=90") > 0 || shape.indexOf(";rotation=-90") > 0 )
  1611. {
  1612. var h = geo.height;
  1613. var w = geo.width;
  1614. geo.height = w;
  1615. geo.width = h;
  1616. var diff = (h - w) / 2;
  1617. geo.x -= diff;
  1618. geo.y += diff;
  1619. }
  1620. }
  1621. };
  1622. mxGraphMlCodec.prototype.addNodeGeo = function (node, geoObj, dx, dy)
  1623. {
  1624. var geoRect = geoObj[mxGraphMlConstants.RECT];
  1625. var x = 0, y = 0, w = 30, h = 30; //some node has no geometry, this is the default
  1626. if (geoRect)
  1627. {
  1628. x = geoRect[mxGraphMlConstants.X];
  1629. y = geoRect[mxGraphMlConstants.Y];
  1630. w = geoRect[mxGraphMlConstants.WIDTH];
  1631. h = geoRect[mxGraphMlConstants.HEIGHT];
  1632. }
  1633. else
  1634. {
  1635. x = geoObj[mxGraphMlConstants.X_L] || x;
  1636. y = geoObj[mxGraphMlConstants.Y_L] || y;
  1637. w = geoObj[mxGraphMlConstants.WIDTH_L] || w;
  1638. h = geoObj[mxGraphMlConstants.HEIGHT_L] || h;
  1639. }
  1640. var geo = node.geometry;
  1641. geo.x = parseFloat(x) - dx;
  1642. geo.y = parseFloat(y) - dy;
  1643. geo.width = parseFloat(w);
  1644. geo.height = parseFloat(h);
  1645. };
  1646. //TODO handle other ports cases
  1647. mxGraphMlCodec.prototype.importEdge = function (edgeElement, graph, parent, dx, dy)
  1648. {
  1649. var data = this.getDirectChildNamedElements(edgeElement, mxGraphMlConstants.DATA);
  1650. var e;
  1651. var id = edgeElement.getAttribute(mxGraphMlConstants.ID);
  1652. var srcId = edgeElement.getAttribute(mxGraphMlConstants.EDGE_SOURCE);
  1653. var trgId = edgeElement.getAttribute(mxGraphMlConstants.EDGE_TARGET);
  1654. var srcPortId = edgeElement.getAttribute(mxGraphMlConstants.EDGE_SOURCE_PORT);
  1655. var trgPortId = edgeElement.getAttribute(mxGraphMlConstants.EDGE_TARGET_PORT);
  1656. var src = this.nodesMap[srcId];
  1657. var trg = this.nodesMap[trgId];
  1658. var edge = graph.insertEdge(parent, null, "", src.node, trg.node, "graphMLId=" + id);
  1659. var style = {graphMlID: id};
  1660. for (var i = 0; i < data.length; i++)
  1661. {
  1662. var d = data[i];
  1663. var dataObj = this.dataElem2Obj(d);
  1664. var desktopEdgeObj = dataObj["y:PolyLineEdge"] || dataObj["y:GenericEdge"] ||
  1665. dataObj["y:ArcEdge"] || dataObj["y:BezierEdge"] ||
  1666. dataObj["y:QuadCurveEdge"] || dataObj["y:SplineEdge"];
  1667. if (dataObj.key == this.edgesKeys[mxGraphMlConstants.EDGE_GEOMETRY].key)
  1668. {
  1669. this.addEdgeGeo(edge, dataObj, dx, dy);
  1670. }
  1671. else if (dataObj.key == this.edgesKeys[mxGraphMlConstants.EDGE_STYLE].key)
  1672. {
  1673. // console.log(dataObj);
  1674. this.addEdgeStyle(edge, dataObj, style);
  1675. }
  1676. else if (dataObj.key == this.edgesKeys[mxGraphMlConstants.EDGE_LABELS].key)
  1677. {
  1678. this.addLabels(edge, dataObj, style, graph);
  1679. }
  1680. else if (desktopEdgeObj)
  1681. {
  1682. this.addEdgeStyle(edge, dataObj, style);
  1683. var absPoints = this.addEdgePath(edge, desktopEdgeObj["y:Path"], style, dx, dy);
  1684. if (desktopEdgeObj["y:EdgeLabel"])
  1685. this.addLabels(edge, desktopEdgeObj["y:EdgeLabel"], style, graph, absPoints);
  1686. //special case for link edge
  1687. //TODO link doesn't support arrow head types
  1688. if (style["shape"] != null && style["shape"].indexOf("link") == 0)
  1689. {
  1690. style["width"] = style["strokeWidth"];
  1691. style["strokeWidth"] = 1;
  1692. }
  1693. }
  1694. }
  1695. //handle simple ports (exit/entry[X/Y])
  1696. if (src.ports && srcPortId)
  1697. {
  1698. var srcPort = src.ports[srcPortId];
  1699. if (srcPort.pos)
  1700. {
  1701. style["exitX"] = srcPort.pos.x;
  1702. style["exitY"] = srcPort.pos.y;
  1703. }
  1704. }
  1705. if (trg.ports && trgPortId)
  1706. {
  1707. var trgPort = trg.ports[trgPortId];
  1708. if (trgPort.pos)
  1709. {
  1710. style["entryX"] = trgPort.pos.x;
  1711. style["entryY"] = trgPort.pos.y;
  1712. }
  1713. }
  1714. edge.style = this.styleMap2Str(style);
  1715. return edge;
  1716. };
  1717. mxGraphMlCodec.prototype.addEdgeGeo = function (edge, geoObj, dx, dy)
  1718. {
  1719. var list = geoObj[mxGraphMlConstants.Y_BEND];
  1720. if (list)
  1721. {
  1722. var points = [];
  1723. for (var i = 0; i < list.length; i++) {
  1724. var pointStr = list[i][mxGraphMlConstants.LOCATION];
  1725. if (pointStr) {
  1726. var xy = pointStr.split(',');
  1727. points.push(new mxPoint(parseFloat(xy[0]) - dx, parseFloat(xy[1]) - dy));
  1728. }
  1729. }
  1730. edge.geometry.points = points;
  1731. }
  1732. };
  1733. mxGraphMlCodec.prototype.addEdgePath = function (edge, pathObj, style, dx, dy)
  1734. {
  1735. var absPoints = [];
  1736. if (pathObj)
  1737. {
  1738. var srcX = parseFloat(pathObj.sx), srcY = parseFloat(pathObj.sy),
  1739. trgX = parseFloat(pathObj.tx), trgY = parseFloat(pathObj.ty);
  1740. var srcGeo = edge.source.geometry;
  1741. if (srcX != 0 || srcY != 0)
  1742. {
  1743. style["exitX"] = (srcX + srcGeo.width/2) / srcGeo.width;
  1744. style["exitY"] = (srcY + srcGeo.height/2) / srcGeo.height;
  1745. absPoints.push(new mxPoint(srcGeo.x + style["exitX"] * srcGeo.width - dx, srcGeo.y + style["exitY"] * srcGeo.height - dy));
  1746. }
  1747. else
  1748. {
  1749. absPoints.push(new mxPoint(srcGeo.x + srcGeo.width/2 - dx, srcGeo.y + srcGeo.height/2 - dy));
  1750. }
  1751. var endP = null;
  1752. var trgGeo = edge.target.geometry;
  1753. if (trgX != 0 || trgY != 0)
  1754. {
  1755. style["entryX"] = (trgX + trgGeo.width/2) / trgGeo.width;
  1756. style["entryY"] = (trgY + trgGeo.height/2) / trgGeo.height;
  1757. endP = new mxPoint(trgGeo.x + style["entryX"] * trgGeo.width - dx, trgGeo.y + style["entryY"] * trgGeo.height - dy);
  1758. }
  1759. else
  1760. {
  1761. endP = new mxPoint(trgGeo.x + trgGeo.width/2 - dx, trgGeo.y + trgGeo.height/2 - dy);
  1762. }
  1763. var list = pathObj["y:Point"];
  1764. if (list)
  1765. {
  1766. if (!(list instanceof Array))
  1767. {
  1768. list = [list];
  1769. }
  1770. var points = [];
  1771. for (var i = 0; i < list.length; i++)
  1772. {
  1773. var p = new mxPoint(parseFloat(list[i].x) - dx, parseFloat(list[i].y) - dy)
  1774. points.push(p);
  1775. absPoints.push(p);
  1776. }
  1777. edge.geometry.points = points;
  1778. }
  1779. absPoints.push(endP);
  1780. }
  1781. return absPoints;
  1782. };
  1783. //TODO improve similarity handling
  1784. mxGraphMlCodec.prototype.addEdgeStyle = function (edge, styleObj, styleMap)
  1785. {
  1786. var dashStyleFn = function(val, map)
  1787. {
  1788. map["dashed"] = 1;
  1789. //map["fixDash"] = 1;
  1790. var pattern = null;
  1791. switch(val)
  1792. {
  1793. case "DashDot":
  1794. pattern = "3 1 1 1";
  1795. break;
  1796. case "Dot":
  1797. pattern = "1 1";
  1798. break;
  1799. case "DashDotDot":
  1800. pattern = "3 1 1 1 1 1";
  1801. break;
  1802. case "Dash":
  1803. pattern = "3 1";
  1804. break;
  1805. default:
  1806. pattern = val.replace(/0/g, '1');
  1807. }
  1808. if (pattern)
  1809. {
  1810. //Some patterns in graphML has only one number
  1811. if (pattern.indexOf(" ") < 0)
  1812. {
  1813. pattern = pattern + " " + pattern;
  1814. }
  1815. map["dashPattern"] = pattern;
  1816. }
  1817. };
  1818. var desktopLineStyleFn = function(val, map)
  1819. {
  1820. if (val != "line")
  1821. map["dashed"] = 1;
  1822. var pattern = null;
  1823. switch(val)
  1824. {
  1825. case "dashed":
  1826. pattern = "3 1";
  1827. break;
  1828. case "dotted":
  1829. pattern = "1 1";
  1830. break;
  1831. case "dashed_dotted":
  1832. pattern = "3 2 1 2";
  1833. break;
  1834. }
  1835. if (pattern)
  1836. map["dashPattern"] = pattern;
  1837. };
  1838. // can be mapping to WHITE => empty, BLACK => filled
  1839. var endArrowFill = function(val, map)
  1840. {
  1841. map["endFill"] = (val == 'WHITE' || val.indexOf("white_") == 0 || val.indexOf("transparent_") == 0)? "0" : "1";
  1842. };
  1843. // can be mapping to WHITE => empty, BLACK => filled
  1844. var startArrowFill = function(val, map)
  1845. {
  1846. map["startFill"] = (val == 'WHITE' || val.indexOf("white_") == 0 || val.indexOf("transparent_") == 0)? "0" : "1";
  1847. };
  1848. var startArrow = function(val, map)
  1849. {
  1850. map["startArrow"] = mxGraphMlArrowsMap[val] || "classic";
  1851. startArrowFill(val, map);
  1852. };
  1853. var endArrow = function(val, map)
  1854. {
  1855. map["endArrow"] = mxGraphMlArrowsMap[val] || "classic";
  1856. endArrowFill(val, map);
  1857. }
  1858. var desktopEdge = {
  1859. "defaults" :
  1860. {
  1861. "rounded": 0,
  1862. "endArrow": "none"
  1863. },
  1864. "configuration": {key: "shape", mod: "shape"},
  1865. "y:LineStyle": {
  1866. "color": {key: "strokeColor", mod: "color"},
  1867. "type": desktopLineStyleFn,
  1868. "width": "strokeWidth"
  1869. },
  1870. "y:Arrows": {
  1871. "source": startArrow,
  1872. "target": endArrow
  1873. },
  1874. "y:BendStyle": {
  1875. "smoothed": {key: "rounded", mod: "bool"}
  1876. }
  1877. };
  1878. var arcEdgeStyle = mxUtils.clone(desktopEdge);
  1879. arcEdgeStyle["defaults"]["curved"] = "1";
  1880. this.mapObject(styleObj, {
  1881. "yjs:PolylineEdgeStyle": {
  1882. "defaults" :
  1883. {
  1884. "endArrow": "none",
  1885. "rounded": 0
  1886. },
  1887. "smoothingLength": function(val, map)
  1888. {
  1889. map["rounded"] = (val && parseFloat(val) > 0)? "1" : "0";
  1890. },
  1891. "stroke": {key: "strokeColor", mod: "color"},
  1892. "stroke.yjs:Stroke":
  1893. {
  1894. "dashStyle": dashStyleFn,
  1895. "dashStyle.yjs:DashStyle.dashes": dashStyleFn,
  1896. "fill": {key: "strokeColor", mod: "color"},
  1897. "fill.yjs:SolidColorFill.color": {key: "strokeColor", mod: "color"},
  1898. //"lineCap": "", //??
  1899. "thickness.sys:Double": "strokeWidth",
  1900. "thickness": "strokeWidth"
  1901. },
  1902. "targetArrow": {key: "endArrow", mod: "arrow"},
  1903. "targetArrow.yjs:Arrow": {
  1904. "defaults" :
  1905. {
  1906. "endArrow": "classic",
  1907. "endFill": "1",
  1908. "endSize": "6"
  1909. },
  1910. // cropLength: "", //??
  1911. "fill": endArrowFill,
  1912. "scale": {key: "endSize", mod: "scale", scale: 5},
  1913. // stroke: "", //?
  1914. "type": {key: "endArrow", mod: "arrow"}
  1915. },
  1916. "sourceArrow": {key: "startArrow", mod: "arrow"},
  1917. "sourceArrow.yjs:Arrow": {
  1918. "defaults" :
  1919. {
  1920. "startArrow": "classic",
  1921. "startFill": "1",
  1922. "startSize": "6"
  1923. },
  1924. // cropLength: "", //??
  1925. "fill": startArrowFill,
  1926. "scale": {key: "startSize", mod: "scale", scale: 5},
  1927. // stroke: "", //?
  1928. "type": {key: "startArrow", mod: "arrow"}
  1929. }
  1930. },
  1931. "y:PolyLineEdge": desktopEdge,
  1932. "y:GenericEdge": desktopEdge,
  1933. //We approximate all curved types with curve
  1934. "y:ArcEdge": arcEdgeStyle,
  1935. "y:BezierEdge": arcEdgeStyle,
  1936. "y:QuadCurveEdge": arcEdgeStyle,
  1937. "y:SplineEdge": arcEdgeStyle
  1938. }, styleMap);
  1939. };
  1940. //TODO label offset
  1941. //TODO labels object is over swim lanes collapse button
  1942. mxGraphMlCodec.prototype.addLabels = function (node, lblObj, nodeStyle, graph, absPoints)
  1943. {
  1944. var lastChildIndex = node.getChildCount();
  1945. var lblList = lblObj[mxGraphMlConstants.Y_LABEL] || lblObj;
  1946. var lblTxts = [];
  1947. var lblStyles = [];
  1948. var lblLayouts = [];
  1949. if (lblList)
  1950. {
  1951. if (!(lblList instanceof Array))
  1952. {
  1953. lblList = [lblList];
  1954. }
  1955. for (var i = 0; i < lblList.length; i++)
  1956. {
  1957. var lbl = lblList[i];
  1958. // console.log(lbl);
  1959. var styleMap = {};
  1960. var txt = lbl[mxGraphMlConstants.TEXT] || lbl;
  1961. if (txt) txt = txt["#text"];
  1962. //layout
  1963. var layout = lbl[mxGraphMlConstants.LAYOUTPARAMETER] || lbl || {};
  1964. //style
  1965. var fontStyleFn = function(val, map)
  1966. {
  1967. if (val)
  1968. {
  1969. val = val.toUpperCase();
  1970. }
  1971. var style = map["fontStyle"] || 0;
  1972. switch(val)
  1973. {
  1974. case "ITALIC":
  1975. style = style | 2;
  1976. break;
  1977. case "BOLD":
  1978. style = style | 1;
  1979. break;
  1980. case "UNDERLINE":
  1981. style = style | 4;
  1982. break;
  1983. }
  1984. map["fontStyle"] = style;
  1985. };
  1986. var underlineStyleFn = function(val, map)
  1987. {
  1988. var style = map["fontStyle"] || 0;
  1989. if (val == "true")
  1990. {
  1991. style = style | 4;
  1992. }
  1993. map["fontStyle"] = style;
  1994. };
  1995. this.mapObject(lbl, {
  1996. "Style.yjs:DefaultLabelStyle":
  1997. {
  1998. "backgroundFill" : {key: "labelBackgroundColor", mod: "color"},
  1999. "backgroundFill.yjs:SolidColorFill.color" : {key: "labelBackgroundColor", mod: "color"},
  2000. "backgroundStroke" : {key: "labelBorderColor", mod: "color"},
  2001. "backgroundStroke.yjs:Stroke.fill" : {key: "labelBorderColor", mod: "color"},
  2002. "textFill": {key: "fontColor", mod: "color"},
  2003. "textFill.yjs:SolidColorFill.color": {key: "fontColor", mod: "color"},
  2004. "textSize": "fontSize",
  2005. "horizontalTextAlignment": "align",
  2006. "verticalTextAlignment": "verticalAlign",
  2007. "wrapping": function(val, map)
  2008. {
  2009. //TODO mxGraph has a single type of wrapping only
  2010. if (val)
  2011. map["whiteSpace"] = "wrap";
  2012. },
  2013. "font.yjs:Font":
  2014. {
  2015. "fontFamily": "fontFamily",
  2016. "fontSize": "fontSize",
  2017. "fontStyle": fontStyleFn,
  2018. "fontWeight": fontStyleFn,
  2019. "textDecoration": fontStyleFn
  2020. }
  2021. },
  2022. "Style.y:VoidLabelStyle": function (val, map)
  2023. {
  2024. map["VoidLbl"] = true;
  2025. },
  2026. //Desktop format
  2027. //hasBackgroundColor="false" hasLineColor="false" hasText="false" height="4.0" iconTextGap="4" modelName="custom" visible="true" width="4.0" x="26.277050018310547" y="70.76200103759766">
  2028. "alignment": "align",
  2029. //"autoSizePolicy": "",//??
  2030. "fontFamily": "fontFamily",
  2031. "fontSize": "fontSize",
  2032. "fontStyle": fontStyleFn,
  2033. "underlinedText": underlineStyleFn,
  2034. "horizontalTextPosition": "",//?? how this is compared to alignment?
  2035. "textColor": {key: "fontColor", mod: "color"},
  2036. "verticalTextPosition": "verticalAlign",
  2037. "hasText": {key: "hasText", mod: "bool"},
  2038. "rotationAngle": "rotation"
  2039. }, styleMap);
  2040. if (!styleMap["VoidLbl"] && styleMap["hasText"] != "0")
  2041. {
  2042. lblTxts.push(txt);
  2043. lblStyles.push(styleMap);
  2044. lblLayouts.push(layout);
  2045. }
  2046. }
  2047. }
  2048. //TODO Use the style map with defaults to change the style
  2049. for (var i = 0; i < lblTxts.length; i++)
  2050. {
  2051. if (lblTxts[i])
  2052. {
  2053. if (lblLayouts[i] && lblLayouts[i]["bpmn:ParticipantParameter"])
  2054. continue;
  2055. lblTxts[i] = mxUtils.htmlEntities(lblTxts[i], false).replace(/\n/g, '<br/>');
  2056. var geo = node.geometry;
  2057. var lblCell = new mxCell(lblTxts[i], new mxGeometry(0, 0, geo.width, geo.height), 'text;html=1;spacing=0;' + this.styleMap2Str(lblStyles[i]));
  2058. lblCell.vertex = true;
  2059. node.insert(lblCell, lastChildIndex);
  2060. var lGeo = lblCell.geometry;
  2061. // console.log(lblTxts[i]);
  2062. // console.log(lblLayouts[i]);
  2063. if (lblLayouts[i]["y:RatioAnchoredLabelModelParameter"])
  2064. {
  2065. var strSize = mxUtils.getSizeForString(lblTxts[i], lblStyles[i]["fontSize"], lblStyles[i]["fontFamily"]);
  2066. var offsetStr = lblLayouts[i]["y:RatioAnchoredLabelModelParameter"]["LayoutOffset"];
  2067. if (offsetStr)
  2068. {
  2069. var parts = offsetStr.split(',');
  2070. lGeo.x = parseFloat(parts[0]);
  2071. lGeo.y = parseFloat(parts[1]);
  2072. lGeo.width = strSize.width;
  2073. lGeo.height = strSize.height;
  2074. lblCell.style += ";spacingTop=-4;";
  2075. }
  2076. else
  2077. {
  2078. //TODO map there?
  2079. var lblRatio = lblLayouts[i]["y:RatioAnchoredLabelModelParameter"]["LabelRatio"];
  2080. var layoutRatio = lblLayouts[i]["y:RatioAnchoredLabelModelParameter"]["LayoutRatio"];
  2081. lblCell.style += ";align=center;";
  2082. }
  2083. }
  2084. else if (lblLayouts[i]["y:InteriorLabelModel"]) //TODO this is probably can be done by setting the value?
  2085. {
  2086. //TODO merge with next one if they are identical in all cases!
  2087. switch (lblLayouts[i]["y:InteriorLabelModel"])
  2088. {
  2089. case "Center":
  2090. lblCell.style += ";verticalAlign=middle;";
  2091. break;
  2092. case "North":
  2093. lGeo.height = 1;
  2094. break;
  2095. case "West":
  2096. lGeo.width = geo.height;
  2097. lGeo.height = geo.width;
  2098. //-90 rotation of origin
  2099. lGeo.y = geo.height /2 - geo.width /2;
  2100. lGeo.x = -lGeo.y;
  2101. lblCell.style += ";rotation=-90";
  2102. break;
  2103. }
  2104. lblCell.style += ";align=center;";
  2105. }
  2106. //TODO Spacing still need to be adjusted
  2107. else if (lblLayouts[i]["y:StretchStripeLabelModel"] || lblLayouts[i]["y:StripeLabelModelParameter"])
  2108. {
  2109. //TODO merge with previous one if they are identical in all cases!
  2110. var dir = lblLayouts[i]["y:StretchStripeLabelModel"] || lblLayouts[i]["y:StripeLabelModelParameter"]["Position"];
  2111. switch (dir)
  2112. {
  2113. case "North":
  2114. lGeo.height = 1;
  2115. break;
  2116. case "West":
  2117. lGeo.width = geo.height;
  2118. lGeo.height = geo.width;
  2119. //-90 rotation of origin
  2120. lGeo.y = geo.height /2 - geo.width /2;
  2121. lGeo.x = -lGeo.y;
  2122. lblCell.style += ";rotation=-90;";
  2123. break;
  2124. }
  2125. }
  2126. else if (lblLayouts[i]["bpmn:PoolHeaderLabelModel"])
  2127. {
  2128. //TODO merge with previous one if they are identical in all cases!
  2129. switch (lblLayouts[i]["bpmn:PoolHeaderLabelModel"])
  2130. {
  2131. case "NORTH":
  2132. lGeo.height = 1;
  2133. break;
  2134. case "WEST":
  2135. lGeo.width = geo.height;
  2136. lGeo.height = geo.width;
  2137. //-90 rotation of origin
  2138. lGeo.y = geo.height /2 - geo.width /2;
  2139. lGeo.x = -lGeo.y;
  2140. lblCell.style += ";rotation=-90;";
  2141. break;
  2142. }
  2143. lblCell.style += ";align=center;";
  2144. }
  2145. else if (lblLayouts[i]["y:InteriorStretchLabelModelParameter"])
  2146. {
  2147. //TODO probably mapObject is needed in this method in general
  2148. try {
  2149. var insets = lblLayouts[i]["y:InteriorStretchLabelModelParameter"]["Model"]["y:InteriorStretchLabelModel"]["Insets"];
  2150. //TODO how to map it?
  2151. } catch(e) {
  2152. //Ignore
  2153. }
  2154. lblCell.style += ";align=center;";
  2155. }
  2156. else if (lblLayouts[i]["y:ExteriorLabelModel"])
  2157. {
  2158. var lblPos;
  2159. switch (lblLayouts[i]["y:ExteriorLabelModel"])
  2160. {
  2161. case "East":
  2162. lblCell.style += ";labelPosition=right;verticalLabelPosition=middle;align=left;verticalAlign=middle;";
  2163. break;
  2164. case "South":
  2165. lblCell.style += ";labelPosition=center;verticalLabelPosition=bottom;align=center;verticalAlign=top;";
  2166. break;
  2167. case "North":
  2168. lblCell.style += ";labelPosition=center;verticalLabelPosition=top;align=center;verticalAlign=bottom;"
  2169. break;
  2170. case "West":
  2171. lblCell.style += ";labelPosition=left;verticalLabelPosition=middle;align=right;verticalAlign=middle;";
  2172. break;
  2173. }
  2174. }
  2175. else if (lblLayouts[i]["y:FreeEdgeLabelModelParameter"])
  2176. {
  2177. lGeo.relative = true;
  2178. lGeo.adjustIt = true;
  2179. var layout = lblLayouts[i]["y:FreeEdgeLabelModelParameter"];
  2180. var ratio = layout["Ratio"];
  2181. var distance = layout["Distance"];
  2182. var angle = layout["Angle"];
  2183. //The geometry is adjusted after finishing the graph import (in decode method)
  2184. if (ratio)
  2185. {
  2186. lGeo.x = parseFloat(ratio);
  2187. }
  2188. if (distance)
  2189. {
  2190. lGeo.y = parseFloat(distance);
  2191. }
  2192. if (angle)
  2193. {
  2194. lblCell.style += ";rotation=" + (parseFloat(angle) * (180 / Math.PI));
  2195. }
  2196. lblCell.style += ";verticalAlign=middle;";
  2197. }
  2198. else if (lblLayouts[i]["y:EdgePathLabelModelParameter"])
  2199. {
  2200. lGeo.relative = true;
  2201. var layout = lblLayouts[i]["y:EdgePathLabelModelParameter"];
  2202. var side = layout["SideOfEdge"];
  2203. var ratio = layout["SegmentRatio"];
  2204. lGeo.x = ratio? (2 * parseFloat(ratio) - 1) : 0;
  2205. //TODO this is an approximation, it needs to take into consideration the segment direction and label size
  2206. if (side)
  2207. {
  2208. switch(side)
  2209. {
  2210. case "RightOfEdge":
  2211. lGeo.y = -15;
  2212. break;
  2213. case "LeftOfEdge":
  2214. lGeo.y = 15;
  2215. break;
  2216. }
  2217. }
  2218. lblCell.style += ";verticalAlign=middle;";
  2219. }
  2220. else //Desktop format or edge
  2221. {
  2222. var lblX = parseFloat(lblLayouts[i]["x"]),
  2223. lblY = parseFloat(lblLayouts[i]["y"]);
  2224. if (lblLayouts[i]["width"]) lGeo.width = parseFloat(lblLayouts[i]["width"]);
  2225. if (lblLayouts[i]["height"]) lGeo.height = parseFloat(lblLayouts[i]["height"]);
  2226. if (node.edge)
  2227. {
  2228. lGeo.relative = true;
  2229. lGeo.x = 0;
  2230. lGeo.y = 0;
  2231. var dx = node.source.geometry.getCenterX() - node.target.geometry.getCenterX();
  2232. var dy = node.source.geometry.getCenterY() - node.target.geometry.getCenterY();
  2233. if (graph && absPoints && lblLayouts[i]["y:ModelParameter"] && lblLayouts[i]["y:ModelParameter"]["y:SmartEdgeLabelModelParameter"])
  2234. {
  2235. var layout = lblLayouts[i]["y:ModelParameter"]["y:SmartEdgeLabelModelParameter"];
  2236. var angle = parseFloat(layout.angle), distance = parseFloat(layout.distance), distanceToCenter = layout.distanceToCenter == "true",
  2237. position = layout.position, ratio = parseFloat(layout.ratio), segment = parseFloat(layout.segment);
  2238. var eState = new mxCellState();
  2239. eState.absolutePoints = absPoints;
  2240. graph.view.updateEdgeBounds(eState);
  2241. var sign = (position == "left"? 1 : -1);
  2242. if (segment == -1 && angle == 6.283185307179586)
  2243. {
  2244. //TODO FIXME this case is still incorrect
  2245. lGeo.offset = new mxPoint(Math.abs(ratio) < 1? eState.segments[0] * ratio : ratio, sign * distance);
  2246. }
  2247. else
  2248. {
  2249. if (segment == -1) segment = 0;
  2250. //get the edge cell state to get the segments
  2251. var dist = 0;
  2252. for (var k = 0; k < segment; k++)
  2253. {
  2254. dist += eState.segments[k];
  2255. }
  2256. dist += eState.segments[segment] * ratio;
  2257. lGeo.x = 2 * (dist / eState.length) - 1;
  2258. lGeo.y = ((position == "center"? 0 : distance) + lGeo.height/2 * sign * (Math.abs(dx) > Math.abs(dy)? 1 : -1)) * sign;
  2259. }
  2260. }
  2261. else if (!isNaN(lblX) && !isNaN(lblY))
  2262. {
  2263. lGeo.offset = new mxPoint(lblX + dx/2 + (dx > 0? -lGeo.width : lGeo.width), lblY);
  2264. }
  2265. }
  2266. else
  2267. {
  2268. lGeo.x = lblX || 0;
  2269. lGeo.y = lblY || 0;
  2270. }
  2271. }
  2272. if (lblStyles[i]["rotation"])
  2273. {
  2274. //TODO fix label coordinates after rotation
  2275. //console.log(lGeo, lblStyles[i]["rotation"]);
  2276. if (lblStyles[i]["rotation"] == 270)
  2277. {
  2278. lGeo.x -= lGeo.height/2;
  2279. }
  2280. }
  2281. }
  2282. }
  2283. return {lblTxts: lblTxts, lblStyles: lblStyles};
  2284. };
  2285. mxGraphMlCodec.prototype.processPage = function (graph, pageIndex)
  2286. {
  2287. var codec = new mxCodec();
  2288. var node = codec.encode(graph.getModel());
  2289. node.setAttribute("style", "default-style2");
  2290. var modelString = mxUtils.getXml(node);
  2291. var output = "<diagram name=\"Page " + pageIndex + "\">";
  2292. output += Graph.compress(modelString);
  2293. output += "</diagram>";
  2294. return output;
  2295. };
  2296. //These are the same as mxVsdxUtils functions, but added here to be self-dependent
  2297. /**
  2298. * Returns a collection of direct child Elements that match the specified tag name
  2299. * @param {*} parent the parent whose direct children will be processed
  2300. * @param {string} name the child tag name to match
  2301. * @return {*[]} a collection of matching Elements
  2302. */
  2303. mxGraphMlCodec.prototype.getDirectChildNamedElements = function (parent, name) {
  2304. var result = ([]);
  2305. for (var child = parent.firstChild; child != null; child = child.nextSibling) {
  2306. if ((child != null && (child.nodeType == 1)) && (name == child.nodeName)) {
  2307. /* add */ result.push(child);
  2308. }
  2309. }
  2310. ;
  2311. return result;
  2312. };
  2313. mxGraphMlCodec.prototype.getDirectFirstChildNamedElements = function (parent, name) {
  2314. for (var child = parent.firstChild; child != null; child = child.nextSibling) {
  2315. if ((child != null && (child.nodeType == 1)) && (name == child.nodeName)) {
  2316. return child;
  2317. }
  2318. }
  2319. ;
  2320. return null;
  2321. };
  2322. /**
  2323. * Returns a collection of direct child Elements
  2324. * @param {*} parent the parent whose direct children will be processed
  2325. * @return {*[]} a collection of all child Elements
  2326. */
  2327. mxGraphMlCodec.prototype.getDirectChildElements = function (parent) {
  2328. var result = ([]);
  2329. for (var child = parent.firstChild; child != null; child = child.nextSibling) {
  2330. if (child != null && (child.nodeType == 1)) {
  2331. /* add */ result.push(child);
  2332. }
  2333. }
  2334. ;
  2335. return result;
  2336. };
  2337. /**
  2338. * Returns the first direct child Element
  2339. * @param {*} parent the parent whose direct first child will be processed
  2340. * @return {*} the first child Element
  2341. */
  2342. mxGraphMlCodec.prototype.getDirectFirstChildElement = function (parent) {
  2343. for (var child = parent.firstChild; child != null; child = child.nextSibling) {
  2344. if (child != null && (child.nodeType == 1)) {
  2345. return child;
  2346. }
  2347. }
  2348. ;
  2349. return null;
  2350. };
  2351. var mxGraphMlConverters = //TODO this code is taken from yworks.com. Is that OK?
  2352. {
  2353. "orgchartconverters.linebreakconverter": function(e, t) {
  2354. if (typeof e === "string") {
  2355. var i = e;
  2356. while (i.length > 20 && i.indexOf(" ") > -1)
  2357. i = i.substring(0, i.lastIndexOf(" "));
  2358. return t === "true" ? i : e.substring(i.length)
  2359. }
  2360. return ""
  2361. },
  2362. "orgchartconverters.borderconverter": function(e, t) {
  2363. return typeof e === "boolean" ? e ? "#FFBB33" : "rgba(0,0,0,0)" : "#FFF"
  2364. },
  2365. "orgchartconverters.addhashconverter": function(e, t) {
  2366. return typeof e === "string" ? typeof t === "string" ? "#" + e + t : "#" + e : e
  2367. },
  2368. "orgchartconverters.intermediateconverter": function(e, t) {
  2369. return typeof e === "string" && e.length > 17 ? e.replace(/^(.)(\S*)(.*)/, "$1.$3") : e
  2370. },
  2371. "orgchartconverters.overviewconverter": function(e, t) {
  2372. return typeof e === "string" && e.length > 0 ? e.replace(/^(.)(\S*)(.*)/, "$1.$3") : ""
  2373. }
  2374. };
  2375. var mxGraphMlArrowsMap =
  2376. {
  2377. "SIMPLE": "open",
  2378. "TRIANGLE": "block",
  2379. "DIAMOND": "diamond",
  2380. "CIRCLE": "oval",
  2381. "CROSS": "cross",
  2382. "SHORT": "classicThin",
  2383. "DEFAULT": "classic",
  2384. "NONE": "none",
  2385. //desktop
  2386. "none": "none",
  2387. "white_delta_bar": "block", //FIXME not a match
  2388. "delta": "block",
  2389. "standard": "classic",
  2390. "diamond": "diamond",
  2391. "white_diamond": "diamond",
  2392. "white_delta": "block",
  2393. "plain": "open",
  2394. "skewed_dash": "dash",
  2395. "concave": "openThin", //FIXME not exact match
  2396. "transparent_circle": "oval",
  2397. "crows_foot_many": "ERmany",
  2398. "crows_foot_one": "ERone",
  2399. "crows_foot_one_optional": "ERzeroToOne",
  2400. "crows_foot_one_mandatory": "ERmandOne",
  2401. "crows_foot_many_optional": "ERzeroToMany",
  2402. "crows_foot_many_mandatory": "ERoneToMany",
  2403. "white_circle": "oval",
  2404. "t_shape": "ERone", //FIXME not a match
  2405. "short": "classicThin",
  2406. "convex": "", //FIXME not a match
  2407. "cross": "cross"
  2408. };
  2409. var mxGraphMlShapesMap =
  2410. {
  2411. "star5": "mxgraph.basic.star;flipV=1", //TODO This is not close enough!
  2412. "star6": "mxgraph.basic.6_point_star",//;rotation=30", //TODO requires rotation!
  2413. "star8": "mxgraph.basic.8_point_star",
  2414. "sheared_rectangle": "parallelogram",
  2415. "sheared_rectangle2": "parallelogram;flipH=1",
  2416. "hexagon": "hexagon",
  2417. "octagon": "mxgraph.basic.octagon",
  2418. "ellipse": "ellipse",
  2419. "round_rectangle": "rect;rounded=1;arcsize=30",
  2420. "diamond": "rhombus",
  2421. "fat_arrow": "step;perimeter=stepPerimeter",
  2422. "fat_arrow2": "step;perimeter=stepPerimeter;flipH=1",
  2423. "trapez": "trapezoid;perimeter=trapezoidPerimeter;flipV=1",
  2424. "trapez2": "trapezoid;perimeter=trapezoidPerimeter",
  2425. "triangle": "triangle",//;rotation=-90", //TODO requires rotation!
  2426. "triangle2": "triangle",//;rotation=90", //TODO requires rotation!
  2427. "rectangle": "rect",
  2428. "rectangle3d": "", //TODO create this shape
  2429. "roundrectangle": "rect;rounded=1;arcsize=30",
  2430. "fatarrow": "step;perimeter=stepPerimeter",
  2431. "fatarrow2": "step;perimeter=stepPerimeter;flipH=1",
  2432. "parallelogram": "parallelogram",
  2433. "parallelogram2": "parallelogram;flipH=1",
  2434. "trapezoid2": "trapezoid;perimeter=trapezoidPerimeter;flipV=1",
  2435. "trapezoid": "trapezoid;perimeter=trapezoidPerimeter",
  2436. //Bevel TODO make them looks closer to yEd
  2437. "bevelnode": "rect;glass=1;",
  2438. "bevelnodewithshadow": "rect;glass=1;shadow=1",
  2439. "bevelnode2": "rect;glass=1;rounded=1;arcsize=30",
  2440. "bevelnode3": "rect;glass=1;rounded=1;arcsize=30;shadow=1",
  2441. "shinyplatenode": "rect;glass=1",//;rotation=-90",//TODO requires rotation!
  2442. "shinyplatenodewithshadow": "rect;glass=1;shadow=1",//;rotation=-90",//TODO requires rotation!
  2443. "shinyplatenode2": "rect;glass=1;rounded=1;arcsize=30",//;rotation=-90",//TODO requires rotation!
  2444. "shinyplatenode3": "rect;glass=1;rounded=1;arcsize=30;shadow=1",//;rotation=-90",//TODO requires rotation!
  2445. //Table
  2446. // "yed_table_node
  2447. //flowchart
  2448. "process": "mxgraph.flowchart.process",
  2449. "decision": "mxgraph.flowchart.decision",
  2450. "start1": "mxgraph.flowchart.start_1",
  2451. "start2": "mxgraph.flowchart.start_2;aspect=fixed",
  2452. "terminator": "mxgraph.flowchart.terminator",
  2453. "cloud": "cloud",
  2454. "data": "mxgraph.flowchart.data",
  2455. "directdata": "mxgraph.flowchart.direct_data",
  2456. "database": "mxgraph.flowchart.database",
  2457. "document": "mxgraph.flowchart.document",
  2458. "predefinedprocess": "mxgraph.flowchart.predefined_process",
  2459. "storeddata": "mxgraph.flowchart.stored_data",
  2460. "internalstorage": "mxgraph.flowchart.internal_storage",
  2461. "sequentialdata": "mxgraph.flowchart.sequential_data;aspect=fixed",
  2462. "manualinput": "mxgraph.flowchart.manual_input",
  2463. "card": "card;size=10",
  2464. "papertype": "mxgraph.flowchart.paper_tape",
  2465. "delay": "mxgraph.flowchart.delay",
  2466. "display": "mxgraph.flowchart.display",
  2467. "manualoperation": "mxgraph.flowchart.manual_operation",
  2468. "preparation": "mxgraph.flowchart.preparation",
  2469. "looplimit": "mxgraph.flowchart.loop_limit",
  2470. "looplimitend": "mxgraph.flowchart.loop_limit;flipV=1",
  2471. "onpagereference": "mxgraph.flowchart.on-page_reference;aspect=fixed",
  2472. "offpagereference": "mxgraph.flowchart.off-page_reference;aspect=fixed",
  2473. "annotation": "mxgraph.flowchart.annotation_1", //TODO not similar!
  2474. "usermessage": "mxgraph.arrows2.arrow;dy=0;dx=10;notch=0", //TODO requires rotation!
  2475. "networkmessage": "mxgraph.arrows2.arrow;dy=0;dx=0;notch=10",
  2476. //The same like above but with "com.yworks.flowchart." prefex. TODO should we just remove the prefex?
  2477. "com.yworks.flowchart.start1": "mxgraph.flowchart.start_1",
  2478. "com.yworks.flowchart.start2": "mxgraph.flowchart.start_2;aspect=fixed",
  2479. "com.yworks.flowchart.terminator": "mxgraph.flowchart.terminator",
  2480. "com.yworks.flowchart.process": "mxgraph.flowchart.process",
  2481. "com.yworks.flowchart.predefinedprocess": "mxgraph.flowchart.predefined_process",
  2482. "com.yworks.flowchart.decision": "mxgraph.flowchart.decision",
  2483. "com.yworks.flowchart.looplimit": "mxgraph.flowchart.loop_limit",
  2484. "com.yworks.flowchart.looplimitend": "mxgraph.flowchart.loop_limit;flipV=1",
  2485. "com.yworks.flowchart.document": "mxgraph.flowchart.document",
  2486. "com.yworks.flowchart.data": "mxgraph.flowchart.data",
  2487. "com.yworks.flowchart.directdata": "mxgraph.flowchart.direct_data",
  2488. "com.yworks.flowchart.storeddata": "mxgraph.flowchart.stored_data",
  2489. "com.yworks.flowchart.sequentialdata": "mxgraph.flowchart.sequential_data;aspect=fixed",
  2490. "com.yworks.flowchart.database": "mxgraph.flowchart.database",
  2491. "com.yworks.flowchart.internalstorage": "mxgraph.flowchart.internal_storage",
  2492. "com.yworks.flowchart.manualinput": "mxgraph.flowchart.manual_input",
  2493. "com.yworks.flowchart.card": "card;size=10",
  2494. "com.yworks.flowchart.papertype": "mxgraph.flowchart.paper_tape",
  2495. "com.yworks.flowchart.cloud": "cloud",
  2496. "com.yworks.flowchart.delay": "mxgraph.flowchart.delay",
  2497. "com.yworks.flowchart.display": "mxgraph.flowchart.display",
  2498. "com.yworks.flowchart.manualoperation": "mxgraph.flowchart.manual_operation",
  2499. "com.yworks.flowchart.preparation": "mxgraph.flowchart.preparation",
  2500. "com.yworks.flowchart.onpagereference": "mxgraph.flowchart.on-page_reference;aspect=fixed",
  2501. "com.yworks.flowchart.offpagereference": "mxgraph.flowchart.off-page_reference;aspect=fixed",
  2502. "com.yworks.flowchart.usermessage": "mxgraph.arrows2.arrow;dy=0;dx=10;notch=0", //TODO requires rotation!
  2503. "com.yworks.flowchart.networkmessage": "mxgraph.arrows2.arrow;dy=0;dx=0;notch=10",
  2504. "com.yworks.flowchart.annotation": "mxgraph.flowchart.annotation_1", //TODO not similar!
  2505. //icons (network)
  2506. "database.svg": "mxgraph.networks.storage", //TODO not similar!
  2507. "laptop.svg": "mxgraph.networks.laptop",//TODO not similar!
  2508. "server.svg": "mxgraph.networks.server",//TODO not similar!
  2509. "smartphone.svg": "mxgraph.networks.mobile",//TODO not similar! //TODO fixed aspect ratio
  2510. "switch.svg": "mxgraph.networks.switch",//TODO not similar! //TODO fixed aspect ratio
  2511. "wlan.svg": "mxgraph.networks.wireless_hub",//TODO not similar!
  2512. "workstation.svg": "mxgraph.networks.pc",//TODO not similar!
  2513. //bpmn
  2514. "transaction": "ext;double=1;rounded=1",
  2515. "sub_process": "ext;rounded=1",
  2516. "call_activity": "ext;rounded=1;strokeWidth=3",
  2517. //TODO two colors for stroke!
  2518. "exclusive_with_marker": "mxgraph.bpmn.shape;perimeter=rhombusPerimeter;background=gateway;outline=none;symbol=exclusiveGw",
  2519. "event_based": "mxgraph.bpmn.shape;perimeter=rhombusPerimeter;background=gateway;outline=boundInt;symbol=multiple",
  2520. "parallel": "mxgraph.bpmn.shape;perimeter=rhombusPerimeter;background=gateway;outline=none;symbol=parallelGw",
  2521. "inclusive": "mxgraph.bpmn.shape;perimeter=rhombusPerimeter;background=gateway;outline=end;symbol=general",
  2522. "complex": "mxgraph.bpmn.shape;perimeter=rhombusPerimeter;background=gateway;outline=none;symbol=complexGw",
  2523. "exclusive_event_based": "mxgraph.bpmn.shape;perimeter=rhombusPerimeter;background=gateway;outline=standard;symbol=multiple",
  2524. "parallel_event_based": "mxgraph.bpmn.shape;perimeter=rhombusPerimeter;background=gateway;outline=standard;symbol=parallelMultiple",
  2525. //hexagon
  2526. "calling_global_conversation": "hexagon;strokeWidth=4",
  2527. //mxgraph.bpmn.shape;perimeter=ellipsePerimeter;symbol=general
  2528. "message": "mxgraph.bpmn.shape;perimeter=ellipsePerimeter;symbol=message",
  2529. "timer": "mxgraph.bpmn.shape;perimeter=ellipsePerimeter;symbol=timer",
  2530. "escalation": "mxgraph.bpmn.shape;perimeter=ellipsePerimeter;symbol=escalation",
  2531. "conditional": "mxgraph.bpmn.shape;perimeter=ellipsePerimeter;symbol=conditional",
  2532. "link": "mxgraph.bpmn.shape;perimeter=ellipsePerimeter;symbol=link",
  2533. "error": "mxgraph.bpmn.shape;perimeter=ellipsePerimeter;symbol=error",
  2534. "cancel": "mxgraph.bpmn.shape;perimeter=ellipsePerimeter;symbol=cancel",
  2535. "compensation": "mxgraph.bpmn.shape;perimeter=ellipsePerimeter;symbol=compensation",
  2536. "signal": "mxgraph.bpmn.shape;perimeter=ellipsePerimeter;symbol=signal",
  2537. "multiple": "mxgraph.bpmn.shape;perimeter=ellipsePerimeter;symbol=multiple",
  2538. "parallel_multiple": "mxgraph.bpmn.shape;perimeter=ellipsePerimeter;symbol=parallelMultiple",
  2539. "terminate": "mxgraph.bpmn.shape;perimeter=ellipsePerimeter;symbol=terminate",
  2540. // "com.yworks.bpmn.pool
  2541. "com.yworks.bpmn.activity.withshadow": "js:bpmnActivityShadow",
  2542. "com.yworks.bpmn.activity": "js:bpmnActivity",
  2543. "com.yworks.bpmn.gateway.withshadow": "mxgraph.bpmn.shape;perimeter=rhombusPerimeter;background=gateway;shadow=1",
  2544. "com.yworks.bpmn.gateway": "mxgraph.bpmn.shape;perimeter=rhombusPerimeter;background=gateway",
  2545. "com.yworks.bpmn.event.withshadow": "mxgraph.bpmn.shape;perimeter=ellipsePerimeter;shadow=1",
  2546. "com.yworks.bpmn.event": "mxgraph.bpmn.shape;perimeter=ellipsePerimeter",
  2547. "com.yworks.bpmn.conversation.withshadow": "hexagon;shadow=1",
  2548. "com.yworks.bpmn.conversation": "hexagon",
  2549. "com.yworks.bpmn.artifact.withshadow": "js:bpmnArtifactShadow",
  2550. "com.yworks.bpmn.artifact": "js:bpmnArtifact",
  2551. bpmnOutline: {
  2552. "sub_process_interrupting": "eventInt",
  2553. "sub_process_non_interrupting": "eventNonint",
  2554. "catching": "catching",
  2555. "boundary_interrupting": "boundInt",
  2556. "boundary_non_interrupting": "boundNonint",
  2557. "throwing": "throwing",
  2558. "end": "end",
  2559. "event_characteristic_start": "standard",
  2560. "event_characteristic_end": "end",
  2561. "event_characteristic_intermediate_catching": "catching",
  2562. "event_characteristic_start_event_sub_process_interrupting": "eventInt",
  2563. "event_characteristic_intermediate_boundary_interrupting": "boundInt"
  2564. },
  2565. bpmnSymbol: {
  2566. "event_type_plain": "general",
  2567. "event_type_message": "message",
  2568. "event_type_timer": "timer",
  2569. "event_type_escalation": "escalation",
  2570. "event_type_conditional": "conditional",
  2571. "event_type_link": "link",
  2572. "event_type_error": "error",
  2573. "event_type_cancel": "cancel",
  2574. "event_type_compensation": "compensation",
  2575. "event_type_signal": "signal",
  2576. "event_type_multiple": "multiple",
  2577. "event_type_parallel_multiple": "parallelMultiple",
  2578. "event_type_terminate": "terminate",
  2579. "gateway_type_plain": "",
  2580. "gateway_type_data_based_exclusive": "exclusiveGw",
  2581. "gateway_type_inclusive": "general;outline=end",
  2582. "gateway_type_parallel": "parallelGw",
  2583. "gateway_type_complex": "complexGw",
  2584. "gateway_type_event_based_exclusive": "multiple;outline=catching",
  2585. "gateway_type_event_based_exclusive_start_process": "multiple;outline=standard",
  2586. "gateway_type_parallel_event_based_exclusive_start_process": "parallelMultiple;outline=standard",
  2587. "conversation_type": "",
  2588. "artifact_type_data_object": "js:bpmnDataObject",
  2589. "artifact_type_annotation": "mxgraph.flowchart.annotation_1",
  2590. "artifact_type_group": "rect;fillColor=none;dashed=1;dashPattern=3 1 1 1;collapsible=0;rounded=1",
  2591. "artifact_type_data_store": "datastore",
  2592. "artifact_type_reply_message": "message;strokeColor=#000000;fillColor=#A1A1A1",
  2593. "artifact_type_request_message": "message",
  2594. "connection_type_sequence_flow": "",
  2595. "connection_type_default_flow": "",
  2596. "connection_type_conditional_flow": "",
  2597. "connection_type_association": "",
  2598. "connection_type_directed_association": "",
  2599. "connection_type_bidirected_association": "",
  2600. "connection_type_message_flow": "",
  2601. "connection_type_conversation_link": "",
  2602. "connection_type_forked_conversation_link": "",
  2603. "pool_type_lane_and_column": "",
  2604. "pool_type_empty": "",
  2605. "pool_type_lane": "",
  2606. "pool_type_column": "",
  2607. "activity_type": ""
  2608. },
  2609. //desktop entity relationship
  2610. "com.yworks.entityrelationship.big_entity": "js:relationship_big_entity",
  2611. "com.yworks.entityrelationship.small_entity" : "ext",
  2612. "com.yworks.entityrelationship.relationship": "rhombus",
  2613. "com.yworks.entityrelationship.attribute": "js:relationship_attribute",
  2614. //SBGN
  2615. "com.yworks.sbgn.unspecifiedentity": "ellipse",
  2616. "com.yworks.sbgn.simplechemical": "ellipse",
  2617. "com.yworks.sbgn.macromolecule": "ext;rounded=1",
  2618. "com.yworks.sbgn.nucleicacidfeature": "", //TODO create this shape!
  2619. "com.yworks.sbgn.perturbingagent": "", //TODO create this shape!
  2620. "com.yworks.sbgn.phenotype": "hexagon;perimeter=hexagonPerimeter2;size=0.2",
  2621. "com.yworks.sbgn.emptyset": "lineEllipse;line=vertical;perimeter=ellipsePerimeter",//;rotation=45", //TODO create this shape!
  2622. "com.yworks.sbgn.submap": "", //TODO create this shape!
  2623. "com.yworks.sbgn.unitofinformation": "", //TODO create this shape!
  2624. "com.yworks.sbgn.statevariable": "mxgraph.flowchart.terminator",
  2625. "com.yworks.sbgn.tag": "offPageConnector;size=0.25", //;rotation=90", //TODO create this shape without rotation!
  2626. "com.yworks.sbgn.process": "rect",
  2627. "com.yworks.sbgn.operator": "ellipse",
  2628. //special edges
  2629. "com.yworks.edge.framed": "link",
  2630. //Male/Female icons (FIXME Not similar and unsafe as it refers to remote resources)
  2631. "usericon_female1.svg": "image;image=https://cdn1.iconfinder.com/data/icons/user-pictures/100/female1-128.png",
  2632. "usericon_female2.svg": "image;image=https://cdn1.iconfinder.com/data/icons/user-pictures/100/female1-128.png",
  2633. "usericon_female3.svg": "image;image=https://cdn1.iconfinder.com/data/icons/user-pictures/100/female1-128.png",
  2634. "usericon_female4.svg": "image;image=https://cdn1.iconfinder.com/data/icons/user-pictures/100/female1-128.png",
  2635. "usericon_female5.svg": "image;image=https://cdn1.iconfinder.com/data/icons/user-pictures/100/female1-128.png",
  2636. "usericon_male1.svg": "image;image=https://cdn1.iconfinder.com/data/icons/user-pictures/101/malecostume-128.png",
  2637. "usericon_male2.svg": "image;image=https://cdn1.iconfinder.com/data/icons/user-pictures/101/malecostume-128.png",
  2638. "usericon_male3.svg": "image;image=https://cdn1.iconfinder.com/data/icons/user-pictures/101/malecostume-128.png",
  2639. "usericon_male4.svg": "image;image=https://cdn1.iconfinder.com/data/icons/user-pictures/101/malecostume-128.png",
  2640. "usericon_male5.svg": "image;image=https://cdn1.iconfinder.com/data/icons/user-pictures/101/malecostume-128.png"
  2641. };
  2642. var mxGraphMlConstants =
  2643. {
  2644. ID: "id",
  2645. KEY_FOR: "for",
  2646. KEY_NAME: "attr.name",
  2647. KEY_TYPE: "attr.type",
  2648. KEY_YTYPE: "yfiles.type",
  2649. GRAPH: "graph",
  2650. GRAPHML: "graphml",
  2651. NODE: "node",
  2652. EDGE: "edge",
  2653. HYPEREDGE: "hyperedge",
  2654. PORT: "port",
  2655. ENDPOINT: "endpoint",
  2656. KEY: "key",
  2657. DATA: "data",
  2658. ALL: "all",
  2659. EDGE_SOURCE: "source",
  2660. EDGE_SOURCE_PORT: "sourceport",
  2661. EDGE_TARGET: "target",
  2662. EDGE_TARGET_PORT: "targetport",
  2663. EDGE_DIRECTED: "directed",
  2664. EDGE_UNDIRECTED: "undirected",
  2665. EDGE_DEFAULT: "edgedefault",
  2666. PORT_NAME: "name",
  2667. HEIGHT: "Height",
  2668. WIDTH: "Width",
  2669. X: "X",
  2670. Y: "Y",
  2671. HEIGHT_L: "height",
  2672. WIDTH_L: "width",
  2673. X_L: "x",
  2674. Y_L: "y",
  2675. JGRAPH: "jGraph:",
  2676. GEOMETRY: "y:Geometry",
  2677. FILL: "Fill",
  2678. SHAPENODE: "y:ShapeNode",
  2679. SHAPEEDGE: "ShapeEdge",
  2680. JGRAPH_URL: "http://www.jgraph.com/",
  2681. KEY_NODE_ID: "d0",
  2682. KEY_NODE_NAME: "nodeData",
  2683. KEY_EDGE_ID: "d1",
  2684. KEY_EDGE_NAME: "edgeData",
  2685. STYLE: "Style",
  2686. SHAPE: "Shape",
  2687. TYPE: "type",
  2688. LABEL: "label",
  2689. TEXT: "text",
  2690. PROPERTIES: "properties",
  2691. SOURCETARGET: "SourceTarget",
  2692. RECT: "y:RectD",
  2693. NODE_LABELS: "NodeLabels",
  2694. NODE_LABEL: "y:NodeLabel",
  2695. NODE_GEOMETRY: "NodeGeometry",
  2696. USER_TAGS: "UserTags",
  2697. NODE_STYLE: "NodeStyle",
  2698. NODE_GRAPHICS: "nodegraphics",
  2699. NODE_VIEW_STATE: "NodeViewState",
  2700. EDGE_LABELS: "EdgeLabels",
  2701. EDGE_GEOMETRY: "EdgeGeometry",
  2702. EDGE_STYLE: "EdgeStyle",
  2703. EDGE_VIEW_STATE: "EdgeViewState",
  2704. PORT_LOCATION_PARAMETER: "PortLocationParameter",
  2705. PORT_STYLE: "PortStyle",
  2706. PORT_VIEW_STATE: "PortViewState",
  2707. SHARED_DATA: "SharedData",
  2708. Y_SHARED_DATA: "y:SharedData",
  2709. X_KEY: "x:Key",
  2710. GRAPHML_REFERENCE: "y:GraphMLReference",
  2711. RESOURCE_KEY: "ResourceKey",
  2712. Y_RESOURCES: "y:Resources",
  2713. Y_RESOURCE: "y:Resource",
  2714. REFID: "refid",
  2715. X_LIST: "x:List",
  2716. X_STATIC: "x:Static",
  2717. Y_BEND: "y:Bend",
  2718. LOCATION: "Location",
  2719. Y_LABEL: "y:Label",
  2720. LAYOUTPARAMETER: "LayoutParameter",
  2721. YJS_DEFAULTLABELSTYLE: "yjs:DefaultLabelStyle",
  2722. MEMBER: "Member"
  2723. };
  2724. EditorUi.prototype.doImportGraphML = function(xmlData, done, onerror)
  2725. {
  2726. new mxGraphMlCodec().decode(xmlData, done, onerror);
  2727. };