exporting.js 14 KB

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