export-data.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /*
  2. Highcharts JS v7.0.2 (2019-01-17)
  3. Exporting module
  4. (c) 2010-2019 Torstein Honsi
  5. License: www.highcharts.com/license
  6. */
  7. (function (h) {
  8. "object" === typeof module && module.exports ? (h["default"] = h, module.exports = h) : "function" === typeof define && define.amd ? define(function () {
  9. return h
  10. }) : h("undefined" !== typeof Highcharts ? Highcharts : void 0)
  11. })(function (h) {
  12. (function (a) {
  13. a.ajax = function (k) {
  14. var b = a.merge(!0, {
  15. url: !1,
  16. type: "GET",
  17. dataType: "json",
  18. success: !1,
  19. error: !1,
  20. data: !1,
  21. headers: {}
  22. }, k);
  23. k = {
  24. json: "application/json",
  25. xml: "application/xml",
  26. text: "text/plain",
  27. octet: "application/octet-stream"
  28. };
  29. var f = new XMLHttpRequest;
  30. if (!b.url) return !1;
  31. f.open(b.type.toUpperCase(),
  32. b.url, !0);
  33. f.setRequestHeader("Content-Type", k[b.dataType] || k.text);
  34. a.objectEach(b.headers, function (a, k) {
  35. f.setRequestHeader(k, a)
  36. });
  37. f.onreadystatechange = function () {
  38. var a;
  39. if (4 === f.readyState) {
  40. if (200 === f.status) {
  41. a = f.responseText;
  42. if ("json" === b.dataType) try {
  43. a = JSON.parse(a)
  44. } catch (n) {
  45. b.error && b.error(f, n);
  46. return
  47. }
  48. return b.success && b.success(a)
  49. }
  50. b.error && b.error(f, f.responseText)
  51. }
  52. };
  53. try {
  54. b.data = JSON.stringify(b.data)
  55. } catch (C) {
  56. }
  57. f.send(b.data || !0)
  58. }
  59. })(h);
  60. (function (a) {
  61. var k = a.win, b = k.navigator, f = k.document, h = k.URL ||
  62. k.webkitURL || k, n = /Edge\/\d+/.test(b.userAgent);
  63. a.dataURLtoBlob = function (a) {
  64. if ((a = a.match(/data:([^;]*)(;base64)?,([0-9A-Za-z+/]+)/)) && 3 < a.length && k.atob && k.ArrayBuffer && k.Uint8Array && k.Blob && h.createObjectURL) {
  65. for (var f = k.atob(a[3]), b = new k.ArrayBuffer(f.length), b = new k.Uint8Array(b), l = 0; l < b.length; ++l) b[l] = f.charCodeAt(l);
  66. a = new k.Blob([b], {type: a[1]});
  67. return h.createObjectURL(a)
  68. }
  69. };
  70. a.downloadURL = function (c, h) {
  71. var d = f.createElement("a"), l;
  72. if ("string" === typeof c || c instanceof String || !b.msSaveOrOpenBlob) {
  73. if (n ||
  74. 2E6 < c.length) if (c = a.dataURLtoBlob(c), !c) throw Error("Failed to convert to blob");
  75. if (void 0 !== d.download) d.href = c, d.download = h, f.body.appendChild(d), d.click(), f.body.removeChild(d); else try {
  76. if (l = k.open(c, "chart"), void 0 === l || null === l) throw Error("Failed to open window");
  77. } catch (y) {
  78. k.location.href = c
  79. }
  80. } else b.msSaveOrOpenBlob(c, h)
  81. }
  82. })(h);
  83. (function (a) {
  84. function k(a, b) {
  85. if (h.Blob && h.navigator.msSaveOrOpenBlob) return new h.Blob(["\ufeff" + a], {type: b})
  86. }
  87. var b = a.defined, f = a.pick, h = a.win, n = h.document, c = a.seriesTypes,
  88. z = a.downloadURL;
  89. a.setOptions({
  90. exporting: {
  91. csv: {
  92. columnHeaderFormatter: null,
  93. dateFormat: "%Y-%m-%d %H:%M:%S",
  94. decimalPoint: null,
  95. itemDelimiter: null,
  96. lineDelimiter: "\n"
  97. }, showTable: !1, useMultiLevelHeaders: !0, useRowspanHeaders: !0
  98. },
  99. lang: {
  100. downloadCSV: "Download CSV",
  101. downloadXLS: "Download XLS",
  102. openInCloud: "Open in Highcharts Cloud",
  103. viewData: "View data table"
  104. }
  105. });
  106. a.addEvent(a.Chart, "render", function () {
  107. this.options && this.options.exporting && this.options.exporting.showTable && this.viewData()
  108. });
  109. a.Chart.prototype.setUpKeyToAxis =
  110. function () {
  111. c.arearange && (c.arearange.prototype.keyToAxis = {low: "y", high: "y"});
  112. c.gantt && (c.gantt.prototype.keyToAxis = {start: "x", end: "x"})
  113. };
  114. a.Chart.prototype.getDataRows = function (l) {
  115. var k = this.time, h = this.options.exporting && this.options.exporting.csv || {}, g, c = this.xAxis,
  116. q = {}, d = [], m, n = [], p = [], u, t, r, B = function (e, b, g) {
  117. if (h.columnHeaderFormatter) {
  118. var r = h.columnHeaderFormatter(e, b, g);
  119. if (!1 !== r) return r
  120. }
  121. return e ? e instanceof a.Axis ? e.options.title && e.options.title.text || (e.isDatetimeAxis ? "DateTime" : "Category") :
  122. l ? {
  123. columnTitle: 1 < g ? b : e.name,
  124. topLevelColumnTitle: e.name
  125. } : e.name + (1 < g ? " (" + b + ")" : "") : "Category"
  126. }, w = [];
  127. t = 0;
  128. this.setUpKeyToAxis();
  129. this.series.forEach(function (e) {
  130. var b = e.options.keys || e.pointArrayMap || ["y"], g = b.length, r = !e.requireSorting && {}, v = {},
  131. y = {}, m = c.indexOf(e.xAxis), A, d;
  132. b.forEach(function (a) {
  133. var b = (e.keyToAxis && e.keyToAxis[a] || a) + "Axis";
  134. v[a] = e[b] && e[b].categories || [];
  135. y[a] = e[b] && e[b].isDatetimeAxis
  136. });
  137. if (!1 !== e.options.includeInCSVExport && !e.options.isInternal && !1 !== e.visible) {
  138. a.find(w, function (e) {
  139. return e[0] ===
  140. m
  141. }) || w.push([m, t]);
  142. for (d = 0; d < g;) u = B(e, b[d], b.length), p.push(u.columnTitle || u), l && n.push(u.topLevelColumnTitle || u), d++;
  143. A = {
  144. chart: e.chart,
  145. autoIncrement: e.autoIncrement,
  146. options: e.options,
  147. pointArrayMap: e.pointArrayMap
  148. };
  149. e.options.data.forEach(function (a, l) {
  150. var c, p;
  151. p = {series: A};
  152. e.pointClass.prototype.applyOptions.apply(p, [a]);
  153. a = p.x;
  154. c = e.data[l] && e.data[l].name;
  155. r && (r[a] && (a += "|" + l), r[a] = !0);
  156. d = 0;
  157. e.xAxis && "name" !== e.exportKey || (a = c);
  158. q[a] || (q[a] = [], q[a].xValues = []);
  159. q[a].x = p.x;
  160. q[a].name = c;
  161. for (q[a].xValues[m] =
  162. p.x; d < g;) l = b[d], c = p[l], q[a][t + d] = f(v[l][c], y[l] ? k.dateFormat(h.dateFormat, c) : null, c), d++
  163. });
  164. t += d
  165. }
  166. });
  167. for (m in q) q.hasOwnProperty(m) && d.push(q[m]);
  168. var v, x;
  169. m = l ? [n, p] : [p];
  170. for (t = w.length; t--;) v = w[t][0], x = w[t][1], g = c[v], d.sort(function (a, b) {
  171. return a.xValues[v] - b.xValues[v]
  172. }), r = B(g), m[0].splice(x, 0, r), l && m[1] && m[1].splice(x, 0, r), d.forEach(function (a) {
  173. var e = a.name;
  174. g && !b(e) && (g.isDatetimeAxis ? (a.x instanceof Date && (a.x = a.x.getTime()), e = k.dateFormat(h.dateFormat, a.x)) : e = g.categories ? f(g.names[a.x], g.categories[a.x],
  175. a.x) : a.x);
  176. a.splice(x, 0, e)
  177. });
  178. m = m.concat(d);
  179. a.fireEvent(this, "exportData", {dataRows: m});
  180. return m
  181. };
  182. a.Chart.prototype.getCSV = function (a) {
  183. var b = "", l = this.getDataRows(), g = this.options.exporting.csv,
  184. c = f(g.decimalPoint, "," !== g.itemDelimiter && a ? (1.1).toLocaleString()[1] : "."),
  185. k = f(g.itemDelimiter, "," === c ? ";" : ","), h = g.lineDelimiter;
  186. l.forEach(function (a, g) {
  187. for (var f, d = a.length; d--;) f = a[d], "string" === typeof f && (f = '"' + f + '"'), "number" === typeof f && "." !== c && (f = f.toString().replace(".", c)), a[d] = f;
  188. b += a.join(k);
  189. g < l.length -
  190. 1 && (b += h)
  191. });
  192. return b
  193. };
  194. a.Chart.prototype.getTable = function (b) {
  195. var c = '\x3ctable id\x3d"highcharts-data-table-' + this.index + '"\x3e', l = this.options,
  196. g = b ? (1.1).toLocaleString()[1] : ".", k = f(l.exporting.useMultiLevelHeaders, !0);
  197. b = this.getDataRows(k);
  198. var d = 0, h = k ? b.shift() : null, m = b.shift(), n = function (a, b, c, l) {
  199. var d = f(l, "");
  200. b = "text" + (b ? " " + b : "");
  201. "number" === typeof d ? (d = d.toString(), "," === g && (d = d.replace(".", g)), b = "number") : l || (b = "empty");
  202. return "\x3c" + a + (c ? " " + c : "") + ' class\x3d"' + b + '"\x3e' + d + "\x3c/" + a + "\x3e"
  203. };
  204. !1 !==
  205. l.exporting.tableCaption && (c += '\x3ccaption class\x3d"highcharts-table-caption"\x3e' + f(l.exporting.tableCaption, l.title.text ? l.title.text.replace(/&/g, "\x26amp;").replace(/</g, "\x26lt;").replace(/>/g, "\x26gt;").replace(/"/g, "\x26quot;").replace(/'/g, "\x26#x27;").replace(/\//g, "\x26#x2F;") : "Chart") + "\x3c/caption\x3e");
  206. for (var p = 0, u = b.length; p < u; ++p) b[p].length > d && (d = b[p].length);
  207. c += function (a, b, c) {
  208. var d = "\x3cthead\x3e", g = 0;
  209. c = c || b && b.length;
  210. var f, e, h = 0;
  211. if (e = k && a && b) {
  212. a:if (e = a.length, b.length === e) {
  213. for (; e--;) if (a[e] !==
  214. b[e]) {
  215. e = !1;
  216. break a
  217. }
  218. e = !0
  219. } else e = !1;
  220. e = !e
  221. }
  222. if (e) {
  223. for (d += "\x3ctr\x3e"; g < c; ++g) e = a[g], f = a[g + 1], e === f ? ++h : h ? (d += n("th", "highcharts-table-topheading", 'scope\x3d"col" colspan\x3d"' + (h + 1) + '"', e), h = 0) : (e === b[g] ? l.exporting.useRowspanHeaders ? (f = 2, delete b[g]) : (f = 1, b[g] = "") : f = 1, d += n("th", "highcharts-table-topheading", 'scope\x3d"col"' + (1 < f ? ' valign\x3d"top" rowspan\x3d"' + f + '"' : ""), e));
  224. d += "\x3c/tr\x3e"
  225. }
  226. if (b) {
  227. d += "\x3ctr\x3e";
  228. g = 0;
  229. for (c = b.length; g < c; ++g) void 0 !== b[g] && (d += n("th", null, 'scope\x3d"col"', b[g]));
  230. d += "\x3c/tr\x3e"
  231. }
  232. return d +
  233. "\x3c/thead\x3e"
  234. }(h, m, Math.max(d, m.length));
  235. c += "\x3ctbody\x3e";
  236. b.forEach(function (a) {
  237. c += "\x3ctr\x3e";
  238. for (var b = 0; b < d; b++) c += n(b ? "td" : "th", null, b ? "" : 'scope\x3d"row"', a[b]);
  239. c += "\x3c/tr\x3e"
  240. });
  241. c += "\x3c/tbody\x3e\x3c/table\x3e";
  242. b = {html: c};
  243. a.fireEvent(this, "afterGetTable", b);
  244. return b.html
  245. };
  246. a.Chart.prototype.downloadCSV = function () {
  247. var a = this.getCSV(!0);
  248. z(k(a, "text/csv") || "data:text/csv,\ufeff" + encodeURIComponent(a), this.getFilename() + ".csv")
  249. };
  250. a.Chart.prototype.downloadXLS = function () {
  251. var a = '\x3chtml xmlns:o\x3d"urn:schemas-microsoft-com:office:office" xmlns:x\x3d"urn:schemas-microsoft-com:office:excel" xmlns\x3d"http://www.w3.org/TR/REC-html40"\x3e\x3chead\x3e\x3c!--[if gte mso 9]\x3e\x3cxml\x3e\x3cx:ExcelWorkbook\x3e\x3cx:ExcelWorksheets\x3e\x3cx:ExcelWorksheet\x3e\x3cx:Name\x3eArk1\x3c/x:Name\x3e\x3cx:WorksheetOptions\x3e\x3cx:DisplayGridlines/\x3e\x3c/x:WorksheetOptions\x3e\x3c/x:ExcelWorksheet\x3e\x3c/x:ExcelWorksheets\x3e\x3c/x:ExcelWorkbook\x3e\x3c/xml\x3e\x3c![endif]--\x3e\x3cstyle\x3etd{border:none;font-family: Calibri, sans-serif;} .number{mso-number-format:"0.00";} .text{ mso-number-format:"@";}\x3c/style\x3e\x3cmeta name\x3dProgId content\x3dExcel.Sheet\x3e\x3cmeta charset\x3dUTF-8\x3e\x3c/head\x3e\x3cbody\x3e' +
  252. this.getTable(!0) + "\x3c/body\x3e\x3c/html\x3e";
  253. z(k(a, "application/vnd.ms-excel") || "data:application/vnd.ms-excel;base64," + h.btoa(unescape(encodeURIComponent(a))), this.getFilename() + ".xls")
  254. };
  255. a.Chart.prototype.viewData = function () {
  256. this.dataTableDiv || (this.dataTableDiv = n.createElement("div"), this.dataTableDiv.className = "highcharts-data-table", this.renderTo.parentNode.insertBefore(this.dataTableDiv, this.renderTo.nextSibling));
  257. this.dataTableDiv.innerHTML = this.getTable()
  258. };
  259. a.Chart.prototype.openInCloud = function () {
  260. function b(c) {
  261. Object.keys(c).forEach(function (d) {
  262. "function" ===
  263. typeof c[d] && delete c[d];
  264. a.isObject(c[d]) && b(c[d])
  265. })
  266. }
  267. var c, d;
  268. c = a.merge(this.userOptions);
  269. b(c);
  270. c = {
  271. name: c.title && c.title.text || "Chart title",
  272. options: c,
  273. settings: {constructor: "Chart", dataProvider: {csv: this.getCSV()}}
  274. };
  275. d = JSON.stringify(c);
  276. (function () {
  277. var a = n.createElement("form");
  278. n.body.appendChild(a);
  279. a.method = "post";
  280. a.action = "https://cloud-api.highcharts.com/openincloud";
  281. a.target = "_blank";
  282. var b = n.createElement("input");
  283. b.type = "hidden";
  284. b.name = "chart";
  285. b.value = d;
  286. a.appendChild(b);
  287. a.submit();
  288. n.body.removeChild(a)
  289. })()
  290. };
  291. var d = a.getOptions().exporting;
  292. d && (a.extend(d.menuItemDefinitions, {
  293. downloadCSV: {
  294. textKey: "downloadCSV", onclick: function () {
  295. this.downloadCSV()
  296. }
  297. }, downloadXLS: {
  298. textKey: "downloadXLS", onclick: function () {
  299. this.downloadXLS()
  300. }
  301. }, viewData: {
  302. textKey: "viewData", onclick: function () {
  303. this.viewData()
  304. }
  305. }, openInCloud: {
  306. textKey: "openInCloud", onclick: function () {
  307. this.openInCloud()
  308. }
  309. }
  310. }), d.buttons.contextButton.menuItems.push("separator", "downloadCSV", "downloadXLS", "viewData", "openInCloud"));
  311. c.map && (c.map.prototype.exportKey = "name");
  312. c.mapbubble && (c.mapbubble.prototype.exportKey = "name");
  313. c.treemap && (c.treemap.prototype.exportKey = "name")
  314. })(h)
  315. });
  316. //# sourceMappingURL=export-data.js.map