Editor.js 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931
  1. /**
  2. * Copyright (c) 2006-2017, JGraph Ltd
  3. * Copyright (c) 2006-2017, Gaudenz Alder
  4. */
  5. (function()
  6. {
  7. /**
  8. * Specifies the app name. Default is document.title.
  9. */
  10. Editor.prototype.appName = 'draw.io';
  11. /**
  12. * Used in the GraphViewer lightbox.
  13. */
  14. Editor.closeImage = (mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAMAAADzN3VRAAAApVBMVEUAAAD////k5OT///8AAAB1dXXMzMz9/f39/f37+/v5+fn+/v7///9iYmJaWlqFhYWnp6ejo6OHh4f////////////////7+/v5+fnx8fH///8AAAD///8bGxv7+/v5+fkoKCghISFDQ0MYGBjh4eHY2Njb29tQUFBvb29HR0c/Pz82NjYrKyu/v78SEhLu7u7s7OzV1dVVVVU7OzsVFRXAv78QEBBzqehMAAAAG3RSTlMAA/7p/vz5xZlrTiPL/v78+/v7+OXd2TYQDs8L70ZbAAABKUlEQVQoz3VS13LCMBBUXHChd8iukDslQChJ/v/TchaG4cXS+OSb1c7trU7V60OpdRz2ZtNZL4zXNlcN8BEtSG6+NxIXkeRPoBuQ1cjvZ31/VJFB10ISli6diYfH8iYO3WUNCcNlB0gTrXOtkxTo0O1aKKiBBMhhv2MNBQKoiA5wxlZo0JDzD3AYKbWacyj3fs01wxey0pyEP+R8pWKWXoqtIZ0DDg5pbki9krEKOa6LVDQsdoXEsi46Zqh69KFz7B1u7Hb2yDV8firXDKBlZ4UFiswKGRhXTS93/ECK7yxnJ3+S3y/ThpO+cfSD017nqa18aasabU0/t7d+tk0/1oMEJ1NaD67iwdF68OabFSLn+eHb0+vjy+uk8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w862xdC9ytW/y9a/zNbCztjG0drH0tvK1N3M1t7N19/U3ePb4uff5urj6Ozk6e3l6u7m6u7o7PDq7vDt8PPv8vTw8vTw8/X19vf6+vv///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGQ8CXcEgsvlytVUplJLJIpSEDUESFTELBwSgCCQEV42kjDFiMo4uQsDB2MkLHoEHUTD7DRAHC8VAiZ0QSCgYIDxhNiUEAOw==';
  23. /**
  24. * Used in the GraphViewer lightbox.
  25. */
  26. Editor.tweetImage = (mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAARlJREFUeNpi/P//PwM1ABMDlQDVDGKAeo0biMXwKOMD4ilA/AiInwDxfCBWBeIgINYDmwE1yB2Ir0Alsbl6JchONPwNiC8CsTPIDJjXuIBYG4gPAnE8EDMjGaQCxGFYLOAEYlYg/o3sNSkgfo1k2ykgLgRiIyAOwOIaGE6CmwE1SA6IZ0BNR1f8GY9BXugG2UMN+YtHEzr+Aw0OFINYgHgdCYaA8HUgZkM3CASEoYb9ItKgapQkhGQQKC0dJdKQx1CLsRoEArpAvAuI3+Ix5B8Q+2AkaiyZVgGId+MwBBQhKVhzB9QgKyDuAOJ90BSLzZBzQOyCK5uxQNnXoGlJHogfIOU7UCI9C8SbgHgjEP/ElRkZB115BBBgAPbkvQ/azcC0AAAAAElFTkSuQmCC' : IMAGE_PATH + '/tweet.png';
  27. /**
  28. * Used in the GraphViewer lightbox.
  29. */
  30. Editor.facebookImage = (mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAMAAABhEH5lAAAARVBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADc6ur3AAAAFnRSTlMAYmRg2KVCC/oPq0uAcVQtHtvZuoYh/a7JUAAAAGJJREFUGNOlzkkOgCAMQNEvagvigBP3P6pRNoCJG/+myVu0RdsqxcQqQ/NFVkKQgqwDzoJ2WKajoB66atcAa0GjX0D8lJHwNGfknYJzY77LDtDZ+L74j0z26pZI2yYlMN9TL17xEd+fl1D+AAAAAElFTkSuQmCC' : IMAGE_PATH + '/facebook.png';
  31. /**
  32. * Blank 1x1 pixel transparent PNG image.
  33. */
  34. Editor.blankImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==';
  35. /**
  36. * Default value for custom libraries in mxSettings.
  37. */
  38. Editor.defaultCustomLibraries = [];
  39. /**
  40. * Contains the default XML for an empty diagram.
  41. */
  42. Editor.defaultCsvValue = '##\n' +
  43. '## Example CSV import. Use ## for comments and # for configuration. Paste CSV below.\n' +
  44. '## The following names are reserved and should not be used (or ignored):\n' +
  45. '## id, tooltip, placeholder(s), link and label (see below)\n' +
  46. '##\n' +
  47. '#\n' +
  48. '## Node label with placeholders and HTML.\n' +
  49. '## Default is \'%name_of_first_column%\'.\n' +
  50. '#\n' +
  51. '# label: %name%<br><i style="color:gray;">%position%</i><br><a href="mailto:%email%">Email</a>\n' +
  52. '#\n' +
  53. '## Node style (placeholders are replaced once).\n' +
  54. '## Default is the current style for nodes.\n' +
  55. '#\n' +
  56. '# style: label;image=%image%;whiteSpace=wrap;html=1;rounded=1;fillColor=%fill%;strokeColor=%stroke%;\n' +
  57. '#\n' +
  58. '## Uses the given column name as the identity for cells (updates existing cells).\n' +
  59. '## Default is no identity (empty value or -).\n' +
  60. '#\n' +
  61. '# identity: -\n' +
  62. '#\n' +
  63. '## Connections between rows ("from": source colum, "to": target column).\n' +
  64. '## Label, style and invert are optional. Defaults are \'\', current style and false.\n' +
  65. '## The target column may contain a comma-separated list of values.\n' +
  66. '## Multiple connect entries are allowed.\n' +
  67. '#\n' +
  68. '# connect: {"from": "manager", "to": "name", "invert": true, "label": "manages", \\\n' +
  69. '# "style": "curved=1;endArrow=blockThin;endFill=1;fontSize=11;"}\n' +
  70. '# connect: {"from": "refs", "to": "id", "style": "curved=1;fontSize=11;"}\n' +
  71. '#\n' +
  72. '## Node width. Possible value are px or auto. Default is auto.\n' +
  73. '#\n' +
  74. '# width: auto\n' +
  75. '#\n' +
  76. '## Node height. Possible value are px or auto. Default is auto.\n' +
  77. '#\n' +
  78. '# height: auto\n' +
  79. '#\n' +
  80. '## Padding for autosize. Default is 0.\n' +
  81. '#\n' +
  82. '# padding: -26\n' +
  83. '#\n' +
  84. '## Comma-separated list of ignored columns for metadata. (These can be\n' +
  85. '## used for connections and styles but will not be added as metadata.)\n' +
  86. '#\n' +
  87. '# ignore: id,image,fill,stroke\n' +
  88. '#\n' +
  89. '## Column to be renamed to link attribute (used as link).\n' +
  90. '#\n' +
  91. '# link: url\n' +
  92. '#\n' +
  93. '## Spacing between nodes. Default is 40.\n' +
  94. '#\n' +
  95. '# nodespacing: 40\n' +
  96. '#\n' +
  97. '## Spacing between parallel edges. Default is 40.\n' +
  98. '#\n' +
  99. '# edgespacing: 40\n' +
  100. '#\n' +
  101. '## Name of layout. Possible values are auto, none, verticaltree, horizontaltree,\n' +
  102. '## verticalflow, horizontalflow, organic, circle. Default is auto.\n' +
  103. '#\n' +
  104. '# layout: auto\n' +
  105. '#\n' +
  106. '## ---- CSV below this line. First line are column names. ----\n' +
  107. 'name,position,id,location,manager,email,fill,stroke,refs,url,image\n' +
  108. 'Evan Miller,CFO,emi,Office 1,,me@example.com,#dae8fc,#6c8ebf,,https://www.draw.io,https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-9-2-128.png\n' +
  109. 'Edward Morrison,Brand Manager,emo,Office 2,Evan Miller,me@example.com,#d5e8d4,#82b366,,https://www.draw.io,https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-10-3-128.png\n' +
  110. 'Ron Donovan,System Admin,rdo,Office 3,Evan Miller,me@example.com,#d5e8d4,#82b366,"emo,tva",https://www.draw.io,https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-2-128.png\n' +
  111. 'Tessa Valet,HR Director,tva,Office 4,Evan Miller,me@example.com,#d5e8d4,#82b366,,https://www.draw.io,https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-3-128.png\n';
  112. /**
  113. * Global configuration of the Editor
  114. * see https://desk.draw.io/solution/articles/16000058316
  115. *
  116. * For defaultVertexStyle, defaultEdgeStyle and defaultLibraries, this must be called before
  117. * mxSettings.load via global config variable window.mxLoadSettings = false.
  118. */
  119. Editor.configure = function(config)
  120. {
  121. if (config != null)
  122. {
  123. Menus.prototype.defaultFonts = config.defaultFonts || Menus.prototype.defaultFonts;
  124. ColorDialog.prototype.presetColors = config.presetColors || ColorDialog.prototype.presetColors;
  125. ColorDialog.prototype.defaultColors = config.defaultColors || ColorDialog.prototype.defaultColors;
  126. StyleFormatPanel.prototype.defaultColorSchemes = config.defaultColorSchemes || StyleFormatPanel.prototype.defaultColorSchemes;
  127. // Custom CSS injected directly into the page
  128. if (config.css != null)
  129. {
  130. var s = document.createElement('style');
  131. s.setAttribute('type', 'text/css');
  132. s.appendChild(document.createTextNode(config.css));
  133. var t = document.getElementsByTagName('script')[0];
  134. t.parentNode.insertBefore(s, t);
  135. }
  136. // Overrides default libraries
  137. if (config.defaultLibraries != null)
  138. {
  139. Sidebar.prototype.defaultEntries = config.defaultLibraries;
  140. }
  141. // Overrides default custom libraries
  142. if (config.defaultCustomLibraries != null)
  143. {
  144. Editor.defaultCustomLibraries = config.defaultCustomLibraries;
  145. }
  146. // Overrides default vertex style
  147. if (config.defaultVertexStyle != null)
  148. {
  149. Graph.prototype.defaultVertexStyle = config.defaultVertexStyle;
  150. }
  151. // Overrides default edge style
  152. if (config.defaultEdgeStyle != null)
  153. {
  154. Graph.prototype.defaultEdgeStyle = config.defaultEdgeStyle;
  155. }
  156. }
  157. };
  158. /**
  159. * Executes the first step for connecting to Google Drive.
  160. */
  161. Editor.prototype.editButtonLink = (urlParams['edit'] != null) ? decodeURIComponent(urlParams['edit']) : null;
  162. /**
  163. *
  164. */
  165. if (urlParams['dev'] == '1')
  166. {
  167. Editor.prototype.editBlankUrl = Editor.prototype.editBlankUrl + '&dev=1';
  168. Editor.prototype.editBlankFallbackUrl = Editor.prototype.editBlankFallbackUrl + '&dev=1';
  169. }
  170. /**
  171. * Adds support for old stylesheets and compressed files
  172. */
  173. var editorSetGraphXml = Editor.prototype.setGraphXml;
  174. Editor.prototype.setGraphXml = function(node)
  175. {
  176. node = (node != null && node.nodeName != 'mxlibrary') ? this.extractGraphModel(node) : null;
  177. if (node != null)
  178. {
  179. // Checks input for parser errors
  180. var errs = node.getElementsByTagName('parsererror');
  181. if (errs != null && errs.length > 0)
  182. {
  183. var elt = errs[0];
  184. var divs = elt.getElementsByTagName('div');
  185. if (divs != null && divs.length > 0)
  186. {
  187. elt = divs[0];
  188. }
  189. throw {message: mxUtils.getTextContent(elt)};
  190. }
  191. else if (node.nodeName == 'mxGraphModel')
  192. {
  193. var style = node.getAttribute('style') || 'default-style2';
  194. // Decodes the style if required
  195. if (urlParams['embed'] != '1' && (style == null || style == ''))
  196. {
  197. var node2 = (this.graph.themes != null) ?
  198. this.graph.themes['default-old'] :
  199. mxUtils.load(STYLE_PATH + '/default-old.xml').getDocumentElement();
  200. if (node2 != null)
  201. {
  202. var dec2 = new mxCodec(node2.ownerDocument);
  203. dec2.decode(node2, this.graph.getStylesheet());
  204. }
  205. }
  206. else if (style != this.graph.currentStyle)
  207. {
  208. var node2 = (this.graph.themes != null) ?
  209. this.graph.themes[style] :
  210. mxUtils.load(STYLE_PATH + '/' + style + '.xml').getDocumentElement()
  211. if (node2 != null)
  212. {
  213. var dec2 = new mxCodec(node2.ownerDocument);
  214. dec2.decode(node2, this.graph.getStylesheet());
  215. }
  216. }
  217. this.graph.currentStyle = style;
  218. this.graph.mathEnabled = (urlParams['math'] == '1' || node.getAttribute('math') == '1');
  219. var bgImg = node.getAttribute('backgroundImage');
  220. if (bgImg != null)
  221. {
  222. bgImg = JSON.parse(bgImg);
  223. this.graph.setBackgroundImage(new mxImage(bgImg.src, bgImg.width, bgImg.height));
  224. }
  225. else
  226. {
  227. this.graph.setBackgroundImage(null);
  228. }
  229. mxClient.NO_FO = (this.graph.mathEnabled) ? true : this.originalNoForeignObject;
  230. this.graph.setShadowVisible(node.getAttribute('shadow') == '1', false);
  231. }
  232. // Calls updateGraphComponents
  233. editorSetGraphXml.apply(this, arguments);
  234. }
  235. else
  236. {
  237. throw {
  238. message: mxResources.get('notADiagramFile') || 'Invalid data',
  239. toString: function() { return this.message; }
  240. };
  241. }
  242. };
  243. /**
  244. * Adds persistent style to file
  245. */
  246. var editorGetGraphXml = Editor.prototype.getGraphXml;
  247. Editor.prototype.getGraphXml = function(ignoreSelection)
  248. {
  249. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  250. var node = editorGetGraphXml.apply(this, arguments);
  251. // Adds the current style
  252. if (this.graph.currentStyle != null && this.graph.currentStyle != 'default-style2')
  253. {
  254. node.setAttribute('style', this.graph.currentStyle);
  255. }
  256. // Adds the background image
  257. if (this.graph.backgroundImage != null)
  258. {
  259. node.setAttribute('backgroundImage', JSON.stringify(this.graph.backgroundImage));
  260. }
  261. node.setAttribute('math', (this.graph.mathEnabled) ? '1' : '0');
  262. node.setAttribute('shadow', (this.graph.shadowVisible) ? '1' : '0');
  263. return node;
  264. };
  265. /**
  266. * Helper function to extract the graph model XML node.
  267. */
  268. Editor.prototype.isDataSvg = function(svg)
  269. {
  270. try
  271. {
  272. var svgRoot = mxUtils.parseXml(svg).documentElement;
  273. var tmp = svgRoot.getAttribute('content');
  274. if (tmp != null)
  275. {
  276. if (tmp != null && tmp.charAt(0) != '<' && tmp.charAt(0) != '%')
  277. {
  278. tmp = unescape((window.atob) ? atob(tmp) : Base64.decode(cont, tmp));
  279. }
  280. if (tmp != null && tmp.charAt(0) == '%')
  281. {
  282. tmp = decodeURIComponent(tmp);
  283. }
  284. if (tmp != null && tmp.length > 0)
  285. {
  286. var node = mxUtils.parseXml(tmp).documentElement;
  287. return node.nodeName == 'mxfile' || node.nodeName == 'mxGraphModel';
  288. }
  289. }
  290. }
  291. catch (e)
  292. {
  293. // ignore
  294. }
  295. return false;
  296. };
  297. /**
  298. * Helper function to extract the graph model XML node.
  299. */
  300. Editor.prototype.extractGraphModel = function(node, allowMxFile)
  301. {
  302. if (node != null && typeof(pako) !== 'undefined')
  303. {
  304. var tmp = node.ownerDocument.getElementsByTagName('div');
  305. var divs = [];
  306. if (tmp != null && tmp.length > 0)
  307. {
  308. for (var i = 0; i < tmp.length; i++)
  309. {
  310. if (tmp[i].getAttribute('class') == 'mxgraph')
  311. {
  312. divs.push(tmp[i]);
  313. break;
  314. }
  315. }
  316. }
  317. if (divs.length > 0)
  318. {
  319. var data = divs[0].getAttribute('data-mxgraph');
  320. if (data != null)
  321. {
  322. var config = JSON.parse(data);
  323. if (config != null && config.xml != null)
  324. {
  325. var doc2 = mxUtils.parseXml(config.xml);
  326. node = doc2.documentElement;
  327. }
  328. }
  329. else
  330. {
  331. var divs2 = divs[0].getElementsByTagName('div');
  332. if (divs2.length > 0)
  333. {
  334. var data = mxUtils.getTextContent(divs2[0]);
  335. data = this.graph.decompress(data);
  336. if (data.length > 0)
  337. {
  338. var doc2 = mxUtils.parseXml(data);
  339. node = doc2.documentElement;
  340. }
  341. }
  342. }
  343. }
  344. }
  345. if (node != null && node.nodeName == 'svg')
  346. {
  347. var tmp = node.getAttribute('content');
  348. if (tmp != null && tmp.charAt(0) != '<' && tmp.charAt(0) != '%')
  349. {
  350. tmp = unescape((window.atob) ? atob(tmp) : Base64.decode(cont, tmp));
  351. }
  352. if (tmp != null && tmp.charAt(0) == '%')
  353. {
  354. tmp = decodeURIComponent(tmp);
  355. }
  356. if (tmp != null && tmp.length > 0)
  357. {
  358. node = mxUtils.parseXml(tmp).documentElement;
  359. }
  360. else
  361. {
  362. throw {message: mxResources.get('notADiagramFile')};
  363. }
  364. }
  365. if (node != null && !allowMxFile)
  366. {
  367. var diagramNode = null;
  368. if (node.nodeName == 'diagram')
  369. {
  370. diagramNode = node;
  371. }
  372. else if (node.nodeName == 'mxfile')
  373. {
  374. var diagrams = node.getElementsByTagName('diagram');
  375. if (diagrams.length > 0)
  376. {
  377. diagramNode = diagrams[Math.max(0, Math.min(diagrams.length - 1, urlParams['page'] || 0))];
  378. }
  379. }
  380. if (diagramNode != null)
  381. {
  382. var tmp = this.graph.decompress(mxUtils.getTextContent(diagramNode));
  383. if (tmp != null && tmp.length > 0)
  384. {
  385. node = mxUtils.parseXml(tmp).documentElement;
  386. }
  387. }
  388. }
  389. if (node != null && node.nodeName != 'mxGraphModel' && (!allowMxFile || node.nodeName != 'mxfile'))
  390. {
  391. node = null;
  392. }
  393. return node;
  394. };
  395. /**
  396. * Overrides reset graph.
  397. */
  398. var editorResetGraph = Editor.prototype.resetGraph;
  399. Editor.prototype.resetGraph = function()
  400. {
  401. this.graph.mathEnabled = (urlParams['math'] == '1');
  402. this.graph.view.x0 = null;
  403. this.graph.view.y0 = null;
  404. mxClient.NO_FO = (this.graph.mathEnabled) ? true : this.originalNoForeignObject;
  405. editorResetGraph.apply(this, arguments);
  406. };
  407. /**
  408. * Math support.
  409. */
  410. Editor.prototype.originalNoForeignObject = mxClient.NO_FO;
  411. var editorUpdateGraphComponents = Editor.prototype.updateGraphComponents;
  412. Editor.prototype.updateGraphComponents = function()
  413. {
  414. editorUpdateGraphComponents.apply(this, arguments);
  415. mxClient.NO_FO = (this.graph.mathEnabled && Editor.MathJaxRender != null) ? true : this.originalNoForeignObject;
  416. };
  417. /**
  418. * Initializes math typesetting and loads respective code.
  419. */
  420. Editor.initMath = function(src, config)
  421. {
  422. src = (src != null) ? src : 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_HTMLorMML';
  423. Editor.mathJaxQueue = [];
  424. Editor.doMathJaxRender = function(container)
  425. {
  426. MathJax.Hub.Queue(['Typeset', MathJax.Hub, container]);
  427. };
  428. // Disables global typesetting and messages on startup, adds queue for
  429. // asynchronous rendering while MathJax is loading
  430. window.MathJax =
  431. {
  432. skipStartupTypeset: true,
  433. showMathMenu: false,
  434. messageStyle: 'none',
  435. AuthorInit: function ()
  436. {
  437. // Specification recommends using SVG over HTML-CSS if browser is known
  438. // Check if too inconsistent with image export and print output
  439. MathJax.Hub.Config(config || {
  440. jax: ['input/TeX', 'input/MathML', 'input/AsciiMath', 'output/HTML-CSS'],
  441. extensions: ['tex2jax.js', 'mml2jax.js', 'asciimath2jax.js'],
  442. TeX: {
  443. extensions: ['AMSmath.js', 'AMSsymbols.js', 'noErrors.js', 'noUndefined.js']
  444. },
  445. // Ignores math in in-place editor
  446. tex2jax: {
  447. ignoreClass: 'mxCellEditor'
  448. },
  449. asciimath2jax: {
  450. ignoreClass: 'mxCellEditor'
  451. }
  452. });
  453. MathJax.Hub.Register.StartupHook('Begin', function()
  454. {
  455. for (var i = 0; i < Editor.mathJaxQueue.length; i++)
  456. {
  457. Editor.doMathJaxRender(Editor.mathJaxQueue[i]);
  458. }
  459. });
  460. }
  461. };
  462. // Adds global enqueue method for async rendering
  463. Editor.MathJaxRender = function(container)
  464. {
  465. // Initial rendering when MathJax finished loading
  466. if (typeof(MathJax) !== 'undefined' && typeof(MathJax.Hub) !== 'undefined')
  467. {
  468. Editor.doMathJaxRender(container);
  469. }
  470. else
  471. {
  472. Editor.mathJaxQueue.push(container);
  473. }
  474. };
  475. // Adds global clear queue method
  476. Editor.MathJaxClear = function()
  477. {
  478. Editor.mathJaxQueue = [];
  479. };
  480. // Updates typeset after changes
  481. var editorInit = Editor.prototype.init;
  482. Editor.prototype.init = function()
  483. {
  484. editorInit.apply(this, arguments);
  485. this.graph.addListener(mxEvent.SIZE, mxUtils.bind(this, function(sender, evt)
  486. {
  487. if (this.graph.mathEnabled)
  488. {
  489. Editor.MathJaxRender(this.graph.container);
  490. }
  491. }));
  492. };
  493. var tags = document.getElementsByTagName('script');
  494. if (tags != null && tags.length > 0)
  495. {
  496. var script = document.createElement('script');
  497. script.type = 'text/javascript';
  498. script.src = src;
  499. tags[0].parentNode.appendChild(script);
  500. }
  501. };
  502. /**
  503. * Return array of string values, or NULL if CSV string not well formed.
  504. */
  505. Editor.prototype.csvToArray = function(text)
  506. {
  507. var re_valid = /^\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*(?:,\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*)*$/;
  508. var re_value = /(?!\s*$)\s*(?:'([^'\\]*(?:\\[\S\s][^'\\]*)*)'|"([^"\\]*(?:\\[\S\s][^"\\]*)*)"|([^,'"\s\\]*(?:\s+[^,'"\s\\]+)*))\s*(?:,|$)/g;
  509. // Return NULL if input string is not well formed CSV string.
  510. if (!re_valid.test(text)) return null;
  511. var a = []; // Initialize array to receive values.
  512. text.replace(re_value, // "Walk" the string using replace with callback.
  513. function(m0, m1, m2, m3) {
  514. // Remove backslash from \' in single quoted values.
  515. if (m1 !== undefined) a.push(m1.replace(/\\'/g, "'"));
  516. // Remove backslash from \" in double quoted values.
  517. else if (m2 !== undefined) a.push(m2.replace(/\\"/g, '"'));
  518. else if (m3 !== undefined) a.push(m3);
  519. return ''; // Return empty string.
  520. });
  521. // Handle special case of empty last value.
  522. if (/,\s*$/.test(text)) a.push('');
  523. return a;
  524. };
  525. /**
  526. * Adds persistence for recent colors
  527. */
  528. if (window.ColorDialog)
  529. {
  530. var colorDialogAddRecentColor = ColorDialog.addRecentColor;
  531. ColorDialog.addRecentColor = function(color, max)
  532. {
  533. colorDialogAddRecentColor.apply(this, arguments);
  534. mxSettings.setRecentColors(ColorDialog.recentColors);
  535. mxSettings.save();
  536. };
  537. var colorDialogResetRecentColors = ColorDialog.resetRecentColors;
  538. ColorDialog.resetRecentColors = function()
  539. {
  540. colorDialogResetRecentColors.apply(this, arguments);
  541. mxSettings.setRecentColors(ColorDialog.recentColors);
  542. mxSettings.save();
  543. };
  544. }
  545. // Overridden to add edit shape option
  546. if (window.StyleFormatPanel != null)
  547. {
  548. var formatInit = Format.prototype.init;
  549. Format.prototype.init = function()
  550. {
  551. formatInit.apply(this, arguments);
  552. var ui = this.editorUi;
  553. ui.editor.addListener('fileLoaded', this.update);
  554. };
  555. var formatRefresh = Format.prototype.refresh;
  556. Format.prototype.refresh = function()
  557. {
  558. var ui = this.editorUi;
  559. if (ui.getCurrentFile() != null || urlParams['embed'] == '1')
  560. {
  561. formatRefresh.apply(this, arguments);
  562. }
  563. else
  564. {
  565. this.clear();
  566. }
  567. };
  568. /**
  569. * Adds autosave and math typesetting options.
  570. */
  571. var diagramFormatPanelAddOptions = DiagramFormatPanel.prototype.addOptions;
  572. DiagramFormatPanel.prototype.addOptions = function(div)
  573. {
  574. div = diagramFormatPanelAddOptions.apply(this, arguments);
  575. var ui = this.editorUi;
  576. var editor = ui.editor;
  577. var graph = editor.graph;
  578. if (graph.isEnabled())
  579. {
  580. var file = ui.getCurrentFile();
  581. if (file != null && file.isAutosaveOptional())
  582. {
  583. var opt = this.createOption(mxResources.get('autosave'), function()
  584. {
  585. return ui.editor.autosave;
  586. }, function(checked)
  587. {
  588. ui.editor.setAutosave(checked);
  589. },
  590. {
  591. install: function(apply)
  592. {
  593. this.listener = function()
  594. {
  595. apply(ui.editor.autosave);
  596. };
  597. ui.editor.addListener('autosaveChanged', this.listener);
  598. },
  599. destroy: function()
  600. {
  601. ui.editor.removeListener(this.listener);
  602. }
  603. });
  604. div.appendChild(opt);
  605. }
  606. }
  607. return div;
  608. };
  609. /**
  610. * Configures global color schemes.
  611. */
  612. StyleFormatPanel.prototype.defaultColorSchemes = [[null, {fill: '#f5f5f5', stroke: '#666666'},
  613. {fill: '#dae8fc', stroke: '#6c8ebf'}, {fill: '#d5e8d4', stroke: '#82b366'},
  614. {fill: '#ffe6cc', stroke: '#d79b00'}, {fill: '#fff2cc', stroke: '#d6b656'},
  615. {fill: '#f8cecc', stroke: '#b85450'}, {fill: '#e1d5e7', stroke: '#9673a6'}],
  616. [null,
  617. {fill: '#f5f5f5', stroke: '#666666', gradient: '#b3b3b3'},
  618. {fill: '#dae8fc', stroke: '#6c8ebf', gradient: '#7ea6e0'},
  619. {fill: '#d5e8d4', stroke: '#82b366', gradient: '#97d077'},
  620. {fill: '#ffcd28', stroke: '#d79b00', gradient: '#ffa500'},
  621. {fill: '#fff2cc', stroke: '#d6b656', gradient: '#ffd966'},
  622. {fill: '#f8cecc', stroke: '#b85450', gradient: '#ea6b66'},
  623. {fill: '#e6d0de', stroke: '#996185', gradient: '#d5739d'}],
  624. [null, {fill: '#eeeeee', stroke: '#36393d'},
  625. {fill: '#f9f7ed', stroke: '#36393d'}, {fill: '#ffcc99', stroke: '#36393d'},
  626. {fill: '#cce5ff', stroke: '#36393d'}, {fill: '#ffff88', stroke: '#36393d'},
  627. {fill: '#cdeb8b', stroke: '#36393d'}, {fill: '#ffcccc', stroke: '#36393d'}]];
  628. /**
  629. * Adds predefiend styles.
  630. */
  631. var StyleFormatPanelInit = StyleFormatPanel.prototype.init;
  632. StyleFormatPanel.prototype.init = function()
  633. {
  634. // TODO: Update sstate in Format
  635. var sstate = this.format.createSelectionState();
  636. if (sstate.style.shape != 'image')
  637. {
  638. this.container.appendChild(this.addStyles(this.createPanel()));
  639. }
  640. StyleFormatPanelInit.apply(this, arguments);
  641. };
  642. /**
  643. * Overridden to add copy and paste style.
  644. */
  645. var styleFormatPanelAddStyleOps = StyleFormatPanel.prototype.addStyleOps;
  646. StyleFormatPanel.prototype.addStyleOps = function(div)
  647. {
  648. var btn = mxUtils.button(mxResources.get('copyStyle'), mxUtils.bind(this, function(evt)
  649. {
  650. this.editorUi.actions.get('copyStyle').funct();
  651. }));
  652. btn.setAttribute('title', mxResources.get('copyStyle') + ' (' + this.editorUi.actions.get('copyStyle').shortcut + ')');
  653. btn.style.marginBottom = '2px';
  654. btn.style.width = '100px';
  655. btn.style.marginRight = '2px';
  656. div.appendChild(btn);
  657. var btn = mxUtils.button(mxResources.get('pasteStyle'), mxUtils.bind(this, function(evt)
  658. {
  659. this.editorUi.actions.get('pasteStyle').funct();
  660. }));
  661. btn.setAttribute('title', mxResources.get('pasteStyle') + ' (' + this.editorUi.actions.get('pasteStyle').shortcut + ')');
  662. btn.style.marginBottom = '2px';
  663. btn.style.width = '100px';
  664. div.appendChild(btn);
  665. mxUtils.br(div);
  666. return styleFormatPanelAddStyleOps.apply(this, arguments);
  667. };
  668. /**
  669. * Creates the buttons for the predefined styles.
  670. */
  671. StyleFormatPanel.prototype.addStyles = function(div)
  672. {
  673. var graph = this.editorUi.editor.graph;
  674. var picker = document.createElement('div');
  675. picker.style.whiteSpace = 'normal';
  676. picker.style.paddingLeft = '24px';
  677. picker.style.paddingRight = '20px';
  678. div.style.paddingLeft = '16px';
  679. div.style.paddingBottom = '6px';
  680. div.style.position = 'relative';
  681. div.appendChild(picker);
  682. var stylenames = ['plain-gray', 'plain-blue', 'plain-green', 'plain-turquoise',
  683. 'plain-orange', 'plain-yellow', 'plain-red', 'plain-pink', 'plain-purple', 'gray',
  684. 'blue', 'green', 'turquoise', 'orange', 'yellow', 'red', 'pink', 'purple'];
  685. function updateScheme(colorsets)
  686. {
  687. function addButton(colorset)
  688. {
  689. var btn = mxUtils.button('', function(evt)
  690. {
  691. graph.getModel().beginUpdate();
  692. try
  693. {
  694. var cells = graph.getSelectionCells();
  695. for (var i = 0; i < cells.length; i++)
  696. {
  697. var style = graph.getModel().getStyle(cells[i]);
  698. for (var j = 0; j < stylenames.length; j++)
  699. {
  700. style = mxUtils.removeStylename(style, stylenames[j]);
  701. }
  702. if (colorset != null)
  703. {
  704. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR, colorset['fill']);
  705. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR, colorset['stroke']);
  706. style = mxUtils.setStyle(style, mxConstants.STYLE_GRADIENTCOLOR, colorset['gradient']);
  707. }
  708. else
  709. {
  710. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR, '#ffffff');
  711. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR, '#000000');
  712. style = mxUtils.setStyle(style, mxConstants.STYLE_GRADIENTCOLOR, null);
  713. }
  714. graph.getModel().setStyle(cells[i], style);
  715. }
  716. }
  717. finally
  718. {
  719. graph.getModel().endUpdate();
  720. }
  721. })
  722. btn.style.width = '36px';
  723. btn.style.height = '30px';
  724. btn.style.margin = '0px 6px 6px 0px';
  725. if (colorset != null)
  726. {
  727. if (colorset['gradient'] != null)
  728. {
  729. if (mxClient.IS_IE && (mxClient.IS_QUIRKS || document.documentMode < 10))
  730. {
  731. btn.style.filter = 'progid:DXImageTransform.Microsoft.Gradient('+
  732. 'StartColorStr=\'' + colorset['fill'] +
  733. '\', EndColorStr=\'' + colorset['gradient'] + '\', GradientType=0)';
  734. }
  735. else
  736. {
  737. btn.style.backgroundImage = 'linear-gradient(' + colorset['fill'] + ' 0px,' +
  738. colorset['gradient'] + ' 100%)';
  739. }
  740. }
  741. else
  742. {
  743. btn.style.backgroundColor = colorset['fill'];
  744. }
  745. btn.style.border = '1px solid ' + colorset['stroke'];
  746. }
  747. else
  748. {
  749. btn.style.backgroundColor = '#ffffff';
  750. btn.style.border = '1px solid #000000';
  751. }
  752. picker.appendChild(btn);
  753. };
  754. picker.innerHTML = '';
  755. for (var i = 0; i < colorsets.length; i++)
  756. {
  757. if (i > 0 && mxUtils.mod(i, 4) == 0)
  758. {
  759. mxUtils.br(picker);
  760. }
  761. addButton(colorsets[i]);
  762. }
  763. };
  764. if (this.editorUi.currentScheme == null)
  765. {
  766. this.editorUi.currentScheme = 0;
  767. }
  768. var left = document.createElement('div');
  769. left.style.cssText = 'position:absolute;left:10px;top:8px;bottom:8px;width:20px;margin:4px;opacity:0.5;' +
  770. 'background-repeat:no-repeat;background-position:center center;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAQBAMAAADQT4M0AAAAIVBMVEUAAAB2dnZ4eHh3d3d1dXVxcXF2dnZ2dnZ2dnZxcXF2dnYmb3w1AAAACnRSTlMAfCTkhhvb7cQSPH2JPgAAADRJREFUCNdjwACMAmBKaiGYs2oJmLPKAZ3DabU8AMRTXpUKopislqFyVzCAuUZgikkBZjoAcMYLnp53P/UAAAAASUVORK5CYII=);';
  771. mxEvent.addListener(left, 'click', mxUtils.bind(this, function()
  772. {
  773. this.editorUi.currentScheme = mxUtils.mod(this.editorUi.currentScheme - 1, this.defaultColorSchemes.length);
  774. updateScheme(this.defaultColorSchemes[this.editorUi.currentScheme]);
  775. }));
  776. var right = document.createElement('div');
  777. right.style.cssText = 'position:absolute;left:202px;top:8px;bottom:8px;width:20px;margin:4px;opacity:0.5;' +
  778. 'background-repeat:no-repeat;background-position:center center;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAQBAMAAADQT4M0AAAAIVBMVEUAAAB2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnYBuwCcAAAACnRSTlMAfCTkhhvb7cQSPH2JPgAAADZJREFUCNdjQAOMAmBKaiGY8loF5rKswsZlrVo8AUiFrTICcbIWK8A5DF1gDoMymMPApIAwHwCS0Qx/U7qCBQAAAABJRU5ErkJggg==);';
  779. if (this.defaultColorSchemes.length > 1)
  780. {
  781. div.appendChild(left);
  782. div.appendChild(right);
  783. }
  784. mxEvent.addListener(right, 'click', mxUtils.bind(this, function()
  785. {
  786. this.editorUi.currentScheme = mxUtils.mod(this.editorUi.currentScheme + 1, this.defaultColorSchemes.length);
  787. updateScheme(this.defaultColorSchemes[this.editorUi.currentScheme]);
  788. }));
  789. // Hover state
  790. function addHoverState(elt)
  791. {
  792. mxEvent.addListener(elt, 'mouseenter', function()
  793. {
  794. elt.style.opacity = '1';
  795. });
  796. mxEvent.addListener(elt, 'mouseleave', function()
  797. {
  798. elt.style.opacity = '0.5';
  799. });
  800. };
  801. addHoverState(left);
  802. addHoverState(right);
  803. updateScheme(this.defaultColorSchemes[this.editorUi.currentScheme]);
  804. return div;
  805. };
  806. StyleFormatPanel.prototype.addEditOps = function(div)
  807. {
  808. var ss = this.format.getSelectionState();
  809. var btn = null;
  810. if (this.editorUi.editor.graph.getSelectionCount() == 1)
  811. {
  812. btn = mxUtils.button(mxResources.get('editStyle'), mxUtils.bind(this, function(evt)
  813. {
  814. this.editorUi.actions.get('editStyle').funct();
  815. }));
  816. btn.setAttribute('title', mxResources.get('editStyle') + ' (' + this.editorUi.actions.get('editStyle').shortcut + ')');
  817. btn.style.width = '202px';
  818. btn.style.marginBottom = '2px';
  819. div.appendChild(btn);
  820. }
  821. var graph = this.editorUi.editor.graph;
  822. var state = graph.view.getState(graph.getSelectionCell());
  823. if (graph.getSelectionCount() == 1 && state != null && state.shape != null && state.shape.stencil != null)
  824. {
  825. var btn2 = mxUtils.button(mxResources.get('editShape'), mxUtils.bind(this, function(evt)
  826. {
  827. this.editorUi.actions.get('editShape').funct();
  828. }));
  829. btn2.setAttribute('title', mxResources.get('editShape'));
  830. btn2.style.marginBottom = '2px';
  831. if (btn == null)
  832. {
  833. btn2.style.width = '202px';
  834. }
  835. else
  836. {
  837. btn.style.width = '100px';
  838. btn2.style.width = '100px';
  839. btn2.style.marginLeft = '2px';
  840. }
  841. div.appendChild(btn2);
  842. }
  843. else if (ss.image)
  844. {
  845. var btn2 = mxUtils.button(mxResources.get('editImage'), mxUtils.bind(this, function(evt)
  846. {
  847. this.editorUi.actions.get('image').funct();
  848. }));
  849. btn2.setAttribute('title', mxResources.get('editImage'));
  850. btn2.style.marginBottom = '2px';
  851. if (btn == null)
  852. {
  853. btn2.style.width = '202px';
  854. }
  855. else
  856. {
  857. btn.style.width = '100px';
  858. btn2.style.width = '100px';
  859. btn2.style.marginLeft = '2px';
  860. }
  861. div.appendChild(btn2);
  862. }
  863. return div;
  864. };
  865. }
  866. /**
  867. * Changes the default stylename so that it matches the old named style
  868. * if one was specified in the XML.
  869. */
  870. Graph.prototype.defaultThemeName = 'default-style2';
  871. /**
  872. * Contains the last XML that was pasted.
  873. */
  874. Graph.prototype.lastPasteXml = null;
  875. /**
  876. * Contains the number of times the last XML was pasted.
  877. */
  878. Graph.prototype.pasteCounter = 0;
  879. /**
  880. * Graph Overrides
  881. */
  882. Graph.prototype.defaultScrollbars = urlParams['sb'] != '0';
  883. /**
  884. * Specifies if the page should be visible for new files. Default is true.
  885. */
  886. Graph.prototype.defaultPageVisible = urlParams['pv'] != '0';
  887. /**
  888. * Specifies if the page should be visible for new files. Default is true.
  889. */
  890. Graph.prototype.shadowId = 'dropShadow';
  891. /**
  892. * Enables move of bends/segments without selecting.
  893. */
  894. Graph.prototype.edgeMode = urlParams['edge'] != 'move';
  895. /**
  896. * Adds rack child layout style.
  897. */
  898. var graphInit = Graph.prototype.init;
  899. Graph.prototype.init = function()
  900. {
  901. graphInit.apply(this, arguments);
  902. // Override insert location for current mouse point
  903. var mouseEvent = null;
  904. function setMouseEvent(evt)
  905. {
  906. mouseEvent = evt;
  907. // Workaround for member not found in IE8-
  908. if (mxClient.IS_QUIRKS || document.documentMode == 7 || document.documentMode == 8)
  909. {
  910. mouseEvent = mxUtils.clone(evt);
  911. }
  912. };
  913. mxEvent.addListener(this.container, 'mouseenter', setMouseEvent);
  914. mxEvent.addListener(this.container, 'mousemove', setMouseEvent);
  915. mxEvent.addListener(this.container, 'mouseleave', function(evt)
  916. {
  917. mouseEvent = null;
  918. });
  919. // Extends getInsertPoint to use the current mouse location
  920. this.isMouseInsertPoint = function()
  921. {
  922. return mouseEvent != null;
  923. };
  924. var getInsertPoint = this.getInsertPoint;
  925. this.getInsertPoint = function()
  926. {
  927. if (mouseEvent != null)
  928. {
  929. return this.getPointForEvent(mouseEvent);
  930. }
  931. return getInsertPoint.apply(this, arguments);
  932. };
  933. var layoutManagerGetLayout = this.layoutManager.getLayout;
  934. this.layoutManager.getLayout = function(cell)
  935. {
  936. var state = this.graph.view.getState(cell);
  937. var style = (state != null) ? state.style : this.graph.getCellStyle(cell);
  938. // mxRackContainer may be undefined as it is dynamically loaded at render time
  939. if (typeof(mxRackContainer) != 'undefined' && style['childLayout'] == 'rack')
  940. {
  941. var rackLayout = new mxStackLayout(this.graph, false);
  942. rackLayout.setChildGeometry = function(child, geo)
  943. {
  944. var unitSize = 20;
  945. geo.height = Math.max(geo.height, unitSize);
  946. if (geo.height / unitSize > 1)
  947. {
  948. var mod = geo.height % unitSize;
  949. geo.height += mod > unitSize / 2 ? (unitSize - mod) : -mod;
  950. }
  951. this.graph.getModel().setGeometry(child, geo);
  952. };
  953. rackLayout.fill = true;
  954. rackLayout.unitSize = mxRackContainer.unitSize | 20;
  955. rackLayout.marginLeft = style['marginLeft'] || 0;
  956. rackLayout.marginRight = style['marginRight'] || 0;
  957. rackLayout.marginTop = style['marginTop'] || 0;
  958. rackLayout.marginBottom = style['marginBottom'] || 0;
  959. rackLayout.resizeParent = false;
  960. return rackLayout;
  961. }
  962. return layoutManagerGetLayout.apply(this, arguments);
  963. }
  964. };
  965. /**
  966. * Sets default style (used in editor.get/setGraphXml below)
  967. */
  968. var graphLoadStylesheet = Graph.prototype.loadStylesheet;
  969. Graph.prototype.loadStylesheet = function()
  970. {
  971. graphLoadStylesheet.apply(this, arguments);
  972. this.currentStyle = 'default-style2';
  973. };
  974. /**
  975. * Adds support for page links.
  976. */
  977. Graph.prototype.isPageLink = function(href)
  978. {
  979. return href != null && href.substring(0, 10) == 'data:page/';
  980. };
  981. /**
  982. * Adds a shadow filter to the given svg root.
  983. */
  984. Graph.prototype.addSvgShadow = function(svgRoot, group, createOnly)
  985. {
  986. createOnly = (createOnly != null) ? createOnly : false;
  987. var svgDoc = svgRoot.ownerDocument;
  988. var filter = (svgDoc.createElementNS != null) ?
  989. svgDoc.createElementNS(mxConstants.NS_SVG, 'filter') : svgDoc.createElement('filter');
  990. filter.setAttribute('id', this.shadowId);
  991. var blur = (svgDoc.createElementNS != null) ?
  992. svgDoc.createElementNS(mxConstants.NS_SVG, 'feGaussianBlur') : svgDoc.createElement('feGaussianBlur');
  993. blur.setAttribute('in', 'SourceAlpha');
  994. blur.setAttribute('stdDeviation', '1.7');
  995. blur.setAttribute('result', 'blur');
  996. filter.appendChild(blur);
  997. var offset = (svgDoc.createElementNS != null) ?
  998. svgDoc.createElementNS(mxConstants.NS_SVG, 'feOffset') : svgDoc.createElement('feOffset');
  999. offset.setAttribute('in', 'blur');
  1000. offset.setAttribute('dx', '3');
  1001. offset.setAttribute('dy', '3');
  1002. offset.setAttribute('result', 'offsetBlur');
  1003. filter.appendChild(offset);
  1004. var flood = (svgDoc.createElementNS != null) ?
  1005. svgDoc.createElementNS(mxConstants.NS_SVG, 'feFlood') : svgDoc.createElement('feFlood');
  1006. flood.setAttribute('flood-color', '#3D4574');
  1007. flood.setAttribute('flood-opacity', '0.4');
  1008. flood.setAttribute('result', 'offsetColor');
  1009. filter.appendChild(flood);
  1010. var composite = (svgDoc.createElementNS != null) ?
  1011. svgDoc.createElementNS(mxConstants.NS_SVG, 'feComposite') : svgDoc.createElement('feComposite');
  1012. composite.setAttribute('in', 'offsetColor');
  1013. composite.setAttribute('in2', 'offsetBlur');
  1014. composite.setAttribute('operator', 'in');
  1015. composite.setAttribute('result', 'offsetBlur');
  1016. filter.appendChild(composite);
  1017. var feBlend = (svgDoc.createElementNS != null) ?
  1018. svgDoc.createElementNS(mxConstants.NS_SVG, 'feBlend') : svgDoc.createElement('feBlend');
  1019. feBlend.setAttribute('in', 'SourceGraphic');
  1020. feBlend.setAttribute('in2', 'offsetBlur');
  1021. filter.appendChild(feBlend);
  1022. // Creates defs element if not available
  1023. var defs = svgRoot.getElementsByTagName('defs');
  1024. var defsElt = null;
  1025. if (defs.length == 0)
  1026. {
  1027. defsElt = (svgDoc.createElementNS != null) ?
  1028. svgDoc.createElementNS(mxConstants.NS_SVG, 'defs') : svgDoc.createElement('defs');
  1029. if (svgRoot.firstChild != null)
  1030. {
  1031. svgRoot.insertBefore(defsElt, svgRoot.firstChild);
  1032. }
  1033. else
  1034. {
  1035. svgRoot.appendChild(defsElt);
  1036. }
  1037. }
  1038. else
  1039. {
  1040. defsElt = defs[0];
  1041. }
  1042. defsElt.appendChild(filter);
  1043. if (!createOnly)
  1044. {
  1045. (group || svgRoot.getElementsByTagName('g')[0]).setAttribute('filter', 'url(#' + this.shadowId + ')');
  1046. if (!isNaN(parseInt(svgRoot.getAttribute('width'))))
  1047. {
  1048. svgRoot.setAttribute('width', parseInt(svgRoot.getAttribute('width')) + 6);
  1049. svgRoot.setAttribute('height', parseInt(svgRoot.getAttribute('height')) + 6);
  1050. }
  1051. }
  1052. return filter;
  1053. };
  1054. /**
  1055. * Loads the stylesheet for this graph.
  1056. */
  1057. Graph.prototype.setShadowVisible = function(value, fireEvent)
  1058. {
  1059. if (mxClient.IS_SVG)
  1060. {
  1061. fireEvent = (fireEvent != null) ? fireEvent : true;
  1062. this.shadowVisible = value;
  1063. if (this.shadowVisible)
  1064. {
  1065. this.view.getDrawPane().setAttribute('filter', 'url(#' + this.shadowId + ')');
  1066. }
  1067. else
  1068. {
  1069. this.view.getDrawPane().removeAttribute('filter');
  1070. }
  1071. if (fireEvent)
  1072. {
  1073. this.fireEvent(new mxEventObject('shadowVisibleChanged'));
  1074. }
  1075. }
  1076. };
  1077. /**
  1078. * Selects first unlocked layer if one exists
  1079. */
  1080. Graph.prototype.selectUnlockedLayer = function()
  1081. {
  1082. if (this.defaultParent == null)
  1083. {
  1084. var childCount = this.model.getChildCount(this.model.root);
  1085. var cell = null;
  1086. var index = 0;
  1087. do
  1088. {
  1089. cell = this.model.getChildAt(this.model.root, index);
  1090. } while (index++ < childCount && mxUtils.getValue(this.getCellStyle(cell), 'locked', '0') == '1')
  1091. if (cell != null)
  1092. {
  1093. this.setDefaultParent(cell);
  1094. }
  1095. }
  1096. };
  1097. /**
  1098. * Specifies special libraries that are loaded via dynamic JS. Add cases
  1099. * where the filename cannot be worked out from the package name. The
  1100. * standard scheme for this mapping is stencils/packagename.xml. If there
  1101. * are multiple XML files, any JS files or any anomalies in the filename or
  1102. * directory that contains the file, then an entry must be added here and
  1103. * in EmbedServlet2 for the loading of the shapes to work.
  1104. */
  1105. // Required to avoid 404 for mockup.xml since naming of mxgraph.mockup.anchor does not contain
  1106. // buttons even though it is defined in the mxMockupButtons.js file. This could only be fixed
  1107. // with aliases for existing shapes or aliases for basenames, but this is essentially the same.
  1108. mxStencilRegistry.libraries['mockup'] = [SHAPES_PATH + '/mockup/mxMockupButtons.js'];
  1109. mxStencilRegistry.libraries['arrows2'] = [SHAPES_PATH + '/mxArrows.js'];
  1110. mxStencilRegistry.libraries['atlassian'] = [STENCIL_PATH + '/atlassian.xml'];
  1111. mxStencilRegistry.libraries['bpmn'] = [SHAPES_PATH + '/bpmn/mxBpmnShape2.js', STENCIL_PATH + '/bpmn.xml'];
  1112. mxStencilRegistry.libraries['er'] = [SHAPES_PATH + '/er/mxER.js'];
  1113. mxStencilRegistry.libraries['ios'] = [SHAPES_PATH + '/mockup/mxMockupiOS.js'];
  1114. mxStencilRegistry.libraries['rackGeneral'] = [SHAPES_PATH + '/rack/mxRack.js', STENCIL_PATH + '/rack/general.xml'];
  1115. mxStencilRegistry.libraries['rackF5'] = [STENCIL_PATH + '/rack/f5.xml'];
  1116. mxStencilRegistry.libraries['lean_mapping'] = [SHAPES_PATH + '/mxLeanMap.js', STENCIL_PATH + '/lean_mapping.xml'];
  1117. mxStencilRegistry.libraries['basic'] = [SHAPES_PATH + '/mxBasic.js', STENCIL_PATH + '/basic.xml'];
  1118. mxStencilRegistry.libraries['ios7icons'] = [STENCIL_PATH + '/ios7/icons.xml'];
  1119. mxStencilRegistry.libraries['ios7ui'] = [SHAPES_PATH + '/ios7/mxIOS7Ui.js', STENCIL_PATH + '/ios7/misc.xml'];
  1120. mxStencilRegistry.libraries['android'] = [SHAPES_PATH + '/mxAndroid.js', STENCIL_PATH + '/android/android.xml'];
  1121. mxStencilRegistry.libraries['electrical/transmission'] = [SHAPES_PATH + '/mxElectrical.js', STENCIL_PATH + '/electrical/transmission.xml'];
  1122. mxStencilRegistry.libraries['mockup/buttons'] = [SHAPES_PATH + '/mockup/mxMockupButtons.js'];
  1123. mxStencilRegistry.libraries['mockup/containers'] = [SHAPES_PATH + '/mockup/mxMockupContainers.js'];
  1124. mxStencilRegistry.libraries['mockup/forms'] = [SHAPES_PATH + '/mockup/mxMockupForms.js'];
  1125. mxStencilRegistry.libraries['mockup/graphics'] = [SHAPES_PATH + '/mockup/mxMockupGraphics.js', STENCIL_PATH + '/mockup/misc.xml'];
  1126. mxStencilRegistry.libraries['mockup/markup'] = [SHAPES_PATH + '/mockup/mxMockupMarkup.js'];
  1127. mxStencilRegistry.libraries['mockup/misc'] = [SHAPES_PATH + '/mockup/mxMockupMisc.js', STENCIL_PATH + '/mockup/misc.xml'];
  1128. mxStencilRegistry.libraries['mockup/navigation'] = [SHAPES_PATH + '/mockup/mxMockupNavigation.js', STENCIL_PATH + '/mockup/misc.xml'];
  1129. mxStencilRegistry.libraries['mockup/text'] = [SHAPES_PATH + '/mockup/mxMockupText.js'];
  1130. mxStencilRegistry.libraries['floorplan'] = [SHAPES_PATH + '/mxFloorplan.js', STENCIL_PATH + '/floorplan.xml'];
  1131. mxStencilRegistry.libraries['bootstrap'] = [SHAPES_PATH + '/mxBootstrap.js', STENCIL_PATH + '/bootstrap.xml'];
  1132. mxStencilRegistry.libraries['gmdl'] = [SHAPES_PATH + '/mxGmdl.js', STENCIL_PATH + '/gmdl.xml'];
  1133. mxStencilRegistry.libraries['cabinets'] = [SHAPES_PATH + '/mxCabinets.js', STENCIL_PATH + '/cabinets.xml'];
  1134. mxStencilRegistry.libraries['archimate'] = [SHAPES_PATH + '/mxArchiMate.js'];
  1135. mxStencilRegistry.libraries['archimate3'] = [SHAPES_PATH + '/mxArchiMate3.js'];
  1136. mxStencilRegistry.libraries['sysml'] = [SHAPES_PATH + '/mxSysML.js'];
  1137. mxStencilRegistry.libraries['eip'] = [SHAPES_PATH + '/mxEip.js', STENCIL_PATH + '/eip.xml'];
  1138. mxStencilRegistry.libraries['networks'] = [SHAPES_PATH + '/mxNetworks.js', STENCIL_PATH + '/networks.xml'];
  1139. mxStencilRegistry.libraries['aws3d'] = [SHAPES_PATH + '/mxAWS3D.js', STENCIL_PATH + '/aws3d.xml'];
  1140. mxStencilRegistry.libraries['pid2inst'] = [SHAPES_PATH + '/pid2/mxPidInstruments.js'];
  1141. mxStencilRegistry.libraries['pid2misc'] = [SHAPES_PATH + '/pid2/mxPidMisc.js', STENCIL_PATH + '/pid/misc.xml'];
  1142. mxStencilRegistry.libraries['pid2valves'] = [SHAPES_PATH + '/pid2/mxPidValves.js'];
  1143. mxStencilRegistry.libraries['pidFlowSensors'] = [STENCIL_PATH + '/pid/flow_sensors.xml'];
  1144. // Triggers dynamic loading for markers
  1145. mxMarker.getPackageForType = function(type)
  1146. {
  1147. var name = null;
  1148. if (type != null && type.length > 0)
  1149. {
  1150. if (type.substring(0, 2) == 'ER')
  1151. {
  1152. name = 'mxgraph.er';
  1153. }
  1154. else if (type.substring(0, 5) == 'sysML')
  1155. {
  1156. name = 'mxgraph.sysml';
  1157. }
  1158. }
  1159. return name;
  1160. };
  1161. var mxMarkerCreateMarker = mxMarker.createMarker;
  1162. mxMarker.createMarker = function(canvas, shape, type, pe, unitX, unitY, size, source, sw, filled)
  1163. {
  1164. if (type != null)
  1165. {
  1166. var f = mxMarker.markers[type];
  1167. if (f == null)
  1168. {
  1169. var name = this.getPackageForType(type);
  1170. if (name != null)
  1171. {
  1172. mxStencilRegistry.getStencil(name);
  1173. }
  1174. }
  1175. }
  1176. return mxMarkerCreateMarker.apply(this, arguments);
  1177. };
  1178. /**
  1179. * Constructs a new print dialog.
  1180. */
  1181. PrintDialog.prototype.create = function(editorUi, titleText)
  1182. {
  1183. var graph = editorUi.editor.graph;
  1184. var div = document.createElement('div');
  1185. var title = document.createElement('h3');
  1186. title.style.width = '100%';
  1187. title.style.textAlign = 'center';
  1188. title.style.marginTop = '0px';
  1189. mxUtils.write(title, titleText || mxResources.get('print'));
  1190. div.appendChild(title);
  1191. var pageCount = 1;
  1192. var currentPage = 1;
  1193. // Pages
  1194. var pagesSection = document.createElement('div');
  1195. pagesSection.style.cssText = 'border-bottom:1px solid lightGray;padding-bottom:12px;margin-bottom:12px;';
  1196. var allPagesRadio = document.createElement('input');
  1197. allPagesRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
  1198. allPagesRadio.setAttribute('value', 'all');
  1199. allPagesRadio.setAttribute('type', 'radio');
  1200. allPagesRadio.setAttribute('name', 'pages-printdialog');
  1201. pagesSection.appendChild(allPagesRadio);
  1202. var span = document.createElement('span');
  1203. mxUtils.write(span, mxResources.get('printAllPages'));
  1204. pagesSection.appendChild(span);
  1205. mxUtils.br(pagesSection);
  1206. // Pages ... to ...
  1207. var pagesRadio = allPagesRadio.cloneNode(true);
  1208. allPagesRadio.setAttribute('checked', 'checked');
  1209. pagesRadio.setAttribute('value', 'range');
  1210. pagesSection.appendChild(pagesRadio);
  1211. var span = document.createElement('span');
  1212. mxUtils.write(span, mxResources.get('pages') + ':');
  1213. pagesSection.appendChild(span);
  1214. var pagesFromInput = document.createElement('input');
  1215. pagesFromInput.style.cssText = 'margin:0 8px 0 8px;'
  1216. pagesFromInput.setAttribute('value', '1');
  1217. pagesFromInput.setAttribute('type', 'number');
  1218. pagesFromInput.setAttribute('min', '1');
  1219. pagesFromInput.style.width = '50px';
  1220. pagesSection.appendChild(pagesFromInput);
  1221. var span = document.createElement('span');
  1222. mxUtils.write(span, mxResources.get('to'));
  1223. pagesSection.appendChild(span);
  1224. var pagesToInput = pagesFromInput.cloneNode(true);
  1225. pagesSection.appendChild(pagesToInput);
  1226. mxEvent.addListener(pagesFromInput, 'focus', function()
  1227. {
  1228. pagesRadio.checked = true;
  1229. });
  1230. mxEvent.addListener(pagesToInput, 'focus', function()
  1231. {
  1232. pagesRadio.checked = true;
  1233. });
  1234. function validatePageRange()
  1235. {
  1236. pagesToInput.value = Math.max(1, Math.min(pageCount, Math.max(parseInt(pagesToInput.value), parseInt(pagesFromInput.value))));
  1237. pagesFromInput.value = Math.max(1, Math.min(pageCount, Math.min(parseInt(pagesToInput.value), parseInt(pagesFromInput.value))));
  1238. };
  1239. mxEvent.addListener(pagesFromInput, 'change', validatePageRange);
  1240. mxEvent.addListener(pagesToInput, 'change', validatePageRange);
  1241. if (editorUi.pages != null)
  1242. {
  1243. pageCount = editorUi.pages.length;
  1244. if (editorUi.currentPage != null)
  1245. {
  1246. for (var i = 0; i < editorUi.pages.length; i++)
  1247. {
  1248. if (editorUi.currentPage == editorUi.pages[i])
  1249. {
  1250. currentPage = i + 1;
  1251. pagesFromInput.value = currentPage;
  1252. pagesToInput.value = currentPage;
  1253. break;
  1254. }
  1255. }
  1256. }
  1257. }
  1258. pagesFromInput.setAttribute('max', pageCount);
  1259. pagesToInput.setAttribute('max', pageCount);
  1260. if (pageCount > 1)
  1261. {
  1262. div.appendChild(pagesSection);
  1263. }
  1264. // Adjust to ...
  1265. var adjustSection = document.createElement('div');
  1266. adjustSection.style.marginBottom = '10px';
  1267. var adjustRadio = document.createElement('input');
  1268. adjustRadio.style.marginRight = '8px';
  1269. adjustRadio.setAttribute('value', 'adjust');
  1270. adjustRadio.setAttribute('type', 'radio');
  1271. adjustRadio.setAttribute('name', 'printZoom');
  1272. adjustSection.appendChild(adjustRadio);
  1273. var span = document.createElement('span');
  1274. mxUtils.write(span, mxResources.get('adjustTo'));
  1275. adjustSection.appendChild(span);
  1276. var zoomInput = document.createElement('input');
  1277. zoomInput.style.cssText = 'margin:0 8px 0 8px;';
  1278. zoomInput.setAttribute('value', '100 %');
  1279. zoomInput.style.width = '50px';
  1280. adjustSection.appendChild(zoomInput);
  1281. mxEvent.addListener(zoomInput, 'focus', function()
  1282. {
  1283. adjustRadio.checked = true;
  1284. });
  1285. div.appendChild(adjustSection);
  1286. // Fit to ...
  1287. var fitSection = pagesSection.cloneNode(false);
  1288. var fitRadio = adjustRadio.cloneNode(true);
  1289. fitRadio.setAttribute('value', 'fit');
  1290. adjustRadio.setAttribute('checked', 'checked');
  1291. var spanFitRadio = document.createElement('div');
  1292. spanFitRadio.style.cssText = 'display:inline-block;height:100%;vertical-align:top;padding-top:2px;';
  1293. spanFitRadio.appendChild(fitRadio);
  1294. fitSection.appendChild(spanFitRadio);
  1295. var table = document.createElement('table');
  1296. table.style.display = 'inline-block';
  1297. var tbody = document.createElement('tbody');
  1298. var row1 = document.createElement('tr');
  1299. var row2 = row1.cloneNode(true);
  1300. var td1 = document.createElement('td');
  1301. var td2 = td1.cloneNode(true);
  1302. var td3 = td1.cloneNode(true);
  1303. var td4 = td1.cloneNode(true);
  1304. var td5 = td1.cloneNode(true);
  1305. var td6 = td1.cloneNode(true);
  1306. td1.style.textAlign = 'right';
  1307. td4.style.textAlign = 'right';
  1308. mxUtils.write(td1, mxResources.get('fitTo'));
  1309. var sheetsAcrossInput = document.createElement('input');
  1310. sheetsAcrossInput.style.cssText = 'margin:0 8px 0 8px;';
  1311. sheetsAcrossInput.setAttribute('value', '1');
  1312. sheetsAcrossInput.setAttribute('min', '1');
  1313. sheetsAcrossInput.setAttribute('type', 'number');
  1314. sheetsAcrossInput.style.width = '40px';
  1315. td2.appendChild(sheetsAcrossInput);
  1316. var span = document.createElement('span');
  1317. mxUtils.write(span, mxResources.get('fitToSheetsAcross'));
  1318. td3.appendChild(span);
  1319. mxUtils.write(td4, mxResources.get('fitToBy'));
  1320. var sheetsDownInput = sheetsAcrossInput.cloneNode(true);
  1321. td5.appendChild(sheetsDownInput);
  1322. mxEvent.addListener(sheetsAcrossInput, 'focus', function()
  1323. {
  1324. fitRadio.checked = true;
  1325. });
  1326. mxEvent.addListener(sheetsDownInput, 'focus', function()
  1327. {
  1328. fitRadio.checked = true;
  1329. });
  1330. var span = document.createElement('span');
  1331. mxUtils.write(span, mxResources.get('fitToSheetsDown'));
  1332. td6.appendChild(span);
  1333. row1.appendChild(td1);
  1334. row1.appendChild(td2);
  1335. row1.appendChild(td3);
  1336. row2.appendChild(td4);
  1337. row2.appendChild(td5);
  1338. row2.appendChild(td6);
  1339. tbody.appendChild(row1);
  1340. tbody.appendChild(row2);
  1341. table.appendChild(tbody);
  1342. fitSection.appendChild(table);
  1343. div.appendChild(fitSection);
  1344. // Page scale ...
  1345. var pageScaleSection = document.createElement('div');
  1346. var span = document.createElement('div');
  1347. span.style.fontWeight = 'bold';
  1348. span.style.marginBottom = '12px';
  1349. mxUtils.write(span, mxResources.get('paperSize'));
  1350. pageScaleSection.appendChild(span);
  1351. var span = document.createElement('div');
  1352. span.style.marginBottom = '12px';
  1353. var accessor = PageSetupDialog.addPageFormatPanel(span, 'printdialog',
  1354. editorUi.editor.graph.pageFormat || mxConstants.PAGE_FORMAT_A4_PORTRAIT);
  1355. pageScaleSection.appendChild(span);
  1356. var span = document.createElement('span');
  1357. mxUtils.write(span, mxResources.get('pageScale'));
  1358. pageScaleSection.appendChild(span);
  1359. var pageScaleInput = document.createElement('input');
  1360. pageScaleInput.style.cssText = 'margin:0 8px 0 8px;';
  1361. pageScaleInput.setAttribute('value', '100 %');
  1362. pageScaleInput.style.width = '60px';
  1363. pageScaleSection.appendChild(pageScaleInput);
  1364. div.appendChild(pageScaleSection);
  1365. // Buttons
  1366. var buttons = document.createElement('div');
  1367. buttons.style.cssText = 'text-align:right;margin:62px 0 0 0;';
  1368. // Overall scale for print-out to account for print borders in dialogs etc
  1369. function preview(print)
  1370. {
  1371. var printScale = parseInt(pageScaleInput.value) / 100;
  1372. if (isNaN(printScale))
  1373. {
  1374. printScale = 1;
  1375. pageScaleInput.value = '100 %';
  1376. }
  1377. // Workaround to match available paper size in actual print output
  1378. printScale *= 0.75;
  1379. function printGraph(thisGraph, pv, forcePageBreaks)
  1380. {
  1381. // Negative coordinates are cropped or shifted if page visible
  1382. var gb = thisGraph.getGraphBounds();
  1383. var border = 0;
  1384. var x0 = 0;
  1385. var y0 = 0;
  1386. var pf = accessor.get();
  1387. var scale = 1 / thisGraph.pageScale;
  1388. var autoOrigin = fitRadio.checked;
  1389. if (autoOrigin)
  1390. {
  1391. var h = parseInt(sheetsAcrossInput.value);
  1392. var v = parseInt(sheetsDownInput.value);
  1393. scale = Math.min((pf.height * v) / (gb.height / thisGraph.view.scale),
  1394. (pf.width * h) / (gb.width / thisGraph.view.scale));
  1395. }
  1396. else
  1397. {
  1398. scale = parseInt(zoomInput.value) / (100 * thisGraph.pageScale);
  1399. if (isNaN(scale))
  1400. {
  1401. printScale = 1 / thisGraph.pageScale;
  1402. zoomInput.value = '100 %';
  1403. }
  1404. }
  1405. // Applies print scale
  1406. pf = mxRectangle.fromRectangle(pf);
  1407. pf.width = Math.ceil(pf.width * printScale);
  1408. pf.height = Math.ceil(pf.height * printScale);
  1409. scale *= printScale;
  1410. // Starts at first visible page
  1411. if (!autoOrigin && thisGraph.pageVisible)
  1412. {
  1413. var layout = thisGraph.getPageLayout();
  1414. x0 -= layout.x * pf.width;
  1415. y0 -= layout.y * pf.height;
  1416. }
  1417. else
  1418. {
  1419. autoOrigin = true;
  1420. }
  1421. if (pv == null)
  1422. {
  1423. pv = PrintDialog.createPrintPreview(thisGraph, scale, pf, border, x0, y0, autoOrigin);
  1424. pv.pageSelector = false;
  1425. pv.mathEnabled = false;
  1426. if (typeof(MathJax) !== 'undefined')
  1427. {
  1428. // Adds class to ignore if math is disabled
  1429. var printPreviewRenderPage = pv.renderPage;
  1430. pv.renderPage = function(w, h, dx, dy, content, pageNumber)
  1431. {
  1432. var result = printPreviewRenderPage.apply(this, arguments);
  1433. if (this.graph.mathEnabled)
  1434. {
  1435. this.mathEnabled = true;
  1436. }
  1437. else
  1438. {
  1439. result.className = 'geDisableMathJax';
  1440. }
  1441. return result;
  1442. };
  1443. }
  1444. pv.open(null, null, forcePageBreaks, true);
  1445. }
  1446. else
  1447. {
  1448. var bg = thisGraph.background;
  1449. if (bg == null || bg == '' || bg == mxConstants.NONE)
  1450. {
  1451. bg = '#ffffff';
  1452. }
  1453. pv.backgroundColor = bg;
  1454. pv.autoOrigin = autoOrigin;
  1455. pv.appendGraph(thisGraph, scale, x0, y0, forcePageBreaks, true);
  1456. }
  1457. return pv;
  1458. };
  1459. var pagesFrom = pagesFromInput.value;
  1460. var pagesTo = pagesToInput.value;
  1461. var ignorePages = !allPagesRadio.checked;
  1462. var pv = null;
  1463. if (ignorePages)
  1464. {
  1465. ignorePages = pagesFrom == currentPage && pagesTo == currentPage;
  1466. }
  1467. if (!ignorePages && editorUi.pages != null && editorUi.pages.length)
  1468. {
  1469. var i0 = 0;
  1470. var imax = editorUi.pages.length - 1;
  1471. if (!allPagesRadio.checked)
  1472. {
  1473. i0 = parseInt(pagesFrom) - 1;
  1474. imax = parseInt(pagesTo) - 1;
  1475. }
  1476. for (var i = i0; i <= imax; i++)
  1477. {
  1478. var page = editorUi.pages[i];
  1479. var tempGraph = (page == editorUi.currentPage) ? graph : null;
  1480. if (tempGraph == null)
  1481. {
  1482. tempGraph = editorUi.createTemporaryGraph(graph.getStylesheet());
  1483. // Restores graph settings that are relevant for printing
  1484. var pageVisible = true;
  1485. var mathEnabled = false;
  1486. var bg = null;
  1487. var bgImage = null;
  1488. if (page.viewState == null && page.mapping == null)
  1489. {
  1490. // Workaround to extract view state from XML node
  1491. // This changes the state of the page and parses
  1492. // the XML for the graph model even if not needed.
  1493. if (page.root == null)
  1494. {
  1495. editorUi.updatePageRoot(page);
  1496. }
  1497. }
  1498. if (page.viewState != null)
  1499. {
  1500. pageVisible = page.viewState.pageVisible;
  1501. mathEnabled = page.viewState.mathEnabled;
  1502. bg = page.viewState.background;
  1503. bgImage = page.viewState.backgroundImage;
  1504. }
  1505. else if (page.mapping != null && page.mapping.diagramMap != null)
  1506. {
  1507. // Default pageVisible in realtime is true
  1508. mathEnabled = page.mapping.diagramMap.get('mathEnabled') != '0';
  1509. bg = page.mapping.diagramMap.get('background');
  1510. var temp = page.mapping.diagramMap.get('backgroundImage');
  1511. bgImage = (temp != null && temp.length > 0) ? JSON.parse(temp) : null;
  1512. }
  1513. tempGraph.background = bg;
  1514. tempGraph.backgroundImage = (bgImage != null) ? new mxImage(bgImage.src, bgImage.width, bgImage.height) : null;
  1515. tempGraph.pageVisible = pageVisible;
  1516. tempGraph.mathEnabled = mathEnabled;
  1517. // Redirects placeholders to current page
  1518. var graphGetGlobalVariable = tempGraph.getGlobalVariable;
  1519. tempGraph.getGlobalVariable = function(name)
  1520. {
  1521. if (name == 'page')
  1522. {
  1523. return page.getName();
  1524. }
  1525. else if (name == 'pagenumber')
  1526. {
  1527. return i + 1;
  1528. }
  1529. return graphGetGlobalVariable.apply(this, arguments);
  1530. };
  1531. document.body.appendChild(tempGraph.container);
  1532. editorUi.updatePageRoot(page);
  1533. tempGraph.model.setRoot(page.root);
  1534. }
  1535. pv = printGraph(tempGraph, pv, i != imax);
  1536. if (tempGraph != graph)
  1537. {
  1538. tempGraph.container.parentNode.removeChild(tempGraph.container);
  1539. }
  1540. }
  1541. }
  1542. else
  1543. {
  1544. pv = printGraph(graph);
  1545. }
  1546. if (pv.mathEnabled)
  1547. {
  1548. var doc = pv.wnd.document;
  1549. doc.writeln('<script type="text/x-mathjax-config">');
  1550. doc.writeln('MathJax.Hub.Config({');
  1551. doc.writeln('messageStyle: "none",');
  1552. doc.writeln('jax: ["input/TeX", "input/MathML", "input/AsciiMath", "output/HTML-CSS"],');
  1553. doc.writeln('extensions: ["tex2jax.js", "mml2jax.js", "asciimath2jax.js"],');
  1554. doc.writeln('TeX: {');
  1555. doc.writeln('extensions: ["AMSmath.js", "AMSsymbols.js", "noErrors.js", "noUndefined.js"]');
  1556. doc.writeln('},');
  1557. // Ignores math in in-place editor
  1558. doc.writeln('tex2jax: {');
  1559. doc.writeln(' ignoreClass: "geDisableMathJax"');
  1560. doc.writeln('},');
  1561. doc.writeln('asciimath2jax: {');
  1562. doc.writeln(' ignoreClass: "geDisableMathJax"');
  1563. doc.writeln('}');
  1564. doc.writeln('});');
  1565. // Adds asynchronous printing when MathJax finished rendering
  1566. if (print)
  1567. {
  1568. doc.writeln('MathJax.Hub.Queue(function () {');
  1569. doc.writeln('window.print();');
  1570. doc.writeln('});');
  1571. }
  1572. doc.writeln('</script>');
  1573. doc.writeln('<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>');
  1574. }
  1575. pv.closeDocument();
  1576. if (!pv.mathEnabled && print)
  1577. {
  1578. PrintDialog.printPreview(pv);
  1579. }
  1580. };
  1581. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1582. {
  1583. editorUi.hideDialog();
  1584. });
  1585. cancelBtn.className = 'geBtn';
  1586. if (editorUi.editor.cancelFirst)
  1587. {
  1588. buttons.appendChild(cancelBtn);
  1589. }
  1590. if (!editorUi.isOffline())
  1591. {
  1592. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  1593. {
  1594. window.open('https://desk.draw.io/support/solutions/articles/16000048947');
  1595. });
  1596. helpBtn.className = 'geBtn';
  1597. buttons.appendChild(helpBtn);
  1598. }
  1599. if (PrintDialog.previewEnabled)
  1600. {
  1601. var previewBtn = mxUtils.button(mxResources.get('preview'), function()
  1602. {
  1603. editorUi.hideDialog();
  1604. preview(false);
  1605. });
  1606. previewBtn.className = 'geBtn';
  1607. buttons.appendChild(previewBtn);
  1608. }
  1609. var printBtn = mxUtils.button(mxResources.get((!PrintDialog.previewEnabled) ? 'ok' : 'print'), function()
  1610. {
  1611. editorUi.hideDialog();
  1612. preview(true);
  1613. });
  1614. printBtn.className = 'geBtn gePrimaryBtn';
  1615. buttons.appendChild(printBtn);
  1616. if (!editorUi.editor.cancelFirst)
  1617. {
  1618. buttons.appendChild(cancelBtn);
  1619. }
  1620. div.appendChild(buttons);
  1621. this.container = div;
  1622. };
  1623. })();