export.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <script>
  6. var mathJaxQueue = [];
  7. // Disables global typesetting and messages on startup, adds queue for
  8. // asynchronous rendering while MathJax is loading
  9. window.MathJax =
  10. {
  11. skipStartupTypeset: true,
  12. messageStyle: 'none',
  13. AuthorInit: function ()
  14. {
  15. MathJax.Hub.Register.StartupHook('Begin', function()
  16. {
  17. for (var i = 0; i < mathJaxQueue.length; i++)
  18. {
  19. MathJax.Hub.Queue(['Typeset', MathJax.Hub, mathJaxQueue[i]]);
  20. }
  21. });
  22. }
  23. };
  24. // Adds global enqueue method for async rendering
  25. window.MathJaxRender = function(container)
  26. {
  27. // Initial rendering when MathJax finished loading
  28. if (typeof(MathJax) !== 'undefined' && typeof(MathJax.Hub) !== 'undefined')
  29. {
  30. MathJax.Hub.Queue(['Typeset', MathJax.Hub, container]);
  31. }
  32. else
  33. {
  34. mathJaxQueue.push(container);
  35. }
  36. }
  37. </script>
  38. <script src="https://cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_HTMLorMML"></script>
  39. <script>
  40. var urlParams = (function(url)
  41. {
  42. var result = new Object();
  43. var params = window.location.search.slice(1).split('&');
  44. for (var i = 0; i < params.length; i++)
  45. {
  46. idx = params[i].indexOf('=');
  47. if (idx > 0)
  48. {
  49. result[params[i].substring(0, idx)] = params[i].substring(idx + 1);
  50. }
  51. }
  52. return result;
  53. })(window.location.href);
  54. // Removes unused dependencies
  55. urlParams['analytics'] = '0';
  56. urlParams['picker'] = '0';
  57. urlParams['gapi'] = '0';
  58. urlParams['db'] = '0';
  59. // Public global variables
  60. var MAX_REQUEST_SIZE = 10485760;
  61. var MAX_AREA = 10000 * 10000;
  62. // Paths and files
  63. var STENCIL_PATH = 'stencils';
  64. var SHAPES_PATH = 'shapes';
  65. var IMAGE_PATH = 'images';
  66. // Path for images inside the diagram
  67. var GRAPH_IMAGE_PATH = 'img';
  68. var STYLE_PATH = 'styles';
  69. var CSS_PATH = 'styles';
  70. // Directory for i18 files and basename for main i18n file
  71. var RESOURCES_PATH = 'resources';
  72. var RESOURCE_BASE = RESOURCES_PATH + '/dia';
  73. // Specifies connection mode for touch devices (at least one should be true)
  74. var isLocalStorage = false;
  75. var uiTheme = null;
  76. // Sets the base path, the UI language via URL param and configures the
  77. // supported languages to avoid 404s. The loading of all core language
  78. // resources is disabled as all required resources are in grapheditor.
  79. // properties. Note that in this example the loading of two resource
  80. // files (the special bundle and the default bundle) is disabled to
  81. // save a GET request. This requires that all resources be present in
  82. // the special bundle.
  83. var mxLoadResources = false;
  84. var mxLanguage = 'en'
  85. var geBasePath = 'js';
  86. var mxBasePath = 'mxgraph';
  87. function render(data)
  88. {
  89. mxConstants.SHADOWCOLOR = '#000000';
  90. mxConstants.SHADOW_OPACITY = 0.25;
  91. var graph = new Graph(document.getElementById('graph'));
  92. graph.foldingEnabled = false;
  93. graph.setEnabled(false);
  94. if (data.math)
  95. {
  96. mxClient.NO_FO = true;
  97. }
  98. var xmlDoc = mxUtils.parseXml(data.xml);
  99. var codec = new mxCodec(xmlDoc);
  100. codec.decode(xmlDoc.documentElement, graph.getModel());
  101. // Handles PDF output where the output should match the page format if the page is visible
  102. if (data.math && data.format == 'pdf' && xmlDoc.documentElement.getAttribute('page') == '1')
  103. {
  104. graph.pageVisible = true;
  105. var pw = xmlDoc.documentElement.getAttribute('pageWidth');
  106. var ph = xmlDoc.documentElement.getAttribute('pageHeight');
  107. if (pw != null && ph != null)
  108. {
  109. graph.pageFormat = new mxRectangle(0, 0, parseFloat(pw), parseFloat(ph));
  110. }
  111. var ps = xmlDoc.documentElement.getAttribute('pageScale');
  112. if (ps != null)
  113. {
  114. graph.pageScale = ps;
  115. }
  116. graph.getPageSize = function()
  117. {
  118. return new mxRectangle(0, 0, this.pageFormat.width * this.pageScale,
  119. this.pageFormat.height * this.pageScale);
  120. };
  121. graph.getPageLayout = function()
  122. {
  123. var size = (this.pageVisible) ? this.getPageSize() : this.scrollTileSize;
  124. var bounds = this.getGraphBounds();
  125. if (bounds.width == 0 || bounds.height == 0)
  126. {
  127. return new mxRectangle(0, 0, 1, 1);
  128. }
  129. else
  130. {
  131. // Computes untransformed graph bounds
  132. var x = bounds.x / this.view.scale - this.view.translate.x;
  133. var y = bounds.y / this.view.scale - this.view.translate.y;
  134. var w = bounds.width / this.view.scale;
  135. var h = bounds.height / this.view.scale;
  136. var x0 = Math.floor(x / size.width);
  137. var y0 = Math.floor(y / size.height);
  138. var w0 = Math.ceil((x + w) / size.width) - x0;
  139. var h0 = Math.ceil((y + h) / size.height) - y0;
  140. return new mxRectangle(x0, y0, w0, h0);
  141. }
  142. };
  143. // Fits the number of background pages to the graph
  144. graph.view.getBackgroundPageBounds = function()
  145. {
  146. var layout = this.graph.getPageLayout();
  147. var page = this.graph.getPageSize();
  148. return new mxRectangle(this.scale * (this.translate.x + layout.x * page.width),
  149. this.scale * (this.translate.y + layout.y * page.height),
  150. this.scale * layout.width * page.width,
  151. this.scale * layout.height * page.height);
  152. };
  153. }
  154. else if (data.crop)
  155. {
  156. var b = graph.getGraphBounds();
  157. graph.view.setTranslate(-b.x, -b.y);
  158. }
  159. else if (data.w != null && data.h != null)
  160. {
  161. var b = graph.getGraphBounds();
  162. var s = Math.floor(Math.min(data.w / b.width, data.h / b.height) * 100) / 100;
  163. graph.view.scaleAndTranslate(s, (data.w - b.width * s) / 2 / s - b.x,
  164. (data.h - b.height * s) / 2 / s - b.y);
  165. }
  166. if (data.math)
  167. {
  168. window.MathJaxRender(graph.container);
  169. // Asynchronous callback when MathJax has finished
  170. window.MathJax.Hub.Queue(function ()
  171. {
  172. if (typeof window.callPhantom === 'function')
  173. {
  174. window.callPhantom();
  175. }
  176. });
  177. }
  178. var bounds = (graph.pageVisible) ? graph.view.getBackgroundPageBounds() : graph.getGraphBounds();
  179. var bg = xmlDoc.documentElement.getAttribute('background');
  180. // Apply background color for direct export
  181. if (data.format == 'jpg' && bg == 'none')
  182. {
  183. bg = '#ffffff';
  184. }
  185. if (graph.pageVisible)
  186. {
  187. document.body.style.width = bounds.width + 'px';
  188. document.body.style.height = bounds.height + 'px';
  189. }
  190. document.body.style.backgroundColor = bg || '#ffffff';
  191. // SVG not needed for math export
  192. var svg = (data.math) ? '' : mxUtils.getXml(graph.getSvg());
  193. return {width: bounds.width, height: bounds.height, bg: bg, svg: svg};
  194. };
  195. </script>
  196. <script src="js/app.min.js"></script>
  197. </head>
  198. <body style="margin:0px;">
  199. <div id="graph"></div>
  200. </body>
  201. </html>