exporting.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. /*
  2. Highcharts JS v4.1.3 (2015-02-27)
  3. Exporting module
  4. (c) 2010-2014 Torstein Honsi
  5. License: www.highcharts.com/license
  6. */
  7. (function(g) {
  8. var z = g.Chart, s = g.addEvent, A = g.removeEvent, B = HighchartsAdapter.fireEvent, j = g.createElement, p = g.discardElement, u = g.css, l = g.merge, m = g.each, q = g.extend, E = g.splat, F = Math.max, k = document, C = window, G = g.isTouchDevice, H = g.Renderer.prototype.symbols, r = g
  9. .getOptions(), x;
  10. q(r.lang, {
  11. printChart : "Print chart",
  12. downloadPNG : "Download PNG image",
  13. downloadJPEG : "Download JPEG image",
  14. downloadPDF : "Download PDF document",
  15. downloadSVG : "Download SVG vector image",
  16. contextButtonTitle : "Chart context menu"
  17. });
  18. r.navigation = {
  19. menuStyle : {
  20. border : "1px solid #A0A0A0",
  21. background : "#FFFFFF",
  22. padding : "5px 0"
  23. },
  24. menuItemStyle : {
  25. padding : "0 10px",
  26. background : "none",
  27. color : "#303030",
  28. fontSize : G ? "14px" : "11px"
  29. },
  30. menuItemHoverStyle : {
  31. background : "#4572A5",
  32. color : "#FFFFFF"
  33. },
  34. buttonOptions : {
  35. symbolFill : "#E0E0E0",
  36. symbolSize : 14,
  37. symbolStroke : "#666",
  38. symbolStrokeWidth : 3,
  39. symbolX : 12.5,
  40. symbolY : 10.5,
  41. align : "right",
  42. buttonSpacing : 3,
  43. height : 22,
  44. theme : {
  45. fill : "white",
  46. stroke : "none"
  47. },
  48. verticalAlign : "top",
  49. width : 24
  50. }
  51. };
  52. r.exporting = {
  53. type : "image/png",
  54. url : "http://export.highcharts.com/",
  55. buttons : {
  56. contextButton : {
  57. menuClassName : "highcharts-contextmenu",
  58. symbol : "menu",
  59. _titleKey : "contextButtonTitle",
  60. menuItems : [ {
  61. textKey : "printChart",
  62. onclick : function() {
  63. this.print()
  64. }
  65. }, {
  66. separator : !0
  67. }, {
  68. textKey : "downloadPNG",
  69. onclick : function() {
  70. this.exportChart()
  71. }
  72. }, {
  73. textKey : "downloadJPEG",
  74. onclick : function() {
  75. this.exportChart({
  76. type : "image/jpeg"
  77. })
  78. }
  79. }, {
  80. textKey : "downloadPDF",
  81. onclick : function() {
  82. this.exportChart({
  83. type : "application/pdf"
  84. })
  85. }
  86. }, {
  87. textKey : "downloadSVG",
  88. onclick : function() {
  89. this.exportChart({
  90. type : "image/svg+xml"
  91. })
  92. }
  93. } ]
  94. }
  95. }
  96. };
  97. g.post = function(b, a, e) {
  98. var c, b = j("form", l({
  99. method : "post",
  100. action : b,
  101. enctype : "multipart/form-data"
  102. }, e), {
  103. display : "none"
  104. }, k.body);
  105. for (c in a)
  106. j("input", {
  107. type : "hidden",
  108. name : c,
  109. value : a[c]
  110. }, null, b);
  111. b.submit();
  112. p(b)
  113. };
  114. q(
  115. z.prototype,
  116. {
  117. sanitizeSVG : function(b) {
  118. return b
  119. .replace(/zIndex="[^"]+"/g, "")
  120. .replace(/isShadow="[^"]+"/g, "")
  121. .replace(/symbolName="[^"]+"/g, "")
  122. .replace(/jQuery[0-9]+="[^"]+"/g, "")
  123. .replace(/url\([^#]+#/g, "url(#")
  124. .replace(/<svg /,
  125. '<svg xmlns:xlink="http://www.w3.org/1999/xlink" ')
  126. .replace(/ (NS[0-9]+\:)?href=/g, " xlink:href=")
  127. .replace(/\n/, " ")
  128. .replace(/<\/svg>.*?$/, "</svg>")
  129. .replace(
  130. /(fill|stroke)="rgba\(([ 0-9]+,[ 0-9]+,[ 0-9]+),([ 0-9\.]+)\)"/g,
  131. '$1="rgb($2)" $1-opacity="$3"').replace(
  132. /(text-shadow:)([^;"]+)([;"])/g,
  133. function(a, b, c, f) {
  134. c = c.replace(/\([^\)]+\)/g,
  135. function(a) {
  136. return a.replace(/,/g, "|")
  137. });
  138. c = c.split(",")[0];
  139. c = c
  140. .replace(/\([^\)]+\)/g,
  141. function(a) {
  142. return a.replace(
  143. /\|/g, ",")
  144. });
  145. return b + c + f
  146. }).replace(/&nbsp;/g, " ").replace(
  147. /&shy;/g, "­").replace(/<IMG /g, "<image ")
  148. .replace(/height=([^" ]+)/g, 'height="$1"')
  149. .replace(/width=([^" ]+)/g, 'width="$1"').replace(
  150. /hc-svg-href="([^"]+)">/g,
  151. 'xlink:href="$1"/>').replace(
  152. /id=([^" >]+)/g, 'id="$1"').replace(
  153. /class=([^" >]+)/g, 'class="$1"').replace(
  154. / transform /g, " ").replace(
  155. /:(path|rect)/g, "$1").replace(
  156. /style="([^"]+)"/g, function(a) {
  157. return a.toLowerCase()
  158. })
  159. },
  160. getSVG : function(b) {
  161. var a = this, e, c, f, y, h, d = l(a.options, b);
  162. if (!k.createElementNS)
  163. k.createElementNS = function(a, b) {
  164. return k.createElement(b)
  165. };
  166. c = j("div", null, {
  167. position : "absolute",
  168. top : "-9999em",
  169. width : a.chartWidth + "px",
  170. height : a.chartHeight + "px"
  171. }, k.body);
  172. f = a.renderTo.style.width;
  173. h = a.renderTo.style.height;
  174. f = d.exporting.sourceWidth || d.chart.width
  175. || /px$/.test(f) && parseInt(f, 10) || 600;
  176. h = d.exporting.sourceHeight || d.chart.height
  177. || /px$/.test(h) && parseInt(h, 10) || 400;
  178. q(d.chart, {
  179. animation : !1,
  180. renderTo : c,
  181. forExport : !0,
  182. width : f,
  183. height : h
  184. });
  185. d.exporting.enabled = !1;
  186. delete d.data;
  187. d.series = [];
  188. m(a.series, function(a) {
  189. y = l(a.options, {
  190. animation : !1,
  191. enableMouseTracking : !1,
  192. showCheckbox : !1,
  193. visible : a.visible
  194. });
  195. y.isInternal || d.series.push(y)
  196. });
  197. b && m([ "xAxis", "yAxis" ], function(a) {
  198. m(E(b[a]), function(b, c) {
  199. d[a][c] = l(d[a][c], b)
  200. })
  201. });
  202. e = new g.Chart(d, a.callback);
  203. m(
  204. [ "xAxis", "yAxis" ],
  205. function(b) {
  206. m(
  207. a[b],
  208. function(a, c) {
  209. var d = e[b][c], f = a
  210. .getExtremes(), h = f.userMin, f = f.userMax;
  211. d
  212. && (h !== void 0 || f !== void 0)
  213. && d.setExtremes(h, f, !0,
  214. !1)
  215. })
  216. });
  217. f = e.container.innerHTML;
  218. d = null;
  219. e.destroy();
  220. p(c);
  221. f = this.sanitizeSVG(f);
  222. return f = f.replace(/(url\(#highcharts-[0-9]+)&quot;/g,
  223. "$1").replace(/&quot;/g, "'")
  224. },
  225. getSVGForExport : function(b, a) {
  226. var e = this.options.exporting;
  227. return this.getSVG(l({
  228. chart : {
  229. borderRadius : 0
  230. }
  231. }, e.chartOptions, a, {
  232. exporting : {
  233. sourceWidth : b && b.sourceWidth || e.sourceWidth,
  234. sourceHeight : b && b.sourceHeight
  235. || e.sourceHeight
  236. }
  237. }))
  238. },
  239. exportChart : function(b, a) {
  240. var e = this.getSVGForExport(b, a), b = l(
  241. this.options.exporting, b);
  242. g.post(b.url, {
  243. filename : b.filename || "chart",
  244. type : b.type,
  245. width : b.width || 0,
  246. scale : b.scale || 2,
  247. svg : e
  248. }, b.formAttributes)
  249. },
  250. print : function() {
  251. var b = this, a = b.container, e = [], c = a.parentNode, f = k.body, g = f.childNodes;
  252. if (!b.isPrinting)
  253. b.isPrinting = !0, B(b, "beforePrint"), m(g, function(
  254. a, b) {
  255. if (a.nodeType === 1)
  256. e[b] = a.style.display,
  257. a.style.display = "none"
  258. }), f.appendChild(a), C.focus(), C.print(), setTimeout(
  259. function() {
  260. c.appendChild(a);
  261. m(g, function(a, b) {
  262. if (a.nodeType === 1)
  263. a.style.display = e[b]
  264. });
  265. b.isPrinting = !1;
  266. B(b, "afterPrint")
  267. }, 1E3)
  268. },
  269. contextMenu : function(b, a, e, c, f, g, h) {
  270. var d = this, l = d.options.navigation, D = l.menuItemStyle, n = d.chartWidth, o = d.chartHeight, k = "cache-"
  271. + b, i = d[k], t = F(f, g), v, w, p, r = function(a) {
  272. d.pointer.inClass(a.target, b) || w()
  273. };
  274. if (!i)
  275. d[k] = i = j("div", {
  276. className : b
  277. }, {
  278. position : "absolute",
  279. zIndex : 1E3,
  280. padding : t + "px"
  281. }, d.container),
  282. v = j("div", null, q({
  283. MozBoxShadow : "3px 3px 10px #888",
  284. WebkitBoxShadow : "3px 3px 10px #888",
  285. boxShadow : "3px 3px 10px #888"
  286. }, l.menuStyle), i),
  287. w = function() {
  288. u(i, {
  289. display : "none"
  290. });
  291. h && h.setState(0);
  292. d.openMenu = !1
  293. },
  294. s(i, "mouseleave", function() {
  295. p = setTimeout(w, 500)
  296. }),
  297. s(i, "mouseenter", function() {
  298. clearTimeout(p)
  299. }),
  300. s(document, "mouseup", r),
  301. s(d, "destroy", function() {
  302. A(document, "mouseup", r)
  303. }),
  304. m(
  305. a,
  306. function(a) {
  307. if (a) {
  308. var b = a.separator ? j("hr",
  309. null, null, v)
  310. : j(
  311. "div",
  312. {
  313. onmouseover : function() {
  314. u(
  315. this,
  316. l.menuItemHoverStyle)
  317. },
  318. onmouseout : function() {
  319. u(this,
  320. D)
  321. },
  322. onclick : function() {
  323. w();
  324. a.onclick
  325. && a.onclick
  326. .apply(
  327. d,
  328. arguments)
  329. },
  330. innerHTML : a.text
  331. || d.options.lang[a.textKey]
  332. },
  333. q(
  334. {
  335. cursor : "pointer"
  336. }, D),
  337. v);
  338. d.exportDivElements.push(b)
  339. }
  340. }), d.exportDivElements.push(v, i),
  341. d.exportMenuWidth = i.offsetWidth,
  342. d.exportMenuHeight = i.offsetHeight;
  343. a = {
  344. display : "block"
  345. };
  346. e + d.exportMenuWidth > n ? a.right = n - e - f - t + "px"
  347. : a.left = e - t + "px";
  348. c + g + d.exportMenuHeight > o
  349. && h.alignOptions.verticalAlign !== "top" ? a.bottom = o
  350. - c - t + "px"
  351. : a.top = c + g - t + "px";
  352. u(i, a);
  353. d.openMenu = !0
  354. },
  355. addButton : function(b) {
  356. var a = this, e = a.renderer, c = l(
  357. a.options.navigation.buttonOptions, b), f = c.onclick, k = c.menuItems, h, d, m = {
  358. stroke : c.symbolStroke,
  359. fill : c.symbolFill
  360. }, j = c.symbolSize || 12;
  361. if (!a.btnCount)
  362. a.btnCount = 0;
  363. if (!a.exportDivElements)
  364. a.exportDivElements = [], a.exportSVGElements = [];
  365. if (c.enabled !== !1) {
  366. var n = c.theme, o = n.states, p = o && o.hover, o = o
  367. && o.select, i;
  368. delete n.states;
  369. f ? i = function() {
  370. f.apply(a, arguments)
  371. } : k
  372. && (i = function() {
  373. a.contextMenu(d.menuClassName, k,
  374. d.translateX, d.translateY,
  375. d.width, d.height, d);
  376. d.setState(2)
  377. });
  378. c.text && c.symbol ? n.paddingLeft = g.pick(
  379. n.paddingLeft, 25) : c.text || q(n, {
  380. width : c.width,
  381. height : c.height,
  382. padding : 0
  383. });
  384. d = e.button(c.text, 0, 0, i, n, p, o).attr({
  385. title : a.options.lang[c._titleKey],
  386. "stroke-linecap" : "round"
  387. });
  388. d.menuClassName = b.menuClassName || "highcharts-menu-"
  389. + a.btnCount++;
  390. c.symbol
  391. && (h = e.symbol(c.symbol, c.symbolX - j / 2,
  392. c.symbolY - j / 2, j, j).attr(q(m, {
  393. "stroke-width" : c.symbolStrokeWidth || 1,
  394. zIndex : 1
  395. })).add(d));
  396. d.add().align(q(c, {
  397. width : d.width,
  398. x : g.pick(c.x, x)
  399. }), !0, "spacingBox");
  400. x += (d.width + c.buttonSpacing)
  401. * (c.align === "right" ? -1 : 1);
  402. a.exportSVGElements.push(d, h)
  403. }
  404. },
  405. destroyExport : function(b) {
  406. var b = b.target, a, e;
  407. for (a = 0; a < b.exportSVGElements.length; a++)
  408. if (e = b.exportSVGElements[a])
  409. e.onclick = e.ontouchstart = null,
  410. b.exportSVGElements[a] = e.destroy();
  411. for (a = 0; a < b.exportDivElements.length; a++)
  412. e = b.exportDivElements[a],
  413. A(e, "mouseleave"),
  414. b.exportDivElements[a] = e.onmouseout = e.onmouseover = e.ontouchstart = e.onclick = null,
  415. p(e)
  416. }
  417. });
  418. H.menu = function(b, a, e, c) {
  419. return [ "M", b, a + 2.5, "L", b + e, a + 2.5, "M", b, a + c / 2 + 0.5,
  420. "L", b + e, a + c / 2 + 0.5, "M", b, a + c - 1.5, "L", b + e,
  421. a + c - 1.5 ]
  422. };
  423. z.prototype.callbacks.push(function(b) {
  424. var a, e = b.options.exporting, c = e.buttons;
  425. x = 0;
  426. if (e.enabled !== !1) {
  427. for (a in c)
  428. b.addButton(c[a]);
  429. s(b, "destroy", b.destroyExport)
  430. }
  431. })
  432. })(Highcharts);